mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Zero the subkey in {stream,xor}_xsalsa20
Spotted by Michael Rogers.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user