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
@@ -1,4 +1,5 @@
1
1
 
2
+ #include <stdlib.h>
2
3
  #include <string.h>
3
4
  #include <time.h>
4
5
  #ifdef _WIN32
@@ -40,11 +41,11 @@ int
40
41
  sodium_init(void)
41
42
  {
42
43
  if (sodium_crit_enter() != 0) {
43
- return -1;
44
+ return -1; /* LCOV_EXCL_LINE */
44
45
  }
45
46
  if (initialized != 0) {
46
47
  if (sodium_crit_leave() != 0) {
47
- return -1;
48
+ return -1; /* LCOV_EXCL_LINE */
48
49
  }
49
50
  return 1;
50
51
  }
@@ -59,7 +60,7 @@ sodium_init(void)
59
60
  _crypto_stream_salsa20_pick_best_implementation();
60
61
  initialized = 1;
61
62
  if (sodium_crit_leave() != 0) {
62
- return -1;
63
+ return -1; /* LCOV_EXCL_LINE */
63
64
  }
64
65
  return 0;
65
66
  }
@@ -94,7 +95,7 @@ int
94
95
  sodium_crit_enter(void)
95
96
  {
96
97
  if (_sodium_crit_init() != 0) {
97
- return -1;
98
+ return -1; /* LCOV_EXCL_LINE */
98
99
  }
99
100
  EnterCriticalSection(&_sodium_lock);
100
101
 
@@ -169,3 +170,34 @@ sodium_crit_leave(void)
169
170
  }
170
171
 
171
172
  #endif
173
+
174
+ static void (*_misuse_handler)(void);
175
+
176
+ void
177
+ sodium_misuse(void)
178
+ {
179
+ void (*handler)(void);
180
+
181
+ if (sodium_crit_enter() == 0) {
182
+ handler = _misuse_handler;
183
+ if (sodium_crit_leave() == 0 && handler != NULL) {
184
+ handler();
185
+ }
186
+ }
187
+ /* LCOV_EXCL_START */
188
+ abort();
189
+ }
190
+ /* LCOV_EXCL_STOP */
191
+
192
+ int
193
+ sodium_set_misuse_handler(void (*handler)(void))
194
+ {
195
+ if (sodium_crit_enter() != 0) {
196
+ return -1; /* LCOV_EXCL_LINE */
197
+ }
198
+ _misuse_handler = handler;
199
+ if (sodium_crit_leave() != 0) {
200
+ return -1; /* LCOV_EXCL_LINE */
201
+ }
202
+ return 0;
203
+ }
@@ -16,6 +16,7 @@ typedef struct CPUFeatures_ {
16
16
  int has_sse41;
17
17
  int has_avx;
18
18
  int has_avx2;
19
+ int has_avx512f;
19
20
  int has_pclmul;
20
21
  int has_aesni;
21
22
  } CPUFeatures;
@@ -23,6 +24,7 @@ typedef struct CPUFeatures_ {
23
24
  static CPUFeatures _cpu_features;
24
25
 
25
26
  #define CPUID_EBX_AVX2 0x00000020
27
+ #define CPUID_EBX_AVX512F 0x00010000
26
28
 
27
29
  #define CPUID_ECX_SSE3 0x00000001
28
30
  #define CPUID_ECX_PCLMUL 0x00000002
@@ -176,6 +178,16 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
176
178
  }
177
179
  #endif
178
180
 
181
+ cpu_features->has_avx512f = 0;
182
+ #ifdef HAVE_AVX512FINTRIN_H
183
+ if (cpu_features->has_avx2) {
184
+ unsigned int cpu_info7[4];
185
+
186
+ _cpuid(cpu_info7, 0x00000007);
187
+ cpu_features->has_avx512f = ((cpu_info7[1] & CPUID_EBX_AVX512F) != 0x0);
188
+ }
189
+ #endif
190
+
179
191
  #ifdef HAVE_WMMINTRIN_H
180
192
  cpu_features->has_pclmul = ((cpu_info[2] & CPUID_ECX_PCLMUL) != 0x0);
181
193
  cpu_features->has_aesni = ((cpu_info[2] & CPUID_ECX_AESNI) != 0x0);
@@ -241,6 +253,12 @@ sodium_runtime_has_avx2(void)
241
253
  return _cpu_features.has_avx2;
