rbnacl-libsodium 1.0.13 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +5 -0
  3. data/lib/rbnacl/libsodium.rb +1 -0
  4. data/lib/rbnacl/libsodium/version.rb +1 -1
  5. data/vendor/libsodium/AUTHORS +2 -2
  6. data/vendor/libsodium/ChangeLog +64 -0
  7. data/vendor/libsodium/Makefile.am +1 -0
  8. data/vendor/libsodium/README.markdown +1 -3
  9. data/vendor/libsodium/THANKS +13 -3
  10. data/vendor/libsodium/builds/Makefile.am +65 -0
  11. data/vendor/libsodium/builds/msvc/resource.rc +2 -2
  12. data/vendor/libsodium/builds/msvc/version.h +3 -3
  13. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +168 -173
  14. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +382 -394
  15. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +168 -173
  16. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +382 -394
  17. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +168 -173
  18. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +382 -394
  19. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +168 -173
  20. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +382 -394
  21. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj +168 -173
  22. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +382 -394
  23. data/vendor/libsodium/configure.ac +59 -10
  24. data/vendor/libsodium/contrib/Findsodium.cmake +2 -0
  25. data/vendor/libsodium/dist-build/emscripten-symbols.def +72 -32
  26. data/vendor/libsodium/dist-build/emscripten.sh +33 -6
  27. data/vendor/libsodium/dist-build/generate-emscripten-symbols.sh +52 -38
  28. data/vendor/libsodium/dist-build/ios.sh +2 -2
  29. data/vendor/libsodium/libsodium.vcxproj +168 -173
  30. data/vendor/libsodium/libsodium.vcxproj.filters +220 -235
  31. data/vendor/libsodium/m4/ax_check_catchable_abrt.m4 +57 -0
  32. data/vendor/libsodium/m4/ax_check_gnu_make.m4 +2 -2
  33. data/vendor/libsodium/m4/ax_pthread.m4 +2 -2
  34. data/vendor/libsodium/msvc-scripts/process.bat +3 -3
  35. data/vendor/libsodium/packaging/dotnet-core/README.md +5 -5
  36. data/vendor/libsodium/packaging/dotnet-core/libsodium.props +5 -2
  37. data/vendor/libsodium/packaging/dotnet-core/prepare.py +13 -31
  38. data/vendor/libsodium/packaging/dotnet-core/recipes/linux-x64 +4 -0
  39. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  40. data/vendor/libsodium/src/libsodium/Makefile.am +11 -12
  41. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +11 -4
  42. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +17 -4
  43. data/vendor/libsodium/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c +8 -1
  44. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box.c +6 -0
  45. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +5 -4
  46. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +11 -4
  47. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c +6 -0
  48. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +78 -17
  49. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c +74 -64
  50. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c +2 -0
  51. data/vendor/libsodium/src/libsodium/crypto_kx/crypto_kx.c +7 -0
  52. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +1 -1
  53. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +1 -0
  54. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +17 -17
  55. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +53 -48
  56. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +37 -11
  57. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +23 -179
  58. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c +4 -12
  59. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx512f.c +244 -0
  60. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +3 -12
  61. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +4 -12
  62. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +1 -5
  63. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +1 -1
  64. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-avx512f.h +145 -0
  65. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +91 -14
  66. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c +35 -14
  67. data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +41 -4
  68. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +31 -17
  69. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +4 -0
  70. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +5 -1
  71. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +30 -1
  72. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +8 -0
  73. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c +3 -3
  74. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox.c +6 -0
  75. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +5 -4
  76. data/vendor/libsodium/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c +11 -4
  77. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c +6 -0
  78. data/vendor/libsodium/src/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c +311 -0
  79. data/vendor/libsodium/src/libsodium/crypto_sign/crypto_sign.c +6 -0
  80. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ed25519_ref10.h +3 -0
  81. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +9 -2
  82. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +1 -1
  83. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +6 -5
  84. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c +6 -0
  85. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c +3 -2
  86. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c +3 -2
  87. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u0.h +1 -1
  88. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c +3 -2
  89. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c +12 -0
  90. data/vendor/libsodium/src/libsodium/crypto_stream/crypto_stream.c +6 -0
  91. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c +7 -1
  92. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u0.h +1 -1
  93. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012.c +6 -0
  94. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208.c +6 -0
  95. data/vendor/libsodium/src/libsodium/crypto_stream/xchacha20/stream_xchacha20.c +6 -0
  96. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c +6 -0
  97. data/vendor/libsodium/src/libsodium/crypto_verify/sodium/verify.c +66 -29
  98. data/vendor/libsodium/src/libsodium/include/Makefile.am +1 -1
  99. data/vendor/libsodium/src/libsodium/include/sodium.h +2 -2
  100. data/vendor/libsodium/src/libsodium/include/sodium/core.h +9 -0
  101. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +26 -0
  102. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +16 -4
  103. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h +10 -4
  104. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +4 -0
  105. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h +6 -0
  106. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +24 -15
  107. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_salsa208.h +8 -4
  108. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +40 -18
  109. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +8 -2
  110. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2id.h +8 -2
  111. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +11 -3
  112. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +4 -0
  113. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h +6 -0
  114. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +17 -8
  115. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h +102 -0
  116. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +4 -0
  117. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +4 -0
  118. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +1 -0
  119. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +4 -0
  120. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +10 -0
  121. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +4 -0
  122. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +4 -0
  123. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +15 -5
  124. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xchacha20.h +4 -0
  125. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +4 -0
  126. data/vendor/libsodium/src/libsodium/include/sodium/export.h +9 -0
  127. data/vendor/libsodium/src/libsodium/include/sodium/private/common.h +11 -0
  128. data/vendor/libsodium/src/libsodium/include/sodium/private/curve25519_ref10.h +2 -30
  129. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +2 -0
  130. data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +12 -9
  131. data/vendor/libsodium/src/libsodium/include/sodium/utils.h +36 -0
  132. data/vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +3 -2
  133. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +18 -14
  134. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +11 -10
  135. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +20 -8
  136. data/vendor/libsodium/src/libsodium/sodium/codecs.c +333 -0
  137. data/vendor/libsodium/src/libsodium/sodium/core.c +36 -4
  138. data/vendor/libsodium/src/libsodium/sodium/runtime.c +18 -0
  139. data/vendor/libsodium/src/libsodium/sodium/utils.c +87 -100
  140. data/vendor/libsodium/test/constcheck.sh +19 -0
  141. data/vendor/libsodium/test/default/Makefile.am +39 -7
  142. data/vendor/libsodium/test/default/aead_aes256gcm.c +6 -0
  143. data/vendor/libsodium/test/default/aead_chacha20poly1305.c +16 -0
  144. data/vendor/libsodium/test/default/aead_xchacha20poly1305.c +25 -15
  145. data/vendor/libsodium/test/default/auth.c +13 -0
  146. data/vendor/libsodium/test/default/auth.exp +8 -0
  147. data/vendor/libsodium/test/default/box.c +3 -0
  148. data/vendor/libsodium/test/default/box2.c +2 -0
  149. data/vendor/libsodium/test/default/box_easy.c +1 -4
  150. data/vendor/libsodium/test/default/box_easy2.c +7 -3
  151. data/vendor/libsodium/test/default/chacha20.c +9 -2
  152. data/vendor/libsodium/test/default/cmptest.h +47 -1
  153. data/vendor/libsodium/test/default/codecs.c +226 -0
  154. data/vendor/libsodium/test/default/codecs.exp +28 -0
  155. data/vendor/libsodium/test/default/core3.c +42 -15
  156. data/vendor/libsodium/test/default/ed25519_convert.c +17 -0
  157. data/vendor/libsodium/test/default/kdf.c +8 -4
  158. data/vendor/libsodium/test/default/keygen.c +5 -2
  159. data/vendor/libsodium/test/default/kx.c +30 -0
  160. data/vendor/libsodium/test/default/metamorphic.c +187 -0
  161. data/vendor/libsodium/test/default/metamorphic.exp +1 -0
  162. data/vendor/libsodium/test/default/misuse.c +145 -0
  163. data/vendor/libsodium/test/default/misuse.exp +0 -0
  164. data/vendor/libsodium/test/default/onetimeauth.c +2 -0
  165. data/vendor/libsodium/test/default/{pwhash.c → pwhash_argon2i.c} +133 -106
  166. data/vendor/libsodium/test/default/{pwhash.exp → pwhash_argon2i.exp} +0 -1
  167. data/vendor/libsodium/test/default/pwhash_argon2id.c +254 -144
  168. data/vendor/libsodium/test/default/pwhash_argon2id.exp +2 -3
  169. data/vendor/libsodium/test/default/pwhash_scrypt.c +61 -18
  170. data/vendor/libsodium/test/default/pwhash_scrypt.exp +6 -0
  171. data/vendor/libsodium/test/default/randombytes.c +8 -3
  172. data/vendor/libsodium/test/default/secretbox.c +8 -0
  173. data/vendor/libsodium/test/default/secretbox2.c +5 -0
  174. data/vendor/libsodium/test/default/secretbox_easy.c +19 -1
  175. data/vendor/libsodium/test/default/secretbox_easy.exp +2 -0
  176. data/vendor/libsodium/test/default/secretbox_easy2.c +4 -0
  177. data/vendor/libsodium/test/default/secretstream.c +280 -0
  178. data/vendor/libsodium/test/default/secretstream.exp +1 -0
  179. data/vendor/libsodium/test/default/sign.c +31 -0
  180. data/vendor/libsodium/test/default/sodium_core.c +23 -1
  181. data/vendor/libsodium/test/default/sodium_core.exp +1 -1
  182. data/vendor/libsodium/test/default/sodium_utils.c +45 -56
  183. data/vendor/libsodium/test/default/sodium_utils.exp +0 -8
  184. data/vendor/libsodium/test/default/stream.c +2 -0
  185. data/vendor/libsodium/test/default/stream2.c +1 -0
  186. data/vendor/libsodium/test/default/xchacha20.c +58 -7
  187. metadata +21 -18
  188. data/vendor/libsodium/dist-build/emscripten-wasm.sh +0 -132
  189. data/vendor/libsodium/m4/pkg.m4 +0 -214
  190. data/vendor/libsodium/packaging/dotnet-core/desktop.targets +0 -16
  191. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/afternm_aes128ctr.c +0 -174
  192. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/beforenm_aes128ctr.c +0 -66
  193. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/common.h +0 -766
  194. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts.h +0 -28
  195. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts_aes128ctr.c +0 -28
  196. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128.h +0 -50
  197. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128_aes128ctr.c +0 -149
  198. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/stream_aes128ctr_nacl.c +0 -31
  199. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/xor_afternm_aes128ctr.c +0 -195
  200. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/stream_aes128ctr.c +0 -19
  201. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +0 -65
