summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-10-31 15:07:50 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-10-31 15:07:50 +0000
commit4cf39a081f576bbfda05d774cbf51c205f2e22f7 (patch)
tree5487196fdcede1471d343166e2b95514b1332e74 /lib
parent0a8f487379c983c7f18d680e65e64938108ab1f9 (diff)
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 'lib')
-rw-r--r--lib/libcrypto/ec/ec_asn1.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/libcrypto/ec/ec_asn1.c b/lib/libcrypto/ec/ec_asn1.c
index c44b06be82e..50e089a063a 100644
--- a/lib/libcrypto/ec/ec_asn1.c
+++ b/lib/libcrypto/ec/ec_asn1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_asn1.c,v 1.102 2024/10/31 14:58:22 tb Exp $ */
+/* $OpenBSD: ec_asn1.c,v 1.103 2024/10/31 15:07:49 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
@@ -1382,29 +1382,32 @@ d2i_ECParameters(EC_KEY **out_ec_key, const unsigned char **in, long len)
LCRYPTO_ALIAS(d2i_ECParameters);
EC_KEY *
-o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)
+o2i_ECPublicKey(EC_KEY **in_ec_key, const unsigned char **in, long len)
{
- EC_KEY *ret = NULL;
+ EC_KEY *ec_key = NULL;
+ const EC_GROUP *group;
+ uint8_t form;
- if (a == NULL || (*a) == NULL || (*a)->group == NULL) {
- /* An EC_GROUP structure is necessary to set the public key. */
+ if (in_ec_key == NULL || (ec_key = *in_ec_key) == NULL) {
ECerror(ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
- ret = *a;
- if (ret->pub_key == NULL &&
- (ret->pub_key = EC_POINT_new(ret->group)) == NULL) {
- ECerror(ERR_R_MALLOC_FAILURE);
+ if ((group = ec_key->group) == NULL) {
+ ECerror(ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
- if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) {
- ECerror(ERR_R_EC_LIB);
+ if (len < 0) {
+ ECerror(EC_R_INVALID_ARGUMENT);
return NULL;
}
- /* save the point conversion form */
- ret->conv_form = (point_conversion_form_t) (*in[0] & ~0x01);
+
+ if (!ec_point_from_octets(group, *in, len, &ec_key->pub_key, &form, NULL))
+ return NULL;
+ EC_KEY_set_conv_form(ec_key, form);
+
*in += len;
- return ret;
+
+ return ec_key;
}
LCRYPTO_ALIAS(o2i_ECPublicKey);