From 60610da39d20b6923935ff06040e07f501f9428a Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 23 Nov 2014 23:42:07 -0800 Subject: [PATCH] Zero the subkey in {stream,xor}_xsalsa20 Spotted by Michael Rogers. --- src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c | 6 +++++- src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c b/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c index 50f87887..64e42cb7 100644 --- a/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c +++ b/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c @@ -7,6 +7,7 @@ Public domain. #include "api.h" #include "crypto_core_hsalsa20.h" #include "crypto_stream_salsa20.h" +#include "utils.h" static const unsigned char sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k' @@ -19,6 +20,9 @@ int crypto_stream( ) { unsigned char subkey[32]; + int ret; crypto_core_hsalsa20(subkey,n,k,sigma); - return crypto_stream_salsa20(c,clen,n + 16,subkey); + ret = crypto_stream_salsa20(c,clen,n + 16,subkey); + sodium_memzero(subkey, sizeof subkey); + return ret; } diff --git a/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c b/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c index 14cce18a..b77b9f78 100644 --- a/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c +++ b/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c @@ -7,6 +7,7 @@ Public domain. #include "api.h" #include "crypto_core_hsalsa20.h" #include "crypto_stream_salsa20.h" +#include "utils.h" static const unsigned char sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k' @@ -20,6 +21,9 @@ int crypto_stream_xor( ) { unsigned char subkey[32]; + int ret; crypto_core_hsalsa20(subkey,n,k,sigma); - return crypto_stream_salsa20_xor(c,m,mlen,n + 16,subkey); + ret = crypto_stream_salsa20_xor(c,m,mlen,n + 16,subkey); + sodium_memzero(subkey, sizeof subkey); + return ret; }