rbnacl-libsodium 0.5.0.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/lib/rbnacl/libsodium/version.rb +1 -1
  4. data/vendor/libsodium/AUTHORS +62 -81
  5. data/vendor/libsodium/ChangeLog +31 -1
  6. data/vendor/libsodium/README.markdown +15 -364
  7. data/vendor/libsodium/THANKS +6 -0
  8. data/vendor/libsodium/autom4te.cache/output.0 +67 -36
  9. data/vendor/libsodium/autom4te.cache/output.1 +67 -36
  10. data/vendor/libsodium/autom4te.cache/output.2 +67 -36
  11. data/vendor/libsodium/autom4te.cache/traces.0 +52 -51
  12. data/vendor/libsodium/autom4te.cache/traces.1 +137 -133
  13. data/vendor/libsodium/autom4te.cache/traces.2 +52 -51
  14. data/vendor/libsodium/builds/msvc/version.h +2 -2
  15. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +365 -345
  16. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +1114 -1037
  17. data/vendor/libsodium/builds/msvc/vs2010/test/test.props +8 -2
  18. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +364 -344
  19. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +1113 -1036
  20. data/vendor/libsodium/builds/msvc/vs2012/test/test.props +8 -2
  21. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +365 -345
  22. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +1114 -1037
  23. data/vendor/libsodium/builds/msvc/vs2013/test/test.props +8 -2
  24. data/vendor/libsodium/configure +66 -35
  25. data/vendor/libsodium/configure.ac +25 -14
  26. data/vendor/libsodium/dist-build/ios.sh +1 -1
  27. data/vendor/libsodium/dist-build/msys2-win64.sh +1 -1
  28. data/vendor/libsodium/libsodium.vcxproj +29 -14
  29. data/vendor/libsodium/libsodium.vcxproj.filters +77 -28
  30. data/vendor/libsodium/msvc-scripts/process.bat +3 -3
  31. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  32. data/vendor/libsodium/packaging/nuget/package.gsl +6 -1
  33. data/vendor/libsodium/packaging/nuget/package.nuspec +1 -1
  34. data/vendor/libsodium/src/libsodium/Makefile.am +31 -13
  35. data/vendor/libsodium/src/libsodium/Makefile.in +406 -155
  36. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +146 -0
  37. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box.c +13 -0
  38. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +39 -73
  39. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305_api.c +5 -0
  40. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/api.h +2 -0
  41. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/keypair_curve25519xsalsa20poly1305.c +15 -0
  42. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +6 -5
  43. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +6 -5
  44. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/crypto_onetimeauth.c +25 -0
  45. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +76 -47
  46. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +30 -7
  47. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +3 -16
  48. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +3 -10
  49. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/verify_poly1305_donna.c +11 -6
  50. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +23 -1
  51. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c +1 -1
  52. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/crypto_scrypt-common.c +7 -7
  53. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/crypto_scrypt.h +6 -20
  54. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256_nosse.c → scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c} +0 -0
  55. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/pbkdf2-sha256.c +1 -11
  56. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/pbkdf2-sha256.h +0 -0
  57. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c → scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c} +50 -25
  58. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/scrypt_platform.c +4 -0
  59. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c → scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c} +0 -0
  60. data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/sysendian.h +0 -0
  61. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/smult_curve25519_donna_c64.c +1 -1
  62. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/{ref → ref10}/api.h +0 -3
  63. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/base_curve25519_ref10.c +14 -0
  64. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe.h +44 -0
  65. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_0_curve25519_ref10.c +23 -0
  66. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_1_curve25519_ref10.c +23 -0
  67. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_add_curve25519_ref10.c +61 -0
  68. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_copy_curve25519_ref10.c +33 -0
  69. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_cswap_curve25519_ref10.c +77 -0
  70. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_frombytes_curve25519_ref10.c +73 -0
  71. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_invert_curve25519_ref10.c +18 -0
  72. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_mul121666_curve25519_ref10.c +74 -0
  73. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_mul_curve25519_ref10.c +257 -0
  74. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_sq_curve25519_ref10.c +153 -0
  75. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_sub_curve25519_ref10.c +61 -0
  76. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_tobytes_curve25519_ref10.c +123 -0
  77. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/montgomery.h +140 -0
  78. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/pow225521.h +160 -0
  79. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c +54 -0
  80. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +92 -61
  81. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_scalarmult_base.c +3 -3
  82. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/pow22523.h +2 -2
  83. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/pow225521.h +2 -2
  84. data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/sc25519_edwards25519sha512batch.c +8 -4
  85. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/consts_aes128ctr.c +3 -3
  86. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128.h +6 -3
  87. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128_aes128ctr.c +23 -23
  88. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/api.h +12 -0
  89. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +275 -0
  90. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20_api.c +36 -0
  91. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S +11 -10
  92. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +8 -3
  93. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c +8 -0
  94. data/vendor/libsodium/src/libsodium/include/Makefile.am +3 -2
  95. data/vendor/libsodium/src/libsodium/include/Makefile.in +3 -2
  96. data/vendor/libsodium/src/libsodium/include/sodium.h +3 -1
  97. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +55 -0
  98. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +21 -0
  99. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +11 -1
  100. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash.h +7 -0
  101. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +7 -0
  102. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha512.h +7 -0
  103. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth.h +15 -0
  104. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +25 -0
  105. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +80 -0
  106. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +2 -2
  107. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +14 -0
  108. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +11 -0
  109. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes256estream.h +11 -6
  110. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +49 -0
  111. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +6 -0
  112. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +7 -7
  113. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +10 -14
  114. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +10 -13
  115. data/vendor/libsodium/src/libsodium/sodium/compat.c +55 -4
  116. data/vendor/libsodium/src/libsodium/sodium/utils.c +18 -0
  117. data/vendor/libsodium/test/default/Makefile.am +24 -12
  118. data/vendor/libsodium/test/default/Makefile.in +116 -73
  119. data/vendor/libsodium/test/default/aead_chacha20poly1305.c +97 -0
  120. data/vendor/libsodium/test/default/aead_chacha20poly1305.exp +8 -0
  121. data/vendor/libsodium/test/default/box_easy.c +1 -1
  122. data/vendor/libsodium/test/default/box_seed.c +28 -0
  123. data/vendor/libsodium/test/default/box_seed.exp +8 -0
  124. data/vendor/libsodium/test/default/chacha20.c +45 -0
  125. data/vendor/libsodium/test/default/chacha20.exp +5 -0
  126. data/vendor/libsodium/test/default/pwhash.c +83 -15
  127. data/vendor/libsodium/test/default/pwhash.exp +10 -1
  128. data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +67 -0
  129. data/vendor/libsodium/test/default/pwhash_scrypt_ll.exp +15 -0
  130. data/vendor/libsodium/test/default/secretbox_easy.c +13 -1
  131. data/vendor/libsodium/test/default/secretbox_easy.exp +19 -0
  132. data/vendor/libsodium/test/default/secretbox_easy2.c +5 -0
  133. data/vendor/libsodium/test/default/secretbox_easy2.exp +1 -0
  134. data/vendor/libsodium/test/default/sign.c +7 -3
  135. metadata +44 -21
  136. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/api.h +0 -8
  137. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref/base_curve25519_ref.c +0 -20
  138. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c +0 -268
  139. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_donna.h +0 -37
  140. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h +0 -48
  141. data/vendor/libsodium/test/default/scalarmult7.c +0 -32
  142. data/vendor/libsodium/test/default/scalarmult7.exp +0 -1
  143. data/vendor/libsodium/test/default/scalarmult8.c +0 -32
  144. data/vendor/libsodium/test/default/scalarmult8.exp +0 -1
