-/* $OpenBSD: sha2.c,v 1.16 2014/01/08 04:35:34 deraadt Exp $ */
+/* $OpenBSD: sha2.c,v 1.17 2014/01/08 06:14:57 tedu Exp $ */
/*
* FILE: sha2.c
{
SHA224Pad(context);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != NULL) {
#if BYTE_ORDER == LITTLE_ENDIAN
- int i;
+ int i;
- /* Convert TO host byte order */
- for (i = 0; i < 7; i++)
- BE_32_TO_8(digest + i * 4, context->state.st32[i]);
+ /* Convert TO host byte order */
+ for (i = 0; i < 7; i++)
+ BE_32_TO_8(digest + i * 4, context->state.st32[i]);
#else
- memcpy(digest, context->state.st32, SHA224_DIGEST_LENGTH);
+ memcpy(digest, context->state.st32, SHA224_DIGEST_LENGTH);
#endif
- memset(context, 0, sizeof(*context));
- }
+ memset(context, 0, sizeof(*context));
}
#endif /* !defined(SHA2_SMALL) */
{
SHA256Pad(context);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != NULL) {
#if BYTE_ORDER == LITTLE_ENDIAN
- int i;
+ int i;
- /* Convert TO host byte order */
- for (i = 0; i < 8; i++)
- BE_32_TO_8(digest + i * 4, context->state.st32[i]);
+ /* Convert TO host byte order */
+ for (i = 0; i < 8; i++)
+ BE_32_TO_8(digest + i * 4, context->state.st32[i]);
#else
- memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH);
+ memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH);
#endif
- memset(context, 0, sizeof(*context));
- }
+ memset(context, 0, sizeof(*context));
}
{
SHA512Pad(context);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != NULL) {
#if BYTE_ORDER == LITTLE_ENDIAN
- int i;
+ int i;
- /* Convert TO host byte order */
- for (i = 0; i < 8; i++)
- BE_64_TO_8(digest + i * 8, context->state.st64[i]);
+ /* Convert TO host byte order */
+ for (i = 0; i < 8; i++)
+ BE_64_TO_8(digest + i * 8, context->state.st64[i]);
#else
- memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH);
+ memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH);
#endif
- memset(context, 0, sizeof(*context));
- }
+ memset(context, 0, sizeof(*context));
}
#if !defined(SHA2_SMALL)
{
SHA384Pad(context);
- /* If no digest buffer is passed, we don't bother doing this: */
- if (digest != NULL) {
#if BYTE_ORDER == LITTLE_ENDIAN
- int i;
+ int i;
- /* Convert TO host byte order */
- for (i = 0; i < 6; i++)
- BE_64_TO_8(digest + i * 8, context->state.st64[i]);
+ /* Convert TO host byte order */
+ for (i = 0; i < 6; i++)
+ BE_64_TO_8(digest + i * 8, context->state.st64[i]);
#else
- memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH);
+ memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH);
#endif
- }
-
/* Zero out state data */
memset(context, 0, sizeof(*context));
}