bcrypt: Add support for importing and exporting ECC public keys.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
73b695f059
commit
5c2ac77ab7
|
@ -813,6 +813,14 @@ static NTSTATUS key_export( struct key *key, const WCHAR *type, UCHAR *output, U
|
|||
memcpy( output + sizeof(len), key->u.s.secret, key->u.s.secret_len );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
else if (!strcmpW( type, BCRYPT_ECCPUBLIC_BLOB ))
|
||||
{
|
||||
*size = key->u.a.pubkey_len;
|
||||
if (output_len < key->u.a.pubkey_len) return STATUS_SUCCESS;
|
||||
|
||||
memcpy( output, key->u.a.pubkey, key->u.a.pubkey_len );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
FIXME( "unsupported key type %s\n", debugstr_w(type) );
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
|
@ -1012,6 +1020,11 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
|
|||
|
||||
switch (alg->id)
|
||||
{
|
||||
case ALG_ID_ECDH_P256:
|
||||
key_size = 32;
|
||||
magic = BCRYPT_ECDH_PUBLIC_P256_MAGIC;
|
||||
break;
|
||||
|
||||
case ALG_ID_ECDSA_P256:
|
||||
key_size = 32;
|
||||
magic = BCRYPT_ECDSA_PUBLIC_P256_MAGIC;
|
||||
|
@ -1028,7 +1041,8 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
|
|||
}
|
||||
|
||||
if (ecc_blob->dwMagic != magic) return STATUS_NOT_SUPPORTED;
|
||||
if (ecc_blob->cbKey != key_size) return STATUS_INVALID_PARAMETER;
|
||||
if (ecc_blob->cbKey != key_size || input_len < sizeof(*ecc_blob) + ecc_blob->cbKey * 2)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
if (!(key = heap_alloc_zero( sizeof(*key) ))) return STATUS_NO_MEMORY;
|
||||
key->hdr.magic = MAGIC_KEY;
|
||||
|
|
|
@ -1659,9 +1659,12 @@ static void test_RSA(void)
|
|||
|
||||
static void test_ECDH(void)
|
||||
{
|
||||
BYTE *buf;
|
||||
BCRYPT_ECCKEY_BLOB *ecckey;
|
||||
BCRYPT_ALG_HANDLE alg;
|
||||
BCRYPT_KEY_HANDLE key;
|
||||
NTSTATUS status;
|
||||
ULONG size;
|
||||
|
||||
status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDH_P256_ALGORITHM, NULL, 0);
|
||||
if (status)
|
||||
|
@ -1678,6 +1681,25 @@ static void test_ECDH(void)
|
|||
status = pBCryptFinalizeKeyPair(key, 0);
|
||||
ok(status == STATUS_SUCCESS, "got %08x\n", status);
|
||||
|
||||
size = 0;
|
||||
SetLastError(0xdeadbeef);
|
||||
status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, NULL, 0, &size, 0);
|
||||
ok(status == STATUS_SUCCESS, "got %08x\n", status);
|
||||
ok(size, "size not set\n");
|
||||
|
||||
buf = HeapAlloc(GetProcessHeap(), 0, size);
|
||||
status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buf, size, &size, 0);
|
||||
ok(status == STATUS_SUCCESS, "got %08x\n", status);
|
||||
ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
|
||||
ok(ecckey->dwMagic == BCRYPT_ECDH_PUBLIC_P256_MAGIC, "got %08x\n", ecckey->dwMagic);
|
||||
ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey);
|
||||
ok(size == sizeof(*ecckey) + ecckey->cbKey * 2, "got %u\n", size);
|
||||
pBCryptDestroyKey(key);
|
||||
|
||||
status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buf, size, 0);
|
||||
ok(status == STATUS_SUCCESS, "got %08x\n", status);
|
||||
HeapFree(GetProcessHeap(), 0, buf);
|
||||
|
||||
pBCryptDestroyKey(key);
|
||||
pBCryptCloseAlgorithmProvider(alg, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue