X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=crc%2Fsha256.c;h=dcb1677274a128cd584a19d4144a776531c3b187;hb=ff1f3280ded10c6844c07f0e466ca02224e48b62;hp=fe08ab3a0e0554ed417e6b7c11dedadffd20677b;hpb=5921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373;p=fio.git diff --git a/crc/sha256.c b/crc/sha256.c index fe08ab3a..dcb16772 100644 --- a/crc/sha256.c +++ b/crc/sha256.c @@ -19,24 +19,9 @@ #include #include +#include "../lib/bswap.h" #include "sha256.h" -#if __BYTE_ORDER == __LITTLE_ENDIAN -static int __be32_to_cpu(uint32_t val) -{ - uint32_t c1, c2, c3, c4; - - c1 = (val >> 24) & 0xff; - c2 = (val >> 16) & 0xff; - c3 = (val >> 8) & 0xff; - c4 = val & 0xff; - - return c1 | c2 << 8 | c3 << 16 | c4 << 24; -} -#else -#define __be32_to_cpu(x) (x) -#endif - #define SHA256_DIGEST_SIZE 32 #define SHA256_HMAC_BLOCK_SIZE 64 @@ -258,10 +243,10 @@ void sha256_init(struct sha256_ctx *sctx) void sha256_update(struct sha256_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) & 0x3f); + idx = (unsigned int)((sctx->count[0] >> 3) & 0x3f); /* Update number of bits */ if ((sctx->count[0] += (len << 3)) < (len << 3)) { @@ -269,20 +254,20 @@ void sha256_update(struct sha256_ctx *sctx, const uint8_t *data, sctx->count[1] += (len >> 29); } - part_len = 64 - index; + part_len = 64 - 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); sha256_transform(sctx->state, sctx->buf); for (i = part_len; i + 63 < len; i += 64) sha256_transform(sctx->state, &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); }