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
@@ -49,6 +49,12 @@ crypto_box_macbytes(void)
49
49
  return crypto_box_MACBYTES;
50
50
  }
51
51
 
52
+ size_t
53
+ crypto_box_messagebytes_max(void)
54
+ {
55
+ return crypto_box_MESSAGEBYTES_MAX;
56
+ }
57
+
52
58
  const char *
53
59
  crypto_box_primitive(void)
54
60
  {
@@ -3,6 +3,7 @@
3
3
  #include <stdint.h>
4
4
  #include <stdlib.h>
5
5
 
6
+ #include "core.h"
6
7
  #include "crypto_box.h"
7
8
  #include "crypto_secretbox.h"
8
9
  #include "private/common.h"
@@ -40,8 +41,8 @@ crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
40
41
  unsigned long long mlen, const unsigned char *n,
41
42
  const unsigned char *k)
42
43
  {
43
- if (mlen > SIZE_MAX - crypto_box_MACBYTES) {
44
- return -1;
44
+ if (mlen > crypto_box_MESSAGEBYTES_MAX) {
45
+ sodium_misuse();
45
46
  }
46
47
  return crypto_box_detached_afternm(c + crypto_box_MACBYTES, c, m, mlen, n,
47
48
  k);
@@ -52,8 +53,8 @@ crypto_box_easy(unsigned char *c, const unsigned char *m,
52
53
  unsigned long long mlen, const unsigned char *n,
53
54
  const unsigned char *pk, const unsigned char *sk)
54
55
  {
55
- if (mlen > SIZE_MAX - crypto_box_MACBYTES) {
56
- return -1;
56
+ if (mlen > crypto_box_MESSAGEBYTES_MAX) {
57
+ sodium_misuse();
57
58
  }
58
59
  return crypto_box_detached(c + crypto_box_MACBYTES, c, m, mlen, n,
59
60
  pk, sk);
@@ -4,6 +4,7 @@
4
4
  #include <stdlib.h>
5
5
  #include <string.h>
6
6
 
7
+ #include "core.h"
7
8
  #include "crypto_box_curve25519xchacha20poly1305.h"
8
9
  #include "crypto_core_hchacha20.h"
9
10
  #include "crypto_hash_sha512.h"
@@ -86,8 +87,8 @@ crypto_box_curve25519xchacha20poly1305_easy_afternm(unsigned char *c,
86
87
  const unsigned char *n,
87
88
  const unsigned char *k)
88
89
  {
89
- if (mlen > SIZE_MAX - crypto_box_curve25519xchacha20poly1305_MACBYTES) {
90
- return -1;
90
+ if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) {
91
+ sodium_misuse();
91
92
  }
92
93
  return crypto_box_curve25519xchacha20poly1305_detached_afternm(
93
94
  c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, m, mlen, n, k);
@@ -98,8 +99,8 @@ crypto_box_curve25519xchacha20poly1305_easy(
98
99
  unsigned char *c, const unsigned char *m, unsigned long long mlen,
99
100
  const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
100
101
  {
101
- if (mlen > SIZE_MAX - crypto_box_curve25519xchacha20poly1305_MACBYTES) {
102
- return -1;
102
+ if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) {
103
+ sodium_misuse();
103
104
  }
104
105
  return crypto_box_curve25519xchacha20poly1305_detached(
105
106
  c + crypto_box_curve25519xchacha20poly1305_MACBYTES, c, m, mlen, n, pk,
@@ -195,3 +196,9 @@ crypto_box_curve25519xchacha20poly1305_macbytes(void)
195
196
  {
196
197
  return crypto_box_curve25519xchacha20poly1305_MACBYTES;
197
198
  }
199
+
200
+ size_t
201
+ crypto_box_curve25519xchacha20poly1305_messagebytes_max(void)
202
+ {
203
+ return crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX;
204
+ }
@@ -148,3 +148,9 @@ crypto_box_curve25519xsalsa20poly1305_macbytes(void)
148
148
  {
149
149
  return crypto_box_curve25519xsalsa20poly1305_MACBYTES;
150
150
  }
151
+
152
+ size_t
153
+ crypto_box_curve25519xsalsa20poly1305_messagebytes_max(void)
154
+ {
155
+ return crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX;
156
+ }
@@ -119,7 +119,7 @@ fe_add(fe h, const fe f, const fe g)
119
119
  Preconditions: b in {0,1}.
120
120
  */
121
121
 
122
- void
122
+ static void
123
123
  fe_cmov(fe f, const fe g, unsigned int b)
124
124
  {
125
125
  int32_t f0 = f[0];
@@ -428,7 +428,7 @@ fe_tobytes(unsigned char *s, const fe h)
428
428
  |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
429
429
  */
430
430
 
431
- int
431
+ static int
432
432
  fe_isnegative(const fe f)
433
433
  {
434
434
  unsigned char s[32];
@@ -759,7 +759,7 @@ fe_mul(fe h, const fe f, const fe g)
759
759
  |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
760
760
  */
761
761
 
762
- void
762
+ static void
763
763
  fe_neg(fe h, const fe f)
764
764
  {
765
765
  int32_t f0 = f[0];
@@ -987,7 +987,7 @@ fe_sq(fe h, const fe f)
987
987
  See fe_mul.c for discussion of implementation strategy.
988
988
  */
989
989
 
990
- void
990
+ static void
991
991
  fe_sq2(fe h, const fe f)
992
992
  {
993
993
  int32_t f0 = f[0];
@@ -1217,7 +1217,7 @@ fe_invert(fe out, const fe z)
1217
1217
  fe_mul(out, t1, t0);
1218
1218
  }
1219
1219
 
1220
- void
1220
+ static void
1221
1221
  fe_pow22523(fe out, const fe z)
1222
1222
  {
1223
1223
  fe t0;
@@ -1457,7 +1457,7 @@ ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s)
1457
1457
  r = p + q
1458
1458
  */
1459
1459
 
1460
- void
1460
+ static void
1461
1461
  ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q)
1462
1462
  {
1463
1463
  fe t0;
@@ -1478,7 +1478,7 @@ ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q)
1478
1478
  r = p - q
1479
1479
  */
1480
1480
 
1481
- void
1481
+ static void
1482
1482
  ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q)
1483
1483
  {
1484
1484
  fe t0;
@@ -1499,7 +1499,7 @@ ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q)
1499
1499
  r = p
1500
1500
  */
1501
1501
 
1502
- extern void
1502
+ void
1503
1503
  ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p)
1504
1504
  {
1505
1505
  fe_mul(r->X, p->X, p->T);
@@ -1511,7 +1511,7 @@ ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p)
1511
1511
  r = p
1512
1512
  */
1513
1513
 
1514
- extern void
1514
+ static void
1515
1515
  ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p)
1516
1516
  {
1517
1517
  fe_mul(r->X, p->X, p->T);
@@ -1520,7 +1520,7 @@ ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p)
1520
1520
  fe_mul(r->T, p->X, p->Y);
1521
1521
  }
1522
1522
 
1523
- void
1523
+ static void
1524
1524
  ge_p2_0(ge_p2 *h)
1525
1525
  {
1526
1526
  fe_0(h->X);
@@ -1532,7 +1532,7 @@ ge_p2_0(ge_p2 *h)
1532
1532
  r = 2 * p
1533
1533
  */
1534
1534
 
1535
- void
1535
+ static void
1536
1536
  ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p)
1537
1537
  {
1538
1538
  fe t0;
@@ -1548,7 +1548,7 @@ ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p)
1548
1548
  fe_sub(r->T, r->T, r->Z);
1549
1549
  }
1550
1550
 
1551
- void
1551
+ static void
1552
1552
  ge_p3_0(ge_p3 *h)
1553
1553
  {
1554
1554
  fe_0(h->X);
@@ -1567,7 +1567,7 @@ ge_p3_0(ge_p3 *h)
1567
1567
  static const fe d2 = { -21827239, -5839606, -30745221, 13898782, 229458,
1568
1568
  15978800, -12551817, -6495438, 29715968, 9444199 };
1569
1569
 
1570
- extern void
1570
+ void
1571
1571
  ge_p3_to_cached(ge_cached *r, const ge_p3 *p)
1572
1572
  {
1573
1573
  fe_add(r->YplusX, p->Y, p->X);
@@ -1580,7 +1580,7 @@ ge_p3_to_cached(ge_cached *r, const ge_p3 *p)
1580
1580
  r = p
1581
1581
  */
1582
1582
 
1583
- extern void
1583
+ static void
1584
1584
  ge_p3_to_p2(ge_p2 *r, const ge_p3 *p)
1585
1585
  {
1586
1586
  fe_copy(r->X, p->X);
@@ -1606,7 +1606,7 @@ ge_p3_tobytes(unsigned char *s, const ge_p3 *h)
1606
1606
  r = 2 * p
1607
1607
  */
1608
1608
 
1609
- void
1609
+ static void
1610
1610
  ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p)
1611
1611
  {
1612
1612
  ge_p2 q;
@@ -1614,7 +1614,7 @@ ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p)
1614
1614
  ge_p2_dbl(r, &q);
1615
1615
  }
1616
1616
 
1617
- void
1617
+ static void
1618
1618
  ge_precomp_0(ge_precomp *h)
1619
1619
  {
1620
1620
  fe_1(h->yplusx);
@@ -1686,7 +1686,7 @@ ge_select(ge_precomp *t, int pos, signed char b)
1686
1686
  r = p - q
1687
1687
  */
1688
1688
 
1689
- void
1689
+ static void
1690
1690
  ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
1691
1691
  {
1692
1692
  fe t0;
@@ -1804,6 +1804,10 @@ ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A,
1804
1804
  }
1805
1805
  }
1806
1806
 
1807
+ #ifndef MINIMAL
1808
+
1809
+ /* only used for verification of legacy (edwards25519sha512batch) signatures */
1810
+
1807
1811
  void
1808
1812
  ge_scalarmult_vartime(ge_p3 *r, const unsigned char *a, const ge_p3 *A)
1809
1813
  {
@@ -1863,6 +1867,8 @@ ge_scalarmult_vartime(ge_p3 *r, const unsigned char *a, const ge_p3 *A)
1863
1867
  }
1864
1868
  }
1865
1869
 
1870
+ #endif
1871
+
1866
1872
  void
1867
1873
  ge_scalarmult_base(ge_p3 *h, const unsigned char *a)
1868
1874
  {
@@ -1913,6 +1919,61 @@ ge_scalarmult_base(ge_p3 *h, const unsigned char *a)
1913
1919
  }
1914
1920
  }
1915
1921
 
1922
+ /* multiply by the order of the main subgroup l = 2^252+27742317777372353535851937790883648493 */
1923
+ void
1924
+ ge_mul_l(ge_p3 *r, const ge_p3 *A)
1925
+ {
1926
+ static const signed char aslide[253] = {
1927
+ 13, 0, 0, 0, 0, -1, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 3, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
1928
+ };
1929
+ ge_cached Ai[8];
1930
+ ge_p1p1 t;
1931
+ ge_p3 u;
1932
+ ge_p3 A2;
1933
+ int i;
1934
+
1935
+ ge_p3_to_cached(&Ai[0], A);
1936
+ ge_p3_dbl(&t, A);
1937
+ ge_p1p1_to_p3(&A2, &t);
1938
+ ge_add(&t, &A2, &Ai[0]);
1939
+ ge_p1p1_to_p3(&u, &t);
1940
+ ge_p3_to_cached(&Ai[1], &u);
1941
+ ge_add(&t, &A2, &Ai[1]);
1942
+ ge_p1p1_to_p3(&u, &t);
1943
+ ge_p3_to_cached(&Ai[2], &u);
1944
+ ge_add(&t, &A2, &Ai[2]);
1945
+ ge_p1p1_to_p3(&u, &t);
1946
+ ge_p3_to_cached(&Ai[3], &u);
1947
+ ge_add(&t, &A2, &Ai[3]);
1948
+ ge_p1p1_to_p3(&u, &t);
1949
+ ge_p3_to_cached(&Ai[4], &u);
1950
+ ge_add(&t, &A2, &Ai[4]);
1951
+ ge_p1p1_to_p3(&u, &t);
1952
+ ge_p3_to_cached(&Ai[5], &u);
1953
+ ge_add(&t, &A2, &Ai[5]);
1954
+ ge_p1p1_to_p3(&u, &t);
1955
+ ge_p3_to_cached(&Ai[6], &u);
1956
+ ge_add(&t, &A2, &Ai[6]);
1957
+ ge_p1p1_to_p3(&u, &t);
1958
+ ge_p3_to_cached(&Ai[7], &u);
1959
+
1960
+ ge_p3_0(r);
1961
+
1962
+ for (i = 252; i >= 0; --i) {
1963
+ ge_p3_dbl(&t, r);
1964
+
1965
+ if (aslide[i] > 0) {
1966
+ ge_p1p1_to_p3(&u, &t);
1967
+ ge_add(&t, &u, &Ai[aslide[i] / 2]);
1968
+ } else if (aslide[i] < 0) {
1969
+ ge_p1p1_to_p3(&u, &t);
1970
+ ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
1971
+ }
1972
+
1973
+ ge_p1p1_to_p3(r, &t);
1974
+ }
1975
+ }
1976
+
1916
1977
  /*
1917
1978
  Input:
1918
1979
  a[0]+256*a[1]+...+256^31*a[31] = a
@@ -14,11 +14,13 @@
14
14
  */
15
15
 
16
16
  #include <assert.h>
17
+ #include <stddef.h>
17
18
  #include <stdint.h>
18
19
  #include <stdlib.h>
19
20
  #include <string.h>
20
21
 
21
22
  #include "blake2.h"
23
+ #include "core.h"
22
24
  #include "private/common.h"
23
25
  #include "runtime.h"
24
26
  #include "utils.h"
@@ -159,11 +161,12 @@ static inline int
159
161
  blake2b_init0(blake2b_state *S)
160
162
  {
161
163
  int i;
162
- memset(S, 0, sizeof(blake2b_state));
163
164
 
164
165
  for (i = 0; i < 8; i++) {
165
166
  S->h[i] = blake2b_IV[i];
166
167
  }
168
+ memset(S->t, 0, offsetof(blake2b_state, last_node) + sizeof(S->last_node)
169
+ - offsetof(blake2b_state, t));
167
170
  return 0;
168
171
  }
169
172
 
@@ -190,9 +193,9 @@ blake2b_init(blake2b_state *S, const uint8_t outlen)
190
193
  {
191
194
  blake2b_param P[1];
192
195
 
193
- if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
194
- abort();
195
-
196
+ if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
197
+ sodium_misuse();
198
+ }
196
199
  P->digest_length = outlen;
197
200
  P->key_length = 0;
198
201
  P->fanout = 1;
@@ -213,9 +216,9 @@ blake2b_init_salt_personal(blake2b_state *S, const uint8_t outlen,
213
216
  {
214
217
  blake2b_param P[1];
215
218
 
216
- if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
217
- abort();
218
-
219
+ if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
220
+ sodium_misuse();
221
+ }
219
222
  P->digest_length = outlen;
220
223
  P->key_length = 0;
221
224
  P->fanout = 1;
@@ -244,12 +247,12 @@ blake2b_init_key(blake2b_state *S, const uint8_t outlen, const void *key,
244
247
  {
245
248
  blake2b_param P[1];
246
249
 
247
- if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
248
- abort();
249
-
250
- if (!key || !keylen || keylen > BLAKE2B_KEYBYTES)
251
- abort();
252
-
250
+ if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
251
+ sodium_misuse();
252
+ }
253
+ if (!key || !keylen || keylen > BLAKE2B_KEYBYTES) {
254
+ sodium_misuse();
255
+ }
253
256
  P->digest_length = outlen;
254
257
  P->key_length = keylen;
255
258
  P->fanout = 1;
@@ -262,9 +265,9 @@ blake2b_init_key(blake2b_state *S, const uint8_t outlen, const void *key,
262
265
  memset(P->salt, 0, sizeof(P->salt));
263
266
  memset(P->personal, 0, sizeof(P->personal));
264
267
 
265
- if (blake2b_init_param(S, P) < 0)
266
- abort();
267
-
268
+ if (blake2b_init_param(S, P) < 0) {
269
+ sodium_misuse();
270
+ }
268
271
  {
269
272
  uint8_t block[BLAKE2B_BLOCKBYTES];
270
273
  memset(block, 0, BLAKE2B_BLOCKBYTES);
@@ -282,12 +285,12 @@ blake2b_init_key_salt_personal(blake2b_state *S, const uint8_t outlen,
282
285
  {
283
286
  blake2b_param P[1];
284
287
 
285
- if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
286
- abort();
287
-
288
- if (!key || !keylen || keylen > BLAKE2B_KEYBYTES)
289
- abort();
290
-
288
+ if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
289
+ sodium_misuse();
290
+ }
291
+ if (!key || !keylen || keylen > BLAKE2B_KEYBYTES) {
292
+ sodium_misuse();
293
+ }
291
294
  P->digest_length = outlen;
292
295
  P->key_length = keylen;
293
296
  P->fanout = 1;
@@ -308,9 +311,9 @@ blake2b_init_key_salt_personal(blake2b_state *S, const uint8_t outlen,
308
311
  memset(P->personal, 0, sizeof(P->personal));
309
312
  }
310
313
 
311
- if (blake2b_init_param(S, P) < 0)
312
- abort();
313
-
314
+ if (blake2b_init_param(S, P) < 0) {
315
+ sodium_misuse();
316
+ }
314
317
  {
315
318
  uint8_t block[BLAKE2B_BLOCKBYTES];
316
319
  memset(block, 0, BLAKE2B_BLOCKBYTES);
@@ -355,7 +358,7 @@ int
355
358
  blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen)
356
359
  {
357
360
  if (!outlen || outlen > BLAKE2B_OUTBYTES) {
358
- abort(); /* LCOV_EXCL_LINE */
361
+ sodium_misuse();
359
362
  }
360
363
  if (blake2b_is_lastblock(S)) {
361
364
  return -1;
@@ -387,6 +390,9 @@ blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen)
387
390
  memcpy(out, buffer, outlen);
388
391
  }
389
392
  #endif
393
+ sodium_memzero(S->h, sizeof S->h);
394
+ sodium_memzero(S->buf, sizeof S->buf);
395
+
390
396
  return 0;
391
397
  }
392
398
 
@@ -398,27 +404,29 @@ blake2b(uint8_t *out, const void *in, const void *key, const uint8_t outlen,
398
404
  blake2b_state S[1];
399
405
 
400
406
  /* Verify parameters */
401
- if (NULL == in && inlen > 0)
402
- abort();
403
-
404
- if (NULL == out)
405
- abort();
406
-
407
- if (!outlen || outlen > BLAKE2B_OUTBYTES)
408
- abort();
409
-
410
- if (NULL == key && keylen > 0)
411
- abort();
412
-
413
- if (keylen > BLAKE2B_KEYBYTES)
414
- abort();
415
-
407
+ if (NULL == in && inlen > 0) {
408
+ sodium_misuse();
409
+ }
410
+ if (NULL == out) {
411
+ sodium_misuse();
412
+ }
413
+ if (!outlen || outlen > BLAKE2B_OUTBYTES) {
414
+ sodium_misuse();
415
+ }
416
+ if (NULL == key && keylen > 0) {
417
+ sodium_misuse();
418
+ }
419
+ if (keylen > BLAKE2B_KEYBYTES) {
420
+ sodium_misuse();
421
+ }
416
422
  if (keylen > 0) {
417
- if (blake2b_init_key(S, outlen, key, keylen) < 0)
418
- abort();
423
+ if (blake2b_init_key(S, outlen, key, keylen) < 0) {
424
+ sodium_misuse();
425
+ }
419
426
  } else {
420
- if (blake2b_init(S, outlen) < 0)
421
- abort();
427
+ if (blake2b_init(S, outlen) < 0) {
428
+ sodium_misuse();
429
+ }
422
430
  }
423
431
 
424
432
  blake2b_update(S, (const uint8_t *) in, inlen);
@@ -434,28 +442,30 @@ blake2b_salt_personal(uint8_t *out, const void *in, const void *key,
434
442
  blake2b_state S[1];
435
443
 
436
444
  /* Verify parameters */
437
- if (NULL == in && inlen > 0)
438
- abort();
439
-
440
- if (NULL == out)
441
- abort();
442
-
443
- if (!outlen || outlen > BLAKE2B_OUTBYTES)
444
- abort();
445
-
446
- if (NULL == key && keylen > 0)
447
- abort();
448
-
449
- if (keylen > BLAKE2B_KEYBYTES)
450
- abort();
451
-
445
+ if (NULL == in && inlen > 0) {
446
+ sodium_misuse();
447
+ }
448
+ if (NULL == out) {
449
+ sodium_misuse();
450
+ }
451
+ if (!outlen || outlen > BLAKE2B_OUTBYTES) {
452
+ sodium_misuse();
453
+ }
454
+ if (NULL == key && keylen > 0) {
455
+ sodium_misuse();
456
+ }
457
+ if (keylen > BLAKE2B_KEYBYTES) {
458
+ sodium_misuse();
459
+ }
452
460
  if (keylen > 0) {
453
461
  if (blake2b_init_key_salt_personal(S, outlen, key, keylen, salt,
454
- personal) < 0)
455
- abort();
462
+ personal) < 0) {
463
+ sodium_misuse();
464
+ }
456
465
  } else {
457
- if (blake2b_init_salt_personal(S, outlen, salt, personal) < 0)
458
- abort();
466
+ if (blake2b_init_salt_personal(S, outlen, salt, personal) < 0) {
467
+ sodium_misuse();
468
+ }
459
469
  }
460
470
 
461
471
  blake2b_update(S, (const uint8_t *) in, inlen);