+2024-03-29 Niels Möller <nisse@lysator.liu.se>
+
+ * bswap-internal.h (nettle_bswap32_n): New inline function.
+ (bswap32_n_if_le): New macro, to reduce code duplication.
+ * blowfish-bcrypt.c (bswap32_if_le_n): Deleted, usage replaced
+ with shared bswap32_n_if_le.
+ * umac-set-key.c (bswap32_if_le_n): Likewise.
+
2024-03-28 Niels Möller <nisse@lysator.liu.se>
* sha512-224-meta.c (nettle_sha512_224): Change name to
0x64657253, 0x63727944, 0x6F756274
};
-#if WORDS_BIGENDIAN
-#define bswap32_if_le_n(n, x)
-#else
-static void
-bswap32_if_le_n (unsigned n, uint32_t *x)
-{
- unsigned i;
- for (i = 0; i < n; i++)
- x[i] = nettle_bswap32 (x[i]);
-}
-#endif
-
static void set_xkey(size_t lenkey, const uint8_t *key,
bf_key expanded, bf_key initial,
unsigned bug, uint32_t safety)
else if (lenscheme < HASHOFFSET)
return 0;
memcpy(psalt, data.binary.salt, BLOWFISH_BCRYPT_BINSALT_SIZE);
- bswap32_if_le_n (4, data.binary.salt);
+ bswap32_n_if_le (4, data.binary.salt);
if (log2rounds < minlog2rounds || log2rounds > 31)
return 0;
dst = (uint8_t*)
encode_radix64((char*) dst, BLOWFISH_BCRYPT_BINSALT_SIZE, psalt) - 1;
- bswap32_if_le_n (6, data.binary.output);
+ bswap32_n_if_le (6, data.binary.output);
/* This has to be bug-compatible with the original implementation, so
only encode 23 of the 24 bytes. */
encode_radix64((char*) dst, 23, (uint8_t *) data.binary.output);
}
#endif
+static inline void
+nettle_bswap32_n (unsigned n, uint32_t *x)
+{
+ unsigned i;
+ for (i = 0; i < n; i++)
+ x[i] = nettle_bswap32 (x[i]);
+}
+
#if WORDS_BIGENDIAN
#define bswap64_if_be nettle_bswap64
#define bswap32_if_be nettle_bswap32
#define bswap64_if_le(x) (x)
#define bswap32_if_le(x) (x)
+#define bswap32_n_if_le(n, x)
#else
#define bswap64_if_be(x) (x)
#define bswap32_if_be(x) (x)
#define bswap64_if_le nettle_bswap64
#define bswap32_if_le nettle_bswap32
+#define bswap32_n_if_le nettle_bswap32_n
#endif
#endif /* NETTLE_BSWAP_INTERNAL_H_INCLUDED */
}
}
-#if WORDS_BIGENDIAN
-/* FIXME: Duplicated with blowfish-bcrypt.c. */
-#define bswap32_if_le_n(n, x)
-#else
-static void
-bswap32_if_le_n (unsigned n, uint32_t *x)
-{
- unsigned i;
- for (i = 0; i < n; i++)
- x[i] = nettle_bswap32 (x[i]);
-}
-#endif
-
void
_nettle_umac_set_key (uint32_t *l1_key, uint32_t *l2_key,
uint64_t *l3_key1, uint32_t *l3_key2,
size = UMAC_BLOCK_SIZE / 4 + 4*(n-1);
umac_kdf (aes, 1, size * sizeof(uint32_t), (uint8_t *) l1_key);
- bswap32_if_le_n (size, l1_key);
+ bswap32_n_if_le (size, l1_key);
size = 6*n;
umac_kdf (aes, 2, size * sizeof(uint32_t), (uint8_t *) l2_key);