diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-12-31 16:56:56 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-12-31 16:56:56 +0000 |
commit | ac0c6a730415544cc27672f678c5f04ecdf71d7a (patch) | |
tree | b96b56aa53216405fc7bb800c8b9c3c3ceeb7526 /sys/crypto | |
parent | 8c9bf706f5d3e6d01b46e53726ceb693d9009d59 (diff) |
recent changes broke alignment requirements on arm.
simplify a bit more, swapping only aligned values and then using memcpy
to fill the digest. fix confirmed by jsg.
ok jsg kettenis millert
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/sha2.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/sys/crypto/sha2.c b/sys/crypto/sha2.c index 56db10c882f..1619919fa3c 100644 --- a/sys/crypto/sha2.c +++ b/sys/crypto/sha2.c @@ -1,4 +1,4 @@ -/* $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 @@ -473,7 +473,6 @@ SHA256Update(SHA2_CTX *context, const void *dataptr, size_t len) 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; @@ -519,12 +518,11 @@ SHA256Final(u_int8_t digest[], SHA2_CTX *context) /* 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; @@ -800,7 +798,6 @@ SHA512Last(SHA2_CTX *context) void SHA512Final(u_int8_t digest[], SHA2_CTX *context) { - u_int64_t *d = (u_int64_t *)digest; SHA512Last(context); @@ -810,12 +807,11 @@ SHA512Final(u_int8_t digest[], SHA2_CTX *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)); @@ -841,7 +837,6 @@ SHA384Update(SHA2_CTX *context, const void *data, size_t len) void SHA384Final(u_int8_t digest[], SHA2_CTX *context) { - u_int64_t *d = (u_int64_t *)digest; SHA512Last(context); @@ -851,12 +846,11 @@ SHA384Final(u_int8_t digest[], SHA2_CTX *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)); } |