diff options
| author | Ron Yorston <rmy@pobox.com> | 2025-08-12 11:59:30 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2025-08-12 11:59:30 +0100 |
| commit | aed19625ff874bb2fc95480a6f684a9acc1bf2c9 (patch) | |
| tree | df216d2ebb6aefba5928336b2bdd66b82d14b29a /include | |
| parent | 4e6b0b3e8b8f819bc9e2f69b0c267abecfe30968 (diff) | |
| download | busybox-w32-aed19625ff874bb2fc95480a6f684a9acc1bf2c9.tar.gz busybox-w32-aed19625ff874bb2fc95480a6f684a9acc1bf2c9.tar.bz2 busybox-w32-aed19625ff874bb2fc95480a6f684a9acc1bf2c9.zip | |
Post-merge fixes
Upstream has moved some functions from networking/tls.c to a new
file, libbb/hash_hmac.c. The merge didn't adjust this code to
allow it to work with the native Windows checksum API.
This only matters if FEATURE_USE_CNG_API is enabled and
CONFIG_FEATURE_TLS_SCHANNEL isn't. In that case the wget applet
fails to handle https. None of the default configurations
has this combination, but it should work. Make it so.
The Windows code doesn't implement hmac_block(), as that's only
used for password encryption which isn't currently supported.
The variadic function hmac_peek_hash() isn't declared FAST_FUNC,
as that causes clang to issue many warnings.
Diffstat (limited to 'include')
| -rw-r--r-- | include/libbb.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/include/libbb.h b/include/libbb.h index 7a375f4d2..8dc4e4992 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -281,12 +281,26 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | |||
| 281 | # endif | 281 | # endif |
| 282 | #endif | 282 | #endif |
| 283 | 283 | ||
| 284 | #if ENABLE_FEATURE_TLS_SCHANNEL | 284 | #if ENABLE_FEATURE_TLS_SCHANNEL || ENABLE_FEATURE_USE_CNG_API |
| 285 | # define SECURITY_WIN32 | 285 | # define SECURITY_WIN32 |
| 286 | # include <windows.h> | 286 | # include <windows.h> |
| 287 | # include <security.h> | 287 | # include <security.h> |
| 288 | #endif | 288 | #endif |
| 289 | 289 | ||
| 290 | #if ENABLE_FEATURE_USE_CNG_API | ||
| 291 | # include <bcrypt.h> | ||
| 292 | |||
| 293 | // these work on Windows >= 10 | ||
| 294 | # define BCRYPT_HMAC_SHA1_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000a1) | ||
| 295 | # define BCRYPT_HMAC_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000b1) | ||
| 296 | # define sha1_begin_hmac BCRYPT_HMAC_SHA1_ALG_HANDLE | ||
| 297 | # define sha256_begin_hmac BCRYPT_HMAC_SHA256_ALG_HANDLE | ||
| 298 | #else | ||
| 299 | # define sha1_begin_hmac sha1_begin | ||
| 300 | # define sha256_begin_hmac sha256_begin | ||
| 301 | # define hmac_uninit(...) ((void)0) | ||
| 302 | #endif | ||
| 303 | |||
| 290 | /* Tested to work correctly with all int types (IIRC :]) */ | 304 | /* Tested to work correctly with all int types (IIRC :]) */ |
| 291 | #define MAXINT(T) (T)( \ | 305 | #define MAXINT(T) (T)( \ |
| 292 | ((T)-1) > 0 \ | 306 | ((T)-1) > 0 \ |
| @@ -2444,12 +2458,17 @@ typedef struct md5_ctx_t md5sha_ctx_t; | |||
| 2444 | #endif | 2458 | #endif |
| 2445 | 2459 | ||
| 2446 | /* RFC 2104 HMAC (hash-based message authentication code) */ | 2460 | /* RFC 2104 HMAC (hash-based message authentication code) */ |
| 2461 | #if !ENABLE_FEATURE_USE_CNG_API | ||
| 2447 | typedef struct hmac_ctx { | 2462 | typedef struct hmac_ctx { |
| 2448 | md5sha_ctx_t hashed_key_xor_ipad; | 2463 | md5sha_ctx_t hashed_key_xor_ipad; |
| 2449 | md5sha_ctx_t hashed_key_xor_opad; | 2464 | md5sha_ctx_t hashed_key_xor_opad; |
| 2450 | } hmac_ctx_t; | 2465 | } hmac_ctx_t; |
| 2466 | #else | ||
| 2467 | typedef struct bcrypt_hash_ctx_t hmac_ctx_t; | ||
| 2468 | #endif | ||
| 2451 | #define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1) | 2469 | #define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1) |
| 2452 | typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; | 2470 | typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; |
| 2471 | #if !ENABLE_FEATURE_USE_CNG_API | ||
| 2453 | #if HMAC_ONLY_SHA256 | 2472 | #if HMAC_ONLY_SHA256 |
| 2454 | #define hmac_begin(ctx,key,key_size,begin) \ | 2473 | #define hmac_begin(ctx,key,key_size,begin) \ |
| 2455 | hmac_begin(ctx,key,key_size) | 2474 | hmac_begin(ctx,key,key_size) |
| @@ -2459,6 +2478,17 @@ static ALWAYS_INLINE void hmac_hash(hmac_ctx_t *ctx, const void *in, size_t len) | |||
| 2459 | { | 2478 | { |
| 2460 | md5sha_hash(&ctx->hashed_key_xor_ipad, in, len); | 2479 | md5sha_hash(&ctx->hashed_key_xor_ipad, in, len); |
| 2461 | } | 2480 | } |
| 2481 | #else | ||
| 2482 | # if HMAC_ONLY_SHA256 | ||
| 2483 | # define hmac_begin(pre,key,key_size,begin) \ | ||
| 2484 | _hmac_begin(pre, key, key_size, sha256_begin_hmac) | ||
| 2485 | # else | ||
| 2486 | # define hmac_begin _hmac_begin | ||
| 2487 | # endif | ||
| 2488 | void _hmac_begin(hmac_ctx_t *pre, uint8_t *key, unsigned key_size, | ||
| 2489 | BCRYPT_ALG_HANDLE alg_handle); | ||
| 2490 | void hmac_uninit(hmac_ctx_t *pre); | ||
| 2491 | #endif | ||
| 2462 | unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out); | 2492 | unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out); |
| 2463 | #if HMAC_ONLY_SHA256 | 2493 | #if HMAC_ONLY_SHA256 |
| 2464 | #define hmac_block(key,key_size,begin,in,sz,out) \ | 2494 | #define hmac_block(key,key_size,begin,in,sz,out) \ |
| @@ -2470,7 +2500,7 @@ unsigned FAST_FUNC hmac_block(const uint8_t *key, unsigned key_size, | |||
| 2470 | uint8_t *out); | 2500 | uint8_t *out); |
| 2471 | /* HMAC helpers for TLS: */ | 2501 | /* HMAC helpers for TLS: */ |
| 2472 | void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va); | 2502 | void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va); |
| 2473 | unsigned FAST_FUNC hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...); | 2503 | unsigned hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...); |
| 2474 | 2504 | ||
| 2475 | extern uint32_t *global_crc32_table; | 2505 | extern uint32_t *global_crc32_table; |
| 2476 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 2506 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |
