Skip to content

Commit 06c13cd

Browse files
committed
Non-constant-time password hash comparison
In wolfSSHd, the comparisons of the password hash and public keys were using memcmp(). Changed to use ConstantCompare(). Affected functions: CheckPasswordHashUnix, CheckPublicKeyUnix. Issue: F-53
1 parent 0103806 commit 06c13cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

apps/wolfsshd/auth.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ static int CheckPasswordHashUnix(const char* input, char* stored)
338338
if (storedSz == 0 || stored[0] == '*' ||
339339
hashedInputSz == 0 || hashedInput[0] == '*' ||
340340
hashedInputSz != storedSz ||
341-
WMEMCMP(hashedInput, stored, storedSz) != 0) {
341+
ConstantCompare((byte*)hashedInput,
342+
(byte*)stored, storedSz) != 0) {
342343
ret = WSSHD_AUTH_FAILURE;
343344
}
344345
}
@@ -656,7 +657,7 @@ static int CheckPublicKeyUnix(const char* name,
656657
if (rc == WS_SUCCESS) {
657658
rc = wc_Hash(WC_HASH_TYPE_SHA256, caKey, caKeySz, fingerprint,
658659
WC_SHA256_DIGEST_SIZE);
659-
if (rc == 0 && WMEMCMP(fingerprint, pubKeyCtx->caKey,
660+
if (rc == 0 && ConstantCompare(fingerprint, pubKeyCtx->caKey,
660661
WC_SHA256_DIGEST_SIZE) == 0) {
661662
foundKey = 1;
662663
break;

0 commit comments

Comments
 (0)