rbnacl-libsodium 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/AUTHORS +3 -0
- data/vendor/libsodium/ChangeLog +21 -0
- data/vendor/libsodium/Makefile.in +9 -0
- data/vendor/libsodium/THANKS +3 -0
- data/vendor/libsodium/aclocal.m4 +1 -0
- data/vendor/libsodium/autom4te.cache/output.1 +919 -85
- data/vendor/libsodium/autom4te.cache/output.5 +18351 -0
- data/vendor/libsodium/autom4te.cache/requests +960 -725
- data/vendor/libsodium/autom4te.cache/traces.1 +289 -247
- data/vendor/libsodium/autom4te.cache/traces.5 +3032 -0
- data/vendor/libsodium/build-aux/ltmain.sh +70 -11
- data/vendor/libsodium/builds/msvc/properties/ARM.props +20 -0
- data/vendor/libsodium/builds/msvc/properties/ReleaseDEXE.props +1 -1
- data/vendor/libsodium/builds/msvc/version.h +2 -2
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +3 -1
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +13 -1
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +244 -241
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +192 -189
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +2 -0
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +13 -1
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +244 -241
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +192 -189
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +3 -1
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +13 -1
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +244 -241
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +192 -189
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +3 -1
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +13 -1
- data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj +244 -241
- data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj.filters +192 -189
- data/vendor/libsodium/configure +918 -84
- data/vendor/libsodium/configure.ac +89 -15
- data/vendor/libsodium/dist-build/Makefile.am +6 -2
- data/vendor/libsodium/dist-build/Makefile.in +15 -2
- data/vendor/libsodium/dist-build/android-armv8-a.sh +4 -0
- data/vendor/libsodium/dist-build/android-build.sh +9 -9
- data/vendor/libsodium/dist-build/android-mips64.sh +4 -0
- data/vendor/libsodium/dist-build/android-x86-64.sh +4 -0
- data/vendor/libsodium/dist-build/emscripten.sh +3 -3
- data/vendor/libsodium/dist-build/ios.sh +5 -5
- data/vendor/libsodium/dist-build/nativeclient.sh +28 -0
- data/vendor/libsodium/examples/Makefile +21 -0
- data/vendor/libsodium/examples/auth.c +68 -0
- data/vendor/libsodium/examples/box.c +133 -0
- data/vendor/libsodium/examples/box_detached.c +132 -0
- data/vendor/libsodium/examples/generichash.c +80 -0
- data/vendor/libsodium/examples/generichash_stream.c +58 -0
- data/vendor/libsodium/examples/shorthash.c +58 -0
- data/vendor/libsodium/examples/sign.c +78 -0
- data/vendor/libsodium/examples/utils.h +106 -0
- data/vendor/libsodium/libsodium-uninstalled.pc.in +1 -1
- data/vendor/libsodium/libsodium.vcxproj +2 -0
- data/vendor/libsodium/libsodium.vcxproj.filters +6 -0
- data/vendor/libsodium/m4/ax_check_compile_flag.m4 +2 -2
- data/vendor/libsodium/m4/ax_check_define.m4 +92 -0
- data/vendor/libsodium/m4/ax_check_link_flag.m4 +3 -2
- data/vendor/libsodium/m4/libtool.m4 +111 -60
- data/vendor/libsodium/m4/ltoptions.m4 +1 -1
- data/vendor/libsodium/m4/ltsugar.m4 +1 -1
- data/vendor/libsodium/m4/ltversion.m4 +6 -6
- data/vendor/libsodium/m4/lt~obsolete.m4 +1 -1
- data/vendor/libsodium/msvc-scripts/Makefile.in +9 -0
- data/vendor/libsodium/msvc-scripts/process.bat +2 -2
- data/vendor/libsodium/src/Makefile.in +9 -0
- data/vendor/libsodium/src/libsodium/Makefile.am +27 -3
- data/vendor/libsodium/src/libsodium/Makefile.in +170 -63
- data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +852 -0
- data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +137 -17
- data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/cp/hmac_hmacsha256.c +1 -0
- data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/cp/hmac_hmacsha512.c +1 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +10 -6
- data/vendor/libsodium/src/libsodium/crypto_generichash/crypto_generichash.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +29 -23
- data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +9 -10
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +4 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +4 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +3 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +2 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_frombytes_curve25519_ref10.c +10 -10
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/api.h +10 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +51 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20_api.c +29 -0
- data/vendor/libsodium/src/libsodium/include/Makefile.am +6 -0
- data/vendor/libsodium/src/libsodium/include/Makefile.in +67 -40
- data/vendor/libsodium/src/libsodium/include/sodium.h +4 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +88 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +28 -2
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +0 -6
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +1 -1
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +23 -0
- data/vendor/libsodium/src/libsodium/include/sodium/export.h +8 -0
- data/vendor/libsodium/src/libsodium/include/sodium/randombytes_nativeclient.h +37 -0
- data/vendor/libsodium/src/libsodium/include/sodium/randombytes_salsa20_random.h +3 -2
- data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +6 -0
- data/vendor/libsodium/src/libsodium/include/sodium/utils.h +15 -1
- data/vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +49 -0
- data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +11 -1
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +71 -45
- data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +12 -2
- data/vendor/libsodium/src/libsodium/sodium/runtime.c +26 -3
- data/vendor/libsodium/src/libsodium/sodium/utils.c +86 -13
- data/vendor/libsodium/test/Makefile.in +9 -0
- data/vendor/libsodium/test/default/Makefile.am +130 -0
- data/vendor/libsodium/test/default/Makefile.in +197 -50
- data/vendor/libsodium/test/default/aead_aes256gcm.c +3197 -0
- data/vendor/libsodium/test/default/aead_aes256gcm.exp +1 -0
- data/vendor/libsodium/test/default/aead_chacha20poly1305.c +150 -17
- data/vendor/libsodium/test/default/aead_chacha20poly1305.exp +51 -0
- data/vendor/libsodium/test/default/chacha20.c +80 -5
- data/vendor/libsodium/test/default/chacha20.exp +11 -0
- data/vendor/libsodium/test/default/generichash.c +1332 -1
- data/vendor/libsodium/test/default/generichash.exp +1 -1
- data/vendor/libsodium/test/default/generichash2.c +3 -2
- data/vendor/libsodium/test/default/generichash3.c +2 -1
- data/vendor/libsodium/test/default/nacl-test-wrapper.sh +26 -0
- data/vendor/libsodium/test/default/randombytes.c +4 -0
- data/vendor/libsodium/test/default/scalarmult.c +33 -14
- data/vendor/libsodium/test/default/scalarmult.exp +4 -4
- data/vendor/libsodium/test/default/secretbox.c +9 -0
- data/vendor/libsodium/test/default/secretbox.exp +19 -0
- data/vendor/libsodium/test/default/secretbox_easy.c +40 -4
- data/vendor/libsodium/test/default/secretbox_easy.exp +58 -1
- data/vendor/libsodium/test/default/sodium_core.c +2 -0
- data/vendor/libsodium/test/default/sodium_utils.c +46 -7
- data/vendor/libsodium/test/default/sodium_utils.exp +5 -0
- data/vendor/libsodium/test/default/stream.c +1 -0
- metadata +28 -3
data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
#include "crypto_verify_16.h"
|
9
9
|
#include "utils.h"
|
10
10
|
|
11
|
+
static unsigned char _pad0[16];
|
12
|
+
|
11
13
|
static inline void
|
12
14
|
_u64_le_from_ull(unsigned char out[8U], unsigned long long x)
|
13
15
|
{
|
@@ -23,7 +25,7 @@ _u64_le_from_ull(unsigned char out[8U], unsigned long long x)
|
|
23
25
|
|
24
26
|
int
|
25
27
|
crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
|
26
|
-
unsigned long long *
|
28
|
+
unsigned long long *clen_p,
|
27
29
|
const unsigned char *m,
|
28
30
|
unsigned long long mlen,
|
29
31
|
const unsigned char *ad,
|
@@ -40,8 +42,8 @@ crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
|
|
40
42
|
/* LCOV_EXCL_START */
|
41
43
|
#ifdef ULONG_LONG_MAX
|
42
44
|
if (mlen > ULONG_LONG_MAX - crypto_aead_chacha20poly1305_ABYTES) {
|
43
|
-
if (
|
44
|
-
*
|
45
|
+
if (clen_p != NULL) {
|
46
|
+
*clen_p = 0ULL;
|
45
47
|
}
|
46
48
|
return -1;
|
47
49
|
}
|
@@ -65,15 +67,69 @@ crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
|
|
65
67
|
crypto_onetimeauth_poly1305_final(&state, c + mlen);
|
66
68
|
sodium_memzero(&state, sizeof state);
|
67
69
|
|
68
|
-
if (
|
69
|
-
*
|
70
|
+
if (clen_p != NULL) {
|
71
|
+
*clen_p = mlen + crypto_aead_chacha20poly1305_ABYTES;
|
72
|
+
}
|
73
|
+
return 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
int
|
77
|
+
crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,
|
78
|
+
unsigned long long *clen_p,
|
79
|
+
const unsigned char *m,
|
80
|
+
unsigned long long mlen,
|
81
|
+
const unsigned char *ad,
|
82
|
+
unsigned long long adlen,
|
83
|
+
const unsigned char *nsec,
|
84
|
+
const unsigned char *npub,
|
85
|
+
const unsigned char *k)
|
86
|
+
{
|
87
|
+
crypto_onetimeauth_poly1305_state state;
|
88
|
+
unsigned char block0[64U];
|
89
|
+
unsigned char slen[8U];
|
90
|
+
|
91
|
+
(void) nsec;
|
92
|
+
/* LCOV_EXCL_START */
|
93
|
+
#ifdef ULONG_LONG_MAX
|
94
|
+
if (mlen > ULONG_LONG_MAX - crypto_aead_chacha20poly1305_ABYTES) {
|
95
|
+
if (clen_p != NULL) {
|
96
|
+
*clen_p = 0ULL;
|
97
|
+
}
|
98
|
+
return -1;
|
99
|
+
}
|
100
|
+
#endif
|
101
|
+
/* LCOV_EXCL_STOP */
|
102
|
+
|
103
|
+
crypto_stream_chacha20_ietf(block0, sizeof block0, npub, k);
|
104
|
+
crypto_onetimeauth_poly1305_init(&state, block0);
|
105
|
+
sodium_memzero(block0, sizeof block0);
|
106
|
+
|
107
|
+
crypto_onetimeauth_poly1305_update(&state, ad, adlen);
|
108
|
+
crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - adlen) & 0xf);
|
109
|
+
|
110
|
+
crypto_stream_chacha20_ietf_xor_ic(c, m, mlen, npub, 1U, k);
|
111
|
+
|
112
|
+
crypto_onetimeauth_poly1305_update(&state, c, mlen);
|
113
|
+
crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - mlen) & 0xf);
|
114
|
+
|
115
|
+
_u64_le_from_ull(slen, adlen);
|
116
|
+
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
117
|
+
|
118
|
+
_u64_le_from_ull(slen, mlen);
|
119
|
+
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
120
|
+
|
121
|
+
crypto_onetimeauth_poly1305_final(&state, c + mlen);
|
122
|
+
sodium_memzero(&state, sizeof state);
|
123
|
+
|
124
|
+
if (clen_p != NULL) {
|
125
|
+
*clen_p = mlen + crypto_aead_chacha20poly1305_ABYTES;
|
70
126
|
}
|
71
127
|
return 0;
|
72
128
|
}
|
73
129
|
|
74
130
|
int
|
75
131
|
crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
|
76
|
-
unsigned long long *
|
132
|
+
unsigned long long *mlen_p,
|
77
133
|
unsigned char *nsec,
|
78
134
|
const unsigned char *c,
|
79
135
|
unsigned long long clen,
|
@@ -86,11 +142,12 @@ crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
|
|
86
142
|
unsigned char block0[64U];
|
87
143
|
unsigned char slen[8U];
|
88
144
|
unsigned char mac[crypto_aead_chacha20poly1305_ABYTES];
|
145
|
+
unsigned long long mlen;
|
89
146
|
int ret;
|
90
147
|
|
91
148
|
(void) nsec;
|
92
|
-
if (
|
93
|
-
*
|
149
|
+
if (mlen_p != NULL) {
|
150
|
+
*mlen_p = 0ULL;
|
94
151
|
}
|
95
152
|
if (clen < crypto_aead_chacha20poly1305_ABYTES) {
|
96
153
|
return -1;
|
@@ -103,26 +160,84 @@ crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
|
|
103
160
|
_u64_le_from_ull(slen, adlen);
|
104
161
|
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
105
162
|
|
106
|
-
|
107
|
-
|
108
|
-
_u64_le_from_ull(slen,
|
163
|
+
mlen = clen - crypto_aead_chacha20poly1305_ABYTES;
|
164
|
+
crypto_onetimeauth_poly1305_update(&state, c, mlen);
|
165
|
+
_u64_le_from_ull(slen, mlen);
|
109
166
|
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
110
167
|
|
111
168
|
crypto_onetimeauth_poly1305_final(&state, mac);
|
112
169
|
sodium_memzero(&state, sizeof state);
|
113
170
|
|
114
171
|
(void) sizeof(int[sizeof mac == 16U ? 1 : -1]);
|
115
|
-
ret = crypto_verify_16(mac,
|
116
|
-
c + clen - crypto_aead_chacha20poly1305_ABYTES);
|
172
|
+
ret = crypto_verify_16(mac, c + mlen);
|
117
173
|
sodium_memzero(mac, sizeof mac);
|
118
174
|
if (ret != 0) {
|
119
|
-
memset(m, 0,
|
175
|
+
memset(m, 0, mlen);
|
120
176
|
return -1;
|
121
177
|
}
|
122
178
|
crypto_stream_chacha20_xor_ic
|
123
|
-
(m, c,
|
124
|
-
if (
|
125
|
-
*
|
179
|
+
(m, c, mlen, npub, 1U, k);
|
180
|
+
if (mlen_p != NULL) {
|
181
|
+
*mlen_p = mlen;
|
182
|
+
}
|
183
|
+
return 0;
|
184
|
+
}
|
185
|
+
|
186
|
+
int
|
187
|
+
crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,
|
188
|
+
unsigned long long *mlen_p,
|
189
|
+
unsigned char *nsec,
|
190
|
+
const unsigned char *c,
|
191
|
+
unsigned long long clen,
|
192
|
+
const unsigned char *ad,
|
193
|
+
unsigned long long adlen,
|
194
|
+
const unsigned char *npub,
|
195
|
+
const unsigned char *k)
|
196
|
+
{
|
197
|
+
crypto_onetimeauth_poly1305_state state;
|
198
|
+
unsigned char block0[64U];
|
199
|
+
unsigned char slen[8U];
|
200
|
+
unsigned char mac[crypto_aead_chacha20poly1305_ABYTES];
|
201
|
+
unsigned long long mlen;
|
202
|
+
int ret;
|
203
|
+
|
204
|
+
(void) nsec;
|
205
|
+
if (mlen_p != NULL) {
|
206
|
+
*mlen_p = 0ULL;
|
207
|
+
}
|
208
|
+
if (clen < crypto_aead_chacha20poly1305_ABYTES) {
|
209
|
+
return -1;
|
210
|
+
}
|
211
|
+
crypto_stream_chacha20_ietf(block0, sizeof block0, npub, k);
|
212
|
+
crypto_onetimeauth_poly1305_init(&state, block0);
|
213
|
+
sodium_memzero(block0, sizeof block0);
|
214
|
+
|
215
|
+
crypto_onetimeauth_poly1305_update(&state, ad, adlen);
|
216
|
+
crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - adlen) & 0xf);
|
217
|
+
|
218
|
+
mlen = clen - crypto_aead_chacha20poly1305_ABYTES;
|
219
|
+
crypto_onetimeauth_poly1305_update(&state, c, mlen);
|
220
|
+
crypto_onetimeauth_poly1305_update(&state, _pad0, (0x10 - mlen) & 0xf);
|
221
|
+
|
222
|
+
_u64_le_from_ull(slen, adlen);
|
223
|
+
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
224
|
+
|
225
|
+
_u64_le_from_ull(slen, mlen);
|
226
|
+
crypto_onetimeauth_poly1305_update(&state, slen, sizeof slen);
|
227
|
+
|
228
|
+
crypto_onetimeauth_poly1305_final(&state, mac);
|
229
|
+
sodium_memzero(&state, sizeof state);
|
230
|
+
|
231
|
+
(void) sizeof(int[sizeof mac == 16U ? 1 : -1]);
|
232
|
+
ret = crypto_verify_16(mac, c + mlen);
|
233
|
+
sodium_memzero(mac, sizeof mac);
|
234
|
+
if (ret != 0) {
|
235
|
+
memset(m, 0, mlen);
|
236
|
+
return -1;
|
237
|
+
}
|
238
|
+
crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, npub, 1U, k);
|
239
|
+
if (mlen_p != NULL) {
|
240
|
+
*mlen_p = mlen;
|
126
241
|
}
|
127
242
|
return 0;
|
128
243
|
}
|
@@ -137,6 +252,11 @@ crypto_aead_chacha20poly1305_npubbytes(void) {
|
|
137
252
|
return crypto_aead_chacha20poly1305_NPUBBYTES;
|
138
253
|
}
|
139
254
|
|
255
|
+
size_t
|
256
|
+
crypto_aead_chacha20poly1305_ietf_npubbytes(void) {
|
257
|
+
return crypto_aead_chacha20poly1305_IETF_NPUBBYTES;
|
258
|
+
}
|
259
|
+
|
140
260
|
size_t
|
141
261
|
crypto_aead_chacha20poly1305_nsecbytes(void) {
|
142
262
|
return crypto_aead_chacha20poly1305_NSECBYTES;
|
@@ -46,14 +46,14 @@ static const uint8_t blake2b_sigma[12][16] =
|
|
46
46
|
/* LCOV_EXCL_START */
|
47
47
|
static inline int blake2b_set_lastnode( blake2b_state *S )
|
48
48
|
{
|
49
|
-
S->f[1] =
|
49
|
+
S->f[1] = -1;
|
50
50
|
return 0;
|
51
51
|
}
|
52
52
|
/* LCOV_EXCL_STOP */
|
53
53
|
#if 0
|
54
54
|
static inline int blake2b_clear_lastnode( blake2b_state *S )
|
55
55
|
{
|
56
|
-
S->f[1] =
|
56
|
+
S->f[1] = 0;
|
57
57
|
return 0;
|
58
58
|
}
|
59
59
|
#endif
|
@@ -62,7 +62,7 @@ static inline int blake2b_set_lastblock( blake2b_state *S )
|
|
62
62
|
{
|
63
63
|
if( S->last_node ) blake2b_set_lastnode( S );
|
64
64
|
|
65
|
-
S->f[0] =
|
65
|
+
S->f[0] = -1;
|
66
66
|
return 0;
|
67
67
|
}
|
68
68
|
#if 0
|
@@ -70,7 +70,7 @@ static inline int blake2b_clear_lastblock( blake2b_state *S )
|
|
70
70
|
{
|
71
71
|
if( S->last_node ) blake2b_clear_lastnode( S );
|
72
72
|
|
73
|
-
S->f[0] =
|
73
|
+
S->f[0] = 0;
|
74
74
|
return 0;
|
75
75
|
}
|
76
76
|
#endif
|
@@ -418,11 +418,15 @@ int blake2b( uint8_t *out, const void *in, const void *key, const uint8_t outlen
|
|
418
418
|
blake2b_state S[1];
|
419
419
|
|
420
420
|
/* Verify parameters */
|
421
|
-
if ( NULL == in ) return -1;
|
421
|
+
if ( NULL == in && inlen > 0 ) return -1;
|
422
422
|
|
423
423
|
if ( NULL == out ) return -1;
|
424
424
|
|
425
|
-
if( NULL == key
|
425
|
+
if( NULL == key && keylen > 0 ) return -1;
|
426
|
+
|
427
|
+
if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
|
428
|
+
|
429
|
+
if( keylen > BLAKE2B_KEYBYTES ) return -1;
|
426
430
|
|
427
431
|
if( keylen > 0 )
|
428
432
|
{
|
@@ -40,6 +40,7 @@
|
|
40
40
|
/* Avoid namespace collisions with BSD <sys/endian.h>. */
|
41
41
|
#define be32dec _sha256_be32dec
|
42
42
|
#define be32enc _sha256_be32enc
|
43
|
+
#define be64enc _sha256_be64enc
|
43
44
|
|
44
45
|
static inline uint32_t
|
45
46
|
be32dec(const void *pp)
|
@@ -53,7 +54,7 @@ be32dec(const void *pp)
|
|
53
54
|
static inline void
|
54
55
|
be32enc(void *pp, uint32_t x)
|
55
56
|
{
|
56
|
-
uint8_t *
|
57
|
+
uint8_t *p = (uint8_t *)pp;
|
57
58
|
|
58
59
|
p[3] = x & 0xff;
|
59
60
|
p[2] = (x >> 8) & 0xff;
|
@@ -61,6 +62,21 @@ be32enc(void *pp, uint32_t x)
|
|
61
62
|
p[0] = (x >> 24) & 0xff;
|
62
63
|
}
|
63
64
|
|
65
|
+
static inline void
|
66
|
+
be64enc(void * pp, uint64_t x)
|
67
|
+
{
|
68
|
+
uint8_t * p = (uint8_t *)pp;
|
69
|
+
|
70
|
+
p[7] = x & 0xff;
|
71
|
+
p[6] = (x >> 8) & 0xff;
|
72
|
+
p[5] = (x >> 16) & 0xff;
|
73
|
+
p[4] = (x >> 24) & 0xff;
|
74
|
+
p[3] = (x >> 32) & 0xff;
|
75
|
+
p[2] = (x >> 40) & 0xff;
|
76
|
+
p[1] = (x >> 48) & 0xff;
|
77
|
+
p[0] = (x >> 56) & 0xff;
|
78
|
+
}
|
79
|
+
|
64
80
|
static void
|
65
81
|
be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len)
|
66
82
|
{
|
@@ -206,9 +222,9 @@ SHA256_Pad(crypto_hash_sha256_state *state)
|
|
206
222
|
unsigned char len[8];
|
207
223
|
uint32_t r, plen;
|
208
224
|
|
209
|
-
|
225
|
+
be64enc(len, state->count);
|
210
226
|
|
211
|
-
r = (state->count
|
227
|
+
r = (state->count >> 3) & 0x3f;
|
212
228
|
plen = (r < 56) ? (56 - r) : (120 - r);
|
213
229
|
crypto_hash_sha256_update(state, PAD, (unsigned long long) plen);
|
214
230
|
|
@@ -218,16 +234,13 @@ SHA256_Pad(crypto_hash_sha256_state *state)
|
|
218
234
|
int
|
219
235
|
crypto_hash_sha256_init(crypto_hash_sha256_state *state)
|
220
236
|
{
|
221
|
-
|
237
|
+
static const uint32_t sha256_initstate[8] = {
|
238
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
239
|
+
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
240
|
+
};
|
222
241
|
|
223
|
-
state->
|
224
|
-
state->state
|
225
|
-
state->state[2] = 0x3C6EF372;
|
226
|
-
state->state[3] = 0xA54FF53A;
|
227
|
-
state->state[4] = 0x510E527F;
|
228
|
-
state->state[5] = 0x9B05688C;
|
229
|
-
state->state[6] = 0x1F83D9AB;
|
230
|
-
state->state[7] = 0x5BE0CD19;
|
242
|
+
state->count = (uint64_t) 0U;
|
243
|
+
memcpy(state->state, sha256_initstate, sizeof sha256_initstate);
|
231
244
|
|
232
245
|
return 0;
|
233
246
|
}
|
@@ -237,20 +250,13 @@ crypto_hash_sha256_update(crypto_hash_sha256_state *state,
|
|
237
250
|
const unsigned char *in,
|
238
251
|
unsigned long long inlen)
|
239
252
|
{
|
240
|
-
uint32_t bitlen[2];
|
241
253
|
uint32_t r;
|
242
254
|
|
243
|
-
|
244
|
-
|
245
|
-
bitlen[1] = ((uint32_t)inlen) << 3;
|
246
|
-
bitlen[0] = (uint32_t)(inlen >> 29);
|
247
|
-
|
248
|
-
/* LCOV_EXCL_START */
|
249
|
-
if ((state->count[1] += bitlen[1]) < bitlen[1]) {
|
250
|
-
state->count[0]++;
|
255
|
+
if (inlen <= 0U) {
|
256
|
+
return 0;
|
251
257
|
}
|
252
|
-
|
253
|
-
state->count
|
258
|
+
r = (state->count >> 3) & 0x3f;
|
259
|
+
state->count += (uint64_t)(inlen) << 3;
|
254
260
|
|
255
261
|
if (inlen < 64 - r) {
|
256
262
|
memcpy(&state->buf[r], in, inlen);
|
@@ -244,16 +244,15 @@ SHA512_Pad(crypto_hash_sha512_state *state)
|
|
244
244
|
int
|
245
245
|
crypto_hash_sha512_init(crypto_hash_sha512_state *state)
|
246
246
|
{
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
state->state[
|
255
|
-
state->state
|
256
|
-
state->state[7] = 0x5be0cd19137e2179ULL;
|
247
|
+
static const uint64_t sha512_initstate[8] = {
|
248
|
+
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
249
|
+
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
250
|
+
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
251
|
+
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
252
|
+
};
|
253
|
+
|
254
|
+
state->count[0] = state->count[1] = (uint64_t) 0U;
|
255
|
+
memcpy(state->state, sha512_initstate, sizeof sha512_initstate);
|
257
256
|
|
258
257
|
return 0;
|
259
258
|
}
|
data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c
CHANGED
@@ -153,7 +153,8 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen,
|
|
153
153
|
if (need > buflen || need < saltlen) {
|
154
154
|
return NULL;
|
155
155
|
}
|
156
|
-
#if defined(HAVE_EMMINTRIN_H) ||
|
156
|
+
#if defined(HAVE_EMMINTRIN_H) || \
|
157
|
+
(defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
|
157
158
|
escrypt_kdf =
|
158
159
|
sodium_runtime_has_sse2() ? escrypt_kdf_sse : escrypt_kdf_nosse;
|
159
160
|
#else
|
@@ -234,7 +235,8 @@ crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen,
|
|
234
235
|
if (escrypt_init_local(&local)) {
|
235
236
|
return -1; /* LCOV_EXCL_LINE */
|
236
237
|
}
|
237
|
-
#if defined(HAVE_EMMINTRIN_H) ||
|
238
|
+
#if defined(HAVE_EMMINTRIN_H) || \
|
239
|
+
(defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
|
238
240
|
escrypt_kdf =
|
239
241
|
sodium_runtime_has_sse2() ? escrypt_kdf_sse : escrypt_kdf_nosse;
|
240
242
|
#else
|