aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h34
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
2447typedef struct hmac_ctx { 2462typedef 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
2467typedef 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)
2452typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; 2470typedef 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
2488void _hmac_begin(hmac_ctx_t *pre, uint8_t *key, unsigned key_size,
2489 BCRYPT_ALG_HANDLE alg_handle);
2490void hmac_uninit(hmac_ctx_t *pre);
2491#endif
2462unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out); 2492unsigned 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: */
2472void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va); 2502void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va);
2473unsigned FAST_FUNC hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...); 2503unsigned hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...);
2474 2504
2475extern uint32_t *global_crc32_table; 2505extern uint32_t *global_crc32_table;
2476uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; 2506uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;