#ifdef _STRING_ARCH_unaligned
*(uint64_t *) &ctx->buffer[bytes + pad] = SWAP64 (ctx->total64 << 3);
#else
- *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
- *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
- (ctx->total[0] >> 29));
+ *(uint32_t *) &ctx->buffer[bytes + pad + 4]
+ = SWAP (ctx->total[TOTAL64_low] << 3);
+ *(uint32_t *) &ctx->buffer[bytes + pad]
+ = SWAP ((ctx->total[TOTAL64_high] << 3) |
+ (ctx->total[TOTAL64_low] >> 29));
#endif
/* Process last bytes. */
#ifdef USE_TOTAL128
ctx->total128 += len;
#else
- ctx->total[0] += len;
- if (ctx->total[0] < len)
- ++ctx->total[1];
+ ctx->total[TOTAL128_low] += len;
+ if (ctx->total[TOTAL128_low] < len)
+ ++ctx->total[TOTAL128_high];
#endif
/* Process all bytes in the buffer with 128 bytes in each round of
#ifdef USE_TOTAL128
ctx->total128 += bytes;
#else
- ctx->total[0] += bytes;
- if (ctx->total[0] < bytes)
- ++ctx->total[1];
+ ctx->total[TOTAL128_low] += bytes;
+ if (ctx->total[TOTAL128_low] < bytes)
+ ++ctx->total[TOTAL128_high];
#endif
pad = bytes >= 112 ? 128 + 112 - bytes : 112 - bytes;
memcpy (&ctx->buffer[bytes], fillbuf, pad);
/* Put the 128-bit file length in *bits* at the end of the buffer. */
- *(uint64_t *) &ctx->buffer[bytes + pad + 8] = SWAP (ctx->total[0] << 3);
- *(uint64_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
- (ctx->total[0] >> 61));
+ *(uint64_t *) &ctx->buffer[bytes + pad + 8]
+ = SWAP (ctx->total[TOTAL128_low] << 3);
+ *(uint64_t *) &ctx->buffer[bytes + pad]
+ = SWAP ((ctx->total[TOTAL128_high] << 3) |
+ (ctx->total[TOTAL128_low] >> 61));
/* Process last bytes. */
sha512_process_block (ctx->buffer, bytes + pad + 16, ctx);
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
-#ifdef _LIBC
-# include <bits/wordsize.h>
-#endif
+#include <endian.h>
+#include <bits/wordsize.h>
/* Structure to save state of computation between the single steps. */
#if defined __GNUC__ && __WORDSIZE == 64
# define USE_TOTAL128
unsigned int total128 __attribute__ ((__mode__ (TI)));
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define TOTAL128_low 0
+# define TOTAL128_high 1
+#else
+# define TOTAL128_low 1
+# define TOTAL128_high 0
#endif
uint64_t total[2];
};