|
29 | 29 | * [1] https://www.rfc-editor.org/rfc/rfc6979#appendix-A.2.5 |
30 | 30 | */ |
31 | 31 | static const psa_algorithm_t algo = PSA_ALG_ECDSA(PSA_ALG_SHA_256); |
32 | | -static const psa_key_type_t type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_SECP_R1); |
| 32 | +static const psa_key_type_t type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1); |
33 | 33 |
|
34 | 34 | static const uint8_t private_key[] = {0xC9, 0xAF, 0xA9, 0xD8, 0x45, 0xBA, 0x75, 0x16, 0x6B, 0x5C, |
35 | 35 | 0x21, 0x57, 0x67, 0xB1, 0xD6, 0x93, 0x4E, 0x50, 0xC3, 0xDB, 0x36, 0xE8, 0x9B, 0x12, 0x7B, 0x8A, |
@@ -60,17 +60,29 @@ psa_status_t test_ecdsa_p256_vectors(void) { |
60 | 60 | psa_key_attributes_t key_attr = psa_key_attributes_init(); |
61 | 61 | psa_key_id_t key_id; |
62 | 62 |
|
63 | | - psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_VERIFY_MESSAGE); |
| 63 | + psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_VERIFY_MESSAGE | PSA_KEY_USAGE_EXPORT); |
64 | 64 | psa_set_key_algorithm(&key_attr, algo); |
65 | 65 | psa_set_key_bits(&key_attr, PSA_BYTES_TO_BITS(sizeof(private_key))); |
66 | 66 | psa_set_key_type(&key_attr, type); |
67 | 67 |
|
68 | 68 | psa_status_t status; |
69 | | - status = psa_import_key(&key_attr, public_key, sizeof(public_key), &key_id); |
| 69 | + status = psa_import_key(&key_attr, private_key, sizeof(private_key), &key_id); |
70 | 70 | if (status != PSA_SUCCESS) { |
71 | 71 | return status; |
72 | 72 | } |
73 | 73 |
|
| 74 | + /* testing public key derivation */ |
| 75 | + uint8_t exp_public_key[sizeof(public_key)]; |
| 76 | + size_t length; |
| 77 | + status = psa_export_public_key(key_id, exp_public_key, sizeof(public_key), &length); |
| 78 | + if (status != PSA_SUCCESS) { |
| 79 | + return status; |
| 80 | + } |
| 81 | + |
| 82 | + if (0 != memcmp(public_key, exp_public_key, sizeof(public_key))) { |
| 83 | + return -1; |
| 84 | + } |
| 85 | + |
74 | 86 | status = psa_verify_message(key_id, algo, message, sizeof(message), signature, sizeof(signature)); |
75 | 87 |
|
76 | 88 | psa_destroy_key(key_id); |
|
0 commit comments