rbnacl-libsodium 1.0.15.1 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -6
  3. data/CHANGES.md +50 -42
  4. data/Gemfile +1 -1
  5. data/README.md +3 -1
  6. data/Rakefile +46 -0
  7. data/ext/rbnacl/extconf.rb +16 -1
  8. data/lib/rbnacl/libsodium.rb +16 -8
  9. data/lib/rbnacl/libsodium/version.rb +1 -1
  10. data/rbnacl-libsodium.gemspec +3 -0
  11. data/vendor/libsodium/AUTHORS +20 -5
  12. data/vendor/libsodium/ChangeLog +25 -0
  13. data/vendor/libsodium/Makefile.in +3 -1
  14. data/vendor/libsodium/README.markdown +2 -1
  15. data/vendor/libsodium/aclocal.m4 +1 -0
  16. data/vendor/libsodium/autom4te.cache/output.1 +836 -123
  17. data/vendor/libsodium/autom4te.cache/output.4 +21342 -0
  18. data/vendor/libsodium/autom4te.cache/requests +801 -554
  19. data/vendor/libsodium/autom4te.cache/traces.1 +717 -596
  20. data/vendor/libsodium/autom4te.cache/traces.4 +4355 -0
  21. data/vendor/libsodium/builds/Makefile.in +3 -1
  22. data/vendor/libsodium/builds/msvc/resource.h +1 -1
  23. data/vendor/libsodium/builds/msvc/resource.rc +2 -2
  24. data/vendor/libsodium/builds/msvc/version.h +2 -2
  25. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +17 -8
  26. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +60 -24
  27. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +17 -8
  28. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +60 -24
  29. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +17 -8
  30. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +60 -24
  31. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +17 -8
  32. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +60 -24
  33. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj +17 -8
  34. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +60 -24
  35. data/vendor/libsodium/configure +834 -121
  36. data/vendor/libsodium/configure.ac +55 -13
  37. data/vendor/libsodium/contrib/Findsodium.cmake +22 -3
  38. data/vendor/libsodium/contrib/Makefile.in +3 -1
  39. data/vendor/libsodium/dist-build/Makefile.in +3 -1
  40. data/vendor/libsodium/dist-build/android-build.sh +2 -2
  41. data/vendor/libsodium/dist-build/emscripten-symbols.def +38 -26
  42. data/vendor/libsodium/dist-build/emscripten.sh +23 -8
  43. data/vendor/libsodium/dist-build/msys2-win32.sh +1 -1
  44. data/vendor/libsodium/dist-build/msys2-win64.sh +1 -1
  45. data/vendor/libsodium/libsodium.vcxproj +17 -8
  46. data/vendor/libsodium/libsodium.vcxproj.filters +41 -14
  47. data/vendor/libsodium/m4/ax_tls.m4 +74 -0
  48. data/vendor/libsodium/msvc-scripts/Makefile.in +3 -1
  49. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  50. data/vendor/libsodium/packaging/dotnet-core/README.md +5 -5
  51. data/vendor/libsodium/packaging/dotnet-core/prepare.py +7 -7
  52. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  53. data/vendor/libsodium/regen-msvc/libsodium.vcxproj +326 -0
  54. data/vendor/libsodium/regen-msvc/libsodium.vcxproj.filters +23 -0
  55. data/vendor/libsodium/regen-msvc/libsodium.vcxproj.filters.tpl +35 -0
  56. data/vendor/libsodium/regen-msvc/libsodium.vcxproj.tpl +93 -0
  57. data/vendor/libsodium/regen-msvc/regen-msvc.py +136 -0
  58. data/vendor/libsodium/regen-msvc/tl_libsodium.vcxproj.filters.tpl +23 -0
  59. data/vendor/libsodium/regen-msvc/tl_libsodium.vcxproj.tpl +331 -0
  60. data/vendor/libsodium/src/Makefile.in +3 -1
  61. data/vendor/libsodium/src/libsodium/Makefile.am +40 -24
  62. data/vendor/libsodium/src/libsodium/Makefile.in +238 -180
  63. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +10 -2
  64. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/core_ed25519.c +79 -0
  65. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c +2031 -0
  66. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_25_5/base.h +1344 -0
  67. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_25_5/base2.h +40 -0
  68. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_25_5/constants.h +20 -0
  69. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_25_5/fe.h +220 -0
  70. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_51/base.h +1344 -0
  71. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_51/base2.h +40 -0
  72. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_51/constants.h +21 -0
  73. data/vendor/libsodium/src/libsodium/crypto_core/ed25519/ref10/fe_51/fe.h +116 -0
  74. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2.h +1 -1
  75. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c +2 -1
  76. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c +14 -82
  77. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c +1 -0
  78. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c +3 -3
  79. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c +3 -3
  80. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +1 -7
  81. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +1 -0
  82. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +0 -6
  83. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +19 -92
  84. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +72 -4
  85. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +5 -1
  86. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +1 -1
  87. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +10 -7
  88. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +108 -231
  89. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h +1 -1
  90. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/curve25519_sandy2x.c +27 -27
  91. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c +2 -1
  92. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c +6 -3
  93. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c +3 -11
  94. data/vendor/libsodium/src/libsodium/crypto_scalarmult/ed25519/ref10/scalarmult_ed25519_ref10.c +86 -0
  95. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +28 -26
  96. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +32 -30
  97. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +14 -115
  98. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +56 -13
  99. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/{ed25519_ref10.h → sign_ed25519_ref10.h} +2 -5
  100. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c +1 -1
  101. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c +1 -0
  102. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c +1 -0
  103. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u8.h +1 -1
  104. data/vendor/libsodium/src/libsodium/include/Makefile.am +2 -0
  105. data/vendor/libsodium/src/libsodium/include/Makefile.in +13 -9
  106. data/vendor/libsodium/src/libsodium/include/sodium.h +2 -0
  107. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_ed25519.h +37 -0
  108. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult.h +8 -0
  109. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +8 -0
  110. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_ed25519.h +41 -0
  111. data/vendor/libsodium/src/libsodium/include/sodium/private/common.h +18 -0
  112. data/vendor/libsodium/src/libsodium/include/sodium/private/ed25519_ref10.h +125 -0
  113. data/vendor/libsodium/src/libsodium/include/sodium/private/ed25519_ref10_fe_25_5.h +1050 -0
  114. data/vendor/libsodium/src/libsodium/include/sodium/private/ed25519_ref10_fe_51.h +518 -0
  115. data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +3 -0
  116. data/vendor/libsodium/src/libsodium/include/sodium/utils.h +3 -0
  117. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +182 -102
  118. data/vendor/libsodium/src/libsodium/sodium/core.c +30 -2
  119. data/vendor/libsodium/src/libsodium/sodium/runtime.c +14 -0
  120. data/vendor/libsodium/src/libsodium/sodium/utils.c +46 -0
  121. data/vendor/libsodium/test/Makefile.in +3 -1
  122. data/vendor/libsodium/test/default/Makefile.am +16 -0
  123. data/vendor/libsodium/test/default/Makefile.in +71 -23
  124. data/vendor/libsodium/test/default/aead_aes256gcm.c +1 -1
  125. data/vendor/libsodium/test/default/cmptest.h +4 -0
  126. data/vendor/libsodium/test/default/core3.c +44 -4
  127. data/vendor/libsodium/test/default/core3.exp +2 -0
  128. data/vendor/libsodium/test/default/core4.c +1 -1
  129. data/vendor/libsodium/test/default/core_ed25519.c +151 -0
  130. data/vendor/libsodium/test/default/core_ed25519.exp +1 -0
  131. data/vendor/libsodium/test/default/ed25519_convert.c +9 -1
  132. data/vendor/libsodium/test/default/index.html.tpl +17 -3
  133. data/vendor/libsodium/test/default/kdf.c +4 -2
  134. data/vendor/libsodium/test/default/metamorphic.c +8 -8
  135. data/vendor/libsodium/test/default/misuse.c +29 -1
  136. data/vendor/libsodium/test/default/pwhash_argon2i.c +9 -3
  137. data/vendor/libsodium/test/default/pwhash_argon2i.exp +2 -2
  138. data/vendor/libsodium/test/default/pwhash_argon2id.c +7 -2
  139. data/vendor/libsodium/test/default/pwhash_argon2id.exp +2 -2
  140. data/vendor/libsodium/test/default/scalarmult.c +0 -2
  141. data/vendor/libsodium/test/default/scalarmult.exp +0 -1
  142. data/vendor/libsodium/test/default/scalarmult_ed25519.c +90 -0
  143. data/vendor/libsodium/test/default/scalarmult_ed25519.exp +1 -0
  144. data/vendor/libsodium/test/default/secretbox_easy2.c +1 -1
  145. data/vendor/libsodium/test/default/secretstream.c +52 -3
  146. data/vendor/libsodium/test/default/sign.c +16 -0
  147. data/vendor/libsodium/test/default/sodium_core.c +1 -0
  148. data/vendor/libsodium/test/default/sodium_utils.c +2 -1
  149. data/vendor/libsodium/test/default/xchacha20.c +2 -1
  150. metadata +63 -12
  151. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/base.h +0 -1344
  152. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/base2.h +0 -40
  153. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +0 -2797
  154. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +0 -545
  155. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.h +0 -10
  156. data/vendor/libsodium/src/libsodium/include/sodium/private/curve25519_ref10.h +0 -132
  157. data/vendor/libsodium/test/default/index-wasm.html.tpl +0 -118