@@ -4,12 +4,11 @@
4
4
  [tv] pwhash failure (maybe intentional): [3]
5
5
  08d8cd330c57e1b4643241d05bb468ba4ee4e932cd0858816be9ef15360b27bbd06a87130ee92222be267a29b81f5ae8fe8613324cfc4832dc49387fd0602f1c57b4d0f3855db94fb7e12eb05f9a484aed4a4307abf586cd3d55c809bc081541e00b682772fb2066504ff935b8ebc551a2083882f874bc0fae68e56848ae34c91097c3bf0cca8e75c0797eef3efde3f75e005815018db3cf7c109a812264c4de69dcb22322dbbcfa447f5b00ecd1b04a7be1569c8e556adb7bba48adf81d
6
6
  d6e9d6cabd42fb9ba7162fe9b8e41d59d3c7034756cb460c9affe393308bd0225ce0371f2e6c3ca32aca2002bf2d3909c6b6e7dfc4a00e850ff4f570f8f749d4bb6f0091e554be67a9095ae1eefaa1a933316cbec3c2fd4a14a5b6941bda9b7eabd821d79abde2475a53af1a8571c7ee46460be415882e0b393f48c12f740a6a72cba9773000602e13b40d3dfa6ac1d4ec43a838b7e3e165fecad4b2498389e60a3ff9f0f8f4b9fca1126e64f49501e38690
7
- [tv] pwhash failure (maybe intentional): [6]
7
+ 7fb72409b0987f8190c3729710e98c3f80c5a8727d425fdcde7f3644d467fe973f5b5fee683bd3fce812cb9ae5e9921a2d06c2f1905e4e839692f2b934b682f11a2fe2b90482ea5dd234863516dba6f52dc0702d324ec77d860c2e181f84472bd7104fedce071ffa93c5309494ad51623d214447a7b2b1462dc7d5d55a1f6fd5b54ce024118d86f0c6489d16545aaa87b6689dad9f2fb47fda9894f8e12b87d978b483ccd4cc5fd9595cdc7a818452f915ce2f7df95ec12b1c72e3788d473441d884f9748eb14703c21b45d82fd667b85f5b2d98c13303b3fe76285531a826b6fc0fe8e3dddecf
8
8
  4e702bc5f891df884c6ddaa243aa846ce3c087fe930fef0f36b3c2be34164ccc295db509254743f18f947159c813bcd5dd8d94a3aec93bbe57605d1fad1aef1112687c3d4ef1cb329d21f1632f626818d766915d886e8d819e4b0b9c9307f4b6afc081e13b0cf31db382ff1bf05a16aac7af696336d75e99f82163e0f371e1d25c4add808e215697ad3f779a51a462f8bf52610af21fc69dba6b072606f2dabca7d4ae1d91d919
9
9
  2d232f9dc4de96628b2a4c2b39ceb6a813011fb74a3ba1da096761fabe08f563bd91366aba5c5e35aecd98643cabc16ce560dca261a963230a1fa2af52f2413a57a827c6ee13bcec0c123d195914a55700ccb5756196a86fb9cb4aeacccc0e6dd850f4386b705aaae147ea347543b7fbe24553d9da41f1b335b6e9980cdb966cf7b48520eb42a7269380c885dbefbccf447851fcacbe1753a5b9e1
10
10
  34b207147fb7ef83e1ca1a97e30aa6e08ea9b6b1048c59c9c13050dff33e76ce3c440d7f018f817e6b8593e78f339ba633b9d7ec3519b5eafbcc4bc2d20b5136bbc7e5b7e92ff37d024bbbecf5738f718ab22c8adcdb82ceffc233b8ad61f91850abdfe8bb119775d9c4243ec1ac761dfbd132489228dfeab5268c7f0ddc29f56b957d1b76c874cdd77e16139e0df9b847248fd782c9a1147b8480
11
11
  [tv3] pwhash_argon2id_str failure (maybe intentional): [0]
12
12
  [tv3] pwhash_argon2id_str failure (maybe intentional): [1]
13
- [tv3] pwhash_argon2id_str failure (maybe intentional): [2]
14
13
  [tv3] pwhash_argon2id_str failure (maybe intentional): [3]
