From cc57ea7cbdc701a51098137d26a5903f44a31b5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niels=20M=C3=B6ller?= Date: Mon, 23 Jun 2025 19:53:01 +0200 Subject: [PATCH] Simplify bcrypt salt logic, eliminating a compiler warning. --- ChangeLog | 5 +++++ blowfish-bcrypt.c | 28 +++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31e3bf45..e4634851 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2025-06-23 Niels Möller + + * blowfish-bcrypt.c (ibcrypt): Simplify salt logic, eliminating a + compiler warning. + 2025-06-22 Niels Möller Delete the old "generic" HMAC API. diff --git a/blowfish-bcrypt.c b/blowfish-bcrypt.c index b590748e..385503ac 100644 --- a/blowfish-bcrypt.c +++ b/blowfish-bcrypt.c @@ -309,25 +309,27 @@ static int ibcrypt(uint8_t *dst, scheme += 2; if (lenscheme >= CRYPTPLEN && *scheme++ != '$') return 0; - if (lenscheme >= HASHOFFSET && !salt) { - struct base64_decode_ctx ctx; - size_t saltlen = BLOWFISH_BCRYPT_BINSALT_SIZE; - - base64_decode_init(&ctx); - ctx.table = radix64_decode_table; - - if (!base64_decode_update(&ctx, &saltlen, (uint8_t *) data.binary.salt, - SALTLEN, (const char*) scheme) - || saltlen != BLOWFISH_BCRYPT_BINSALT_SIZE) - return 0; - } } } if (salt) memcpy(data.binary.salt, salt, BLOWFISH_BCRYPT_BINSALT_SIZE); - else if (lenscheme < HASHOFFSET) + else if (lenscheme >= HASHOFFSET) + { + struct base64_decode_ctx ctx; + size_t saltlen = BLOWFISH_BCRYPT_BINSALT_SIZE; + + base64_decode_init(&ctx); + ctx.table = radix64_decode_table; + + if (!base64_decode_update(&ctx, &saltlen, (uint8_t *) data.binary.salt, + SALTLEN, (const char*) scheme) + || saltlen != BLOWFISH_BCRYPT_BINSALT_SIZE) + return 0; + } + else return 0; + memcpy(psalt, data.binary.salt, BLOWFISH_BCRYPT_BINSALT_SIZE); bswap32_n_if_le (4, data.binary.salt); -- 2.47.2