summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha/sha256.c
diff options
context:
space:
mode:
authorjsing <>2025-02-14 12:01:58 +0000
committerjsing <>2025-02-14 12:01:58 +0000
commit55a1827d4b1706532809a68f02c30336000e01a9 (patch)
tree606af9a8caef4eada19e055b0a35e755d199b0d1 /src/lib/libcrypto/sha/sha256.c
parentaee4d44b17e8fc57dfaadf57efabb128712c9f72 (diff)
downloadopenbsd-55a1827d4b1706532809a68f02c30336000e01a9.tar.gz
openbsd-55a1827d4b1706532809a68f02c30336000e01a9.tar.bz2
openbsd-55a1827d4b1706532809a68f02c30336000e01a9.zip
Replace Makefile based SHA*_ASM defines with HAVE_SHA_* defines.
Currently, SHA{1,256,512}_ASM defines are used to remove the C implementation of sha{1,256,512}_block_data_order() when it is provided by assembly. However, this prevents the C implementation from being used as a fallback. Rename the C sha*_block_data_order() to sha*_block_generic() and provide a sha*_block_data_order() that calls sha*_block_generic(). Replace the Makefile based SHA*_ASM defines with two HAVE_SHA_* defines that allow these functions to be compiled in or removed, such that machine specific verisons can be provided. This should effectively be a no-op on any platform that defined SHA{1,256,512}_ASM. ok tb@
Diffstat (limited to 'src/lib/libcrypto/sha/sha256.c')
-rw-r--r--src/lib/libcrypto/sha/sha256.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/lib/libcrypto/sha/sha256.c b/src/lib/libcrypto/sha/sha256.c
index ab00c17878..5d002ca62c 100644
--- a/src/lib/libcrypto/sha/sha256.c
+++ b/src/lib/libcrypto/sha/sha256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha256.c,v 1.32 2024/06/01 07:36:16 tb Exp $ */ 1/* $OpenBSD: sha256.c,v 1.33 2025/02/14 12:01:58 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -68,11 +68,10 @@
68/* Ensure that SHA_LONG and uint32_t are equivalent. */ 68/* Ensure that SHA_LONG and uint32_t are equivalent. */
69CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); 69CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t));
70 70
71#ifdef SHA256_ASM
72void sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num); 71void sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num);
73#endif 72void sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num);
74 73
75#ifndef SHA256_ASM 74#ifndef HAVE_SHA256_BLOCK_GENERIC
76static const SHA_LONG K256[64] = { 75static const SHA_LONG K256[64] = {
77 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 76 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
78 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 77 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
@@ -155,8 +154,8 @@ sha256_round(SHA_LONG *a, SHA_LONG *b, SHA_LONG *c, SHA_LONG *d, SHA_LONG *e,
155 *a = T1 + T2; 154 *a = T1 + T2;
156} 155}
157 156
158static void 157void
159sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num) 158sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num)
160{ 159{
161 const uint8_t *in = _in; 160 const uint8_t *in = _in;
162 const SHA_LONG *in32; 161 const SHA_LONG *in32;
@@ -277,7 +276,15 @@ sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num)
277 ctx->h[7] += h; 276 ctx->h[7] += h;
278 } 277 }
279} 278}
280#endif /* SHA256_ASM */ 279#endif
280
281#ifndef HAVE_SHA256_BLOCK_DATA_ORDER
282void
283sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num)
284{
285 sha256_block_generic(ctx, _in, num);
286}
287#endif
281 288
282int 289int
283SHA224_Init(SHA256_CTX *c) 290SHA224_Init(SHA256_CTX *c)