libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  4. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  6. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  7. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  14. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  61. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  62. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  63. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  64. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  65. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  66. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  67. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  71. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  75. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  79. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  80. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  196. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  198. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  199. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  314. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  315. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  316. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  318. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  370. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  371. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  373. data/lib/libmongocrypt_helper/version.rb +2 -2
  374. data.tar.gz.sig +0 -0
  375. metadata +154 -26
  376. metadata.gz.sig +0 -0
  377. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  378. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  380. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  381. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  382. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  392. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
  393. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  394. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -14,879 +14,427 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- #include <mongocrypt.h>
18
17
  #include <mongocrypt-crypto-private.h>
18
+ #include <mongocrypt.h>
19
19
 
20
20
  #include "test-mongocrypt.h"
21
21
 
22
- static void
23
- _test_roundtrip (_mongocrypt_tester_t *tester)
24
- {
25
- mongocrypt_t *crypt;
26
- mongocrypt_status_t *const status = mongocrypt_status_new ();
27
- _mongocrypt_buffer_t key = {0}, iv = {0}, associated_data = {0},
28
- plaintext = {0}, ciphertext = {0}, decrypted = {0};
29
- uint32_t bytes_written;
30
- bool ret;
31
-
32
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
33
- plaintext.data = (uint8_t *) "test";
34
- plaintext.len = 5; /* include NULL. */
35
-
36
- ciphertext.len = _mongocrypt_calculate_ciphertext_len (5, status);
37
- ciphertext.data = bson_malloc (ciphertext.len);
38
- BSON_ASSERT (ciphertext.data);
39
-
40
- ciphertext.owned = true;
41
-
42
- decrypted.len = _mongocrypt_calculate_plaintext_len (ciphertext.len, status);
43
- decrypted.data = bson_malloc (decrypted.len);
44
- BSON_ASSERT (decrypted.data);
45
-
46
- decrypted.owned = true;
47
-
48
- key.data = (uint8_t *) _mongocrypt_repeat_char ('k', MONGOCRYPT_KEY_LEN);
49
- key.len = MONGOCRYPT_KEY_LEN;
50
- key.owned = true;
51
-
52
- iv.data = (uint8_t *) _mongocrypt_repeat_char ('i', MONGOCRYPT_IV_LEN);
53
- iv.len = MONGOCRYPT_IV_LEN;
54
- iv.owned = true;
55
-
56
- ret = _mongocrypt_do_encryption (crypt->crypto,
57
- &iv,
58
- &associated_data,
59
- &key,
60
- &plaintext,
61
- &ciphertext,
62
- &bytes_written,
63
- status);
64
- BSON_ASSERT (ret);
65
-
66
- BSON_ASSERT (bytes_written == ciphertext.len);
67
-
68
- ret = _mongocrypt_do_decryption (crypt->crypto,
69
- &associated_data,
70
- &key,
71
- &ciphertext,
72
- &decrypted,
73
- &bytes_written,
74
- status);
75
- BSON_ASSERT (ret);
76
-
77
-
78
- BSON_ASSERT (bytes_written == plaintext.len);
79
- decrypted.len = bytes_written;
80
- BSON_ASSERT (0 == strcmp ((char *) decrypted.data, (char *) plaintext.data));
81
-
82
- /* Modify a bit in the ciphertext hash to ensure HMAC integrity check. */
83
- ciphertext.data[ciphertext.len - 1] ^= 1;
84
-
85
- _mongocrypt_buffer_cleanup (&decrypted);
86
- decrypted.len = _mongocrypt_calculate_plaintext_len (ciphertext.len, status);
87
- decrypted.data = bson_malloc (decrypted.len);
88
- BSON_ASSERT (decrypted.data);
89
-
90
- decrypted.owned = true;
91
-
92
- ret = _mongocrypt_do_decryption (crypt->crypto,
93
- &associated_data,
94
- &key,
95
- &ciphertext,
96
- &decrypted,
97
- &bytes_written,
98
- status);
99
- BSON_ASSERT (!ret);
100
- BSON_ASSERT (0 == strcmp (mongocrypt_status_message (status, NULL),
101
- "HMAC validation failure"));
102
- /* undo the change (flip the bit again). Double check that decryption works
103
- * again. */
104
- ciphertext.data[ciphertext.len - 1] ^= 1;
105
- _mongocrypt_status_reset (status);
106
- ret = _mongocrypt_do_decryption (crypt->crypto,
107
- &associated_data,
108
- &key,
109
- &ciphertext,
110
- &decrypted,
111
- &bytes_written,
112
- status);
113
- BSON_ASSERT (ret);
114
-
115
- /* Modify parts of the key. */
116
- key.data[0] ^= 1; /* part of the mac key */
117
- ret = _mongocrypt_do_decryption (crypt->crypto,
118
- &associated_data,
119
- &key,
120
- &ciphertext,
121
- &decrypted,
122
- &bytes_written,
123
- status);
124
- BSON_ASSERT (!ret);
125
- BSON_ASSERT (0 == strcmp (mongocrypt_status_message (status, NULL),
126
- "HMAC validation failure"));
127
- /* undo */
128
- key.data[0] ^= 1;
129
- _mongocrypt_status_reset (status);
130
-
131
- /* Modify the portion of the key responsible for encryption/decryption */
132
- key.data[MONGOCRYPT_MAC_KEY_LEN + 1] ^= 1; /* part of the encryption key */
133
- ret = _mongocrypt_do_decryption (crypt->crypto,
134
- &associated_data,
135
- &key,
136
- &ciphertext,
137
- &decrypted,
138
- &bytes_written,
139
- status);
140
- BSON_ASSERT (!ret);
141
- BSON_ASSERT (0 == strcmp (mongocrypt_status_message (status, NULL),
142
- "error, ciphertext malformed padding"));
143
-
144
- mongocrypt_status_destroy (status);
145
- _mongocrypt_buffer_cleanup (&decrypted);
146
- _mongocrypt_buffer_cleanup (&ciphertext);
147
- _mongocrypt_buffer_cleanup (&key);
148
- _mongocrypt_buffer_cleanup (&iv);
149
- mongocrypt_destroy (crypt);
22
+ typedef struct {
23
+ const char *name;
24
+ const _mongocrypt_value_encryption_algorithm_t *algo;
25
+ _mongocrypt_buffer_t key;
26
+ _mongocrypt_buffer_t aad;
27
+ _mongocrypt_buffer_t iv;
28
+ _mongocrypt_buffer_t plaintext;
29
+ _mongocrypt_buffer_t ciphertext;
30
+ const char *encrypt_error;
31
+ const char *decrypt_error;
32
+ // Special case test for payload which decrypts to empty string.
33
+ bool ignore_ciphertext_mismatch_on_encrypt;
34
+ } _test_mc_crypto_roundtrip_t;
35
+
36
+ static bool _test_uses_ctr(const _test_mc_crypto_roundtrip_t *test) {
37
+ return (test->algo == _mcFLE2AEADAlgorithm()) || (test->algo == _mcFLE2Algorithm());
150
38
  }
151
39
 
40
+ #define ASSERT_BAD_DECRYPT(ret, out, test, status) \
41
+ if (test->algo == _mcFLE2Algorithm()) { \
42
+ /* A bad decrypt with CTR and no MAC isn't directly visible, */ \
43
+ /* we just get garbage data. */ \
44
+ ASSERT(out.len == test->plaintext.len); \
45
+ ASSERT(memcmp(out.data, test->plaintext.data, out.len) != 0); \
46
+ } else { \
47
+ ASSERT_FAILS_STATUS(ret, status, "HMAC validation failure"); \
48
+ }
49
+
50
+ static void _test_roundtrip_single(const _test_mc_crypto_roundtrip_t *test) {
51
+ if (!_aes_ctr_is_supported_by_os && _test_uses_ctr(test)) {
52
+ printf("Common Crypto with no CTR support detected. Skipping %s", test->name);
53
+ return;
54
+ }
55
+
56
+ printf("Begin %s...\n", test->name);
57
+
58
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
59
+ mongocrypt_status_t *const status = mongocrypt_status_new();
60
+ _mongocrypt_buffer_t out;
61
+
62
+ // Test encrypt
63
+ _mongocrypt_buffer_init_size(&out, test->algo->get_ciphertext_len(test->plaintext.len, status));
64
+ ASSERT_OK_STATUS(true, status);
65
+ uint32_t outlen;
66
+ bool ret =
67
+ test->algo
68
+ ->do_encrypt(crypt->crypto, &test->iv, &test->aad, &test->key, &test->plaintext, &out, &outlen, status);
69
+ if (test->encrypt_error) {
70
+ ASSERT_FAILS_STATUS(ret, status, test->encrypt_error);
71
+ goto done;
72
+ } else if (test->ignore_ciphertext_mismatch_on_encrypt) {
73
+ _mongocrypt_status_reset(status);
74
+ } else {
75
+ ASSERT_OK_STATUS(ret, status);
76
+ out.len = outlen;
77
+ ASSERT_CMPBUF(out, test->ciphertext);
78
+ }
79
+
80
+ // Test decrypt
81
+ const uint32_t plaintext_len = test->algo->get_plaintext_len(test->ciphertext.len, status);
82
+ if (test->decrypt_error && !mongocrypt_status_ok(status)) {
83
+ ASSERT_FAILS_STATUS(false, status, test->decrypt_error);
84
+ goto done;
85
+ }
86
+ ASSERT_OK_STATUS(true, status);
87
+ _mongocrypt_buffer_resize(&out, plaintext_len);
88
+ ret = test->algo->do_decrypt(crypt->crypto, &test->aad, &test->key, &test->ciphertext, &out, &outlen, status);
89
+ if (test->decrypt_error) {
90
+ ASSERT_FAILS_STATUS(ret, status, test->decrypt_error);
91
+ goto done;
92
+ }
93
+ ASSERT_OK_STATUS(ret, status);
94
+ out.len = outlen;
95
+ ASSERT_CMPBUF(out, test->plaintext);
96
+
97
+ // Negative: Mutated IV
98
+ _mongocrypt_buffer_t modified_ciphertext = {0};
99
+ _mongocrypt_buffer_copy_to(&test->ciphertext, &modified_ciphertext);
100
+ _mongocrypt_buffer_resize(&out, plaintext_len);
101
+ modified_ciphertext.data[0] ^= 1;
102
+ ret = test->algo->do_decrypt(crypt->crypto, &test->aad, &test->key, &modified_ciphertext, &out, &outlen, status);
103
+ out.len = outlen;
104
+ ASSERT_BAD_DECRYPT(ret, out, test, status);
105
+
106
+ // Negative: Mutated ciphertext
107
+ _mongocrypt_buffer_copy_to(&test->ciphertext, &modified_ciphertext);
108
+ _mongocrypt_buffer_resize(&out, plaintext_len);
109
+ modified_ciphertext.data[MONGOCRYPT_IV_LEN] ^= 1;
110
+ ret = test->algo->do_decrypt(crypt->crypto, &test->aad, &test->key, &modified_ciphertext, &out, &outlen, status);
111
+ ASSERT_BAD_DECRYPT(ret, out, test, status);
112
+
113
+ // Negative: Mutated tag
114
+ // Note: On algorithms without HMAC, this just repeats the mutated ciphertext
115
+ // test in a different part of S.
116
+ _mongocrypt_buffer_copy_to(&test->ciphertext, &modified_ciphertext);
117
+ _mongocrypt_buffer_resize(&out, plaintext_len);
118
+ modified_ciphertext.data[modified_ciphertext.len - 1] ^= 1;
119
+ ret = test->algo->do_decrypt(crypt->crypto, &test->aad, &test->key, &modified_ciphertext, &out, &outlen, status);
120
+ ASSERT_BAD_DECRYPT(ret, out, test, status);
121
+
122
+ _mongocrypt_buffer_cleanup(&modified_ciphertext);
123
+ done:
124
+ _mongocrypt_buffer_cleanup(&out);
125
+ mongocrypt_status_destroy(status);
126
+ mongocrypt_destroy(crypt);
127
+
128
+ printf("End %s...\n", test->name);
129
+ }
152
130
 
153
- /* From [MCGREW], see comment at the top of this file. */
154
- static void
155
- _test_mcgrew (_mongocrypt_tester_t *tester)
156
- {
157
- mongocrypt_t *crypt;
158
- mongocrypt_status_t *const status = mongocrypt_status_new ();
159
- _mongocrypt_buffer_t key, iv, associated_data, plaintext,
160
- ciphertext_expected, ciphertext_actual;
161
- uint32_t bytes_written;
162
- bool ret;
163
-
164
- _mongocrypt_buffer_copy_from_hex (
165
- &key,
166
- "000102030405060708090a0b0c0d0e0f101112131415161718191a1"
167
- "b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536"
168
- "3738393a3b3c3d3e3f"
169
- /* includes our additional 32 byte IV key */
170
- "0000000000000000000000000000000000000000000000000000000000000000");
171
- _mongocrypt_buffer_copy_from_hex (&iv, "1af38c2dc2b96ffdd86694092341bc04");
172
- _mongocrypt_buffer_copy_from_hex (
173
- &plaintext,
174
- "41206369706865722073797374656d206d757374206e6f742"
175
- "0626520726571756972656420746f20626520736563726574"
176
- "2c20616e64206974206d7573742062652061626c6520746f2"
177
- "066616c6c20696e746f207468652068616e6473206f662074"
178
- "686520656e656d7920776974686f757420696e636f6e76656"
179
- "e69656e6365");
180
- _mongocrypt_buffer_copy_from_hex (
181
- &associated_data,
182
- "546865207365636f6e64207072696e6369706c65206"
183
- "f662041756775737465204b6572636b686f666673");
184
- _mongocrypt_buffer_copy_from_hex (
185
- &ciphertext_expected,
186
- "1af38c2dc2b96ffdd86694092341bc044affaaadb78c31c5da4b1b590d10f"
187
- "fbd3dd8d5d302423526912da037ecbcc7bd822c301dd67c373bccb584ad3e"
188
- "9279c2e6d12a1374b77f077553df829410446b36ebd97066296ae6427ea75"
189
- "c2e0846a11a09ccf5370dc80bfecbad28c73f09b3a3b75e662a2594410ae4"
190
- "96b2e2e6609e31e6e02cc837f053d21f37ff4f51950bbe2638d09dd7a4930"
191
- "930806d0703b1f64dd3b4c088a7f45c216839645b2012bf2e6269a8c56a81"
192
- "6dbc1b267761955bc5");
193
-
194
- ciphertext_actual.len =
195
- _mongocrypt_calculate_ciphertext_len (plaintext.len, status);
196
- ciphertext_actual.data = bson_malloc (ciphertext_actual.len);
197
- BSON_ASSERT (ciphertext_actual.data);
198
-
199
- ciphertext_actual.owned = true;
200
-
201
- /* Force the crypto stack to initialize with mongocrypt_new */
202
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
203
- ret = _mongocrypt_do_encryption (crypt->crypto,
204
- &iv,
205
- &associated_data,
206
- &key,
207
- &plaintext,
208
- &ciphertext_actual,
209
- &bytes_written,
210
- status);
211
- BSON_ASSERT (ret);
212
- BSON_ASSERT (ciphertext_actual.len == ciphertext_expected.len);
213
- BSON_ASSERT (0 == memcmp (ciphertext_actual.data,
214
- ciphertext_expected.data,
215
- ciphertext_actual.len));
216
-
217
- _mongocrypt_buffer_cleanup (&key);
218
- _mongocrypt_buffer_cleanup (&iv);
219
- _mongocrypt_buffer_cleanup (&plaintext);
220
- _mongocrypt_buffer_cleanup (&associated_data);
221
- _mongocrypt_buffer_cleanup (&ciphertext_expected);
222
- _mongocrypt_buffer_cleanup (&ciphertext_actual);
223
- mongocrypt_status_destroy (status);
224
- mongocrypt_destroy (crypt);
131
+ static const _mongocrypt_value_encryption_algorithm_t *get_algo_by_name(const char *name) {
132
+ if (!strcmp(name, "AES-256-CBC/SHA-512-256") || !strcmp(name, "FLE1")) {
133
+ return _mcFLE1Algorithm();
134
+ }
135
+ if (!strcmp(name, "AES-256-CTR/SHA-256") || !strcmp(name, "FLE2AEAD")) {
136
+ return _mcFLE2AEADAlgorithm();
137
+ }
138
+ if (!strcmp(name, "AES-256-CTR/NONE") || !strcmp(name, "FLE2")) {
139
+ return _mcFLE2Algorithm();
140
+ }
141
+ if (!strcmp(name, "AES-256-CBC/SHA-256") || !strcmp(name, "FLE2v2AEAD")) {
142
+ return _mcFLE2v2AEADAlgorithm();
143
+ }
144
+ TEST_ERROR("Unknown algorithm: %s", name);
225
145
  }
226
146
 
227
- typedef struct {
228
- const char *testname;
229
- const char *key;
230
- const char *iv;
231
- const char *plaintext;
232
- const char *ciphertext;
233
- } aes_256_ctr_test_t;
234
-
235
- void
236
- _test_native_crypto_aes_256_ctr (_mongocrypt_tester_t *tester)
237
- {
238
- aes_256_ctr_test_t tests[] = {
239
- {.testname = "See NIST SP 800-38A section F.5.5",
240
- .key = "603deb1015ca71be2b73aef0857d7781"
241
- "1f352c073b6108d72d9810a30914dff4",
242
- .iv = "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff",
243
- .plaintext = "6bc1bee22e409f96e93d7e117393172a"
244
- "ae2d8a571e03ac9c9eb76fac45af8e51"
245
- "30c81c46a35ce411e5fbc1191a0a52ef"
246
- "f69f2445df4f9b17ad2b417be66c3710",
247
- .ciphertext = "601ec313775789a5b7a7f504bbf3d228"
248
- "f443e3ca4d62b59aca84e990cacaf5c5"
249
- "2b0930daa23de94ce87017ba2d84988d"
250
- "dfc9c58db67aada613c2dd08457941a6"},
251
- {.testname = "Not 64 byte aligned input",
252
- .key = "603deb1015ca71be2b73aef0857d7781"
253
- "1f352c073b6108d72d9810a30914dff4",
254
- .iv = "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff",
255
- .plaintext = "AAAA",
256
- .ciphertext = "A175"},
257
- #include <data/aes-ctr.cstructs>
258
- {0}};
259
- aes_256_ctr_test_t *test;
260
-
261
- mongocrypt_t *crypt;
262
- crypt = mongocrypt_new ();
263
-
264
- for (test = tests; test->testname != NULL; test++) {
265
- bool ret;
266
- _mongocrypt_buffer_t key;
267
- _mongocrypt_buffer_t iv;
268
- _mongocrypt_buffer_t plaintext;
269
- _mongocrypt_buffer_t ciphertext;
270
- _mongocrypt_buffer_t plaintext_got;
271
- _mongocrypt_buffer_t ciphertext_got;
272
- mongocrypt_status_t *status;
273
- uint32_t bytes_written;
274
-
275
- if (!_aes_ctr_is_supported_by_os) {
276
- printf ("Common Crypto with no CTR support detected. Skipping.");
277
- return;
278
- }
279
-
280
- printf ("Begin test '%s'.\n", test->testname);
281
-
282
- _mongocrypt_buffer_copy_from_hex (&key, test->key);
283
- _mongocrypt_buffer_copy_from_hex (&iv, test->iv);
284
- _mongocrypt_buffer_copy_from_hex (&plaintext, test->plaintext);
285
- _mongocrypt_buffer_copy_from_hex (&ciphertext, test->ciphertext);
286
- _mongocrypt_buffer_init (&plaintext_got);
287
- _mongocrypt_buffer_resize (&plaintext_got, plaintext.len);
288
- /* Allocate memory for output ciphertext. CTR mode does not use padding.
289
- * Use plaintext length as expected ciphertext length. */
290
- _mongocrypt_buffer_init (&ciphertext_got);
291
- _mongocrypt_buffer_resize (&ciphertext_got, plaintext.len);
292
- status = mongocrypt_status_new ();
293
-
294
- /* Test encrypt. */
295
- ret = _native_crypto_aes_256_ctr_encrypt (
296
- (aes_256_args_t){.key = &key,
297
- .iv = &iv,
298
- .in = &plaintext,
299
- .out = &ciphertext_got,
300
- .bytes_written = &bytes_written,
301
- .status = status});
302
- ASSERT_OR_PRINT (ret, status);
303
- ASSERT_CMPBYTES (ciphertext.data,
304
- ciphertext.len,
305
- ciphertext_got.data,
306
- ciphertext_got.len);
307
- ASSERT_CMPINT ((int) bytes_written, ==, (int) ciphertext.len);
308
-
309
- /* Test decrypt. */
310
- ret = _native_crypto_aes_256_ctr_decrypt (
311
- (aes_256_args_t){.key = &key,
312
- .iv = &iv,
313
- .in = &ciphertext,
314
- .out = &plaintext_got,
315
- .bytes_written = &bytes_written,
316
- .status = status});
317
- ASSERT_OR_PRINT (ret, status);
318
- ASSERT_CMPBYTES (
319
- plaintext.data, plaintext.len, plaintext_got.data, plaintext_got.len);
320
- ASSERT_CMPINT ((int) bytes_written, ==, (int) plaintext.len);
321
-
322
- mongocrypt_status_destroy (status);
323
- _mongocrypt_buffer_cleanup (&ciphertext_got);
324
- _mongocrypt_buffer_cleanup (&plaintext_got);
325
- _mongocrypt_buffer_cleanup (&ciphertext);
326
- _mongocrypt_buffer_cleanup (&plaintext);
327
- _mongocrypt_buffer_cleanup (&iv);
328
- _mongocrypt_buffer_cleanup (&key);
329
-
330
- printf ("End test '%s'.\n", test->testname);
331
- }
332
-
333
- mongocrypt_destroy (crypt);
147
+ static void _parse_roundtrip_test(bson_iter_t *iter, _test_mc_crypto_roundtrip_t *test) {
148
+ while (bson_iter_next(iter)) {
149
+ const char *field = bson_iter_key(iter);
150
+ ASSERT(field);
151
+
152
+ if (!strcmp(field, "algo")) {
153
+ ASSERT_OR_PRINT_MSG(!test->algo, "Duplicate field 'algo' in test");
154
+ ASSERT(BSON_ITER_HOLDS_UTF8(iter));
155
+ test->algo = get_algo_by_name(bson_iter_utf8(iter, NULL));
156
+ } else if (!strcmp(field, "ignore_ciphertext_mismatch_on_encrypt")) {
157
+ ASSERT_OR_PRINT_MSG(!test->ignore_ciphertext_mismatch_on_encrypt,
158
+ "Duplicate field 'ignore_ciphertext_mismatch_on_encrypt' in test");
159
+ ASSERT(BSON_ITER_HOLDS_BOOL(iter));
160
+ ASSERT_OR_PRINT_MSG(bson_iter_bool(iter), "value of 'ignore_ciphertext_mismatch_on_encrypt' must be true");
161
+ test->ignore_ciphertext_mismatch_on_encrypt = true;
162
+ }
163
+
164
+ #define STR_FIELD(Name) \
165
+ else if (!strcmp(field, #Name)) { \
166
+ ASSERT_OR_PRINT_MSG(!test->Name, "Duplicate field '" #Name "' in test"); \
167
+ ASSERT(BSON_ITER_HOLDS_UTF8(iter)); \
168
+ test->Name = bson_strdup(bson_iter_utf8(iter, NULL)); \
169
+ }
170
+
171
+ STR_FIELD(name)
172
+ STR_FIELD(encrypt_error)
173
+ STR_FIELD(decrypt_error)
174
+
175
+ #undef STR_FIELD
176
+
177
+ // If we encounter a zero-length hexit string,
178
+ // then mcb_copy_from_hex will leave the buffer unallocated.
179
+ // This complicates field detection when we want an empty plaintext.
180
+ // Similarly, mcb_init_size will not allocate a lenght of zero.
181
+ // Simplify the flow elsewhere by allocating 1 byte, then truncating.
182
+ #define HEXBUF_FIELD(Name) \
183
+ else if (!strcmp(field, #Name)) { \
184
+ ASSERT_OR_PRINT_MSG(!test->Name.data, "Duplicate field '" #Name "' in test"); \
185
+ ASSERT(BSON_ITER_HOLDS_UTF8(iter)); \
186
+ const char *value = bson_iter_utf8(iter, NULL); \
187
+ const size_t value_len = strlen(value); \
188
+ if (value_len > 0) { \
189
+ _mongocrypt_buffer_copy_from_hex(&test->Name, value); \
190
+ ASSERT(strlen(value) == (test->Name.len * 2)); \
191
+ } else { \
192
+ _mongocrypt_buffer_init_size(&test->Name, 1); \
193
+ test->Name.len = 0; \
194
+ } \
195
+ }
196
+
197
+ HEXBUF_FIELD(key)
198
+ HEXBUF_FIELD(aad)
199
+ HEXBUF_FIELD(iv)
200
+ HEXBUF_FIELD(plaintext)
201
+ HEXBUF_FIELD(ciphertext)
202
+ #undef HEXBUF_FIELD
203
+ }
204
+
205
+ ASSERT_OR_PRINT_MSG(test->name, "Missing field 'name'");
206
+ ASSERT_OR_PRINT_MSG(test->algo, "Missing field 'algo'");
207
+ ASSERT_OR_PRINT_MSG(test->key.data, "Missing field 'key'");
208
+ if (test->algo == _mcFLE2Algorithm()) {
209
+ ASSERT_OR_PRINT_MSG(test->aad.len == 0, "Unexpected value in field 'aad' for cipher without MAC");
210
+ } else {
211
+ ASSERT_OR_PRINT_MSG(test->aad.data, "Missing field 'aad'");
212
+ }
213
+ ASSERT_OR_PRINT_MSG(test->iv.data, "Missing field 'iv'");
214
+ ASSERT_OR_PRINT_MSG(test->plaintext.data, "Missing field 'plaintext'");
215
+ ASSERT_OR_PRINT_MSG(test->ciphertext.data || test->encrypt_error, "Missing field 'ciphertext'");
216
+ }
217
+
218
+ static void _test_mc_crypto_roundtrip_destroy(_test_mc_crypto_roundtrip_t *test) {
219
+ if (test->name) {
220
+ bson_free((void *)test->name);
221
+ }
222
+ _mongocrypt_buffer_cleanup(&test->key);
223
+ _mongocrypt_buffer_cleanup(&test->aad);
224
+ _mongocrypt_buffer_cleanup(&test->iv);
225
+ _mongocrypt_buffer_cleanup(&test->plaintext);
226
+ _mongocrypt_buffer_cleanup(&test->ciphertext);
227
+ if (test->encrypt_error) {
228
+ bson_free((void *)test->encrypt_error);
229
+ }
230
+ if (test->decrypt_error) {
231
+ bson_free((void *)test->decrypt_error);
232
+ }
233
+ }
234
+
235
+ static void _test_roundtrip_set(_mongocrypt_tester_t *tester, const char *path) {
236
+ printf("Loading tests from %s...\n", path);
237
+
238
+ mongocrypt_binary_t *test_bin = TEST_FILE(path);
239
+ if (!test_bin) {
240
+ TEST_ERROR("Failed loading test data file '%s'\n", path);
241
+ }
242
+ if (test_bin->len == 5) {
243
+ TEST_ERROR("Invalid JSON in file '%s'\n", path);
244
+ }
245
+
246
+ bson_t test_bson;
247
+ ASSERT(bson_init_static(&test_bson, test_bin->data, test_bin->len));
248
+ ASSERT(bson_validate(&test_bson, BSON_VALIDATE_NONE, NULL));
249
+
250
+ bson_iter_t it;
251
+ ASSERT(bson_iter_init(&it, &test_bson));
252
+ while (bson_iter_next(&it)) {
253
+ bson_iter_t docit;
254
+ ASSERT(BSON_ITER_HOLDS_DOCUMENT(&it));
255
+ ASSERT(bson_iter_recurse(&it, &docit));
256
+ _test_mc_crypto_roundtrip_t test = {0};
257
+ _parse_roundtrip_test(&docit, &test);
258
+ _test_roundtrip_single(&test);
259
+ _test_mc_crypto_roundtrip_destroy(&test);
260
+ }
261
+
262
+ printf("Finished tests in %s\n", path);
263
+ }
264
+
265
+ static void _test_roundtrip(_mongocrypt_tester_t *tester) {
266
+ _test_roundtrip_set(tester, "./test/data/roundtrip/mcgrew.json");
267
+ _test_roundtrip_set(tester, "./test/data/roundtrip/nist.json");
268
+ _test_roundtrip_set(tester, "./test/data/roundtrip/aes-ctr.json");
269
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2v2-aead-fixed.json");
270
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2v2-aead-generated.json");
271
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2aead-fixed.json");
272
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2aead-generated.json");
273
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2aead-decrypt.json");
274
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2-fixed.json");
275
+ _test_roundtrip_set(tester, "./test/data/roundtrip/fle2-generated.json");
334
276
  }
335
277
 
336
278
  typedef struct {
337
- const char *testname;
338
- const char *key;
339
- const char *input;
340
- const char *expect;
279
+ const char *testname;
280
+ const char *key;
281
+ const char *input;
282
+ const char *expect;
341
283
  } hmac_sha_256_test_t;
342
284
 
343
- void
344
- _test_native_crypto_hmac_sha_256 (_mongocrypt_tester_t *tester)
345
- {
346
- /* Test data generated with OpenSSL CLI:
347
- $ echo -n "test" | openssl dgst -mac hmac -macopt \
348
- hexkey:6bb2664e8d444377d3cd9566c005593b7ed8a35ab8eac9eb5ffa6e426854e5cc \
349
- -sha256
350
- d80a4d2271fdaa45ad4a1bf85d606fe465cb40176d1d83e69628a154c2c528ff
351
-
352
- Hex representation of "test" is: 74657374
353
- */
354
- hmac_sha_256_test_t tests[] = {
355
- {.testname = "String 'test'",
356
- .key = "6bb2664e8d444377d3cd9566c005593b"
357
- "7ed8a35ab8eac9eb5ffa6e426854e5cc",
358
- .input = "74657374",
359
- .expect = "d80a4d2271fdaa45ad4a1bf85d606fe4"
360
- "65cb40176d1d83e69628a154c2c528ff"},
361
- {.testname = "Data larger than one block",
362
- .key = "6bb2664e8d444377d3cd9566c005593b"
363
- "7ed8a35ab8eac9eb5ffa6e426854e5cc",
364
- .input = "fd2368de92202a33fcaf48f9b5807fc8"
365
- "6b9837aa376beb6044d6db6b07347f7e"
366
- "2af3eedfc968218f76b588fff9ae1c91"
367
- "74cca2368389bf211270f0449771c260"
368
- "689bb59a32f0c5ae40372ecb371ec2a7"
369
- "2179bbe8d46260eef7d0e7c1ae679b71",
370
- .expect = "1985743613238e3c8c05a0274be76fa6"
371
- "7821228f7b880e72dbd0f314fb63e63f"},
285
+ void _test_native_crypto_hmac_sha_256(_mongocrypt_tester_t *tester) {
286
+ /* Test data generated with OpenSSL CLI:
287
+ $ echo -n "test" | openssl dgst -mac hmac -macopt \
288
+ hexkey:6bb2664e8d444377d3cd9566c005593b7ed8a35ab8eac9eb5ffa6e426854e5cc \
289
+ -sha256
290
+ d80a4d2271fdaa45ad4a1bf85d606fe465cb40176d1d83e69628a154c2c528ff
291
+
292
+ Hex representation of "test" is: 74657374
293
+ */
294
+ hmac_sha_256_test_t tests[] = {{.testname = "String 'test'",
295
+ .key = "6bb2664e8d444377d3cd9566c005593b"
296
+ "7ed8a35ab8eac9eb5ffa6e426854e5cc",
297
+ .input = "74657374",
298
+ .expect = "d80a4d2271fdaa45ad4a1bf85d606fe4"
299
+ "65cb40176d1d83e69628a154c2c528ff"},
300
+ {.testname = "Data larger than one block",
301
+ .key = "6bb2664e8d444377d3cd9566c005593b"
302
+ "7ed8a35ab8eac9eb5ffa6e426854e5cc",
303
+ .input = "fd2368de92202a33fcaf48f9b5807fc8"
304
+ "6b9837aa376beb6044d6db6b07347f7e"
305
+ "2af3eedfc968218f76b588fff9ae1c91"
306
+ "74cca2368389bf211270f0449771c260"
307
+ "689bb59a32f0c5ae40372ecb371ec2a7"
308
+ "2179bbe8d46260eef7d0e7c1ae679b71",
309
+ .expect = "1985743613238e3c8c05a0274be76fa6"
310
+ "7821228f7b880e72dbd0f314fb63e63f"},
372
311
  #include "./data/NIST-CAVP.cstructs"
373
- {0}};
374
- hmac_sha_256_test_t *test;
375
- mongocrypt_t *crypt;
376
-
377
- /* Create a mongocrypt_t to call _native_crypto_init(). */
378
- crypt = mongocrypt_new ();
379
-
380
- for (test = tests; test->testname != NULL; test++) {
381
- bool ret;
382
- _mongocrypt_buffer_t key;
383
- _mongocrypt_buffer_t input;
384
- _mongocrypt_buffer_t expect;
385
- _mongocrypt_buffer_t got;
386
- mongocrypt_status_t *status;
387
-
388
-
389
- printf ("Begin test '%s'.\n", test->testname);
390
-
391
- _mongocrypt_buffer_copy_from_hex (&key, test->key);
392
- _mongocrypt_buffer_copy_from_hex (&input, test->input);
393
- _mongocrypt_buffer_copy_from_hex (&expect, test->expect);
394
- _mongocrypt_buffer_init (&got);
395
- _mongocrypt_buffer_resize (&got, MONGOCRYPT_HMAC_SHA256_LEN);
396
- status = mongocrypt_status_new ();
397
-
398
- ret = _native_crypto_hmac_sha_256 (&key, &input, &got, status);
399
- ASSERT_OR_PRINT (ret, status);
400
- if (expect.len < got.len) {
401
- /* Some NIST CAVP tests expect the output tag to be truncated. */
402
- got.len = expect.len;
403
- }
404
- ASSERT_CMPBYTES (expect.data, expect.len, got.data, got.len);
405
-
406
- mongocrypt_status_destroy (status);
407
- _mongocrypt_buffer_cleanup (&got);
408
- _mongocrypt_buffer_cleanup (&expect);
409
- _mongocrypt_buffer_cleanup (&input);
410
- _mongocrypt_buffer_cleanup (&key);
411
-
412
- printf ("End test '%s'.\n", test->testname);
413
- }
414
-
415
- mongocrypt_destroy (crypt);
312
+ {0}};
313
+ hmac_sha_256_test_t *test;
314
+ mongocrypt_t *crypt;
315
+
316
+ /* Create a mongocrypt_t to call _native_crypto_init(). */
317
+ crypt = mongocrypt_new();
318
+
319
+ for (test = tests; test->testname != NULL; test++) {
320
+ bool ret;
321
+ _mongocrypt_buffer_t key;
322
+ _mongocrypt_buffer_t input;
323
+ _mongocrypt_buffer_t expect;
324
+ _mongocrypt_buffer_t got;
325
+ mongocrypt_status_t *status;
326
+
327
+ printf("Begin test '%s'.\n", test->testname);
328
+
329
+ _mongocrypt_buffer_copy_from_hex(&key, test->key);
330
+ _mongocrypt_buffer_copy_from_hex(&input, test->input);
331
+ _mongocrypt_buffer_copy_from_hex(&expect, test->expect);
332
+ _mongocrypt_buffer_init(&got);
333
+ _mongocrypt_buffer_resize(&got, MONGOCRYPT_HMAC_SHA256_LEN);
334
+ status = mongocrypt_status_new();
335
+
336
+ ret = _native_crypto_hmac_sha_256(&key, &input, &got, status);
337
+ ASSERT_OR_PRINT(ret, status);
338
+ if (expect.len < got.len) {
339
+ /* Some NIST CAVP tests expect the output tag to be truncated. */
340
+ got.len = expect.len;
341
+ }
342
+ ASSERT_CMPBYTES(expect.data, expect.len, got.data, got.len);
343
+
344
+ mongocrypt_status_destroy(status);
345
+ _mongocrypt_buffer_cleanup(&got);
346
+ _mongocrypt_buffer_cleanup(&expect);
347
+ _mongocrypt_buffer_cleanup(&input);
348
+ _mongocrypt_buffer_cleanup(&key);
349
+
350
+ printf("End test '%s'.\n", test->testname);
351
+ }
352
+
353
+ mongocrypt_destroy(crypt);
416
354
  }
417
355
 
418
- static bool
419
- _hook_hmac_sha_256 (void *ctx,
420
- mongocrypt_binary_t *key,
421
- mongocrypt_binary_t *in,
422
- mongocrypt_binary_t *out,
423
- mongocrypt_status_t *status)
424
- {
425
- const uint8_t *data_to_copy = (const uint8_t *) ctx;
426
- uint8_t *outdata = mongocrypt_binary_data (out);
427
- uint32_t outlen = mongocrypt_binary_len (out);
428
-
429
- ASSERT_CMPINT ((int) outlen, ==, 32);
430
- memcpy (outdata, data_to_copy, outlen);
431
- return true;
356
+ static bool _hook_hmac_sha_256(void *ctx,
357
+ mongocrypt_binary_t *key,
358
+ mongocrypt_binary_t *in,
359
+ mongocrypt_binary_t *out,
360
+ mongocrypt_status_t *status) {
361
+ const uint8_t *data_to_copy = (const uint8_t *)ctx;
362
+ uint8_t *outdata = mongocrypt_binary_data(out);
363
+ uint32_t outlen = mongocrypt_binary_len(out);
364
+
365
+ ASSERT_CMPINT((int)outlen, ==, 32);
366
+ memcpy(outdata, data_to_copy, outlen);
367
+ return true;
432
368
  }
433
369
 
434
- static void
435
- _test_mongocrypt_hmac_sha_256_hook (_mongocrypt_tester_t *tester)
436
- {
437
- mongocrypt_t *crypt;
438
- _mongocrypt_crypto_t crypto = {0};
439
- _mongocrypt_buffer_t key = {0};
440
- _mongocrypt_buffer_t in = {0};
441
- _mongocrypt_buffer_t expect;
442
- _mongocrypt_buffer_t got;
443
- mongocrypt_status_t *status;
444
-
445
- /* Create a mongocrypt_t to call _native_crypto_init(). */
446
- crypt = mongocrypt_new ();
447
-
448
- status = mongocrypt_status_new ();
449
- _mongocrypt_buffer_resize (&key, MONGOCRYPT_MAC_KEY_LEN);
450
- _mongocrypt_buffer_copy_from_hex (&expect,
370
+ static void _test_mongocrypt_hmac_sha_256_hook(_mongocrypt_tester_t *tester) {
371
+ mongocrypt_t *crypt;
372
+ _mongocrypt_crypto_t crypto = {0};
373
+ _mongocrypt_buffer_t key = {0};
374
+ _mongocrypt_buffer_t in = {0};
375
+ _mongocrypt_buffer_t expect;
376
+ _mongocrypt_buffer_t got;
377
+ mongocrypt_status_t *status;
378
+
379
+ /* Create a mongocrypt_t to call _native_crypto_init(). */
380
+ crypt = mongocrypt_new();
381
+
382
+ status = mongocrypt_status_new();
383
+ _mongocrypt_buffer_resize(&key, MONGOCRYPT_MAC_KEY_LEN);
384
+ _mongocrypt_buffer_copy_from_hex(&expect,
451
385
  "000102030405060708090A0B0C0D0E0F"
452
386
  "101112131415161718191A1B1C1D1E1F");
453
- _mongocrypt_buffer_init (&got);
454
- _mongocrypt_buffer_resize (&got, MONGOCRYPT_HMAC_SHA256_LEN);
455
-
456
- crypto.hooks_enabled = true;
457
- crypto.hmac_sha_256 = _hook_hmac_sha_256;
458
- crypto.ctx = expect.data;
459
-
460
- ASSERT_OR_PRINT (_mongocrypt_hmac_sha_256 (&crypto, &key, &in, &got, status),
461
- status);
387
+ _mongocrypt_buffer_init(&got);
388
+ _mongocrypt_buffer_resize(&got, MONGOCRYPT_HMAC_SHA256_LEN);
462
389
 
463
- ASSERT_CMPBYTES (expect.data, expect.len, got.data, got.len);
390
+ crypto.hooks_enabled = true;
391
+ crypto.hmac_sha_256 = _hook_hmac_sha_256;
392
+ crypto.ctx = expect.data;
464
393
 
465
- _mongocrypt_buffer_cleanup (&got);
466
- _mongocrypt_buffer_cleanup (&expect);
467
- _mongocrypt_buffer_cleanup (&key);
468
- mongocrypt_status_destroy (status);
469
- mongocrypt_destroy (crypt);
470
- }
471
-
472
- typedef struct {
473
- const char *testname;
474
- const char *iv;
475
- const char *associated_data;
476
- /* key is a 96 byte Data Encryption Key (DEK).
477
- * The first 32 bytes are the encryption key. The second 32 bytes are the mac
478
- * key. The last 32 bytes are unused. See [AEAD with
479
- * CTR](https://docs.google.com/document/d/1eCU7R8Kjr-mdyz6eKvhNIDVmhyYQcAaLtTfHeK7a_vE/).
480
- */
481
- const char *key;
482
- const char *plaintext;
483
- const char *ciphertext;
484
- uint32_t bytes_written_expected;
485
- const char *expect_encrypt_error;
486
- } fle2_aead_roundtrip_test_t;
487
-
488
- void
489
- _test_fle2_aead_roundtrip (_mongocrypt_tester_t *tester)
490
- {
491
- mongocrypt_t *crypt;
492
- fle2_aead_roundtrip_test_t tests[] = {
493
- {.testname = "Plaintext is 'test1'",
494
- .iv = "918ab83c8966995dfb528a0020d9bb10",
495
- .associated_data = "99f05406f40d1af74cc737a96c1932fdec90",
496
- .key =
497
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e50ec"
498
- "c9c6c1a6277ad951f729b3cc6446e21b4024345088a0edda82231a46ca9a00000000"
499
- "00000000000000000000000000000000000000000000000000000000",
500
- .plaintext = "74657374310a",
501
- .ciphertext = "918ab83c8966995dfb528a0020d9bb1070cead40b081ee0cbfe7265dd"
502
- "57a84f6c331421b7fe6a9c8375748b46acbed1ec7a1b998387c",
503
- .bytes_written_expected = 54},
504
-
505
- {.testname = "Plaintext is one byte",
506
- .iv = "918ab83c8966995dfb528a0020d9bb10",
507
- .associated_data = "99f05406f40d1af74cc737a96c1932fdec90",
508
- .key =
509
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e50ec"
510
- "c9c6c1a6277ad951f729b3cc6446e21b4024345088a0edda82231a46ca9a00000000"
511
- "00000000000000000000000000000000000000000000000000000000",
512
- .plaintext = "00",
513
- .ciphertext = "918ab83c8966995dfb528a0020d9bb1004b2f319e0ec466bc9d265cbf"
514
- "0ae6b895d4d1db028502bb4e2293780d7196af635",
515
- .bytes_written_expected = 49},
516
- {.testname = "Plaintext is zero bytes",
517
- .iv = "918ab83c8966995dfb528a0020d9bb10",
518
- .associated_data = "99f05406f40d1af74cc737a96c1932fdec90",
519
- .key =
520
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e50ec"
521
- "c9c6c1a6277ad951f729b3cc6446e21b4024345088a0edda82231a46ca9a00000000"
522
- "00000000000000000000000000000000000000000000000000000000",
523
- .plaintext = "",
524
- .ciphertext = "",
525
- .expect_encrypt_error = "input plaintext too small"},
526
- #include "data/fle2-aead.cstructs"
527
- {0}};
528
- fle2_aead_roundtrip_test_t *test;
529
-
530
- if (!_aes_ctr_is_supported_by_os) {
531
- printf ("Common Crypto with no CTR support detected. Skipping.");
532
- return;
533
- }
534
-
535
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
536
-
537
- for (test = tests; test->testname != NULL; test++) {
538
- bool ret;
539
- _mongocrypt_buffer_t iv;
540
- _mongocrypt_buffer_t associated_data;
541
- _mongocrypt_buffer_t key;
542
- _mongocrypt_buffer_t plaintext;
543
- _mongocrypt_buffer_t ciphertext;
544
- _mongocrypt_buffer_t plaintext_got;
545
- _mongocrypt_buffer_t ciphertext_got;
546
- mongocrypt_status_t *status;
547
- uint32_t bytes_written;
548
-
549
- printf ("Begin test '%s'.\n", test->testname);
550
-
551
- _mongocrypt_buffer_copy_from_hex (&iv, test->iv);
552
- _mongocrypt_buffer_copy_from_hex (&associated_data,
553
- test->associated_data);
554
- _mongocrypt_buffer_copy_from_hex (&key, test->key);
555
- _mongocrypt_buffer_copy_from_hex (&plaintext, test->plaintext);
556
- _mongocrypt_buffer_copy_from_hex (&ciphertext, test->ciphertext);
557
- _mongocrypt_buffer_init (&plaintext_got);
558
- if (plaintext.len > 0) {
559
- _mongocrypt_buffer_resize (&plaintext_got, plaintext.len);
560
- }
561
- _mongocrypt_buffer_init (&ciphertext_got);
562
- status = mongocrypt_status_new ();
563
- _mongocrypt_buffer_resize (
564
- &ciphertext_got,
565
- _mongocrypt_fle2aead_calculate_ciphertext_len (plaintext.len, status));
566
-
567
- /* Test encrypt. */
568
- ret = _mongocrypt_fle2aead_do_encryption (crypt->crypto,
569
- &iv,
570
- &associated_data,
571
- &key,
572
- &plaintext,
573
- &ciphertext_got,
574
- &bytes_written,
575
- status);
576
-
577
- if (NULL == test->expect_encrypt_error) {
578
- ASSERT_OR_PRINT (ret, status);
579
- ASSERT_CMPBYTES (ciphertext.data,
580
- ciphertext.len,
581
- ciphertext_got.data,
582
- ciphertext_got.len);
583
- ASSERT_CMPINT ((int) bytes_written, ==, (int) ciphertext.len);
584
-
585
- /* Test decrypt. */
586
- ret = _mongocrypt_fle2aead_do_decryption (crypt->crypto,
587
- &associated_data,
588
- &key,
589
- &ciphertext,
590
- &plaintext_got,
591
- &bytes_written,
592
- status);
593
- ASSERT_OR_PRINT (ret, status);
594
- ASSERT_CMPBYTES (plaintext.data,
595
- plaintext.len,
596
- plaintext_got.data,
597
- plaintext_got.len);
598
- ASSERT_CMPINT ((int) bytes_written, ==, (int) plaintext.len);
599
- } else {
600
- ASSERT_FAILS_STATUS (ret, status, test->expect_encrypt_error);
601
- }
602
-
603
- mongocrypt_status_destroy (status);
604
- _mongocrypt_buffer_cleanup (&ciphertext_got);
605
- _mongocrypt_buffer_cleanup (&plaintext_got);
606
- _mongocrypt_buffer_cleanup (&ciphertext);
607
- _mongocrypt_buffer_cleanup (&plaintext);
608
- _mongocrypt_buffer_cleanup (&iv);
609
- _mongocrypt_buffer_cleanup (&associated_data);
610
- _mongocrypt_buffer_cleanup (&key);
611
-
612
- printf ("End test '%s'.\n", test->testname);
613
- }
614
-
615
- mongocrypt_destroy (crypt);
616
- }
394
+ ASSERT_OR_PRINT(_mongocrypt_hmac_sha_256(&crypto, &key, &in, &got, status), status);
617
395
 
618
- typedef struct {
619
- const char *testname;
620
- const char *associated_data;
621
- /* key is a 96 byte Data Encryption Key (DEK).
622
- * The first 32 bytes are the encryption key. The second 32 bytes are the mac
623
- * key. The last 32 bytes are unused. See [AEAD with
624
- * CTR](https://docs.google.com/document/d/1eCU7R8Kjr-mdyz6eKvhNIDVmhyYQcAaLtTfHeK7a_vE/).
625
- */
626
- const char *key;
627
- const char *plaintext;
628
- const char *ciphertext;
629
- uint32_t bytes_written_expected;
630
- const char *expect_error;
631
- } fle2_aead_decrypt_test_t;
632
-
633
- void
634
- _test_fle2_aead_decrypt (_mongocrypt_tester_t *tester)
635
- {
636
- mongocrypt_t *crypt;
637
- fle2_aead_decrypt_test_t tests[] = {
638
- {.testname = "Mismatched HMAC",
639
- .associated_data = "99f05406f40d1af74cc737a96c1932fdec90",
640
- .key =
641
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e50ec"
642
- "c9c6c1a6277ad951f729b3cc6446e21b4024345088a0edda82231a46ca9a00000000"
643
- "00000000000000000000000000000000000000000000000000000000",
644
- .plaintext = "74657374310a",
645
- .ciphertext = "918ab83c8966995dfb528a0020d9bb1070cead40b081ee0cbfe7265dd"
646
- "57a84f6c331421b7fe6a9c8375748b46acbed1ec7a1b9983800",
647
- .expect_error = "decryption error"},
648
- {.testname = "Ciphertext too small",
649
- .associated_data = "99f05406f40d1af74cc737a96c1932fdec90",
650
- .key =
651
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e50ec"
652
- "c9c6c1a6277ad951f729b3cc6446e21b4024345088a0edda82231a46ca9a00000000"
653
- "00000000000000000000000000000000000000000000000000000000",
654
- .plaintext = "",
655
- .ciphertext = "00",
656
- .expect_error = "input ciphertext too small"},
657
- {.testname = "Ciphertext symmetric cipher output is 0 bytes",
658
- .associated_data = "99f05406f40d1af74cc737a96c1932fdec90",
659
- .key =
660
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e50ec"
661
- "c9c6c1a6277ad951f729b3cc6446e21b4024345088a0edda82231a46ca9a00000000"
662
- "00000000000000000000000000000000000000000000000000000000",
663
- .plaintext = "",
664
- .ciphertext = "74c1b6102bbcb96436795ccbf2703af61703e0e33de37f148490c7ed7"
665
- "989f31720c4ed6a24ecc01cc3622f90ed2b5500",
666
- .expect_error = "input ciphertext too small"},
667
- {0}};
668
- fle2_aead_decrypt_test_t *test;
669
-
670
- if (!_aes_ctr_is_supported_by_os) {
671
- printf ("Common Crypto with no CTR support detected. Skipping.");
672
- return;
673
- }
674
-
675
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
676
-
677
- for (test = tests; test->testname != NULL; test++) {
678
- bool ret;
679
- _mongocrypt_buffer_t associated_data;
680
- _mongocrypt_buffer_t key;
681
- _mongocrypt_buffer_t plaintext;
682
- _mongocrypt_buffer_t ciphertext;
683
- _mongocrypt_buffer_t plaintext_got;
684
- mongocrypt_status_t *status;
685
- uint32_t bytes_written;
686
-
687
- printf ("Begin test '%s'.\n", test->testname);
688
-
689
- _mongocrypt_buffer_copy_from_hex (&associated_data,
690
- test->associated_data);
691
- _mongocrypt_buffer_copy_from_hex (&key, test->key);
692
- _mongocrypt_buffer_copy_from_hex (&plaintext, test->plaintext);
693
- _mongocrypt_buffer_copy_from_hex (&ciphertext, test->ciphertext);
694
- _mongocrypt_buffer_init (&plaintext_got);
695
- if (plaintext.len > 0) {
696
- _mongocrypt_buffer_resize (&plaintext_got, plaintext.len);
697
- }
698
- status = mongocrypt_status_new ();
699
-
700
- ret = _mongocrypt_fle2aead_do_decryption (crypt->crypto,
701
- &associated_data,
702
- &key,
703
- &ciphertext,
704
- &plaintext,
705
- &bytes_written,
706
- status);
707
- if (test->expect_error == NULL) {
708
- ASSERT_OR_PRINT (ret, status);
709
- ASSERT_CMPBYTES (plaintext.data,
710
- plaintext.len,
711
- plaintext_got.data,
712
- plaintext_got.len);
713
- ASSERT_CMPINT ((int) bytes_written, ==, (int) plaintext.len);
714
- } else {
715
- ASSERT_FAILS_STATUS (ret, status, test->expect_error);
716
- }
717
-
718
- mongocrypt_status_destroy (status);
719
- _mongocrypt_buffer_cleanup (&plaintext_got);
720
- _mongocrypt_buffer_cleanup (&ciphertext);
721
- _mongocrypt_buffer_cleanup (&plaintext);
722
- _mongocrypt_buffer_cleanup (&key);
723
- _mongocrypt_buffer_cleanup (&associated_data);
724
-
725
- printf ("End test '%s'.\n", test->testname);
726
- }
727
-
728
- mongocrypt_destroy (crypt);
729
- }
396
+ ASSERT_CMPBYTES(expect.data, expect.len, got.data, got.len);
730
397
 
731
- typedef struct {
732
- const char *testname;
733
- const char *iv;
734
- /* key is a 32 encryption key. */
735
- const char *key;
736
- const char *plaintext;
737
- const char *ciphertext;
738
- uint32_t bytes_written_expected;
739
- const char *expect_encrypt_error;
740
- } fle2_encrypt_roundtrip_test_t;
741
-
742
- void
743
- _test_fle2_roundtrip (_mongocrypt_tester_t *tester)
744
- {
745
- mongocrypt_t *crypt;
746
- fle2_aead_roundtrip_test_t tests[] = {
747
- {.testname = "Plaintext is 'test1'",
748
- .iv = "918ab83c8966995dfb528a0020d9bb10",
749
- .key =
750
- "c0b091fd93dfbb2422e53553f971d8127f3731058ba67f32b1549c53fce4120e",
751
- .plaintext = "7465737431",
752
- .ciphertext = "918ab83c8966995dfb528a0020d9bb1070cead40b0",
753
- .bytes_written_expected = 22},
754
- #include "data/fle2.cstructs"
755
- {0}};
756
- fle2_aead_roundtrip_test_t *test;
757
-
758
- if (!_aes_ctr_is_supported_by_os) {
759
- printf ("Common Crypto with no CTR support detected. Skipping.");
760
- return;
761
- }
762
-
763
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
764
-
765
- for (test = tests; test->testname != NULL; test++) {
766
- bool ret;
767
- _mongocrypt_buffer_t iv;
768
- _mongocrypt_buffer_t key;
769
- _mongocrypt_buffer_t plaintext;
770
- _mongocrypt_buffer_t ciphertext;
771
- _mongocrypt_buffer_t plaintext_got;
772
- _mongocrypt_buffer_t ciphertext_got;
773
- mongocrypt_status_t *const status = mongocrypt_status_new ();
774
- uint32_t bytes_written;
775
-
776
- printf ("Begin test '%s'.\n", test->testname);
777
-
778
- _mongocrypt_buffer_copy_from_hex (&iv, test->iv);
779
- _mongocrypt_buffer_copy_from_hex (&key, test->key);
780
- _mongocrypt_buffer_copy_from_hex (&plaintext, test->plaintext);
781
- _mongocrypt_buffer_copy_from_hex (&ciphertext, test->ciphertext);
782
- _mongocrypt_buffer_init (&plaintext_got);
783
- if (plaintext.len > 0) {
784
- _mongocrypt_buffer_resize (&plaintext_got, plaintext.len);
785
- }
786
- _mongocrypt_buffer_init (&ciphertext_got);
787
- _mongocrypt_buffer_resize (
788
- &ciphertext_got,
789
- _mongocrypt_fle2_calculate_ciphertext_len (plaintext.len, status));
790
-
791
- /* Test encrypt. */
792
- ret = _mongocrypt_fle2_do_encryption (crypt->crypto,
793
- &iv,
794
- &key,
795
- &plaintext,
796
- &ciphertext_got,
797
- &bytes_written,
798
- status);
799
-
800
- if (NULL == test->expect_encrypt_error) {
801
- ASSERT_OR_PRINT (ret, status);
802
- ASSERT_CMPBYTES (ciphertext.data,
803
- ciphertext.len,
804
- ciphertext_got.data,
805
- ciphertext_got.len);
806
- ASSERT_CMPINT ((int) bytes_written, ==, (int) ciphertext.len);
807
-
808
- /* Test decrypt. */
809
- ret = _mongocrypt_fle2_do_decryption (crypt->crypto,
810
- &key,
811
- &ciphertext,
812
- &plaintext_got,
813
- &bytes_written,
814
- status);
815
- ASSERT_OR_PRINT (ret, status);
816
- ASSERT_CMPBYTES (plaintext.data,
817
- plaintext.len,
818
- plaintext_got.data,
819
- plaintext_got.len);
820
- ASSERT_CMPINT ((int) bytes_written, ==, (int) plaintext.len);
821
- } else {
822
- ASSERT_FAILS_STATUS (ret, status, test->expect_encrypt_error);
823
- }
824
-
825
- mongocrypt_status_destroy (status);
826
- _mongocrypt_buffer_cleanup (&ciphertext_got);
827
- _mongocrypt_buffer_cleanup (&plaintext_got);
828
- _mongocrypt_buffer_cleanup (&ciphertext);
829
- _mongocrypt_buffer_cleanup (&plaintext);
830
- _mongocrypt_buffer_cleanup (&iv);
831
- _mongocrypt_buffer_cleanup (&key);
832
-
833
- printf ("End test '%s'.\n", test->testname);
834
- }
835
-
836
- mongocrypt_destroy (crypt);
398
+ _mongocrypt_buffer_cleanup(&got);
399
+ _mongocrypt_buffer_cleanup(&expect);
400
+ _mongocrypt_buffer_cleanup(&key);
401
+ mongocrypt_status_destroy(status);
402
+ mongocrypt_destroy(crypt);
837
403
  }
838
404
 
839
- static void
840
- _test_random_int64 (_mongocrypt_tester_t *tester)
841
- {
842
- bool got0 = false, got1 = false, got2 = false;
843
- int trial;
844
- const int max_trials = 1000;
845
- mongocrypt_t *crypt;
846
- mongocrypt_status_t *status;
847
-
848
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
849
- status = mongocrypt_status_new ();
850
-
851
- for (trial = 0; trial < max_trials; trial++) {
852
- int64_t got;
853
-
854
- ASSERT_OR_PRINT (
855
- _mongocrypt_random_int64 (crypt->crypto, 3, &got, status), status);
856
- switch (got) {
857
- case 0:
858
- got0 = true;
859
- break;
860
- case 1:
861
- got1 = true;
862
- break;
863
- case 2:
864
- got2 = true;
865
- break;
866
- default:
867
- TEST_ERROR (
868
- "Expected random number to be in range [0,3), got: %" PRId64, got);
869
- }
870
- }
871
-
872
- ASSERT (got0);
873
- ASSERT (got1);
874
- ASSERT (got2);
875
-
876
- mongocrypt_status_destroy (status);
877
- mongocrypt_destroy (crypt);
405
+ static void _test_random_int64(_mongocrypt_tester_t *tester) {
406
+ bool got0 = false, got1 = false, got2 = false;
407
+ int trial;
408
+ const int max_trials = 1000;
409
+ mongocrypt_t *crypt;
410
+ mongocrypt_status_t *status;
411
+
412
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
413
+ status = mongocrypt_status_new();
414
+
415
+ for (trial = 0; trial < max_trials; trial++) {
416
+ int64_t got;
417
+
418
+ ASSERT_OR_PRINT(_mongocrypt_random_int64(crypt->crypto, 3, &got, status), status);
419
+ switch (got) {
420
+ case 0: got0 = true; break;
421
+ case 1: got1 = true; break;
422
+ case 2: got2 = true; break;
423
+ default: TEST_ERROR("Expected random number to be in range [0,3), got: %" PRId64, got);
424
+ }
425
+ }
426
+
427
+ ASSERT(got0);
428
+ ASSERT(got1);
429
+ ASSERT(got2);
430
+
431
+ mongocrypt_status_destroy(status);
432
+ mongocrypt_destroy(crypt);
878
433
  }
879
434
 
880
- void
881
- _mongocrypt_tester_install_crypto (_mongocrypt_tester_t *tester)
882
- {
883
- INSTALL_TEST (_test_mcgrew);
884
- INSTALL_TEST (_test_roundtrip);
885
- INSTALL_TEST (_test_native_crypto_aes_256_ctr);
886
- INSTALL_TEST (_test_native_crypto_hmac_sha_256);
887
- INSTALL_TEST_CRYPTO (_test_mongocrypt_hmac_sha_256_hook, CRYPTO_OPTIONAL);
888
- INSTALL_TEST (_test_fle2_aead_roundtrip);
889
- INSTALL_TEST (_test_fle2_aead_decrypt);
890
- INSTALL_TEST (_test_fle2_roundtrip);
891
- INSTALL_TEST (_test_random_int64);
435
+ void _mongocrypt_tester_install_crypto(_mongocrypt_tester_t *tester) {
436
+ INSTALL_TEST(_test_roundtrip);
437
+ INSTALL_TEST(_test_native_crypto_hmac_sha_256);
438
+ INSTALL_TEST_CRYPTO(_test_mongocrypt_hmac_sha_256_hook, CRYPTO_OPTIONAL);
439
+ INSTALL_TEST(_test_random_int64);
892
440
  }