@@ -3170,7 +3170,7 @@ tv(void)
3170
3170
  found_message_len = 1;
3171
3171
  if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
3172
3172
  NULL, ciphertext,
3173
- randombytes_uniform(ciphertext_len),
3173
+ randombytes_uniform((uint32_t) ciphertext_len),
3174
3174
  ad, ad_len, nonce, key) != -1) {
3175
3175
  printf("Verification of test vector #%u after truncation succeeded\n",
3176
3176
  (unsigned int) i);
@@ -2,6 +2,10 @@
2
2
  #ifndef __CMPTEST_H__
3
3
  #define __CMPTEST_H__
4
4
 
5
+ #ifdef NDEBUG
6
+ #/**/undef/**/ NDEBUG
7
+ #endif
8
+
5
9
  #include <assert.h>
6
10
  #include <stdio.h>
7
11
  #include <stdint.h>
@@ -27,6 +27,7 @@ main(void)
27
27
  size_t pos = 0;
28
28
  int i;
29
29
 
30
+ pos = 0;
30
31
  secondkey = (unsigned char *) sodium_malloc(32);
31
32
  memcpy(secondkey, SECONDKEY, 32);
32
33
  noncesuffix = (unsigned char *) sodium_malloc(8);
@@ -59,6 +60,45 @@ main(void)
59
60
  }
