diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2020-11-02 12:46:38 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2020-12-07 17:15:39 +1000 |
commit | c1131e6a0e4a9a9734559f7a58b278c027d76711 (patch) | |
tree | c92144dd2d3011967640830a8c9e643ec87a0afe | |
parent | abdd3fa04f3401c4a542257fdd803ff4c4daf8ef (diff) |
Deprecate EC_POINT_bn2point and EC_POINT_point2bn.
Fixes #10366
The one place that actually used was in the legacy printing of ecparams.
This has been replaced by the pointtobuf variant.
The ecparam app was using one of these functions - this line has just been
removed as another PR will remove all the code generated lines..
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13294)
-rw-r--r-- | apps/ecparam.c | 1 | ||||
-rw-r--r-- | crypto/ec/build.info | 2 | ||||
-rw-r--r-- | crypto/ec/ec_deprecated.c | 78 | ||||
-rw-r--r-- | crypto/ec/ec_print.c | 102 | ||||
-rw-r--r-- | crypto/ec/eck_prn.c | 37 | ||||
-rw-r--r-- | doc/man3/EC_POINT_new.pod | 14 | ||||
-rw-r--r-- | doc/man3/OPENSSL_hexchar2int.pod | 14 | ||||
-rw-r--r-- | include/openssl/ec.h | 14 | ||||
-rw-r--r-- | providers/implementations/encode_decode/encode_key2text.c | 20 | ||||
-rw-r--r-- | util/libcrypto.num | 4 |
10 files changed, 168 insertions, 118 deletions
diff --git a/apps/ecparam.c b/apps/ecparam.c index b51a61adc0..3e20be24b2 100644 --- a/apps/ecparam.c +++ b/apps/ecparam.c @@ -294,7 +294,6 @@ int ecparam_main(int argc, char **argv) goto end; } BIO_printf(bio_err, "ok\n"); - } if (outformat == FORMAT_ASN1 && genkey) diff --git a/crypto/ec/build.info b/crypto/ec/build.info index 496a932e4c..63512565ba 100644 --- a/crypto/ec/build.info +++ b/crypto/ec/build.info @@ -45,7 +45,7 @@ ENDIF $COMMON=ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c \ ec_curve.c ec_check.c ec_print.c ec_key.c ecx_key.c ec_asn1.c \ - ec2_smpl.c \ + ec2_smpl.c ec_deprecated.c \ ecp_oct.c ec2_oct.c ec_oct.c ec_kmeth.c ecdh_ossl.c \ ecdsa_ossl.c ecdsa_sign.c ecdsa_vrf.c curve25519.c \ curve448/arch_32/f_impl.c curve448/f_generic.c curve448/scalar.c \ diff --git a/crypto/ec/ec_deprecated.c b/crypto/ec/ec_deprecated.c new file mode 100644 index 0000000000..cd2eec80b7 --- /dev/null +++ b/crypto/ec/ec_deprecated.c @@ -0,0 +1,78 @@ +/* + * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Suppress deprecation warnings for EC low level implementations that are + * kept until removal. + */ +#define OPENSSL_SUPPRESS_DEPRECATED + +#include <openssl/crypto.h> +#include <openssl/err.h> +#include <openssl/ec.h> + +#ifndef OPENSSL_NO_DEPRECATED_3_0 +BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, + const EC_POINT *point, + point_conversion_form_t form, + BIGNUM *ret, BN_CTX *ctx) +{ + size_t buf_len = 0; + unsigned char *buf; + + buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx); + + if (buf_len == 0) + return NULL; + + ret = BN_bin2bn(buf, buf_len, ret); + + OPENSSL_free(buf); + + return ret; +} + +EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, + const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx) +{ + size_t buf_len = 0; + unsigned char *buf; + EC_POINT *ret; + + if ((buf_len = BN_num_bytes(bn)) == 0) + buf_len = 1; + if ((buf = OPENSSL_malloc(buf_len)) == NULL) { + ECerr(EC_F_EC_POINT_BN2POINT, ERR_R_MALLOC_FAILURE); + return NULL; + } + + if (!BN_bn2binpad(bn, buf, buf_len)) { + OPENSSL_free(buf); + return NULL; + } + + if (point == NULL) { + if ((ret = EC_POINT_new(group)) == NULL) { + OPENSSL_free(buf); + return NULL; + } + } else + ret = point; + + if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) { + if (ret != point) + EC_POINT_clear_free(ret); + OPENSSL_free(buf); + return NULL; + } + + OPENSSL_free(buf); + return ret; +} +#endif /* OPENSSL_NO_DEPRECATED_3_0 */ diff --git a/crypto/ec/ec_print.c b/crypto/ec/ec_print.c index 4fb76fe74e..d791e15b48 100644 --- a/crypto/ec/ec_print.c +++ b/crypto/ec/ec_print.c @@ -7,74 +7,10 @@ * https://www.openssl.org/source/license.html */ -/* - * ECDSA low level APIs are deprecated for public use, but still ok for - * internal use. - */ -#include "internal/deprecated.h" - +#include <string.h> /* strlen */ #include <openssl/crypto.h> -#include <openssl/err.h> #include "ec_local.h" -BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, - const EC_POINT *point, - point_conversion_form_t form, - BIGNUM *ret, BN_CTX *ctx) -{ - size_t buf_len = 0; - unsigned char *buf; - - buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx); - - if (buf_len == 0) - return NULL; - - ret = BN_bin2bn(buf, buf_len, ret); - - OPENSSL_free(buf); - - return ret; -} - -EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, - const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx) -{ - size_t buf_len = 0; - unsigned char *buf; - EC_POINT *ret; - - if ((buf_len = BN_num_bytes(bn)) == 0) - buf_len = 1; - if ((buf = OPENSSL_malloc(buf_len)) == NULL) { - ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE); - return NULL; - } - - if (!BN_bn2binpad(bn, buf, buf_len)) { - OPENSSL_free(buf); - return NULL; - } - - if (point == NULL) { - if ((ret = EC_POINT_new(group)) == NULL) { - OPENSSL_free(buf); - return NULL; - } - } else - ret = point; - - if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) { - if (ret != point) - EC_POINT_clear_free(ret); - OPENSSL_free(buf); - return NULL; - } - - OPENSSL_free(buf); - return ret; -} - static const char *HEX_DIGITS = "0123456789ABCDEF"; /* the return value must be freed (using OPENSSL_free()) */ @@ -111,17 +47,39 @@ char *EC_POINT_point2hex(const EC_GROUP *group, } EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, - const char *buf, EC_POINT *point, BN_CTX *ctx) + const char *hex, EC_POINT *point, BN_CTX *ctx) { - EC_POINT *ret = NULL; - BIGNUM *tmp_bn = NULL; + int ok = 0; + unsigned char *oct_buf = NULL; + size_t len, oct_buf_len = 0; + EC_POINT *pt = NULL; - if (!BN_hex2bn(&tmp_bn, buf)) + if (group == NULL || hex == NULL) return NULL; - ret = EC_POINT_bn2point(group, tmp_bn, point, ctx); + if (point == NULL) { + pt = EC_POINT_new(group); + if (pt == NULL) + goto err; + } else { + pt = point; + } - BN_clear_free(tmp_bn); + len = strlen(hex) / 2; + oct_buf = OPENSSL_malloc(len); + if (oct_buf == NULL) + return NULL; - return ret; + if (!OPENSSL_hexstr2buf_ex(oct_buf, len, &oct_buf_len, hex, '\0') + || !EC_POINT_oct2point(group, pt, oct_buf, oct_buf_len, ctx)) + goto err; + ok = 1; +err: + OPENSSL_clear_free(oct_buf, oct_buf_len); + if (!ok) { + if (pt != point) + EC_POINT_clear_free(pt); + pt = NULL; + } + return pt; } diff --git a/crypto/ec/eck_prn.c b/crypto/ec/eck_prn.c index 7b892ae403..20c6065a31 100644 --- a/crypto/ec/eck_prn.c +++ b/crypto/ec/eck_prn.c @@ -69,10 +69,11 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off) int ret = 0, reason = ERR_R_BIO_LIB; BN_CTX *ctx = NULL; const EC_POINT *point = NULL; - BIGNUM *p = NULL, *a = NULL, *b = NULL, *gen = NULL; + BIGNUM *p = NULL, *a = NULL, *b = NULL; + unsigned char *gen_buf = NULL; const BIGNUM *order = NULL, *cofactor = NULL; const unsigned char *seed; - size_t seed_len = 0; + size_t seed_len = 0, gen_buf_len = 0; static const char *gen_compressed = "Generator (compressed):"; static const char *gen_uncompressed = "Generator (uncompressed):"; @@ -112,6 +113,7 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off) goto err; } } else { + const char *form_str; /* explicit parameters */ int is_char_two = 0; point_conversion_form_t form; @@ -144,7 +146,8 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off) form = EC_GROUP_get_point_conversion_form(x); - if ((gen = EC_POINT_point2bn(x, point, form, NULL, ctx)) == NULL) { + gen_buf_len = EC_POINT_point2buf(x, point, form, &gen_buf, ctx); + if (gen_buf_len == 0) { reason = ERR_R_EC_LIB; goto err; } @@ -185,22 +188,18 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off) goto err; if ((b != NULL) && !ASN1_bn_print(bp, "B: ", b, NULL, off)) goto err; - if (form == POINT_CONVERSION_COMPRESSED) { - if ((gen != NULL) && !ASN1_bn_print(bp, gen_compressed, gen, - NULL, off)) - goto err; - } else if (form == POINT_CONVERSION_UNCOMPRESSED) { - if ((gen != NULL) && !ASN1_bn_print(bp, gen_uncompressed, gen, - NULL, off)) - goto err; - } else { /* form == POINT_CONVERSION_HYBRID */ - if ((gen != NULL) && !ASN1_bn_print(bp, gen_hybrid, gen, - NULL, off)) - goto err; - } - if ((order != NULL) && !ASN1_bn_print(bp, "Order: ", order, - NULL, off)) + if (form == POINT_CONVERSION_COMPRESSED) + form_str = gen_compressed; + else if (form == POINT_CONVERSION_UNCOMPRESSED) + form_str = gen_uncompressed; + else + form_str = gen_hybrid; + if (gen_buf != NULL + && !print_bin(bp, form_str, gen_buf, gen_buf_len, off)) + goto err; + + if ((order != NULL) && !ASN1_bn_print(bp, "Order: ", order, NULL, off)) goto err; if ((cofactor != NULL) && !ASN1_bn_print(bp, "Cofactor: ", cofactor, NULL, off)) @@ -215,7 +214,7 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off) BN_free(p); BN_free(a); BN_free(b); - BN_free(gen); + OPENSSL_clear_free(gen_buf, gen_buf_len); BN_CTX_free(ctx); return ret; } diff --git a/doc/man3/EC_POINT_new.pod b/doc/man3/EC_POINT_new.pod index 83b61feb7f..fb247507e5 100644 --- a/doc/man3/EC_POINT_new.pod +++ b/doc/man3/EC_POINT_new.pod @@ -55,11 +55,6 @@ EC_POINT_hex2point unsigned char **pbuf, BN_CTX *ctx); int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, const unsigned char *buf, size_t len, BN_CTX *ctx); - BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *p, - point_conversion_form_t form, BIGNUM *bn, - BN_CTX *ctx); - EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, const BIGNUM *bn, - EC_POINT *p, BN_CTX *ctx); char *EC_POINT_point2hex(const EC_GROUP *group, const EC_POINT *p, point_conversion_form_t form, BN_CTX *ctx); EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, const char *hex, @@ -96,6 +91,11 @@ Deprecated since OpenSSL 3.0: EC_POINT *p, const BIGNUM *x, int y_bit, BN_CTX *ctx); + BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *p, + point_conversion_form_t form, BIGNUM *bn, + BN_CTX *ctx); + EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, const BIGNUM *bn, + EC_POINT *p, BN_CTX *ctx); =head1 DESCRIPTION @@ -257,7 +257,9 @@ EC_POINT_get_Jprojective_coordinates_GFp(), EC_POINT_set_affine_coordinates_GFp(), EC_POINT_get_affine_coordinates_GFp(), EC_POINT_set_compressed_coordinates_GFp(), EC_POINT_set_affine_coordinates_GF2m(), EC_POINT_get_affine_coordinates_GF2m(), -EC_POINT_set_compressed_coordinates_GF2m() were deprecated in OpenSSL 3.0. +EC_POINT_set_compressed_coordinates_GF2m(), +EC_POINT_point2bn(), and EC_POINT_bn2point() were deprecated in OpenSSL 3.0. + B<EC_POINT_set_affine_coordinates>, B<EC_POINT_get_affine_coordinates>, and B<EC_POINT_set_compressed_coordinates> were diff --git a/doc/man3/OPENSSL_hexchar2int.pod b/doc/man3/OPENSSL_hexchar2int.pod index bfb3c709ab..a112815127 100644 --- a/doc/man3/OPENSSL_hexchar2int.pod +++ b/doc/man3/OPENSSL_hexchar2int.pod @@ -26,8 +26,8 @@ equivalent. OPENSSL_hexstr2buf_ex() decodes the hex string B<str> and places the resulting string of bytes in the given I<buf>. -The character I<sep> is the separator between the bytes, which is normally ':', -Setting this to '\0' means that there is no seperator. +The character I<sep> is the separator between the bytes, setting this to '\0' +means that there is no separator. I<buf_n> gives the size of the buffer. If I<buflen> is not NULL, it is filled in with the result length. To find out how large the result will be, call this function with NULL @@ -36,22 +36,24 @@ Colons between two-character hex "bytes" are accepted and ignored. An odd number of hex digits is an error. OPENSSL_hexstr2buf() does the same thing as OPENSSL_hexstr2buf_ex(), -but allocates the space for the result, and returns the result. +but allocates the space for the result, and returns the result. It uses a +default separator of ':'. The memory is allocated by calling OPENSSL_malloc() and should be released by calling OPENSSL_free(). OPENSSL_buf2hexstr_ex() encodes the contents of the given I<buf> with length I<buflen> and places the resulting hexadecimal character string in the given I<str>. -The character I<sep> is the separator between the bytes, which is normally ':', -Setting this to '\0' means that there is no seperator. +The character I<sep> is the separator between the bytes, setting this to '\0' +means that there is no separator. I<str_n> gives the size of the of the string buffer. If I<strlen> is not NULL, it is filled in with the result length. To find out how large the result will be, call this function with NULL for I<str>. OPENSSL_buf2hexstr() does the same thing as OPENSSL_buf2hexstr_ex(), -but allocates the space for the result, and returns the result. +but allocates the space for the result, and returns the result. It uses a +default separator of ':'. The memory is allocated by calling OPENSSL_malloc() and should be released by calling OPENSSL_free(). diff --git a/include/openssl/ec.h b/include/openssl/ec.h index 0d41ef8297..2933d7503a 100644 --- a/include/openssl/ec.h +++ b/include/openssl/ec.h @@ -708,10 +708,16 @@ size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, unsigned char **pbuf, BN_CTX *ctx); /* other interfaces to point2oct/oct2point: */ -BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, - point_conversion_form_t form, BIGNUM *, BN_CTX *); -EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, - EC_POINT *, BN_CTX *); +# ifndef OPENSSL_NO_DEPRECATED_3_0 +OSSL_DEPRECATEDIN_3_0 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, + const EC_POINT *, + point_conversion_form_t form, + BIGNUM *, BN_CTX *); +OSSL_DEPRECATEDIN_3_0 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, + const BIGNUM *, + EC_POINT *, BN_CTX *); +# endif /* OPENSSL_NO_DEPRECATED_3_0 */ + char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, BN_CTX *); EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, diff --git a/providers/implementations/encode_decode/encode_key2text.c b/providers/implementations/encode_decode/encode_key2text.c index 4d33d869ed..2ac5046bf3 100644 --- a/providers/implementations/encode_decode/encode_key2text.c +++ b/providers/implementations/encode_decode/encode_key2text.c @@ -378,18 +378,17 @@ static int ec_param_explicit_curve_to_text(BIO *out, const EC_GROUP *group, static int ec_param_explicit_gen_to_text(BIO *out, const EC_GROUP *group, BN_CTX *ctx) { + int ret; + size_t buflen; + point_conversion_form_t form; const EC_POINT *point = NULL; - BIGNUM *gen = NULL; const char *glabel = NULL; - point_conversion_form_t form; + unsigned char *buf = NULL; form = EC_GROUP_get_point_conversion_form(group); point = EC_GROUP_get0_generator(group); - gen = BN_CTX_get(ctx); - if (gen == NULL - || point == NULL - || EC_POINT_point2bn(group, point, form, gen, ctx) == NULL) + if (point == NULL) return 0; switch (form) { @@ -405,7 +404,14 @@ static int ec_param_explicit_gen_to_text(BIO *out, const EC_GROUP *group, default: return 0; } - return print_labeled_bignum(out, glabel, gen); + + buflen = EC_POINT_point2buf(group, point, form, &buf, ctx); + if (buflen == 0) + return 0; + + ret = print_labeled_buf(out, glabel, buf, buflen); + OPENSSL_clear_free(buf, buflen); + return ret; } /* Print explicit parameters */ diff --git a/util/libcrypto.num b/util/libcrypto.num index 1c6b17c629..e25e52442d 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -2953,7 +2953,7 @@ BIO_dgram_non_fatal_error 3016 3_0_0 EXIST::FUNCTION:DGRAM OCSP_request_is_signed 3017 3_0_0 EXIST::FUNCTION:OCSP i2d_BASIC_CONSTRAINTS 3018 3_0_0 EXIST::FUNCTION: EC_KEY_get_method 3019 3_0_0 EXIST::FUNCTION:EC -EC_POINT_bn2point 3021 3_0_0 EXIST::FUNCTION:EC +EC_POINT_bn2point 3021 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,EC PBE2PARAM_it 3022 3_0_0 EXIST::FUNCTION: BN_rand 3023 3_0_0 EXIST::FUNCTION: ASN1_TYPE_unpack_sequence 3024 3_0_0 EXIST::FUNCTION: @@ -3381,7 +3381,7 @@ BIO_method_type 3451 3_0_0 EXIST::FUNCTION: ECPKParameters_print 3452 3_0_0 EXIST::FUNCTION:EC EVP_rc4 3453 3_0_0 EXIST::FUNCTION:RC4 CMS_data_create 3454 3_0_0 EXIST::FUNCTION:CMS -EC_POINT_point2bn 3455 3_0_0 EXIST::FUNCTION:EC +EC_POINT_point2bn 3455 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,EC CMS_unsigned_get0_data_by_OBJ 3456 3_0_0 EXIST::FUNCTION:CMS ASN1_OCTET_STRING_cmp 3457 3_0_0 EXIST::FUNCTION: X509_NAME_print_ex 3458 3_0_0 EXIST::FUNCTION: |