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