242
254
  }
243
255
 
256
+ int
257
+ sodium_runtime_has_avx512f(void)
258
+ {
259
+ return _cpu_features.has_avx512f;
260
+ }
261
+
244
262
  int
245
263
  sodium_runtime_has_pclmul(void)
246
264
  {
@@ -21,6 +21,7 @@
21
21
  # include <unistd.h>
22
22
  #endif
23
23
 
24
+ #include "core.h"
24
25
  #include "randombytes.h"
25
26
  #include "utils.h"
26
27
 
@@ -62,19 +63,17 @@
62
63
  static size_t page_size;
63
64
  static unsigned char canary[CANARY_SIZE];
64
65
 
66
+ /* LCOV_EXCL_START */
65
67
  #ifdef HAVE_WEAK_SYMBOLS
66
68
  __attribute__((weak)) void
67
- _sodium_memzero_as_a_weak_symbol_to_prevent_lto(void *const pnt,
68
- const size_t len)
69
+ _sodium_dummy_symbol_to_prevent_memzero_lto(void *const pnt,
70
+ const size_t len)
69
71
  {
70
- unsigned char *pnt_ = (unsigned char *) pnt;
71
- size_t i = (size_t) 0U;
72
-
73
- while (i < len) {
74
- pnt_[i++] = 0U;
75
- }
72
+ (void) pnt; /* LCOV_EXCL_LINE */
73
+ (void) len; /* LCOV_EXCL_LINE */
76
74
  }
77
75
  #endif
76
+ /* LCOV_EXCL_STOP */
78
77
 
79
78
  void
80
79
  sodium_memzero(void *const pnt, const size_t len)
@@ -83,12 +82,13 @@ sodium_memzero(void *const pnt, const size_t len)
83
82
  SecureZeroMemory(pnt, len);
84
83
  #elif defined(HAVE_MEMSET_S)
85
84
  if (len > 0U && memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) {
86
- abort(); /* LCOV_EXCL_LINE */
85
+ sodium_misuse(); /* LCOV_EXCL_LINE */
87
86
  }
88
87
  #elif defined(HAVE_EXPLICIT_BZERO)
89
88
  explicit_bzero(pnt, len);
90
89
  #elif HAVE_WEAK_SYMBOLS
91
- _sodium_memzero_as_a_weak_symbol_to_prevent_lto(pnt, len);
90
+ memset(pnt, 0, len);
91
+ _sodium_dummy_symbol_to_prevent_memzero_lto(pnt, len);
92
92
  #else
93
93
  volatile unsigned char *volatile pnt_ =
94
94
  (volatile unsigned char *volatile) pnt;
@@ -163,7 +163,7 @@ sodium_compare(const unsigned char *b1_, const unsigned char *b2_, size_t len)
163
163
  size_t i;
164
164
  volatile unsigned char gt = 0U;
165
165
  volatile unsigned char eq = 1U;
166
- volatile uint16_t x1, x2;
166
+ uint16_t x1, x2;
167
167
 
168
168
  #if HAVE_WEAK_SYMBOLS
169
169
  _sodium_dummy_symbol_to_prevent_compare_lto(b1, b2, len);
@@ -182,8 +182,8 @@ sodium_compare(const unsigned char *b1_, const unsigned char *b2_, size_t len)
182
182
  int
183
183
  sodium_is_zero(const unsigned char *n, const size_t nlen)
184
184
  {
185
- size_t i;
186
- unsigned char d = 0U;
185
+ size_t i;
186
+ volatile unsigned char d = 0U;
187
187
 
188
188
  for (i = 0U; i < nlen; i++) {
189
189
  d |= n[i];
@@ -287,89 +287,6 @@ sodium_add(unsigned char *a, const unsigned char *b, const size_t len)
287
287
  }
288
288
  }
289
289
 
290
- /* Derived from original code by CodesInChaos */
291
- char *
292
- sodium_bin2hex(char *const hex, const size_t hex_maxlen,
293
- const unsigned char *const bin, const size_t bin_len)
294
- {
295
- size_t i = (size_t) 0U;
296
- unsigned int x;
297
- int b;
298
- int c;
299
-
300
- if (bin_len >= SIZE_MAX / 2 || hex_maxlen <= bin_len * 2U) {
301
- abort(); /* LCOV_EXCL_LINE */
302
- }
303
- while (i < bin_len) {
304
- c = bin[i] & 0xf;
305
- b = bin[i] >> 4;
306
- x = (unsigned char) (87U + c + (((c - 10U) >> 8) & ~38U)) << 8 |
307
- (unsigned char) (87U + b + (((b - 10U) >> 8) & ~38U));
308
- hex[i * 2U] = (char) x;
309
- x >>= 8;
310
- hex[i * 2U + 1U] = (char) x;
311
- i++;
312
- }
313
- hex[i * 2U] = 0U;
314
-
315
- return hex;
316
- }
317
-
318
- int
319
- sodium_hex2bin(unsigned char *const bin, const size_t bin_maxlen,
320
- const char *const hex, const size_t hex_len,
321
- const char *const ignore, size_t *const bin_len,
322
- const char **const hex_end)
323
- {
324
- size_t bin_pos = (size_t) 0U;
325
- size_t hex_pos = (size_t) 0U;
326
- int ret = 0;
327
- unsigned char c;
328
- unsigned char c_acc = 0U;
329
- unsigned char c_alpha0, c_alpha;
330
- unsigned char c_num0, c_num;
331
- unsigned char c_val;
332
- unsigned char state = 0U;
333
-
334
- while (hex_pos < hex_len) {
335
- c = (unsigned char) hex[hex_pos];
336
- c_num = c ^ 48U;
337
- c_num0 = (c_num - 10U) >> 8;
338
- c_alpha = (c & ~32U) - 55U;
339
- c_alpha0 = ((c_alpha - 10U) ^ (c_alpha - 16U)) >> 8;
340
- if ((c_num0 | c_alpha0) == 0U) {
341
- if (ignore != NULL && state == 0U && strchr(ignore, c) != NULL) {
342
- hex_pos++;
343
- continue;
344
- }
345
- break;
346
- }
347
- c_val = (c_num0 & c_num) | (c_alpha0 & c_alpha);
348
- if (bin_pos >= bin_maxlen) {
349
- ret = -1;
350
- errno = ERANGE;
351
- break;
352
- }
353
- if (state == 0U) {
354
- c_acc = c_val * 16U;
355
- } else {
356
- bin[bin_pos++] = c_acc | c_val;
357
- }
358
- state = ~state;
359
- hex_pos++;
360
- }
361
- if (state != 0U) {
362
- hex_pos--;
363
- }
364
- if (hex_end != NULL) {
365
- *hex_end = &hex[hex_pos];
366
- }
367
- if (bin_len != NULL) {
368
- *bin_len = bin_pos;
369
- }
370
- return ret;
371
- }
372
-
373
290
  int
374
291
  _sodium_alloc_init(void)
375
292
  {
@@ -385,7 +302,7 @@ _sodium_alloc_init(void)
385
302
  page_size = (size_t) si.dwPageSize;
386
303
  # endif
387
304
  if (page_size < CANARY_SIZE || page_size < sizeof(size_t)) {
388
- abort(); /* LCOV_EXCL_LINE */
305
+ sodium_misuse(); /* LCOV_EXCL_LINE */
389
306
  }
390
307
  #endif
391
308
  randombytes_buf(canary, sizeof canary);
@@ -478,7 +395,7 @@ _out_of_bounds(void)
478
395
  # elif defined(SIGKILL)
479
396
  raise(SIGKILL);
480
397
  # endif
481
- abort();
398
+ abort(); /* not something we want any higher-level API to catch */
482
399
  } /* LCOV_EXCL_LINE */
483
400
 
484
401
  static inline size_t
@@ -537,7 +454,7 @@ _unprotected_ptr_from_user_ptr(void *const ptr)
537
454
  page_mask = page_size - 1U;
538
455
  unprotected_ptr_u = ((uintptr_t) canary_ptr & (uintptr_t) ~page_mask);
539
456
  if (unprotected_ptr_u <= page_size * 2U) {
540
- abort(); /* LCOV_EXCL_LINE */
457
+ sodium_misuse(); /* LCOV_EXCL_LINE */
541
458
  }
542
459
  return (unsigned char *) unprotected_ptr_u;
543
460
  }