@@ -0,0 +1,146 @@
1
+
2
+ #include <limits.h>
3
+ #include <string.h>
4
+
5
+ #include "crypto_aead_chacha20poly1305.h"
6
+ #include "crypto_onetimeauth_poly1305.h"
7
+ #include "crypto_stream_chacha20.h"
8
+ #include "crypto_verify_16.h"
9
+ #include "utils.h"
10
+
11
+ static inline void
12
+ _u64_le_from_ull(unsigned char out[8U], unsigned long long x)
13
+ {
14
+ out[0] = (unsigned char) (x & 0xff); x >>= 8;
15
+ out[1] = (unsigned char) (x & 0xff); x >>= 8;
16
+ out[2] = (unsigned char) (x & 0xff); x >>= 8;
17
+ out[3] = (unsigned char) (x & 0xff); x >>= 8;
18
+ out[4] = (unsigned char) (x & 0xff); x >>= 8;
19
+ out[5] = (unsigned char) (x & 0xff); x >>= 8;
20
+ out[6] = (unsigned char) (x & 0xff); x >>= 8;
21
+ out[7] = (unsigned char) (x & 0xff);
22
+ }
23
+
24
+ int
25
+ crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
26
+ unsigned long long *clen,
27
+ const unsigned char *m,
28
+ unsigned long long mlen,
29
+ const unsigned char *ad,
30
+ unsigned long long adlen,
31
+ const unsigned char *nsec,
32
+ const unsigned char *npub,
33
+ const unsigned char *k)
34
+ {
35
+ crypto_onetimeauth_poly1305_state state;
36
+ unsigned char block0[64U];
37
+ unsigned char slen[8U];
38
+
39
+ (void) nsec;
40
+ #ifdef ULONG_LONG_MAX
41
+ if (mlen > ULONG_LONG_MAX - crypto_aead_chacha20poly1305_ABYTES) {
42
+ if (clen != NULL) {
43
+ *clen = 0ULL;
44
+ }
45
+ return -1;
46
+ }
47
+ #endif
48
+
49
+ crypto_stream_chacha20(block0, sizeof block0, npub, k);
50
+ crypto_onetimeauth_poly1305_init(&state, block0);
51
+ sodium_memzero(block0, sizeof block0);
52
+
53
+ crypto_onetimeauth_poly1305_update(&state, ad, adlen);
54
+ _u64_le_from_ull(slen, adlen);
55
+ crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
56
+
57
+ crypto_stream_chacha20_xor_ic(c, m, mlen, npub, 1U, k);
58
+
59
+ crypto_onetimeauth_poly1305_update(&state, c, mlen);
60
+ _u64_le_from_ull(slen, mlen);
61
+ crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
62
+
63
+ crypto_onetimeauth_poly1305_final(&state, c + mlen);
64
+ sodium_memzero(&state, sizeof state);
65
+
66
+ if (clen != NULL) {
67
+ *clen = mlen + crypto_aead_chacha20poly1305_ABYTES;
68
+ }
69
+ return 0;
70
+ }
71
+
72
+ int
73
+ crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
74
+ unsigned long long *mlen,
75
+ unsigned char *nsec,
76
+ const unsigned char *c,
77
+ unsigned long long clen,
78
+ const unsigned char *ad,
79
+ unsigned long long adlen,
80
+ const unsigned char *npub,
81
+ const unsigned char *k)
82
+ {
83
+ crypto_onetimeauth_poly1305_state state;
84
+ unsigned char block0[64U];
85
+ unsigned char slen[8U];
86
+ unsigned char mac[crypto_aead_chacha20poly1305_ABYTES];
87
+ int ret;
88
+
89
+ (void) nsec;
90
+ if (mlen != NULL) {
91
+ *mlen = 0ULL;
92
+ }
93
+ if (clen < crypto_aead_chacha20poly1305_ABYTES) {
94
+ return -1;
95
+ }
96
+ crypto_stream_chacha20(block0, sizeof block0, npub, k);
97
+ crypto_onetimeauth_poly1305_init(&state, block0);
98
+ sodium_memzero(block0, sizeof block0);
99
+
100
+ crypto_onetimeauth_poly1305_update(&state, ad, adlen);
101
+ _u64_le_from_ull(slen, adlen);
102
+ crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
103
+
104
+ crypto_onetimeauth_poly1305_update
105
+ (&state, c, clen - crypto_aead_chacha20poly1305_ABYTES);
106
+ _u64_le_from_ull(slen, clen - crypto_aead_chacha20poly1305_ABYTES);
107
+ crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
108
+
109
+ crypto_onetimeauth_poly1305_final(&state, mac);
110
+ sodium_memzero(&state, sizeof state);
111
+
112
+ (void) sizeof(int[sizeof mac == 16U ? 1 : -1]);
113
+ ret = crypto_verify_16(mac,
114
+ c + clen - crypto_aead_chacha20poly1305_ABYTES);
115
+ sodium_memzero(mac, sizeof mac);
116
+ if (ret != 0) {
117
+ memset(m, 0, clen - crypto_aead_chacha20poly1305_ABYTES);
118
+ return -1;
119
+ }
120
+ crypto_stream_chacha20_xor_ic
121
+ (m, c, clen - crypto_aead_chacha20poly1305_ABYTES, npub, 1U, k);
122
+ if (mlen != NULL) {
123
+ *mlen = clen - crypto_aead_chacha20poly1305_ABYTES;
124
+ }
125
+ return 0;
126
+ }
127
+
128
+ size_t
129
+ crypto_aead_chacha20poly1305_keybytes(void) {
130
+ return crypto_aead_chacha20poly1305_KEYBYTES;
131
+ }
132
+
133
+ size_t
134
+ crypto_aead_chacha20poly1305_npubbytes(void) {
135
+ return crypto_aead_chacha20poly1305_NPUBBYTES;
136
+ }
137
+
138
+ size_t
139
+ crypto_aead_chacha20poly1305_nsecbytes(void) {
140
+ return crypto_aead_chacha20poly1305_NSECBYTES;
141
+ }
142
+
143
+ size_t
144
+ crypto_aead_chacha20poly1305_abytes(void) {
145
+ return crypto_aead_chacha20poly1305_ABYTES;
146
+ }
@@ -1,6 +1,12 @@
1
1
 
