diff options
author | tb <> | 2024-10-31 15:07:49 +0000 |
---|---|---|
committer | tb <> | 2024-10-31 15:07:49 +0000 |
commit | 3c4e7375bde814ea2663e65bf0caa42fe3b4a05d (patch) | |
tree | 8fd647c41e5e7a67795dec54022b0b16dbe848ea /src | |
parent | 0e3dba5b6baf332335bf0fdd135743ba36e8c5d9 (diff) | |
download | openbsd-3c4e7375bde814ea2663e65bf0caa42fe3b4a05d.tar.gz openbsd-3c4e7375bde814ea2663e65bf0caa42fe3b4a05d.tar.bz2 openbsd-3c4e7375bde814ea2663e65bf0caa42fe3b4a05d.zip |
Clean up o2i_ECPublicKey()
a is a stupid name for an EC_key, so is ret. Pull apart the tests at the
start and check the length for negativity (long is always the wrong type).
Switch to ec_point_from_octets() and let it determine the point conversion
form rather than having yet another copy of the same ugly stanza.
Set the form on the key using EC_KEY_set_conv_form() (which also affects
the group on the key, so this is a slight change of behavior). Why on earth
this function returns the EC_KEY passed in, I'll never know.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index c44b06be82..50e089a063 100644 --- a/src/lib/libcrypto/ec/ec_asn1.c +++ b/src/lib/libcrypto/ec/ec_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1.c,v 1.102 2024/10/31 14:58:22 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.103 2024/10/31 15:07:49 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -1382,29 +1382,32 @@ d2i_ECParameters(EC_KEY **out_ec_key, const unsigned char **in, long len) | |||
1382 | LCRYPTO_ALIAS(d2i_ECParameters); | 1382 | LCRYPTO_ALIAS(d2i_ECParameters); |
1383 | 1383 | ||
1384 | EC_KEY * | 1384 | EC_KEY * |
1385 | o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len) | 1385 | o2i_ECPublicKey(EC_KEY **in_ec_key, const unsigned char **in, long len) |
1386 | { | 1386 | { |
1387 | EC_KEY *ret = NULL; | 1387 | EC_KEY *ec_key = NULL; |
1388 | const EC_GROUP *group; | ||
1389 | uint8_t form; | ||
1388 | 1390 | ||
1389 | if (a == NULL || (*a) == NULL || (*a)->group == NULL) { | 1391 | if (in_ec_key == NULL || (ec_key = *in_ec_key) == NULL) { |
1390 | /* An EC_GROUP structure is necessary to set the public key. */ | ||
1391 | ECerror(ERR_R_PASSED_NULL_PARAMETER); | 1392 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
1392 | return NULL; | 1393 | return NULL; |
1393 | } | 1394 | } |
1394 | ret = *a; | 1395 | if ((group = ec_key->group) == NULL) { |
1395 | if (ret->pub_key == NULL && | 1396 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
1396 | (ret->pub_key = EC_POINT_new(ret->group)) == NULL) { | ||
1397 | ECerror(ERR_R_MALLOC_FAILURE); | ||
1398 | return NULL; | 1397 | return NULL; |
1399 | } | 1398 | } |
1400 | if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) { | 1399 | if (len < 0) { |
1401 | ECerror(ERR_R_EC_LIB); | 1400 | ECerror(EC_R_INVALID_ARGUMENT); |
1402 | return NULL; | 1401 | return NULL; |
1403 | } | 1402 | } |
1404 | /* save the point conversion form */ | 1403 | |
1405 | ret->conv_form = (point_conversion_form_t) (*in[0] & ~0x01); | 1404 | if (!ec_point_from_octets(group, *in, len, &ec_key->pub_key, &form, NULL)) |
1405 | return NULL; | ||
1406 | EC_KEY_set_conv_form(ec_key, form); | ||
1407 | |||
1406 | *in += len; | 1408 | *in += len; |
1407 | return ret; | 1409 | |
1410 | return ec_key; | ||
1408 | } | 1411 | } |
1409 | LCRYPTO_ALIAS(o2i_ECPublicKey); | 1412 | LCRYPTO_ALIAS(o2i_ECPublicKey); |
1410 | 1413 | ||