@@ -567,7 +484,7 @@ _sodium_malloc(const size_t size)
567
484
  return NULL;
568
485
  }
569
486
  if (page_size <= sizeof canary || page_size < sizeof unprotected_size) {
570
- abort(); /* LCOV_EXCL_LINE */
487
+ sodium_misuse(); /* LCOV_EXCL_LINE */
571
488
  }
572
489
  size_with_canary = (sizeof canary) + size;
573
490
  unprotected_size = _page_round(size_with_canary);
@@ -702,3 +619,73 @@ sodium_mprotect_readwrite(void *ptr)
702
619
  {
703
620
  return _sodium_mprotect(ptr, _mprotect_readwrite);
704
621
  }
622
+
623
+ int
624
+ sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
625
+ size_t unpadded_buflen, size_t blocksize, size_t max_buflen)
626
+ {
627
+ unsigned char *tail;
628
+ size_t i;
629
+ size_t xpadlen;
630
+ size_t xpadded_len;
631
+ volatile unsigned char mask;
632
+ unsigned char barrier_mask;
633
+
634
+ if (blocksize <= 0U) {
635
+ return -1;
636
+ }
637
+ xpadlen = blocksize - 1U;
638
+ if ((blocksize & (blocksize - 1U)) == 0U) {
639
+ xpadlen -= unpadded_buflen & (blocksize - 1U);
640
+ } else {
641
+ xpadlen -= unpadded_buflen % blocksize;
642
+ }
643
+ if ((size_t) SIZE_MAX - unpadded_buflen <= xpadlen) {
644
+ sodium_misuse();
645
+ }
646
+ xpadded_len = unpadded_buflen + xpadlen;
647
+ if (xpadded_len >= max_buflen) {
648
+ return -1;
649
+ }
650
+ tail = &buf[xpadded_len];
651
+ if (padded_buflen_p != NULL) {
652
+ *padded_buflen_p = xpadded_len + 1U;
653
+ }
654
+ mask = 0U;
655
+ for (i = 0; i < blocksize; i++) {
656
+ barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U) >> 8);
657
+ tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
658
+ mask |= barrier_mask;
659
+ }
660
+ return 0;
661
+ }
662
+
663
+ int
664
+ sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
665
+ size_t padded_buflen, size_t blocksize)
666
+ {
667
+ const unsigned char *tail;
668
+ unsigned char acc = 0U;
669
+ unsigned char c;
670
+ unsigned char valid = 0U;
671
+ volatile size_t pad_len = 0U;
672
+ size_t i;
673
+ size_t is_barrier;
674
+
675
+ if (padded_buflen < blocksize || blocksize <= 0U) {
676
+ return -1;
677
+ }
678
+ tail = &buf[padded_buflen - 1U];
679
+
680
+ for (i = 0U; i < blocksize; i++) {
681
+ c = tail[-i];
682
+ is_barrier =
683
+ (( (acc - 1U) & (pad_len - 1U) & ((c ^ 0x80) - 1U) ) >> 8) & 1U;
684
+ acc |= c;
685
+ pad_len |= i & (1U + ~is_barrier);
686
+ valid |= (unsigned char) is_barrier;
687
+ }
688
+ *unpadded_buflen_p = padded_buflen - 1U - pad_len;
689
+
690
+ return (int) (valid - 1U);
691
+ }
@@ -0,0 +1,19 @@
1
+ #! /bin/sh
2
+
3
+ CT='ct.c'
4
+
5
+ echo '#include <assert.h>' > "$CT"
6
+ echo '#include <sodium.h>' >> "$CT"
7
+ echo 'int main(void) {' >> "$CT"
8
+ for macro in $(egrep -r '#define crypto_.*BYTES(_[A-Z]+)? ' src/libsodium/include | \
9
+ cut -d: -f2- | cut -d' ' -f2 | \
10
+ fgrep -v edwards25519sha512batch | sort -u); do
11
+ func=$(echo "$macro" | tr A-Z a-z)
12
+ echo " assert($func() == $macro);" >> "$CT"
13
+ done
14
+ echo "return 0; }" >> "$CT"
15
+
16
+ ${CC:-cc} "$CT" $CPPFLAGS $CFLAGS $LDFLAGS -lsodium || exit 1
17
+ ./a.out || exit 1
18
+ rm -f a.out "$CT"
19
+
@@ -21,6 +21,7 @@ EXTRA_DIST = \
21
21
  box_seal.exp \
