Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib-platform/crypto/crypto_scrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "crypto_scrypt_smix_sse2.h"

#include "crypto_scrypt.h"
#include "insecure_memzero.h"

static void (* smix_func)(uint8_t *, size_t, uint64_t, void *, void *) = NULL;

Expand Down Expand Up @@ -144,21 +145,26 @@ crypto_scrypt_internal(const uint8_t * passwd, size_t passwdlen,
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);

/* Free memory. */
insecure_memzero(V, (size_t)(128 * r * N));
#if defined(MAP_ANON) && defined(HAVE_MMAP)
if (munmap(V0, (size_t)(128 * r * N)))
goto err2;
#else
free(V0);
#endif
insecure_memzero(XY, 256 * r + 64);
insecure_memzero(B, 128 * r * p);
free(XY0);
free(B0);

/* Success! */
return (0);

err2:
insecure_memzero(XY, 256 * r + 64);
free(XY0);
err1:
insecure_memzero(B, 128 * r * p);
free(B0);
err0:
/* Failure! */
Expand Down
6 changes: 6 additions & 0 deletions lib/crypto/crypto_scrypt-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "sysendian.h"

#include "crypto_scrypt.h"
#include "insecure_memzero.h"

static void blkcpy(uint8_t *, uint8_t *, size_t);
static void blkxor(uint8_t *, uint8_t *, size_t);
Expand Down Expand Up @@ -267,6 +268,9 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);

/* Free memory. */
insecure_memzero(V, 128 * r * N);
insecure_memzero(XY, 256 * r);
insecure_memzero(B, 128 * r * p);
free(V);
free(XY);
free(B);
Expand All @@ -275,8 +279,10 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
return (0);

err2:
insecure_memzero(XY, 256 * r);
free(XY);
err1:
insecure_memzero(B, 128 * r * p);
free(B);
err0:
/* Failure! */
Expand Down
Loading