| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/cal/private/ecc.h> |
| 6 |
|
| 7 |
#include <aws/cal/cal.h> |
| 8 |
#include <aws/cal/private/der.h> |
| 9 |
|
| 10 |
#include <aws/common/thread.h> |
| 11 |
|
| 12 |
#include <windows.h> |
| 13 |
|
| 14 |
#include <bcrypt.h> |
| 15 |
|
| 16 |
#include <winerror.h> |
| 17 |
|
| 18 |
static BCRYPT_ALG_HANDLE s_ecdsa_p256_alg = NULL; |
| 19 |
static BCRYPT_ALG_HANDLE s_ecdsa_p384_alg = NULL; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#define MAX_SIGNATURE_LENGTH (48 * 2) |
| 24 |
|
| 25 |
static aws_thread_once s_ecdsa_thread_once = AWS_THREAD_ONCE_STATIC_INIT; |
| 26 |
|
| 27 |
static void s_load_alg_handle(void *user_data) { |
| 28 |
(void)user_data; |
| 29 |
|
| 30 |
NTSTATUS status = |
| 31 |
BCryptOpenAlgorithmProvider(&s_ecdsa_p256_alg, BCRYPT_ECDSA_P256_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0); |
| 32 |
AWS_ASSERT(s_ecdsa_p256_alg && "BCryptOpenAlgorithmProvider() failed"); |
| 33 |
|
| 34 |
status = BCryptOpenAlgorithmProvider(&s_ecdsa_p384_alg, BCRYPT_ECDSA_P384_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0); |
| 35 |
AWS_ASSERT(s_ecdsa_p384_alg && "BCryptOpenAlgorithmProvider() failed"); |
| 36 |
|
| 37 |
(void)status; |
| 38 |
} |
| 39 |
|
| 40 |
struct bcrypt_ecc_key_pair { |
| 41 |
struct aws_ecc_key_pair key_pair; |
| 42 |
BCRYPT_KEY_HANDLE key_handle; |
| 43 |
}; |
| 44 |
|
| 45 |
static BCRYPT_ALG_HANDLE s_key_alg_handle_from_curve_name(enum aws_ecc_curve_name curve_name) { |
| 46 |
switch (curve_name) { |
| 47 |
case AWS_CAL_ECDSA_P256: |
| 48 |
return s_ecdsa_p256_alg; |
| 49 |
case AWS_CAL_ECDSA_P384: |
| 50 |
return s_ecdsa_p384_alg; |
| 51 |
default: |
| 52 |
return 0; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
static ULONG s_get_magic_from_curve_name(enum aws_ecc_curve_name curve_name, bool private_key) { |
| 57 |
switch (curve_name) { |
| 58 |
case AWS_CAL_ECDSA_P256: |
| 59 |
return private_key ? BCRYPT_ECDSA_PRIVATE_P256_MAGIC : BCRYPT_ECDSA_PUBLIC_P256_MAGIC; |
| 60 |
case AWS_CAL_ECDSA_P384: |
| 61 |
return private_key ? BCRYPT_ECDSA_PRIVATE_P384_MAGIC : BCRYPT_ECDSA_PUBLIC_P384_MAGIC; |
| 62 |
default: |
| 63 |
return 0; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
static void s_destroy_key(struct aws_ecc_key_pair *key_pair) { |
| 68 |
if (key_pair) { |
| 69 |
struct bcrypt_ecc_key_pair *key_impl = key_pair->impl; |
| 70 |
|
| 71 |
if (key_impl->key_handle) { |
| 72 |
BCryptDestroyKey(key_impl->key_handle); |
| 73 |
} |
| 74 |
|
| 75 |
aws_byte_buf_clean_up_secure(&key_pair->key_buf); |
| 76 |
aws_mem_release(key_pair->allocator, key_impl); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
static size_t s_signature_length(const struct aws_ecc_key_pair *key_pair) { |
| 81 |
static size_t s_der_overhead = 8; |
| 82 |
return s_der_overhead + aws_ecc_key_coordinate_byte_size_from_curve_name(key_pair->curve_name) * 2; |
| 83 |
} |
| 84 |
|
| 85 |
static int s_sign_message( |
| 86 |
const struct aws_ecc_key_pair *key_pair, |
| 87 |
const struct aws_byte_cursor *message, |
| 88 |
struct aws_byte_buf *signature_output) { |
| 89 |
struct bcrypt_ecc_key_pair *key_impl = key_pair->impl; |
| 90 |
|
| 91 |
size_t output_buf_space = signature_output->capacity - signature_output->len; |
| 92 |
|
| 93 |
if (output_buf_space < s_signature_length(key_pair)) { |
| 94 |
return aws_raise_error(AWS_ERROR_SHORT_BUFFER); |
| 95 |
} |
| 96 |
|
| 97 |
uint8_t temp_signature[MAX_SIGNATURE_LENGTH] = {0}; |
| 98 |
struct aws_byte_buf temp_signature_buf = aws_byte_buf_from_empty_array(temp_signature, sizeof(temp_signature)); |
| 99 |
size_t signature_length = temp_signature_buf.capacity; |
| 100 |
|
| 101 |
NTSTATUS status = BCryptSignHash( |
| 102 |
key_impl->key_handle, |
| 103 |
NULL, |
| 104 |
message->ptr, |
| 105 |
(ULONG)message->len, |
| 106 |
temp_signature_buf.buffer, |
| 107 |
(ULONG)signature_length, |
| 108 |
(ULONG *)&signature_length, |
| 109 |
0); |
| 110 |
|
| 111 |
if (status != 0) { |
| 112 |
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 113 |
} |
| 114 |
|
| 115 |
temp_signature_buf.len += signature_length; |
| 116 |
size_t coordinate_len = temp_signature_buf.len / 2; |
| 117 |
|
| 118 |
|
| 119 |
struct aws_byte_cursor s = aws_byte_cursor_from_buf(&temp_signature_buf); |
| 120 |
struct aws_byte_cursor r = aws_byte_cursor_advance(&s, coordinate_len); |
| 121 |
if (aws_ecc_encode_signature_raw_to_der(key_pair->allocator, r, s, signature_output)) { |
| 122 |
return aws_raise_error(AWS_ERROR_CAL_CRYPTO_OPERATION_FAILED); |
| 123 |
} |
| 124 |
|
| 125 |
return AWS_OP_SUCCESS; |
| 126 |
} |
| 127 |
|
| 128 |
static int s_derive_public_key(struct aws_ecc_key_pair *key_pair) { |
| 129 |
struct bcrypt_ecc_key_pair *key_impl = key_pair->impl; |
| 130 |
|
| 131 |
ULONG result = 0; |
| 132 |
NTSTATUS status = BCryptExportKey( |
| 133 |
key_impl->key_handle, |
| 134 |
NULL, |
| 135 |
BCRYPT_ECCPRIVATE_BLOB, |
| 136 |
key_pair->key_buf.buffer, |
| 137 |
(ULONG)key_pair->key_buf.capacity, |
| 138 |
&result, |
| 139 |
0); |
| 140 |
key_pair->key_buf.len = result; |
| 141 |
(void)result; |
| 142 |
|
| 143 |
if (status) { |
| 144 |
return aws_raise_error(AWS_ERROR_CAL_MISSING_REQUIRED_KEY_COMPONENT); |
| 145 |
} |
| 146 |
|
| 147 |
return AWS_OP_SUCCESS; |
| 148 |
} |
| 149 |
|
| 150 |
static int s_append_coordinate( |
| 151 |
struct aws_byte_buf *buffer, |
| 152 |
struct aws_byte_cursor *coordinate, |
| 153 |
enum aws_ecc_curve_name curve_name) { |
| 154 |
|
| 155 |
size_t coordinate_size = aws_ecc_key_coordinate_byte_size_from_curve_name(curve_name); |
| 156 |
if (coordinate->len < coordinate_size) { |
| 157 |
size_t leading_zero_count = coordinate_size - coordinate->len; |
| 158 |
AWS_FATAL_ASSERT(leading_zero_count + buffer->len <= buffer->capacity); |
| 159 |
|
| 160 |
aws_byte_buf_write_u8_n(buffer, 0x0, leading_zero_count); |
| 161 |
} |
| 162 |
|
| 163 |
return aws_byte_buf_append(buffer, coordinate); |
| 164 |
} |
| 165 |
|
| 166 |
static int s_verify_signature( |
| 167 |
const struct aws_ecc_key_pair *key_pair, |
| 168 |
const struct aws_byte_cursor *message, |
| 169 |
const struct aws_byte_cursor *signature) { |
| 170 |
struct bcrypt_ecc_key_pair *key_impl = key_pair->impl; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
uint8_t temp_signature[MAX_SIGNATURE_LENGTH] = {0}; |
| 175 |
struct aws_byte_buf temp_signature_buf = aws_byte_buf_from_empty_array(temp_signature, sizeof(temp_signature)); |
| 176 |
|
| 177 |
struct aws_byte_cursor der_encoded_signature = aws_byte_cursor_from_array(signature->ptr, signature->len); |
| 178 |
|
| 179 |
struct aws_der_decoder *decoder = aws_der_decoder_new(key_pair->allocator, der_encoded_signature); |
| 180 |
if (!decoder) { |
| 181 |
return AWS_OP_ERR; |
| 182 |
} |
| 183 |
|
| 184 |
if (!aws_der_decoder_next(decoder) || aws_der_decoder_tlv_type(decoder) != AWS_DER_SEQUENCE) { |
| 185 |
aws_raise_error(AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED); |
| 186 |
goto error; |
| 187 |
} |
| 188 |
|
| 189 |
if (!aws_der_decoder_next(decoder) || aws_der_decoder_tlv_type(decoder) != AWS_DER_INTEGER) { |
| 190 |
aws_raise_error(AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED); |
| 191 |
goto error; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
struct aws_byte_cursor coordinate; |
| 196 |
AWS_ZERO_STRUCT(coordinate); |
| 197 |
if (aws_der_decoder_tlv_unsigned_integer(decoder, &coordinate)) { |
| 198 |
aws_raise_error(AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED); |
| 199 |
goto error; |
| 200 |
} |
| 201 |
|
| 202 |
if (s_append_coordinate(&temp_signature_buf, &coordinate, key_pair->curve_name)) { |
| 203 |
goto error; |
| 204 |
} |
| 205 |
|
| 206 |
if (!aws_der_decoder_next(decoder) || aws_der_decoder_tlv_type(decoder) != AWS_DER_INTEGER) { |
| 207 |
aws_raise_error(AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED); |
| 208 |
goto error; |
| 209 |
} |
| 210 |
AWS_ZERO_STRUCT(coordinate); |
| 211 |
if (aws_der_decoder_tlv_unsigned_integer(decoder, &coordinate)) { |
| 212 |
aws_raise_error(AWS_ERROR_CAL_MALFORMED_ASN1_ENCOUNTERED); |
| 213 |
goto error; |
| 214 |
} |
| 215 |
|
| 216 |
if (s_append_coordinate(&temp_signature_buf, &coordinate, key_pair->curve_name)) { |
| 217 |
goto error; |
| 218 |
} |
| 219 |
|
| 220 |
aws_der_decoder_destroy(decoder); |
| 221 |
|
| 222 |
|
| 223 |
NTSTATUS status = BCryptVerifySignature( |
| 224 |
key_impl->key_handle, |
| 225 |
NULL, |
| 226 |
message->ptr, |
| 227 |
(ULONG)message->len, |
| 228 |
temp_signature_buf.buffer, |
| 229 |
(ULONG)temp_signature_buf.len, |
| 230 |
0); |
| 231 |
|
| 232 |
return status == 0 ? AWS_OP_SUCCESS : aws_raise_error(AWS_ERROR_CAL_SIGNATURE_VALIDATION_FAILED); |
| 233 |
|
| 234 |
error: |
| 235 |
if (decoder) { |
| 236 |
aws_der_decoder_destroy(decoder); |
| 237 |
} |
| 238 |
return AWS_OP_ERR; |
| 239 |
} |
| 240 |
|
| 241 |
static struct aws_ecc_key_pair_vtable s_vtable = { |
| 242 |
.destroy = s_destroy_key, |
| 243 |
.derive_pub_key = s_derive_public_key, |
| 244 |
.sign_message = s_sign_message, |
| 245 |
.verify_signature = s_verify_signature, |
| 246 |
.signature_length = s_signature_length, |
| 247 |
}; |
| 248 |
|
| 249 |
static struct aws_ecc_key_pair *s_alloc_pair_and_init_buffers( |
| 250 |
struct aws_allocator *allocator, |
| 251 |
enum aws_ecc_curve_name curve_name, |
| 252 |
struct aws_byte_cursor pub_x, |
| 253 |
struct aws_byte_cursor pub_y, |
| 254 |
struct aws_byte_cursor priv_key) { |
| 255 |
|
| 256 |
aws_thread_call_once(&s_ecdsa_thread_once, s_load_alg_handle, NULL); |
| 257 |
|
| 258 |
struct bcrypt_ecc_key_pair *key_impl = aws_mem_calloc(allocator, 1, sizeof(struct bcrypt_ecc_key_pair)); |
| 259 |
|
| 260 |
if (!key_impl) { |
| 261 |
return NULL; |
| 262 |
} |
| 263 |
|
| 264 |
key_impl->key_pair.allocator = allocator; |
| 265 |
key_impl->key_pair.curve_name = curve_name; |
| 266 |
key_impl->key_pair.impl = key_impl; |
| 267 |
key_impl->key_pair.vtable = &s_vtable; |
| 268 |
aws_atomic_init_int(&key_impl->key_pair.ref_count, 1); |
| 269 |
|
| 270 |
size_t s_key_coordinate_size = aws_ecc_key_coordinate_byte_size_from_curve_name(curve_name); |
| 271 |
|
| 272 |
if (!s_key_coordinate_size) { |
| 273 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 274 |
goto error; |
| 275 |
} |
| 276 |
|
| 277 |
if ((pub_x.ptr && pub_x.len != s_key_coordinate_size) || (pub_y.ptr && pub_y.len != s_key_coordinate_size) || |
| 278 |
(priv_key.ptr && priv_key.len != s_key_coordinate_size)) { |
| 279 |
aws_raise_error(AWS_ERROR_CAL_INVALID_KEY_LENGTH_FOR_ALGORITHM); |
| 280 |
goto error; |
| 281 |
} |
| 282 |
|
| 283 |
size_t total_buffer_size = s_key_coordinate_size * 3 + sizeof(BCRYPT_ECCKEY_BLOB); |
| 284 |
|
| 285 |
if (aws_byte_buf_init(&key_impl->key_pair.key_buf, allocator, total_buffer_size)) { |
| 286 |
goto error; |
| 287 |
} |
| 288 |
|
| 289 |
aws_byte_buf_secure_zero(&key_impl->key_pair.key_buf); |
| 290 |
|
| 291 |
BCRYPT_ECCKEY_BLOB key_blob; |
| 292 |
AWS_ZERO_STRUCT(key_blob); |
| 293 |
key_blob.dwMagic = s_get_magic_from_curve_name(curve_name, priv_key.ptr && priv_key.len); |
| 294 |
key_blob.cbKey = (ULONG)s_key_coordinate_size; |
| 295 |
|
| 296 |
struct aws_byte_cursor header = aws_byte_cursor_from_array(&key_blob, sizeof(key_blob)); |
| 297 |
aws_byte_buf_append(&key_impl->key_pair.key_buf, &header); |
| 298 |
|
| 299 |
LPCWSTR blob_type = BCRYPT_ECCPUBLIC_BLOB; |
| 300 |
ULONG flags = 0; |
| 301 |
if (pub_x.ptr && pub_y.ptr) { |
| 302 |
aws_byte_buf_append(&key_impl->key_pair.key_buf, &pub_x); |
| 303 |
aws_byte_buf_append(&key_impl->key_pair.key_buf, &pub_y); |
| 304 |
} else { |
| 305 |
key_impl->key_pair.key_buf.len += s_key_coordinate_size * 2; |
| 306 |
flags = BCRYPT_NO_KEY_VALIDATION; |
| 307 |
} |
| 308 |
|
| 309 |
if (priv_key.ptr) { |
| 310 |
blob_type = BCRYPT_ECCPRIVATE_BLOB; |
| 311 |
aws_byte_buf_append(&key_impl->key_pair.key_buf, &priv_key); |
| 312 |
} |
| 313 |
|
| 314 |
key_impl->key_pair.pub_x = |
| 315 |
aws_byte_buf_from_array(key_impl->key_pair.key_buf.buffer + sizeof(key_blob), s_key_coordinate_size); |
| 316 |
|
| 317 |
key_impl->key_pair.pub_y = |
| 318 |
aws_byte_buf_from_array(key_impl->key_pair.pub_x.buffer + s_key_coordinate_size, s_key_coordinate_size); |
| 319 |
|
| 320 |
key_impl->key_pair.priv_d = |
| 321 |
aws_byte_buf_from_array(key_impl->key_pair.pub_y.buffer + s_key_coordinate_size, s_key_coordinate_size); |
| 322 |
|
| 323 |
BCRYPT_ALG_HANDLE alg_handle = s_key_alg_handle_from_curve_name(curve_name); |
| 324 |
NTSTATUS status = BCryptImportKeyPair( |
| 325 |
alg_handle, |
| 326 |
NULL, |
| 327 |
blob_type, |
| 328 |
&key_impl->key_handle, |
| 329 |
key_impl->key_pair.key_buf.buffer, |
| 330 |
(ULONG)key_impl->key_pair.key_buf.len, |
| 331 |
flags); |
| 332 |
|
| 333 |
if (status) { |
| 334 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 335 |
goto error; |
| 336 |
} |
| 337 |
|
| 338 |
return &key_impl->key_pair; |
| 339 |
|
| 340 |
error: |
| 341 |
s_destroy_key(&key_impl->key_pair); |
| 342 |
return NULL; |
| 343 |
} |
| 344 |
|
| 345 |
struct aws_ecc_key_pair *aws_ecc_key_pair_new_from_private_key_impl( |
| 346 |
struct aws_allocator *allocator, |
| 347 |
enum aws_ecc_curve_name curve_name, |
| 348 |
const struct aws_byte_cursor *priv_key) { |
| 349 |
|
| 350 |
struct aws_byte_cursor empty; |
| 351 |
AWS_ZERO_STRUCT(empty); |
| 352 |
return s_alloc_pair_and_init_buffers(allocator, curve_name, empty, empty, *priv_key); |
| 353 |
} |
| 354 |
|
| 355 |
struct aws_ecc_key_pair *aws_ecc_key_pair_new_from_public_key_impl( |
| 356 |
struct aws_allocator *allocator, |
| 357 |
enum aws_ecc_curve_name curve_name, |
| 358 |
const struct aws_byte_cursor *public_key_x, |
| 359 |
const struct aws_byte_cursor *public_key_y) { |
| 360 |
|
| 361 |
struct aws_byte_cursor empty; |
| 362 |
AWS_ZERO_STRUCT(empty); |
| 363 |
return s_alloc_pair_and_init_buffers(allocator, curve_name, *public_key_x, *public_key_y, empty); |
| 364 |
} |
| 365 |
|
| 366 |
struct aws_ecc_key_pair *aws_ecc_key_pair_new_generate_random_impl( |
| 367 |
struct aws_allocator *allocator, |
| 368 |
enum aws_ecc_curve_name curve_name) { |
| 369 |
aws_thread_call_once(&s_ecdsa_thread_once, s_load_alg_handle, NULL); |
| 370 |
|
| 371 |
struct bcrypt_ecc_key_pair *key_impl = aws_mem_calloc(allocator, 1, sizeof(struct bcrypt_ecc_key_pair)); |
| 372 |
|
| 373 |
if (!key_impl) { |
| 374 |
return NULL; |
| 375 |
} |
| 376 |
|
| 377 |
key_impl->key_pair.allocator = allocator; |
| 378 |
key_impl->key_pair.curve_name = curve_name; |
| 379 |
key_impl->key_pair.impl = key_impl; |
| 380 |
key_impl->key_pair.vtable = &s_vtable; |
| 381 |
aws_atomic_init_int(&key_impl->key_pair.ref_count, 1); |
| 382 |
|
| 383 |
size_t key_coordinate_size = aws_ecc_key_coordinate_byte_size_from_curve_name(curve_name); |
| 384 |
|
| 385 |
if (!key_coordinate_size) { |
| 386 |
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 387 |
goto error; |
| 388 |
} |
| 389 |
|
| 390 |
BCRYPT_ALG_HANDLE alg_handle = s_key_alg_handle_from_curve_name(curve_name); |
| 391 |
|
| 392 |
ULONG key_bit_length = (ULONG)key_coordinate_size * 8; |
| 393 |
NTSTATUS status = BCryptGenerateKeyPair(alg_handle, &key_impl->key_handle, key_bit_length, 0); |
| 394 |
|
| 395 |
if (status) { |
| 396 |
aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE); |
| 397 |
goto error; |
| 398 |
} |
| 399 |
|
| 400 |
status = BCryptFinalizeKeyPair(key_impl->key_handle, 0); |
| 401 |
|
| 402 |
if (status) { |
| 403 |
aws_raise_error(AWS_ERROR_SYS_CALL_FAILURE); |
| 404 |
goto error; |
| 405 |
} |
| 406 |
|
| 407 |
size_t total_buffer_size = key_coordinate_size * 3 + sizeof(BCRYPT_ECCKEY_BLOB); |
| 408 |
|
| 409 |
if (aws_byte_buf_init(&key_impl->key_pair.key_buf, allocator, total_buffer_size)) { |
| 410 |
goto error; |
| 411 |
} |
| 412 |
|
| 413 |
aws_byte_buf_secure_zero(&key_impl->key_pair.key_buf); |
| 414 |
|
| 415 |
key_impl->key_pair.pub_x = |
| 416 |
aws_byte_buf_from_array(key_impl->key_pair.key_buf.buffer + sizeof(BCRYPT_ECCKEY_BLOB), key_coordinate_size); |
| 417 |
|
| 418 |
key_impl->key_pair.pub_y = |
| 419 |
aws_byte_buf_from_array(key_impl->key_pair.pub_x.buffer + key_coordinate_size, key_coordinate_size); |
| 420 |
|
| 421 |
key_impl->key_pair.priv_d = |
| 422 |
aws_byte_buf_from_array(key_impl->key_pair.pub_y.buffer + key_coordinate_size, key_coordinate_size); |
| 423 |
|
| 424 |
if (s_derive_public_key(&key_impl->key_pair)) { |
| 425 |
goto error; |
| 426 |
} |
| 427 |
|
| 428 |
return &key_impl->key_pair; |
| 429 |
|
| 430 |
error: |
| 431 |
s_destroy_key(&key_impl->key_pair); |
| 432 |
return NULL; |
| 433 |
} |
| 434 |
|
| 435 |
struct aws_ecc_key_pair *aws_ecc_key_pair_new_from_asn1_impl( |
| 436 |
struct aws_allocator *allocator, |
| 437 |
const struct aws_byte_cursor *encoded_keys) { |
| 438 |
struct aws_der_decoder *decoder = aws_der_decoder_new(allocator, *encoded_keys); |
| 439 |
|
| 440 |
|
| 441 |
struct aws_byte_cursor pub_x; |
| 442 |
AWS_ZERO_STRUCT(pub_x); |
| 443 |
struct aws_byte_cursor pub_y; |
| 444 |
AWS_ZERO_STRUCT(pub_y); |
| 445 |
struct aws_byte_cursor priv_d; |
| 446 |
AWS_ZERO_STRUCT(priv_d); |
| 447 |
|
| 448 |
enum aws_ecc_curve_name curve_name; |
| 449 |
if (aws_der_decoder_load_ecc_key_pair(decoder, &pub_x, &pub_y, &priv_d, &curve_name)) { |
| 450 |
goto error; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
struct aws_ecc_key_pair *key_pair = s_alloc_pair_and_init_buffers(allocator, curve_name, pub_x, pub_y, priv_d); |
| 455 |
aws_der_decoder_destroy(decoder); |
| 456 |
|
| 457 |
return key_pair; |
| 458 |
error: |
| 459 |
if (decoder) { |
| 460 |
aws_der_decoder_destroy(decoder); |
| 461 |
} |
| 462 |
return NULL; |
| 463 |
} |