15
- pwhash_argon2id_str failure
14
+ OK
@@ -10,9 +10,9 @@ static void
10
10
  tv(void)
11
11
  {
12
12
  static struct {
13
- const char * passwd_hex;
13
+ const char *passwd_hex;
14
14
  size_t passwdlen;
15
- const char * salt_hex;
15
+ const char *salt_hex;
16
16
  size_t outlen;
17
17
  unsigned long long opslimit;
18
18
  size_t memlimit;
@@ -117,9 +117,9 @@ static void
117
117
  tv2(void)
118
118
  {
119
119
  static struct {
120
- const char * passwd_hex;
120
+ const char *passwd_hex;
121
121
  size_t passwdlen;
122
- const char * salt_hex;
122
+ const char *salt_hex;
123
123
  size_t outlen;
124
124
  unsigned long long opslimit;
125
125
  size_t memlimit;
@@ -260,8 +260,19 @@ tv3(void)
260
260
  { "Y0!?iQa9M%5ekffW(`", "$7$" },
261
261
  { "Y0!?iQa9M%5ekffW(`", "" },
262
262
  { "Y0!?iQa9M%5ekffW(`",
263
- "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
264
- "" },
263
+ "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$" },
264
+ { "test",
265
+ "$7$.6..../.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
266
+ { "test",
267
+ "$7$z6..../.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
268
+ { "test",
269
+ "$7$8zzzzz/.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
270
+ { "test",
271
+ "$7$8zzzzzzzzzz.lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
272
+ { "test",
273
+ "$7$8.....zzzzz.lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
274
+ { "test",
275
+ "$7$86..../..../lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." }
265
276
  };
266
277
  char * out;
267
278
  char * passwd;
@@ -283,17 +294,14 @@ tv3(void)
283
294
  } while (++i < (sizeof tests) / (sizeof tests[0]));
284
295
  }
285
296
 
286
- int
287
- main(void)
297
+ static void
298
+ str_tests(void)
288
299
  {
289
- char * str_out;
290
- char * str_out2;
291
- char * salt;
300
+ char *str_out;
301
+ char *str_out2;
302
+ char *salt;
292
303
  const char *passwd = "Correct Horse Battery Staple";
293
304
 
294
- tv();
295
- tv2();
296
- tv3();
297
305
  salt = (char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
298
306
  str_out =
299
307
  (char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
@@ -312,6 +320,24 @@ main(void)
312
320
  if (strcmp(str_out, str_out2) == 0) {
313
321
  printf("pwhash_str doesn't generate different salts\n");
314
322
  }
323
+ if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
324
+ (str_out, OPSLIMIT, MEMLIMIT) != 0) {
325
+ printf("needs_rehash() false positive\n");
326
+ }
327
+ if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
328
+ (str_out, OPSLIMIT, MEMLIMIT / 2) != 1 ||
329
+ crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
330
+ (str_out, OPSLIMIT / 2, MEMLIMIT) != 1 ||
331
+ crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
332
+ (str_out, OPSLIMIT, MEMLIMIT * 2) != 1 ||
333
+ crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
334
+ (str_out, OPSLIMIT * 2, MEMLIMIT) != 1) {
335
+ printf("needs_rehash() false negative\n");
336
+ }
337
+ if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
338
+ (str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
339
+ printf("needs_rehash() didn't fail with an invalid hash string\n");
340
+ }
315
341
  if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
316
342
  strlen(passwd)) != 0) {
317
343
  printf("pwhash_str_verify failure\n");
@@ -328,6 +354,27 @@ main(void)
328
354
  str_out[14]--;
329
355
 
330
356
  assert(str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U] == 0);
357
+
358
+ assert(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
359
+ (str_out, 0, 0) == 1);
360
+ assert(crypto_pwhash_str_needs_rehash(str_out, 0, 0) == -1);
361
+ assert(crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT) == -1);
362
+ assert(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
363
+ ("", OPSLIMIT, MEMLIMIT) == -1);
364
+
365
+ sodium_free(salt);
366
+ sodium_free(str_out);
367
+ sodium_free(str_out2);
368
+ }
369
+
370
+ int
371
+ main(void)
372
+ {
373
+ tv();
374
+ tv2();
375
+ tv3();
376
+ str_tests();
377
+
331
378
  assert(crypto_pwhash_scryptsalsa208sha256_bytes_min() > 0U);
332
379
  assert(crypto_pwhash_scryptsalsa208sha256_bytes_max() >
333
380
  crypto_pwhash_scryptsalsa208sha256_bytes_min());
@@ -347,10 +394,6 @@ main(void)
347
394
  assert(crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() > 0U);
348
395
  assert(crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() > 0U);
349
396
 
350
- sodium_free(salt);
351
- sodium_free(str_out);
352
- sodium_free(str_out2);
353
-
354
397
  printf("OK\n");
355
398
 
356
399
  return 0;
@@ -29,4 +29,10 @@ pwhash_str failure: [24]
29
29
  pwhash_str failure: [25]
30
30
  pwhash_str failure: [26]
31
31
  pwhash_str failure: [27]
32
+ pwhash_str failure: [28]
33
+ pwhash_str failure: [29]
34
+ pwhash_str failure: [30]
35
+ pwhash_str failure: [31]
36
+ pwhash_str failure: [32]
37
+ pwhash_str failure: [33]
32
38
  OK
@@ -39,12 +39,14 @@ randombytes_tests(void)
39
39
  unsigned int i;
40
40
  uint32_t n;
41
41
 
42
- #ifdef __EMSCRIPTEN__
42
+ #ifndef BENCHMARKS
43
+ # ifdef __EMSCRIPTEN__
43
44
  assert(strcmp(randombytes_implementation_name(), "js") == 0);
44
- #elif defined(__native_client__)
45
+ # elif defined(__native_client__)
45
46
  assert(strcmp(randombytes_implementation_name(), "nativeclient") == 0);
46
- #else
47
+ # else
47
48
  assert(strcmp(randombytes_implementation_name(), "sysrandom") == 0);
49
+ # endif
48
50
  #endif
49
51
  randombytes(x, 1U);
50
52
  do {
@@ -137,6 +139,7 @@ impl_tests(void)
137
139
  impl.uniform = randombytes_uniform_impl;
138
140
  randombytes_close();
139
141
  randombytes_set_implementation(&impl);
142
+ assert(randombytes_uniform(1) == 1);
140
143
  assert(randombytes_uniform(v) == v);
141
144
  assert(randombytes_uniform(v) == v);
142
145
  assert(randombytes_uniform(v) == v);
@@ -158,5 +161,7 @@ main(void)
158
161
  #endif
159
162
  printf("OK\n");
160
163
 
164
+ randombytes_set_implementation(&randombytes_salsa20_implementation);
165
+
161
166
  return 0;
162
167
  }
@@ -55,11 +55,17 @@ main(void)
55
55
  }
56
56
  printf("\n");
57
57
 
58
+ assert(crypto_secretbox(c, c, 31, nonce, firstkey) == -1);
59
+ assert(crypto_secretbox(c, c, 12, nonce, firstkey) == -1);
60
+ assert(crypto_secretbox(c, c, 1, nonce, firstkey) == -1);
61
+ assert(crypto_secretbox(c, c, 0, nonce, firstkey) == -1);
62
+
58
63
  assert(crypto_secretbox_keybytes() > 0U);
59
64
  assert(crypto_secretbox_noncebytes() > 0U);
60
65
  assert(crypto_secretbox_zerobytes() > 0U);
61
66
  assert(crypto_secretbox_boxzerobytes() > 0U);
62
67
  assert(crypto_secretbox_macbytes() > 0U);
68
+ assert(crypto_secretbox_messagebytes_max() > 0U);
63
69
  assert(strcmp(crypto_secretbox_primitive(), "xsalsa20poly1305") == 0);
64
70
  assert(crypto_secretbox_keybytes() ==
65
71
  crypto_secretbox_xsalsa20poly1305_keybytes());
@@ -71,6 +77,8 @@ main(void)
71
77
  crypto_secretbox_xsalsa20poly1305_boxzerobytes());
72
78
  assert(crypto_secretbox_macbytes() ==
73
79
  crypto_secretbox_xsalsa20poly1305_macbytes());
80
+ assert(crypto_secretbox_messagebytes_max() ==
81
+ crypto_secretbox_xsalsa20poly1305_messagebytes_max());
74
82
 
75
83
  return 0;
76
84
  }
