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
@@ -3,8 +3,9 @@
3
3
 
4
4
  #include "crypto_hash_sha512.h"
5
5
  #include "crypto_sign_ed25519.h"
6
- #include "ed25519_ref10.h"
7
- #include "private/curve25519_ref10.h"
6
+ #include "sign_ed25519_ref10.h"
7
+ #include "private/ed25519_ref10.h"
8
+ #include "randombytes.h"
8
9
  #include "utils.h"
9
10
 
10
11
  void
@@ -23,6 +24,43 @@ _crypto_sign_ed25519_ref10_hinit(crypto_hash_sha512_state *hs, int prehashed)
23
24
  }
24
25
  }
25
26
 
27
+ static inline void
28
+ _crypto_sign_ed25519_clamp(unsigned char k[32])
29
+ {
30
+ k[0] &= 248;
31
+ k[31] &= 127;
32
+ k[31] |= 64;
33
+ }
34
+
35
+ #ifdef ED25519_NONDETERMINISTIC
36
+ /* r = hash(B || empty_labelset || Z || pad1 || k || pad2 || empty_labelset || K || extra || M) (mod q) */
37
+ static void
38
+ _crypto_sign_ed25519_synthetic_r_hv(crypto_hash_sha512_state *hs,
39
+ unsigned char Z[32],
40
+ const unsigned char sk[64])
41
+ {
42
+ static const unsigned char B[32] = {
43
+ 0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
44
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
45
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
46
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
47
+ };
48
+ static const unsigned char zeros[128] = { 0x00 };
49
+ static const unsigned char empty_labelset[3] = { 0x02, 0x00, 0x00 };
50
+
51
+ crypto_hash_sha512_update(hs, B, 32);
52
+ crypto_hash_sha512_update(hs, empty_labelset, 3);
53
+ randombytes_buf(Z, 32);
54
+ crypto_hash_sha512_update(hs, Z, 32);
55
+ crypto_hash_sha512_update(hs, zeros, 128 - (32 + 3 + 32) % 128);
56
+ crypto_hash_sha512_update(hs, sk, 32);
57
+ crypto_hash_sha512_update(hs, zeros, 128 - 32 % 128);
58
+ crypto_hash_sha512_update(hs, empty_labelset, 3);
59
+ crypto_hash_sha512_update(hs, sk + 32, 32);
60
+ /* empty extra */
61
+ }
62
+ #endif
63
+
26
64
  int
