-/* $OpenBSD: sha2.c,v 1.16 2014/12/23 20:40:06 tedu Exp $ */
+/* $OpenBSD: sha2.c,v 1.17 2014/12/31 16:56:55 tedu Exp $ */
/*
* FILE: sha2.c
void
SHA256Final(u_int8_t digest[], SHA2_CTX *context)
{
- u_int32_t *d = (u_int32_t *)digest;
unsigned int usedspace;
usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH;
/* Convert TO host byte order */
int j;
for (j = 0; j < 8; j++) {
- *d++ = swap32(context->state.st32[j]);
+ context->state.st32[j] = swap32(context->state.st32[j]);
}
}
-#else
- memcpy(d, context->state.st32, SHA256_DIGEST_LENGTH);
#endif
+ memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH);
/* Clean up state data: */
explicit_bzero(context, sizeof(*context));
usedspace = 0;
void
SHA512Final(u_int8_t digest[], SHA2_CTX *context)
{
- u_int64_t *d = (u_int64_t *)digest;
SHA512Last(context);
/* Convert TO host byte order */
int j;
for (j = 0; j < 8; j++) {
- *d++ = swap64(context->state.st64[j]);
+ context->state.st64[j] = swap64(context->state.st64[j]);
}
}
-#else
- memcpy(d, context->state.st64, SHA512_DIGEST_LENGTH);
#endif
+ memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH);
/* Zero out state data */
explicit_bzero(context, sizeof(*context));
void
SHA384Final(u_int8_t digest[], SHA2_CTX *context)
{
- u_int64_t *d = (u_int64_t *)digest;
SHA512Last(context);
/* Convert TO host byte order */
int j;
for (j = 0; j < 6; j++) {
- *d++ = swap64(context->state.st64[j]);
+ context->state.st64[j] = swap64(context->state.st64[j]);
}
}
-#else
- memcpy(d, context->state.st64, SHA384_DIGEST_LENGTH);
#endif
+ memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH);
/* Zero out state data */
explicit_bzero(context, sizeof(*context));
}