libmongocrypt-helper 1.7.4.0.1001 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (398) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/extconf.rb +2 -2
  4. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  5. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  6. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  7. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  8. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  17. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  62. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  63. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  64. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  65. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  66. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  67. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  71. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  75. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  79. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  80. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  143. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  194. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  196. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  198. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  199. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  314. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  315. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  316. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  318. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  370. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  371. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  373. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  374. data/lib/libmongocrypt_helper/version.rb +2 -2
  375. data/lib/libmongocrypt_helper.rb +2 -2
  376. data.tar.gz.sig +0 -0
  377. metadata +154 -26
  378. metadata.gz.sig +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  380. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  381. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  382. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  383. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  384. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  392. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  393. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  394. /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
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /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
  397. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  398. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -15,903 +15,759 @@
15
15
  */
16
16
 
17
17
  #include "mongocrypt-config.h"
18
- #include "mongocrypt-private.h"
19
18
  #include "mongocrypt-crypto-private.h"
19
+ #include "mongocrypt-private.h"
20
20
 
21
21
  #include "test-mongocrypt.h"
22
22
 
23
23
  #define IV_HEX "1F572A1B84EC8F99B7915AA2A2AEA2F4"
24
- #define HMAC_HEX \
25
- "60676DE9FD305FD2C0815763C422687270DA2416D94A917B276E9DCBB13F412F" \
26
- "92FA403AA8AE172BD2E4729ED352793795EE588A2977C9C1F218D2AAD779C997"
24
+ #define HMAC_HEX \
25
+ "60676DE9FD305FD2C0815763C422687270DA2416D94A917B276E9DCBB13F412F" \
26
+ "92FA403AA8AE172BD2E4729ED352793795EE588A2977C9C1F218D2AAD779C997"
27
27
  /* only the first 32 bytes are appended. */
28
- #define HMAC_HEX_TAG \
29
- "60676DE9FD305FD2C0815763C422687270DA2416D94A917B276E9DCBB13F412F"
30
-
31
- #define HMAC_KEY_HEX \
32
- "CCD3836C8F24AC5FAAFAAA630C5C6C5D210FD03934EA1440CD67E0DCDE3F8EA6"
33
- #define ENCRYPTION_KEY_HEX \
34
- "E1D1727BAF970E01181C0868CB9D3E574B47AC09771FF30FE2D093B0950C7DAF"
35
- #define IV_KEY_HEX \
36
- "0A9328FCB6405ABDF5B4BFEC243FE9CF503CD4F24360872B75F08A2A3961802B"
28
+ #define HMAC_HEX_TAG "60676DE9FD305FD2C0815763C422687270DA2416D94A917B276E9DCBB13F412F"
29
+
30
+ #define HMAC_KEY_HEX "CCD3836C8F24AC5FAAFAAA630C5C6C5D210FD03934EA1440CD67E0DCDE3F8EA6"
31
+ #define ENCRYPTION_KEY_HEX "E1D1727BAF970E01181C0868CB9D3E574B47AC09771FF30FE2D093B0950C7DAF"
32
+ #define IV_KEY_HEX "0A9328FCB6405ABDF5B4BFEC243FE9CF503CD4F24360872B75F08A2A3961802B"
37
33
  /* full 96 byte key consists of three "sub" keys */
38
34
  #define KEY_HEX HMAC_KEY_HEX ENCRYPTION_KEY_HEX IV_KEY_HEX
39
- #define HASH_HEX \
40
- "489EC3238378DC624C74B8CC4598ACED2B7EA5DE5C5F7602D8761BAE92FD8ABE"
41
- #define RANDOM_HEX \
42
- "670ACBB44D4E04A279CC0B95D217493205A038C50F537F452C59EFF6541D0026670ACBB44" \
43
- "D4E04A279CC0B95D217493205A038C50F537F452C59EFF6541D0026670ACBB44D4E04A279" \
44
- "CC0B95D217493205A038C50F537F452C59EFF6541D0026"
35
+ #define HASH_HEX "489EC3238378DC624C74B8CC4598ACED2B7EA5DE5C5F7602D8761BAE92FD8ABE"
36
+ #define RANDOM_HEX \
37
+ "670ACBB44D4E04A279CC0B95D217493205A038C50F537F452C59EFF6541D0026670ACBB44" \
38
+ "D4E04A279CC0B95D217493205A038C50F537F452C59EFF6541D0026670ACBB44D4E04A279" \
39
+ "CC0B95D217493205A038C50F537F452C59EFF6541D0026"
45
40
 
46
41
  /* a document containing the history of calls */
47
42
  static bson_string_t *call_history;
48
43
 
