diff options
| author | jsing <> | 2025-02-14 12:01:58 +0000 |
|---|---|---|
| committer | jsing <> | 2025-02-14 12:01:58 +0000 |
| commit | a89810379a758c9cd27af2462547dc646dcfaa61 (patch) | |
| tree | 606af9a8caef4eada19e055b0a35e755d199b0d1 /src/lib/libcrypto/sha | |
| parent | 6e0324f52f75f22301a0c9bbe6f53feb5b6a8628 (diff) | |
| download | openbsd-a89810379a758c9cd27af2462547dc646dcfaa61.tar.gz openbsd-a89810379a758c9cd27af2462547dc646dcfaa61.tar.bz2 openbsd-a89810379a758c9cd27af2462547dc646dcfaa61.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')
| -rw-r--r-- | src/lib/libcrypto/sha/sha1.c | 19 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha256.c | 21 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha512.c | 20 |
3 files changed, 40 insertions, 20 deletions
diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c index 52338812db..ab05709818 100644 --- a/src/lib/libcrypto/sha/sha1.c +++ b/src/lib/libcrypto/sha/sha1.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: sha1.c,v 1.15 2024/06/01 07:36:16 tb Exp $ */ | 1 | /* $OpenBSD: sha1.c,v 1.16 2025/02/14 12:01:58 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -71,11 +71,10 @@ | |||
| 71 | /* Ensure that SHA_LONG and uint32_t are equivalent sizes. */ | 71 | /* Ensure that SHA_LONG and uint32_t are equivalent sizes. */ |
| 72 | CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); | 72 | CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); |
| 73 | 73 | ||
| 74 | #ifdef SHA1_ASM | ||
| 75 | void sha1_block_data_order(SHA_CTX *ctx, const void *p, size_t num); | 74 | void sha1_block_data_order(SHA_CTX *ctx, const void *p, size_t num); |
| 76 | #endif | 75 | void sha1_block_generic(SHA_CTX *ctx, const void *p, size_t num); |
| 77 | 76 | ||
| 78 | #ifndef SHA1_ASM | 77 | #ifndef HAVE_SHA1_BLOCK_GENERIC |
| 79 | static inline SHA_LONG | 78 | static inline SHA_LONG |
| 80 | Ch(SHA_LONG x, SHA_LONG y, SHA_LONG z) | 79 | Ch(SHA_LONG x, SHA_LONG y, SHA_LONG z) |
| 81 | { | 80 | { |
| @@ -164,8 +163,8 @@ sha1_round4(SHA_LONG *a, SHA_LONG *b, SHA_LONG *c, SHA_LONG *d, SHA_LONG *e, | |||
| 164 | *a = T; | 163 | *a = T; |
| 165 | } | 164 | } |
| 166 | 165 | ||
| 167 | static void | 166 | void |
| 168 | sha1_block_data_order(SHA_CTX *ctx, const void *_in, size_t num) | 167 | sha1_block_generic(SHA_CTX *ctx, const void *_in, size_t num) |
| 169 | { | 168 | { |
| 170 | const uint8_t *in = _in; | 169 | const uint8_t *in = _in; |
| 171 | const SHA_LONG *in32; | 170 | const SHA_LONG *in32; |
| @@ -382,6 +381,14 @@ sha1_block_data_order(SHA_CTX *ctx, const void *_in, size_t num) | |||
| 382 | } | 381 | } |
| 383 | #endif | 382 | #endif |
| 384 | 383 | ||
| 384 | #ifndef HAVE_SHA1_BLOCK_DATA_ORDER | ||
| 385 | void | ||
| 386 | sha1_block_data_order(SHA_CTX *ctx, const void *_in, size_t num) | ||
| 387 | { | ||
| 388 | sha1_block_generic(ctx, _in, num); | ||
| 389 | } | ||
| 390 | #endif | ||
| 391 | |||
| 385 | int | 392 | int |
| 386 | SHA1_Init(SHA_CTX *c) | 393 | SHA1_Init(SHA_CTX *c) |
| 387 | { | 394 | { |
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. */ |
| 69 | CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); | 69 | CTASSERT(sizeof(SHA_LONG) == sizeof(uint32_t)); |
| 70 | 70 | ||
| 71 | #ifdef SHA256_ASM | ||
| 72 | void sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num); | 71 | void sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num); |
| 73 | #endif | 72 | void sha256_block_generic(SHA256_CTX *ctx, const void *_in, size_t num); |
| 74 | 73 | ||
| 75 | #ifndef SHA256_ASM | 74 | #ifndef HAVE_SHA256_BLOCK_GENERIC |
| 76 | static const SHA_LONG K256[64] = { | 75 | static 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 | ||
| 158 | static void | 157 | void |
| 159 | sha256_block_data_order(SHA256_CTX *ctx, const void *_in, size_t num) | 158 | sha256_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 | ||
| 282 | void | ||
| 283 | sha256_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 | ||
| 282 | int | 289 | int |
| 283 | SHA224_Init(SHA256_CTX *c) | 290 | SHA224_Init(SHA256_CTX *c) |
diff --git a/src/lib/libcrypto/sha/sha512.c b/src/lib/libcrypto/sha/sha512.c index 7a2a40d3df..43d25eb119 100644 --- a/src/lib/libcrypto/sha/sha512.c +++ b/src/lib/libcrypto/sha/sha512.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: sha512.c,v 1.42 2024/06/01 07:36:16 tb Exp $ */ | 1 | /* $OpenBSD: sha512.c,v 1.43 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 | * |
| @@ -69,11 +69,10 @@ | |||
| 69 | /* Ensure that SHA_LONG64 and uint64_t are equivalent. */ | 69 | /* Ensure that SHA_LONG64 and uint64_t are equivalent. */ |
| 70 | CTASSERT(sizeof(SHA_LONG64) == sizeof(uint64_t)); | 70 | CTASSERT(sizeof(SHA_LONG64) == sizeof(uint64_t)); |
| 71 | 71 | ||
| 72 | #ifdef SHA512_ASM | ||
| 73 | void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num); | 72 | void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num); |
| 74 | #endif | 73 | void sha512_block_generic(SHA512_CTX *ctx, const void *in, size_t num); |
| 75 | 74 | ||
| 76 | #ifndef SHA512_ASM | 75 | #ifndef HAVE_SHA512_BLOCK_GENERIC |
| 77 | static const SHA_LONG64 K512[80] = { | 76 | static const SHA_LONG64 K512[80] = { |
| 78 | U64(0x428a2f98d728ae22), U64(0x7137449123ef65cd), | 77 | U64(0x428a2f98d728ae22), U64(0x7137449123ef65cd), |
| 79 | U64(0xb5c0fbcfec4d3b2f), U64(0xe9b5dba58189dbbc), | 78 | U64(0xb5c0fbcfec4d3b2f), U64(0xe9b5dba58189dbbc), |
| @@ -182,8 +181,8 @@ sha512_round(SHA_LONG64 *a, SHA_LONG64 *b, SHA_LONG64 *c, SHA_LONG64 *d, | |||
| 182 | *a = T1 + T2; | 181 | *a = T1 + T2; |
| 183 | } | 182 | } |
| 184 | 183 | ||
| 185 | static void | 184 | void |
| 186 | sha512_block_data_order(SHA512_CTX *ctx, const void *_in, size_t num) | 185 | sha512_block_generic(SHA512_CTX *ctx, const void *_in, size_t num) |
| 187 | { | 186 | { |
| 188 | const uint8_t *in = _in; | 187 | const uint8_t *in = _in; |
| 189 | const SHA_LONG64 *in64; | 188 | const SHA_LONG64 *in64; |
| @@ -304,8 +303,15 @@ sha512_block_data_order(SHA512_CTX *ctx, const void *_in, size_t num) | |||
| 304 | ctx->h[7] += h; | 303 | ctx->h[7] += h; |
| 305 | } | 304 | } |
| 306 | } | 305 | } |
| 306 | #endif | ||
| 307 | 307 | ||
| 308 | #endif /* SHA512_ASM */ | 308 | #ifndef HAVE_SHA512_BLOCK_DATA_ORDER |
| 309 | void | ||
| 310 | sha512_block_data_order(SHA512_CTX *ctx, const void *_in, size_t num) | ||
| 311 | { | ||
| 312 | sha512_block_generic(ctx, _in, num); | ||
| 313 | } | ||
| 314 | #endif | ||
| 309 | 315 | ||
| 310 | int | 316 | int |
| 311 | SHA384_Init(SHA512_CTX *c) | 317 | SHA384_Init(SHA512_CTX *c) |