60
61
  printf("\n");
61
62
 
63
+ #ifndef SODIUM_LIBRARY_MINIMAL
64
+ pos = 0;
65
+ do {
66
+ do {
67
+ crypto_core_salsa2012(output + pos, in, secondkey, c);
68
+ pos += 64;
69
+ in[8]++;
70
+ } while (in[8] != 0);
71
+ in[9]++;
72
+ } while (in[9] != 0);
73
+
74
+ crypto_hash_sha256(h, output, output_len);
75
+
76
+ for (i = 0; i < 32; ++i) {
77
+ printf("%02x", h[i]);
78
+ }
79
+ printf("\n");
80
+
81
+ pos = 0;
82
+ do {
83
+ do {
84
+ crypto_core_salsa208(output + pos, in, secondkey, c);
85
+ pos += 64;
86
+ in[8]++;
87
+ } while (in[8] != 0);
88
+ in[9]++;
89
+ } while (in[9] != 0);
90
+
91
+ crypto_hash_sha256(h, output, output_len);
92
+
93
+ for (i = 0; i < 32; ++i) {
94
+ printf("%02x", h[i]);
95
+ }
96
+ printf("\n");
97
+ #else
98
+ printf("a4e3147dddd2ba7775939b50208a22eb3277d4e4bad8a1cfbc999c6bd392b638\n"
99
+ "017421baa9959cbe894bd003ec87938254f47c1e757eb66cf89c353d0c2b68de\n");
100
+ #endif
101
+
62
102
  sodium_free(h);
