]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Simplify bcrypt salt logic, eliminating a compiler warning. fix-bcrypt-warning
authorNiels Möller <nisse@lysator.liu.se>
Sun, 22 Jun 2025 20:31:02 +0000 (22:31 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 22 Jun 2025 20:31:02 +0000 (22:31 +0200)
blowfish-bcrypt.c

index b590748eeab690e4d57cbc45dcfde34c934d72d6..385503ac8c7f8212d697a82572bd75279ee2d711 100644 (file)
@@ -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);