[PATCH v2 0/2] MR11137: bcrypt: Add support for Brainpool curves.
-- v2: bcrypt: Add support for Brainpool curves. bcrypt: Add initial support for CHACHA20_POLY1305. https://gitlab.winehq.org/wine/wine/-/merge_requests/11137
From: Hans Leidekker <hans@codeweavers.com> --- dlls/bcrypt/bcrypt_main.c | 38 ++++++++++++++++++++++++++++++++++++++ dlls/bcrypt/tests/bcrypt.c | 35 +++++++++++++++++++++++++++++++++++ include/bcrypt.h | 7 +++++-- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c index af300614b75..b6e635ff257 100644 --- a/dlls/bcrypt/bcrypt_main.c +++ b/dlls/bcrypt/bcrypt_main.c @@ -52,6 +52,7 @@ enum alg_id { /* cipher */ ALG_ID_3DES, + ALG_ID_CHACHA20_POLY1305, ALG_ID_AES, ALG_ID_RC4, @@ -145,6 +146,7 @@ struct gcm_key }; #define BLOCK_LENGTH_RC4 1 +#define BLOCK_LENGTH_CHACHA20_POLY1305 1 #define BLOCK_LENGTH_3DES 8 #define BLOCK_LENGTH_AES 16 @@ -345,6 +347,7 @@ static const struct builtin_algorithms[] = { { BCRYPT_3DES_ALGORITHM, BCRYPT_CIPHER_INTERFACE, 522, 0, 0 }, + { BCRYPT_CHACHA20_POLY1305_ALGORITHM, BCRYPT_CIPHER_INTERFACE, 166, 0, 0 }, { BCRYPT_AES_ALGORITHM, BCRYPT_CIPHER_INTERFACE, 654, 0, 0 }, { BCRYPT_RC4_ALGORITHM, BCRYPT_CIPHER_INTERFACE, 654, 0, 0 }, { BCRYPT_SHA256_ALGORITHM, BCRYPT_HASH_INTERFACE, 286, 32, 512 }, @@ -490,6 +493,13 @@ static const struct algorithm pseudo_algorithms[] = {{ MAGIC_ALG }, ALG_ID_RSA_SIGN }, {{ 0 }}, /* CAPI_KDF */ {{ MAGIC_ALG }, ALG_ID_PBKDF2 }, + {{ 0 }}, /* SP800108_CTR_HMAC */ + {{ 0 }}, /* SP80056A_CONCAT */ + {{ 0 }}, /* TLS1_1_KDF */ + {{ 0 }}, /* TLS1_2_KDF */ + {{ 0 }}, /* XTS_AES */ + {{ 0 }}, /* HKDF */ + {{ MAGIC_ALG }, ALG_ID_CHACHA20_POLY1305 }, }; /* Algorithm pseudo-handles are denoted by having the lowest bit set. @@ -860,6 +870,20 @@ static NTSTATUS get_pbkdf2_property( enum chain_mode mode, const WCHAR *prop, UC return STATUS_NOT_IMPLEMENTED; } +static NTSTATUS get_chacha20_poly1305_property( const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size ) +{ + if (!wcscmp( prop, BCRYPT_BLOCK_LENGTH )) + { + *ret_size = sizeof(ULONG); + if (size < sizeof(ULONG)) return STATUS_BUFFER_TOO_SMALL; + if (buf) *(ULONG *)buf = BLOCK_LENGTH_CHACHA20_POLY1305; + return STATUS_SUCCESS; + } + + FIXME( "unsupported property %s\n", debugstr_w(prop) ); + return STATUS_NOT_IMPLEMENTED; +} + static NTSTATUS get_alg_property( const struct algorithm *alg, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size ) { @@ -873,6 +897,9 @@ static NTSTATUS get_alg_property( const struct algorithm *alg, const WCHAR *prop case ALG_ID_3DES: return get_3des_property( alg->mode, prop, buf, size, ret_size ); + case ALG_ID_CHACHA20_POLY1305: + return get_chacha20_poly1305_property( prop, buf, size, ret_size ); + case ALG_ID_AES: return get_aes_property( alg->mode, prop, buf, size, ret_size ); @@ -918,6 +945,17 @@ static NTSTATUS set_alg_property( struct algorithm *alg, const WCHAR *prop, UCHA FIXME( "unsupported 3des algorithm property %s\n", debugstr_w(prop) ); return STATUS_NOT_IMPLEMENTED; + case ALG_ID_CHACHA20_POLY1305: + if (!wcscmp( prop, BCRYPT_CHAINING_MODE )) + { + if (!wcscmp( (WCHAR *)value, BCRYPT_CHAIN_MODE_NA )) return STATUS_SUCCESS; + + FIXME( "unsupported mode %s\n", debugstr_w((WCHAR *)value) ); + return STATUS_NOT_IMPLEMENTED; + } + FIXME( "unsupported CHACHA20_POLY1305 algorithm property %s\n", debugstr_w(prop) ); + return STATUS_NOT_IMPLEMENTED; + case ALG_ID_AES: if (!wcscmp( prop, BCRYPT_CHAINING_MODE )) { diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c index b7c7fddbffa..de87293431e 100644 --- a/dlls/bcrypt/tests/bcrypt.c +++ b/dlls/bcrypt/tests/bcrypt.c @@ -4888,6 +4888,40 @@ static void test_PBKDF2(void) ok(status == STATUS_SUCCESS, "got %#lx\n", status); } +static void test_CHACHA20_POLY1305(void) +{ + BCRYPT_ALG_HANDLE alg; + NTSTATUS status; + ULONG len, size; + + status = BCryptOpenAlgorithmProvider(&alg, BCRYPT_CHACHA20_POLY1305_ALGORITHM, NULL, 0); + if (status == STATUS_NOT_FOUND) + { + win_skip("CHACHA20_POLY1305 not supported\n"); + return; + } + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + + len = size = 0; + status = BCryptGetProperty(alg, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + ok(len, "expected non-zero len\n"); + ok(size == sizeof(len), "got %lu\n", size); + + len = size = 0; + status = BCryptGetProperty(alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + ok(len == 1, "got %lu\n", len); + ok(size == sizeof(len), "got %lu\n", size); + + size = sizeof(BCRYPT_CHAIN_MODE_NA); + status = BCryptSetProperty(alg, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_NA, size, 0); + ok(!status, "got %#lx\n", status); + + status = BCryptCloseAlgorithmProvider(alg, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); +} + START_TEST(bcrypt) { HMODULE module; @@ -4928,6 +4962,7 @@ START_TEST(bcrypt) test_rsa_encrypt(); test_RC4(); test_PBKDF2(); + test_CHACHA20_POLY1305(); FreeLibrary(module); } diff --git a/include/bcrypt.h b/include/bcrypt.h index a3441fbf72f..a5d044561e3 100644 --- a/include/bcrypt.h +++ b/include/bcrypt.h @@ -94,6 +94,7 @@ extern "C" { #define BCRYPT_3DES_ALGORITHM L"3DES" #define BCRYPT_AES_ALGORITHM L"AES" +#define BCRYPT_CHACHA20_POLY1305_ALGORITHM L"CHACHA20_POLY1305" #define BCRYPT_DES_ALGORITHM L"DES" #define BCRYPT_DH_ALGORITHM L"DH" #define BCRYPT_DSA_ALGORITHM L"DSA" @@ -108,6 +109,7 @@ extern "C" { #define BCRYPT_MD2_ALGORITHM L"MD2" #define BCRYPT_MD4_ALGORITHM L"MD4" #define BCRYPT_MD5_ALGORITHM L"MD5" +#define BCRYPT_PBKDF2_ALGORITHM L"PBKDF2" #define BCRYPT_RC2_ALGORITHM L"RC2" #define BCRYPT_RC4_ALGORITHM L"RC4" #define BCRYPT_RNG_ALGORITHM L"RNG" @@ -117,7 +119,6 @@ extern "C" { #define BCRYPT_SHA256_ALGORITHM L"SHA256" #define BCRYPT_SHA384_ALGORITHM L"SHA384" #define BCRYPT_SHA512_ALGORITHM L"SHA512" -#define BCRYPT_PBKDF2_ALGORITHM L"PBKDF2" #define BCRYPT_CHAIN_MODE_NA L"ChainingModeN/A" #define BCRYPT_CHAIN_MODE_CBC L"ChainingModeCBC" @@ -188,6 +189,7 @@ static const WCHAR MS_PLATFORM_CRYPTO_PROVIDER[] = \ static const WCHAR BCRYPT_3DES_ALGORITHM[] = {'3','D','E','S',0}; static const WCHAR BCRYPT_AES_ALGORITHM[] = {'A','E','S',0}; +static const WCHAR BCRYPT_CHACHA20_POLY1305_ALGORITHM[] = {'C','H','A','C','H','A','2','0','_','P','O','L','Y','1','3','0','5',0}; static const WCHAR BCRYPT_DES_ALGORITHM[] = {'D','E','S',0}; static const WCHAR BCRYPT_DH_ALGORITHM[] = {'D','H',0}; static const WCHAR BCRYPT_DSA_ALGORITHM[] = {'D','S','A',0}; @@ -202,6 +204,7 @@ static const WCHAR BCRYPT_ECDSA_P521_ALGORITHM[] = {'E','C','D','S','A','_','P', static const WCHAR BCRYPT_MD2_ALGORITHM[] = {'M','D','2',0}; static const WCHAR BCRYPT_MD4_ALGORITHM[] = {'M','D','4',0}; static const WCHAR BCRYPT_MD5_ALGORITHM[] = {'M','D','5',0}; +static const WCHAR BCRYPT_PBKDF2_ALGORITHM[] = {'P','B','K','D','F','2',0}; static const WCHAR BCRYPT_RC2_ALGORITHM[] = {'R','C','2',0}; static const WCHAR BCRYPT_RC4_ALGORITHM[] = {'R','C','4',0}; static const WCHAR BCRYPT_RNG_ALGORITHM[] = {'R','N','G',0}; @@ -211,7 +214,6 @@ static const WCHAR BCRYPT_SHA1_ALGORITHM[] = {'S','H','A','1',0}; static const WCHAR BCRYPT_SHA256_ALGORITHM[] = {'S','H','A','2','5','6',0}; static const WCHAR BCRYPT_SHA384_ALGORITHM[] = {'S','H','A','3','8','4',0}; static const WCHAR BCRYPT_SHA512_ALGORITHM[] = {'S','H','A','5','1','2',0}; -static const WCHAR BCRYPT_PBKDF2_ALGORITHM[] = {'P','B','K','D','F','2',0}; static const WCHAR BCRYPT_CHAIN_MODE_NA[] = {'C','h','a','i','n','i','n','g','M','o','d','e','N','/','A',0}; static const WCHAR BCRYPT_CHAIN_MODE_CBC[] = {'C','h','a','i','n','i','n','g','M','o','d','e','C','B','C',0}; @@ -552,6 +554,7 @@ typedef PVOID BCRYPT_SECRET_HANDLE; #define BCRYPT_TLS1_2_KDF_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000371) #define BCRYPT_XTS_AES_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000381) #define BCRYPT_HKDF_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000391) +#define BCRYPT_CHACHA20_POLY1305_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000003a1) /* Flags for BCryptGenRandom */ #define BCRYPT_RNG_USE_ENTROPY_IN_BUFFER 0x00000001 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11137
From: Hans Leidekker <hans@codeweavers.com> --- dlls/bcrypt/bcrypt_main.c | 142 +++++++++++++++++++++++++++++++++++-- dlls/bcrypt/tests/bcrypt.c | 47 ++++++++++++ include/bcrypt.h | 2 + 3 files changed, 187 insertions(+), 4 deletions(-) diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c index b6e635ff257..3ca369538b2 100644 --- a/dlls/bcrypt/bcrypt_main.c +++ b/dlls/bcrypt/bcrypt_main.c @@ -120,6 +120,8 @@ enum ecc_curve_id { ECC_CURVE_NONE, ECC_CURVE_25519, + ECC_CURVE_BRAINPOOLP256R1, + ECC_CURVE_BRAINPOOLP384R1, ECC_CURVE_P256R1, ECC_CURVE_P384R1, ECC_CURVE_P521R1, @@ -1027,6 +1029,16 @@ static NTSTATUS set_alg_property( struct algorithm *alg, const WCHAR *prop, UCHA alg->curve_id = ECC_CURVE_P521R1; return STATUS_SUCCESS; } + else if (!wcscmp( (WCHAR *)value, BCRYPT_ECC_CURVE_BRAINPOOLP256R1 )) + { + alg->curve_id = ECC_CURVE_BRAINPOOLP256R1; + return STATUS_SUCCESS; + } + else if (!wcscmp( (WCHAR *)value, BCRYPT_ECC_CURVE_BRAINPOOLP384R1 )) + { + alg->curve_id = ECC_CURVE_BRAINPOOLP384R1; + return STATUS_SUCCESS; + } FIXME( "unsupported curve %s\n", debugstr_w((WCHAR *)value) ); return STATUS_NOT_IMPLEMENTED; } @@ -2848,6 +2860,120 @@ static UINT32 get_ecc_import_flags( enum alg_id alg ) return flags; } +static const BYTE brainpoolP256r1[] = +{ + /* version */ + 0x01, 0x00, 0x00, 0x00, + /* type */ + 0x01, 0x00, 0x00, 0x00, + /* algId */ + 0x00, 0x00, 0x00, 0x00, + /* cbFieldLength */ + 0x20, 0x00, 0x00, 0x00, + /* cbSubgroupOrder */ + 0x20, 0x00, 0x00, 0x00, + /* cbCofactor */ + 0x01, 0x00, 0x00, 0x00, + /* cbSeed */ + 0x00, 0x00, 0x00, 0x00, + /* P */ + 0xa9, 0xfb, 0x57, 0xdb, 0xa1, 0xee, 0xa9, 0xbc, + 0x3e, 0x66, 0x0a, 0x90, 0x9d, 0x83, 0x8d, 0x72, + 0x6e, 0x3b, 0xf6, 0x23, 0xd5, 0x26, 0x20, 0x28, + 0x20, 0x13, 0x48, 0x1d, 0x1f, 0x6e, 0x53, 0x77, + /* A */ + 0x7d, 0x5a, 0x09, 0x75, 0xfc, 0x2c, 0x30, 0x57, + 0xee, 0xf6, 0x75, 0x30, 0x41, 0x7a, 0xff, 0xe7, + 0xfb, 0x80, 0x55, 0xc1, 0x26, 0xdc, 0x5c, 0x6c, + 0xe9, 0x4a, 0x4b, 0x44, 0xf3, 0x30, 0xb5, 0xd9, + /* B */ + 0x26, 0xdc, 0x5c, 0x6c, 0xe9, 0x4a, 0x4b, 0x44, + 0xf3, 0x30, 0xb5, 0xd9, 0xbb, 0xd7, 0x7c, 0xbf, + 0x95, 0x84, 0x16, 0x29, 0x5c, 0xf7, 0xe1, 0xce, + 0x6b, 0xcc, 0xdc, 0x18, 0xff, 0x8c, 0x07, 0xb6, + /* Gx */ + 0x8b, 0xd2, 0xae, 0xb9, 0xcb, 0x7e, 0x57, 0xcb, + 0x2c, 0x4b, 0x48, 0x2f, 0xfc, 0x81, 0xb7, 0xaf, + 0xb9, 0xde, 0x27, 0xe1, 0xe3, 0xbd, 0x23, 0xc2, + 0x3a, 0x44, 0x53, 0xbd, 0x9a, 0xce, 0x32, 0x62, + /* Gy */ + 0x54, 0x7e, 0xf8, 0x35, 0xc3, 0xda, 0xc4, 0xfd, + 0x97, 0xf8, 0x46, 0x1a, 0x14, 0x61, 0x1d, 0xc9, + 0xc2, 0x77, 0x45, 0x13, 0x2d, 0xed, 0x8e, 0x54, + 0x5c, 0x1d, 0x54, 0xc7, 0x2f, 0x04, 0x69, 0x97, + /* n */ + 0xa9, 0xfb, 0x57, 0xdb, 0xa1, 0xee, 0xa9, 0xbc, + 0x3e, 0x66, 0x0a, 0x90, 0x9d, 0x83, 0x8d, 0x71, + 0x8c, 0x39, 0x7a, 0xa3, 0xb5, 0x61, 0xa6, 0xf7, + 0x90, 0x1e, 0x0e, 0x82, 0x97, 0x48, 0x56, 0xa7, + /* h */ + 0x01 +}; +const SYMCRYPT_ECURVE_PARAMS *SymCryptEcurveParamsBrainpoolP256r1 = (const SYMCRYPT_ECURVE_PARAMS *)brainpoolP256r1; + +static const BYTE brainpoolP384r1[] = +{ + /* version */ + 0x01, 0x00, 0x00, 0x00, + /* type */ + 0x01, 0x00, 0x00, 0x00, + /* algId */ + 0x00, 0x00, 0x00, 0x00, + /* cbFieldLength */ + 0x30, 0x00, 0x00, 0x00, + /* cbSubgroupOrder */ + 0x30, 0x00, 0x00, 0x00, + /* cbCofactor */ + 0x01, 0x00, 0x00, 0x00, + /* cbSeed */ + 0x00, 0x00, 0x00, 0x00, + /* P */ + 0x8c, 0xb9, 0x1e, 0x82, 0xa3, 0x38, 0x6d, 0x28, + 0x0f, 0x5d, 0x6f, 0x7e, 0x50, 0xe6, 0x41, 0xdf, + 0x15, 0x2f, 0x71, 0x09, 0xed, 0x54, 0x56, 0xb4, + 0x12, 0xb1, 0xda, 0x19, 0x7f, 0xb7, 0x11, 0x23, + 0xac, 0xd3, 0xa7, 0x29, 0x90, 0x1d, 0x1a, 0x71, + 0x87, 0x47, 0x00, 0x13, 0x31, 0x07, 0xec, 0x53, + /* A */ + 0x7b, 0xc3, 0x82, 0xc6, 0x3d, 0x8c, 0x15, 0x0c, + 0x3c, 0x72, 0x08, 0x0a, 0xce, 0x05, 0xaf, 0xa0, + 0xc2, 0xbe, 0xa2, 0x8e, 0x4f, 0xb2, 0x27, 0x87, + 0x13, 0x91, 0x65, 0xef, 0xba, 0x91, 0xf9, 0x0f, + 0x8a, 0xa5, 0x81, 0x4a, 0x50, 0x3a, 0xd4, 0xeb, + 0x04, 0xa8, 0xc7, 0xdd, 0x22, 0xce, 0x28, 0x26, + /* B */ + 0x04, 0xa8, 0xc7, 0xdd, 0x22, 0xce, 0x28, 0x26, + 0x8b, 0x39, 0xb5, 0x54, 0x16, 0xf0, 0x44, 0x7c, + 0x2f, 0xb7, 0x7d, 0xe1, 0x07, 0xdc, 0xd2, 0xa6, + 0x2e, 0x88, 0x0e, 0xa5, 0x3e, 0xeb, 0x62, 0xd5, + 0x7c, 0xb4, 0x39, 0x02, 0x95, 0xdb, 0xc9, 0x94, + 0x3a, 0xb7, 0x86, 0x96, 0xfa, 0x50, 0x4c, 0x11, + /* Gx */ + 0x1d, 0x1c, 0x64, 0xf0, 0x68, 0xcf, 0x45, 0xff, + 0xa2, 0xa6, 0x3a, 0x81, 0xb7, 0xc1, 0x3f, 0x6b, + 0x88, 0x47, 0xa3, 0xe7, 0x7e, 0xf1, 0x4f, 0xe3, + 0xdb, 0x7f, 0xca, 0xfe, 0x0c, 0xbd, 0x10, 0xe8, + 0xe8, 0x26, 0xe0, 0x34, 0x36, 0xd6, 0x46, 0xaa, + 0xef, 0x87, 0xb2, 0xe2, 0x47, 0xd4, 0xaf, 0x1e, + /* Gy */ + 0x8a, 0xbe, 0x1d, 0x75, 0x20, 0xf9, 0xc2, 0xa4, + 0x5c, 0xb1, 0xeb, 0x8e, 0x95, 0xcf, 0xd5, 0x52, + 0x62, 0xb7, 0x0b, 0x29, 0xfe, 0xec, 0x58, 0x64, + 0xe1, 0x9c, 0x05, 0x4f, 0xf9, 0x91, 0x29, 0x28, + 0x0e, 0x46, 0x46, 0x21, 0x77, 0x91, 0x81, 0x11, + 0x42, 0x82, 0x03, 0x41, 0x26, 0x3c, 0x53, 0x15, + /* n */ + 0x8c, 0xb9, 0x1e, 0x82, 0xa3, 0x38, 0x6d, 0x28, + 0x0f, 0x5d, 0x6f, 0x7e, 0x50, 0xe6, 0x41, 0xdf, + 0x15, 0x2f, 0x71, 0x09, 0xed, 0x54, 0x56, 0xb3, + 0x1f, 0x16, 0x6e, 0x6c, 0xac, 0x04, 0x25, 0xa7, + 0xcf, 0x3a, 0xb6, 0xaf, 0x6b, 0x7f, 0xc3, 0x10, + 0x3b, 0x88, 0x32, 0x02, 0xe9, 0x04, 0x65, 0x65, + /* h */ + 0x01 +}; +const SYMCRYPT_ECURVE_PARAMS *SymCryptEcurveParamsBrainpoolP384r1 = (const SYMCRYPT_ECURVE_PARAMS *)brainpoolP384r1; + static SYMCRYPT_ECURVE *alloc_ecc_curve( enum ecc_curve_id curve_id ) { const SYMCRYPT_ECURVE_PARAMS *params; @@ -2857,6 +2983,12 @@ static SYMCRYPT_ECURVE *alloc_ecc_curve( enum ecc_curve_id curve_id ) case ECC_CURVE_25519: params = SymCryptEcurveParamsCurve25519; break; + case ECC_CURVE_BRAINPOOLP256R1: + params = SymCryptEcurveParamsBrainpoolP256r1; + break; + case ECC_CURVE_BRAINPOOLP384R1: + params = SymCryptEcurveParamsBrainpoolP384r1; + break; case ECC_CURVE_P256R1: params = SymCryptEcurveParamsNistP256; break; @@ -2877,10 +3009,12 @@ static ULONG curve_strength( enum ecc_curve_id curve_id ) { switch (curve_id) { - case ECC_CURVE_25519: return 253; - case ECC_CURVE_P256R1: return 256; - case ECC_CURVE_P384R1: return 384; - case ECC_CURVE_P521R1: return 521; + case ECC_CURVE_25519: return 253; + case ECC_CURVE_BRAINPOOLP256R1: + case ECC_CURVE_P256R1: return 256; + case ECC_CURVE_BRAINPOOLP384R1: + case ECC_CURVE_P384R1: return 384; + case ECC_CURVE_P521R1: return 521; default: FIXME( "unsupported curve %u\n", curve_id ); return 0; diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c index de87293431e..e7905f32145 100644 --- a/dlls/bcrypt/tests/bcrypt.c +++ b/dlls/bcrypt/tests/bcrypt.c @@ -2256,6 +2256,9 @@ static BYTE cert521Signature[] = static void test_ECDSA(void) { + static UCHAR hash[] = + {0x7e, 0xe3, 0x74, 0xe7, 0xc5, 0x0b, 0x6b, 0x70, 0xdb, 0xab, 0x32, 0x6d, 0x1d, 0x51, 0xd6, + 0x74, 0x79, 0x8e, 0x5b, 0x4b}; BYTE buffer[sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(ecc521Privkey)]; BCRYPT_ECCKEY_BLOB *ecckey = (void *)buffer; BCRYPT_ALG_HANDLE alg; @@ -2263,6 +2266,7 @@ static void test_ECDSA(void) NTSTATUS status; DWORD keylen; ULONG size, strength; + UCHAR sig[64]; status = BCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDSA_P256_ALGORITHM, NULL, 0); ok(!status, "got %#lx\n", status); @@ -2463,6 +2467,35 @@ static void test_ECDSA(void) status = BCryptSetProperty(alg, BCRYPT_ECC_CURVE_NAME, (UCHAR *)BCRYPT_ECC_CURVE_25519, sizeof(BCRYPT_ECC_CURVE_25519), 0); ok(status == STATUS_NOT_SUPPORTED, "got %#lx\n", status); BCryptCloseAlgorithmProvider(alg, 0); + + /* Brainpool curve */ + status = BCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDSA_ALGORITHM, NULL, 0); + ok(!status, "got %#lx\n", status); + + status = BCryptSetProperty(alg, BCRYPT_ECC_CURVE_NAME, (UCHAR *)BCRYPT_ECC_CURVE_BRAINPOOLP256R1, + sizeof(BCRYPT_ECC_CURVE_BRAINPOOLP256R1), 0 ); + ok(!status, "got %#lx\n", status); + + status = BCryptGenerateKeyPair(alg, &key, 256, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + + strength = 0; + status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&strength, sizeof(strength), &size, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + ok(strength == 256, "got %lu\n", strength); + + status = BCryptFinalizeKeyPair(key, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + + size = 0; + status = BCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &size, 0); + ok (status == STATUS_SUCCESS, "got %#lx\n", status); + ok (size == 64, "got %lu\n", size); + + status = BCryptVerifySignature(key, NULL, hash, sizeof(hash), sig, size, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + BCryptDestroyKey(key); + BCryptCloseAlgorithmProvider(alg, 0); } static UCHAR rsaPublicBlob[] = @@ -3599,6 +3632,20 @@ static void test_ECDH(void) BCryptDestroyKey(key2); BCryptDestroyKey(key); BCryptCloseAlgorithmProvider(alg, 0); + + /* Brainpool curve */ + status = BCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDH_ALGORITHM, NULL, 0); + ok(!status, "got %#lx\n", status); + + status = BCryptSetProperty(alg, BCRYPT_ECC_CURVE_NAME, (UCHAR *)BCRYPT_ECC_CURVE_BRAINPOOLP256R1, + sizeof(BCRYPT_ECC_CURVE_BRAINPOOLP256R1), 0 ); + ok(!status, "got %#lx\n", status); + + status = BCryptGenerateKeyPair(alg, &key, 256, 0); + ok(status == STATUS_SUCCESS, "got %#lx\n", status); + + BCryptDestroyKey(key); + BCryptCloseAlgorithmProvider(alg, 0); } static BYTE dh_pubkey[] = diff --git a/include/bcrypt.h b/include/bcrypt.h index a5d044561e3..fe361307b6c 100644 --- a/include/bcrypt.h +++ b/include/bcrypt.h @@ -130,6 +130,7 @@ extern "C" { #define BCRYPT_ECC_CURVE_NAME L"ECCCurveName" #define BCRYPT_ECC_CURVE_25519 L"curve25519" #define BCRYPT_ECC_CURVE_BRAINPOOLP256R1 L"brainpoolP256r1" +#define BCRYPT_ECC_CURVE_BRAINPOOLP384R1 L"brainpoolP384r1" #define BCRYPT_ECC_CURVE_SECP256R1 L"secP256r1" #define BCRYPT_ECC_CURVE_SECP384R1 L"secP384r1" #define BCRYPT_ECC_CURVE_SECP521R1 L"secP521r1" @@ -225,6 +226,7 @@ static const WCHAR BCRYPT_CHAIN_MODE_GCM[] = {'C','h','a','i','n','i','n','g','M static const WCHAR BCRYPT_ECC_CURVE_NAME[] = {'E','C','C','C','u','r','v','e','N','a','m','e',0}; static const WCHAR BCRYPT_ECC_CURVE_25519[] = {'c','u','r','v','e','2','5','5','1','9',0}; static const WCHAR BCRYPT_ECC_CURVE_BRAINPOOLP256R1[] = {'b','r','a','i','n','p','o','o','l','P','2','5','6','r','1',0}; +static const WCHAR BCRYPT_ECC_CURVE_BRAINPOOLP384R1[] = {'b','r','a','i','n','p','o','o','l','P','3','8','4','r','1',0}; static const WCHAR BCRYPT_ECC_CURVE_SECP256R1[] = {'s','e','c','P','2','5','6','r','1',0}; static const WCHAR BCRYPT_ECC_CURVE_SECP384R1[] = {'s','e','c','P','3','8','4','r','1',0}; static const WCHAR BCRYPT_ECC_CURVE_SECP521R1[] = {'s','e','c','P','5','2','1','r','1',0}; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11137
v2: Fix some test failures on old Windows. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/11137#note_142950
participants (2)
-
Hans Leidekker -
Hans Leidekker (@hans)