Skip to content

Commit

Permalink
Fix error handling in bcrypt oe_rsa_public_key_from_modulus
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph M. Wintersteiger <[email protected]>
  • Loading branch information
Christoph M. Wintersteiger committed Nov 9, 2020
1 parent 0e7ea1a commit 1fd03b9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions host/crypto/bcrypt/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ oe_result_t oe_rsa_public_key_from_modulus(
oe_rsa_public_key_t* public_key)
{
oe_result_t result = OE_UNEXPECTED;
NTSTATUS status;
BCRYPT_KEY_HANDLE key_handle;
uint8_t* key_data_bytes = NULL;
size_t key_data_size = 0;
Expand Down Expand Up @@ -599,18 +600,18 @@ oe_result_t oe_rsa_public_key_from_modulus(
modulus,
(ULONG)modulus_size));

if (!BCRYPT_SUCCESS(BCryptImportKeyPair(
BCRYPT_RSA_ALG_HANDLE,
NULL,
BCRYPT_RSAPUBLIC_BLOB,
&key_handle,
(PUCHAR)key_data_bytes,
(ULONG)key_data_size,
BCRYPT_NO_KEY_VALIDATION)))
status = BCryptImportKeyPair(
BCRYPT_RSA_ALG_HANDLE,
NULL,
BCRYPT_RSAPUBLIC_BLOB,
&key_handle,
(PUCHAR)key_data_bytes,
(ULONG)key_data_size,
BCRYPT_NO_KEY_VALIDATION);

if (!BCRYPT_SUCCESS(status))
OE_RAISE_MSG(
OE_CRYPTO_ERROR,
"BCryptImportKeyPair failed with %#x",
bcrypt_status);
OE_CRYPTO_ERROR, "BCryptImportKeyPair failed with %#x", status);

oe_rsa_public_key_init(public_key, key_handle);

Expand Down

0 comments on commit 1fd03b9

Please sign in to comment.