63
103
  sodium_free(output);
64
104
  sodium_free(in);
@@ -66,10 +106,10 @@ main(void)
66
106
  sodium_free(noncesuffix);
67
107
  sodium_free(secondkey);
68
108
 
69
- assert(crypto_core_salsa20_outputbytes() > 0U);
70
- assert(crypto_core_salsa20_inputbytes() > 0U);
71
- assert(crypto_core_salsa20_keybytes() > 0U);
72
- assert(crypto_core_salsa20_constbytes() > 0U);
109
+ assert(crypto_core_salsa20_outputbytes() == crypto_core_salsa20_OUTPUTBYTES);
110
+ assert(crypto_core_salsa20_inputbytes() == crypto_core_salsa20_INPUTBYTES);
111
+ assert(crypto_core_salsa20_keybytes() == crypto_core_salsa20_KEYBYTES);
112
+ assert(crypto_core_salsa20_constbytes() == crypto_core_salsa20_CONSTBYTES);
73
113
 
74
114
  return 0;
75
115
  }
@@ -1 +1,3 @@
1
1
  662b9d0e3463029156069b12f918691a98f7dfb2ca0393c96bbfc6b1fbd630a2
2
+ a4e3147dddd2ba7775939b50208a22eb3277d4e4bad8a1cfbc999c6bd392b638
3
+ 017421baa9959cbe894bd003ec87938254f47c1e757eb66cf89c353d0c2b68de
@@ -27,7 +27,7 @@ main(void)
27
27
  } else {
28
28
  printf(" ");
29
29
  }
30
- printf("%3d", (unsigned int) out[i]);
30
+ printf("%3u", (unsigned int) out[i]);
31
31
  if (i % 8 == 7) {
32
32
  printf("\n");
33
33
  }