2
2
  #include "crypto_box.h"
3
3
 
4
+ size_t
5
+ crypto_box_seedbytes(void)
6
+ {
7
+ return crypto_box_SEEDBYTES;
8
+ }
9
+
4
10
  size_t
5
11
  crypto_box_publickeybytes(void)
6
12
  {
@@ -49,6 +55,13 @@ crypto_box_primitive(void)
49
55
  return crypto_box_PRIMITIVE;
50
56
  }
51
57
 
58
+ int
59
+ crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
60
+ const unsigned char *seed)
61
+ {
62
+ return crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed);
63
+ }
64
+
52
65
  int
53
66
  crypto_box_keypair(unsigned char *pk, unsigned char *sk)
54
67
  {
@@ -1,54 +1,49 @@
1
1
 
2
- #include <assert.h>
3
- #include <limits.h>
4
- #include <stdint.h>
5
- #include <stdlib.h>
6
- #include <string.h>
7
-
8
2
  #include "crypto_box.h"
3
+ #include "crypto_secretbox.h"
9
4
  #include "utils.h"
10
5
 
6
+ int
7
+ crypto_box_detached(unsigned char *c, unsigned char *mac,
8
+ const unsigned char *m, unsigned long long mlen,
9
+ const unsigned char *n, const unsigned char *pk,
10
+ const unsigned char *sk)
11
+ {
12
+ unsigned char k[crypto_box_BEFORENMBYTES];
13
+ int ret;
14
+
15
+ (void) sizeof(int[crypto_box_BEFORENMBYTES >=
16
+ crypto_secretbox_KEYBYTES ? 1 : -1]);
17
+ crypto_box_beforenm(k, pk, sk);
18
+ ret = crypto_secretbox_detached(c, mac, m, mlen, n, k);
19
+ sodium_memzero(k, sizeof k);
20
+
21
+ return ret;
22
+ }
23
+
11
24
  int
12
25
  crypto_box_easy(unsigned char *c, const unsigned char *m,
13
26
  unsigned long long mlen, const unsigned char *n,
14
27
  const unsigned char *pk, const unsigned char *sk)
15
28
  {
16
- unsigned char *c_boxed;
17
- unsigned char *m_boxed;
18
- size_t c_boxed_len;
19
- size_t m_boxed_len;
20
- int rc;
29
+ return crypto_box_detached(c + crypto_box_MACBYTES, c, m, mlen, n,
30
+ pk, sk);
31
+ }
21
32
 
22
- if (mlen > SIZE_MAX - crypto_box_ZEROBYTES) {
23
- return -1;
24
- }
25
- (void) sizeof(char[crypto_box_ZEROBYTES >=
26
- crypto_box_BOXZEROBYTES ? 1 : -1]);
27
- m_boxed_len = (size_t) mlen + crypto_box_ZEROBYTES;
28
- if ((m_boxed = (unsigned char *) malloc((size_t) m_boxed_len)) == NULL) {
29
- return -1;
30
- }
31
- c_boxed_len = (size_t) mlen + crypto_box_ZEROBYTES;
32
- if ((c_boxed = (unsigned char *) malloc(c_boxed_len)) == NULL) {
33
- free(m_boxed);
34
- return -1;
35
- }
36
- memset(m_boxed, 0, crypto_box_ZEROBYTES);
37
- sodium_mlock(m_boxed, m_boxed_len);
38
- memcpy(m_boxed + crypto_box_ZEROBYTES, m, mlen);
39
- rc = crypto_box(c_boxed, m_boxed, m_boxed_len, n, pk, sk);
40
- sodium_munlock(m_boxed, m_boxed_len);
41
- free(m_boxed);
42
- if (rc != 0) {
43
- free(c_boxed);
44
- return -1;
45
- }
46
- assert(m_boxed_len - crypto_box_BOXZEROBYTES ==
47
- mlen + crypto_box_MACBYTES);
48
- memcpy(c, c_boxed + crypto_box_BOXZEROBYTES, mlen + crypto_box_MACBYTES);
49
- free(c_boxed);
33
+ int
34
+ crypto_box_open_detached(unsigned char *m, const unsigned char *c,
35
+ const unsigned char *mac,
36
+ unsigned long long clen, const unsigned char *n,
37
+ const unsigned char *pk, const unsigned char *sk)
38
+ {
39
+ unsigned char k[crypto_box_BEFORENMBYTES];
40
+ int ret;
50
41
 
51
- return 0;
42
+ crypto_box_beforenm(k, pk, sk);
43
+ ret = crypto_secretbox_open_detached(m, c, mac, clen, n, k);
44
+ sodium_memzero(k, sizeof k);
45
+
46
+ return ret;
52
47
  }
53
48
 
54
49
  int
@@ -56,39 +51,10 @@ crypto_box_open_easy(unsigned char *m, const unsigned char *c,
56
51
  unsigned long long clen, const unsigned char *n,
57
52
  const unsigned char *pk, const unsigned char *sk)
58
53
  {
59
- unsigned char *c_boxed;
60
- unsigned char *m_boxed;
61
- size_t c_boxed_len;
62
- size_t m_boxed_len;
63
- int rc;
64
-
65
- if (clen < crypto_box_MACBYTES ||
66
- clen > SIZE_MAX - crypto_box_BOXZEROBYTES) {
54
+ if (clen < crypto_box_MACBYTES) {
67
55
  return -1;
68
56
  }
69
- c_boxed_len = clen + crypto_box_BOXZEROBYTES;
70
- if ((c_boxed = (unsigned char *) malloc(c_boxed_len)) == NULL) {
71
- return -1;
72
- }
73
- memset(c_boxed, 0, crypto_box_BOXZEROBYTES);
74
- memcpy(c_boxed + crypto_box_BOXZEROBYTES, c, clen);
75
- m_boxed_len = c_boxed_len + crypto_box_MACBYTES;
76
- if ((m_boxed = (unsigned char *) malloc(m_boxed_len)) == NULL) {
77
- free(c_boxed);
78
- return -1;
79
- }
80
- sodium_mlock(m_boxed, m_boxed_len);
81
- rc = crypto_box_open(m_boxed, c_boxed,
82
- (unsigned long long) c_boxed_len, n, pk, sk);
83
- free(c_boxed);
84
- if (rc != 0) {
85
- sodium_munlock(m_boxed, m_boxed_len);
86
- free(m_boxed);
87
- return -1;
88
- }
89
- memcpy(m, m_boxed + crypto_box_ZEROBYTES, clen - crypto_box_MACBYTES);
90
- sodium_munlock(m_boxed, m_boxed_len);
91
- free(m_boxed);
92
-
93
- return 0;
57
+ return crypto_box_open_detached(m, c + crypto_box_MACBYTES, c,
58
+ clen - crypto_box_MACBYTES,
59
+ n, pk, sk);
94
60
  }
@@ -1,5 +1,10 @@
1
1
  #include "crypto_box_curve25519xsalsa20poly1305.h"
2
2
 
3
+ size_t
4
+ crypto_box_curve25519xsalsa20poly1305_seedbytes(void) {
5
+ return crypto_box_curve25519xsalsa20poly1305_SEEDBYTES;
6
+ }
7
+
3
8
  size_t
4
9
  crypto_box_curve25519xsalsa20poly1305_publickeybytes(void) {
5
10
  return crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES;
@@ -3,10 +3,12 @@
3
3
 
4
4
  #define crypto_box crypto_box_curve25519xsalsa20poly1305
5
5
  #define crypto_box_open crypto_box_curve25519xsalsa20poly1305_open
6
+ #define crypto_box_seed_keypair crypto_box_curve25519xsalsa20poly1305_seed_keypair
6
7
  #define crypto_box_keypair crypto_box_curve25519xsalsa20poly1305_keypair
7
8
  #define crypto_box_beforenm crypto_box_curve25519xsalsa20poly1305_beforenm
8
9
  #define crypto_box_afternm crypto_box_curve25519xsalsa20poly1305_afternm
9
10
  #define crypto_box_open_afternm crypto_box_curve25519xsalsa20poly1305_open_afternm
11
+ #define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
10
12
  #define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
11
13
  #define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
12
14
  #define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
@@ -1,7 +1,22 @@
1
+ #include <string.h>
2
+
3
+ #include "crypto_hash_sha512.h"
1
4
  #include "crypto_scalarmult_curve25519.h"
2
5
  #include "api.h"
3
6
  #include "randombytes.h"
4
7
 
8
+ int crypto_box_seed_keypair(
9
+ unsigned char *pk,
10
+ unsigned char *sk,
11
+ const unsigned char *seed
12
+ )
13
+ {
14
+ unsigned char hash[64];
15
+ crypto_hash_sha512(hash,seed,32);
16
+ memmove(sk,hash,32);
17
+ return crypto_scalarmult_curve25519_base(pk,sk);
18
+ }
19
+
5
20
  int crypto_box_keypair(
6
21
  unsigned char *pk,
7
22
  unsigned char *sk
@@ -48,13 +48,13 @@ static inline int blake2b_set_lastnode( blake2b_state *S )
48
48
  S->f[1] = ~0ULL;
49
49
  return 0;
50
50
  }
51
-
51
+ #if 0
52
52
  static inline int blake2b_clear_lastnode( blake2b_state *S )
53
53
  {
54
54
  S->f[1] = 0ULL;
55
55
  return 0;
56
56
  }
57
-
57
+ #endif
58
58
  /* Some helper functions, not necessarily useful */
59
59
  static inline int blake2b_set_lastblock( blake2b_state *S )
60
60
  {
@@ -63,7 +63,7 @@ static inline int blake2b_set_lastblock( blake2b_state *S )
63
63
  S->f[0] = ~0ULL;
64
64
  return 0;
65
65
  }
66
-
66
+ #if 0
67
67
  static inline int blake2b_clear_lastblock( blake2b_state *S )
68
68
  {
69
69
  if( S->last_node ) blake2b_clear_lastnode( S );
@@ -71,7 +71,7 @@ static inline int blake2b_clear_lastblock( blake2b_state *S )
71
71
  S->f[0] = 0ULL;
72
72
  return 0;
73
73
  }
74
-
74
+ #endif
75
75
  static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
76
76
  {
77
77
  S->t[0] += inc;
@@ -82,6 +82,7 @@ static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t in
82
82
 
83
83
 
84
84
  // Parameter-related functions
85
+ #if 0
85
86
  static inline int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length )
86
87
  {
87
88
  P->digest_length = digest_length;
@@ -123,7 +124,7 @@ static inline int blake2b_param_set_inner_length( blake2b_param *P, const uint8_
123
124
  P->inner_length = inner_length;
124
125
  return 0;
125
126
  }
126
-
127
+ #endif
127
128
  static inline int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] )
128
129
  {
129
130
  memcpy( P->salt, salt, BLAKE2B_SALTBYTES );
@@ -44,13 +44,13 @@ static inline int blake2s_set_lastnode( blake2s_state *S )
44
44
  S->f[1] = ~0U;
45
45
  return 0;
46
46
  }
47
-
47
+ #if 0
48
48
  static inline int blake2s_clear_lastnode( blake2s_state *S )
49
49
  {
50
50
  S->f[1] = 0U;
51
51
  return 0;
52
52
  }
53
-
53
+ #endif
54
54
  /* Some helper functions, not necessarily useful */
55
55
  static inline int blake2s_set_lastblock( blake2s_state *S )
56
56
  {
@@ -59,7 +59,7 @@ static inline int blake2s_set_lastblock( blake2s_state *S )
59
59
  S->f[0] = ~0U;
60
60
  return 0;
61
61
  }
62
-
62
+ #if 0
63
63
  static inline int blake2s_clear_lastblock( blake2s_state *S )
64
64
  {
65
65
  if( S->last_node ) blake2s_clear_lastnode( S );
@@ -67,7 +67,7 @@ static inline int blake2s_clear_lastblock( blake2s_state *S )
67
67
  S->f[0] = 0U;
68
68
  return 0;
69
69
  }
70
-
70
+ #endif
71
71
  static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t inc )
72
72
  {
73
73
  S->t[0] += inc;
@@ -76,6 +76,7 @@ static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t in
76
76
  }
77
77
 
78
78
  // Parameter-related functions
79
+ #if 0
79
80
  static inline int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length )
80
81
  {
81
82
  P->digest_length = digest_length;
@@ -117,7 +118,7 @@ static inline int blake2s_param_set_inner_length( blake2s_param *P, const uint8_
117
118
  P->inner_length = inner_length;
118
119
  return 0;
119
120
  }
120
-
121
+ #endif
121
122
  static inline int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] )
122
123
  {
123
124
  memcpy( P->salt, salt, BLAKE2S_SALTBYTES );