goto end;
}
BIO_printf(bio_err, "ok\n");
-
}
if (outformat == FORMAT_ASN1 && genkey)
$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 \
--- /dev/null
+/*
+ * 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 */
* 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()) */
}
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;
}
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):";
goto err;
}
} else {
+ const char *form_str;
/* explicit parameters */
int is_char_two = 0;
point_conversion_form_t form;
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;
}
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))
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;
}
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,
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
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
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
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().
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 *,
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) {
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 */
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:
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: