-/* $OpenBSD: sha2.c,v 1.13 2014/12/19 17:16:57 tedu Exp $ */
+/* $OpenBSD: sha2.c,v 1.14 2014/12/23 19:21:58 tedu Exp $ */
/*
* FILE: sha2.c
#define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16)
#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
-
-/*** ENDIAN REVERSAL MACROS *******************************************/
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define REVERSE32(w,x) { \
- u_int32_t tmp = (w); \
- tmp = (tmp >> 16) | (tmp << 16); \
- (x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
-}
-#define REVERSE64(w,x) { \
- u_int64_t tmp = (w); \
- tmp = (tmp >> 32) | (tmp << 32); \
- tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
- ((tmp & 0x00ff00ff00ff00ffULL) << 8); \
- (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
- ((tmp & 0x0000ffff0000ffffULL) << 16); \
-}
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-
/*
* Macro for incrementally adding the unsigned 64-bit integer n to the
* unsigned 128-bit integer (represented using a two-element array of
usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH;
#if BYTE_ORDER == LITTLE_ENDIAN
/* Convert FROM host byte order */
- REVERSE64(context->bitcount[0], context->bitcount[0]);
+ context->bitcount[0] = swap64(context->bitcount[0]);
#endif
if (usedspace > 0) {
/* Begin padding with a 1 bit: */
/* Convert TO host byte order */
int j;
for (j = 0; j < 8; j++) {
- REVERSE32(context->state.st32[j],
- context->state.st32[j]);
- *d++ = context->state.st32[j];
+ *d++ = swap32(context->state.st32[j]);
}
}
#else
usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
#if BYTE_ORDER == LITTLE_ENDIAN
/* Convert FROM host byte order */
- REVERSE64(context->bitcount[0],context->bitcount[0]);
- REVERSE64(context->bitcount[1],context->bitcount[1]);
+ context->bitcount[0] = swap64(context->bitcount[0]);
+ context->bitcount[1] = swap64(context->bitcount[1]);
#endif
if (usedspace > 0) {
/* Begin padding with a 1 bit: */
/* Convert TO host byte order */
int j;
for (j = 0; j < 8; j++) {
- REVERSE64(context->state.st64[j],
- context->state.st64[j]);
- *d++ = context->state.st64[j];
+ *d++ = swap64(context->state.st64[j]);
}
}
#else
/* Convert TO host byte order */
int j;
for (j = 0; j < 6; j++) {
- REVERSE64(context->state.st64[j],
- context->state.st64[j]);
- *d++ = context->state.st64[j];
+ *d++ = swap64(context->state.st64[j]);
}
}
#else