summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec_asn1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ec_asn1.c')
-rw-r--r--src/lib/libcrypto/ec/ec_asn1.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c
index b64b7e14d3..381addfcf6 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.24 2017/05/26 16:32:14 jsing Exp $ */ 1/* $OpenBSD: ec_asn1.c,v 1.25 2018/03/12 13:14:21 inoguchi Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -1380,17 +1380,18 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1380 goto err; 1380 goto err;
1381 } 1381 }
1382 1382
1383 if (ret->pub_key)
1384 EC_POINT_clear_free(ret->pub_key);
1385 ret->pub_key = EC_POINT_new(ret->group);
1386 if (ret->pub_key == NULL) {
1387 ECerror(ERR_R_EC_LIB);
1388 goto err;
1389 }
1390
1383 if (priv_key->publicKey) { 1391 if (priv_key->publicKey) {
1384 const unsigned char *pub_oct; 1392 const unsigned char *pub_oct;
1385 size_t pub_oct_len; 1393 size_t pub_oct_len;
1386 1394
1387 EC_POINT_clear_free(ret->pub_key);
1388 ret->pub_key = EC_POINT_new(ret->group);
1389 if (ret->pub_key == NULL) {
1390 ECerror(ERR_R_EC_LIB);
1391 goto err;
1392 }
1393
1394 pub_oct = ASN1_STRING_data(priv_key->publicKey); 1395 pub_oct = ASN1_STRING_data(priv_key->publicKey);
1395 pub_oct_len = ASN1_STRING_length(priv_key->publicKey); 1396 pub_oct_len = ASN1_STRING_length(priv_key->publicKey);
1396 if (pub_oct == NULL || pub_oct_len <= 0) { 1397 if (pub_oct == NULL || pub_oct_len <= 0) {
@@ -1405,6 +1406,14 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1405 ECerror(ERR_R_EC_LIB); 1406 ECerror(ERR_R_EC_LIB);
1406 goto err; 1407 goto err;
1407 } 1408 }
1409 } else {
1410 if (!EC_POINT_mul(ret->group, ret->pub_key, ret->priv_key,
1411 NULL, NULL, NULL)) {
1412 ECerror(ERR_R_EC_LIB);
1413 goto err;
1414 }
1415 /* Remember the original private-key-only encoding. */
1416 ret->enc_flag |= EC_PKEY_NO_PUBKEY;
1408 } 1417 }
1409 1418
1410 EC_PRIVATEKEY_free(priv_key); 1419 EC_PRIVATEKEY_free(priv_key);
@@ -1429,7 +1438,8 @@ i2d_ECPrivateKey(EC_KEY * a, unsigned char **out)
1429 size_t buf_len = 0, tmp_len; 1438 size_t buf_len = 0, tmp_len;
1430 EC_PRIVATEKEY *priv_key = NULL; 1439 EC_PRIVATEKEY *priv_key = NULL;
1431 1440
1432 if (a == NULL || a->group == NULL || a->priv_key == NULL) { 1441 if (a == NULL || a->group == NULL || a->priv_key == NULL ||
1442 (!(a->enc_flag & EC_PKEY_NO_PUBKEY) && a->pub_key == NULL)) {
1433 ECerror(ERR_R_PASSED_NULL_PARAMETER); 1443 ECerror(ERR_R_PASSED_NULL_PARAMETER);
1434 goto err; 1444 goto err;
1435 } 1445 }