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
@@ -83,7 +83,7 @@ crypto_sign_edwards25519sha512batch_open(unsigned char *m,
83
83
  ge_p3 cs3;
84
84
 
85
85
  *mlen_p = 0;
86
- if (smlen < 64 || smlen > SIZE_MAX) {
86
+ if (smlen < 64 || smlen - 64 > crypto_sign_edwards25519sha512batch_MESSAGEBYTES_MAX) {
87
87
  return -1;
88
88
  }
89
89
  mlen = smlen - 64;
@@ -33,8 +33,8 @@ crypto_sign_check_S_lt_L(const unsigned char *S)
33
33
  return -(c == 0);
34
34
  }
35
35
 
36
- static int
37
- small_order(const unsigned char R[32])
36
+ int
37
+ _crypto_sign_ed25519_small_order(const unsigned char p[32])
38
38
  {
39
39
  CRYPTO_ALIGN(16)
40
40
  static const unsigned char blacklist[][32] = {
@@ -97,7 +97,7 @@ small_order(const unsigned char R[32])
97
97
  for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {
98
98
  c = 0;
99
99
  for (j = 0; j < 32; j++) {
100
- c |= R[j] ^ blacklist[i][j];
100
+ c |= p[j] ^ blacklist[i][j];
101
101
  }
102
102
  if (c == 0) {
103
103
  return 1;
@@ -123,7 +123,8 @@ _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
123
123
  ge_p2 R;
124
124
 
125
125
  #ifndef ED25519_COMPAT
126
- if (crypto_sign_check_S_lt_L(sig + 32) != 0 || small_order(sig) != 0) {
126
+ if (crypto_sign_check_S_lt_L(sig + 32) != 0 ||
127
+ _crypto_sign_ed25519_small_order(sig) != 0) {
127
128
  return -1;
128
129
  }
129
130
  #else
@@ -170,7 +171,7 @@ crypto_sign_ed25519_open(unsigned char *m, unsigned long long *mlen_p,
170
171
  {
171
172
  unsigned long long mlen;
172
173
 
173
- if (smlen < 64 || smlen > SIZE_MAX) {
174
+ if (smlen < 64 || smlen - 64 > crypto_sign_ed25519_MESSAGEBYTES_MAX) {
174
175
  goto badsig;
175
176
  }
176
177
  mlen = smlen - 64;
@@ -35,6 +35,12 @@ crypto_sign_ed25519_secretkeybytes(void)
35
35
  return crypto_sign_ed25519_SECRETKEYBYTES;
36
36
  }
37
37
 
38
+ size_t
39
+ crypto_sign_ed25519_messagebytes_max(void)
40
+ {
41
+ return crypto_sign_ed25519_MESSAGEBYTES_MAX;
42
+ }
43
+
38
44
  int
39
45
  crypto_sign_ed25519_sk_to_seed(unsigned char *seed, const unsigned char *sk)
40
46
  {
@@ -3,6 +3,7 @@
3
3
  #include <stdlib.h>
4
4
  #include <string.h>
5
5
 
6
+ #include "core.h"
6
7
  #include "crypto_stream_chacha20.h"
7
8
  #include "private/common.h"
8
9
  #include "private/sse2_64_32.h"
@@ -76,8 +77,8 @@ chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c,
76
77
  if (!bytes) {
77
78
  return; /* LCOV_EXCL_LINE */
78
79
  }
79
- if (bytes > 64ULL * (1ULL << 32) - 64ULL) {
80
- abort();
80
+ if (bytes > crypto_stream_chacha20_MESSAGEBYTES_MAX) {
81
+ sodium_misuse();
81
82
  }
82
83
  # include "u8.h"
83
84
  # include "u4.h"
@@ -3,6 +3,7 @@
3
3
  #include <stdlib.h>
4
4
  #include <string.h>
5
5
 
6
+ #include "core.h"
6
7
  #include "crypto_stream_chacha20.h"
7
8
  #include "private/common.h"
8
9
  #include "private/sse2_64_32.h"
@@ -71,8 +72,8 @@ chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c,
71
72
  if (!bytes) {
72
73
  return; /* LCOV_EXCL_LINE */
73
74
  }
74
- if (bytes > 64ULL * (1ULL << 32) - 64ULL) {
75
- abort();
75
+ if (bytes > crypto_stream_chacha20_MESSAGEBYTES_MAX) {
76
+ sodium_misuse();
76
77
  }
77
78
  # include "u4.h"
78
79
  # include "u1.h"
@@ -7,7 +7,7 @@ if (bytes > 0) {
7
7
  _mm_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3);
8
8
  uint8_t partialblock[64];
9
9
 
10
- int i;
10
+ unsigned int i;
11
11
 
12
12
  x_0 = _mm_loadu_si128((__m128i*) (x + 0));
13
13
  x_1 = _mm_loadu_si128((__m128i*) (x + 4));
@@ -9,6 +9,7 @@
9
9
  #include <stdlib.h>
10
10
  #include <string.h>
11
11
 
12
+ #include "core.h"
12
13
  #include "crypto_stream_chacha20.h"
13
14
  #include "private/common.h"
14
15
  #include "utils.h"
@@ -91,8 +92,8 @@ chacha20_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c,
91
92
  if (!bytes) {
92
93
  return; /* LCOV_EXCL_LINE */
93
94
  }
94
- if (bytes > 64ULL * (1ULL << 32) - 64ULL) {
95
- abort();
95
+ if (bytes > crypto_stream_chacha20_MESSAGEBYTES_MAX) {
96
+ sodium_misuse();
96
97
  }
97
98
  j0 = ctx->input[0];
98
99
  j1 = ctx->input[1];
@@ -26,6 +26,12 @@ crypto_stream_chacha20_noncebytes(void) {
26
26
  return crypto_stream_chacha20_NONCEBYTES;
27
27
  }
28
28
 
29
+ size_t
30
+ crypto_stream_chacha20_messagebytes_max(void)
31
+ {
32
+ return crypto_stream_chacha20_MESSAGEBYTES_MAX;
33
+ }
34
+
29
35
  size_t
30
36
  crypto_stream_chacha20_ietf_keybytes(void) {
31
37
  return crypto_stream_chacha20_ietf_KEYBYTES;
@@ -36,6 +42,12 @@ crypto_stream_chacha20_ietf_noncebytes(void) {
36
42
  return crypto_stream_chacha20_ietf_NONCEBYTES;
37
43
  }
38
44
 
45
+ size_t
46
+ crypto_stream_chacha20_ietf_messagebytes_max(void)
47
+ {
48
+ return crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX;
49
+ }
50
+
39
51
  int
40
52
  crypto_stream_chacha20(unsigned char *c, unsigned long long clen,
41
53
  const unsigned char *n, const unsigned char *k)
@@ -14,6 +14,12 @@ crypto_stream_noncebytes(void)
14
14
  return crypto_stream_NONCEBYTES;
15
15
  }
16
16
 
17
+ size_t
18
+ crypto_stream_messagebytes_max(void)
19
+ {
20
+ return crypto_stream_MESSAGEBYTES_MAX;
21
+ }
22
+
17
23
  const char *
18
24
  crypto_stream_primitive(void)
19
25
  {
@@ -37,6 +37,12 @@ crypto_stream_salsa20_noncebytes(void)
37
37
  return crypto_stream_salsa20_NONCEBYTES;
38
38
  }
39
39
 
40
+ size_t
41
+ crypto_stream_salsa20_messagebytes_max(void)
42
+ {
43
+ return crypto_stream_salsa20_MESSAGEBYTES_MAX;
44
+ }
45
+
40
46
  int
41
47
  crypto_stream_salsa20(unsigned char *c, unsigned long long clen,
42
48
  const unsigned char *n, const unsigned char *k)
@@ -89,5 +95,5 @@ _crypto_stream_salsa20_pick_best_implementation(void)
89
95
  return 0;
90
96
  }
91
97
  #endif
92
- return 0;
98
+ return 0; /* LCOV_EXCL_LINE */
93
99
  }
@@ -7,7 +7,7 @@ if (bytes > 0) {
7
7
  __m128i b0, b1, b2, b3, b4, b5, b6, b7;
8
8
  uint8_t partialblock[64];
9
9
 
10
- int i;
10
+ unsigned int i;
11
11
 
12
12
  a0 = diag1;
13
13
  for (i = 0; i < ROUNDS; i += 4) {
@@ -13,6 +13,12 @@ crypto_stream_salsa2012_noncebytes(void)
13
13
  return crypto_stream_salsa2012_NONCEBYTES;
14
14
  }
15
15
 
16
+ size_t
17
+ crypto_stream_salsa2012_messagebytes_max(void)
18
+ {
19
+ return crypto_stream_salsa2012_MESSAGEBYTES_MAX;
20
+ }
21
+
16
22
  void
17
23
  crypto_stream_salsa2012_keygen(unsigned char k[crypto_stream_salsa2012_KEYBYTES])
18
24
  {
@@ -13,6 +13,12 @@ crypto_stream_salsa208_noncebytes(void)
13
13
  return crypto_stream_salsa208_NONCEBYTES;
14
14
  }
15
15
 
16
+ size_t
17
+ crypto_stream_salsa208_messagebytes_max(void)
18
+ {
19
+ return crypto_stream_salsa208_MESSAGEBYTES_MAX;
20
+ }
21
+
16
22
  void
17
23
  crypto_stream_salsa208_keygen(unsigned char k[crypto_stream_salsa208_KEYBYTES])
18
24
  {
@@ -19,6 +19,12 @@ crypto_stream_xchacha20_noncebytes(void)
19
19
  return crypto_stream_xchacha20_NONCEBYTES;
20
20
  }
21
21
 
22
+ size_t
23
+ crypto_stream_xchacha20_messagebytes_max(void)
24
+ {
25
+ return crypto_stream_xchacha20_MESSAGEBYTES_MAX;
26
+ }
27
+
22
28
  int
23
29
  crypto_stream_xchacha20(unsigned char *c, unsigned long long clen,
24
30
  const unsigned char *n, const unsigned char *k)
@@ -53,6 +53,12 @@ crypto_stream_xsalsa20_noncebytes(void)
53
53
  return crypto_stream_xsalsa20_NONCEBYTES;
54
54
  }
55
55
 
56
+ size_t
57
+ crypto_stream_xsalsa20_messagebytes_max(void)
58
+ {
59
+ return crypto_stream_xsalsa20_MESSAGEBYTES_MAX;
60
+ }
61
+
56
62
  void
57
63
  crypto_stream_xsalsa20_keygen(unsigned char k[crypto_stream_xsalsa20_KEYBYTES])
58
64
  {
@@ -6,56 +6,93 @@
6
6
  #include "crypto_verify_32.h"
7
7
  #include "crypto_verify_64.h"
8
8
 
9
- int
10
- crypto_verify_16(const unsigned char *x, const unsigned char *y)
9
+ size_t
10
+ crypto_verify_16_bytes(void)
11
11
  {
12
- uint_fast16_t d = 0U;
13
- int i;
12
+ return crypto_verify_16_BYTES;
13
+ }
14
14
 
15
- for (i = 0; i < 16; i++) {
16
- d |= x[i] ^ y[i];
17
- }
18
- return (1 & ((d - 1) >> 8)) - 1;
15
+ size_t
16
+ crypto_verify_32_bytes(void)
17
+ {
18
+ return crypto_verify_32_BYTES;
19
19
  }
20
20
 
21
21
  size_t
22
- crypto_verify_16_bytes(void)
22
+ crypto_verify_64_bytes(void)
23
23
  {
24
- return crypto_verify_16_BYTES;
24
+ return crypto_verify_64_BYTES;
25
25
  }
26
26
 
27
- int
28
- crypto_verify_32(const unsigned char *x, const unsigned char *y)
27
+ #if defined(HAVE_EMMINTRIN_H) && defined(__SSE2__)
28
+
29
+ # ifdef __GNUC__
30
+ # pragma GCC target("sse2")
31
+ # endif
32
+ # include <emmintrin.h>
33
+
34
+ static inline int
35
+ crypto_verify_n(const unsigned char *x_, const unsigned char *y_,
36
+ const int n)
29
37
  {
30
- uint_fast16_t d = 0U;
31
- int i;
38
+ const __m128i zero = _mm_setzero_si128();
39
+ volatile __m128i v1, v2, z;
40
+ volatile int m;
41
+ int i;
42
+
43
+ const volatile __m128i *volatile x =
44
+ (const volatile __m128i *volatile) (const void *) x_;
45
+ const volatile __m128i *volatile y =
46
+ (const volatile __m128i *volatile) (const void *) y_;
47
+ v1 = _mm_loadu_si128((const __m128i *) &x[0]);
48
+ v2 = _mm_loadu_si128((const __m128i *) &y[0]);
49
+ z = _mm_xor_si128(v1, v2);
50
+ for (i = 1; i < n / 16; i++) {
51
+ v1 = _mm_loadu_si128((const __m128i *) &x[i]);
52
+ v2 = _mm_loadu_si128((const __m128i *) &y[i]);
53
+ z = _mm_or_si128(z, _mm_xor_si128(v1, v2));
54
+ }
55
+ m = _mm_movemask_epi8(_mm_cmpeq_epi32(z, zero));
56
+ v1 = zero; v2 = zero; z = zero;
32
57
 
33
- for (i = 0; i < 32; i++) {
58
+ return (int) (((uint32_t) m + 1U) >> 16) - 1;
59
+ }
60
+
61
+ #else
62
+
63
+ static inline int
64
+ crypto_verify_n(const unsigned char *x_, const unsigned char *y_,
65
+ const int n)
66
+ {
67
+ const volatile unsigned char *volatile x =
68
+ (const volatile unsigned char *volatile) x_;
69
+ const volatile unsigned char *volatile y =
70
+ (const volatile unsigned char *volatile) y_;
71
+ volatile uint_fast16_t d = 0U;
72
+ int i;
73
+
74
+ for (i = 0; i < n; i++) {
34
75
  d |= x[i] ^ y[i];
35
76
  }
36
77
  return (1 & ((d - 1) >> 8)) - 1;
37
78
  }
38
79
 
39
- size_t
40
- crypto_verify_32_bytes(void)
80
+ #endif
81
+
82
+ int
83
+ crypto_verify_16(const unsigned char *x, const unsigned char *y)
41
84
  {
42
- return crypto_verify_32_BYTES;
85
+ return crypto_verify_n(x, y, crypto_verify_16_BYTES);
43
86
  }
44
87
 
45
88
  int
46
- crypto_verify_64(const unsigned char *x, const unsigned char *y)
89
+ crypto_verify_32(const unsigned char *x, const unsigned char *y)
47
90
  {
48
- uint_fast16_t d = 0U;
49
- int i;
50
-
51
- for (i = 0; i < 64; i++) {
52
- d |= x[i] ^ y[i];
53
- }
54
- return (1 & ((d - 1) >> 8)) - 1;
91
+ return crypto_verify_n(x, y, crypto_verify_32_BYTES);
55
92
  }
56
93
 
57
- size_t
58
- crypto_verify_64_bytes(void)
94
+ int
95
+ crypto_verify_64(const unsigned char *x, const unsigned char *y)
59
96
  {
60
- return crypto_verify_64_BYTES;
97
+ return crypto_verify_n(x, y, crypto_verify_64_BYTES);
61
98
  }
@@ -36,13 +36,13 @@ SODIUM_EXPORT = \
36
36
  sodium/crypto_secretbox.h \
37
37
  sodium/crypto_secretbox_xchacha20poly1305.h \
38
38
  sodium/crypto_secretbox_xsalsa20poly1305.h \
39
+ sodium/crypto_secretstream_xchacha20poly1305.h \
39
40
  sodium/crypto_shorthash.h \
40
41
  sodium/crypto_shorthash_siphash24.h \
41
42
  sodium/crypto_sign.h \
42
43
  sodium/crypto_sign_ed25519.h \
43
44
  sodium/crypto_sign_edwards25519sha512batch.h \
44
45
  sodium/crypto_stream.h \
45
- sodium/crypto_stream_aes128ctr.h \
46
46
  sodium/crypto_stream_chacha20.h \
47
47
  sodium/crypto_stream_salsa20.h \
48
48
  sodium/crypto_stream_salsa2012.h \
@@ -31,11 +31,11 @@
31
31
  #include "sodium/crypto_onetimeauth_poly1305.h"
32
32
  #include "sodium/crypto_pwhash.h"
33
33
  #include "sodium/crypto_pwhash_argon2i.h"
34
- #include "sodium/crypto_pwhash_scryptsalsa208sha256.h"
35
34
  #include "sodium/crypto_scalarmult.h"
36
35
  #include "sodium/crypto_scalarmult_curve25519.h"
37
36
  #include "sodium/crypto_secretbox.h"
38
37
  #include "sodium/crypto_secretbox_xsalsa20poly1305.h"
38
+ #include "sodium/crypto_secretstream_xchacha20poly1305.h"
39
39
  #include "sodium/crypto_shorthash.h"
40
40
  #include "sodium/crypto_shorthash_siphash24.h"
41
41
  #include "sodium/crypto_sign.h"
@@ -59,7 +59,7 @@
59
59
  #ifndef SODIUM_LIBRARY_MINIMAL
60
60
  # include "sodium/crypto_box_curve25519xchacha20poly1305.h"
61
61
  # include "sodium/crypto_secretbox_xchacha20poly1305.h"
62
- # include "sodium/crypto_stream_aes128ctr.h"
62
+ # include "sodium/crypto_pwhash_scryptsalsa208sha256.h"
63
63
  # include "sodium/crypto_stream_salsa2012.h"
64
64
  # include "sodium/crypto_stream_salsa208.h"
65
65
  # include "sodium/crypto_stream_xchacha20.h"
@@ -12,6 +12,15 @@ SODIUM_EXPORT
12
12
  int sodium_init(void)
13
13
  __attribute__ ((warn_unused_result));
14
14
 
15
+ /* ---- */
16
+
17
+ SODIUM_EXPORT
18
+ int sodium_set_misuse_handler(void (*handler)(void));
19
+
20
+ SODIUM_EXPORT
21
+ void sodium_misuse(void)
22
+ __attribute__ ((noreturn));
23
+
15
24
  #ifdef __cplusplus
16
25
  }
17
26
  #endif
@@ -1,6 +1,26 @@
1
1
  #ifndef crypto_aead_aes256gcm_H
2
2
  #define crypto_aead_aes256gcm_H
3
3
 
4
+ /*
5
+ * WARNING: Despite being the most popular AEAD construction due to its
6
+ * use in TLS, safely using AES-GCM in a different context is tricky.
7
+ *
8
+ * No more than ~ 350 GB of input data should be encrypted with a given key.
9
+ * This is for ~ 16 KB messages -- Actual figures vary according to
10
+ * message sizes.
11
+ *
12
+ * In addition, nonces are short and repeated nonces would totally destroy
13
+ * the security of this scheme.
14
+ *
15
+ * Nonces should thus come from atomic counters, which can be difficult to
16
+ * set up in a distributed environment.
17
+ *
18
+ * Unless you absolutely need AES-GCM, use crypto_aead_xchacha20poly1305_ietf_*()
19
+ * instead. It doesn't have any of these limitations.
20
+ * Or, if you don't need to authenticate additional data, just stick to
21
+ * crypto_secretbox().
22
+ */
23
+
4
24
  #include <stddef.h>
5
25
  #include "export.h"
6
26
 
@@ -30,6 +50,12 @@ size_t crypto_aead_aes256gcm_npubbytes(void);
30
50
  SODIUM_EXPORT
31
51
  size_t crypto_aead_aes256gcm_abytes(void);
32
52
 
53
+ #define crypto_aead_aes256gcm_MESSAGEBYTES_MAX \
54
+ SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aes256gcm_ABYTES, \
55
+ (16ULL * ((1ULL << 32) - 2ULL)) - crypto_aead_aes256gcm_ABYTES)
56
+ SODIUM_EXPORT
57
+ size_t crypto_aead_aes256gcm_messagebytes_max(void);
58
+
33
59
  typedef CRYPTO_ALIGN(16) unsigned char crypto_aead_aes256gcm_state[512];
34
60
 
35
61
  SODIUM_EXPORT