22
22
  box_seed.exp \
23
23
  chacha20.exp \
24
+ codecs.exp \
24
25
  core1.exp \
25
26
  core2.exp \
26
27
  core3.exp \
@@ -37,10 +38,12 @@ EXTRA_DIST = \
37
38
  kdf.exp \
38
39
  keygen.exp \
39
40
  kx.exp \
41
+ metamorphic.exp \
42
+ misuse.exp \
40
43
  onetimeauth.exp \
41
44
  onetimeauth2.exp \
42
45
  onetimeauth7.exp \
43
- pwhash.exp \
46
+ pwhash_argon2i.exp \
44
47
  pwhash_argon2id.exp \
45
48
  pwhash_scrypt.exp \
46
49
  pwhash_scrypt_ll.exp \
@@ -56,6 +59,7 @@ EXTRA_DIST = \
56
59
  secretbox8.exp \
57
60
  secretbox_easy.exp \
58
61
  secretbox_easy2.exp \
62
+ secretstream.exp \
59
63
  shorthash.exp \
60
64
  sign.exp \
61
65
  siphashx24.exp \
@@ -90,6 +94,7 @@ DISTCLEANFILES = \
90
94
  box_seal.res \
91
95
  box_seed.res \
92
96
  chacha20.res \
97
+ codecs.res \
93
98
  core1.res \