49
- static void
50
- _append_bin (const char *name, mongocrypt_binary_t *bin)
51
- {
52
- _mongocrypt_buffer_t tmp;
53
- char *hex;
54
-
55
- _mongocrypt_buffer_from_binary (&tmp, bin);
56
- hex = _mongocrypt_buffer_to_hex (&tmp);
57
- bson_string_append_printf (call_history, "%s:%s\n", name, hex);
58
- bson_free (hex);
59
- _mongocrypt_buffer_cleanup (&tmp);
44
+ static void _append_bin(const char *name, mongocrypt_binary_t *bin) {
45
+ _mongocrypt_buffer_t tmp;
46
+ char *hex;
47
+
48
+ _mongocrypt_buffer_from_binary(&tmp, bin);
49
+ hex = _mongocrypt_buffer_to_hex(&tmp);
50
+ bson_string_append_printf(call_history, "%s:%s\n", name, hex);
51
+ bson_free(hex);
52
+ _mongocrypt_buffer_cleanup(&tmp);
60
53
  }
61
54
 
62
- static bool
63
- _mock_aes_256_xxx_encrypt (void *ctx,
64
- mongocrypt_binary_t *key,
65
- mongocrypt_binary_t *iv,
66
- mongocrypt_binary_t *in,
67
- mongocrypt_binary_t *out,
68
- uint32_t *bytes_written,
69
- mongocrypt_status_t *status)
70
- {
71
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
72
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
73
- _append_bin ("key", key);
74
- if (NULL != iv) {
75
- _append_bin ("iv", iv);
76
- }
77
- _append_bin ("in", in);
78
- /* append it directly, don't encrypt. */
79
- memcpy (out->data + *bytes_written, in->data, in->len);
80
- *bytes_written += in->len;
81
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
82
- if (0 == strcmp ((char *) ctx, "error_on:aes_256_cbc_encrypt") ||
83
- 0 == strcmp ((char *) ctx, "error_on:aes_256_ctr_encrypt") ||
84
- 0 == strcmp ((char *) ctx, "error_on:aes_256_ecb_encrypt")) {
85
- mongocrypt_status_set (
86
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
87
- return false;
88
- }
89
- return true;
55
+ static bool _mock_aes_256_xxx_encrypt(void *ctx,
56
+ mongocrypt_binary_t *key,
57
+ mongocrypt_binary_t *iv,
58
+ mongocrypt_binary_t *in,
59
+ mongocrypt_binary_t *out,
60
+ uint32_t *bytes_written,
61
+ mongocrypt_status_t *status) {
62
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
63
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
64
+ _append_bin("key", key);
65
+ if (NULL != iv) {
66
+ _append_bin("iv", iv);
67
+ }
68
+ _append_bin("in", in);
69
+ /* append it directly, don't encrypt. */
70
+ memcpy(out->data + *bytes_written, in->data, in->len);
71
+ *bytes_written += in->len;
72
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
73
+ if (0 == strcmp((char *)ctx, "error_on:aes_256_cbc_encrypt")
74
+ || 0 == strcmp((char *)ctx, "error_on:aes_256_ctr_encrypt")
75
+ || 0 == strcmp((char *)ctx, "error_on:aes_256_ecb_encrypt")) {
76
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
77
+ return false;
78
+ }
79
+ return true;
90
80
  }
91
81
 
92
- static bool
93
- _mock_aes_256_xxx_decrypt (void *ctx,
94
- mongocrypt_binary_t *key,
95
- mongocrypt_binary_t *iv,
96
- mongocrypt_binary_t *in,
97
- mongocrypt_binary_t *out,
98
- uint32_t *bytes_written,
99
- mongocrypt_status_t *status)
100
- {
101
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
102
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
103
- _append_bin ("key", key);
104
- _append_bin ("iv", iv);
105
- _append_bin ("in", in);
106
- /* append it directly, don't decrypt. */
107
- memcpy (out->data + *bytes_written, in->data, in->len);
108
- *bytes_written += in->len;
109
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
110
- if (0 == strcmp ((char *) ctx, "error_on:aes_256_cbc_decrypt") ||
111
- 0 == strcmp ((char *) ctx, "error_on:aes_256_ctr_decrypt")) {
112
- mongocrypt_status_set (
113
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
114
- return false;
115
- }
116
- return true;
82
+ static bool _mock_aes_256_xxx_decrypt(void *ctx,
83
+ mongocrypt_binary_t *key,
84
+ mongocrypt_binary_t *iv,
85
+ mongocrypt_binary_t *in,
86
+ mongocrypt_binary_t *out,
87
+ uint32_t *bytes_written,
88
+ mongocrypt_status_t *status) {
89
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
90
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
91
+ _append_bin("key", key);
92
+ _append_bin("iv", iv);
93
+ _append_bin("in", in);
94
+ /* append it directly, don't decrypt. */
95
+ memcpy(out->data + *bytes_written, in->data, in->len);
96
+ *bytes_written += in->len;
97
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
98
+ if (0 == strcmp((char *)ctx, "error_on:aes_256_cbc_decrypt")
99
+ || 0 == strcmp((char *)ctx, "error_on:aes_256_ctr_decrypt")) {
100
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
101
+ return false;
102
+ }
103
+ return true;
117
104
  }
118
105
 
119
- bool
120
- _hmac_sha_512 (void *ctx,
121
- mongocrypt_binary_t *key,
122
- mongocrypt_binary_t *in,
123
- mongocrypt_binary_t *out,
124
- mongocrypt_status_t *status)
125
- {
126
- _mongocrypt_buffer_t tmp;
127
-
128
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
129
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
130
- _append_bin ("key", key);
131
- _append_bin ("in", in);
132
-
133
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
134
-
135
- _mongocrypt_buffer_copy_from_hex (&tmp, HMAC_HEX);
136
- memcpy (out->data, tmp.data, tmp.len);
137
- _mongocrypt_buffer_cleanup (&tmp);
138
- if (0 == strcmp ((char *) ctx, "error_on:hmac_sha512")) {
139
- mongocrypt_status_set (
140
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
141
- return false;
142
- }
143
- return true;
106
+ bool _hmac_sha_512(void *ctx,
107
+ mongocrypt_binary_t *key,
108
+ mongocrypt_binary_t *in,
109
+ mongocrypt_binary_t *out,
110
+ mongocrypt_status_t *status) {
111
+ _mongocrypt_buffer_t tmp;
112
+
113
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
114
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
115
+ _append_bin("key", key);
116
+ _append_bin("in", in);
117
+
118
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
119
+
120
+ _mongocrypt_buffer_copy_from_hex(&tmp, HMAC_HEX);
121
+ memcpy(out->data, tmp.data, tmp.len);
122
+ _mongocrypt_buffer_cleanup(&tmp);
123
+ if (0 == strcmp((char *)ctx, "error_on:hmac_sha512")) {
124
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
125
+ return false;
126
+ }
127
+ return true;
144
128
  }
145
129
 
146
- bool
147
- _hmac_sha_256 (void *ctx,
148
- mongocrypt_binary_t *key,
149
- mongocrypt_binary_t *in,
150
- mongocrypt_binary_t *out,
151
- mongocrypt_status_t *status)
152
- {
153
- _mongocrypt_buffer_t tmp;
154
-
155
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
156
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
157
- _append_bin ("key", key);
158
- _append_bin ("in", in);
159
-
160
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
161
-
162
- _mongocrypt_buffer_copy_from_hex (&tmp, HASH_HEX);
163
- memcpy (out->data, tmp.data, tmp.len);
164
- _mongocrypt_buffer_cleanup (&tmp);
165
- if (0 == strcmp ((char *) ctx, "error_on:hmac_sha256")) {
166
- mongocrypt_status_set (
167
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
168
- return false;
169
- }
170
- return true;
130
+ bool _hmac_sha_256(void *ctx,
131
+ mongocrypt_binary_t *key,
132
+ mongocrypt_binary_t *in,
133
+ mongocrypt_binary_t *out,
134
+ mongocrypt_status_t *status) {
135
+ _mongocrypt_buffer_t tmp;
136
+
137
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
138
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
139
+ _append_bin("key", key);
140
+ _append_bin("in", in);
141
+
142
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
143
+
144
+ _mongocrypt_buffer_copy_from_hex(&tmp, HASH_HEX);
145
+ memcpy(out->data, tmp.data, tmp.len);
146
+ _mongocrypt_buffer_cleanup(&tmp);
147
+ if (0 == strcmp((char *)ctx, "error_on:hmac_sha256")) {
148
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
149
+ return false;
150
+ }
151
+ return true;
171
152
  }
172
153
 
173
- bool
174
- _sha_256 (void *ctx,
175
- mongocrypt_binary_t *in,
176
- mongocrypt_binary_t *out,
177
- mongocrypt_status_t *status)
178
- {
179
- _mongocrypt_buffer_t tmp;
180
-
181
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
182
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
183
- _append_bin ("in", in);
184
-
185
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
186
-
187
- _mongocrypt_buffer_copy_from_hex (&tmp, HASH_HEX);
188
- memcpy (out->data, tmp.data, tmp.len);
189
- _mongocrypt_buffer_cleanup (&tmp);
190
- if (0 == strcmp ((char *) ctx, "error_on:sha256")) {
191
- mongocrypt_status_set (
192
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
193
- return false;
194
- }
195
- return true;
154
+ bool _sha_256(void *ctx, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) {
155
+ _mongocrypt_buffer_t tmp;
156
+
157
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
158
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
159
+ _append_bin("in", in);
160
+
161
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
162
+
163
+ _mongocrypt_buffer_copy_from_hex(&tmp, HASH_HEX);
164
+ memcpy(out->data, tmp.data, tmp.len);
165
+ _mongocrypt_buffer_cleanup(&tmp);
166
+ if (0 == strcmp((char *)ctx, "error_on:sha256")) {
167
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
168
+ return false;
169
+ }
170
+ return true;
196
171
  }
197
172
 
198
- bool
199
- _random (void *ctx,
200
- mongocrypt_binary_t *out,
201
- uint32_t count,
202
- mongocrypt_status_t *status)
203
- {
204
- /* only have 32 bytes of random test data. */
205
- BSON_ASSERT (count <= 96);
206
-
207
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
208
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
209
- bson_string_append_printf (call_history, "count:%d\n", (int) count);
210
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
211
-
212
- _mongocrypt_buffer_t tmp;
213
- _mongocrypt_buffer_copy_from_hex (&tmp, RANDOM_HEX);
214
- memcpy (out->data, tmp.data, count);
215
- _mongocrypt_buffer_cleanup (&tmp);
216
- if (0 == strcmp ((char *) ctx, "error_on:random")) {
217
- mongocrypt_status_set (
218
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
219
- return false;
220
- }
221
- return true;
173
+ bool _random(void *ctx, mongocrypt_binary_t *out, uint32_t count, mongocrypt_status_t *status) {
174
+ /* only have 32 bytes of random test data. */
175
+ BSON_ASSERT(count <= 96);
176
+
177
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
178
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
179
+ bson_string_append_printf(call_history, "count:%d\n", (int)count);
180
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
181
+
182
+ _mongocrypt_buffer_t tmp;
183
+ _mongocrypt_buffer_copy_from_hex(&tmp, RANDOM_HEX);
184
+ memcpy(out->data, tmp.data, count);
185
+ _mongocrypt_buffer_cleanup(&tmp);
186
+ if (0 == strcmp((char *)ctx, "error_on:random")) {
187
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
188
+ return false;
189
+ }
190
+ return true;
222
191
  }
223
192
 
224
- bool
225
- _sign_rsaes_pkcs1_v1_5 (void *ctx,
226
- mongocrypt_binary_t *key,
227
- mongocrypt_binary_t *in,
228
- mongocrypt_binary_t *out,
229
- mongocrypt_status_t *status)
230
- {
231
- _mongocrypt_buffer_t tmp;
232
-
233
- BSON_ASSERT (0 == strncmp ("error_on:", (char *) ctx, strlen ("error_on:")));
234
- bson_string_append_printf (call_history, "call:%s\n", BSON_FUNC);
235
- _append_bin ("key", key);
236
- _append_bin ("in", in);
237
-
238
- bson_string_append_printf (call_history, "ret:%s\n", BSON_FUNC);
239
- memset (out->data, 0, out->len);
240
-
241
- _mongocrypt_buffer_copy_from_hex (&tmp, HASH_HEX);
242
- memcpy (out->data, tmp.data, tmp.len);
243
- _mongocrypt_buffer_cleanup (&tmp);
244
- if (0 == strcmp ((char *) ctx, "error_on:sign_rsaes_pkcs1_v1_5")) {
245
- mongocrypt_status_set (
246
- status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *) ctx, -1);
247
- return false;
248
- }
249
- return true;
193
+ bool _sign_rsaes_pkcs1_v1_5(void *ctx,
194
+ mongocrypt_binary_t *key,
195
+ mongocrypt_binary_t *in,
196
+ mongocrypt_binary_t *out,
197
+ mongocrypt_status_t *status) {
198
+ _mongocrypt_buffer_t tmp;
199
+
200
+ BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:")));
201
+ bson_string_append_printf(call_history, "call:%s\n", BSON_FUNC);
202
+ _append_bin("key", key);
203
+ _append_bin("in", in);
204
+
205
+ bson_string_append_printf(call_history, "ret:%s\n", BSON_FUNC);
206
+ memset(out->data, 0, out->len);
207
+
208
+ _mongocrypt_buffer_copy_from_hex(&tmp, HASH_HEX);
209
+ memcpy(out->data, tmp.data, tmp.len);
210
+ _mongocrypt_buffer_cleanup(&tmp);
211
+ if (0 == strcmp((char *)ctx, "error_on:sign_rsaes_pkcs1_v1_5")) {
212
+ mongocrypt_status_set(status, MONGOCRYPT_STATUS_ERROR_CLIENT, 1, (char *)ctx, -1);
213
+ return false;
214
+ }
215
+ return true;
250
216
  }
251
217
 
252
218
  static mongocrypt_t *
253
- _create_mongocrypt_and_hooks (_mongocrypt_tester_t *tester,
254
- const char *error_on,
255
- bool ctr_hook,
256
- bool ecb_hook)
257
- {
258
- bool ret;
259
-
260
- mongocrypt_t *crypt = mongocrypt_new ();
261
- ASSERT_OK (
262
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1),
263
- crypt);
264
- ASSERT_OK (
265
- mongocrypt_setopt_kms_providers (
266
- crypt,
267
- TEST_BSON ("{'gcp': { 'email': 'test', 'privateKey': 'AAAA'}}")),
268
- crypt);
269
- ret = mongocrypt_setopt_crypto_hooks (crypt,
219
+ _create_mongocrypt_and_hooks(_mongocrypt_tester_t *tester, const char *error_on, bool ctr_hook, bool ecb_hook) {
220
+ bool ret;
221
+
222
+ mongocrypt_t *crypt = mongocrypt_new();
223
+ ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1), crypt);
224
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'gcp': { 'email': 'test', 'privateKey': 'AAAA'}}")),
225
+ crypt);
226
+ ret = mongocrypt_setopt_crypto_hooks(crypt,
270
227
  _mock_aes_256_xxx_encrypt,
271
228
  _mock_aes_256_xxx_decrypt,
272
229
  _random,
273
230
  _hmac_sha_512,
274
231
  _hmac_sha_256,
275
232
  _sha_256,
276
- (void *) error_on);
277
- ASSERT_OK (ret, crypt);
278
- ret = mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5 (
279
- crypt, _sign_rsaes_pkcs1_v1_5, (void *) error_on);
280
- ASSERT_OK (ret, crypt);
281
- if (ctr_hook) {
282
- ret = mongocrypt_setopt_aes_256_ctr (crypt,
283
- _mock_aes_256_xxx_encrypt,
284
- _mock_aes_256_xxx_decrypt,
285
- (void *) error_on);
286
- ASSERT_OK (ret, crypt);
287
- }
288
- if (ecb_hook) {
289
- ret = mongocrypt_setopt_aes_256_ecb (
290
- crypt, _mock_aes_256_xxx_encrypt, (void *) error_on);
291
- ASSERT_OK (ret, crypt);
292
- }
293
- ASSERT_OK (mongocrypt_init (crypt), crypt);
294
- return crypt;
233
+ (void *)error_on);
234
+ ASSERT_OK(ret, crypt);
235
+ ret = mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(crypt, _sign_rsaes_pkcs1_v1_5, (void *)error_on);
236
+ ASSERT_OK(ret, crypt);
237
+ if (ctr_hook) {
238
+ ret = mongocrypt_setopt_aes_256_ctr(crypt,
239
+ _mock_aes_256_xxx_encrypt,
240
+ _mock_aes_256_xxx_decrypt,
241
+ (void *)error_on);
242
+ ASSERT_OK(ret, crypt);
243
+ }
244
+ if (ecb_hook) {
245
+ ret = mongocrypt_setopt_aes_256_ecb(crypt, _mock_aes_256_xxx_encrypt, (void *)error_on);
246
+ ASSERT_OK(ret, crypt);
247
+ }
248
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
249
+ return crypt;
295
250
  }
296
251
 
297
- static mongocrypt_t *
298
- _create_mongocrypt (_mongocrypt_tester_t *tester, const char *error_on)
299
- {
300
- return _create_mongocrypt_and_hooks (tester, error_on, false, false);
252
+ static mongocrypt_t *_create_mongocrypt(_mongocrypt_tester_t *tester, const char *error_on) {
253
+ return _create_mongocrypt_and_hooks(tester, error_on, false, false);
301
254
  }
302
255
 
303
256
  static void
304
- _test_crypto_hooks_encryption_helper (_mongocrypt_tester_t *tester,
305
- const char *error_on,
306
- bool ctr_hook,
307
- bool ecb_hook)
308
- {
309
- mongocrypt_t *crypt;
310
- bool ret;
311
- uint32_t bytes_written;
312
- mongocrypt_status_t *status;
313
- _mongocrypt_buffer_t iv, associated_data, key, plaintext, ciphertext;
314
- const char *expected_call_history =
315
- "call:_mock_aes_256_xxx_encrypt\n"
316
- "key:" ENCRYPTION_KEY_HEX "\n"
317
- "iv:" IV_HEX "\n"
318
- "in:BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E\n"
319
- "ret:_mock_aes_256_xxx_encrypt\n"
320
- "call:_hmac_sha_512\n"
321
- "key:CCD3836C8F24AC5FAAFAAA630C5C6C5D210FD03934EA1440CD67E0DCDE3F8EA6\n"
322
- "in:AAAA" IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E0000000000000010\n"
323
- "ret:_hmac_sha_512\n";
324
-
325
- status = mongocrypt_status_new ();
326
- crypt = _create_mongocrypt_and_hooks (tester, error_on, ctr_hook, ecb_hook);
327
-
328
- _mongocrypt_buffer_copy_from_hex (&iv, IV_HEX);
329
- _mongocrypt_buffer_copy_from_hex (&associated_data, "AAAA");
330
- _mongocrypt_buffer_copy_from_hex (&plaintext, "BBBB");
331
-
332
- call_history = bson_string_new (NULL);
333
-
334
- if (ctr_hook || ecb_hook) {
335
- _mongocrypt_buffer_copy_from_hex (&key, ENCRYPTION_KEY_HEX);
336
- _mongocrypt_buffer_init (&ciphertext);
337
- _mongocrypt_buffer_resize (
338
- &ciphertext,
339
- _mongocrypt_fle2_calculate_ciphertext_len (plaintext.len, status));
340
- ret = _mongocrypt_fle2_do_encryption (crypt->crypto,
341
- &iv,
342
- &key,
343
- &plaintext,
344
- &ciphertext,
345
- &bytes_written,
346
- status);
347
- } else {
348
- _mongocrypt_buffer_copy_from_hex (&key, KEY_HEX);
349
- _mongocrypt_buffer_init (&ciphertext);
350
- _mongocrypt_buffer_resize (
351
- &ciphertext,
352
- _mongocrypt_calculate_ciphertext_len (plaintext.len, status));
353
- ret = _mongocrypt_do_encryption (crypt->crypto,
354
- &iv,
355
- &associated_data,
356
- &key,
357
- &plaintext,
358
- &ciphertext,
359
- &bytes_written,
360
- status);
361
- }
362
-
363
- if (0 == strcmp (error_on, "error_on:none")) {
364
- ASSERT_OK_STATUS (ret, status);
365
- ciphertext.len = bytes_written;
366
-
367
- /* Check the full trace. */
368
- ASSERT_STREQUAL (call_history->str, expected_call_history);
369
-
370
- /* Check the structure of the ciphertext */
371
- BSON_ASSERT (
372
- 0 == _mongocrypt_buffer_cmp_hex (
373
- &ciphertext,
374
- IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E" /* the "encrypted"
375
- block which is
376
- really plaintext.
377
- BBBB + padding. */
378
- HMAC_HEX_TAG));
379
- } else {
380
- ASSERT_FAILS_STATUS (ret, status, error_on);
381
- }
382
-
383
-
384
- _mongocrypt_buffer_cleanup (&key);
385
- _mongocrypt_buffer_cleanup (&iv);
386
- _mongocrypt_buffer_cleanup (&associated_data);
387
- _mongocrypt_buffer_cleanup (&plaintext);
388
- _mongocrypt_buffer_cleanup (&ciphertext);
389
- mongocrypt_status_destroy (status);
390
- mongocrypt_destroy (crypt);
391
- bson_string_free (call_history, true);
257
+ _test_crypto_hooks_encryption_helper(_mongocrypt_tester_t *tester, const char *error_on, bool ctr_hook, bool ecb_hook) {
258
+ mongocrypt_t *crypt;
259
+ bool ret;
260
+ uint32_t bytes_written;
261
+ mongocrypt_status_t *status;
262
+ _mongocrypt_buffer_t iv, associated_data, key, plaintext, ciphertext;
263
+ const char *expected_call_history = "call:_mock_aes_256_xxx_encrypt\n"
264
+ "key:" ENCRYPTION_KEY_HEX "\n"
265
+ "iv:" IV_HEX "\n"
266
+ "in:BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E\n"
267
+ "ret:_mock_aes_256_xxx_encrypt\n"
268
+ "call:_hmac_sha_512\n"
269
+ "key:CCD3836C8F24AC5FAAFAAA630C5C6C5D210FD03934EA1440CD67E0DCDE3F8EA6\n"
270
+ "in:AAAA" IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E0000000000000010\n"
271
+ "ret:_hmac_sha_512\n";
272
+
273
+ status = mongocrypt_status_new();
274
+ crypt = _create_mongocrypt_and_hooks(tester, error_on, ctr_hook, ecb_hook);
275
+
276
+ _mongocrypt_buffer_copy_from_hex(&iv, IV_HEX);
277
+ _mongocrypt_buffer_copy_from_hex(&associated_data, "AAAA");
278
+ _mongocrypt_buffer_copy_from_hex(&plaintext, "BBBB");
279
+
280
+ call_history = bson_string_new(NULL);
281
+
282
+ if (ctr_hook || ecb_hook) {
283
+ const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm();
284
+ _mongocrypt_buffer_copy_from_hex(&key, ENCRYPTION_KEY_HEX);
285
+ _mongocrypt_buffer_init(&ciphertext);
286
+ _mongocrypt_buffer_resize(&ciphertext, fle2alg->get_ciphertext_len(plaintext.len, status));
287
+ ret =
288
+ fle2alg
289
+ ->do_encrypt(crypt->crypto, &iv, NULL /* aad */, &key, &plaintext, &ciphertext, &bytes_written, status);
290
+ } else {
291
+ const _mongocrypt_value_encryption_algorithm_t *fle1alg = _mcFLE1Algorithm();
292
+ _mongocrypt_buffer_copy_from_hex(&key, KEY_HEX);
293
+ _mongocrypt_buffer_init(&ciphertext);
294
+ _mongocrypt_buffer_resize(&ciphertext, fle1alg->get_ciphertext_len(plaintext.len, status));
295
+ ret = fle1alg->do_encrypt(crypt->crypto,
296
+ &iv,
297
+ &associated_data,
298
+ &key,
299
+ &plaintext,
300
+ &ciphertext,
301
+ &bytes_written,
302
+ status);
303
+ }
304
+
305
+ if (0 == strcmp(error_on, "error_on:none")) {
306
+ ASSERT_OK_STATUS(ret, status);
307
+ ciphertext.len = bytes_written;
308
+
309
+ /* Check the full trace. */
310
+ ASSERT_STREQUAL(call_history->str, expected_call_history);
311
+
312
+ /* Check the structure of the ciphertext */
313
+ BSON_ASSERT(0
314
+ == _mongocrypt_buffer_cmp_hex(&ciphertext,
315
+ IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E" /* the "encrypted"
316
+ block which is
317
+ really plaintext.
318
+ BBBB + padding. */
319
+ HMAC_HEX_TAG));
320
+ } else {
321
+ ASSERT_FAILS_STATUS(ret, status, error_on);
322
+ }
323
+
324
+ _mongocrypt_buffer_cleanup(&key);
325
+ _mongocrypt_buffer_cleanup(&iv);
326
+ _mongocrypt_buffer_cleanup(&associated_data);
327
+ _mongocrypt_buffer_cleanup(&plaintext);
328
+ _mongocrypt_buffer_cleanup(&ciphertext);
329
+ mongocrypt_status_destroy(status);
330
+ mongocrypt_destroy(crypt);
331
+ bson_string_free(call_history, true);
392
332
  }
393
333
 
394
-
395
- static void
396
- _test_crypto_hooks_encryption (_mongocrypt_tester_t *tester)
397
- {
398
- _test_crypto_hooks_encryption_helper (tester, "error_on:none", false, false);
399
- _test_crypto_hooks_encryption_helper (
400
- tester, "error_on:aes_256_cbc_encrypt", false, false);
401
- _test_crypto_hooks_encryption_helper (
402
- tester, "error_on:aes_256_ctr_encrypt", true, false);
403
- _test_crypto_hooks_encryption_helper (
404
- tester, "error_on:aes_256_ecb_encrypt", false, true);
405
- _test_crypto_hooks_encryption_helper (
406
- tester, "error_on:hmac_sha512", false, false);
334
+ static void _test_crypto_hooks_encryption(_mongocrypt_tester_t *tester) {
335
+ _test_crypto_hooks_encryption_helper(tester, "error_on:none", false, false);
336
+ _test_crypto_hooks_encryption_helper(tester, "error_on:aes_256_cbc_encrypt", false, false);
337
+ _test_crypto_hooks_encryption_helper(tester, "error_on:aes_256_ctr_encrypt", true, false);
338
+ _test_crypto_hooks_encryption_helper(tester, "error_on:aes_256_ecb_encrypt", false, true);
339
+ _test_crypto_hooks_encryption_helper(tester, "error_on:hmac_sha512", false, false);
407
340
  }
408
341
 
409
-
410
342
  static void
411
- _test_crypto_hooks_decryption_helper (_mongocrypt_tester_t *tester,
412
- const char *error_on,
413
- bool ctr_hook,
414
- bool ecb_hook)
415
- {
416
- mongocrypt_t *crypt;
417
- bool ret;
418
- uint32_t bytes_written;
419
- mongocrypt_status_t *status;
420
- _mongocrypt_buffer_t associated_data, key, plaintext, ciphertext;
421
- const char *expected_call_history =
422
- "call:_hmac_sha_512\n"
423
- "key:" HMAC_KEY_HEX "\n"
424
- "in:AAAA" IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E0000000000000010\n"
425
- "ret:_hmac_sha_512\n"
426
- "call:_mock_aes_256_xxx_decrypt\n"
427
- "key:" ENCRYPTION_KEY_HEX "\n"
428
- "iv:" IV_HEX "\n"
429
- "in:BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E\n"
430
- "ret:_mock_aes_256_xxx_decrypt\n";
431
-
432
- status = mongocrypt_status_new ();
433
- crypt = _create_mongocrypt_and_hooks (tester, error_on, ctr_hook, ecb_hook);
434
-
435
- _mongocrypt_buffer_copy_from_hex (&associated_data, "AAAA");
436
- _mongocrypt_buffer_copy_from_hex (
437
- &ciphertext, IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E" HMAC_HEX_TAG);
438
-
439
- call_history = bson_string_new (NULL);
440
-
441
- if (ctr_hook || ecb_hook) {
442
- _mongocrypt_buffer_copy_from_hex (&key, ENCRYPTION_KEY_HEX);
443
- _mongocrypt_buffer_init (&plaintext);
444
- _mongocrypt_buffer_resize (
445
- &plaintext,
446
- _mongocrypt_fle2_calculate_plaintext_len (ciphertext.len, status));
447
-
448
- ret = _mongocrypt_fle2_do_decryption (
449
- crypt->crypto, &key, &ciphertext, &plaintext, &bytes_written, status);
450
- } else {
451
- _mongocrypt_buffer_copy_from_hex (&key, KEY_HEX);
452
- _mongocrypt_buffer_init (&plaintext);
453
- _mongocrypt_buffer_resize (
454
- &plaintext,
455
- _mongocrypt_calculate_plaintext_len (ciphertext.len, status));
456
-
457
- ret = _mongocrypt_do_decryption (crypt->crypto,
458
- &associated_data,
459
- &key,
460
- &ciphertext,
461
- &plaintext,
462
- &bytes_written,
463
- status);
464
- }
465
-
466
- if (0 == strcmp (error_on, "error_on:none")) {
467
- ASSERT_OK_STATUS (ret, status);
468
- plaintext.len = bytes_written;
469
-
470
- /* Check the full trace. */
471
- ASSERT_STREQUAL (call_history->str, expected_call_history);
472
-
473
- /* Check the resulting plaintext */
474
- BSON_ASSERT (0 == _mongocrypt_buffer_cmp_hex (&plaintext, "BBBB"));
475
- } else {
476
- ASSERT_FAILS_STATUS (ret, status, error_on);
477
- }
478
-
479
- _mongocrypt_buffer_cleanup (&key);
480
- _mongocrypt_buffer_cleanup (&associated_data);
481
- _mongocrypt_buffer_cleanup (&plaintext);
482
- _mongocrypt_buffer_cleanup (&ciphertext);
483
- mongocrypt_status_destroy (status);
484
- mongocrypt_destroy (crypt);
485
- bson_string_free (call_history, true);
343
+ _test_crypto_hooks_decryption_helper(_mongocrypt_tester_t *tester, const char *error_on, bool ctr_hook, bool ecb_hook) {
344
+ mongocrypt_t *crypt;
345
+ bool ret;
346
+ uint32_t bytes_written;
347
+ mongocrypt_status_t *status;
348
+ _mongocrypt_buffer_t associated_data, key, plaintext, ciphertext;
349
+ const char *expected_call_history = "call:_hmac_sha_512\n"
350
+ "key:" HMAC_KEY_HEX "\n"
351
+ "in:AAAA" IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E0000000000000010\n"
352
+ "ret:_hmac_sha_512\n"
353
+ "call:_mock_aes_256_xxx_decrypt\n"
354
+ "key:" ENCRYPTION_KEY_HEX "\n"
355
+ "iv:" IV_HEX "\n"
356
+ "in:BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E\n"
357
+ "ret:_mock_aes_256_xxx_decrypt\n";
358
+
359
+ status = mongocrypt_status_new();
360
+ crypt = _create_mongocrypt_and_hooks(tester, error_on, ctr_hook, ecb_hook);
361
+
362
+ _mongocrypt_buffer_copy_from_hex(&associated_data, "AAAA");
363
+ _mongocrypt_buffer_copy_from_hex(&ciphertext, IV_HEX "BBBB0E0E0E0E0E0E0E0E0E0E0E0E0E0E" HMAC_HEX_TAG);
364
+
365
+ call_history = bson_string_new(NULL);
366
+
367
+ if (ctr_hook || ecb_hook) {
368
+ const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm();
369
+ _mongocrypt_buffer_copy_from_hex(&key, ENCRYPTION_KEY_HEX);
370
+ _mongocrypt_buffer_init(&plaintext);
371
+ _mongocrypt_buffer_resize(&plaintext, fle2alg->get_plaintext_len(ciphertext.len, status));
372
+
373
+ ret = fle2alg->do_decrypt(crypt->crypto, NULL /* aad */, &key, &ciphertext, &plaintext, &bytes_written, status);
374
+ } else {
375
+ const _mongocrypt_value_encryption_algorithm_t *fle1alg = _mcFLE1Algorithm();
376
+ _mongocrypt_buffer_copy_from_hex(&key, KEY_HEX);
377
+ _mongocrypt_buffer_init(&plaintext);
378
+ _mongocrypt_buffer_resize(&plaintext, fle1alg->get_plaintext_len(ciphertext.len, status));
379
+
380
+ ret =
381
+ fle1alg->do_decrypt(crypt->crypto, &associated_data, &key, &ciphertext, &plaintext, &bytes_written, status);
382
+ }
383
+
384
+ if (0 == strcmp(error_on, "error_on:none")) {
385
+ ASSERT_OK_STATUS(ret, status);
386
+ plaintext.len = bytes_written;
387
+
388
+ /* Check the full trace. */
389
+ ASSERT_STREQUAL(call_history->str, expected_call_history);
390
+
391
+ /* Check the resulting plaintext */
392
+ BSON_ASSERT(0 == _mongocrypt_buffer_cmp_hex(&plaintext, "BBBB"));
393
+ } else {
394
+ ASSERT_FAILS_STATUS(ret, status, error_on);
395
+ }
396
+
397
+ _mongocrypt_buffer_cleanup(&key);
398
+ _mongocrypt_buffer_cleanup(&associated_data);
399
+ _mongocrypt_buffer_cleanup(&plaintext);
400
+ _mongocrypt_buffer_cleanup(&ciphertext);
401
+ mongocrypt_status_destroy(status);
402
+ mongocrypt_destroy(crypt);
403
+ bson_string_free(call_history, true);
486
404
  }
487
405
 
488
- static void
489
- _test_crypto_hooks_decryption (_mongocrypt_tester_t *tester)
490
- {
491
- _test_crypto_hooks_decryption_helper (tester, "error_on:none", false, false);
492
- _test_crypto_hooks_decryption_helper (
493
- tester, "error_on:aes_256_cbc_decrypt", false, false);
494
- _test_crypto_hooks_decryption_helper (
495
- tester, "error_on:aes_256_ctr_decrypt", true, false);
496
- _test_crypto_hooks_decryption_helper (
497
- tester, "error_on:aes_256_ecb_encrypt", false, true);
498
- _test_crypto_hooks_decryption_helper (
499
- tester, "error_on:hmac_sha512", false, false);
406
+ static void _test_crypto_hooks_decryption(_mongocrypt_tester_t *tester) {
407
+ _test_crypto_hooks_decryption_helper(tester, "error_on:none", false, false);
408
+ _test_crypto_hooks_decryption_helper(tester, "error_on:aes_256_cbc_decrypt", false, false);
409
+ _test_crypto_hooks_decryption_helper(tester, "error_on:aes_256_ctr_decrypt", true, false);
410
+ _test_crypto_hooks_decryption_helper(tester, "error_on:aes_256_ecb_encrypt", false, true);
411
+ _test_crypto_hooks_decryption_helper(tester, "error_on:hmac_sha512", false, false);
500
412
  }
501
413
 
502
- static void
503
- _test_crypto_hooks_iv_gen_helper (_mongocrypt_tester_t *tester, char *error_on)
504
- {
505
- mongocrypt_t *crypt;
506
- bool ret;
507
- mongocrypt_status_t *status;
508
- _mongocrypt_buffer_t associated_data, key, plaintext, iv;
509
- char *expected_iv = bson_strndup (
510
- HMAC_HEX_TAG, 16 * 2); /* only the first 16 bytes are used for IV. */
511
- const char *expected_call_history = "call:_hmac_sha_512\n"
512
- "key:" IV_KEY_HEX "\n"
513
- "in:AAAA0000000000000010BBBB\n"
514
- "ret:_hmac_sha_512\n";
515
-
516
- status = mongocrypt_status_new ();
517
- crypt = _create_mongocrypt (tester, error_on);
518
-
519
- _mongocrypt_buffer_copy_from_hex (&associated_data, "AAAA");
520
- _mongocrypt_buffer_copy_from_hex (&key, KEY_HEX);
521
- _mongocrypt_buffer_copy_from_hex (&plaintext, "BBBB");
522
-
523
- _mongocrypt_buffer_init (&iv);
524
- _mongocrypt_buffer_resize (&iv, MONGOCRYPT_IV_LEN);
525
-
526
- call_history = bson_string_new (NULL);
527
-
528
- ret = _mongocrypt_calculate_deterministic_iv (
529
- crypt->crypto, &key, &plaintext, &associated_data, &iv, status);
530
-
531
- if (0 == strcmp (error_on, "error_on:none")) {
532
- ASSERT_OK_STATUS (ret, status);
533
-
534
- /* Check the full trace. */
535
- ASSERT_STREQUAL (call_history->str, expected_call_history);
536
-
537
- /* Check the resulting iv */
538
- BSON_ASSERT (0 == _mongocrypt_buffer_cmp_hex (&iv, expected_iv));
539
- } else {
540
- ASSERT_FAILS_STATUS (ret, status, error_on);
541
- }
542
-
543
- bson_free (expected_iv);
544
- _mongocrypt_buffer_cleanup (&key);
545
- _mongocrypt_buffer_cleanup (&associated_data);
546
- _mongocrypt_buffer_cleanup (&plaintext);
547
- _mongocrypt_buffer_cleanup (&iv);
548
- mongocrypt_status_destroy (status);
549
- mongocrypt_destroy (crypt);
550
- bson_string_free (call_history, true);
414
+ static void _test_crypto_hooks_iv_gen_helper(_mongocrypt_tester_t *tester, char *error_on) {
415
+ mongocrypt_t *crypt;
416
+ bool ret;
417
+ mongocrypt_status_t *status;
418
+ _mongocrypt_buffer_t associated_data, key, plaintext, iv;
419
+ char *expected_iv = bson_strndup(HMAC_HEX_TAG, 16 * 2); /* only the first 16 bytes are used for IV. */
420
+ const char *expected_call_history = "call:_hmac_sha_512\n"
421
+ "key:" IV_KEY_HEX "\n"
422
+ "in:AAAA0000000000000010BBBB\n"
423
+ "ret:_hmac_sha_512\n";
424
+
425
+ status = mongocrypt_status_new();
426
+ crypt = _create_mongocrypt(tester, error_on);
427
+
428
+ _mongocrypt_buffer_copy_from_hex(&associated_data, "AAAA");
429
+ _mongocrypt_buffer_copy_from_hex(&key, KEY_HEX);
430
+ _mongocrypt_buffer_copy_from_hex(&plaintext, "BBBB");
431
+
432
+ _mongocrypt_buffer_init(&iv);
433
+ _mongocrypt_buffer_resize(&iv, MONGOCRYPT_IV_LEN);
434
+
435
+ call_history = bson_string_new(NULL);
436
+
437
+ ret = _mongocrypt_calculate_deterministic_iv(crypt->crypto, &key, &plaintext, &associated_data, &iv, status);
438
+
439
+ if (0 == strcmp(error_on, "error_on:none")) {
440
+ ASSERT_OK_STATUS(ret, status);
441
+
442
+ /* Check the full trace. */
443
+ ASSERT_STREQUAL(call_history->str, expected_call_history);
444
+
445
+ /* Check the resulting iv */
446
+ BSON_ASSERT(0 == _mongocrypt_buffer_cmp_hex(&iv, expected_iv));
447
+ } else {
448
+ ASSERT_FAILS_STATUS(ret, status, error_on);
449
+ }
450
+
451
+ bson_free(expected_iv);
452
+ _mongocrypt_buffer_cleanup(&key);
453
+ _mongocrypt_buffer_cleanup(&associated_data);
454
+ _mongocrypt_buffer_cleanup(&plaintext);
455
+ _mongocrypt_buffer_cleanup(&iv);
456
+ mongocrypt_status_destroy(status);
457
+ mongocrypt_destroy(crypt);
458
+ bson_string_free(call_history, true);
551
459
  }
552
460
 
553
- static void
554
- _test_crypto_hooks_iv_gen (_mongocrypt_tester_t *tester)
555
- {
556
- _test_crypto_hooks_iv_gen_helper (tester, "error_on:none");
557
- _test_crypto_hooks_iv_gen_helper (tester, "error_on:hmac_sha512");
461
+ static void _test_crypto_hooks_iv_gen(_mongocrypt_tester_t *tester) {
462
+ _test_crypto_hooks_iv_gen_helper(tester, "error_on:none");
463
+ _test_crypto_hooks_iv_gen_helper(tester, "error_on:hmac_sha512");
558
464
  }
559
465
 
466
+ static void _test_crypto_hooks_random_helper(_mongocrypt_tester_t *tester, const char *error_on) {
467
+ mongocrypt_t *crypt;
468
+ bool ret;
469
+ mongocrypt_status_t *status;
470
+ _mongocrypt_buffer_t random;
471
+ const char *expected_call_history = "call:_random\n"
472
+ "count:96\n"
473
+ "ret:_random\n";
560
474
 
561
- static void
562
- _test_crypto_hooks_random_helper (_mongocrypt_tester_t *tester,
563
- const char *error_on)
564
- {
565
- mongocrypt_t *crypt;
566
- bool ret;
567
- mongocrypt_status_t *status;
568
- _mongocrypt_buffer_t random;
569
- const char *expected_call_history = "call:_random\n"
570
- "count:96\n"
571
- "ret:_random\n";
572
-
573
- status = mongocrypt_status_new ();
574
- crypt = _create_mongocrypt (tester, error_on);
575
-
576
- _mongocrypt_buffer_init (&random);
577
- _mongocrypt_buffer_resize (&random, 96);
578
-
579
- call_history = bson_string_new (NULL);
580
-
581
- ret = _mongocrypt_random (crypt->crypto, &random, random.len, status);
582
-
583
- if (0 == strcmp (error_on, "error_on:none")) {
584
- ASSERT_OK_STATUS (ret, status);
585
-
586
- /* Check the full trace. */
587
- ASSERT_STREQUAL (call_history->str, expected_call_history);
588
-
589
- /* Check the resulting iv */
590
- BSON_ASSERT (0 == _mongocrypt_buffer_cmp_hex (&random, RANDOM_HEX));
591
- } else {
592
- ASSERT_FAILS_STATUS (ret, status, error_on);
593
- }
594
-
595
- _mongocrypt_buffer_cleanup (&random);
596
- mongocrypt_status_destroy (status);
597
- mongocrypt_destroy (crypt);
598
- bson_string_free (call_history, true);
475
+ status = mongocrypt_status_new();
476
+ crypt = _create_mongocrypt(tester, error_on);
477
+
478
+ _mongocrypt_buffer_init(&random);
479
+ _mongocrypt_buffer_resize(&random, 96);
480
+
481
+ call_history = bson_string_new(NULL);
482
+
483
+ ret = _mongocrypt_random(crypt->crypto, &random, random.len, status);
484
+
485
+ if (0 == strcmp(error_on, "error_on:none")) {
486
+ ASSERT_OK_STATUS(ret, status);
487
+
488
+ /* Check the full trace. */
489
+ ASSERT_STREQUAL(call_history->str, expected_call_history);
490
+
491
+ /* Check the resulting iv */
492
+ BSON_ASSERT(0 == _mongocrypt_buffer_cmp_hex(&random, RANDOM_HEX));
493
+ } else {
494
+ ASSERT_FAILS_STATUS(ret, status, error_on);
495
+ }
496
+
497
+ _mongocrypt_buffer_cleanup(&random);
498
+ mongocrypt_status_destroy(status);
499
+ mongocrypt_destroy(crypt);
500
+ bson_string_free(call_history, true);
599
501
  }
600
502
 
601
- static void
602
- _test_crypto_hooks_random (_mongocrypt_tester_t *tester)
603
- {
604
- _test_crypto_hooks_random_helper (tester, "error_on:none");
605
- _test_crypto_hooks_random_helper (tester, "error_on:random");
503
+ static void _test_crypto_hooks_random(_mongocrypt_tester_t *tester) {
504
+ _test_crypto_hooks_random_helper(tester, "error_on:none");
505
+ _test_crypto_hooks_random_helper(tester, "error_on:random");
606
506
  }
607
507
 
608
- static void
609
- _test_kms_request_helper (_mongocrypt_tester_t *tester, const char *error_on)
610
- {
611
- mongocrypt_t *crypt;
612
- mongocrypt_status_t *status;
613
- mongocrypt_ctx_t *ctx;
614
- bool ret;
615
-
616
- status = mongocrypt_status_new ();
617
- crypt = _create_mongocrypt (tester, error_on);
618
- ctx = mongocrypt_ctx_new (crypt);
619
-
620
- call_history = bson_string_new (NULL);
621
-
622
- ASSERT_OK (
623
- mongocrypt_ctx_setopt_masterkey_aws (ctx, "us-east-1", -1, "cmk", -1),
624
- ctx);
625
-
626
- mongocrypt_ctx_datakey_init (ctx);
627
- ret = mongocrypt_ctx_status (ctx, status);
628
-
629
- if (0 == strcmp (error_on, "error_on:none")) {
630
- ASSERT_OK_STATUS (ret, status);
631
-
632
- /* The call history includes some random data, just assert we've called
633
- * our hooks. */
634
- BSON_ASSERT (strstr (call_history->str, "call:_hmac_sha_256"));
635
- BSON_ASSERT (strstr (call_history->str, "call:_sha_256"));
636
- } else {
637
- ASSERT_FAILS_STATUS (ret, status, error_on);
638
- }
639
-
640
- mongocrypt_ctx_destroy (ctx);
641
- mongocrypt_status_destroy (status);
642
- mongocrypt_destroy (crypt);
643
- bson_string_free (call_history, true);
508
+ static void _test_kms_request_helper(_mongocrypt_tester_t *tester, const char *error_on) {
509
+ mongocrypt_t *crypt;
510
+ mongocrypt_status_t *status;
511
+ mongocrypt_ctx_t *ctx;
512
+ bool ret;
513
+
514
+ status = mongocrypt_status_new();
515
+ crypt = _create_mongocrypt(tester, error_on);
516
+ ctx = mongocrypt_ctx_new(crypt);
517
+
518
+ call_history = bson_string_new(NULL);
519
+
520
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "us-east-1", -1, "cmk", -1), ctx);
521
+
522
+ mongocrypt_ctx_datakey_init(ctx);
523
+ ret = mongocrypt_ctx_status(ctx, status);
524
+
525
+ if (0 == strcmp(error_on, "error_on:none")) {
526
+ ASSERT_OK_STATUS(ret, status);
527
+
528
+ /* The call history includes some random data, just assert we've called
529
+ * our hooks. */
530
+ BSON_ASSERT(strstr(call_history->str, "call:_hmac_sha_256"));
531
+ BSON_ASSERT(strstr(call_history->str, "call:_sha_256"));
532
+ } else {
533
+ ASSERT_FAILS_STATUS(ret, status, error_on);
534
+ }
535
+
536
+ mongocrypt_ctx_destroy(ctx);
537
+ mongocrypt_status_destroy(status);
538
+ mongocrypt_destroy(crypt);
539
+ bson_string_free(call_history, true);
644
540
  }
645
541
 
646
- static void
647
- _test_kms_request (_mongocrypt_tester_t *tester)
648
- {
649
- _test_kms_request_helper (tester, "error_on:none");
650
- _test_kms_request_helper (tester, "error_on:hmac_sha256");
651
- _test_kms_request_helper (tester, "error_on:sha256");
542
+ static void _test_kms_request(_mongocrypt_tester_t *tester) {
543
+ _test_kms_request_helper(tester, "error_on:none");
544
+ _test_kms_request_helper(tester, "error_on:hmac_sha256");
545
+ _test_kms_request_helper(tester, "error_on:sha256");
652
546
  }
653
547
 
548
+ static void _test_crypto_hooks_unset(_mongocrypt_tester_t *tester) {
549
+ mongocrypt_t *crypt;
654
550
 
655
- static void
656
- _test_crypto_hooks_unset (_mongocrypt_tester_t *tester)
657
- {
658
- mongocrypt_t *crypt;
659
-
660
- crypt = mongocrypt_new ();
661
- mongocrypt_setopt_kms_provider_aws (crypt, "example", -1, "example", -1);
662
- ASSERT_OK (mongocrypt_init (crypt), crypt);
663
- mongocrypt_destroy (crypt);
551
+ crypt = mongocrypt_new();
552
+ mongocrypt_setopt_kms_provider_aws(crypt, "example", -1, "example", -1);
553
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
554
+ mongocrypt_destroy(crypt);
664
555
  }
665
556
 
666
-
667
557
  /* test a bug fix, that an error on explicit encryption in the crypto hooks sets
668
558
  * the context state */
669
- static void
670
- _test_crypto_hooks_explicit_err (_mongocrypt_tester_t *tester)
671
- {
672
- mongocrypt_t *crypt;
673
- mongocrypt_ctx_t *ctx;
674
- mongocrypt_binary_t *bin, *key_id;
675
- const char *deterministic = MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR;
676
-
677
- call_history = bson_string_new (NULL);
678
-
679
- /* error on something during encryption. */
680
- crypt = _create_mongocrypt (tester, "error_on:hmac_sha512");
681
-
682
- ctx = mongocrypt_ctx_new (crypt);
683
- key_id = mongocrypt_binary_new_from_data (
684
- MONGOCRYPT_DATA_AND_LEN ("aaaaaaaaaaaaaaaa"));
685
-
686
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (ctx, deterministic, -1), ctx);
687
- ASSERT_OK (mongocrypt_ctx_setopt_key_id (ctx, key_id), ctx);
688
- ASSERT_OK (
689
- mongocrypt_ctx_explicit_encrypt_init (ctx, TEST_BSON ("{'v': 123}")),
690
- ctx);
691
-
692
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
693
- bin = mongocrypt_binary_new ();
694
- ASSERT_FAILS (
695
- mongocrypt_ctx_finalize (ctx, bin), ctx, "error_on:hmac_sha512");
696
- BSON_ASSERT (MONGOCRYPT_CTX_ERROR == mongocrypt_ctx_state (ctx));
697
- mongocrypt_binary_destroy (bin);
698
- mongocrypt_binary_destroy (key_id);
699
- mongocrypt_ctx_destroy (ctx);
700
- mongocrypt_destroy (crypt);
701
- bson_string_free (call_history, true);
559
+ static void _test_crypto_hooks_explicit_err(_mongocrypt_tester_t *tester) {
560
+ mongocrypt_t *crypt;
561
+ mongocrypt_ctx_t *ctx;
562
+ mongocrypt_binary_t *bin, *key_id;
563
+ const char *deterministic = MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR;
564
+
565
+ call_history = bson_string_new(NULL);
566
+
567
+ /* error on something during encryption. */
568
+ crypt = _create_mongocrypt(tester, "error_on:hmac_sha512");
569
+
570
+ ctx = mongocrypt_ctx_new(crypt);
571
+ key_id = mongocrypt_binary_new_from_data(MONGOCRYPT_DATA_AND_LEN("aaaaaaaaaaaaaaaa"));
572
+
573
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, deterministic, -1), ctx);
574
+ ASSERT_OK(mongocrypt_ctx_setopt_key_id(ctx, key_id), ctx);
575
+ ASSERT_OK(mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': 123}")), ctx);
576
+
577
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
578
+ bin = mongocrypt_binary_new();
579
+ ASSERT_FAILS(mongocrypt_ctx_finalize(ctx, bin), ctx, "error_on:hmac_sha512");
580
+ BSON_ASSERT(MONGOCRYPT_CTX_ERROR == mongocrypt_ctx_state(ctx));
581
+ mongocrypt_binary_destroy(bin);
582
+ mongocrypt_binary_destroy(key_id);
583
+ mongocrypt_ctx_destroy(ctx);
584
+ mongocrypt_destroy(crypt);
585
+ bson_string_free(call_history, true);
702
586
  }
703
587
 
704
588
  /* validate that sha256 errors are handled correctly */
705
- static void
706
- _test_crypto_hooks_explicit_sha256_err (_mongocrypt_tester_t *tester)
707
- {
708
- mongocrypt_t *crypt;
709
- mongocrypt_status_t *status;
710
- mongocrypt_ctx_t *ctx;
711
-
712
- status = mongocrypt_status_new ();
713
- crypt = _create_mongocrypt (tester, "error_on:sha256");
714
- ctx = mongocrypt_ctx_new (crypt);
715
-
716
- call_history = bson_string_new (NULL);
717
-
718
- ASSERT_OK (
719
- mongocrypt_ctx_setopt_masterkey_aws (ctx, "us-east-1", -1, "cmk", -1),
720
- ctx);
721
- ASSERT_FAILS (
722
- mongocrypt_ctx_datakey_init (ctx), ctx, "failed to create KMS message");
723
-
724
- mongocrypt_ctx_destroy (ctx);
725
- mongocrypt_status_destroy (status);
726
- mongocrypt_destroy (crypt);
727
- bson_string_free (call_history, true);
589
+ static void _test_crypto_hooks_explicit_sha256_err(_mongocrypt_tester_t *tester) {
590
+ mongocrypt_t *crypt;
591
+ mongocrypt_status_t *status;
592
+ mongocrypt_ctx_t *ctx;
593
+
594
+ status = mongocrypt_status_new();
595
+ crypt = _create_mongocrypt(tester, "error_on:sha256");
596
+ ctx = mongocrypt_ctx_new(crypt);
597
+
598
+ call_history = bson_string_new(NULL);
599
+
600
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, "us-east-1", -1, "cmk", -1), ctx);
601
+ ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, "failed to create KMS message");
602
+
603
+ mongocrypt_ctx_destroy(ctx);
604
+ mongocrypt_status_destroy(status);
605
+ mongocrypt_destroy(crypt);
606
+ bson_string_free(call_history, true);
728
607
  }
729
608
 
730
- static void
731
- _test_crypto_hook_sign_rsaes_pkcs1_v1_5 (_mongocrypt_tester_t *tester)
732
- {
733
- mongocrypt_t *crypt;
734
- mongocrypt_ctx_t *ctx;
735
-
736
- crypt = _create_mongocrypt (tester, "error_on:none");
737
- call_history = bson_string_new (NULL);
738
-
739
- ctx = mongocrypt_ctx_new (crypt);
740
- mongocrypt_ctx_setopt_key_encryption_key (
741
- ctx,
742
- TEST_BSON ("{'provider': 'gcp', 'projectId': 'test', 'location': "
743
- "'global', 'keyRing': 'ring', 'keyName': 'key'}"));
744
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
745
-
746
- BSON_ASSERT (strstr (call_history->str, "call:_sign_rsaes_pkcs1_v1_5"));
747
- BSON_ASSERT (strstr (call_history->str, "key:000000"));
748
-
749
- mongocrypt_ctx_destroy (ctx);
750
- mongocrypt_destroy (crypt);
751
- bson_string_free (call_history, true);
752
-
753
- /* Test error when creating a data key. */
754
- crypt = _create_mongocrypt (tester, "error_on:sign_rsaes_pkcs1_v1_5");
755
- ctx = mongocrypt_ctx_new (crypt);
756
- call_history = bson_string_new (NULL);
757
-
758
- mongocrypt_ctx_setopt_key_encryption_key (
759
- ctx,
760
- TEST_BSON ("{'provider': 'gcp', 'projectId': 'test', 'location': "
761
- "'global', 'keyRing': 'ring', 'keyName': 'key'}"));
762
- ASSERT_FAILS (
763
- mongocrypt_ctx_datakey_init (ctx), ctx, "error_on:sign_rsaes_pkcs1_v1_5");
764
-
765
- mongocrypt_ctx_destroy (ctx);
766
- mongocrypt_destroy (crypt);
767
- bson_string_free (call_history, true);
768
-
769
- /* Test error when encrypting. */
770
- crypt = _create_mongocrypt (tester, "error_on:sign_rsaes_pkcs1_v1_5");
771
- ctx = mongocrypt_ctx_new (crypt);
772
- call_history = bson_string_new (NULL);
773
-
774
- ASSERT_OK (mongocrypt_ctx_encrypt_init (
775
- ctx, "test", -1, TEST_FILE ("./test/example/cmd.json")),
776
- ctx);
777
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
778
- ASSERT_FAILS (mongocrypt_ctx_mongo_feed (
779
- ctx, TEST_FILE ("./test/data/key-document-gcp.json")),
609
+ static void _test_crypto_hook_sign_rsaes_pkcs1_v1_5(_mongocrypt_tester_t *tester) {
610
+ mongocrypt_t *crypt;
611
+ mongocrypt_ctx_t *ctx;
612
+
613
+ crypt = _create_mongocrypt(tester, "error_on:none");
614
+ call_history = bson_string_new(NULL);
615
+
616
+ ctx = mongocrypt_ctx_new(crypt);
617
+ mongocrypt_ctx_setopt_key_encryption_key(ctx,
618
+ TEST_BSON("{'provider': 'gcp', 'projectId': 'test', 'location': "
619
+ "'global', 'keyRing': 'ring', 'keyName': 'key'}"));
620
+ ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
621
+
622
+ BSON_ASSERT(strstr(call_history->str, "call:_sign_rsaes_pkcs1_v1_5"));
623
+ BSON_ASSERT(strstr(call_history->str, "key:000000"));
624
+
625
+ mongocrypt_ctx_destroy(ctx);
626
+ mongocrypt_destroy(crypt);
627
+ bson_string_free(call_history, true);
628
+
629
+ /* Test error when creating a data key. */
630
+ crypt = _create_mongocrypt(tester, "error_on:sign_rsaes_pkcs1_v1_5");
631
+ ctx = mongocrypt_ctx_new(crypt);
632
+ call_history = bson_string_new(NULL);
633
+
634
+ mongocrypt_ctx_setopt_key_encryption_key(ctx,
635
+ TEST_BSON("{'provider': 'gcp', 'projectId': 'test', 'location': "
636
+ "'global', 'keyRing': 'ring', 'keyName': 'key'}"));
637
+ ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, "error_on:sign_rsaes_pkcs1_v1_5");
638
+
639
+ mongocrypt_ctx_destroy(ctx);
640
+ mongocrypt_destroy(crypt);
641
+ bson_string_free(call_history, true);
642
+
643
+ /* Test error when encrypting. */
644
+ crypt = _create_mongocrypt(tester, "error_on:sign_rsaes_pkcs1_v1_5");
645
+ ctx = mongocrypt_ctx_new(crypt);
646
+ call_history = bson_string_new(NULL);
647
+
648
+ ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, "test", -1, TEST_FILE("./test/example/cmd.json")), ctx);
649
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
650
+ ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-gcp.json")),
780
651
  ctx,
781
652
  "error_on:sign_rsaes_pkcs1_v1_5");
782
653
 
783
- mongocrypt_ctx_destroy (ctx);
784
- mongocrypt_destroy (crypt);
785
- bson_string_free (call_history, true);
654
+ mongocrypt_ctx_destroy(ctx);
655
+ mongocrypt_destroy(crypt);
656
+ bson_string_free(call_history, true);
786
657
  }
787
658
 
788
659
  #ifdef MONGOCRYPT_ENABLE_CRYPTO_LIBCRYPTO
789
- bool
790
- _native_crypto_aes_256_ecb_encrypt (aes_256_args_t args);
791
-
792
- static bool
793
- _aes_256_ecb_encrypt (void *ctx,
794
- mongocrypt_binary_t *key,
795
- mongocrypt_binary_t *iv,
796
- mongocrypt_binary_t *in,
797
- mongocrypt_binary_t *out,
798
- uint32_t *bytes_written,
799
- mongocrypt_status_t *status)
800
- {
801
- _mongocrypt_buffer_t key_buf;
802
- _mongocrypt_buffer_from_binary (&key_buf, key);
803
- if (iv) {
804
- CLIENT_ERR ("IV expected to be NULL in this mode");
805
- return false;
806
- }
807
- _mongocrypt_buffer_t in_buf;
808
- _mongocrypt_buffer_from_binary (&in_buf, in);
809
- _mongocrypt_buffer_t out_buf;
810
- _mongocrypt_buffer_from_binary (&out_buf, out);
811
-
812
- aes_256_args_t args = {
813
- &key_buf, NULL, &in_buf, &out_buf, bytes_written, status};
814
-
815
- return _native_crypto_aes_256_ecb_encrypt (args);
660
+ bool _native_crypto_aes_256_ecb_encrypt(aes_256_args_t args);
661
+
662
+ static bool _aes_256_ecb_encrypt(void *ctx,
663
+ mongocrypt_binary_t *key,
664
+ mongocrypt_binary_t *iv,
665
+ mongocrypt_binary_t *in,
666
+ mongocrypt_binary_t *out,
667
+ uint32_t *bytes_written,
668
+ mongocrypt_status_t *status) {
669
+ _mongocrypt_buffer_t key_buf;
670
+ _mongocrypt_buffer_from_binary(&key_buf, key);
671
+ if (iv) {
672
+ CLIENT_ERR("IV expected to be NULL in this mode");
673
+ return false;
674
+ }
675
+ _mongocrypt_buffer_t in_buf;
676
+ _mongocrypt_buffer_from_binary(&in_buf, in);
677
+ _mongocrypt_buffer_t out_buf;
678
+ _mongocrypt_buffer_from_binary(&out_buf, out);
679
+
680
+ aes_256_args_t args = {&key_buf, NULL, &in_buf, &out_buf, bytes_written, status};
681
+
682
+ return _native_crypto_aes_256_ecb_encrypt(args);
816
683
  }
817
684
 
818
-
819
- void
820
- _test_fle2_crypto_via_ecb_hook (_mongocrypt_tester_t *tester)
821
- {
822
- bool ret;
823
- _mongocrypt_buffer_t key;
824
- _mongocrypt_buffer_t iv;
825
- _mongocrypt_buffer_t plaintext;
826
- _mongocrypt_buffer_t ciphertext_reg;
827
- _mongocrypt_buffer_t ciphertext_ecb;
828
- _mongocrypt_buffer_t plaintext_ecb;
829
- uint32_t bytes_written;
830
- mongocrypt_status_t *status = mongocrypt_status_new ();
831
-
832
- _mongocrypt_buffer_copy_from_hex (&iv, IV_HEX);
833
- _mongocrypt_buffer_copy_from_hex (
834
- &plaintext,
835
- "4f6c64204d63446f6e616c64206861642061206661726d2e20456965696f0a");
836
- _mongocrypt_buffer_copy_from_hex (&key, ENCRYPTION_KEY_HEX);
837
-
838
- /* Encrypt data using native CTR and ECB-hook and compare */
839
-
840
- mongocrypt_t *crypt_reg = mongocrypt_new ();
841
- _mongocrypt_buffer_init (&ciphertext_reg);
842
- _mongocrypt_buffer_resize (
843
- &ciphertext_reg,
844
- _mongocrypt_fle2_calculate_ciphertext_len (plaintext.len, status));
845
- ret = _mongocrypt_fle2_do_encryption (crypt_reg->crypto,
846
- &iv,
847
- &key,
848
- &plaintext,
849
- &ciphertext_reg,
850
- &bytes_written,
851
- status);
852
- ASSERT_OK (ret, crypt_reg);
853
-
854
- mongocrypt_t *crypt_ecb = mongocrypt_new ();
855
- ret = mongocrypt_setopt_aes_256_ecb (crypt_ecb, _aes_256_ecb_encrypt, NULL);
856
- ASSERT_OK (ret, crypt_ecb);
857
- _mongocrypt_buffer_init (&ciphertext_ecb);
858
- _mongocrypt_buffer_resize (
859
- &ciphertext_ecb,
860
- _mongocrypt_fle2_calculate_ciphertext_len (plaintext.len, status));
861
- ret = _mongocrypt_fle2_do_encryption (crypt_ecb->crypto,
862
- &iv,
863
- &key,
864
- &plaintext,
865
- &ciphertext_ecb,
866
- &bytes_written,
867
- status);
868
- ASSERT_OK (ret, crypt_ecb);
869
-
870
- ASSERT (0 == _mongocrypt_buffer_cmp (&ciphertext_reg, &ciphertext_ecb));
871
-
872
- /* Decrypt data using ECB-hook and compare to original */
873
-
874
- _mongocrypt_buffer_init (&plaintext_ecb);
875
- _mongocrypt_buffer_resize (
876
- &plaintext_ecb,
877
- _mongocrypt_fle2_calculate_plaintext_len (ciphertext_ecb.len, status));
878
- ret = _mongocrypt_fle2_do_decryption (crypt_ecb->crypto,
879
- &key,
880
- &ciphertext_ecb,
881
- &plaintext_ecb,
882
- &bytes_written,
883
- status);
884
- ASSERT_OK (ret, crypt_ecb);
885
-
886
- ASSERT (0 == _mongocrypt_buffer_cmp (&plaintext, &plaintext_ecb));
887
-
888
- _mongocrypt_buffer_cleanup (&key);
889
- _mongocrypt_buffer_cleanup (&iv);
890
- _mongocrypt_buffer_cleanup (&plaintext);
891
- _mongocrypt_buffer_cleanup (&ciphertext_reg);
892
- _mongocrypt_buffer_cleanup (&ciphertext_ecb);
893
- _mongocrypt_buffer_cleanup (&plaintext_ecb);
894
- mongocrypt_destroy (crypt_reg);
895
- mongocrypt_destroy (crypt_ecb);
896
- mongocrypt_status_destroy (status);
685
+ void _test_fle2_crypto_via_ecb_hook(_mongocrypt_tester_t *tester) {
686
+ const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm();
687
+ bool ret;
688
+ _mongocrypt_buffer_t key;
689
+ _mongocrypt_buffer_t iv;
690
+ _mongocrypt_buffer_t plaintext;
691
+ _mongocrypt_buffer_t ciphertext_reg;
692
+ _mongocrypt_buffer_t ciphertext_ecb;
693
+ _mongocrypt_buffer_t plaintext_ecb;
694
+ uint32_t bytes_written;
695
+ mongocrypt_status_t *status = mongocrypt_status_new();
696
+
697
+ _mongocrypt_buffer_copy_from_hex(&iv, IV_HEX);
698
+ _mongocrypt_buffer_copy_from_hex(&plaintext, "4f6c64204d63446f6e616c64206861642061206661726d2e20456965696f0a");
699
+ _mongocrypt_buffer_copy_from_hex(&key, ENCRYPTION_KEY_HEX);
700
+
701
+ /* Encrypt data using native CTR and ECB-hook and compare */
702
+
703
+ mongocrypt_t *crypt_reg = mongocrypt_new();
704
+ _mongocrypt_buffer_init(&ciphertext_reg);
705
+ _mongocrypt_buffer_resize(&ciphertext_reg, fle2alg->get_ciphertext_len(plaintext.len, status));
706
+ ret = fle2alg->do_encrypt(crypt_reg->crypto,
707
+ &iv,
708
+ NULL /* aad */,
709
+ &key,
710
+ &plaintext,
711
+ &ciphertext_reg,
712
+ &bytes_written,
713
+ status);
714
+ ASSERT_OK(ret, crypt_reg);
715
+
716
+ mongocrypt_t *crypt_ecb = mongocrypt_new();
717
+ ret = mongocrypt_setopt_aes_256_ecb(crypt_ecb, _aes_256_ecb_encrypt, NULL);
718
+ ASSERT_OK(ret, crypt_ecb);
719
+ _mongocrypt_buffer_init(&ciphertext_ecb);
720
+ _mongocrypt_buffer_resize(&ciphertext_ecb, fle2alg->get_ciphertext_len(plaintext.len, status));
721
+ ret = fle2alg->do_encrypt(crypt_ecb->crypto,
722
+ &iv,
723
+ NULL /* aad */,
724
+ &key,
725
+ &plaintext,
726
+ &ciphertext_ecb,
727
+ &bytes_written,
728
+ status);
729
+ ASSERT_OK(ret, crypt_ecb);
730
+
731
+ ASSERT(0 == _mongocrypt_buffer_cmp(&ciphertext_reg, &ciphertext_ecb));
732
+
733
+ /* Decrypt data using ECB-hook and compare to original */
734
+
735
+ _mongocrypt_buffer_init(&plaintext_ecb);
736
+ _mongocrypt_buffer_resize(&plaintext_ecb, fle2alg->get_plaintext_len(ciphertext_ecb.len, status));
737
+ ret = fle2alg->do_decrypt(crypt_ecb->crypto,
738
+ NULL /* aad */,
739
+ &key,
740
+ &ciphertext_ecb,
741
+ &plaintext_ecb,
742
+ &bytes_written,
743
+ status);
744
+ ASSERT_OK(ret, crypt_ecb);
745
+
746
+ ASSERT(0 == _mongocrypt_buffer_cmp(&plaintext, &plaintext_ecb));
747
+
748
+ _mongocrypt_buffer_cleanup(&key);
749
+ _mongocrypt_buffer_cleanup(&iv);
750
+ _mongocrypt_buffer_cleanup(&plaintext);
751
+ _mongocrypt_buffer_cleanup(&ciphertext_reg);
752
+ _mongocrypt_buffer_cleanup(&ciphertext_ecb);
753
+ _mongocrypt_buffer_cleanup(&plaintext_ecb);
754
+ mongocrypt_destroy(crypt_reg);
755
+ mongocrypt_destroy(crypt_ecb);
756
+ mongocrypt_status_destroy(status);
897
757
  }
898
758
  #endif
899
759
 
900
- void
901
- _mongocrypt_tester_install_crypto_hooks (_mongocrypt_tester_t *tester)
902
- {
903
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_encryption, CRYPTO_OPTIONAL);
904
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_decryption, CRYPTO_OPTIONAL);
905
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_iv_gen, CRYPTO_OPTIONAL);
906
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_random, CRYPTO_OPTIONAL);
907
- INSTALL_TEST_CRYPTO (_test_kms_request, CRYPTO_OPTIONAL);
908
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_unset, CRYPTO_PROHIBITED);
909
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_explicit_err, CRYPTO_OPTIONAL);
910
- INSTALL_TEST_CRYPTO (_test_crypto_hooks_explicit_sha256_err,
911
- CRYPTO_OPTIONAL);
912
- INSTALL_TEST_CRYPTO (_test_crypto_hook_sign_rsaes_pkcs1_v1_5,
913
- CRYPTO_OPTIONAL);
760
+ void _mongocrypt_tester_install_crypto_hooks(_mongocrypt_tester_t *tester) {
761
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_encryption, CRYPTO_OPTIONAL);
762
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_decryption, CRYPTO_OPTIONAL);
763
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_iv_gen, CRYPTO_OPTIONAL);
764
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_random, CRYPTO_OPTIONAL);
765
+ INSTALL_TEST_CRYPTO(_test_kms_request, CRYPTO_OPTIONAL);
766
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_unset, CRYPTO_PROHIBITED);
767
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_explicit_err, CRYPTO_OPTIONAL);
768
+ INSTALL_TEST_CRYPTO(_test_crypto_hooks_explicit_sha256_err, CRYPTO_OPTIONAL);
769
+ INSTALL_TEST_CRYPTO(_test_crypto_hook_sign_rsaes_pkcs1_v1_5, CRYPTO_OPTIONAL);
914
770
  #ifdef MONGOCRYPT_ENABLE_CRYPTO_LIBCRYPTO
915
- INSTALL_TEST (_test_fle2_crypto_via_ecb_hook);
771
+ INSTALL_TEST(_test_fle2_crypto_via_ecb_hook);
916
772
  #endif
917
773
  }