From: Niels Möller Date: Sun, 22 Jun 2025 20:31:02 +0000 (+0200) Subject: Simplify bcrypt salt logic, eliminating a compiler warning. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ffix-bcrypt-warning;p=thirdparty%2Fnettle.git Simplify bcrypt salt logic, eliminating a compiler warning. --- 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);