rbnacl-libsodium 1.0.15.1 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -5,6 +5,6 @@
5
5
  #include "../scalarmult_curve25519.h"
6
6
 
7
7
  extern struct crypto_scalarmult_curve25519_implementation
8
- crypto_scalarmult_curve25519_ref10_implementation;
8
+ crypto_scalarmult_curve25519_ref10_implementation;
9
9
 
10
10
  #endif
@@ -25,22 +25,22 @@ static int
25
25
  crypto_scalarmult_curve25519_sandy2x(unsigned char *q, const unsigned char *n,
26
26
  const unsigned char *p)
27
27
  {
28
- unsigned char e[32];
29
- unsigned int i;
30
-
31
- fe var[3];
32
-
33
- fe51 x_51;
34
- fe51 z_51;
35
-
36
- for (i = 0;i < 32;++i) e[i] = n[i];
37
- e[0] &= 248;
38
- e[31] &= 127;
39
- e[31] |= 64;
28
+ unsigned char *t = q;
29
+ fe var[3];
30
+ fe51 x_51;
31
+ fe51 z_51;
32
+ unsigned int i;
33
+
34
+ for (i = 0; i < 32; i++) {
35
+ t[i] = n[i];
36
+ }
37
+ t[0] &= 248;
38
+ t[31] &= 127;
39
+ t[31] |= 64;
40
40
 
41
41
  fe_frombytes(x1, p);
42
42
 
43
- ladder(var, e);
43
+ ladder(var, t);
44
44
 
45
45
  z_51.v[0] = (z2[1] << 26) + z2[0];
46
46
  z_51.v[1] = (z2[3] << 26) + z2[2];
@@ -71,20 +71,20 @@ static int
71
71
  crypto_scalarmult_curve25519_sandy2x_base(unsigned char *q,
72
72
  const unsigned char *n)
73
73
  {
74
- unsigned char e[32];
75
- unsigned int i;
76
-
77
- fe var[3];
78
-
79
- fe51 x_51;
80
- fe51 z_51;
81
-
82
- for (i = 0;i < 32;++i) e[i] = n[i];
83
- e[0] &= 248;
84
- e[31] &= 127;
85
- e[31] |= 64;
86
-
87
- ladder_base(var, e);
74
+ unsigned char *t = q;
75
+ fe var[3];
76
+ fe51 x_51;
77
+ fe51 z_51;
78
+ unsigned int i;
79
+
80
+ for (i = 0;i < 32; i++) {
81
+ t[i] = n[i];
82
+ }
83
+ t[0] &= 248;
84
+ t[31] &= 127;
85
+ t[31] |= 64;
86
+
87
+ ladder_base(var, t);
88
88
 
89
89
  z_51.v[0] = (z2[1] << 26) + z2[0];
90
90
  z_51.v[1] = (z2[3] << 26) + z2[2];
@@ -9,7 +9,8 @@
9
9
 
10
10
  #define fe51_square(x, y) fe51_nsquare(x, y, 1)
11
11
 
12
- void fe51_invert(fe51 *r, const fe51 *x)
12
+ void
13
+ fe51_invert(fe51 *r, const fe51 *x)
13
14
  {
14
15
  fe51 z2;
15
16
  fe51 z9;
@@ -6,7 +6,8 @@
6
6
 
7
7
  #ifdef HAVE_AVX_ASM
8
8
 
9
- static uint64_t load_3(const unsigned char *in)
9
+ static uint64_t
10
+ load_3(const unsigned char *in)
10
11
  {
11
12
  uint64_t result;
12
13
  result = (uint64_t) in[0];
@@ -15,7 +16,8 @@ static uint64_t load_3(const unsigned char *in)
15
16
  return result;
16
17
  }
17
18
 
18
- static uint64_t load_4(const unsigned char *in)
19
+ static uint64_t
20
+ load_4(const unsigned char *in)
19
21
  {
20
22
  uint64_t result;
21
23
  result = (uint64_t) in[0];
@@ -25,7 +27,8 @@ static uint64_t load_4(const unsigned char *in)
25
27
  return result;
26
28
  }
27
29
 
28
- void fe_frombytes(fe h,const unsigned char *s)
30
+ void
31
+ fe_frombytes(fe h, const unsigned char *s)
29
32
  {
30
33
  uint64_t h0 = load_4(s);
31
34
  uint64_t h1 = load_3(s + 4) << 6;
@@ -1,20 +1,15 @@
1
1
 
2
2
  #include "crypto_scalarmult_curve25519.h"
3
+ #include "private/implementations.h"
3
4
  #include "scalarmult_curve25519.h"
4
5
  #include "runtime.h"
5
6
 
6
7
  #ifdef HAVE_AVX_ASM
7
8
  # include "sandy2x/curve25519_sandy2x.h"
8
9
  #endif
9
- #ifdef HAVE_TI_MODE
10
- # include "donna_c64/curve25519_donna_c64.h"
11
- static const crypto_scalarmult_curve25519_implementation *implementation =
12
- &crypto_scalarmult_curve25519_donna_c64_implementation;
13
- #else
14
- # include "ref10/x25519_ref10.h"
10
+ #include "ref10/x25519_ref10.h"
15
11
  static const crypto_scalarmult_curve25519_implementation *implementation =
16
12
  &crypto_scalarmult_curve25519_ref10_implementation;
17
- #endif
18
13
 
19
14
  int
20
15
  crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,
@@ -53,11 +48,8 @@ crypto_scalarmult_curve25519_scalarbytes(void)
53
48
  int
54
49
  _crypto_scalarmult_curve25519_pick_best_implementation(void)
55
50
  {
56
- #ifdef HAVE_TI_MODE
57
- implementation = &crypto_scalarmult_curve25519_donna_c64_implementation;
58
- #else
59
51
  implementation = &crypto_scalarmult_curve25519_ref10_implementation;
60
- #endif
52
+
61
53
  #ifdef HAVE_AVX_ASM
62
54
  if (sodium_runtime_has_avx()) {
63
55
  implementation = &crypto_scalarmult_curve25519_sandy2x_implementation;
@@ -0,0 +1,86 @@
1
+
2
+ #include <string.h>
3
+
4
+ #include "crypto_scalarmult_ed25519.h"
5
+ #include "private/ed25519_ref10.h"
6
+ #include "utils.h"
7
+
8
+ static int
9
+ _crypto_scalarmult_ed25519_is_inf(const unsigned char s[32])
10
+ {
11
+ unsigned char c;
12
+ unsigned int i;
13
+
14
+ c = s[0] ^ 0x01;
15
+ for (i = 1; i < 31; i++) {
16
+ c |= s[i];
17
+ }
18
+ c |= s[31] & 0x7f;
19
+
20
+ return ((((unsigned int) c) - 1U) >> 8) & 1;
21
+ }
22
+
23
+ static inline void
24
+ _crypto_scalarmult_ed25519_clamp(unsigned char k[32])
25
+ {
26
+ k[0] &= 248;
27
+ k[31] &= 127;
28
+ k[31] |= 64;
29
+ }
30
+
31
+ int
32
+ crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n,
33
+ const unsigned char *p)
34
+ {
35
+ unsigned char *t = q;
36
+ ge25519_p3 Q;
37
+ ge25519_p3 P;
38
+ unsigned int i;
39
+
40
+ if (ge25519_is_canonical(p) == 0 || ge25519_has_small_order(p) != 0 ||
41
+ ge25519_frombytes(&P, p) != 0 || ge25519_is_on_main_subgroup(&P) == 0) {
42
+ return -1;
43
+ }
44
+ for (i = 0; i < 32; ++i) {
45
+ t[i] = n[i];
46
+ }
47
+ _crypto_scalarmult_ed25519_clamp(t);
48
+ ge25519_scalarmult(&Q, t, &P);
49
+ ge25519_p3_tobytes(q, &Q);
50
+ if (_crypto_scalarmult_ed25519_is_inf(q) != 0 || sodium_is_zero(n, 32)) {
51
+ return -1;
52
+ }
53
+ return 0;
54
+ }
55
+
56
+ int
57
+ crypto_scalarmult_ed25519_base(unsigned char *q,
58
+ const unsigned char *n)
59
+ {
60
+ unsigned char *t = q;
61
+ ge25519_p3 Q;
62
+ unsigned int i;
63
+
64
+ for (i = 0; i < 32; ++i) {
65
+ t[i] = n[i];
66
+ }
67
+ _crypto_scalarmult_ed25519_clamp(t);
68
+ ge25519_scalarmult_base(&Q, t);
69
+ ge25519_p3_tobytes(q, &Q);
70
+ if (sodium_is_zero(n, 32) != 0) {
71
+ return -1;
72
+ }
73
+ return 0;
74
+ }
75
+
76
+ size_t
77
+ crypto_scalarmult_ed25519_bytes(void)
78
+ {
79
+ return crypto_scalarmult_ed25519_BYTES;
80
+ }
81
+
82
+ size_t
83
+ crypto_scalarmult_ed25519_scalarbytes(void)
84
+ {
85
+ return crypto_scalarmult_ed25519_SCALARBYTES;
86
+ }
@@ -4,8 +4,8 @@
4
4
  #include "crypto_hash_sha512.h"
5
5
  #include "crypto_scalarmult_curve25519.h"
6
6
  #include "crypto_sign_ed25519.h"
7
- #include "ed25519_ref10.h"
8
- #include "private/curve25519_ref10.h"
7
+ #include "sign_ed25519_ref10.h"
8
+ #include "private/ed25519_ref10.h"
9
9
  #include "randombytes.h"
10
10
  #include "utils.h"
11
11
 
@@ -13,15 +13,19 @@ int
13
13
  crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,
14
14
  const unsigned char *seed)
15
15
  {
16
- ge_p3 A;
16
+ ge25519_p3 A;
17
17
 
18
+ #ifdef ED25519_NONDETERMINISTIC
19
+ memmove(sk, seed, 32);
20
+ #else
18
21
  crypto_hash_sha512(sk, seed, 32);
22
+ #endif
19
23
  sk[0] &= 248;
20
- sk[31] &= 63;
24
+ sk[31] &= 127;
21
25
  sk[31] |= 64;
22
26
 
23
- ge_scalarmult_base(&A, sk);
24
- ge_p3_tobytes(pk, &A);
27
+ ge25519_scalarmult_base(&A, sk);
28
+ ge25519_p3_tobytes(pk, &A);
25
29
 
26
30
  memmove(sk, seed, 32);
27
31
  memmove(sk + 32, pk, 32);
@@ -46,26 +50,22 @@ int
46
50
  crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
47
51
  const unsigned char *ed25519_pk)
48
52
  {
49
- ge_p3 A;
50
- ge_p3 pl;
51
- fe x;
52
- fe one_minus_y;
53
+ ge25519_p3 A;
54
+ fe25519 x;
55
+ fe25519 one_minus_y;
53
56
 
54
- if (_crypto_sign_ed25519_small_order(ed25519_pk) ||
55
- ge_frombytes_negate_vartime(&A, ed25519_pk) != 0) {
56
- return -1;
57
- }
58
- ge_mul_l(&pl, &A);
59
- if (fe_isnonzero(pl.X)) {
57
+ if (ge25519_has_small_order(ed25519_pk) != 0 ||
58
+ ge25519_frombytes_negate_vartime(&A, ed25519_pk) != 0 ||
59
+ ge25519_is_on_main_subgroup(&A) == 0) {
60
60
  return -1;
61
61
  }
62
- fe_1(one_minus_y);
63
- fe_sub(one_minus_y, one_minus_y, A.Y);
64
- fe_invert(one_minus_y, one_minus_y);
65
- fe_1(x);
66
- fe_add(x, x, A.Y);
67
- fe_mul(x, x, one_minus_y);
68
- fe_tobytes(curve25519_pk, x);
62
+ fe25519_1(one_minus_y);
63
+ fe25519_sub(one_minus_y, one_minus_y, A.Y);
64
+ fe25519_invert(one_minus_y, one_minus_y);
65
+ fe25519_1(x);
66
+ fe25519_add(x, x, A.Y);
67
+ fe25519_mul(x, x, one_minus_y);
68
+ fe25519_tobytes(curve25519_pk, x);
69
69
 
70
70
  return 0;
71
71
  }
@@ -76,9 +76,11 @@ crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
76
76
  {
77
77
  unsigned char h[crypto_hash_sha512_BYTES];
78
78
 
79
- crypto_hash_sha512(h, ed25519_sk,
80
- crypto_sign_ed25519_SECRETKEYBYTES -
81
- crypto_sign_ed25519_PUBLICKEYBYTES);
79
+ #ifdef ED25519_NONDETERMINISTIC
80
+ memcpy(h, ed25519_sk, 32);
81
+ #else
82
+ crypto_hash_sha512(h, ed25519_sk, 32);
83
+ #endif
82
84
  h[0] &= 248;
83
85
  h[31] &= 127;
84
86
  h[31] |= 64;
@@ -6,7 +6,7 @@
6
6
  #include "crypto_hash_sha512.h"
7
7
  #include "crypto_sign_edwards25519sha512batch.h"
8
8
  #include "crypto_verify_32.h"
9
- #include "private/curve25519_ref10.h"
9
+ #include "private/ed25519_ref10.h"
10
10
  #include "randombytes.h"
11
11
  #include "utils.h"
12
12
 
@@ -14,15 +14,15 @@ int
14
14
  crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk,
15
15
  unsigned char *sk)
16
16
  {
17
- ge_p3 A;
17
+ ge25519_p3 A;
18
18
 
19
19
  randombytes_buf(sk, 32);
20
20
  crypto_hash_sha512(sk, sk, 32);
21
21
  sk[0] &= 248;
22
- sk[31] &= 63;
22
+ sk[31] &= 127;
23
23
  sk[31] |= 64;
24
- ge_scalarmult_base(&A, sk);
25
- ge_p3_tobytes(pk, &A);
24
+ ge25519_scalarmult_base(&A, sk);
25
+ ge25519_p3_tobytes(pk, &A);
26
26
 
27
27
  return 0;
28
28
  }
@@ -38,24 +38,24 @@ crypto_sign_edwards25519sha512batch(unsigned char *sm,
38
38
  unsigned char nonce[64];
39
39
  unsigned char hram[64];
40
40
  unsigned char sig[64];
41
- ge_p3 A;
42
- ge_p3 R;
41
+ ge25519_p3 A;
42
+ ge25519_p3 R;
43
43
 
44
44
  crypto_hash_sha512_init(&hs);
45
45
  crypto_hash_sha512_update(&hs, sk + 32, 32);
46
46
  crypto_hash_sha512_update(&hs, m, mlen);
47
47
  crypto_hash_sha512_final(&hs, nonce);
48
- ge_scalarmult_base(&A, sk);
49
- ge_p3_tobytes(sig + 32, &A);
50
- sc_reduce(nonce);
51
- ge_scalarmult_base(&R, nonce);
52
- ge_p3_tobytes(sig, &R);
48
+ ge25519_scalarmult_base(&A, sk);
49
+ ge25519_p3_tobytes(sig + 32, &A);
50
+ sc25519_reduce(nonce);
51
+ ge25519_scalarmult_base(&R, nonce);
52
+ ge25519_p3_tobytes(sig, &R);
53
53
  crypto_hash_sha512_init(&hs);
54
54
  crypto_hash_sha512_update(&hs, sig, 32);
55
55
  crypto_hash_sha512_update(&hs, m, mlen);
56
56
  crypto_hash_sha512_final(&hs, hram);
57
- sc_reduce(hram);
58
- sc_muladd(sig + 32, hram, nonce, sk);
57
+ sc25519_reduce(hram);
58
+ sc25519_muladd(sig + 32, hram, nonce, sk);
59
59
  sodium_memzero(hram, sizeof hram);
60
60
  memmove(sm + 32, m, (size_t) mlen);
61
61
  memcpy(sm, sig, 32);
@@ -75,12 +75,12 @@ crypto_sign_edwards25519sha512batch_open(unsigned char *m,
75
75
  unsigned char h[64];
76
76
  unsigned char t1[32], t2[32];
77
77
  unsigned long long mlen;
78
- ge_cached Ai;
79
- ge_p1p1 csa;
80
- ge_p2 cs;
81
- ge_p3 A;
82
- ge_p3 R;
83
- ge_p3 cs3;
78
+ ge25519_cached Ai;
79
+ ge25519_p1p1 csa;
80
+ ge25519_p2 cs;
81
+ ge25519_p3 A;
82
+ ge25519_p3 R;
83
+ ge25519_p3 cs3;
84
84
 
85
85
  *mlen_p = 0;
86
86
  if (smlen < 64 || smlen - 64 > crypto_sign_edwards25519sha512batch_MESSAGEBYTES_MAX) {
@@ -90,20 +90,22 @@ crypto_sign_edwards25519sha512batch_open(unsigned char *m,
90
90
  if (sm[smlen - 1] & 224) {
91
91
  return -1;
92
92
  }
93
- if (ge_frombytes_negate_vartime(&A, pk) != 0 ||
94
- ge_frombytes_negate_vartime(&R, sm) != 0) {
93
+ if (ge25519_has_small_order(pk) != 0 ||
94
+ ge25519_frombytes_negate_vartime(&A, pk) != 0 ||
95
+ ge25519_has_small_order(sm) != 0 ||
96
+ ge25519_frombytes_negate_vartime(&R, sm) != 0) {
95
97
  return -1;
96
98
  }
97
- ge_p3_to_cached(&Ai, &A);
99
+ ge25519_p3_to_cached(&Ai, &A);
98
100
  crypto_hash_sha512(h, sm, mlen + 32);
99
- sc_reduce(h);
100
- ge_scalarmult_vartime(&cs3, h, &R);
101
- ge_add(&csa, &cs3, &Ai);
102
- ge_p1p1_to_p2(&cs, &csa);
103
- ge_tobytes(t1, &cs);
101
+ sc25519_reduce(h);
102
+ ge25519_scalarmult(&cs3, h, &R);
103
+ ge25519_add(&csa, &cs3, &Ai);
104
+ ge25519_p1p1_to_p2(&cs, &csa);
105
+ ge25519_tobytes(t1, &cs);
104
106
  t1[31] ^= 1 << 7;
105
- ge_scalarmult_base(&R, sm + 32 + mlen);
106
- ge_p3_tobytes(t2, &R);
107
+ ge25519_scalarmult_base(&R, sm + 32 + mlen);
108
+ ge25519_p3_tobytes(t2, &R);
107
109
  if (crypto_verify_32(t1, t2) != 0) {
108
110
  return -1;
109
111
  }
@@ -6,107 +6,10 @@
6
6
  #include "crypto_hash_sha512.h"
7
7
  #include "crypto_sign_ed25519.h"
8
8
  #include "crypto_verify_32.h"
9
- #include "ed25519_ref10.h"
10
- #include "private/curve25519_ref10.h"
9
+ #include "sign_ed25519_ref10.h"
10
+ #include "private/ed25519_ref10.h"
11
11
  #include "utils.h"
12
12
 
13
- #ifndef ED25519_COMPAT
14
- static int
15
- crypto_sign_check_S_lt_L(const unsigned char *S)
16
- {
17
- /* 2^252+27742317777372353535851937790883648493 */
18
- static const unsigned char L[32] = {
19
- 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7,
20
- 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
22
- };
23
- unsigned char c = 0;
24
- unsigned char n = 1;
25
- unsigned int i = 32;
26
-
27
- do {
28
- i--;
29
- c |= ((S[i] - L[i]) >> 8) & n;
30
- n &= ((S[i] ^ L[i]) - 1) >> 8;
31
- } while (i != 0);
32
-
33
- return -(c == 0);
34
- }
35
-
36
- int
37
- _crypto_sign_ed25519_small_order(const unsigned char p[32])
38
- {
39
- CRYPTO_ALIGN(16)
40
- static const unsigned char blacklist[][32] = {
41
- /* 0 (order 4) */
42
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
45
- /* 1 (order 1) */
46
- { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
49
- /* 2707385501144840649318225287225658788936804267575313519463743609750303402022
50
- (order 8) */
51
- { 0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4,
52
- 0x89, 0xf2, 0xef, 0x98, 0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6,
53
- 0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x05 },
54
- /* 55188659117513257062467267217118295137698188065244968500265048394206261417927
55
- (order 8) */
56
- { 0xc7, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b,
57
- 0x76, 0x0d, 0x10, 0x67, 0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39,
58
- 0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac, 0x03, 0x7a },
59
- /* p-1 (order 2) */
60
- { 0x13, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4,
61
- 0x89, 0xf2, 0xef, 0x98, 0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6,
62
- 0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x85 },
63
- /* p (order 4) */
64
- { 0xb4, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b,
65
- 0x76, 0x0d, 0x10, 0x67, 0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39,
66
- 0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac, 0x03, 0xfa },
67
- /* p+1 (order 1) */
68
- { 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
69
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
70
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },
71
- /* p+2707385501144840649318225287225658788936804267575313519463743609750303402022
72
- (order 8) */
73
- { 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
74
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
75
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },
76
- /* p+55188659117513257062467267217118295137698188065244968500265048394206261417927
77
- (order 8) */
78
- { 0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
79
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
80
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },
81
- /* 2p-1 (order 2) */
82
- { 0xd9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
83
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
84
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
85
- /* 2p (order 4) */
86
- { 0xda, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
87
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
88
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
89
- /* 2p+1 (order 1) */
90
- { 0xdb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
91
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
92
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
93
- };
94
- size_t i, j;
95
- unsigned char c;
96
-
97
- for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {
98
- c = 0;
99
- for (j = 0; j < 32; j++) {
100
- c |= p[j] ^ blacklist[i][j];
101
- }
102
- if (c == 0) {
103
- return 1;
104
- }
105
- }
106
- return 0;
107
- }
108
- #endif
109
-
110
13
  int
111
14
  _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
112
15
  const unsigned char *m,
@@ -117,14 +20,15 @@ _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
117
20
  crypto_hash_sha512_state hs;
118
21
  unsigned char h[64];
119
22
  unsigned char rcheck[32];
120
- unsigned int i;
121
- unsigned char d = 0;
122
- ge_p3 A;
123
- ge_p2 R;
23
+ ge25519_p3 A;
24
+ ge25519_p2 R;
124
25
 
125
26
  #ifndef ED25519_COMPAT
126
- if (crypto_sign_check_S_lt_L(sig + 32) != 0 ||
127
- _crypto_sign_ed25519_small_order(sig) != 0) {
27
+ if (sc25519_is_canonical(sig + 32) == 0 ||
28
+ ge25519_has_small_order(sig) != 0) {
29
+ return -1;
30
+ }
31
+ if (ge25519_is_canonical(pk) == 0) {
128
32
  return -1;
129
33
  }
130
34
  #else
@@ -132,13 +36,8 @@ _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
132
36
  return -1;
133
37
  }
134
38
  #endif
135
- if (ge_frombytes_negate_vartime(&A, pk) != 0) {
136
- return -1;
137
- }
138
- for (i = 0; i < 32; ++i) {
139
- d |= pk[i];
140
- }
141
- if (d == 0) {
39
+ if (ge25519_has_small_order(pk) != 0 ||
40
+ ge25519_frombytes_negate_vartime(&A, pk) != 0) {
142
41
  return -1;
143
42
  }
144
43
  _crypto_sign_ed25519_ref10_hinit(&hs, prehashed);
@@ -146,10 +45,10 @@ _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
146
45
  crypto_hash_sha512_update(&hs, pk, 32);
147
46
  crypto_hash_sha512_update(&hs, m, mlen);
148
47
  crypto_hash_sha512_final(&hs, h);
149
- sc_reduce(h);
48
+ sc25519_reduce(h);
150
49
 
151
- ge_double_scalarmult_vartime(&R, h, &A, sig + 32);
152
- ge_tobytes(rcheck, &R);
50
+ ge25519_double_scalarmult_vartime(&R, h, &A, sig + 32);
51
+ ge25519_tobytes(rcheck, &R);
153
52
 
154
53
  return crypto_verify_32(rcheck, sig) | (-(rcheck == sig)) |
155
54
  sodium_memcmp(sig, rcheck, 32);