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;