1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -07:00

Sync salsa20/ref with supercop-20140425

But these changes may be reverted unless there is a solid reason for
adding these copies to the stack.
This commit is contained in:
Frank Denis 2014-05-07 21:39:43 -07:00
parent c81c5c1010
commit dcf8869229
2 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* /*
version 20080913 version 20140420
D. J. Bernstein D. J. Bernstein
Public domain. Public domain.
*/ */
@ -23,16 +23,18 @@ int crypto_stream(
{ {
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned char kcopy[32];
unsigned long long i; unsigned long long i;
unsigned int u; unsigned int u;
if (!clen) return 0; if (!clen) return 0;
for (i = 0;i < 32;++i) kcopy[i] = k[i];
for (i = 0;i < 8;++i) in[i] = n[i]; for (i = 0;i < 8;++i) in[i] = n[i];
for (i = 8;i < 16;++i) in[i] = 0; for (i = 8;i < 16;++i) in[i] = 0;
while (clen >= 64) { while (clen >= 64) {
crypto_core_salsa20(c,in,k,sigma); crypto_core_salsa20(c,in,kcopy,sigma);
u = 1; u = 1;
for (i = 8;i < 16;++i) { for (i = 8;i < 16;++i) {
@ -46,7 +48,7 @@ int crypto_stream(
} }
if (clen) { if (clen) {
crypto_core_salsa20(block,in,k,sigma); crypto_core_salsa20(block,in,kcopy,sigma);
for (i = 0;i < clen;++i) c[i] = block[i]; for (i = 0;i < clen;++i) c[i] = block[i];
} }
return 0; return 0;

View File

@ -1,5 +1,5 @@
/* /*
version 20080913 version 20140420
D. J. Bernstein D. J. Bernstein
Public domain. Public domain.
*/ */
@ -24,16 +24,18 @@ int crypto_stream_xor(
{ {
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned char kcopy[32];
unsigned long long i; unsigned long long i;
unsigned int u; unsigned int u;
if (!mlen) return 0; if (!mlen) return 0;
for (i = 0;i < 32;++i) kcopy[i] = k[i];
for (i = 0;i < 8;++i) in[i] = n[i]; for (i = 0;i < 8;++i) in[i] = n[i];
for (i = 8;i < 16;++i) in[i] = 0; for (i = 8;i < 16;++i) in[i] = 0;
while (mlen >= 64) { while (mlen >= 64) {
crypto_core_salsa20(block,in,k,sigma); crypto_core_salsa20(block,in,kcopy,sigma);
for (i = 0;i < 64;++i) c[i] = m[i] ^ block[i]; for (i = 0;i < 64;++i) c[i] = m[i] ^ block[i];
u = 1; u = 1;
@ -49,7 +51,7 @@ int crypto_stream_xor(
} }
if (mlen) { if (mlen) {
crypto_core_salsa20(block,in,k,sigma); crypto_core_salsa20(block,in,kcopy,sigma);
for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i]; for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i];
} }
return 0; return 0;