From 55a1827d4b1706532809a68f02c30336000e01a9 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 14 Feb 2025 12:01:58 +0000 Subject: 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@ --- src/lib/libcrypto/sha/sha256.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/lib/libcrypto/sha/sha256.c') 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 @@ -/* $OpenBSD: sha256.c,v 1.32 2024/06/01 07:36:16 tb Exp $ */ +/* $OpenBSD: sha256.c,v 1.33 2025/02/14 12:01:58 jsing Exp $ */ /* ==================================================================== * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. * @@ -68,11 +68,10 @@ /* Ensure that SHA_LONG and uint32_t are equivalent. */ CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); -#ifdef SHA256_ASM void sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num); -#endif +void sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num); -#ifndef SHA256_ASM +#ifndef HAVE_SHA256_BLOCK_GENERIC static const SHA_LONG K256[64] = { 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 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, *a = T1 + T2; } -static void -sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num) +void +sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num) { const uint8_t *in = _in; const SHA_LONG *in32; @@ -277,7 +276,15 @@ sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num) ctx->h[7] += h; } } -#endif /* SHA256_ASM */ +#endif + +#ifndef HAVE_SHA256_BLOCK_DATA_ORDER +void +sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num) +{ + sha256_block_generic(ctx, _in, num); +} +#endif int SHA224_Init(SHA256_CTX *c) -- cgit v1.2.3-55-g6feb