summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-04-11 13:03:04 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-04-11 13:03:04 +0000
commit08f590e8bc19419db5a687cea51158da20f927a9 (patch)
treea76cd9889139a1cd9e8e7fd417bb559be010d499 /lib
parent82ada6c0937d5597611f4f4652754a1c5e662072 (diff)
Back out r1.27 using htobe64() - apparently some OS don't have it.
ok jsing
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/sha/sha512.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/libcrypto/sha/sha512.c b/lib/libcrypto/sha/sha512.c
index 8c78f826c8e..d923a8e2afb 100644
--- a/lib/libcrypto/sha/sha512.c
+++ b/lib/libcrypto/sha/sha512.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sha512.c,v 1.28 2023/04/11 10:35:21 jsing Exp $ */
+/* $OpenBSD: sha512.c,v 1.29 2023/04/11 13:03:03 tb Exp $ */
/* ====================================================================
* Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
*
@@ -546,9 +546,28 @@ SHA512_Final(unsigned char *md, SHA512_CTX *c)
sha512_block_data_order(c, p, 1);
}
- memset(p + n, 0, sizeof(c->u) - 16 - n);
- c->u.d[SHA_LBLOCK - 2] = htobe64(c->Nh);
- c->u.d[SHA_LBLOCK - 1] = htobe64(c->Nl);
+ memset (p + n, 0, sizeof(c->u) - 16 - n);
+#if BYTE_ORDER == BIG_ENDIAN
+ c->u.d[SHA_LBLOCK - 2] = c->Nh;
+ c->u.d[SHA_LBLOCK - 1] = c->Nl;
+#else
+ p[sizeof(c->u) - 1] = (unsigned char)(c->Nl);
+ p[sizeof(c->u) - 2] = (unsigned char)(c->Nl >> 8);
+ p[sizeof(c->u) - 3] = (unsigned char)(c->Nl >> 16);
+ p[sizeof(c->u) - 4] = (unsigned char)(c->Nl >> 24);
+ p[sizeof(c->u) - 5] = (unsigned char)(c->Nl >> 32);
+ p[sizeof(c->u) - 6] = (unsigned char)(c->Nl >> 40);
+ p[sizeof(c->u) - 7] = (unsigned char)(c->Nl >> 48);
+ p[sizeof(c->u) - 8] = (unsigned char)(c->Nl >> 56);
+ p[sizeof(c->u) - 9] = (unsigned char)(c->Nh);
+ p[sizeof(c->u) - 10] = (unsigned char)(c->Nh >> 8);
+ p[sizeof(c->u) - 11] = (unsigned char)(c->Nh >> 16);
+ p[sizeof(c->u) - 12] = (unsigned char)(c->Nh >> 24);
+ p[sizeof(c->u) - 13] = (unsigned char)(c->Nh >> 32);
+ p[sizeof(c->u) - 14] = (unsigned char)(c->Nh >> 40);
+ p[sizeof(c->u) - 15] = (unsigned char)(c->Nh >> 48);
+ p[sizeof(c->u) - 16] = (unsigned char)(c->Nh >> 56);
+#endif
sha512_block_data_order(c, p, 1);