@@ -46,5 +46,10 @@ main(void)
46
46
  }
47
47
  printf("\n");
48
48
  }
49
+ assert(crypto_secretbox_open(m, c, 31, nonce, firstkey) == -1);
50
+ assert(crypto_secretbox_open(m, c, 16, nonce, firstkey) == -1);
51
+ assert(crypto_secretbox_open(m, c, 1, nonce, firstkey) == -1);
52
+ assert(crypto_secretbox_open(m, c, 0, nonce, firstkey) == -1);
53
+
49
54
  return 0;
50
55
  }
@@ -76,7 +76,7 @@ main(void)
76
76
  }
77
77
  printf("\n");
78
78
 
79
- assert(crypto_secretbox_easy(c, m, SIZE_MAX - 1U, nonce, firstkey) == -1);
79
+ assert(crypto_secretbox_easy(c, m, 0, nonce, firstkey) == 0);
80
80
 
81
81
  /* Null message */
82
82
 
@@ -99,6 +99,24 @@ main(void)
99
99
  printf("Null tampered crypto_secretbox_open_easy() failed\n");
100
100
  }
101
101
 
102
+ /* No overlap, but buffers are next to each other */
103
+
104
+ memset(c, 0, 131 + crypto_secretbox_MACBYTES + 1);
105
+ memcpy(c, m, 20);
106
+ crypto_secretbox_easy(c, c + 10, 10, nonce, firstkey);
107
+ for (i = 0; i < 10 + crypto_secretbox_MACBYTES; ++i) {
108
+ printf(",0x%02x", (unsigned int) c[i]);
109
+ }
110
+ printf("\n");
111
+
112
+ memset(c, 0, 131 + crypto_secretbox_MACBYTES + 1);
113
+ memcpy(c, m, 20);
114
+ crypto_secretbox_easy(c + 10, c, 10, nonce, firstkey);
115
+ for (i = 0; i < 10 + crypto_secretbox_MACBYTES; ++i) {
116
+ printf(",0x%02x", (unsigned int) c[i]);
117
+ }
118
+ printf("\n");
119
+
102
120
  sodium_free(mac);