27
65
  _crypto_sign_ed25519_detached(unsigned char *sig, unsigned long long *siglen_p,
28
66
  const unsigned char *m, unsigned long long mlen,
@@ -32,33 +70,38 @@ _crypto_sign_ed25519_detached(unsigned char *sig, unsigned long long *siglen_p,
32
70
  unsigned char az[64];
33
71
  unsigned char nonce[64];
34
72
  unsigned char hram[64];
35
- ge_p3 R;
36
-
37
- crypto_hash_sha512(az, sk, 32);
38
- az[0] &= 248;
39
- az[31] &= 63;
40
- az[31] |= 64;
73
+ ge25519_p3 R;
41
74
 
42
75
  _crypto_sign_ed25519_ref10_hinit(&hs, prehashed);
76
+
77
+ #ifdef ED25519_NONDETERMINISTIC
78
+ memcpy(az, sk, 32);
79
+ _crypto_sign_ed25519_synthetic_r_hv(&hs, nonce, az);
80
+ #else
81
+ crypto_hash_sha512(az, sk, 32);
43
82
  crypto_hash_sha512_update(&hs, az + 32, 32);
83
+ #endif
84
+
44
85
  crypto_hash_sha512_update(&hs, m, mlen);
45
86
  crypto_hash_sha512_final(&hs, nonce);
46
87
 
47
88
  memmove(sig + 32, sk + 32, 32);
48
89
 
49
- sc_reduce(nonce);
50
- ge_scalarmult_base(&R, nonce);
51
- ge_p3_tobytes(sig, &R);
90
+ sc25519_reduce(nonce);
91
+ ge25519_scalarmult_base(&R, nonce);
92
+ ge25519_p3_tobytes(sig, &R);
52
93
 
53
94
  _crypto_sign_ed25519_ref10_hinit(&hs, prehashed);
54
95
  crypto_hash_sha512_update(&hs, sig, 64);
55
96
  crypto_hash_sha512_update(&hs, m, mlen);
56
97
  crypto_hash_sha512_final(&hs, hram);
57
98
 
58
- sc_reduce(hram);
59
- sc_muladd(sig + 32, hram, az, nonce);
99
+ sc25519_reduce(hram);
100
+ _crypto_sign_ed25519_clamp(az);
101
+ sc25519_muladd(sig + 32, hram, az, nonce);
60
102
 
61
103
  sodium_memzero(az, sizeof az);
104
+ sodium_memzero(nonce, sizeof nonce);
62
105
 
63
106
  if (siglen_p != NULL) {
64
107
  *siglen_p = 64U;
@@ -1,5 +1,5 @@
1
- #ifndef ed25519_ref10_H
2
- #define ed25519_ref10_H
1
+ #ifndef sign_ed25519_ref10_H
2
+ #define sign_ed25519_ref10_H
3
3
 
4
4
  void _crypto_sign_ed25519_ref10_hinit(crypto_hash_sha512_state *hs,
5
5
  int prehashed);
@@ -15,7 +15,4 @@ int _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
15
15
  unsigned long long mlen,
16
16
  const unsigned char *pk,
17
17
  int prehashed);
18
-
19
- int _crypto_sign_ed25519_small_order(const unsigned char p[32]);
20
-
21
18
  #endif
@@ -3,7 +3,7 @@
3
3
 
4
4
  #include "crypto_hash_sha512.h"
5
5
  #include "crypto_sign_ed25519.h"
6
- #include "ref10/ed25519_ref10.h"
6
+ #include "ref10/sign_ed25519_ref10.h"
7
7
 
8
8
  size_t
9
9
  crypto_sign_ed25519ph_statebytes(void)
@@ -1,5 +1,6 @@
1
1
  #include "crypto_stream_chacha20.h"
2
2
  #include "private/common.h"
3
+ #include "private/implementations.h"
3
4
  #include "randombytes.h"
4
5
  #include "runtime.h"
5
6
  #include "stream_chacha20.h"
@@ -1,5 +1,6 @@
1
1
  #include "crypto_stream_salsa20.h"
2
2
  #include "private/common.h"
3
+ #include "private/implementations.h"
3
4
  #include "randombytes.h"
4
5
  #include "runtime.h"
5
6
  #include "stream_salsa20.h"
@@ -96,7 +96,7 @@ if (bytes >= 512) {
96
96
  z4 = orig4;
97
97
  z8 = orig8;
98
98
 
99
- for (i = 0; i < 20; i += 2) {
99
+ for (i = 0; i < ROUNDS; i += 2) {
100
100
  /* the inner loop is a direct translation (regexp search/replace)
101
101
  * from the amd64-xmm6 ASM */
102
102
  __m256i r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13,
@@ -12,6 +12,7 @@ SODIUM_EXPORT = \
12
12
  sodium/crypto_box.h \
13
13
  sodium/crypto_box_curve25519xchacha20poly1305.h \
14
14
  sodium/crypto_box_curve25519xsalsa20poly1305.h \
15
+ sodium/crypto_core_ed25519.h \
15
16
  sodium/crypto_core_hchacha20.h \
16
17
  sodium/crypto_core_hsalsa20.h \
17
18
  sodium/crypto_core_salsa20.h \
@@ -33,6 +34,7 @@ SODIUM_EXPORT = \
33
34
  sodium/crypto_pwhash_scryptsalsa208sha256.h \
34
35
  sodium/crypto_scalarmult.h \
35
36
  sodium/crypto_scalarmult_curve25519.h \
37
+ sodium/crypto_scalarmult_ed25519.h \
36
38
  sodium/crypto_secretbox.h \
37
39
  sodium/crypto_secretbox_xchacha20poly1305.h \
38
40
  sodium/crypto_secretbox_xsalsa20poly1305.h \
@@ -98,7 +98,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_catchable_abrt.m4 \
98
98
  $(top_srcdir)/m4/ax_check_compile_flag.m4 \
99
99
  $(top_srcdir)/m4/ax_check_define.m4 \
100
100
  $(top_srcdir)/m4/ax_check_link_flag.m4 \
101
- $(top_srcdir)/m4/ax_pthread.m4 \
101
+ $(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/ax_tls.m4 \
102
102
  $(top_srcdir)/m4/ax_valgrind_check.m4 \
103
103
  $(top_srcdir)/m4/ld-output-def.m4 $(top_srcdir)/m4/libtool.m4 \
104
104
  $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -139,9 +139,10 @@ am__nobase_include_HEADERS_DIST = sodium.h sodium/core.h \
139
139
  sodium/crypto_auth_hmacsha512256.h sodium/crypto_box.h \
140
140
  sodium/crypto_box_curve25519xchacha20poly1305.h \
141
141
  sodium/crypto_box_curve25519xsalsa20poly1305.h \
142
- sodium/crypto_core_hchacha20.h sodium/crypto_core_hsalsa20.h \
143
- sodium/crypto_core_salsa20.h sodium/crypto_core_salsa2012.h \
144
- sodium/crypto_core_salsa208.h sodium/crypto_generichash.h \
142
+ sodium/crypto_core_ed25519.h sodium/crypto_core_hchacha20.h \
143
+ sodium/crypto_core_hsalsa20.h sodium/crypto_core_salsa20.h \
144
+ sodium/crypto_core_salsa2012.h sodium/crypto_core_salsa208.h \
145
+ sodium/crypto_generichash.h \
145
146
  sodium/crypto_generichash_blake2b.h sodium/crypto_hash.h \
146
147
  sodium/crypto_hash_sha256.h sodium/crypto_hash_sha512.h \
147
148
  sodium/crypto_kdf.h sodium/crypto_kdf_blake2b.h \
@@ -151,7 +152,7 @@ am__nobase_include_HEADERS_DIST = sodium.h sodium/core.h \
151
152
  sodium/crypto_pwhash_scryptsalsa208sha256.h \
152
153
  sodium/crypto_scalarmult.h \
153
154
  sodium/crypto_scalarmult_curve25519.h \
154
- sodium/crypto_secretbox.h \
155
+ sodium/crypto_scalarmult_ed25519.h sodium/crypto_secretbox.h \
155
156
  sodium/crypto_secretbox_xchacha20poly1305.h \
156
157
  sodium/crypto_secretbox_xsalsa20poly1305.h \
157
158
  sodium/crypto_secretstream_xchacha20poly1305.h \
@@ -220,6 +221,7 @@ CTAGS = ctags
220
221
  am__DIST_COMMON = $(srcdir)/Makefile.in
221
222
  DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
222
223
  ACLOCAL = @ACLOCAL@
224
+ ALLOCA = @ALLOCA@
223
225
  AMTAR = @AMTAR@
224
226
  AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
225
227
  AR = @AR@
@@ -240,6 +242,7 @@ CFLAGS_AVX2 = @CFLAGS_AVX2@
240
242
  CFLAGS_AVX512F = @CFLAGS_AVX512F@
241
243
  CFLAGS_MMX = @CFLAGS_MMX@
242
244
  CFLAGS_PCLMUL = @CFLAGS_PCLMUL@
245
+ CFLAGS_RDRAND = @CFLAGS_RDRAND@
243
246
  CFLAGS_SSE2 = @CFLAGS_SSE2@
244
247
  CFLAGS_SSE3 = @CFLAGS_SSE3@
245
248
  CFLAGS_SSE41 = @CFLAGS_SSE41@
@@ -384,9 +387,10 @@ SODIUM_EXPORT = sodium.h sodium/core.h sodium/crypto_aead_aes256gcm.h \
384
387
  sodium/crypto_auth_hmacsha512256.h sodium/crypto_box.h \
385
388
  sodium/crypto_box_curve25519xchacha20poly1305.h \
386
389
  sodium/crypto_box_curve25519xsalsa20poly1305.h \
387
- sodium/crypto_core_hchacha20.h sodium/crypto_core_hsalsa20.h \
388
- sodium/crypto_core_salsa20.h sodium/crypto_core_salsa2012.h \
389
- sodium/crypto_core_salsa208.h sodium/crypto_generichash.h \
390
+ sodium/crypto_core_ed25519.h sodium/crypto_core_hchacha20.h \
391
+ sodium/crypto_core_hsalsa20.h sodium/crypto_core_salsa20.h \
392
+ sodium/crypto_core_salsa2012.h sodium/crypto_core_salsa208.h \
393
+ sodium/crypto_generichash.h \
390
394
  sodium/crypto_generichash_blake2b.h sodium/crypto_hash.h \
391
395
  sodium/crypto_hash_sha256.h sodium/crypto_hash_sha512.h \
392
396
  sodium/crypto_kdf.h sodium/crypto_kdf_blake2b.h \
@@ -396,7 +400,7 @@ SODIUM_EXPORT = sodium.h sodium/core.h sodium/crypto_aead_aes256gcm.h \
396
400
  sodium/crypto_pwhash_scryptsalsa208sha256.h \
397
401
  sodium/crypto_scalarmult.h \
398
402
  sodium/crypto_scalarmult_curve25519.h \
399
- sodium/crypto_secretbox.h \
403
+ sodium/crypto_scalarmult_ed25519.h sodium/crypto_secretbox.h \
400
404
  sodium/crypto_secretbox_xchacha20poly1305.h \
401
405
  sodium/crypto_secretbox_xsalsa20poly1305.h \
402
406
  sodium/crypto_secretstream_xchacha20poly1305.h \
@@ -58,6 +58,8 @@
58
58
 
59
59
  #ifndef SODIUM_LIBRARY_MINIMAL
60
60
  # include "sodium/crypto_box_curve25519xchacha20poly1305.h"
61
+ # include "sodium/crypto_core_ed25519.h"
62
+ # include "sodium/crypto_scalarmult_ed25519.h"
61
63
  # include "sodium/crypto_secretbox_xchacha20poly1305.h"
62
64
  # include "sodium/crypto_pwhash_scryptsalsa208sha256.h"
63
65
  # include "sodium/crypto_stream_salsa2012.h"
@@ -0,0 +1,37 @@
1
+ #ifndef crypto_core_ed25519_H
2
+ #define crypto_core_ed25519_H
3
+
4
+ #include <stddef.h>
5
+ #include "export.h"
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ #define crypto_core_ed25519_BYTES 32
12
+ SODIUM_EXPORT
13
+ size_t crypto_core_ed25519_bytes(void);
14
+
15
+ #define crypto_core_ed25519_UNIFORMBYTES 32
16
+ SODIUM_EXPORT
17
+ size_t crypto_core_ed25519_uniformbytes(void);
18
+
19
+ SODIUM_EXPORT
20
+ int crypto_core_ed25519_is_valid_point(const unsigned char *p);
21
+
22
+ SODIUM_EXPORT
23
+ int crypto_core_ed25519_add(unsigned char *r,
24
+ const unsigned char *p, const unsigned char *q);
25
+
26
+ SODIUM_EXPORT
27
+ int crypto_core_ed25519_sub(unsigned char *r,
28
+ const unsigned char *p, const unsigned char *q);
29
+
30
+ SODIUM_EXPORT
31
+ int crypto_core_ed25519_from_uniform(unsigned char *p, const unsigned char *r);
32
+
33
+ #ifdef __cplusplus
34
+ }
35
+ #endif
36
+
37
+ #endif
@@ -25,6 +25,14 @@ const char *crypto_scalarmult_primitive(void);
25
25
  SODIUM_EXPORT
26
26
  int crypto_scalarmult_base(unsigned char *q, const unsigned char *n);
27
27
 
28
+ /*
29
+ * NOTE: Do not use the result of this function directly.
30
+ *
31
+ * Hash the result with the public keys in order to compute a shared
32
+ * secret key: H(q || client_pk || server_pk)
33
+ *
34
+ * Or unless this is not an option, use the crypto_kx() API instead.
35
+ */
28
36
  SODIUM_EXPORT
29
37
  int crypto_scalarmult(unsigned char *q, const unsigned char *n,
30
38
  const unsigned char *p)
@@ -17,6 +17,14 @@ size_t crypto_scalarmult_curve25519_bytes(void);
17
17
  SODIUM_EXPORT
18
18
  size_t crypto_scalarmult_curve25519_scalarbytes(void);
19
19
 
20
+ /*
21
+ * NOTE: Do not use the result of this function directly.
22
+ *
23
+ * Hash the result with the public keys in order to compute a shared
24
+ * secret key: H(q || client_pk || server_pk)
25
+ *
26
+ * Or unless this is not an option, use the crypto_kx() API instead.
27
+ */
20
28
  SODIUM_EXPORT
21
29
  int crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,
22
30
  const unsigned char *p)
@@ -0,0 +1,41 @@
1
+
2
+ #ifndef crypto_scalarmult_ed25519_H
3
+ #define crypto_scalarmult_ed25519_H
4
+
5
+ #include <stddef.h>
6
+
7
+ #include "export.h"
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ #define crypto_scalarmult_ed25519_BYTES 32U
14
+ SODIUM_EXPORT
15
+ size_t crypto_scalarmult_ed25519_bytes(void);
16
+
17
+ #define crypto_scalarmult_ed25519_SCALARBYTES 32U
18
+ SODIUM_EXPORT
19
+ size_t crypto_scalarmult_ed25519_scalarbytes(void);
20
+
21
+ /*
22
+ * NOTE: Do not use the result of this function directly.
23
+ *
24
+ * Hash the result with the public keys in order to compute a shared
25
+ * secret key: H(q || client_pk || server_pk)
26
+ *
27
+ * Or unless this is not an option, use the crypto_kx() API instead.
28
+ */
29
+ SODIUM_EXPORT
30
+ int crypto_scalarmult_ed25519(unsigned char *q, const unsigned char *n,
31
+ const unsigned char *p)
32
+ __attribute__ ((warn_unused_result));
33
+
34
+ SODIUM_EXPORT
35
+ int crypto_scalarmult_ed25519_base(unsigned char *q, const unsigned char *n);
36
+
37
+ #ifdef __cplusplus
38
+ }
39
+ #endif
40
+
41
+ #endif
@@ -7,6 +7,14 @@
7
7
 
8
8
  #define COMPILER_ASSERT(X) (void) sizeof(char[(X) ? 1 : -1])
9
9
 
10
+ #ifdef HAVE_TI_MODE
11
+ # if defined(__SIZEOF_INT128__)
12
+ typedef unsigned __int128 uint128_t;
13
+ # else
14
+ typedef unsigned uint128_t __attribute__((mode(TI)));
15
+ # endif
16
+ #endif
17
+
10
18
  #define ROTL32(X, B) rotl32((X), (B))
11
19
  static inline uint32_t
12
20
  rotl32(const uint32_t x, const int b)
@@ -225,4 +233,14 @@ xor_buf(unsigned char *out, const unsigned char *in, size_t n)
225
233
  # include <intrin.h>
226
234
  #endif
227
235
 
236
+ #ifdef HAVE_LIBCTGRIND
237
+ extern void ct_poison (const void *, size_t);
238
+ extern void ct_unpoison(const void *, size_t);
239
+ # define POISON(X, L) ct_poison((X), (L))
240
+ # define UNPOISON(X, L) ct_unpoison((X), (L))
241
+ #else
242
+ # define POISON(X, L) (void) 0
243
+ # define UNPOISON(X, L) (void) 0
244
+ #endif
245
+
228
246
  #endif
@@ -0,0 +1,125 @@
1
+ #ifndef ed25519_ref10_H
2
+ #define ed25519_ref10_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ /*
8
+ fe means field element.
9
+ Here the field is \Z/(2^255-19).
10
+ */
11
+
12
+ #ifdef HAVE_TI_MODE
13
+ typedef uint64_t fe25519[5];
14
+ #else
15
+ typedef int32_t fe25519[10];
16
+ #endif
17
+
18
+ void fe25519_invert(fe25519 out, const fe25519 z);
19
+ void fe25519_frombytes(fe25519 h, const unsigned char *s);
20
+ void fe25519_tobytes(unsigned char *s, const fe25519 h);
21
+
22
+ #ifdef HAVE_TI_MODE
23
+ # include "ed25519_ref10_fe_51.h"
24
+ #else
25
+ # include "ed25519_ref10_fe_25_5.h"
26
+ #endif
27
+
28
+
29
+ /*
30
+ ge means group element.
31
+
32
+ Here the group is the set of pairs (x,y) of field elements
33
+ satisfying -x^2 + y^2 = 1 + d x^2y^2
34
+ where d = -121665/121666.
35
+
36
+ Representations:
37
+ ge25519_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
38
+ ge25519_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
39
+ ge25519_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
40
+ ge25519_precomp (Duif): (y+x,y-x,2dxy)
41
+ */
42
+
43
+ typedef struct {
44
+ fe25519 X;
45
+ fe25519 Y;
46
+ fe25519 Z;
47
+ } ge25519_p2;
48
+
49
+ typedef struct {
50
+ fe25519 X;
51
+ fe25519 Y;
52
+ fe25519 Z;
53
+ fe25519 T;
54
+ } ge25519_p3;
55
+
56
+ typedef struct {
57
+ fe25519 X;
58
+ fe25519 Y;
59
+ fe25519 Z;
60
+ fe25519 T;
61
+ } ge25519_p1p1;
62
+
63
+ typedef struct {
64
+ fe25519 yplusx;
65
+ fe25519 yminusx;
66
+ fe25519 xy2d;
67
+ } ge25519_precomp;
68
+
69
+ typedef struct {
70
+ fe25519 YplusX;
71
+ fe25519 YminusX;
72
+ fe25519 Z;
73
+ fe25519 T2d;
74
+ } ge25519_cached;
75
+
76
+ void ge25519_tobytes(unsigned char *s, const ge25519_p2 *h);
77
+
78
+ void ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h);
79
+
80
+ int ge25519_frombytes(ge25519_p3 *h, const unsigned char *s);
81
+
82
+ int ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s);
83
+
84
+ void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p);
85
+
86
+ void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p);
87
+
88
+ void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p);
89
+
90
+ void ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q);
91
+
92
+ void ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q);
93
+
94
+ void ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a);
95
+
96
+ void ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a,
97
+ const ge25519_p3 *A,
98
+ const unsigned char *b);
99
+
100
+ void ge25519_scalarmult(ge25519_p3 *h, const unsigned char *a,
101
+ const ge25519_p3 *p);
102
+
103
+ int ge25519_is_canonical(const unsigned char *s);
104
+
105
+ int ge25519_is_on_curve(const ge25519_p3 *p);
106
+
107
+ int ge25519_is_on_main_subgroup(const ge25519_p3 *p);
108
+
109
+ int ge25519_has_small_order(const unsigned char s[32]);
110
+
111
+ void ge25519_from_uniform(unsigned char s[32], const unsigned char r[32]);
112
+
113
+ /*
114
+ The set of scalars is \Z/l
115
+ where l = 2^252 + 27742317777372353535851937790883648493.
116
+ */
117
+
118
+ void sc25519_reduce(unsigned char *s);
119
+
120
+ void sc25519_muladd(unsigned char *s, const unsigned char *a,
121
+ const unsigned char *b, const unsigned char *c);
122
+
123
+ int sc25519_is_canonical(const unsigned char *s);
124
+
125
+ #endif