@@ -0,0 +1,151 @@
1
+ #define TEST_NAME "core_ed25519"
2
+ #include "cmptest.h"
3
+
4
+ static const unsigned char non_canonical_p[32] = {
5
+ 0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
7
+ };
8
+ static const unsigned char non_canonical_invalid_p[32] = {
9
+ 0xf5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
10
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
11
+ };
12
+ static const unsigned char max_canonical_p[32] = {
13
+ 0xe4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
14
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
15
+ };
16
+
17
+ static void
18
+ add_P(unsigned char * const S)
19
+ {
20
+ static const unsigned char P[32] = {
21
+ 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
22
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
23
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
24
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
25
+ };
26
+ unsigned char c = 0U;
27
+ unsigned int i;
28
+ unsigned int s;
29
+
30
+ for (i = 0U; i < 32U; i++) {
31
+ s = S[i] + P[i] + c;
32
+ S[i] = (unsigned char) s;
33
+ c = (s >> 8) & 1;
34
+ }
35
+ }
36
+
37
+ int
38
+ main(void)
39
+ {
40
+ unsigned char *h;
41
+ unsigned char *p, *p2, *p3;
42
+ unsigned char *sc;
43
+ int i, j;
44
+
45
+ h = (unsigned char *) sodium_malloc(crypto_core_ed25519_UNIFORMBYTES);
46
+ p = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
47
+ for (i = 0; i < 1000; i++) {
48
+ randombytes_buf(h, crypto_core_ed25519_UNIFORMBYTES);
49
+ if (crypto_core_ed25519_from_uniform(p, h) != 0) {
50
+ printf("crypto_core_ed25519_from_uniform() failed\n");
51
+ }
52
+ if (crypto_core_ed25519_is_valid_point(p) == 0) {
53
+ printf("crypto_core_ed25519_from_uniform() returned an invalid point\n");
54
+ }
55
+ }
56
+
57
+ p2 = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
58
+ p3 = (unsigned char *) sodium_malloc(crypto_core_ed25519_BYTES);
59
+ randombytes_buf(h, crypto_core_ed25519_UNIFORMBYTES);
60
+ crypto_core_ed25519_from_uniform(p2, h);
61
+
62
+ j = 1 + (int) randombytes_uniform(100);
63
+ memcpy(p3, p, crypto_core_ed25519_BYTES);
64
+ for (i = 0; i < j; i++) {
65
+ crypto_core_ed25519_add(p, p, p2);
66
+ if (crypto_core_ed25519_is_valid_point(p) != 1) {
67
+ printf("crypto_core_add() returned an invalid point\n");
68
+ }
69
+ }
70
+ if (memcmp(p, p3, crypto_core_ed25519_BYTES) == 0) {
71
+ printf("crypto_core_add() failed\n");
72
+ }
73
+ for (i = 0; i < j; i++) {
74
+ crypto_core_ed25519_sub(p, p, p2);
75
+ }
76
+ if (memcmp(p, p3, crypto_core_ed25519_BYTES) != 0) {
77
+ printf("crypto_core_add() or crypto_core_sub() failed\n");
78
+ }
79
+ sc = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_SCALARBYTES);
80
+ memset(sc, 0, crypto_scalarmult_ed25519_SCALARBYTES);
81
+ sc[0] = 8;
82
+ memcpy(p2, p, crypto_core_ed25519_BYTES);
83
+ memcpy(p3, p, crypto_core_ed25519_BYTES);
84
+
85
+ for (i = 0; i < 254; i++) {
86
+ crypto_core_ed25519_add(p2, p2, p2);
87
+ }
88
+ for (i = 0; i < 8; i++) {
89
+ crypto_core_ed25519_add(p2, p2, p);
90
+ }
91
+ if (crypto_scalarmult_ed25519(p3, sc, p) != 0) {
92
+ printf("crypto_scalarmult_ed25519() failed\n");
93
+ }
94
+ if (memcmp(p2, p3, crypto_core_ed25519_BYTES) != 0) {
95
+ printf("crypto_scalarmult_ed25519() is inconsistent with crypto_core_ed25519_add()\n");
96
+ }
97
+
98
+ assert(crypto_core_ed25519_is_valid_point(p) == 1);
99
+
100
+ memset(p, 0, crypto_core_ed25519_BYTES);
101
+ assert(crypto_core_ed25519_is_valid_point(p) == 0);
102
+
103
+ p[0] = 1;
104
+ assert(crypto_core_ed25519_is_valid_point(p) == 0);
105
+
106
+ p[0] = 2;
107
+ assert(crypto_core_ed25519_is_valid_point(p) == 0);
108
+
109
+ p[0] = 9;
110
+ assert(crypto_core_ed25519_is_valid_point(p) == 1);
111
+
112
+ assert(crypto_core_ed25519_is_valid_point(max_canonical_p) == 1);
113
+ assert(crypto_core_ed25519_is_valid_point(non_canonical_invalid_p) == 0);
114
+ assert(crypto_core_ed25519_is_valid_point(non_canonical_p) == 0);
115
+
116
+ memcpy(p2, p, crypto_core_ed25519_BYTES);
117
+ add_P(p2);
118
+ crypto_core_ed25519_add(p3, p2, p2);
119
+ crypto_core_ed25519_sub(p3, p3, p2);
120
+ assert(memcmp(p2, p, crypto_core_ed25519_BYTES) != 0);
121
+ assert(memcmp(p3, p, crypto_core_ed25519_BYTES) == 0);
122
+
123
+ p[0] = 2;
124
+ assert(crypto_core_ed25519_add(p3, p2, p) == -1);
125
+ assert(crypto_core_ed25519_add(p3, p2, non_canonical_p) == 0);
126
+ assert(crypto_core_ed25519_add(p3, p2, non_canonical_invalid_p) == -1);
127
+ assert(crypto_core_ed25519_add(p3, p, p3) == -1);
128
+ assert(crypto_core_ed25519_add(p3, non_canonical_p, p3) == 0);
129
+ assert(crypto_core_ed25519_add(p3, non_canonical_invalid_p, p3) == -1);
130
+
131
+ assert(crypto_core_ed25519_sub(p3, p2, p) == -1);
132
+ assert(crypto_core_ed25519_sub(p3, p2, non_canonical_p) == 0);
133
+ assert(crypto_core_ed25519_sub(p3, p2, non_canonical_invalid_p) == -1);
134
+ assert(crypto_core_ed25519_sub(p3, p, p3) == -1);
135
+ assert(crypto_core_ed25519_sub(p3, non_canonical_p, p3) == 0);
136
+ assert(crypto_core_ed25519_sub(p3, non_canonical_invalid_p, p3) == -1);
137
+
138
+ sodium_free(sc);
139
+ sodium_free(p3);
140
+ sodium_free(p2);
141
+ sodium_free(p);
142
+ sodium_free(h);
143
+
144
+ assert(crypto_core_ed25519_BYTES == crypto_core_ed25519_bytes());
145
+ assert(crypto_core_ed25519_UNIFORMBYTES == crypto_core_ed25519_uniformbytes());
146
+ assert(crypto_core_ed25519_UNIFORMBYTES >= crypto_core_ed25519_BYTES);
147
+
148
+ printf("OK\n");
149
+
150
+ return 0;
151
+ }
@@ -18,9 +18,17 @@ main(void)
18
18
  unsigned char curve25519_sk[crypto_scalarmult_curve25519_BYTES];