94
99
  core2.res \
95
100
  core3.res \
@@ -106,10 +111,12 @@ DISTCLEANFILES = \
106
111
  kdf.res \
107
112
  keygen.res \
108
113
  kx.res \
114
+ metamorphic.res \
115
+ misuse.res \
109
116
  onetimeauth.res \
110
117
  onetimeauth2.res \
111
118
  onetimeauth7.res \
112
- pwhash.res \
119
+ pwhash_argon2i.res \
113
120
  pwhash_argon2id.res \
114
121
  pwhash_scrypt.res \
115
122
  pwhash_scrypt_ll.res \
@@ -125,6 +132,7 @@ DISTCLEANFILES = \
125
132
  secretbox8.res \
126
133
  secretbox_easy.res \
127
134
  secretbox_easy2.res \
135
+ secretstream.res \
128
136
  shorthash.res \
129
137
  sign.res \
130
138
  siphashx24.res \
@@ -160,6 +168,7 @@ CLEANFILES = \
160
168
  box_seal.final \
161
169
  box_seed.final \
162
170
  chacha20.final \
171
+ codecs.final \
163
172
  core1.final \
164
173
  core2.final \
165
174
  core3.final \
@@ -176,10 +185,12 @@ CLEANFILES = \
176
185
  kdf.final \
177
186
  keygen.final \
178
187
  kx.final \
188
+ metamorphic.final \
189
+ misuse.final \
179
190
  onetimeauth.final \
180
191
  onetimeauth2.final \
181
192
  onetimeauth7.final \
182
- pwhash.final \
193
+ pwhash_argon2i.final \
183
194
  pwhash_argon2id.final \
184
195
  pwhash_scrypt.final \
185
196
  pwhash_scrypt_ll.final \
@@ -195,6 +206,7 @@ CLEANFILES = \
195
206
  secretbox8.final \
196
207
  secretbox_easy.final \
197
208
  secretbox_easy2.final \
209
+ secretstream.final \
198
210
  shorthash.final \
199
211
  sign.final \
200
212
  siphashx24.final \
@@ -225,6 +237,7 @@ CLEANFILES = \
225
237
  box_seal.nexe \
226
238
  box_seed.nexe \
227
239
  chacha20.nexe \
240
+ codecs.nexe \
228
241
  core1.nexe \
229
242
  core2.nexe \
230
243
  core3.nexe \
@@ -241,10 +254,12 @@ CLEANFILES = \
241
254
  kdf.nexe \
242
255
  keygen.nexe \
243
256
  kx.nexe \
257
+ metamorphic.nexe \
258
+ misuse.nexe \
244
259
  onetimeauth.nexe \
245
260
  onetimeauth2.nexe \
246
261
  onetimeauth7.nexe \
