summaryrefslogtreecommitdiff
path: root/blowfish-bcrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'blowfish-bcrypt.c')
-rw-r--r--blowfish-bcrypt.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/blowfish-bcrypt.c b/blowfish-bcrypt.c
index 800d1468..08b1e32e 100644
--- a/blowfish-bcrypt.c
+++ b/blowfish-bcrypt.c
@@ -42,7 +42,7 @@
#include "blowfish.h"
#include "blowfish-internal.h"
#include "base64.h"
-
+#include "bswap-internal.h"
#include "macros.h"
#define CRYPTPLEN 7
@@ -149,19 +149,16 @@ static uint32_t magic_w[6] = {
0x64657253, 0x63727944, 0x6F756274
};
-/* conflicts with OpenBSD's swap32 macro */
-#undef swap32
-
-static void swap32(uint32_t *x, int count)
+#if WORDS_BIGENDIAN
+#define bswap32_if_le(x, n)
+#else
+static void bswap32_if_le (uint32_t *x, unsigned n)
{
-#if !WORDS_BIGENDIAN
- do {
- uint32_t tmp = *x;
- tmp = (tmp << 16) | (tmp >> 16);
- *x++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF);
- } while (--count);
-#endif
+ 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,
@@ -343,7 +340,7 @@ static int ibcrypt(uint8_t *dst,
else if (lenscheme < HASHOFFSET)
return 0;
memcpy(psalt, data.binary.salt, BLOWFISH_BCRYPT_BINSALT_SIZE);
- swap32(data.binary.salt, 4);
+ bswap32_if_le (data.binary.salt, 4);
if (log2rounds < minlog2rounds || log2rounds > 31)
return 0;
@@ -448,7 +445,7 @@ static int ibcrypt(uint8_t *dst,
dst = (uint8_t*)
encode_radix64((char*) dst, BLOWFISH_BCRYPT_BINSALT_SIZE, psalt) - 1;
- swap32(data.binary.output, 6);
+ bswap32_if_le (data.binary.output, 6);
/* 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);