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.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/AUTHORS +62 -81
- data/vendor/libsodium/ChangeLog +31 -1
- data/vendor/libsodium/README.markdown +15 -364
- data/vendor/libsodium/THANKS +6 -0
- data/vendor/libsodium/autom4te.cache/output.0 +67 -36
- data/vendor/libsodium/autom4te.cache/output.1 +67 -36
- data/vendor/libsodium/autom4te.cache/output.2 +67 -36
- data/vendor/libsodium/autom4te.cache/traces.0 +52 -51
- data/vendor/libsodium/autom4te.cache/traces.1 +137 -133
- data/vendor/libsodium/autom4te.cache/traces.2 +52 -51
- data/vendor/libsodium/builds/msvc/version.h +2 -2
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +365 -345
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +1114 -1037
- data/vendor/libsodium/builds/msvc/vs2010/test/test.props +8 -2
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +364 -344
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +1113 -1036
- data/vendor/libsodium/builds/msvc/vs2012/test/test.props +8 -2
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +365 -345
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +1114 -1037
- data/vendor/libsodium/builds/msvc/vs2013/test/test.props +8 -2
- data/vendor/libsodium/configure +66 -35
- data/vendor/libsodium/configure.ac +25 -14
- data/vendor/libsodium/dist-build/ios.sh +1 -1
- data/vendor/libsodium/dist-build/msys2-win64.sh +1 -1
- data/vendor/libsodium/libsodium.vcxproj +29 -14
- data/vendor/libsodium/libsodium.vcxproj.filters +77 -28
- data/vendor/libsodium/msvc-scripts/process.bat +3 -3
- data/vendor/libsodium/packaging/nuget/package.config +1 -1
- data/vendor/libsodium/packaging/nuget/package.gsl +6 -1
- data/vendor/libsodium/packaging/nuget/package.nuspec +1 -1
- data/vendor/libsodium/src/libsodium/Makefile.am +31 -13
- data/vendor/libsodium/src/libsodium/Makefile.in +406 -155
- data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +146 -0
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box.c +13 -0
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +39 -73
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305_api.c +5 -0
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/api.h +2 -0
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/keypair_curve25519xsalsa20poly1305.c +15 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +6 -5
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +6 -5
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/crypto_onetimeauth.c +25 -0
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +76 -47
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +30 -7
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +3 -16
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +3 -10
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/verify_poly1305_donna.c +11 -6
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +23 -1
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/crypto_scrypt-common.c +7 -7
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/crypto_scrypt.h +6 -20
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256_nosse.c → scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c} +0 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/pbkdf2-sha256.c +1 -11
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/pbkdf2-sha256.h +0 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c → scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c} +50 -25
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/scrypt_platform.c +4 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c → scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c} +0 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/{scryptxsalsa208sha256 → scryptsalsa208sha256}/sysendian.h +0 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/smult_curve25519_donna_c64.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/{ref → ref10}/api.h +0 -3
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/base_curve25519_ref10.c +14 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe.h +44 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_0_curve25519_ref10.c +23 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_1_curve25519_ref10.c +23 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_add_curve25519_ref10.c +61 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_copy_curve25519_ref10.c +33 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_cswap_curve25519_ref10.c +77 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_frombytes_curve25519_ref10.c +73 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_invert_curve25519_ref10.c +18 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_mul121666_curve25519_ref10.c +74 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_mul_curve25519_ref10.c +257 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_sq_curve25519_ref10.c +153 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_sub_curve25519_ref10.c +61 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_tobytes_curve25519_ref10.c +123 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/montgomery.h +140 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/pow225521.h +160 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c +54 -0
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +92 -61
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_scalarmult_base.c +3 -3
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/pow22523.h +2 -2
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/pow225521.h +2 -2
- data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/sc25519_edwards25519sha512batch.c +8 -4
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/consts_aes128ctr.c +3 -3
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128.h +6 -3
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128_aes128ctr.c +23 -23
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/api.h +12 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +275 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20_api.c +36 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S +11 -10
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +8 -3
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c +8 -0
- data/vendor/libsodium/src/libsodium/include/Makefile.am +3 -2
- data/vendor/libsodium/src/libsodium/include/Makefile.in +3 -2
- data/vendor/libsodium/src/libsodium/include/sodium.h +3 -1
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +55 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +21 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +11 -1
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash.h +7 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +7 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha512.h +7 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth.h +15 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +25 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +80 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +2 -2
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +14 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +11 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes256estream.h +11 -6
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +49 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +6 -0
- data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +7 -7
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +10 -14
- data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +10 -13
- data/vendor/libsodium/src/libsodium/sodium/compat.c +55 -4
- data/vendor/libsodium/src/libsodium/sodium/utils.c +18 -0
- data/vendor/libsodium/test/default/Makefile.am +24 -12
- data/vendor/libsodium/test/default/Makefile.in +116 -73
- data/vendor/libsodium/test/default/aead_chacha20poly1305.c +97 -0
- data/vendor/libsodium/test/default/aead_chacha20poly1305.exp +8 -0
- data/vendor/libsodium/test/default/box_easy.c +1 -1
- data/vendor/libsodium/test/default/box_seed.c +28 -0
- data/vendor/libsodium/test/default/box_seed.exp +8 -0
- data/vendor/libsodium/test/default/chacha20.c +45 -0
- data/vendor/libsodium/test/default/chacha20.exp +5 -0
- data/vendor/libsodium/test/default/pwhash.c +83 -15
- data/vendor/libsodium/test/default/pwhash.exp +10 -1
- data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +67 -0
- data/vendor/libsodium/test/default/pwhash_scrypt_ll.exp +15 -0
- data/vendor/libsodium/test/default/secretbox_easy.c +13 -1
- data/vendor/libsodium/test/default/secretbox_easy.exp +19 -0
- data/vendor/libsodium/test/default/secretbox_easy2.c +5 -0
- data/vendor/libsodium/test/default/secretbox_easy2.exp +1 -0
- data/vendor/libsodium/test/default/sign.c +7 -3
- metadata +44 -21
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/api.h +0 -8
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref/base_curve25519_ref.c +0 -20
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref/smult_curve25519_ref.c +0 -268
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_donna.h +0 -37
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h +0 -48
- data/vendor/libsodium/test/default/scalarmult7.c +0 -32
- data/vendor/libsodium/test/default/scalarmult7.exp +0 -1
- data/vendor/libsodium/test/default/scalarmult8.c +0 -32
- data/vendor/libsodium/test/default/scalarmult8.exp +0 -1
data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/scalarmult_curve25519_ref10.c
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
#include "api.h"
|
3
|
+
#include "crypto_scalarmult.h"
|
4
|
+
#include "fe.h"
|
5
|
+
|
6
|
+
#ifndef HAVE_TI_MODE
|
7
|
+
|
8
|
+
int crypto_scalarmult(unsigned char *q,
|
9
|
+
const unsigned char *n,
|
10
|
+
const unsigned char *p)
|
11
|
+
{
|
12
|
+
unsigned char e[32];
|
13
|
+
unsigned int i;
|
14
|
+
fe x1;
|
15
|
+
fe x2;
|
16
|
+
fe z2;
|
17
|
+
fe x3;
|
18
|
+
fe z3;
|
19
|
+
fe tmp0;
|
20
|
+
fe tmp1;
|
21
|
+
int pos;
|
22
|
+
unsigned int swap;
|
23
|
+
unsigned int b;
|
24
|
+
|
25
|
+
for (i = 0;i < 32;++i) e[i] = n[i];
|
26
|
+
e[0] &= 248;
|
27
|
+
e[31] &= 127;
|
28
|
+
e[31] |= 64;
|
29
|
+
fe_frombytes(x1,p);
|
30
|
+
fe_1(x2);
|
31
|
+
fe_0(z2);
|
32
|
+
fe_copy(x3,x1);
|
33
|
+
fe_1(z3);
|
34
|
+
|
35
|
+
swap = 0;
|
36
|
+
for (pos = 254;pos >= 0;--pos) {
|
37
|
+
b = e[pos / 8] >> (pos & 7);
|
38
|
+
b &= 1;
|
39
|
+
swap ^= b;
|
40
|
+
fe_cswap(x2,x3,swap);
|
41
|
+
fe_cswap(z2,z3,swap);
|
42
|
+
swap = b;
|
43
|
+
#include "montgomery.h"
|
44
|
+
}
|
45
|
+
fe_cswap(x2,x3,swap);
|
46
|
+
fe_cswap(z2,z3,swap);
|
47
|
+
|
48
|
+
fe_invert(z2,z2);
|
49
|
+
fe_mul(x2,x2,z2);
|
50
|
+
fe_tobytes(q,x2);
|
51
|
+
return 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
#endif
|
@@ -5,90 +5,121 @@
|
|
5
5
|
#include <stdlib.h>
|
6
6
|
#include <string.h>
|
7
7
|
|
8
|
+
#include "crypto_core_hsalsa20.h"
|
9
|
+
#include "crypto_onetimeauth_poly1305.h"
|
8
10
|
#include "crypto_secretbox.h"
|
11
|
+
#include "crypto_stream_salsa20.h"
|
9
12
|
#include "utils.h"
|
10
13
|
|
14
|
+
static const unsigned char sigma[16] = {
|
15
|
+
'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'
|
16
|
+
};
|
17
|
+
|
11
18
|
int
|
12
|
-
|
13
|
-
|
14
|
-
|
19
|
+
crypto_secretbox_detached(unsigned char *c, unsigned char *mac,
|
20
|
+
const unsigned char *m,
|
21
|
+
unsigned long long mlen, const unsigned char *n,
|
22
|
+
const unsigned char *k)
|
15
23
|
{
|
16
|
-
|
17
|
-
unsigned char
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
crypto_onetimeauth_poly1305_state state;
|
25
|
+
unsigned char block0[64U];
|
26
|
+
unsigned char subkey[crypto_stream_salsa20_KEYBYTES];
|
27
|
+
unsigned long long i;
|
28
|
+
unsigned long long mlen0;
|
21
29
|
|
22
|
-
if (mlen > SIZE_MAX -
|
30
|
+
if (mlen > SIZE_MAX - crypto_secretbox_MACBYTES) {
|
23
31
|
return -1;
|
24
32
|
}
|
25
|
-
(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
crypto_core_hsalsa20(subkey, n, k, sigma);
|
34
|
+
|
35
|
+
memset(block0, 0U, crypto_secretbox_ZEROBYTES);
|
36
|
+
(void) sizeof(int[64U >= crypto_secretbox_ZEROBYTES ? 1 : -1]);
|
37
|
+
mlen0 = mlen;
|
38
|
+
if (mlen0 > 64U - crypto_secretbox_ZEROBYTES) {
|
39
|
+
mlen0 = 64U - crypto_secretbox_ZEROBYTES;
|
30
40
|
}
|
31
|
-
|
32
|
-
|
33
|
-
free(m_boxed);
|
34
|
-
return -1;
|
41
|
+
for (i = 0U; i < mlen0; i++) {
|
42
|
+
block0[i + crypto_secretbox_ZEROBYTES] = m[i];
|
35
43
|
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
crypto_stream_salsa20_xor(block0, block0,
|
45
|
+
mlen0 + crypto_secretbox_ZEROBYTES,
|
46
|
+
n + 16, subkey);
|
47
|
+
(void) sizeof(int[crypto_secretbox_ZEROBYTES >=
|
48
|
+
crypto_onetimeauth_poly1305_KEYBYTES ? 1 : -1]);
|
49
|
+
crypto_onetimeauth_poly1305_init(&state, block0);
|
50
|
+
|
51
|
+
memcpy(c, block0 + crypto_secretbox_ZEROBYTES, mlen0);
|
52
|
+
sodium_memzero(block0, sizeof block0);
|
53
|
+
if (mlen > mlen0) {
|
54
|
+
crypto_stream_salsa20_xor_ic(c + mlen0, m + mlen0, mlen - mlen0,
|
55
|
+
n + 16, 1U, subkey);
|
44
56
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
sodium_memzero(subkey, sizeof subkey);
|
58
|
+
|
59
|
+
crypto_onetimeauth_poly1305_update(&state, c, mlen);
|
60
|
+
crypto_onetimeauth_poly1305_final(&state, mac);
|
61
|
+
sodium_memzero(&state, sizeof state);
|
50
62
|
|
51
63
|
return 0;
|
52
64
|
}
|
53
65
|
|
54
66
|
int
|
55
|
-
|
56
|
-
|
57
|
-
|
67
|
+
crypto_secretbox_easy(unsigned char *c, const unsigned char *m,
|
68
|
+
unsigned long long mlen, const unsigned char *n,
|
69
|
+
const unsigned char *k)
|
58
70
|
{
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
71
|
+
return crypto_secretbox_detached(c + crypto_secretbox_MACBYTES,
|
72
|
+
c, m, mlen, n, k);
|
73
|
+
}
|
74
|
+
|
75
|
+
int
|
76
|
+
crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c,
|
77
|
+
const unsigned char *mac,
|
78
|
+
unsigned long long clen,
|
79
|
+
const unsigned char *n,
|
80
|
+
const unsigned char *k)
|
81
|
+
{
|
82
|
+
unsigned char block0[64U];
|
83
|
+
unsigned char subkey[crypto_stream_salsa20_KEYBYTES];
|
84
|
+
unsigned long long i;
|
85
|
+
unsigned long long mlen0;
|
64
86
|
|
65
|
-
(
|
66
|
-
|
67
|
-
|
68
|
-
|
87
|
+
crypto_core_hsalsa20(subkey, n, k, sigma);
|
88
|
+
crypto_stream_salsa20(block0, crypto_stream_salsa20_KEYBYTES,
|
89
|
+
n + 16, subkey);
|
90
|
+
if (crypto_onetimeauth_poly1305_verify(mac, c, clen, block0) != 0) {
|
91
|
+
sodium_memzero(subkey, sizeof subkey);
|
69
92
|
return -1;
|
70
93
|
}
|
71
|
-
|
72
|
-
if (
|
73
|
-
|
94
|
+
mlen0 = clen;
|
95
|
+
if (mlen0 > 64U - crypto_secretbox_ZEROBYTES) {
|
96
|
+
mlen0 = 64U - crypto_secretbox_ZEROBYTES;
|
74
97
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
98
|
+
memcpy(block0 + crypto_secretbox_ZEROBYTES, c, mlen0);
|
99
|
+
crypto_stream_salsa20_xor(block0, block0,
|
100
|
+
crypto_secretbox_ZEROBYTES + mlen0,
|
101
|
+
n + 16, subkey);
|
102
|
+
for (i = 0U; i < mlen0; i++) {
|
103
|
+
m[i] = block0[i + crypto_secretbox_ZEROBYTES];
|
81
104
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
if (rc != 0) {
|
86
|
-
free(m_boxed);
|
87
|
-
return -1;
|
105
|
+
if (clen > mlen0) {
|
106
|
+
crypto_stream_salsa20_xor_ic(m + mlen0, c + mlen0, clen - mlen0,
|
107
|
+
n + 16, 1U, subkey);
|
88
108
|
}
|
89
|
-
|
90
|
-
clen - crypto_secretbox_MACBYTES);
|
91
|
-
free(m_boxed);
|
109
|
+
sodium_memzero(subkey, sizeof subkey);
|
92
110
|
|
93
111
|
return 0;
|
94
112
|
}
|
113
|
+
|
114
|
+
int
|
115
|
+
crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c,
|
116
|
+
unsigned long long clen, const unsigned char *n,
|
117
|
+
const unsigned char *k)
|
118
|
+
{
|
119
|
+
if (clen < crypto_secretbox_MACBYTES) {
|
120
|
+
return -1;
|
121
|
+
}
|
122
|
+
return crypto_secretbox_open_detached(m, c + crypto_secretbox_MACBYTES, c,
|
123
|
+
clen - crypto_secretbox_MACBYTES,
|
124
|
+
n, k);
|
125
|
+
}
|
@@ -37,7 +37,7 @@ static ge_precomp base[32][8] = {
|
|
37
37
|
#include "base.h"
|
38
38
|
} ;
|
39
39
|
|
40
|
-
static void
|
40
|
+
static void ge_select(ge_precomp *t,int pos,signed char b)
|
41
41
|
{
|
42
42
|
ge_precomp minust;
|
43
43
|
unsigned char bnegative = negative(b);
|
@@ -95,7 +95,7 @@ void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
|
|
95
95
|
|
96
96
|
ge_p3_0(h);
|
97
97
|
for (i = 1;i < 64;i += 2) {
|
98
|
-
|
98
|
+
ge_select(&t,i / 2,e[i]);
|
99
99
|
ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
|
100
100
|
}
|
101
101
|
|
@@ -105,7 +105,7 @@ void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
|
|
105
105
|
ge_p2_dbl(&r,&s); ge_p1p1_to_p3(h,&r);
|
106
106
|
|
107
107
|
for (i = 0;i < 64;i += 2) {
|
108
|
-
|
108
|
+
ge_select(&t,i / 2,e[i]);
|
109
109
|
ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
|
110
110
|
}
|
111
111
|
}
|
@@ -50,7 +50,7 @@
|
|
50
50
|
/* qhasm: z2 = z1^2^1 */
|
51
51
|
/* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
|
52
52
|
/* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
|
53
|
-
fe_sq(t0,z); for (i = 1;i < 1;++i) fe_sq(t0,t0);
|
53
|
+
fe_sq(t0,z); /* for (i = 1;i < 1;++i) fe_sq(t0,t0); */
|
54
54
|
|
55
55
|
/* qhasm: z8 = z2^2^2 */
|
56
56
|
/* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
|
@@ -70,7 +70,7 @@ fe_mul(t0,t0,t1);
|
|
70
70
|
/* qhasm: z22 = z11^2^1 */
|
71
71
|
/* asm 1: fe_sq(>z22=fe#1,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#1,>z22=fe#1); */
|
72
72
|
/* asm 2: fe_sq(>z22=t0,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t0,>z22=t0); */
|
73
|
-
fe_sq(t0,t0); for (i = 1;i < 1;++i) fe_sq(t0,t0);
|
73
|
+
fe_sq(t0,t0); /* for (i = 1;i < 1;++i) fe_sq(t0,t0); */
|
74
74
|
|
75
75
|
/* qhasm: z_5_0 = z9*z22 */
|
76
76
|
/* asm 1: fe_mul(>z_5_0=fe#1,<z9=fe#2,<z22=fe#1); */
|
@@ -50,7 +50,7 @@
|
|
50
50
|
/* qhasm: z2 = z1^2^1 */
|
51
51
|
/* asm 1: fe_sq(>z2=fe#1,<z1=fe#11); for (i = 1;i < 1;++i) fe_sq(>z2=fe#1,>z2=fe#1); */
|
52
52
|
/* asm 2: fe_sq(>z2=t0,<z1=z); for (i = 1;i < 1;++i) fe_sq(>z2=t0,>z2=t0); */
|
53
|
-
fe_sq(t0,z); for (i = 1;i < 1;++i) fe_sq(t0,t0);
|
53
|
+
fe_sq(t0,z); /* for (i = 1;i < 1;++i) fe_sq(t0,t0); */
|
54
54
|
|
55
55
|
/* qhasm: z8 = z2^2^2 */
|
56
56
|
/* asm 1: fe_sq(>z8=fe#2,<z2=fe#1); for (i = 1;i < 2;++i) fe_sq(>z8=fe#2,>z8=fe#2); */
|
@@ -70,7 +70,7 @@ fe_mul(t0,t0,t1);
|
|
70
70
|
/* qhasm: z22 = z11^2^1 */
|
71
71
|
/* asm 1: fe_sq(>z22=fe#3,<z11=fe#1); for (i = 1;i < 1;++i) fe_sq(>z22=fe#3,>z22=fe#3); */
|
72
72
|
/* asm 2: fe_sq(>z22=t2,<z11=t0); for (i = 1;i < 1;++i) fe_sq(>z22=t2,>z22=t2); */
|
73
|
-
fe_sq(t2,t0); for (i = 1;i < 1;++i) fe_sq(t2,t2);
|
73
|
+
fe_sq(t2,t0); /* for (i = 1;i < 1;++i) fe_sq(t2,t2); */
|
74
74
|
|
75
75
|
/* qhasm: z_5_0 = z9*z22 */
|
76
76
|
/* asm 1: fe_mul(>z_5_0=fe#2,<z9=fe#2,<z22=fe#3); */
|
@@ -46,10 +46,14 @@ static void barrett_reduce(sc25519 *r, const crypto_uint32 x[64])
|
|
46
46
|
q2[33] += carry;
|
47
47
|
|
48
48
|
for(i=0;i<33;i++)r1[i] = x[i];
|
49
|
-
for(i=0;i<32;i++)
|
50
|
-
for(j=0;j<33;j++)
|
51
|
-
if(i+j < 33)
|
52
|
-
|
49
|
+
for(i=0;i<32;i++) {
|
50
|
+
for(j=0;j<33;j++) {
|
51
|
+
if(i+j < 33) {
|
52
|
+
/* coverity[overrun-local] */
|
53
|
+
r2[i+j] += m[i]*q3[j];
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
53
57
|
for(i=0;i<32;i++)
|
54
58
|
{
|
55
59
|
carry = r2[i] >> 8;
|
@@ -9,6 +9,6 @@ const unsigned char M0SWAP[16] = {0x0c, 0x08, 0x04, 0x00, 0x0d, 0x09, 0x05, 0x01
|
|
9
9
|
const unsigned char SR[16] = {0x01, 0x02, 0x03, 0x00, 0x06, 0x07, 0x04, 0x05, 0x0b, 0x08, 0x09, 0x0a, 0x0c, 0x0d, 0x0e, 0x0f};
|
10
10
|
const unsigned char SRM0[16] = {0x0f, 0x0a, 0x05, 0x00, 0x0e, 0x09, 0x04, 0x03, 0x0d, 0x08, 0x07, 0x02, 0x0c, 0x0b, 0x06, 0x01};
|
11
11
|
|
12
|
-
const int128 BS0 = {0x5555555555555555ULL, 0x5555555555555555ULL};
|
13
|
-
const int128 BS1 = {0x3333333333333333ULL, 0x3333333333333333ULL};
|
14
|
-
const int128 BS2 = {0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL};
|
12
|
+
const int128 BS0 = {{0x5555555555555555ULL, 0x5555555555555555ULL}};
|
13
|
+
const int128 BS1 = {{0x3333333333333333ULL, 0x3333333333333333ULL}};
|
14
|
+
const int128 BS2 = {{0x0f0f0f0f0f0f0f0fULL, 0x0f0f0f0f0f0f0f0fULL}};
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#ifndef INT128_H
|
2
2
|
#define INT128_H
|
3
3
|
|
4
|
+
#include <stdint.h>
|
5
|
+
|
4
6
|
#include "common.h"
|
5
7
|
|
6
8
|
#ifdef __cplusplus
|
@@ -9,9 +11,10 @@
|
|
9
11
|
# endif
|
10
12
|
#endif
|
11
13
|
|
12
|
-
typedef
|
13
|
-
|
14
|
-
|
14
|
+
typedef union {
|
15
|
+
uint64_t u64[2];
|
16
|
+
uint32_t u32[4];
|
17
|
+
uint8_t u8[16];
|
15
18
|
} int128;
|
16
19
|
|
17
20
|
#define xor2 crypto_stream_aes128ctr_portable_xor2
|
@@ -1,39 +1,40 @@
|
|
1
|
+
|
1
2
|
#include "int128.h"
|
2
3
|
#include "common.h"
|
3
4
|
|
4
5
|
void xor2(int128 *r, const int128 *x)
|
5
6
|
{
|
6
|
-
r->
|
7
|
-
r->
|
7
|
+
r->u64[0] ^= x->u64[0];
|
8
|
+
r->u64[1] ^= x->u64[1];
|
8
9
|
}
|
9
10
|
|
10
11
|
void and2(int128 *r, const int128 *x)
|
11
12
|
{
|
12
|
-
r->
|
13
|
-
r->
|
13
|
+
r->u64[0] &= x->u64[0];
|
14
|
+
r->u64[1] &= x->u64[1];
|
14
15
|
}
|
15
16
|
|
16
17
|
void or2(int128 *r, const int128 *x)
|
17
18
|
{
|
18
|
-
r->
|
19
|
-
r->
|
19
|
+
r->u64[0] |= x->u64[0];
|
20
|
+
r->u64[1] |= x->u64[1];
|
20
21
|
}
|
21
22
|
|
22
23
|
void copy2(int128 *r, const int128 *x)
|
23
24
|
{
|
24
|
-
r->
|
25
|
-
r->
|
25
|
+
r->u64[0] = x->u64[0];
|
26
|
+
r->u64[1] = x->u64[1];
|
26
27
|
}
|
27
28
|
|
28
29
|
void shufb(int128 *r, const unsigned char *l)
|
29
30
|
{
|
30
|
-
int128
|
31
|
-
|
32
|
-
|
31
|
+
int128 t;
|
32
|
+
uint8_t *ct;
|
33
|
+
uint8_t *cr;
|
33
34
|
|
34
|
-
copy2(&t,r);
|
35
|
-
cr =
|
36
|
-
ct =
|
35
|
+
copy2(&t, r);
|
36
|
+
cr = r->u8;
|
37
|
+
ct = t.u8;
|
37
38
|
cr[0] = ct[l[0]];
|
38
39
|
cr[1] = ct[l[1]];
|
39
40
|
cr[2] = ct[l[2]];
|
@@ -55,13 +56,12 @@ void shufb(int128 *r, const unsigned char *l)
|
|
55
56
|
void shufd(int128 *r, const int128 *x, const unsigned int c)
|
56
57
|
{
|
57
58
|
int128 t;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
copy2(r,&t);
|
59
|
+
|
60
|
+
t.u32[0] = x->u32[c >> 0 & 3];
|
61
|
+
t.u32[1] = x->u32[c >> 2 & 3];
|
62
|
+
t.u32[2] = x->u32[c >> 4 & 3];
|
63
|
+
t.u32[3] = x->u32[c >> 6 & 3];
|
64
|
+
copy2(r, &t);
|
65
65
|
}
|
66
66
|
|
67
67
|
void rshift32_littleendian(int128 *r, const unsigned int n)
|
@@ -108,8 +108,8 @@ void lshift64_littleendian(int128 *r, const unsigned int n)
|
|
108
108
|
|
109
109
|
void toggle(int128 *r)
|
110
110
|
{
|
111
|
-
r->
|
112
|
-
r->
|
111
|
+
r->u64[0] ^= 0xffffffffffffffffULL;
|
112
|
+
r->u64[1] ^= 0xffffffffffffffffULL;
|
113
113
|
}
|
114
114
|
|
115
115
|
void xor_rcon(int128 *r)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
#include "crypto_stream_chacha20.h"
|
3
|
+
|
4
|
+
int
|
5
|
+
crypto_stream_chacha20_ref(unsigned char *c, unsigned long long clen,
|
6
|
+
const unsigned char *n, const unsigned char *k);
|
7
|
+
|
8
|
+
int
|
9
|
+
crypto_stream_chacha20_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
10
|
+
unsigned long long mlen,
|
11
|
+
const unsigned char *n, uint64_t ic,
|
12
|
+
const unsigned char *k);
|