103
121
  sodium_free(c);
104
122
 
@@ -5,3 +5,5 @@
5
5
  ,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74,0xe3,0x55,0xa5
6
6
  ,0x25,0x39,0x12,0x1d,0x8e,0x23,0x4e,0x65,0x2d,0x65,0x1f,0xa4,0xc8,0xcf,0xf8,0x80,0x8e
7
7
  ,0x25,0x39,0x12,0x1d,0x8e,0x23,0x4e,0x65,0x2d,0x65,0x1f,0xa4,0xc8,0xcf,0xf8,0x80,0x8e
8
+ ,0x8c,0xf3,0x90,0x57,0xc9,0xbc,0xf2,0xba,0x98,0x87,0xfb,0x15,0x9f,0x21,0x0c,0xd8,0x23,0x88,0x8f,0xb1,0x78,0x92,0xb2,0x8e,0xc8,0xa8
9
+ ,0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5,0xcf,0x14,0xd2,0xe8,0xe8,0x1a,0xac,0xd2,0xba,0x1b,0xaa,0x60,0x99,0xe3,0xd9,0x63,0x56,0x18
@@ -40,6 +40,10 @@ main(void)
40
40
  }
41
41
  }
42
42
  crypto_secretbox_detached(c, mac, m, (unsigned long long) mlen, nonce, k);