19
19
  char curve25519_pk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
20
20
  char curve25519_sk_hex[crypto_scalarmult_curve25519_BYTES * 2 + 1];
21
+ unsigned char hseed[crypto_hash_sha512_BYTES];
21
22
  unsigned int i;
22
23
 
23
- crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, keypair_seed);
24
+ assert(crypto_sign_ed25519_SEEDBYTES <= crypto_hash_sha512_BYTES);
25
+ #ifdef ED25519_NONDETERMINISTIC
26
+ crypto_hash_sha512(hseed, keypair_seed, crypto_sign_ed25519_SEEDBYTES);
27
+ #else
28
+ memcpy(hseed, keypair_seed, crypto_sign_ed25519_SEEDBYTES);
29
+ #endif
30
+ crypto_sign_ed25519_seed_keypair(ed25519_pk, ed25519_skpk, hseed);
31
+
24
32
  if (crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) != 0) {
25
33
  printf("conversion failed\n");
26
34
  }
@@ -28,9 +28,20 @@ body {
28
28
  <h1></h1>
29
29
  <section class="test" id="test-res"></section>
30
30
  <script>
31
+ var performance;
32
+ if (typeof performance !== 'object') {
33
+ performance = {
34
+ mark: function(s) { this[s] = new Date() },
35
+ measure: function(_t, s1, s2) { this.t = this[s2] - this[s1] },
36
+ getEntriesByName: function() { return [ { duration: this.t } ] }
37
+ };
38
+ }
39
+
40
+ var Module = { preRun: function() { performance.mark('bench_start') } };
41
+
31
42
  function runTest(tname) {
32
43
  var xhr, expected, hn, idx = 0, passed = true;
33
-
44
+
34
45
  function outputReceived(e) {
35
46
  var found = e.data;
36
47
  var p = document.createElement('p');
@@ -42,8 +53,11 @@ function runTest(tname) {
42
53
  document.getElementById('test-res').appendChild(p);
43
54
  if (idx >= expected.length) {
44
55
  if (passed) {
45
- hn.appendChild(document.createTextNode(' - PASSED'));
46
- hn.className = 'passed';
56
+ performance.mark('bench_end')
57
+ performance.measure('bench', 'bench_start', 'bench_end');
58
+ var duration = Math.round(performance.getEntriesByName('bench')[0].duration);
59
+ hn.appendChild(document.createTextNode(' - PASSED (time: ' + duration + ' ms)'));
60
+ hn.className = 'passed';
47
61
  } else {
48
62
  hn.appendChild(document.createTextNode(' - FAILED'));
49
63
  hn.className = 'err';
@@ -10,6 +10,7 @@ tv_kdf(void)
10
10
  char *context;
11
11
  char hex[crypto_kdf_BYTES_MAX * 2 + 1];
12
12
  uint64_t i;
13
+ int ret;
13
14
 
14
15
  context = (char *) sodium_malloc(crypto_kdf_CONTEXTBYTES);
15
16
  memcpy(context, "KDF test", strlen("KDF test"));
@@ -19,8 +20,9 @@ tv_kdf(void)
19
20
  }
20
21
  subkey = (unsigned char *) sodium_malloc(crypto_kdf_BYTES_MAX);
21
22
  for (i = 0; i < 10; i++) {
22
- assert(crypto_kdf_derive_from_key(subkey, crypto_kdf_BYTES_MAX,
23
- i, context, master_key) == 0);
23
+ ret = crypto_kdf_derive_from_key(subkey, crypto_kdf_BYTES_MAX,
24
+ i, context, master_key);
25
+ assert(ret == 0);
24
26
  sodium_bin2hex(hex, sizeof hex, subkey, crypto_kdf_BYTES_MAX);
25
27
  printf("%s\n", hex);
26
28
  }
@@ -35,8 +35,8 @@ mm_generichash(void)
35
35
  randombytes_buf(m, mlen);
36
36
 
37
37
  crypto_generichash_init(&st, k, klen, hlen);
38
- l1 = randombytes_uniform(mlen);
39
- l2 = randombytes_uniform(mlen - l1);
38
+ l1 = randombytes_uniform((uint32_t) mlen);
39
+ l2 = randombytes_uniform((uint32_t) (mlen - l1));
40
40
  crypto_generichash_update(&st, m, l1);
41
41
  crypto_generichash_update(&st, m + l1, l2);
42
42
  crypto_generichash_update(&st, m + l1 + l2, mlen - l1 - l2);
@@ -75,8 +75,8 @@ mm_onetimeauth(void)
75
75
  randombytes_buf(m, mlen);
76
76
 
77
77
  crypto_onetimeauth_init(&st, k);
78
- l1 = randombytes_uniform(mlen);
79
- l2 = randombytes_uniform(mlen - l1);
78
+ l1 = randombytes_uniform((uint32_t) mlen);
79
+ l2 = randombytes_uniform((uint32_t) (mlen - l1));
80
80
  crypto_onetimeauth_update(&st, m, l1);
81
81
  crypto_onetimeauth_update(&st, m + l1, l2);
82
82
  crypto_onetimeauth_update(&st, m + l1 + l2, mlen - l1 - l2);
@@ -115,8 +115,8 @@ mm_hmacsha256(void)
115
115
  randombytes_buf(m, mlen);
116
116
 
117
117
  crypto_auth_hmacsha256_init(&st, k, crypto_auth_hmacsha256_KEYBYTES);
118
- l1 = randombytes_uniform(mlen);
119
- l2 = randombytes_uniform(mlen - l1);
118
+ l1 = randombytes_uniform((uint32_t) mlen);
119
+ l2 = randombytes_uniform((uint32_t) (mlen - l1));
120
120
  crypto_auth_hmacsha256_update(&st, m, l1);
121
121
  crypto_auth_hmacsha256_update(&st, m + l1, l2);
122
122
  crypto_auth_hmacsha256_update(&st, m + l1 + l2, mlen - l1 - l2);
@@ -155,8 +155,8 @@ mm_hmacsha512(void)
155
155
  randombytes_buf(m, mlen);
156
156
 
157
157
  crypto_auth_hmacsha512_init(&st, k, crypto_auth_hmacsha512_KEYBYTES);
158
- l1 = randombytes_uniform(mlen);
159
- l2 = randombytes_uniform(mlen - l1);
158
+ l1 = randombytes_uniform((uint32_t) mlen);
159
+ l2 = randombytes_uniform((uint32_t) (mlen - l1));
160
160
  crypto_auth_hmacsha512_update(&st, m, l1);
161
161
  crypto_auth_hmacsha512_update(&st, m + l1, l2);
162
162
  crypto_auth_hmacsha512_update(&st, m + l1 + l2, mlen - l1 - l2);
@@ -6,17 +6,45 @@
6
6
  # include <signal.h>
7
7
 
8
8
  static void
9
- sigabrt_handler_13(int sig)
9
+ sigabrt_handler_15(int sig)
10
10
  {
11
11
  (void) sig;
12
12
  exit(0);
13
13
  }
14
14
 
15
+ # ifndef SODIUM_LIBRARY_MINIMAL
16
+ static void
17
+ sigabrt_handler_14(int sig)
18
+ {
19
+ (void) sig;
20
+ signal(SIGABRT, sigabrt_handler_15);
21
+ assert(crypto_box_curve25519xchacha20poly1305_easy
22
+ (NULL, NULL, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
23
+ NULL, NULL, NULL) == -1);
24
+ exit(1);
25
+ }
26
+
27
+ static void
28
+ sigabrt_handler_13(int sig)
29
+ {
30
+ (void) sig;
31
+ signal(SIGABRT, sigabrt_handler_14);
32
+ assert(crypto_box_curve25519xchacha20poly1305_easy_afternm
33
+ (NULL, NULL, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
34
+ NULL, NULL) == -1);
35
+ exit(1);
36
+ }
37
+ # endif
38
+
15
39
  static void
16
40
  sigabrt_handler_12(int sig)
17
41
  {
18
42
  (void) sig;
43
+ # ifdef SODIUM_LIBRARY_MINIMAL
44
+ signal(SIGABRT, sigabrt_handler_15);
45
+ # else
19
46
  signal(SIGABRT, sigabrt_handler_13);
47
+ # endif
20
48
  assert(crypto_pwhash_str_alg(NULL, "", 0U, 1U, 1U, -1) == -1);
21
49
  exit(1);
22
50
  }
@@ -121,14 +121,14 @@ tv2(void)
121
121
  "8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
122
122
  127,
123
123
  "5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
124
- 155, 4, 1397645, 1 },
124
+ 155, 4, 397645, 1 },
125
125
  { "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
126
126
  "65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
127
127
  "a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
128
128
  "8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
129
129
  127,
130
130
  "5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
131
- 155, 3, 1397645, 1 },
131
+ 155, 3, 397645, 1 },
132
132
  };
133
133
  char passwd[256];
134
134
  unsigned char salt[crypto_pwhash_SALTBYTES];
@@ -181,6 +181,8 @@ tv2(void)
181
181
  1ULL << 12, crypto_pwhash_alg_argon2i13()) != -1) {
182
182
  printf("[tv2] pwhash with a long password length should have failed\n");
183
183
  }
184
+ assert(crypto_pwhash_argon2i(out, sizeof out, "password", strlen("password"), salt,
185
+ OPSLIMIT, MEMLIMIT, crypto_pwhash_alg_argon2id13()) == -1);
184
186
  }
185
187
 
186
188
  static void
@@ -256,7 +258,11 @@ str_tests(void)
256
258
  crypto_pwhash_argon2i_str_needs_rehash(str_out, OPSLIMIT * 2, MEMLIMIT) != 1) {
257
259
  printf("needs_rehash() false negative\n");
258
260
  }
259
- if (crypto_pwhash_argon2i_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
261
+ if (crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT / 2) != 1) {
262
+ printf("pwhash_str_needs_rehash() didn't handle argon2i\n");
263
+ }
264
+ if (crypto_pwhash_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1 ||
265
+ crypto_pwhash_argon2i_str_needs_rehash(str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
260
266
  printf("needs_rehash() didn't fail with an invalid hash string\n");
261
267
  }
262
268
  if (sodium_is_zero((const unsigned char *) str_out + strlen(str_out),