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
@@ -0,0 +1,275 @@
|
|
1
|
+
|
2
|
+
/* $OpenBSD: chacha.c,v 1.1 2013/11/21 00:45:44 djm Exp $ */
|
3
|
+
|
4
|
+
/*
|
5
|
+
chacha-merged.c version 20080118
|
6
|
+
D. J. Bernstein
|
7
|
+
Public domain.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <stdint.h>
|
11
|
+
#include <string.h>
|
12
|
+
|
13
|
+
#include "api.h"
|
14
|
+
#include "crypto_stream_chacha20.h"
|
15
|
+
#include "utils.h"
|
16
|
+
|
17
|
+
struct chacha_ctx {
|
18
|
+
uint32_t input[16];
|
19
|
+
};
|
20
|
+
|
21
|
+
typedef uint8_t u8;
|
22
|
+
typedef uint32_t u32;
|
23
|
+
|
24
|
+
typedef struct chacha_ctx chacha_ctx;
|
25
|
+
|
26
|
+
#define U8C(v) (v##U)
|
27
|
+
#define U32C(v) (v##U)
|
28
|
+
|
29
|
+
#define U8V(v) ((u8)(v) & U8C(0xFF))
|
30
|
+
#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
|
31
|
+
|
32
|
+
#define ROTL32(v, n) \
|
33
|
+
(U32V((v) << (n)) | ((v) >> (32 - (n))))
|
34
|
+
|
35
|
+
#define U8TO32_LITTLE(p) \
|
36
|
+
(((u32)((p)[0]) ) | \
|
37
|
+
((u32)((p)[1]) << 8) | \
|
38
|
+
((u32)((p)[2]) << 16) | \
|
39
|
+
((u32)((p)[3]) << 24))
|
40
|
+
|
41
|
+
#define U32TO8_LITTLE(p, v) \
|
42
|
+
do { \
|
43
|
+
(p)[0] = U8V((v) ); \
|
44
|
+
(p)[1] = U8V((v) >> 8); \
|
45
|
+
(p)[2] = U8V((v) >> 16); \
|
46
|
+
(p)[3] = U8V((v) >> 24); \
|
47
|
+
} while (0)
|
48
|
+
|
49
|
+
#define ROTATE(v,c) (ROTL32(v,c))
|
50
|
+
#define XOR(v,w) ((v) ^ (w))
|
51
|
+
#define PLUS(v,w) (U32V((v) + (w)))
|
52
|
+
#define PLUSONE(v) (PLUS((v),1))
|
53
|
+
|
54
|
+
#define QUARTERROUND(a,b,c,d) \
|
55
|
+
a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
|
56
|
+
c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
|
57
|
+
a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
|
58
|
+
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
|
59
|
+
|
60
|
+
static const unsigned char sigma[16] = {
|
61
|
+
'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'
|
62
|
+
};
|
63
|
+
|
64
|
+
static void
|
65
|
+
chacha_keysetup(chacha_ctx *x, const u8 *k)
|
66
|
+
{
|
67
|
+
const unsigned char *constants;
|
68
|
+
|
69
|
+
x->input[4] = U8TO32_LITTLE(k + 0);
|
70
|
+
x->input[5] = U8TO32_LITTLE(k + 4);
|
71
|
+
x->input[6] = U8TO32_LITTLE(k + 8);
|
72
|
+
x->input[7] = U8TO32_LITTLE(k + 12);
|
73
|
+
k += 16;
|
74
|
+
constants = sigma;
|
75
|
+
x->input[8] = U8TO32_LITTLE(k + 0);
|
76
|
+
x->input[9] = U8TO32_LITTLE(k + 4);
|
77
|
+
x->input[10] = U8TO32_LITTLE(k + 8);
|
78
|
+
x->input[11] = U8TO32_LITTLE(k + 12);
|
79
|
+
x->input[0] = U8TO32_LITTLE(constants + 0);
|
80
|
+
x->input[1] = U8TO32_LITTLE(constants + 4);
|
81
|
+
x->input[2] = U8TO32_LITTLE(constants + 8);
|
82
|
+
x->input[3] = U8TO32_LITTLE(constants + 12);
|
83
|
+
}
|
84
|
+
|
85
|
+
static void
|
86
|
+
chacha_ivsetup(chacha_ctx *x, const u8 *iv, const u8 *counter)
|
87
|
+
{
|
88
|
+
x->input[12] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 0);
|
89
|
+
x->input[13] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 4);
|
90
|
+
x->input[14] = U8TO32_LITTLE(iv + 0);
|
91
|
+
x->input[15] = U8TO32_LITTLE(iv + 4);
|
92
|
+
}
|
93
|
+
|
94
|
+
static void
|
95
|
+
chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, unsigned long long bytes)
|
96
|
+
{
|
97
|
+
u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
|
98
|
+
u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
|
99
|
+
u8 *ctarget = NULL;
|
100
|
+
u8 tmp[64];
|
101
|
+
unsigned long long i;
|
102
|
+
|
103
|
+
if (!bytes) {
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
j0 = x->input[0];
|
107
|
+
j1 = x->input[1];
|
108
|
+
j2 = x->input[2];
|
109
|
+
j3 = x->input[3];
|
110
|
+
j4 = x->input[4];
|
111
|
+
j5 = x->input[5];
|
112
|
+
j6 = x->input[6];
|
113
|
+
j7 = x->input[7];
|
114
|
+
j8 = x->input[8];
|
115
|
+
j9 = x->input[9];
|
116
|
+
j10 = x->input[10];
|
117
|
+
j11 = x->input[11];
|
118
|
+
j12 = x->input[12];
|
119
|
+
j13 = x->input[13];
|
120
|
+
j14 = x->input[14];
|
121
|
+
j15 = x->input[15];
|
122
|
+
|
123
|
+
for (;;) {
|
124
|
+
if (bytes < 64) {
|
125
|
+
for (i = 0; i < bytes; ++i) {
|
126
|
+
tmp[i] = m[i];
|
127
|
+
}
|
128
|
+
m = tmp;
|
129
|
+
ctarget = c;
|
130
|
+
c = tmp;
|
131
|
+
}
|
132
|
+
x0 = j0;
|
133
|
+
x1 = j1;
|
134
|
+
x2 = j2;
|
135
|
+
x3 = j3;
|
136
|
+
x4 = j4;
|
137
|
+
x5 = j5;
|
138
|
+
x6 = j6;
|
139
|
+
x7 = j7;
|
140
|
+
x8 = j8;
|
141
|
+
x9 = j9;
|
142
|
+
x10 = j10;
|
143
|
+
x11 = j11;
|
144
|
+
x12 = j12;
|
145
|
+
x13 = j13;
|
146
|
+
x14 = j14;
|
147
|
+
x15 = j15;
|
148
|
+
for (i = 20; i > 0; i -= 2) {
|
149
|
+
QUARTERROUND(x0, x4, x8, x12)
|
150
|
+
QUARTERROUND(x1, x5, x9, x13)
|
151
|
+
QUARTERROUND(x2, x6, x10, x14)
|
152
|
+
QUARTERROUND(x3, x7, x11, x15)
|
153
|
+
QUARTERROUND(x0, x5, x10, x15)
|
154
|
+
QUARTERROUND(x1, x6, x11, x12)
|
155
|
+
QUARTERROUND(x2, x7, x8, x13)
|
156
|
+
QUARTERROUND(x3, x4, x9, x14)
|
157
|
+
}
|
158
|
+
x0 = PLUS(x0, j0);
|
159
|
+
x1 = PLUS(x1, j1);
|
160
|
+
x2 = PLUS(x2, j2);
|
161
|
+
x3 = PLUS(x3, j3);
|
162
|
+
x4 = PLUS(x4, j4);
|
163
|
+
x5 = PLUS(x5, j5);
|
164
|
+
x6 = PLUS(x6, j6);
|
165
|
+
x7 = PLUS(x7, j7);
|
166
|
+
x8 = PLUS(x8, j8);
|
167
|
+
x9 = PLUS(x9, j9);
|
168
|
+
x10 = PLUS(x10, j10);
|
169
|
+
x11 = PLUS(x11, j11);
|
170
|
+
x12 = PLUS(x12, j12);
|
171
|
+
x13 = PLUS(x13, j13);
|
172
|
+
x14 = PLUS(x14, j14);
|
173
|
+
x15 = PLUS(x15, j15);
|
174
|
+
|
175
|
+
x0 = XOR(x0, U8TO32_LITTLE(m + 0));
|
176
|
+
x1 = XOR(x1, U8TO32_LITTLE(m + 4));
|
177
|
+
x2 = XOR(x2, U8TO32_LITTLE(m + 8));
|
178
|
+
x3 = XOR(x3, U8TO32_LITTLE(m + 12));
|
179
|
+
x4 = XOR(x4, U8TO32_LITTLE(m + 16));
|
180
|
+
x5 = XOR(x5, U8TO32_LITTLE(m + 20));
|
181
|
+
x6 = XOR(x6, U8TO32_LITTLE(m + 24));
|
182
|
+
x7 = XOR(x7, U8TO32_LITTLE(m + 28));
|
183
|
+
x8 = XOR(x8, U8TO32_LITTLE(m + 32));
|
184
|
+
x9 = XOR(x9, U8TO32_LITTLE(m + 36));
|
185
|
+
x10 = XOR(x10, U8TO32_LITTLE(m + 40));
|
186
|
+
x11 = XOR(x11, U8TO32_LITTLE(m + 44));
|
187
|
+
x12 = XOR(x12, U8TO32_LITTLE(m + 48));
|
188
|
+
x13 = XOR(x13, U8TO32_LITTLE(m + 52));
|
189
|
+
x14 = XOR(x14, U8TO32_LITTLE(m + 56));
|
190
|
+
x15 = XOR(x15, U8TO32_LITTLE(m + 60));
|
191
|
+
|
192
|
+
j12 = PLUSONE(j12);
|
193
|
+
if (!j12) {
|
194
|
+
j13 = PLUSONE(j13);
|
195
|
+
/* stopping at 2^70 bytes per nonce is user's responsibility */
|
196
|
+
}
|
197
|
+
|
198
|
+
U32TO8_LITTLE(c + 0, x0);
|
199
|
+
U32TO8_LITTLE(c + 4, x1);
|
200
|
+
U32TO8_LITTLE(c + 8, x2);
|
201
|
+
U32TO8_LITTLE(c + 12, x3);
|
202
|
+
U32TO8_LITTLE(c + 16, x4);
|
203
|
+
U32TO8_LITTLE(c + 20, x5);
|
204
|
+
U32TO8_LITTLE(c + 24, x6);
|
205
|
+
U32TO8_LITTLE(c + 28, x7);
|
206
|
+
U32TO8_LITTLE(c + 32, x8);
|
207
|
+
U32TO8_LITTLE(c + 36, x9);
|
208
|
+
U32TO8_LITTLE(c + 40, x10);
|
209
|
+
U32TO8_LITTLE(c + 44, x11);
|
210
|
+
U32TO8_LITTLE(c + 48, x12);
|
211
|
+
U32TO8_LITTLE(c + 52, x13);
|
212
|
+
U32TO8_LITTLE(c + 56, x14);
|
213
|
+
U32TO8_LITTLE(c + 60, x15);
|
214
|
+
|
215
|
+
if (bytes <= 64) {
|
216
|
+
if (bytes < 64) {
|
217
|
+
for (i = 0; i < bytes; ++i) {
|
218
|
+
ctarget[i] = c[i];
|
219
|
+
}
|
220
|
+
}
|
221
|
+
x->input[12] = j12;
|
222
|
+
x->input[13] = j13;
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
bytes -= 64;
|
226
|
+
c += 64;
|
227
|
+
m += 64;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
int
|
232
|
+
crypto_stream_chacha20_ref(unsigned char *c, unsigned long long clen,
|
233
|
+
const unsigned char *n, const unsigned char *k)
|
234
|
+
{
|
235
|
+
struct chacha_ctx ctx;
|
236
|
+
|
237
|
+
if (!clen) {
|
238
|
+
return 0;
|
239
|
+
}
|
240
|
+
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
|
241
|
+
chacha_keysetup(&ctx, k);
|
242
|
+
chacha_ivsetup(&ctx, n, NULL);
|
243
|
+
memset(c, 0, clen);
|
244
|
+
chacha_encrypt_bytes(&ctx, c, c, clen);
|
245
|
+
sodium_memzero(&ctx, sizeof ctx);
|
246
|
+
|
247
|
+
return 0;
|
248
|
+
}
|
249
|
+
|
250
|
+
int
|
251
|
+
crypto_stream_chacha20_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
252
|
+
unsigned long long mlen,
|
253
|
+
const unsigned char *n, uint64_t ic,
|
254
|
+
const unsigned char *k)
|
255
|
+
{
|
256
|
+
struct chacha_ctx ctx;
|
257
|
+
uint8_t ic_bytes[8];
|
258
|
+
uint32_t ic_high;
|
259
|
+
uint32_t ic_low;
|
260
|
+
|
261
|
+
if (!mlen) {
|
262
|
+
return 0;
|
263
|
+
}
|
264
|
+
ic_high = U32V(ic >> 32);
|
265
|
+
ic_low = U32V(ic);
|
266
|
+
U32TO8_LITTLE(&ic_bytes[0], ic_low);
|
267
|
+
U32TO8_LITTLE(&ic_bytes[4], ic_high);
|
268
|
+
chacha_keysetup(&ctx, k);
|
269
|
+
chacha_ivsetup(&ctx, n, ic_bytes);
|
270
|
+
chacha_encrypt_bytes(&ctx, m, c, mlen);
|
271
|
+
sodium_memzero(&ctx, sizeof ctx);
|
272
|
+
sodium_memzero(ic_bytes, sizeof ic_bytes);
|
273
|
+
|
274
|
+
return 0;
|
275
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#include "crypto_stream_chacha20.h"
|
2
|
+
#include "ref/api.h"
|
3
|
+
|
4
|
+
size_t
|
5
|
+
crypto_stream_chacha20_keybytes(void) {
|
6
|
+
return crypto_stream_chacha20_KEYBYTES;
|
7
|
+
}
|
8
|
+
|
9
|
+
size_t
|
10
|
+
crypto_stream_chacha20_noncebytes(void) {
|
11
|
+
return crypto_stream_chacha20_NONCEBYTES;
|
12
|
+
}
|
13
|
+
|
14
|
+
int
|
15
|
+
crypto_stream_chacha20(unsigned char *c, unsigned long long clen,
|
16
|
+
const unsigned char *n, const unsigned char *k)
|
17
|
+
{
|
18
|
+
return crypto_stream_chacha20_ref(c, clen, n, k);
|
19
|
+
}
|
20
|
+
|
21
|
+
int
|
22
|
+
crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
23
|
+
unsigned long long mlen,
|
24
|
+
const unsigned char *n, uint64_t ic,
|
25
|
+
const unsigned char *k)
|
26
|
+
{
|
27
|
+
return crypto_stream_chacha20_ref_xor_ic(c, m, mlen, n, ic, k);
|
28
|
+
}
|
29
|
+
|
30
|
+
int
|
31
|
+
crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,
|
32
|
+
unsigned long long mlen, const unsigned char *n,
|
33
|
+
const unsigned char *k)
|
34
|
+
{
|
35
|
+
return crypto_stream_chacha20_ref_xor_ic(c, m, mlen, n, 0U, k);
|
36
|
+
}
|
data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S
CHANGED
@@ -33,19 +33,20 @@ mov $0,%rax
|
|
33
33
|
mov %r9,%rcx
|
34
34
|
rep stosb
|
35
35
|
sub %r9,%rdi
|
36
|
+
movq $0,472(%rsp)
|
36
37
|
jmp ._start
|
37
38
|
|
38
39
|
.text
|
39
40
|
.p2align 5
|
40
41
|
|
41
|
-
.globl
|
42
|
-
.globl
|
42
|
+
.globl crypto_stream_salsa20_xor_ic
|
43
|
+
.globl _crypto_stream_salsa20_xor_ic
|
43
44
|
#ifdef __ELF__
|
44
|
-
.type
|
45
|
-
.type
|
45
|
+
.type crypto_stream_salsa20_xor_ic, @function
|
46
|
+
.type _crypto_stream_salsa20_xor_ic, @function
|
46
47
|
#endif
|
47
|
-
|
48
|
-
|
48
|
+
crypto_stream_salsa20_xor_ic:
|
49
|
+
_crypto_stream_salsa20_xor_ic:
|
49
50
|
|
50
51
|
mov %rsp,%r11
|
51
52
|
and $31,%r11
|
@@ -60,9 +61,10 @@ movq %rbx,456(%rsp)
|
|
60
61
|
movq %rbp,464(%rsp)
|
61
62
|
mov %rdi,%rdi
|
62
63
|
mov %rsi,%rsi
|
64
|
+
mov %r9,%r10
|
65
|
+
movq %r8,472(%rsp)
|
63
66
|
mov %rdx,%r9
|
64
67
|
mov %rcx,%rdx
|
65
|
-
mov %r8,%r10
|
66
68
|
cmp $0,%r9
|
67
69
|
jbe ._done
|
68
70
|
|
@@ -75,17 +77,16 @@ movl %ecx,64(%rsp)
|
|
75
77
|
movl %r8d,4+64(%rsp)
|
76
78
|
movl %eax,8+64(%rsp)
|
77
79
|
movl %r11d,12+64(%rsp)
|
78
|
-
mov $0,%rcx
|
79
80
|
movl 24(%r10),%r8d
|
80
81
|
movl 4(%r10),%eax
|
81
82
|
movl 4(%rdx),%edx
|
82
|
-
movq
|
83
|
+
movq 472(%rsp),%rcx
|
83
84
|
movl %ecx,80(%rsp)
|
84
85
|
movl %r8d,4+80(%rsp)
|
85
86
|
movl %eax,8+80(%rsp)
|
86
87
|
movl %edx,12+80(%rsp)
|
87
88
|
movl 12(%r10),%edx
|
88
|
-
|
89
|
+
shr $32,%rcx
|
89
90
|
movl 28(%r10),%r8d
|
90
91
|
movl 8(%r10),%eax
|
91
92
|
movl %edx,96(%rsp)
|
@@ -4,6 +4,8 @@ D. J. Bernstein
|
|
4
4
|
Public domain.
|
5
5
|
*/
|
6
6
|
|
7
|
+
#include <stdint.h>
|
8
|
+
|
7
9
|
#include "api.h"
|
8
10
|
#include "crypto_core_salsa20.h"
|
9
11
|
#include "utils.h"
|
@@ -16,10 +18,10 @@ static const unsigned char sigma[16] = {
|
|
16
18
|
'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'
|
17
19
|
};
|
18
20
|
|
19
|
-
int
|
21
|
+
int crypto_stream_salsa20_xor_ic(
|
20
22
|
unsigned char *c,
|
21
23
|
const unsigned char *m,unsigned long long mlen,
|
22
|
-
const unsigned char *n,
|
24
|
+
const unsigned char *n, uint64_t ic,
|
23
25
|
const unsigned char *k
|
24
26
|
)
|
25
27
|
{
|
@@ -33,7 +35,10 @@ int crypto_stream_xor(
|
|
33
35
|
|
34
36
|
for (i = 0;i < 32;++i) kcopy[i] = k[i];
|
35
37
|
for (i = 0;i < 8;++i) in[i] = n[i];
|
36
|
-
for (i = 8;i < 16;++i)
|
38
|
+
for (i = 8;i < 16;++i) {
|
39
|
+
in[i] = (unsigned char) (ic & 0xff);
|
40
|
+
ic >>= 8;
|
41
|
+
}
|
37
42
|
|
38
43
|
while (mlen >= 64) {
|
39
44
|
crypto_core_salsa20(block,in,kcopy,sigma);
|
@@ -9,3 +9,11 @@ size_t
|
|
9
9
|
crypto_stream_salsa20_noncebytes(void) {
|
10
10
|
return crypto_stream_salsa20_NONCEBYTES;
|
11
11
|
}
|
12
|
+
|
13
|
+
int
|
14
|
+
crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m,
|
15
|
+
unsigned long long mlen, const unsigned char *n,
|
16
|
+
const unsigned char *k)
|
17
|
+
{
|
18
|
+
return crypto_stream_salsa20_xor_ic(c, m, mlen, n, 0U, k);
|
19
|
+
}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
SODIUM_EXPORT = \
|
3
3
|
sodium.h \
|
4
4
|
sodium/core.h \
|
5
|
+
sodium/crypto_aead_chacha20poly1305.h \
|
5
6
|
sodium/crypto_auth.h \
|
6
7
|
sodium/crypto_auth_hmacsha256.h \
|
7
8
|
sodium/crypto_auth_hmacsha512.h \
|
@@ -19,8 +20,7 @@ SODIUM_EXPORT = \
|
|
19
20
|
sodium/crypto_hash_sha512.h \
|
20
21
|
sodium/crypto_onetimeauth.h \
|
21
22
|
sodium/crypto_onetimeauth_poly1305.h \
|
22
|
-
sodium/
|
23
|
-
sodium/crypto_pwhash_scryptxsalsa208sha256.h \
|
23
|
+
sodium/crypto_pwhash_scryptsalsa208sha256.h \
|
24
24
|
sodium/crypto_scalarmult.h \
|
25
25
|
sodium/crypto_scalarmult_curve25519.h \
|
26
26
|
sodium/crypto_secretbox.h \
|
@@ -33,6 +33,7 @@ SODIUM_EXPORT = \
|
|
33
33
|
sodium/crypto_stream.h \
|
34
34
|
sodium/crypto_stream_aes128ctr.h \
|
35
35
|
sodium/crypto_stream_aes256estream.h \
|
36
|
+
sodium/crypto_stream_chacha20.h \
|
36
37
|
sodium/crypto_stream_salsa20.h \
|
37
38
|
sodium/crypto_stream_salsa2012.h \
|
38
39
|
sodium/crypto_stream_salsa208.h \
|
@@ -299,6 +299,7 @@ top_srcdir = @top_srcdir@
|
|
299
299
|
SODIUM_EXPORT = \
|
300
300
|
sodium.h \
|
301
301
|
sodium/core.h \
|
302
|
+
sodium/crypto_aead_chacha20poly1305.h \
|
302
303
|
sodium/crypto_auth.h \
|
303
304
|
sodium/crypto_auth_hmacsha256.h \
|
304
305
|
sodium/crypto_auth_hmacsha512.h \
|
@@ -316,8 +317,7 @@ SODIUM_EXPORT = \
|
|
316
317
|
sodium/crypto_hash_sha512.h \
|
317
318
|
sodium/crypto_onetimeauth.h \
|
318
319
|
sodium/crypto_onetimeauth_poly1305.h \
|
319
|
-
sodium/
|
320
|
-
sodium/crypto_pwhash_scryptxsalsa208sha256.h \
|
320
|
+
sodium/crypto_pwhash_scryptsalsa208sha256.h \
|
321
321
|
sodium/crypto_scalarmult.h \
|
322
322
|
sodium/crypto_scalarmult_curve25519.h \
|
323
323
|
sodium/crypto_secretbox.h \
|
@@ -330,6 +330,7 @@ SODIUM_EXPORT = \
|
|
330
330
|
sodium/crypto_stream.h \
|
331
331
|
sodium/crypto_stream_aes128ctr.h \
|
332
332
|
sodium/crypto_stream_aes256estream.h \
|
333
|
+
sodium/crypto_stream_chacha20.h \
|
333
334
|
sodium/crypto_stream_salsa20.h \
|
334
335
|
sodium/crypto_stream_salsa2012.h \
|
335
336
|
sodium/crypto_stream_salsa208.h \
|