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
@@ -8,6 +8,7 @@
8
8
  #include "argon2-core.h"
9
9
  #include "argon2.h"
10
10
  #include "crypto_pwhash_argon2id.h"
11
+ #include "private/common.h"
11
12
  #include "randombytes.h"
12
13
  #include "utils.h"
13
14
 
@@ -22,30 +23,36 @@ crypto_pwhash_argon2id_alg_argon2id13(void)
22
23
  size_t
23
24
  crypto_pwhash_argon2id_bytes_min(void)
24
25
  {
26
+ COMPILER_ASSERT(crypto_pwhash_argon2id_BYTES_MIN >= ARGON2_MIN_OUTLEN);
25
27
  return crypto_pwhash_argon2id_BYTES_MIN;
26
28
  }
27
29
 
28
30
  size_t
29
31
  crypto_pwhash_argon2id_bytes_max(void)
30
32
  {
33
+ COMPILER_ASSERT(crypto_pwhash_argon2id_BYTES_MAX <= ARGON2_MAX_OUTLEN);
31
34
  return crypto_pwhash_argon2id_BYTES_MAX;
32
35
  }
33
36
 
34
37
  size_t
35
38
  crypto_pwhash_argon2id_passwd_min(void)
36
39
  {
40
+ COMPILER_ASSERT(crypto_pwhash_argon2id_PASSWD_MIN >= ARGON2_MIN_PWD_LENGTH);
37
41
  return crypto_pwhash_argon2id_PASSWD_MIN;
38
42
  }
39
43
 
40
44
  size_t
41
45
  crypto_pwhash_argon2id_passwd_max(void)
42
46
  {
47
+ COMPILER_ASSERT(crypto_pwhash_argon2id_PASSWD_MAX <= ARGON2_MAX_PWD_LENGTH);
43
48
  return crypto_pwhash_argon2id_PASSWD_MAX;
44
49
  }
45
50
 
46
51
  size_t
47
52
  crypto_pwhash_argon2id_saltbytes(void)
48
53
  {
54
+ COMPILER_ASSERT(crypto_pwhash_argon2id_SALTBYTES >= ARGON2_MIN_SALT_LENGTH);
55
+ COMPILER_ASSERT(crypto_pwhash_argon2id_SALTBYTES <= ARGON2_MAX_SALT_LENGTH);
49
56
  return crypto_pwhash_argon2id_SALTBYTES;
50
57
  }
51
58
 
@@ -64,24 +71,28 @@ crypto_pwhash_argon2id_strprefix(void)
64
71
  size_t
65
72
  crypto_pwhash_argon2id_opslimit_min(void)
66
73
  {
74
+ COMPILER_ASSERT(crypto_pwhash_argon2id_OPSLIMIT_MIN >= ARGON2_MIN_TIME);
67
75
  return crypto_pwhash_argon2id_OPSLIMIT_MIN;
68
76
  }
69
77
 
70
78
  size_t
71
79
  crypto_pwhash_argon2id_opslimit_max(void)
72
80
  {
81
+ COMPILER_ASSERT(crypto_pwhash_argon2id_OPSLIMIT_MAX <= ARGON2_MAX_TIME);
73
82
  return crypto_pwhash_argon2id_OPSLIMIT_MAX;
74
83
  }
75
84
 
76
85
  size_t
77
86
  crypto_pwhash_argon2id_memlimit_min(void)
78
87
  {
88
+ COMPILER_ASSERT((crypto_pwhash_argon2id_MEMLIMIT_MIN / 1024U) >= ARGON2_MIN_MEMORY);
79
89
  return crypto_pwhash_argon2id_MEMLIMIT_MIN;
80
90
  }
81
91
 
82
92
  size_t
83
93
  crypto_pwhash_argon2id_memlimit_max(void)
84
94
  {
95
+ COMPILER_ASSERT((crypto_pwhash_argon2id_MEMLIMIT_MAX / 1024U) <= ARGON2_MAX_MEMORY);
85
96
  return crypto_pwhash_argon2id_MEMLIMIT_MAX;
86
97
  }
87
98
 
@@ -128,20 +139,29 @@ crypto_pwhash_argon2id(unsigned char *const out, unsigned long long outlen,
128
139
  unsigned long long opslimit, size_t memlimit, int alg)