43
+ if (crypto_secretbox_open_detached(NULL, c, mac, (unsigned long long) mlen,
44
+ nonce, k) != 0) {
45
+ printf("crypto_secretbox_open_detached() with a NULL message pointer failed\n");
46
+ }
43
47
  if (crypto_secretbox_open_detached(m2, c, mac, (unsigned long long) mlen,
44
48
  nonce, k) != 0) {
45
49
  printf("crypto_secretbox_open_detached() failed\n");
@@ -0,0 +1,280 @@
1
+
2
+ #define TEST_NAME "secretstream"
3
+ #include "cmptest.h"
4
+
5
+ int
6
+ main(void)
7
+ {
8
+ crypto_secretstream_xchacha20poly1305_state *state;
9
+ crypto_secretstream_xchacha20poly1305_state state_copy;
10
+ unsigned char *ad;
11
+ unsigned char *header;
12
+ unsigned char *k;
13
+ unsigned char *c1, *c2, *c3;
14
+ unsigned char *m1, *m2, *m3;
15
+ unsigned char *m1_, *m2_, *m3_;
16
+ unsigned long long res_len;
17
+ size_t ad_len;
18
+ size_t m1_len, m2_len, m3_len;
19
+ int ret;
20
+ unsigned char tag;
21
+
22
+ state = (crypto_secretstream_xchacha20poly1305_state *)
23
+ sodium_malloc(crypto_secretstream_xchacha20poly1305_statebytes());
24
+ header = (unsigned char *)
25
+ sodium_malloc(crypto_secretstream_xchacha20poly1305_HEADERBYTES);
26
+
27
+ ad_len = randombytes_uniform(100);
28
+ m1_len = randombytes_uniform(1000);
29
+ m2_len = randombytes_uniform(1000);
30
+ m3_len = randombytes_uniform(1000);
31
+
32
+ c1 = (unsigned char *)
33
+ sodium_malloc(m1_len + crypto_secretstream_xchacha20poly1305_ABYTES);
34
+ c2 = (unsigned char *)
35
+ sodium_malloc(m2_len + crypto_secretstream_xchacha20poly1305_ABYTES);
36
+ c3 = (unsigned char *)
37
+ sodium_malloc(m3_len + crypto_secretstream_xchacha20poly1305_ABYTES);
38
+
39
+ ad = (unsigned char *) sodium_malloc(ad_len);
40
+ m1 = (unsigned char *) sodium_malloc(m1_len);
41
+ m2 = (unsigned char *) sodium_malloc(m2_len);
42
+ m3 = (unsigned char *) sodium_malloc(m3_len);
43
+ m1_ = (unsigned char *) sodium_malloc(m1_len);
44
+ m2_ = (unsigned char *) sodium_malloc(m2_len);
45
+ m3_ = (unsigned char *) sodium_malloc(m3_len);
46
+
47
+ randombytes_buf(ad, ad_len);
48
+
49
+ randombytes_buf(m1, m1_len);
50
+ memcpy(m1_, m1, m1_len);
51
+ randombytes_buf(m2, m2_len);
52
+ memcpy(m2_, m2, m2_len);
53
+ randombytes_buf(m3, m3_len);
54
+ memcpy(m3_, m3, m3_len);
55
+
56
+ k = (unsigned char *)
57
+ sodium_malloc(crypto_secretstream_xchacha20poly1305_KEYBYTES);
58
+ crypto_secretstream_xchacha20poly1305_keygen(k);
59
+
60
+ /* push */
61
+
62
+ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k);
63
+ assert(ret == 0);
64
+
65
+ ret = crypto_secretstream_xchacha20poly1305_push
66
+ (state, c1, &res_len, m1, m1_len, NULL, 0, 0);
67
+ assert(ret == 0);
68
+ assert(res_len == m1_len + crypto_secretstream_xchacha20poly1305_ABYTES);
69
+
70
+ ret = crypto_secretstream_xchacha20poly1305_push
71
+ (state, c2, NULL, m2, m2_len, ad, 0, 0);
72
+ assert(ret == 0);
73
+
74
+ ret = crypto_secretstream_xchacha20poly1305_push
75
+ (state, c3, NULL, m3, m3_len, ad, ad_len,
76
+ crypto_secretstream_xchacha20poly1305_TAG_FINAL);
77
+ assert(ret == 0);
78
+
79
+ /* pull */
80
+
81
+ ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k);
82
+ assert(ret == 0);
83
+
84
+ ret = crypto_secretstream_xchacha20poly1305_pull
85
+ (state, m1, &res_len, &tag,
86
+ c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
87
+ assert(ret == 0);
88
+ assert(tag == 0);
89
+ assert(memcmp(m1, m1_, m1_len) == 0);
90
+ assert(res_len == m1_len);
91
+
92
+ ret = crypto_secretstream_xchacha20poly1305_pull
93
+ (state, m2, NULL, &tag,
94
+ c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
95
+ assert(ret == 0);
96
+ assert(tag == 0);
97
+ assert(memcmp(m2, m2_, m2_len) == 0);
98
+
99
+ if (ad_len > 0) {
100
+ ret = crypto_secretstream_xchacha20poly1305_pull
101
+ (state, m3, NULL, &tag,
102
+ c3, m3_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
103
+ assert(ret == -1);
104
+ }
105
+ ret = crypto_secretstream_xchacha20poly1305_pull
106
+ (state, m3, NULL, &tag,
107
+ c3, m3_len + crypto_secretstream_xchacha20poly1305_ABYTES, ad, ad_len);
108
+ assert(ret == 0);
109
+ assert(tag == crypto_secretstream_xchacha20poly1305_TAG_FINAL);
110
+ assert(memcmp(m3, m3_, m3_len) == 0);
111
+
112
+ /* previous with FINAL tag */
113
+
114
+ ret = crypto_secretstream_xchacha20poly1305_pull
115
+ (state, m3, NULL, &tag,
116
+ c3, m3_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
117
+ assert(ret == -1);
118
+
119
+ /* previous without a tag */
120
+
121
+ ret = crypto_secretstream_xchacha20poly1305_pull
122
+ (state, m2, NULL, &tag,
123
+ c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
124
+ assert(ret == -1);
125
+
126
+ /* short ciphertext */
127
+
128
+ ret = crypto_secretstream_xchacha20poly1305_pull
129
+ (state, m2, NULL, &tag, c2,
130
+ randombytes_uniform(crypto_secretstream_xchacha20poly1305_ABYTES),
131
+ NULL, 0);
132
+ assert(ret == -1);
133
+ ret = crypto_secretstream_xchacha20poly1305_pull
134
+ (state, m2, NULL, &tag, c2, 0, NULL, 0);
135
+ assert(ret == -1);
136
+
137
+ /* empty ciphertext */
138
+
139
+ ret = crypto_secretstream_xchacha20poly1305_pull
140
+ (state, m2, NULL, &tag, c2,
141
+ crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
142
+ assert(ret == -1);
143
+
144
+ /* without explicit rekeying */
145
+
146
+ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k);
147
+ assert(ret == 0);
148
+ ret = crypto_secretstream_xchacha20poly1305_push
149
+ (state, c1, NULL, m1, m1_len, NULL, 0, 0);
150
+ assert(ret == 0);
151
+ ret = crypto_secretstream_xchacha20poly1305_push
152
+ (state, c2, NULL, m2, m2_len, NULL, 0, 0);
153
+ assert(ret == 0);
154
+
155
+ ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k);
156
+ assert(ret == 0);
157
+ ret = crypto_secretstream_xchacha20poly1305_pull
158
+ (state, m1, NULL, &tag,
159
+ c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
160
+ assert(ret == 0);
161
+ ret = crypto_secretstream_xchacha20poly1305_pull
162
+ (state, m2, NULL, &tag,
163
+ c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
164
+ assert(ret == 0);
165
+
166
+ /* with explicit rekeying */
167
+
168
+ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k);
169
+ assert(ret == 0);
170
+ ret = crypto_secretstream_xchacha20poly1305_push
171
+ (state, c1, NULL, m1, m1_len, NULL, 0, 0);
172
+ assert(ret == 0);
173
+
174
+ crypto_secretstream_xchacha20poly1305_rekey(state);
175
+
176
+ ret = crypto_secretstream_xchacha20poly1305_push
177
+ (state, c2, NULL, m2, m2_len, NULL, 0, 0);
178
+ assert(ret == 0);
179
+
180
+ ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k);
181
+ assert(ret == 0);
182
+ ret = crypto_secretstream_xchacha20poly1305_pull
183
+ (state, m1, NULL, &tag,
184
+ c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
185
+ assert(ret == 0);
186
+
187
+ ret = crypto_secretstream_xchacha20poly1305_pull
188
+ (state, m2, NULL, &tag,
189
+ c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
190
+ assert(ret == -1);
191
+
192
+ crypto_secretstream_xchacha20poly1305_rekey(state);
193
+
194
+ ret = crypto_secretstream_xchacha20poly1305_pull
195
+ (state, m2, NULL, &tag,
196
+ c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
197
+ assert(ret == 0);
198
+
199
+ /* New stream */
200
+
201
+ ret = crypto_secretstream_xchacha20poly1305_init_push(state, header, k);
202
+ assert(ret == 0);
203
+
204
+ ret = crypto_secretstream_xchacha20poly1305_push
205
+ (state, c1, &res_len, m1, m1_len, NULL, 0,
206
+ crypto_secretstream_xchacha20poly1305_TAG_PUSH);
207
+ assert(ret == 0);
208
+ assert(res_len == m1_len + crypto_secretstream_xchacha20poly1305_ABYTES);
209
+
210
+ /* Force a counter overflow, check that the key has been updated
211
+ * even though the tag was not changed to REKEY */
212
+
213
+ memset(state->nonce, 0xff, 4U);
214
+ state_copy = *state;
215
+
216
+ ret = crypto_secretstream_xchacha20poly1305_push
217
+ (state, c2, NULL, m2, m2_len, ad, 0, 0);
218
+ assert(ret == 0);
219
+
220
+ assert(memcmp(state_copy.k, state->k, sizeof state->k) != 0);
221
+ assert(memcmp(state_copy.nonce, state->nonce, sizeof state->nonce) != 0);
222
+ assert(state->nonce[0] == 1U);
223
+ assert(sodium_is_zero(state->nonce + 1, 3U));
224
+
225
+ ret = crypto_secretstream_xchacha20poly1305_init_pull(state, header, k);
226
+ assert(ret == 0);
227
+
228
+ ret = crypto_secretstream_xchacha20poly1305_pull
229
+ (state, m1, &res_len, &tag,
230
+ c1, m1_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
231
+ assert(ret == 0);
232
+ assert(tag == crypto_secretstream_xchacha20poly1305_TAG_PUSH);
233
+ assert(memcmp(m1, m1_, m1_len) == 0);
234
+ assert(res_len == m1_len);
235
+
236
+ memset(state->nonce, 0xff, 4U);
237
+
238
+ ret = crypto_secretstream_xchacha20poly1305_pull
239
+ (state, m2, NULL, &tag,
240
+ c2, m2_len + crypto_secretstream_xchacha20poly1305_ABYTES, NULL, 0);
241
+ assert(ret == 0);
242
+ assert(tag == 0);
243
+ assert(memcmp(m2, m2_, m2_len) == 0);
244
+
245
+ sodium_free(m3_);
246
+ sodium_free(m2_);
247
+ sodium_free(m1_);
248
+ sodium_free(m3);
249
+ sodium_free(m2);
250
+ sodium_free(m1);
251
+ sodium_free(ad);
252
+ sodium_free(c3);
253
+ sodium_free(c2);
254
+ sodium_free(c1);
255
+ sodium_free(k);
256
+ sodium_free(header);
257
+ sodium_free(state);
258
+
259
+ assert(crypto_secretstream_xchacha20poly1305_abytes() ==
260
+ crypto_secretstream_xchacha20poly1305_ABYTES);
261
+ assert(crypto_secretstream_xchacha20poly1305_headerbytes() ==
262
+ crypto_secretstream_xchacha20poly1305_HEADERBYTES);
263
+ assert(crypto_secretstream_xchacha20poly1305_keybytes() ==
264
+ crypto_secretstream_xchacha20poly1305_KEYBYTES);
265
+ assert(crypto_secretstream_xchacha20poly1305_messagebytes_max() ==
266
+ crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX);
267
+
268
+ assert(crypto_secretstream_xchacha20poly1305_tag_message() ==
269
+ crypto_secretstream_xchacha20poly1305_TAG_MESSAGE);
270
+ assert(crypto_secretstream_xchacha20poly1305_tag_push() ==
271
+ crypto_secretstream_xchacha20poly1305_TAG_PUSH);
272
+ assert(crypto_secretstream_xchacha20poly1305_tag_rekey() ==
273
+ crypto_secretstream_xchacha20poly1305_TAG_REKEY);
274
+ assert(crypto_secretstream_xchacha20poly1305_tag_final() ==
275
+ crypto_secretstream_xchacha20poly1305_TAG_FINAL);
276
+
277
+ printf("OK\n");
278
+
279
+ return 0;
280
+ }