From dcf8869229cdf6344d457555043d0ca888ca9df0 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 7 May 2014 21:39:43 -0700 Subject: [PATCH] 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. --- .../crypto_stream/salsa20/ref/stream_salsa20_ref.c | 8 +++++--- src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c b/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c index 66015e32..5bed8717 100644 --- a/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +++ b/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c @@ -1,5 +1,5 @@ /* -version 20080913 +version 20140420 D. J. Bernstein Public domain. */ @@ -23,16 +23,18 @@ int crypto_stream( { unsigned char in[16]; unsigned char block[64]; + unsigned char kcopy[32]; unsigned long long i; unsigned int u; 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 = 8;i < 16;++i) in[i] = 0; while (clen >= 64) { - crypto_core_salsa20(c,in,k,sigma); + crypto_core_salsa20(c,in,kcopy,sigma); u = 1; for (i = 8;i < 16;++i) { @@ -46,7 +48,7 @@ int crypto_stream( } 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]; } return 0; diff --git a/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c b/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c index 7d728b27..47d07e0a 100644 --- a/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +++ b/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c @@ -1,5 +1,5 @@ /* -version 20080913 +version 20140420 D. J. Bernstein Public domain. */ @@ -24,16 +24,18 @@ int crypto_stream_xor( { unsigned char in[16]; unsigned char block[64]; + unsigned char kcopy[32]; unsigned long long i; unsigned int u; 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 = 8;i < 16;++i) in[i] = 0; 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]; u = 1; @@ -49,7 +51,7 @@ int crypto_stream_xor( } 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]; } return 0;