129
140
  {
130
141
  memset(out, 0, outlen);
131
- memlimit /= 1024U;
132
- if (outlen > ARGON2_MAX_OUTLEN || passwdlen > ARGON2_MAX_PWD_LENGTH ||
133
- opslimit > ARGON2_MAX_TIME || memlimit > ARGON2_MAX_MEMORY) {
142
+ if (outlen > crypto_pwhash_argon2id_BYTES_MAX) {
134
143
  errno = EFBIG;
135
144
  return -1;
136
145
  }
137
- if (outlen < ARGON2_MIN_OUTLEN || passwdlen < ARGON2_MIN_PWD_LENGTH ||
138
- opslimit < ARGON2_MIN_TIME || memlimit < ARGON2_MIN_MEMORY) {
146
+ if (outlen < crypto_pwhash_argon2id_BYTES_MIN) {
147
+ errno = EINVAL;
148
+ return -1;
149
+ }
150
+ if (passwdlen > crypto_pwhash_argon2id_PASSWD_MAX ||
151
+ opslimit > crypto_pwhash_argon2id_OPSLIMIT_MAX ||
152
+ memlimit > crypto_pwhash_argon2id_MEMLIMIT_MAX) {
153
+ errno = EFBIG;
154
+ return -1;
155
+ }
156
+ if (passwdlen < crypto_pwhash_argon2id_PASSWD_MIN ||
157
+ opslimit < crypto_pwhash_argon2id_OPSLIMIT_MIN ||
158
+ memlimit < crypto_pwhash_argon2id_MEMLIMIT_MIN) {
139
159
  errno = EINVAL;
140
160
  return -1;
141
161
  }
142
162
  switch (alg) {
143
163
  case crypto_pwhash_argon2id_ALG_ARGON2ID13:
144
- if (argon2id_hash_raw((uint32_t) opslimit, (uint32_t) memlimit,
164
+ if (argon2id_hash_raw((uint32_t) opslimit, (uint32_t) (memlimit / 1024U),
145
165
  (uint32_t) 1U, passwd, (size_t) passwdlen, salt,
146
166
  (size_t) crypto_pwhash_argon2id_SALTBYTES, out,
147
167
  (size_t) outlen) != ARGON2_OK) {
@@ -163,19 +183,20 @@ crypto_pwhash_argon2id_str(char out[crypto_pwhash_argon2id_STRBYTES],
163
183
  unsigned char salt[crypto_pwhash_argon2id_SALTBYTES];
164
184
 
165
185
  memset(out, 0, crypto_pwhash_argon2id_STRBYTES);
166
- memlimit /= 1024U;
167
- if (passwdlen > ARGON2_MAX_PWD_LENGTH || opslimit > ARGON2_MAX_TIME ||
168
- memlimit > ARGON2_MAX_MEMORY) {
186
+ if (passwdlen > crypto_pwhash_argon2id_PASSWD_MAX ||
187
+ opslimit > crypto_pwhash_argon2id_OPSLIMIT_MAX ||
188
+ memlimit > crypto_pwhash_argon2id_MEMLIMIT_MAX) {
169
189
  errno = EFBIG;
170
190
  return -1;
171
191
  }
172
- if (passwdlen < ARGON2_MIN_PWD_LENGTH || opslimit < ARGON2_MIN_TIME ||
173
- memlimit < ARGON2_MIN_MEMORY) {
192
+ if (passwdlen < crypto_pwhash_argon2id_PASSWD_MIN ||
193
+ opslimit < crypto_pwhash_argon2id_OPSLIMIT_MIN ||
194
+ memlimit < crypto_pwhash_argon2id_MEMLIMIT_MIN) {
174
195
  errno = EINVAL;
175
196
  return -1;
176
197
  }
177
198
  randombytes_buf(salt, sizeof salt);
178
- if (argon2id_hash_encoded((uint32_t) opslimit, (uint32_t) memlimit,
199
+ if (argon2id_hash_encoded((uint32_t) opslimit, (uint32_t) (memlimit / 1024U),
179
200
  (uint32_t) 1U, passwd, (size_t) passwdlen, salt,
180
201
  sizeof salt, STR_HASHBYTES, out,
181
202
  crypto_pwhash_argon2id_STRBYTES) != ARGON2_OK) {
@@ -191,12 +212,12 @@ crypto_pwhash_argon2id_str_verify(const char str[crypto_pwhash_argon2id_STRBYTES
191
212
  {
192
213
  int verify_ret;
193
214
 
194
- if (passwdlen > ARGON2_MAX_PWD_LENGTH) {
215
+ if (passwdlen > crypto_pwhash_argon2id_PASSWD_MAX) {
195
216
  errno = EFBIG;
196
217
  return -1;
197
218
  }
198
219
  /* LCOV_EXCL_START */
199
- if (passwdlen < ARGON2_MIN_PWD_LENGTH) {
220
+ if (passwdlen < crypto_pwhash_argon2id_PASSWD_MIN) {
200
221
  errno = EINVAL;
201
222
  return -1;
202
223
  }
@@ -2,6 +2,7 @@
2
2
  #include <errno.h>
3
3
  #include <string.h>
4
4
 
5
+ #include "core.h"
5
6
  #include "crypto_pwhash.h"
6
7
 
7
8
  int
@@ -19,7 +20,7 @@ crypto_pwhash_alg_argon2id13(void)
19
20
  int
20
21
  crypto_pwhash_alg_default(void)
21
22
  {
22
- return crypto_pwhash_ALG_ARGON2I13;
23
+ return crypto_pwhash_ALG_DEFAULT;
23
24
  }
24
25
 
25
26
  size_t
@@ -131,10 +132,12 @@ crypto_pwhash(unsigned char * const out, unsigned long long outlen,
131
132
  unsigned long long opslimit, size_t memlimit, int alg)
132
133
  {
133
134
  switch (alg) {
134
- case crypto_pwhash_ALG_ARGON2ID13:
135
135
  case crypto_pwhash_ALG_ARGON2I13:
136
136
  return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt,
137
137
  opslimit, memlimit, alg);
138
+ case crypto_pwhash_ALG_ARGON2ID13:
139
+ return crypto_pwhash_argon2id(out, outlen, passwd, passwdlen, salt,
140
+ opslimit, memlimit, alg);
138
141
  default:
139
142
  errno = EINVAL;
140
143
  return -1;
@@ -146,8 +149,25 @@ crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
146
149
  const char * const passwd, unsigned long long passwdlen,
147
150
  unsigned long long opslimit, size_t memlimit)
148
151
  {
149
- return crypto_pwhash_argon2i_str(out, passwd, passwdlen,
150
- opslimit, memlimit);
152
+ return crypto_pwhash_argon2id_str(out, passwd, passwdlen,
153
+ opslimit, memlimit);
154
+ }
155
+
156
+ int
157
+ crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES],
158
+ const char * const passwd, unsigned long long passwdlen,
159
+ unsigned long long opslimit, size_t memlimit, int alg)
160
+ {
161
+ switch (alg) {
162
+ case crypto_pwhash_ALG_ARGON2I13:
163
+ return crypto_pwhash_argon2i_str(out, passwd, passwdlen,
164
+ opslimit, memlimit);
165
+ case crypto_pwhash_ALG_ARGON2ID13:
166
+ return crypto_pwhash_argon2id_str(out, passwd, passwdlen,
167
+ opslimit, memlimit);
168
+ }
169
+ sodium_misuse();
170
+ /* NOTREACHED */
151
171
  }
152
172
 
153
173
  int
@@ -168,6 +188,23 @@ crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES],
168
188
  return -1;
169
189
  }
170
190
 
191
+ int
192
+ crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
193
+ unsigned long long opslimit, size_t memlimit)
194
+ {
195
+ if (strncmp(str, crypto_pwhash_argon2id_STRPREFIX,
196
+ sizeof crypto_pwhash_argon2id_STRPREFIX - 1) == 0) {
197
+ return crypto_pwhash_argon2id_str_needs_rehash(str, opslimit, memlimit);
198
+ }
199
+ if (strncmp(str, crypto_pwhash_argon2i_STRPREFIX,
200
+ sizeof crypto_pwhash_argon2i_STRPREFIX - 1) == 0) {
201
+ return crypto_pwhash_argon2i_str_needs_rehash(str, opslimit, memlimit);
202
+ }
203
+ errno = EINVAL;
204
+
205
+ return -1;
206
+ }
207
+
171
208
  const char *
172
209
  crypto_pwhash_primitive(void) {
173
210
  return crypto_pwhash_PRIMITIVE;
@@ -105,6 +105,34 @@ decode64_uint32(uint32_t *dst, uint32_t dstbits, const uint8_t *src)
105
105
  return src;
106
106
  }
107
107
 
108
+ const uint8_t *
109
+ escrypt_parse_setting(const uint8_t *setting,
110
+ uint32_t *N_log2_p, uint32_t *r_p, uint32_t *p_p)
111
+ {
112
+ const uint8_t *src;
113
+
114
+ if (setting[0] != '$' || setting[1] != '7' || setting[2] != '$') {
115
+ return NULL;
116
+ }
117
+ src = setting + 3;
118
+
119
+ if (decode64_one(N_log2_p, *src)) {
120
+ return NULL;
121
+ }
122
+ src++;
123
+
124
+ src = decode64_uint32(r_p, 30, src);
125
+ if (!src) {
126
+ return NULL;
127
+ }
128
+
129
+ src = decode64_uint32(p_p, 30, src);
130
+ if (!src) {
131
+ return NULL;
132
+ }
133
+ return src;
134
+ }
135
+
108
136
  uint8_t *
109
137
  escrypt_r(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
110
138
  const uint8_t *setting, uint8_t *buf, size_t buflen)
@@ -122,25 +150,11 @@ escrypt_r(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
122
150
  uint32_t r;
123
151
  uint32_t p;
124
152
 
125
- if (setting[0] != '$' || setting[1] != '7' || setting[2] != '$') {
126
- return NULL;
127
- }
128
- src = setting + 3;
129
-
130
- if (decode64_one(&N_log2, *src)) {
131
- return NULL;
132
- }
133
- src++;
134
- N = (uint64_t) 1 << N_log2;
135
-
136
- src = decode64_uint32(&r, 30, src);
137
- if (!src) {
138
- return NULL;
139
- }
140
- src = decode64_uint32(&p, 30, src);
153
+ src = escrypt_parse_setting(setting, &N_log2, &r, &p);
141
154
  if (!src) {
142
155
  return NULL;
143
156
  }
157
+ N = (uint64_t) 1 << N_log2;
144
158
  prefixlen = src - setting;
145
159
 
146
160
  salt = src;
@@ -195,7 +209,7 @@ escrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p, const uint8_t *src,
195
209
  return NULL; /* LCOV_EXCL_LINE */
196
210
  }
197
211
  if (N_log2 > 63 || ((uint64_t) r * (uint64_t) p >= (1U << 30))) {
198
- return NULL;
212
+ return NULL; /* LCOV_EXCL_LINE */
199
213
  }
200
214
  dst = buf;
201
215
  *dst++ = '$';
@@ -91,4 +91,8 @@ extern uint8_t *escrypt_gensalt_r(uint32_t __N_log2, uint32_t __r, uint32_t __p,
91
91
  const uint8_t *__src, size_t __srclen,
92
92
  uint8_t *__buf, size_t __buflen);
93
93
 
94
+ extern const uint8_t *escrypt_parse_setting(const uint8_t *setting,
95
+ uint32_t *N_log2_p, uint32_t *r_p,
96
+ uint32_t *p_p);
97
+
94
98
  #endif /* !_CRYPTO_SCRYPT_H_ */
@@ -31,7 +31,9 @@
31
31
 
32
32
  #include <sys/types.h>
33
33
 
34
+ #include "core.h"
34
35
  #include "crypto_auth_hmacsha256.h"
36
+ #include "crypto_pwhash_scryptsalsa208sha256.h"
35
37
  #include "pbkdf2-sha256.h"
36
38
  #include "private/common.h"
37
39
  #include "utils.h"
@@ -55,8 +57,10 @@ PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen, const uint8_t *salt,
55
57
  size_t clen;
56
58
 
57
59
  #if SIZE_MAX > 0x1fffffffe0ULL
60
+ COMPILER_ASSERT(crypto_pwhash_scryptsalsa208sha256_BYTES_MAX
61
+ <= 0x1fffffffe0ULL);
58
62
  if (dkLen > 0x1fffffffe0ULL) {
59
- abort();
63
+ sodium_misuse(); /* LCOV_EXCL_LINE */
60
64
  }
61
65
  #endif
62
66
  crypto_auth_hmacsha256_init(&PShctx, passwd, passwdlen);
@@ -27,7 +27,7 @@ pickparams(unsigned long long opslimit, const size_t memlimit,
27
27
  }
28
28
  *r = 8;
29
29
  if (opslimit < memlimit / 32) {
30
- *p = 1;
30
+ *p = 1;
31
31
  maxN = opslimit / (*r * 4);
32
32
  for (*N_log2 = 1; *N_log2 < 63; *N_log2 += 1) {
33
33
  if ((uint64_t)(1) << *N_log2 > maxN / 2) {
@@ -254,3 +254,32 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(
254
254
 
255
255
  return ret;
256
256
  }
257
+
258
+ int
259
+ crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(
260
+ const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES],
261
+ unsigned long long opslimit, size_t memlimit)
262
+ {
263
+ uint32_t N_log2, N_log2_;
264
+ uint32_t p, p_;
265
+ uint32_t r, r_;
266
+
267
+ if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
268
+ errno = EINVAL;
269
+ return -1;
270
+ }
271
+ if (memchr(str, 0, crypto_pwhash_scryptsalsa208sha256_STRBYTES) !=
272
+ &str[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U]) {
273
+ errno = EINVAL;
274
+ return -1;
275
+ }
276
+ if (escrypt_parse_setting((const uint8_t *) str,
277
+ &N_log2_, &r_, &p_) == NULL) {
278
+ errno = EINVAL;
279
+ return -1;
280
+ }
281
+ if (N_log2 != N_log2_ || r != r_ || p != p_) {
282
+ return 1;
283
+ }
284
+ return 0;
285
+ }
@@ -318,10 +318,12 @@ escrypt_kdf_sse(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
318
318
 
319
319
  /* Sanity-check parameters. */
320
320
  # if SIZE_MAX > UINT32_MAX
321
+ /* LCOV_EXCL_START */
321
322
  if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
322
323
  errno = EFBIG;
323
324
  return -1;
324
325
  }
326
+ /* LCOV_EXCL_END */
325
327
  # endif
326
328
  if ((uint64_t)(r) * (uint64_t)(p) >= ((uint64_t) 1 << 30)) {
327
329
  errno = EFBIG;
@@ -339,6 +341,7 @@ escrypt_kdf_sse(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
339
341
  errno = EINVAL;
340
342
  return -1;
341
343
  }
344
+ /* LCOV_EXCL_START */
342
345
  if ((r > SIZE_MAX / 128 / p) ||
343
346
  # if SIZE_MAX / 256 <= UINT32_MAX
344
347
  (r > SIZE_MAX / 256) ||
@@ -347,21 +350,26 @@ escrypt_kdf_sse(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
347
350
  errno = ENOMEM;
348
351
  return -1;
349
352
  }
353
+ /* LCOV_EXCL_END */
350
354
 
351
355
  /* Allocate memory. */
352
356
  B_size = (size_t) 128 * r * p;
353
357
  V_size = (size_t) 128 * r * N;
354
358
  need = B_size + V_size;
359
+ /* LCOV_EXCL_START */
355
360
  if (need < V_size) {
356
361
  errno = ENOMEM;
357
362
  return -1;
358
363
  }
364
+ /* LCOV_EXCL_END */
359
365
  XY_size = (size_t) 256 * r + 64;
360
366
  need += XY_size;
367
+ /* LCOV_EXCL_START */
361
368
  if (need < XY_size) {
362
369
  errno = ENOMEM;
363
370
  return -1;
364
371
  }
372
+ /* LCOV_EXCL_END */
365
373
  if (local->size < need) {
366
374
  if (free_region(local)) {
367
375
  return -1; /* LCOV_EXCL_LINE */
@@ -20,11 +20,11 @@ int
20
20
  crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,
21
21
  const unsigned char *p)
22
22
  {
23
- size_t i;
24
- unsigned char d = 0;
23
+ size_t i;
24
+ volatile unsigned char d = 0;
25
25
 
26
26
  if (implementation->mult(q, n, p) != 0) {
27
- return -1;
27
+ return -1; /* LCOV_EXCL_LINE */
28
28
  }
29
29
  for (i = 0; i < crypto_scalarmult_curve25519_BYTES; i++) {
30
30
  d |= q[i];
@@ -32,6 +32,12 @@ crypto_secretbox_macbytes(void)
32
32
  return crypto_secretbox_MACBYTES;
33
33
  }
34
34
 
35
+ size_t
36
+ crypto_secretbox_messagebytes_max(void)
37
+ {
38
+ return crypto_secretbox_MESSAGEBYTES_MAX;
39
+ }
40
+
35
41
  const char *
36
42
  crypto_secretbox_primitive(void)
37
43
  {