diff --git a/ChangeLog b/ChangeLog index d51898b..b0ce2e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * src/sha512.h, src/sha512.c: New. * src/sha256.c (initial_state): Don't export, it's internal. + (memcpy_output_bswap32): Rename and remove last argument. 2014-01-28 Niibe Yutaka diff --git a/src/sha256.c b/src/sha256.c index c948018..7267014 100644 --- a/src/sha256.c +++ b/src/sha256.c @@ -52,13 +52,17 @@ #define SHA256_MASK (SHA256_BLOCK_SIZE - 1) -static void memcpy_bswap32 (void *dst, const uint32_t *p, int n) +static void memcpy_output_bswap32 (unsigned char *dst, const uint32_t *p) { - uint32_t *q = (uint32_t *)dst; + int i; + uint32_t q; - n >>= 2; - while (n--) - q[n] = __builtin_bswap32 (p[n]); /* bswap32 is GCC extention */ + for (i = 0; i < 32; i++) + { + if ((i & 3) == 0) + q[i] = __builtin_bswap32 (p[i >> 2]); /* bswap32 is GCC extention */ + dst[i] = q >> ((i & 3) * 8); + } } #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) @@ -193,7 +197,7 @@ sha256_finish (sha256_context *ctx, unsigned char output[32]) ctx->wbuf[15] = __builtin_bswap32 (ctx->total[0] << 3); sha256_process (ctx); - memcpy_bswap32 (output, ctx->state, SHA256_DIGEST_SIZE); + memcpy_output_bswap32 (output, ctx->state); memset (ctx, 0, sizeof (sha256_context)); } diff --git a/src/sha512.c b/src/sha512.c index c9e3897..640d9c7 100644 --- a/src/sha512.c +++ b/src/sha512.c @@ -37,7 +37,7 @@ #define SHA512_MASK (SHA512_BLOCK_SIZE - 1) -static void memcpy_bswap64 (unsigned char dst[64], const uint64_t *p) +static void memcpy_output_bswap64 (unsigned char dst[64], const uint64_t *p) { int i; uint64_t q; @@ -187,7 +187,7 @@ sha512_finish (sha512_context *ctx, unsigned char output[64]) ctx->wbuf[15] = __builtin_bswap64 (ctx->total[0] << 3); sha512_process (ctx); - memcpy_bswap64 (output, ctx->state); + memcpy_output_bswap64 (output, ctx->state); memset (ctx, 0, sizeof (sha512_context)); }