Commit 65b90ab3 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

bcrypt: Add BCRYPT_KEY_STRENGTH key property implementation.

parent a632ac55
......@@ -122,7 +122,7 @@ builtin_algorithms[] =
{ BCRYPT_RNG_ALGORITHM, BCRYPT_RNG_INTERFACE, 0, 0, 0 },
};
static inline BOOL is_symmetric_key( struct key *key )
static inline BOOL is_symmetric_key( const struct key *key )
{
return builtin_algorithms[key->alg_id].class == BCRYPT_CIPHER_INTERFACE;
}
......@@ -902,6 +902,18 @@ static NTSTATUS get_hash_property( const struct hash *hash, const WCHAR *prop, U
static NTSTATUS get_key_property( const struct key *key, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size )
{
if (!wcscmp( prop, BCRYPT_KEY_STRENGTH ))
{
*ret_size = sizeof(DWORD);
if (size < sizeof(DWORD)) return STATUS_BUFFER_TOO_SMALL;
if (buf)
{
if (is_symmetric_key(key)) *(DWORD *)buf = key->u.s.block_size * 8;
else *(DWORD *)buf = key->u.a.bitlen;
}
return STATUS_SUCCESS;
}
switch (key->alg_id)
{
case ALG_ID_3DES:
......
......@@ -781,6 +781,12 @@ static void test_BCryptGenerateSymmetricKey(void)
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
ok(key != NULL, "key not set\n");
keylen = 0;
ret = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
ok(!ret, "got %#lx\n", ret);
ok(size == sizeof(keylen), "got %lu\n", size);
ok(keylen == 128, "got %lu\n", keylen);
ret = BCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_CBC,
sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
......@@ -2176,6 +2182,7 @@ static void test_ECDSA(void)
BCRYPT_ALG_HANDLE alg;
BCRYPT_KEY_HANDLE key;
NTSTATUS status;
DWORD keylen;
ULONG size;
status = BCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDSA_P256_ALGORITHM, NULL, 0);
......@@ -2211,6 +2218,12 @@ static void test_ECDSA(void)
status = BCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0);
ok(!status, "BCryptImportKeyPair failed: %#lx\n", status);
keylen = 0;
status = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
ok(!status, "got %#lx\n", status);
ok(size == sizeof(keylen), "got %lu\n", size);
ok(keylen == 256, "got %lu\n", keylen);
memset(buffer, 0xcc, sizeof(buffer));
status = BCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buffer, sizeof(buffer), &size, 0);
ok(!status, "Got unexpected status %#lx\n", status);
......@@ -2542,6 +2555,12 @@ static void test_RSA(void)
ret = BCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
ok(!ret, "BCryptImportKeyPair failed: %#lx\n", ret);
keylen = 0;
ret = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
ok(!ret, "got %#lx\n", ret);
ok(size == sizeof(keylen), "got %lu\n", size);
ok(keylen == 2048, "got %lu\n", keylen);
pad.pszAlgId = BCRYPT_SHA1_ALGORITHM;
ret = BCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
ok(!ret, "BCryptVerifySignature failed: %#lx\n", ret);
......@@ -2580,6 +2599,12 @@ static void test_RSA(void)
ret = BCryptFinalizeKeyPair(key, 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
keylen = 0;
ret = BCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
ok(!ret, "got %#lx\n", ret);
ok(size == sizeof(keylen), "got %lu\n", size);
ok(keylen == 2048, "got %lu\n", keylen);
ret = BCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
ok(ret == STATUS_SUCCESS, "got %#lx\n", ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment