Sync reduced rounds versions of salsa20 with supercop

This commit is contained in:
Frank Denis 2015-01-13 19:36:50 +01:00
parent 0fef202b37
commit f580fcfa92
6 changed files with 36 additions and 24 deletions

View File

@ -25,7 +25,7 @@ int crypto_stream(
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned char kcopy[32]; unsigned char kcopy[32];
unsigned long long i; unsigned int i;
unsigned int u; unsigned int u;
if (!clen) return 0; if (!clen) return 0;
@ -50,7 +50,7 @@ int crypto_stream(
if (clen) { if (clen) {
crypto_core_salsa20(block,in,kcopy,sigma); crypto_core_salsa20(block,in,kcopy,sigma);
for (i = 0;i < clen;++i) c[i] = block[i]; for (i = 0;i < (unsigned int) clen;++i) c[i] = block[i];
} }
sodium_memzero(block, sizeof block); sodium_memzero(block, sizeof block);
sodium_memzero(kcopy, sizeof kcopy); sodium_memzero(kcopy, sizeof kcopy);

View File

@ -28,7 +28,7 @@ int crypto_stream_salsa20_xor_ic(
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned char kcopy[32]; unsigned char kcopy[32];
unsigned long long i; unsigned int i;
unsigned int u; unsigned int u;
if (!mlen) return 0; if (!mlen) return 0;
@ -58,7 +58,7 @@ int crypto_stream_salsa20_xor_ic(
if (mlen) { if (mlen) {
crypto_core_salsa20(block,in,kcopy,sigma); crypto_core_salsa20(block,in,kcopy,sigma);
for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i]; for (i = 0;i < (unsigned int) mlen;++i) c[i] = m[i] ^ block[i];
} }
sodium_memzero(block, sizeof block); sodium_memzero(block, sizeof block);
sodium_memzero(kcopy, sizeof kcopy); sodium_memzero(kcopy, sizeof kcopy);

View File

@ -1,5 +1,5 @@
/* /*
version 20080913 version 20140420
D. J. Bernstein D. J. Bernstein
Public domain. Public domain.
*/ */
@ -22,16 +22,18 @@ int crypto_stream(
{ {
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned long long i; unsigned char kcopy[32];
unsigned int 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_salsa2012(c,in,k,sigma); crypto_core_salsa2012(c,in,kcopy,sigma);
u = 1; u = 1;
for (i = 8;i < 16;++i) { for (i = 8;i < 16;++i) {
@ -45,10 +47,11 @@ int crypto_stream(
} }
if (clen) { if (clen) {
crypto_core_salsa2012(block,in,k,sigma); crypto_core_salsa2012(block,in,kcopy,sigma);
for (i = 0;i < clen;++i) c[i] = block[i]; for (i = 0;i < (unsigned int) clen;++i) c[i] = block[i];
} }
sodium_memzero(block, sizeof block); sodium_memzero(block, sizeof block);
sodium_memzero(kcopy, sizeof kcopy);
return 0; return 0;
} }

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_xor(
{ {
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned long long i; unsigned char kcopy[32];
unsigned int 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_salsa2012(block,in,k,sigma); crypto_core_salsa2012(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;
@ -48,10 +50,11 @@ int crypto_stream_xor(
} }
if (mlen) { if (mlen) {
crypto_core_salsa2012(block,in,k,sigma); crypto_core_salsa2012(block,in,kcopy,sigma);
for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i]; for (i = 0;i < (unsigned int) mlen;++i) c[i] = m[i] ^ block[i];
} }
sodium_memzero(block, sizeof block); sodium_memzero(block, sizeof block);
sodium_memzero(kcopy, sizeof kcopy);
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
version 20080913 version 20140420
D. J. Bernstein D. J. Bernstein
Public domain. Public domain.
*/ */
@ -22,16 +22,18 @@ int crypto_stream(
{ {
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned long long i; unsigned char kcopy[32];
unsigned int 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_salsa208(c,in,k,sigma); crypto_core_salsa208(c,in,kcopy,sigma);
u = 1; u = 1;
for (i = 8;i < 16;++i) { for (i = 8;i < 16;++i) {
@ -45,10 +47,11 @@ int crypto_stream(
} }
if (clen) { if (clen) {
crypto_core_salsa208(block,in,k,sigma); crypto_core_salsa208(block,in,kcopy,sigma);
for (i = 0;i < clen;++i) c[i] = block[i]; for (i = 0;i < (unsigned int) clen;++i) c[i] = block[i];
} }
sodium_memzero(block, sizeof block); sodium_memzero(block, sizeof block);
sodium_memzero(kcopy, sizeof kcopy);
return 0; return 0;
} }

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_xor(
{ {
unsigned char in[16]; unsigned char in[16];
unsigned char block[64]; unsigned char block[64];
unsigned long long i; unsigned char kcopy[32];
unsigned int 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_salsa208(block,in,k,sigma); crypto_core_salsa208(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;
@ -48,10 +50,11 @@ int crypto_stream_xor(
} }
if (mlen) { if (mlen) {
crypto_core_salsa208(block,in,k,sigma); crypto_core_salsa208(block,in,kcopy,sigma);
for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i]; for (i = 0;i < (unsigned int) mlen;++i) c[i] = m[i] ^ block[i];
} }
sodium_memzero(block, sizeof block); sodium_memzero(block, sizeof block);
sodium_memzero(kcopy, sizeof kcopy);
return 0; return 0;
} }