X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=crc%2Fsha512.c;h=9268a4900e01006ddae9ca2c6fc745a5e146e523;hb=1294c3ec7a02d20a98b105c1c41b23358afc67e4;hp=d9069e30d6cdeea90e63d0800d7532ff49617bd7;hpb=5921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373;p=fio.git diff --git a/crc/sha512.c b/crc/sha512.c index d9069e30..9268a490 100644 --- a/crc/sha512.c +++ b/crc/sha512.c @@ -14,28 +14,9 @@ #include #include +#include "../lib/bswap.h" #include "sha512.h" -#if __BYTE_ORDER == __LITTLE_ENDIAN -static int __be64_to_cpu(uint64_t val) -{ - uint64_t c1, c2, c3, c4, c5, c6, c7, c8; - - c1 = (val >> 56) & 0xff; - c2 = (val >> 48) & 0xff; - c3 = (val >> 40) & 0xff; - c4 = (val >> 32) & 0xff; - c5 = (val >> 24) & 0xff; - c6 = (val >> 16) & 0xff; - c7 = (val >> 8) & 0xff; - c8 = val & 0xff; - - return c1 | c2 << 8 | c3 << 16 | c4 << 24 | c5 << 32 | c6 << 40 | c7 << 48 | c8 << 56; -} -#else -#define __be64_to_cpu(x) (x) -#endif - #define SHA384_DIGEST_SIZE 48 #define SHA512_DIGEST_SIZE 64 #define SHA384_HMAC_BLOCK_SIZE 128 @@ -181,10 +162,10 @@ void sha512_init(struct sha512_ctx *sctx) void sha512_update(struct sha512_ctx *sctx, const uint8_t *data, unsigned int len) { - unsigned int i, index, part_len; + unsigned int i, idx, part_len; /* Compute number of bytes mod 128 */ - index = (unsigned int)((sctx->count[0] >> 3) & 0x7F); + idx = (unsigned int)((sctx->count[0] >> 3) & 0x7F); /* Update number of bits */ if ((sctx->count[0] += (len << 3)) < (len << 3)) { @@ -194,23 +175,23 @@ void sha512_update(struct sha512_ctx *sctx, const uint8_t *data, sctx->count[1] += (len >> 29); } - part_len = 128 - index; + part_len = 128 - idx; /* Transform as many times as possible. */ if (len >= part_len) { - memcpy(&sctx->buf[index], data, part_len); + memcpy(&sctx->buf[idx], data, part_len); sha512_transform(sctx->state, sctx->W, sctx->buf); for (i = part_len; i + 127 < len; i+=128) sha512_transform(sctx->state, sctx->W, &data[i]); - index = 0; + idx = 0; } else { i = 0; } /* Buffer remaining input */ - memcpy(&sctx->buf[index], &data[i], len - i); + memcpy(&sctx->buf[idx], &data[i], len - i); /* erase our data */ memset(sctx->W, 0, sizeof(sctx->W));