From: Charalampos Mitrodimas Date: Thu, 26 Jan 2023 13:01:42 +0000 (+0100) Subject: crypto: sha256: Add mechanism to keep C code as fallback for SHA256_ASM X-Git-Tag: openssl-3.3.0-alpha1~756 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=204a1c9854193bd7fcc3ea1baaf685c9a67d17bb;p=thirdparty%2Fopenssl.git crypto: sha256: Add mechanism to keep C code as fallback for SHA256_ASM Currently, architectures have to decide if they want the C code or an arch-specific implementation. Let's add a macro, that allows to keep the C code even if SHA256_ASM is defined (but rename it from sha256_block_data_order to sha256_block_data_order_c). The macro INCLUDE_C_SHA256 can be used by architectures, that want the C code as fallback code. Signed-off-by: Charalampos Mitrodimas Signed-off-by: Christoph Müllner Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale Reviewed-by: Hugo Landau (Merged from https://github.com/openssl/openssl/pull/21923) --- diff --git a/crypto/sha/sha256.c b/crypto/sha/sha256.c index 4017137c270..6ef218e86e3 100644 --- a/crypto/sha/sha256.c +++ b/crypto/sha/sha256.c @@ -116,12 +116,16 @@ int SHA224_Final(unsigned char *md, SHA256_CTX *c) #define HASH_BLOCK_DATA_ORDER sha256_block_data_order #ifndef SHA256_ASM static -#endif +#else +# ifdef INCLUDE_C_SHA256 +void sha256_block_data_order_c(SHA256_CTX *ctx, const void *in, size_t num); +# endif /* INCLUDE_C_SHA256 */ +#endif /* SHA256_ASM */ void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num); #include "crypto/md32_common.h" -#ifndef SHA256_ASM +#if !defined(SHA256_ASM) || defined(INCLUDE_C_SHA256) static const SHA_LONG K256[64] = { 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, @@ -279,8 +283,12 @@ static void sha256_block_data_order(SHA256_CTX *ctx, const void *in, T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \ ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0) +#ifdef INCLUDE_C_SHA256 +void sha256_block_data_order_c(SHA256_CTX *ctx, const void *in, size_t num) +#else static void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num) +#endif { unsigned MD32_REG_T a, b, c, d, e, f, g, h, s0, s1, T1; SHA_LONG X[16];