247
- pwhash.nexe \
262
+ pwhash_argon2i.nexe \
248
263
  pwhash_argon2id.nexe \
249
264
  pwhash_scrypt.nexe \
250
265
  pwhash_scrypt_ll.nexe \
@@ -260,6 +275,7 @@ CLEANFILES = \
260
275
  secretbox8.nexe \
261
276
  secretbox_easy.nexe \
262
277
  secretbox_easy2.nexe \
278
+ secretstream.nexe \
263
279
  shorthash.nexe \
264
280
  sign.nexe \
265
281
  siphashx24.nexe \
@@ -303,6 +319,7 @@ TESTS_TARGETS = \
303
319
  box_seal \
304
320
  box_seed \
305
321
  chacha20 \
322
+ codecs \
306
323
  core1 \
307
324
  core2 \
308
325
  core3 \
@@ -318,10 +335,12 @@ TESTS_TARGETS = \
318
335
  kdf \
319
336
  keygen \
320
337
  kx \
338
+ metamorphic \
339
+ misuse \
321
340
  onetimeauth \
322
341
  onetimeauth2 \
323
342
  onetimeauth7 \
324
- pwhash \
343
+ pwhash_argon2i \
325
344
  pwhash_argon2id \
326
345
  randombytes \
327
346
  scalarmult \
@@ -335,6 +354,7 @@ TESTS_TARGETS = \
335
354
  secretbox8 \
336
355
  secretbox_easy \
337
356
  secretbox_easy2 \
357
+ secretstream \
338
358
  shorthash \
339
359
  sign \
340
360
  sodium_core \
@@ -415,6 +435,9 @@ box_seed_LDADD = $(TESTS_LDADD)
415
435
  chacha20_SOURCE = cmptest.h chacha20.c
416
436
  chacha20_LDADD = $(TESTS_LDADD)
417
437
 
438
+ codecs_SOURCE = cmptest.h codecs.c
439
+ codecs_LDADD = $(TESTS_LDADD)
440
+
418
441
  core1_SOURCE = cmptest.h core1.c
419
442
  core1_LDADD = $(TESTS_LDADD)
420
443
 
@@ -460,6 +483,12 @@ keygen_LDADD = $(TESTS_LDADD)
460
483
  kx_SOURCE = cmptest.h kx.c
461
484
  kx_LDADD = $(TESTS_LDADD)
462
485
 
486
+ metamorphic_SOURCE = cmptest.h metamorphic.c
487
+ metamorphic_LDADD = $(TESTS_LDADD)
488
+
489
+ misuse_SOURCE = cmptest.h misuse.c
490
+ misuse_LDADD = $(TESTS_LDADD)
491
+
463
492
  onetimeauth_SOURCE = cmptest.h onetimeauth.c
464
493
  onetimeauth_LDADD = $(TESTS_LDADD)
465
494
 
@@ -469,8 +498,8 @@ onetimeauth2_LDADD = $(TESTS_LDADD)
469
498
  onetimeauth7_SOURCE = cmptest.h onetimeauth7.c
470
499
  onetimeauth7_LDADD = $(TESTS_LDADD)
471
500
 
472
- pwhash_SOURCE = cmptest.h pwhash.c
473
- pwhash_LDADD = $(TESTS_LDADD)
501
+ pwhash_argon2i_SOURCE = cmptest.h pwhash_argon2i.c
502
+ pwhash_argon2i_LDADD = $(TESTS_LDADD)
474
503
 
475
504
  pwhash_argon2id_SOURCE = cmptest.h pwhash_argon2id.c
476
505
  pwhash_argon2id_LDADD = $(TESTS_LDADD)
@@ -517,6 +546,9 @@ secretbox_easy_LDADD = $(TESTS_LDADD)
517
546
  secretbox_easy2_SOURCE = cmptest.h secretbox_easy2.c
518
547
  secretbox_easy2_LDADD = $(TESTS_LDADD)
519
548
 
549
+ secretstream_SOURCE = cmptest.h secretstream.c
550
+ secretstream_LDADD = $(TESTS_LDADD)
551
+
520
552
  shorthash_SOURCE = cmptest.h shorthash.c
521
553
  shorthash_LDADD = $(TESTS_LDADD)
522
554