Deprecate EC_POINT_bn2point and EC_POINT_point2bn.
authorShane Lontis <shane.lontis@oracle.com>
Mon, 2 Nov 2020 02:46:38 +0000 (12:46 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Mon, 7 Dec 2020 07:15:39 +0000 (17:15 +1000)
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)

apps/ecparam.c
crypto/ec/build.info
crypto/ec/ec_deprecated.c [new file with mode: 0644]
crypto/ec/ec_print.c
crypto/ec/eck_prn.c
doc/man3/EC_POINT_new.pod
doc/man3/OPENSSL_hexchar2int.pod
include/openssl/ec.h
providers/implementations/encode_decode/encode_key2text.c
util/libcrypto.num

index b51a61adc0c3d3f4ba9013e1b274744833d97031..3e20be24b282466a5241364955780b2b1ee7eda6 100644 (file)
@@ -294,7 +294,6 @@ int ecparam_main(int argc, char **argv)
             goto end;
         }
         BIO_printf(bio_err, "ok\n");
-
     }
 
     if (outformat == FORMAT_ASN1 && genkey)
index 496a932e4c6fc9f60d19fcd0707ec3596fa4037f..63512565bac99e384e03fcc25dc90aeeab84f845 100644 (file)
@@ -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 (file)
index 0000000..cd2eec8
--- /dev/null
@@ -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 */
index 4fb76fe74e19272dd2e31ecb4e84c0799a88edd7..d791e15b4839ddf74956a5f4d39444696378774e 100644 (file)
@@ -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;
 }
index 7b892ae403f10003c05f0e13bfaa8a654394280e..20c6065a31c960c9acfd5c81f12c7b96dec742cb 100644 (file)
@@ -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;
 }
index 83b61feb7fa8807f569e14ef415719b7176dd81c..fb247507e5cbef7d07891f9e178e7707bbe42f5a 100644 (file)
@@ -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
index bfb3c709ab6e56d8acd5d2ef99043241ece8d9ff..a112815127bd1346045fddbe1049e9a4a5abd95b 100644 (file)
@@ -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().
 
index 0d41ef829758c18b208b34ffeda30852abc8c8cf..2933d7503a1bb04cd106a63fe920408b7f63dc29 100644 (file)
@@ -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 *,
index 4d33d869ed6e3b4d0d0021d4c7b4b9a41ee0419d..2ac5046bf31df215fd1ea476e70da2decfbc0c31 100644 (file)
@@ -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 */
index 1c6b17c629a74b97b11a95c4634e16e8e7aecf0f..e25e52442d1053c153bcd58bb88ba75ef36bbe65 100644 (file)
@@ -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: