From df83ed92353791be18780c540bb483fce4cd706c Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 24 Nov 2020 22:50:15 +0100 Subject: [PATCH] pwhash never supported "in-place" operation - return EINVAL --- src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c | 4 ++++ src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c | 4 ++++ .../scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c index 685fa03a..f9e9a390 100644 --- a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +++ b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c @@ -163,6 +163,10 @@ crypto_pwhash_argon2i(unsigned char *const out, unsigned long long outlen, errno = EINVAL; return -1; } + if ((const void *) out == (const void *) passwd) { + errno = EINVAL; + return -1; + } switch (alg) { case crypto_pwhash_argon2i_ALG_ARGON2I13: if (argon2i_hash_raw((uint32_t) opslimit, (uint32_t) (memlimit / 1024U), diff --git a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c index 99d3e219..d641a617 100644 --- a/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c +++ b/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c @@ -159,6 +159,10 @@ crypto_pwhash_argon2id(unsigned char *const out, unsigned long long outlen, errno = EINVAL; return -1; } + if ((const void *) out == (const void *) passwd) { + errno = EINVAL; + return -1; + } switch (alg) { case crypto_pwhash_argon2id_ALG_ARGON2ID13: if (argon2id_hash_raw((uint32_t) opslimit, (uint32_t) (memlimit / 1024U), diff --git a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c index b77588fa..6f0cb6bc 100644 --- a/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +++ b/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c @@ -176,6 +176,10 @@ crypto_pwhash_scryptsalsa208sha256(unsigned char *const out, errno = EINVAL; /* LCOV_EXCL_LINE */ return -1; /* LCOV_EXCL_LINE */ } + if ((const void *) out == (const void *) passwd) { + errno = EINVAL; + return -1; + } return crypto_pwhash_scryptsalsa208sha256_ll( (const uint8_t *) passwd, (size_t) passwdlen, (const uint8_t *) salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES, (uint64_t)(1) << N_log2,