|
||||
File indexing completed on 2025-01-18 10:05:42
0001 /* 0002 * Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved. 0003 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved 0004 * 0005 * Licensed under the Apache License 2.0 (the "License"). You may not use 0006 * this file except in compliance with the License. You can obtain a copy 0007 * in the file LICENSE in the source distribution or at 0008 * https://www.openssl.org/source/license.html 0009 */ 0010 0011 #ifndef OPENSSL_EC_H 0012 # define OPENSSL_EC_H 0013 # pragma once 0014 0015 # include <openssl/macros.h> 0016 # ifndef OPENSSL_NO_DEPRECATED_3_0 0017 # define HEADER_EC_H 0018 # endif 0019 0020 # include <openssl/opensslconf.h> 0021 # include <openssl/types.h> 0022 0023 # include <string.h> 0024 0025 # ifdef __cplusplus 0026 extern "C" { 0027 # endif 0028 0029 /* Values for EVP_PKEY_CTX_set_ec_param_enc() */ 0030 # define OPENSSL_EC_EXPLICIT_CURVE 0x000 0031 # define OPENSSL_EC_NAMED_CURVE 0x001 0032 0033 int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid); 0034 int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc); 0035 int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx, int cofactor_mode); 0036 int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx); 0037 0038 int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX *ctx, int kdf); 0039 int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX *ctx); 0040 0041 int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); 0042 int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD **md); 0043 0044 int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int len); 0045 int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int *len); 0046 0047 int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm, 0048 int len); 0049 # ifndef OPENSSL_NO_DEPRECATED_3_0 0050 OSSL_DEPRECATEDIN_3_0 0051 int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm); 0052 # endif 0053 0054 # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1) 0055 # define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2) 0056 # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3) 0057 # define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4) 0058 # define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5) 0059 # define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6) 0060 # define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7) 0061 # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8) 0062 # define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9) 0063 # define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10) 0064 0065 /* KDF types */ 0066 # define EVP_PKEY_ECDH_KDF_NONE 1 0067 # define EVP_PKEY_ECDH_KDF_X9_63 2 0068 /* 0069 * The old name for EVP_PKEY_ECDH_KDF_X9_63 0070 * The ECDH KDF specification has been mistakenly attributed to ANSI X9.62, 0071 * it is actually specified in ANSI X9.63. 0072 * This identifier is retained for backwards compatibility 0073 */ 0074 # define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63 0075 0076 /** Enum for the point conversion form as defined in X9.62 (ECDSA) 0077 * for the encoding of a elliptic curve point (x,y) */ 0078 typedef enum { 0079 /** the point is encoded as z||x, where the octet z specifies 0080 * which solution of the quadratic equation y is */ 0081 POINT_CONVERSION_COMPRESSED = 2, 0082 /** the point is encoded as z||x||y, where z is the octet 0x04 */ 0083 POINT_CONVERSION_UNCOMPRESSED = 4, 0084 /** the point is encoded as z||x||y, where the octet z specifies 0085 * which solution of the quadratic equation y is */ 0086 POINT_CONVERSION_HYBRID = 6 0087 } point_conversion_form_t; 0088 0089 const char *OSSL_EC_curve_nid2name(int nid); 0090 0091 # ifndef OPENSSL_NO_STDIO 0092 # include <stdio.h> 0093 # endif 0094 # ifndef OPENSSL_NO_EC 0095 # include <openssl/asn1.h> 0096 # include <openssl/symhacks.h> 0097 # ifndef OPENSSL_NO_DEPRECATED_1_1_0 0098 # include <openssl/bn.h> 0099 # endif 0100 # include <openssl/ecerr.h> 0101 0102 # ifndef OPENSSL_ECC_MAX_FIELD_BITS 0103 # define OPENSSL_ECC_MAX_FIELD_BITS 661 0104 # endif 0105 0106 # include <openssl/params.h> 0107 # ifndef OPENSSL_NO_DEPRECATED_3_0 0108 typedef struct ec_method_st EC_METHOD; 0109 # endif 0110 typedef struct ec_group_st EC_GROUP; 0111 typedef struct ec_point_st EC_POINT; 0112 typedef struct ecpk_parameters_st ECPKPARAMETERS; 0113 typedef struct ec_parameters_st ECPARAMETERS; 0114 0115 /********************************************************************/ 0116 /* EC_METHODs for curves over GF(p) */ 0117 /********************************************************************/ 0118 0119 # ifndef OPENSSL_NO_DEPRECATED_3_0 0120 /** Returns the basic GFp ec methods which provides the basis for the 0121 * optimized methods. 0122 * \return EC_METHOD object 0123 */ 0124 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_simple_method(void); 0125 0126 /** Returns GFp methods using montgomery multiplication. 0127 * \return EC_METHOD object 0128 */ 0129 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_mont_method(void); 0130 0131 /** Returns GFp methods using optimized methods for NIST recommended curves 0132 * \return EC_METHOD object 0133 */ 0134 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nist_method(void); 0135 0136 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 0137 /** Returns 64-bit optimized methods for nistp224 0138 * \return EC_METHOD object 0139 */ 0140 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp224_method(void); 0141 0142 /** Returns 64-bit optimized methods for nistp256 0143 * \return EC_METHOD object 0144 */ 0145 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp256_method(void); 0146 0147 /** Returns 64-bit optimized methods for nistp521 0148 * \return EC_METHOD object 0149 */ 0150 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp521_method(void); 0151 # endif /* OPENSSL_NO_EC_NISTP_64_GCC_128 */ 0152 0153 # ifndef OPENSSL_NO_EC2M 0154 /********************************************************************/ 0155 /* EC_METHOD for curves over GF(2^m) */ 0156 /********************************************************************/ 0157 0158 /** Returns the basic GF2m ec method 0159 * \return EC_METHOD object 0160 */ 0161 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GF2m_simple_method(void); 0162 0163 # endif 0164 0165 /********************************************************************/ 0166 /* EC_GROUP functions */ 0167 /********************************************************************/ 0168 0169 /** 0170 * Creates a new EC_GROUP object 0171 * \param meth EC_METHOD to use 0172 * \return newly created EC_GROUP object or NULL in case of an error. 0173 */ 0174 OSSL_DEPRECATEDIN_3_0 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); 0175 0176 /** Clears and frees a EC_GROUP object 0177 * \param group EC_GROUP object to be cleared and freed. 0178 */ 0179 OSSL_DEPRECATEDIN_3_0 void EC_GROUP_clear_free(EC_GROUP *group); 0180 0181 /** Returns the EC_METHOD of the EC_GROUP object. 0182 * \param group EC_GROUP object 0183 * \return EC_METHOD used in this EC_GROUP object. 0184 */ 0185 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); 0186 0187 /** Returns the field type of the EC_METHOD. 0188 * \param meth EC_METHOD object 0189 * \return NID of the underlying field type OID. 0190 */ 0191 OSSL_DEPRECATEDIN_3_0 int EC_METHOD_get_field_type(const EC_METHOD *meth); 0192 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0193 0194 /** Frees a EC_GROUP object 0195 * \param group EC_GROUP object to be freed. 0196 */ 0197 void EC_GROUP_free(EC_GROUP *group); 0198 0199 /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD. 0200 * \param dst destination EC_GROUP object 0201 * \param src source EC_GROUP object 0202 * \return 1 on success and 0 if an error occurred. 0203 */ 0204 int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src); 0205 0206 /** Creates a new EC_GROUP object and copies the content 0207 * form src to the newly created EC_KEY object 0208 * \param src source EC_GROUP object 0209 * \return newly created EC_GROUP object or NULL in case of an error. 0210 */ 0211 EC_GROUP *EC_GROUP_dup(const EC_GROUP *src); 0212 0213 /** Sets the generator and its order/cofactor of a EC_GROUP object. 0214 * \param group EC_GROUP object 0215 * \param generator EC_POINT object with the generator. 0216 * \param order the order of the group generated by the generator. 0217 * \param cofactor the index of the sub-group generated by the generator 0218 * in the group of all points on the elliptic curve. 0219 * \return 1 on success and 0 if an error occurred 0220 */ 0221 int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, 0222 const BIGNUM *order, const BIGNUM *cofactor); 0223 0224 /** Returns the generator of a EC_GROUP object. 0225 * \param group EC_GROUP object 0226 * \return the currently used generator (possibly NULL). 0227 */ 0228 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); 0229 0230 /** Returns the montgomery data for order(Generator) 0231 * \param group EC_GROUP object 0232 * \return the currently used montgomery data (possibly NULL). 0233 */ 0234 BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group); 0235 0236 /** Gets the order of a EC_GROUP 0237 * \param group EC_GROUP object 0238 * \param order BIGNUM to which the order is copied 0239 * \param ctx unused 0240 * \return 1 on success and 0 if an error occurred 0241 */ 0242 int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); 0243 0244 /** Gets the order of an EC_GROUP 0245 * \param group EC_GROUP object 0246 * \return the group order 0247 */ 0248 const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); 0249 0250 /** Gets the number of bits of the order of an EC_GROUP 0251 * \param group EC_GROUP object 0252 * \return number of bits of group order. 0253 */ 0254 int EC_GROUP_order_bits(const EC_GROUP *group); 0255 0256 /** Gets the cofactor of a EC_GROUP 0257 * \param group EC_GROUP object 0258 * \param cofactor BIGNUM to which the cofactor is copied 0259 * \param ctx unused 0260 * \return 1 on success and 0 if an error occurred 0261 */ 0262 int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, 0263 BN_CTX *ctx); 0264 0265 /** Gets the cofactor of an EC_GROUP 0266 * \param group EC_GROUP object 0267 * \return the group cofactor 0268 */ 0269 const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); 0270 0271 /** Sets the name of a EC_GROUP object 0272 * \param group EC_GROUP object 0273 * \param nid NID of the curve name OID 0274 */ 0275 void EC_GROUP_set_curve_name(EC_GROUP *group, int nid); 0276 0277 /** Returns the curve name of a EC_GROUP object 0278 * \param group EC_GROUP object 0279 * \return NID of the curve name OID or 0 if not set. 0280 */ 0281 int EC_GROUP_get_curve_name(const EC_GROUP *group); 0282 0283 /** Gets the field of an EC_GROUP 0284 * \param group EC_GROUP object 0285 * \return the group field 0286 */ 0287 const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group); 0288 0289 /** Returns the field type of the EC_GROUP. 0290 * \param group EC_GROUP object 0291 * \return NID of the underlying field type OID. 0292 */ 0293 int EC_GROUP_get_field_type(const EC_GROUP *group); 0294 0295 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); 0296 int EC_GROUP_get_asn1_flag(const EC_GROUP *group); 0297 0298 void EC_GROUP_set_point_conversion_form(EC_GROUP *group, 0299 point_conversion_form_t form); 0300 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); 0301 0302 unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); 0303 size_t EC_GROUP_get_seed_len(const EC_GROUP *); 0304 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); 0305 0306 /** Sets the parameters of an ec curve defined by y^2 = x^3 + a*x + b (for GFp) 0307 * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) 0308 * \param group EC_GROUP object 0309 * \param p BIGNUM with the prime number (GFp) or the polynomial 0310 * defining the underlying field (GF2m) 0311 * \param a BIGNUM with parameter a of the equation 0312 * \param b BIGNUM with parameter b of the equation 0313 * \param ctx BN_CTX object (optional) 0314 * \return 1 on success and 0 if an error occurred 0315 */ 0316 int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, 0317 const BIGNUM *b, BN_CTX *ctx); 0318 0319 /** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp) 0320 * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) 0321 * \param group EC_GROUP object 0322 * \param p BIGNUM with the prime number (GFp) or the polynomial 0323 * defining the underlying field (GF2m) 0324 * \param a BIGNUM for parameter a of the equation 0325 * \param b BIGNUM for parameter b of the equation 0326 * \param ctx BN_CTX object (optional) 0327 * \return 1 on success and 0 if an error occurred 0328 */ 0329 int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, 0330 BN_CTX *ctx); 0331 0332 # ifndef OPENSSL_NO_DEPRECATED_3_0 0333 /** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve 0334 * \param group EC_GROUP object 0335 * \param p BIGNUM with the prime number (GFp) or the polynomial 0336 * defining the underlying field (GF2m) 0337 * \param a BIGNUM with parameter a of the equation 0338 * \param b BIGNUM with parameter b of the equation 0339 * \param ctx BN_CTX object (optional) 0340 * \return 1 on success and 0 if an error occurred 0341 */ 0342 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_set_curve_GFp(EC_GROUP *group, 0343 const BIGNUM *p, 0344 const BIGNUM *a, 0345 const BIGNUM *b, 0346 BN_CTX *ctx); 0347 0348 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve 0349 * \param group EC_GROUP object 0350 * \param p BIGNUM with the prime number (GFp) or the polynomial 0351 * defining the underlying field (GF2m) 0352 * \param a BIGNUM for parameter a of the equation 0353 * \param b BIGNUM for parameter b of the equation 0354 * \param ctx BN_CTX object (optional) 0355 * \return 1 on success and 0 if an error occurred 0356 */ 0357 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_get_curve_GFp(const EC_GROUP *group, 0358 BIGNUM *p, 0359 BIGNUM *a, BIGNUM *b, 0360 BN_CTX *ctx); 0361 0362 # ifndef OPENSSL_NO_EC2M 0363 /** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve 0364 * \param group EC_GROUP object 0365 * \param p BIGNUM with the prime number (GFp) or the polynomial 0366 * defining the underlying field (GF2m) 0367 * \param a BIGNUM with parameter a of the equation 0368 * \param b BIGNUM with parameter b of the equation 0369 * \param ctx BN_CTX object (optional) 0370 * \return 1 on success and 0 if an error occurred 0371 */ 0372 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_set_curve_GF2m(EC_GROUP *group, 0373 const BIGNUM *p, 0374 const BIGNUM *a, 0375 const BIGNUM *b, 0376 BN_CTX *ctx); 0377 0378 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve 0379 * \param group EC_GROUP object 0380 * \param p BIGNUM with the prime number (GFp) or the polynomial 0381 * defining the underlying field (GF2m) 0382 * \param a BIGNUM for parameter a of the equation 0383 * \param b BIGNUM for parameter b of the equation 0384 * \param ctx BN_CTX object (optional) 0385 * \return 1 on success and 0 if an error occurred 0386 */ 0387 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, 0388 BIGNUM *p, 0389 BIGNUM *a, BIGNUM *b, 0390 BN_CTX *ctx); 0391 # endif /* OPENSSL_NO_EC2M */ 0392 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0393 0394 /** Returns the number of bits needed to represent a field element 0395 * \param group EC_GROUP object 0396 * \return number of bits needed to represent a field element 0397 */ 0398 int EC_GROUP_get_degree(const EC_GROUP *group); 0399 0400 /** Checks whether the parameter in the EC_GROUP define a valid ec group 0401 * \param group EC_GROUP object 0402 * \param ctx BN_CTX object (optional) 0403 * \return 1 if group is a valid ec group and 0 otherwise 0404 */ 0405 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); 0406 0407 /** Checks whether the discriminant of the elliptic curve is zero or not 0408 * \param group EC_GROUP object 0409 * \param ctx BN_CTX object (optional) 0410 * \return 1 if the discriminant is not zero and 0 otherwise 0411 */ 0412 int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx); 0413 0414 /** Compares two EC_GROUP objects 0415 * \param a first EC_GROUP object 0416 * \param b second EC_GROUP object 0417 * \param ctx BN_CTX object (optional) 0418 * \return 0 if the groups are equal, 1 if not, or -1 on error 0419 */ 0420 int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx); 0421 0422 /* 0423 * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after 0424 * choosing an appropriate EC_METHOD 0425 */ 0426 0427 /** Creates a new EC_GROUP object with the specified parameters defined 0428 * over GFp (defined by the equation y^2 = x^3 + a*x + b) 0429 * \param p BIGNUM with the prime number 0430 * \param a BIGNUM with the parameter a of the equation 0431 * \param b BIGNUM with the parameter b of the equation 0432 * \param ctx BN_CTX object (optional) 0433 * \return newly created EC_GROUP object with the specified parameters 0434 */ 0435 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, 0436 const BIGNUM *b, BN_CTX *ctx); 0437 # ifndef OPENSSL_NO_EC2M 0438 /** Creates a new EC_GROUP object with the specified parameters defined 0439 * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b) 0440 * \param p BIGNUM with the polynomial defining the underlying field 0441 * \param a BIGNUM with the parameter a of the equation 0442 * \param b BIGNUM with the parameter b of the equation 0443 * \param ctx BN_CTX object (optional) 0444 * \return newly created EC_GROUP object with the specified parameters 0445 */ 0446 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, 0447 const BIGNUM *b, BN_CTX *ctx); 0448 # endif 0449 0450 /** 0451 * Creates a EC_GROUP object with a curve specified by parameters. 0452 * The parameters may be explicit or a named curve, 0453 * \param params A list of parameters describing the group. 0454 * \param libctx The associated library context or NULL for the default 0455 * context 0456 * \param propq A property query string 0457 * \return newly created EC_GROUP object with specified parameters or NULL 0458 * if an error occurred 0459 */ 0460 EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[], 0461 OSSL_LIB_CTX *libctx, const char *propq); 0462 0463 /** 0464 * Creates an OSSL_PARAM array with the parameters describing the given 0465 * EC_GROUP. 0466 * The resulting parameters may contain an explicit or a named curve depending 0467 * on the EC_GROUP. 0468 * \param group pointer to the EC_GROUP object 0469 * \param libctx The associated library context or NULL for the default 0470 * context 0471 * \param propq A property query string 0472 * \param bnctx BN_CTX object (optional) 0473 * \return newly created OSSL_PARAM array with the parameters 0474 * describing the given EC_GROUP or NULL if an error occurred 0475 */ 0476 OSSL_PARAM *EC_GROUP_to_params(const EC_GROUP *group, OSSL_LIB_CTX *libctx, 0477 const char *propq, BN_CTX *bnctx); 0478 0479 /** 0480 * Creates a EC_GROUP object with a curve specified by a NID 0481 * \param libctx The associated library context or NULL for the default 0482 * context 0483 * \param propq A property query string 0484 * \param nid NID of the OID of the curve name 0485 * \return newly created EC_GROUP object with specified curve or NULL 0486 * if an error occurred 0487 */ 0488 EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq, 0489 int nid); 0490 0491 /** 0492 * Creates a EC_GROUP object with a curve specified by a NID. Same as 0493 * EC_GROUP_new_by_curve_name_ex but the libctx and propq are always 0494 * NULL. 0495 * \param nid NID of the OID of the curve name 0496 * \return newly created EC_GROUP object with specified curve or NULL 0497 * if an error occurred 0498 */ 0499 EC_GROUP *EC_GROUP_new_by_curve_name(int nid); 0500 0501 /** Creates a new EC_GROUP object from an ECPARAMETERS object 0502 * \param params pointer to the ECPARAMETERS object 0503 * \return newly created EC_GROUP object with specified curve or NULL 0504 * if an error occurred 0505 */ 0506 EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); 0507 0508 /** Creates an ECPARAMETERS object for the given EC_GROUP object. 0509 * \param group pointer to the EC_GROUP object 0510 * \param params pointer to an existing ECPARAMETERS object or NULL 0511 * \return pointer to the new ECPARAMETERS object or NULL 0512 * if an error occurred. 0513 */ 0514 ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, 0515 ECPARAMETERS *params); 0516 0517 /** Creates a new EC_GROUP object from an ECPKPARAMETERS object 0518 * \param params pointer to an existing ECPKPARAMETERS object, or NULL 0519 * \return newly created EC_GROUP object with specified curve, or NULL 0520 * if an error occurred 0521 */ 0522 EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); 0523 0524 /** Creates an ECPKPARAMETERS object for the given EC_GROUP object. 0525 * \param group pointer to the EC_GROUP object 0526 * \param params pointer to an existing ECPKPARAMETERS object or NULL 0527 * \return pointer to the new ECPKPARAMETERS object or NULL 0528 * if an error occurred. 0529 */ 0530 ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, 0531 ECPKPARAMETERS *params); 0532 0533 /********************************************************************/ 0534 /* handling of internal curves */ 0535 /********************************************************************/ 0536 0537 typedef struct { 0538 int nid; 0539 const char *comment; 0540 } EC_builtin_curve; 0541 0542 /* 0543 * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all 0544 * available curves or zero if a error occurred. In case r is not zero, 0545 * nitems EC_builtin_curve structures are filled with the data of the first 0546 * nitems internal groups 0547 */ 0548 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 0549 0550 const char *EC_curve_nid2nist(int nid); 0551 int EC_curve_nist2nid(const char *name); 0552 int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only, 0553 BN_CTX *ctx); 0554 0555 /********************************************************************/ 0556 /* EC_POINT functions */ 0557 /********************************************************************/ 0558 0559 /** Creates a new EC_POINT object for the specified EC_GROUP 0560 * \param group EC_GROUP the underlying EC_GROUP object 0561 * \return newly created EC_POINT object or NULL if an error occurred 0562 */ 0563 EC_POINT *EC_POINT_new(const EC_GROUP *group); 0564 0565 /** Frees a EC_POINT object 0566 * \param point EC_POINT object to be freed 0567 */ 0568 void EC_POINT_free(EC_POINT *point); 0569 0570 /** Clears and frees a EC_POINT object 0571 * \param point EC_POINT object to be cleared and freed 0572 */ 0573 void EC_POINT_clear_free(EC_POINT *point); 0574 0575 /** Copies EC_POINT object 0576 * \param dst destination EC_POINT object 0577 * \param src source EC_POINT object 0578 * \return 1 on success and 0 if an error occurred 0579 */ 0580 int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); 0581 0582 /** Creates a new EC_POINT object and copies the content of the supplied 0583 * EC_POINT 0584 * \param src source EC_POINT object 0585 * \param group underlying the EC_GROUP object 0586 * \return newly created EC_POINT object or NULL if an error occurred 0587 */ 0588 EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); 0589 0590 /** Sets a point to infinity (neutral element) 0591 * \param group underlying EC_GROUP object 0592 * \param point EC_POINT to set to infinity 0593 * \return 1 on success and 0 if an error occurred 0594 */ 0595 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); 0596 0597 # ifndef OPENSSL_NO_DEPRECATED_3_0 0598 /** Returns the EC_METHOD used in EC_POINT object 0599 * \param point EC_POINT object 0600 * \return the EC_METHOD used 0601 */ 0602 OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); 0603 0604 /** Sets the jacobian projective coordinates of a EC_POINT over GFp 0605 * \param group underlying EC_GROUP object 0606 * \param p EC_POINT object 0607 * \param x BIGNUM with the x-coordinate 0608 * \param y BIGNUM with the y-coordinate 0609 * \param z BIGNUM with the z-coordinate 0610 * \param ctx BN_CTX object (optional) 0611 * \return 1 on success and 0 if an error occurred 0612 */ 0613 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_Jprojective_coordinates_GFp 0614 (const EC_GROUP *group, EC_POINT *p, 0615 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, 0616 BN_CTX *ctx); 0617 0618 /** Gets the jacobian projective coordinates of a EC_POINT over GFp 0619 * \param group underlying EC_GROUP object 0620 * \param p EC_POINT object 0621 * \param x BIGNUM for the x-coordinate 0622 * \param y BIGNUM for the y-coordinate 0623 * \param z BIGNUM for the z-coordinate 0624 * \param ctx BN_CTX object (optional) 0625 * \return 1 on success and 0 if an error occurred 0626 */ 0627 OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_Jprojective_coordinates_GFp 0628 (const EC_GROUP *group, const EC_POINT *p, 0629 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); 0630 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0631 0632 /** Sets the affine coordinates of an EC_POINT 0633 * \param group underlying EC_GROUP object 0634 * \param p EC_POINT object 0635 * \param x BIGNUM with the x-coordinate 0636 * \param y BIGNUM with the y-coordinate 0637 * \param ctx BN_CTX object (optional) 0638 * \return 1 on success and 0 if an error occurred 0639 */ 0640 int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, 0641 const BIGNUM *x, const BIGNUM *y, 0642 BN_CTX *ctx); 0643 0644 /** Gets the affine coordinates of an EC_POINT. 0645 * \param group underlying EC_GROUP object 0646 * \param p EC_POINT object 0647 * \param x BIGNUM for the x-coordinate 0648 * \param y BIGNUM for the y-coordinate 0649 * \param ctx BN_CTX object (optional) 0650 * \return 1 on success and 0 if an error occurred 0651 */ 0652 int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, 0653 BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 0654 0655 # ifndef OPENSSL_NO_DEPRECATED_3_0 0656 /** Sets the affine coordinates of an EC_POINT. A synonym of 0657 * EC_POINT_set_affine_coordinates 0658 * \param group underlying EC_GROUP object 0659 * \param p EC_POINT object 0660 * \param x BIGNUM with the x-coordinate 0661 * \param y BIGNUM with the y-coordinate 0662 * \param ctx BN_CTX object (optional) 0663 * \return 1 on success and 0 if an error occurred 0664 */ 0665 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_affine_coordinates_GFp 0666 (const EC_GROUP *group, EC_POINT *p, 0667 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx); 0668 0669 /** Gets the affine coordinates of an EC_POINT. A synonym of 0670 * EC_POINT_get_affine_coordinates 0671 * \param group underlying EC_GROUP object 0672 * \param p EC_POINT object 0673 * \param x BIGNUM for the x-coordinate 0674 * \param y BIGNUM for the y-coordinate 0675 * \param ctx BN_CTX object (optional) 0676 * \return 1 on success and 0 if an error occurred 0677 */ 0678 OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_affine_coordinates_GFp 0679 (const EC_GROUP *group, const EC_POINT *p, 0680 BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 0681 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0682 0683 /** Sets the x9.62 compressed coordinates of a EC_POINT 0684 * \param group underlying EC_GROUP object 0685 * \param p EC_POINT object 0686 * \param x BIGNUM with x-coordinate 0687 * \param y_bit integer with the y-Bit (either 0 or 1) 0688 * \param ctx BN_CTX object (optional) 0689 * \return 1 on success and 0 if an error occurred 0690 */ 0691 int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, 0692 const BIGNUM *x, int y_bit, 0693 BN_CTX *ctx); 0694 0695 # ifndef OPENSSL_NO_DEPRECATED_3_0 0696 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of 0697 * EC_POINT_set_compressed_coordinates 0698 * \param group underlying EC_GROUP object 0699 * \param p EC_POINT object 0700 * \param x BIGNUM with x-coordinate 0701 * \param y_bit integer with the y-Bit (either 0 or 1) 0702 * \param ctx BN_CTX object (optional) 0703 * \return 1 on success and 0 if an error occurred 0704 */ 0705 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_compressed_coordinates_GFp 0706 (const EC_GROUP *group, EC_POINT *p, 0707 const BIGNUM *x, int y_bit, BN_CTX *ctx); 0708 # ifndef OPENSSL_NO_EC2M 0709 /** Sets the affine coordinates of an EC_POINT. A synonym of 0710 * EC_POINT_set_affine_coordinates 0711 * \param group underlying EC_GROUP object 0712 * \param p EC_POINT object 0713 * \param x BIGNUM with the x-coordinate 0714 * \param y BIGNUM with the y-coordinate 0715 * \param ctx BN_CTX object (optional) 0716 * \return 1 on success and 0 if an error occurred 0717 */ 0718 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_affine_coordinates_GF2m 0719 (const EC_GROUP *group, EC_POINT *p, 0720 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx); 0721 0722 /** Gets the affine coordinates of an EC_POINT. A synonym of 0723 * EC_POINT_get_affine_coordinates 0724 * \param group underlying EC_GROUP object 0725 * \param p EC_POINT object 0726 * \param x BIGNUM for the x-coordinate 0727 * \param y BIGNUM for the y-coordinate 0728 * \param ctx BN_CTX object (optional) 0729 * \return 1 on success and 0 if an error occurred 0730 */ 0731 OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_affine_coordinates_GF2m 0732 (const EC_GROUP *group, const EC_POINT *p, 0733 BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 0734 0735 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of 0736 * EC_POINT_set_compressed_coordinates 0737 * \param group underlying EC_GROUP object 0738 * \param p EC_POINT object 0739 * \param x BIGNUM with x-coordinate 0740 * \param y_bit integer with the y-Bit (either 0 or 1) 0741 * \param ctx BN_CTX object (optional) 0742 * \return 1 on success and 0 if an error occurred 0743 */ 0744 OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_compressed_coordinates_GF2m 0745 (const EC_GROUP *group, EC_POINT *p, 0746 const BIGNUM *x, int y_bit, BN_CTX *ctx); 0747 # endif 0748 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0749 0750 /** Encodes a EC_POINT object to a octet string 0751 * \param group underlying EC_GROUP object 0752 * \param p EC_POINT object 0753 * \param form point conversion form 0754 * \param buf memory buffer for the result. If NULL the function returns 0755 * required buffer size. 0756 * \param len length of the memory buffer 0757 * \param ctx BN_CTX object (optional) 0758 * \return the length of the encoded octet string or 0 if an error occurred 0759 */ 0760 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, 0761 point_conversion_form_t form, 0762 unsigned char *buf, size_t len, BN_CTX *ctx); 0763 0764 /** Decodes a EC_POINT from a octet string 0765 * \param group underlying EC_GROUP object 0766 * \param p EC_POINT object 0767 * \param buf memory buffer with the encoded ec point 0768 * \param len length of the encoded ec point 0769 * \param ctx BN_CTX object (optional) 0770 * \return 1 on success and 0 if an error occurred 0771 */ 0772 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, 0773 const unsigned char *buf, size_t len, BN_CTX *ctx); 0774 0775 /** Encodes an EC_POINT object to an allocated octet string 0776 * \param group underlying EC_GROUP object 0777 * \param point EC_POINT object 0778 * \param form point conversion form 0779 * \param pbuf returns pointer to allocated buffer 0780 * \param ctx BN_CTX object (optional) 0781 * \return the length of the encoded octet string or 0 if an error occurred 0782 */ 0783 size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, 0784 point_conversion_form_t form, 0785 unsigned char **pbuf, BN_CTX *ctx); 0786 0787 /* other interfaces to point2oct/oct2point: */ 0788 # ifndef OPENSSL_NO_DEPRECATED_3_0 0789 OSSL_DEPRECATEDIN_3_0 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, 0790 const EC_POINT *, 0791 point_conversion_form_t form, 0792 BIGNUM *, BN_CTX *); 0793 OSSL_DEPRECATEDIN_3_0 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, 0794 const BIGNUM *, 0795 EC_POINT *, BN_CTX *); 0796 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0797 0798 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, 0799 point_conversion_form_t form, BN_CTX *); 0800 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, 0801 EC_POINT *, BN_CTX *); 0802 0803 /********************************************************************/ 0804 /* functions for doing EC_POINT arithmetic */ 0805 /********************************************************************/ 0806 0807 /** Computes the sum of two EC_POINT 0808 * \param group underlying EC_GROUP object 0809 * \param r EC_POINT object for the result (r = a + b) 0810 * \param a EC_POINT object with the first summand 0811 * \param b EC_POINT object with the second summand 0812 * \param ctx BN_CTX object (optional) 0813 * \return 1 on success and 0 if an error occurred 0814 */ 0815 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 0816 const EC_POINT *b, BN_CTX *ctx); 0817 0818 /** Computes the double of a EC_POINT 0819 * \param group underlying EC_GROUP object 0820 * \param r EC_POINT object for the result (r = 2 * a) 0821 * \param a EC_POINT object 0822 * \param ctx BN_CTX object (optional) 0823 * \return 1 on success and 0 if an error occurred 0824 */ 0825 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 0826 BN_CTX *ctx); 0827 0828 /** Computes the inverse of a EC_POINT 0829 * \param group underlying EC_GROUP object 0830 * \param a EC_POINT object to be inverted (it's used for the result as well) 0831 * \param ctx BN_CTX object (optional) 0832 * \return 1 on success and 0 if an error occurred 0833 */ 0834 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); 0835 0836 /** Checks whether the point is the neutral element of the group 0837 * \param group the underlying EC_GROUP object 0838 * \param p EC_POINT object 0839 * \return 1 if the point is the neutral element and 0 otherwise 0840 */ 0841 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); 0842 0843 /** Checks whether the point is on the curve 0844 * \param group underlying EC_GROUP object 0845 * \param point EC_POINT object to check 0846 * \param ctx BN_CTX object (optional) 0847 * \return 1 if the point is on the curve, 0 if not, or -1 on error 0848 */ 0849 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, 0850 BN_CTX *ctx); 0851 0852 /** Compares two EC_POINTs 0853 * \param group underlying EC_GROUP object 0854 * \param a first EC_POINT object 0855 * \param b second EC_POINT object 0856 * \param ctx BN_CTX object (optional) 0857 * \return 1 if the points are not equal, 0 if they are, or -1 on error 0858 */ 0859 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, 0860 BN_CTX *ctx); 0861 0862 # ifndef OPENSSL_NO_DEPRECATED_3_0 0863 OSSL_DEPRECATEDIN_3_0 int EC_POINT_make_affine(const EC_GROUP *group, 0864 EC_POINT *point, BN_CTX *ctx); 0865 OSSL_DEPRECATEDIN_3_0 int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, 0866 EC_POINT *points[], BN_CTX *ctx); 0867 0868 /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i] 0869 * \param group underlying EC_GROUP object 0870 * \param r EC_POINT object for the result 0871 * \param n BIGNUM with the multiplier for the group generator (optional) 0872 * \param num number further summands 0873 * \param p array of size num of EC_POINT objects 0874 * \param m array of size num of BIGNUM objects 0875 * \param ctx BN_CTX object (optional) 0876 * \return 1 on success and 0 if an error occurred 0877 */ 0878 OSSL_DEPRECATEDIN_3_0 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, 0879 const BIGNUM *n, size_t num, 0880 const EC_POINT *p[], const BIGNUM *m[], 0881 BN_CTX *ctx); 0882 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0883 0884 /** Computes r = generator * n + q * m 0885 * \param group underlying EC_GROUP object 0886 * \param r EC_POINT object for the result 0887 * \param n BIGNUM with the multiplier for the group generator (optional) 0888 * \param q EC_POINT object with the first factor of the second summand 0889 * \param m BIGNUM with the second factor of the second summand 0890 * \param ctx BN_CTX object (optional) 0891 * \return 1 on success and 0 if an error occurred 0892 */ 0893 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, 0894 const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); 0895 0896 # ifndef OPENSSL_NO_DEPRECATED_3_0 0897 /** Stores multiples of generator for faster point multiplication 0898 * \param group EC_GROUP object 0899 * \param ctx BN_CTX object (optional) 0900 * \return 1 on success and 0 if an error occurred 0901 */ 0902 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); 0903 0904 /** Reports whether a precomputation has been done 0905 * \param group EC_GROUP object 0906 * \return 1 if a pre-computation has been done and 0 otherwise 0907 */ 0908 OSSL_DEPRECATEDIN_3_0 int EC_GROUP_have_precompute_mult(const EC_GROUP *group); 0909 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0910 0911 /********************************************************************/ 0912 /* ASN1 stuff */ 0913 /********************************************************************/ 0914 0915 DECLARE_ASN1_ITEM(ECPKPARAMETERS) 0916 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS) 0917 DECLARE_ASN1_ITEM(ECPARAMETERS) 0918 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) 0919 0920 /* 0921 * EC_GROUP_get_basis_type() returns the NID of the basis type used to 0922 * represent the field elements 0923 */ 0924 int EC_GROUP_get_basis_type(const EC_GROUP *); 0925 # ifndef OPENSSL_NO_EC2M 0926 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k); 0927 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, 0928 unsigned int *k2, unsigned int *k3); 0929 # endif 0930 0931 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); 0932 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); 0933 0934 # define d2i_ECPKParameters_bio(bp,x) \ 0935 ASN1_d2i_bio_of(EC_GROUP, NULL, d2i_ECPKParameters, bp, x) 0936 # define i2d_ECPKParameters_bio(bp,x) \ 0937 ASN1_i2d_bio_of(EC_GROUP, i2d_ECPKParameters, bp, x) 0938 # define d2i_ECPKParameters_fp(fp,x) \ 0939 (EC_GROUP *)ASN1_d2i_fp(NULL, (d2i_of_void *)d2i_ECPKParameters, (fp), \ 0940 (void **)(x)) 0941 # define i2d_ECPKParameters_fp(fp,x) \ 0942 ASN1_i2d_fp((i2d_of_void *)i2d_ECPKParameters, (fp), (void *)(x)) 0943 0944 # ifndef OPENSSL_NO_DEPRECATED_3_0 0945 OSSL_DEPRECATEDIN_3_0 int ECPKParameters_print(BIO *bp, const EC_GROUP *x, 0946 int off); 0947 # ifndef OPENSSL_NO_STDIO 0948 OSSL_DEPRECATEDIN_3_0 int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, 0949 int off); 0950 # endif 0951 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 0952 0953 /********************************************************************/ 0954 /* EC_KEY functions */ 0955 /********************************************************************/ 0956 0957 /* some values for the encoding_flag */ 0958 # define EC_PKEY_NO_PARAMETERS 0x001 0959 # define EC_PKEY_NO_PUBKEY 0x002 0960 0961 /* some values for the flags field */ 0962 # define EC_FLAG_SM2_RANGE 0x0004 0963 # define EC_FLAG_COFACTOR_ECDH 0x1000 0964 # define EC_FLAG_CHECK_NAMED_GROUP 0x2000 0965 # define EC_FLAG_CHECK_NAMED_GROUP_NIST 0x4000 0966 # define EC_FLAG_CHECK_NAMED_GROUP_MASK \ 0967 (EC_FLAG_CHECK_NAMED_GROUP | EC_FLAG_CHECK_NAMED_GROUP_NIST) 0968 0969 /* Deprecated flags - it was using 0x01..0x02 */ 0970 # define EC_FLAG_NON_FIPS_ALLOW 0x0000 0971 # define EC_FLAG_FIPS_CHECKED 0x0000 0972 0973 # ifndef OPENSSL_NO_DEPRECATED_3_0 0974 /** 0975 * Creates a new EC_KEY object. 0976 * \param ctx The library context for to use for this EC_KEY. May be NULL in 0977 * which case the default library context is used. 0978 * \return EC_KEY object or NULL if an error occurred. 0979 */ 0980 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_ex(OSSL_LIB_CTX *ctx, const char *propq); 0981 0982 /** 0983 * Creates a new EC_KEY object. Same as calling EC_KEY_new_ex with a 0984 * NULL library context 0985 * \return EC_KEY object or NULL if an error occurred. 0986 */ 0987 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new(void); 0988 0989 OSSL_DEPRECATEDIN_3_0 int EC_KEY_get_flags(const EC_KEY *key); 0990 0991 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_flags(EC_KEY *key, int flags); 0992 0993 OSSL_DEPRECATEDIN_3_0 void EC_KEY_clear_flags(EC_KEY *key, int flags); 0994 0995 OSSL_DEPRECATEDIN_3_0 int EC_KEY_decoded_from_explicit_params(const EC_KEY *key); 0996 0997 /** 0998 * Creates a new EC_KEY object using a named curve as underlying 0999 * EC_GROUP object. 1000 * \param ctx The library context for to use for this EC_KEY. May be NULL in 1001 * which case the default library context is used. 1002 * \param propq Any property query string 1003 * \param nid NID of the named curve. 1004 * \return EC_KEY object or NULL if an error occurred. 1005 */ 1006 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_by_curve_name_ex(OSSL_LIB_CTX *ctx, 1007 const char *propq, 1008 int nid); 1009 1010 /** 1011 * Creates a new EC_KEY object using a named curve as underlying 1012 * EC_GROUP object. Same as calling EC_KEY_new_by_curve_name_ex with a NULL 1013 * library context and property query string. 1014 * \param nid NID of the named curve. 1015 * \return EC_KEY object or NULL if an error occurred. 1016 */ 1017 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_by_curve_name(int nid); 1018 1019 /** Frees a EC_KEY object. 1020 * \param key EC_KEY object to be freed. 1021 */ 1022 OSSL_DEPRECATEDIN_3_0 void EC_KEY_free(EC_KEY *key); 1023 1024 /** Copies a EC_KEY object. 1025 * \param dst destination EC_KEY object 1026 * \param src src EC_KEY object 1027 * \return dst or NULL if an error occurred. 1028 */ 1029 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); 1030 1031 /** Creates a new EC_KEY object and copies the content from src to it. 1032 * \param src the source EC_KEY object 1033 * \return newly created EC_KEY object or NULL if an error occurred. 1034 */ 1035 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_dup(const EC_KEY *src); 1036 1037 /** Increases the internal reference count of a EC_KEY object. 1038 * \param key EC_KEY object 1039 * \return 1 on success and 0 if an error occurred. 1040 */ 1041 OSSL_DEPRECATEDIN_3_0 int EC_KEY_up_ref(EC_KEY *key); 1042 1043 /** Returns the ENGINE object of a EC_KEY object 1044 * \param eckey EC_KEY object 1045 * \return the ENGINE object (possibly NULL). 1046 */ 1047 OSSL_DEPRECATEDIN_3_0 ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey); 1048 1049 /** Returns the EC_GROUP object of a EC_KEY object 1050 * \param key EC_KEY object 1051 * \return the EC_GROUP object (possibly NULL). 1052 */ 1053 OSSL_DEPRECATEDIN_3_0 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); 1054 1055 /** Sets the EC_GROUP of a EC_KEY object. 1056 * \param key EC_KEY object 1057 * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY 1058 * object will use an own copy of the EC_GROUP). 1059 * \return 1 on success and 0 if an error occurred. 1060 */ 1061 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); 1062 1063 /** Returns the private key of a EC_KEY object. 1064 * \param key EC_KEY object 1065 * \return a BIGNUM with the private key (possibly NULL). 1066 */ 1067 OSSL_DEPRECATEDIN_3_0 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); 1068 1069 /** Sets the private key of a EC_KEY object. 1070 * \param key EC_KEY object 1071 * \param prv BIGNUM with the private key (note: the EC_KEY object 1072 * will use an own copy of the BIGNUM). 1073 * \return 1 on success and 0 if an error occurred. 1074 */ 1075 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); 1076 1077 /** Returns the public key of a EC_KEY object. 1078 * \param key the EC_KEY object 1079 * \return a EC_POINT object with the public key (possibly NULL) 1080 */ 1081 OSSL_DEPRECATEDIN_3_0 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); 1082 1083 /** Sets the public key of a EC_KEY object. 1084 * \param key EC_KEY object 1085 * \param pub EC_POINT object with the public key (note: the EC_KEY object 1086 * will use an own copy of the EC_POINT object). 1087 * \return 1 on success and 0 if an error occurred. 1088 */ 1089 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); 1090 1091 OSSL_DEPRECATEDIN_3_0 unsigned EC_KEY_get_enc_flags(const EC_KEY *key); 1092 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags); 1093 OSSL_DEPRECATEDIN_3_0 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); 1094 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_conv_form(EC_KEY *eckey, 1095 point_conversion_form_t cform); 1096 # endif /*OPENSSL_NO_DEPRECATED_3_0 */ 1097 1098 # define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ 1099 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) 1100 1101 # ifndef OPENSSL_NO_DEPRECATED_3_0 1102 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg); 1103 OSSL_DEPRECATEDIN_3_0 void *EC_KEY_get_ex_data(const EC_KEY *key, int idx); 1104 1105 /* wrapper functions for the underlying EC_GROUP object */ 1106 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); 1107 1108 /** Creates a table of pre-computed multiples of the generator to 1109 * accelerate further EC_KEY operations. 1110 * \param key EC_KEY object 1111 * \param ctx BN_CTX object (optional) 1112 * \return 1 on success and 0 if an error occurred. 1113 */ 1114 OSSL_DEPRECATEDIN_3_0 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); 1115 1116 /** Creates a new ec private (and optional a new public) key. 1117 * \param key EC_KEY object 1118 * \return 1 on success and 0 if an error occurred. 1119 */ 1120 OSSL_DEPRECATEDIN_3_0 int EC_KEY_generate_key(EC_KEY *key); 1121 1122 /** Verifies that a private and/or public key is valid. 1123 * \param key the EC_KEY object 1124 * \return 1 on success and 0 otherwise. 1125 */ 1126 OSSL_DEPRECATEDIN_3_0 int EC_KEY_check_key(const EC_KEY *key); 1127 1128 /** Indicates if an EC_KEY can be used for signing. 1129 * \param eckey the EC_KEY object 1130 * \return 1 if can sign and 0 otherwise. 1131 */ 1132 OSSL_DEPRECATEDIN_3_0 int EC_KEY_can_sign(const EC_KEY *eckey); 1133 1134 /** Sets a public key from affine coordinates performing 1135 * necessary NIST PKV tests. 1136 * \param key the EC_KEY object 1137 * \param x public key x coordinate 1138 * \param y public key y coordinate 1139 * \return 1 on success and 0 otherwise. 1140 */ 1141 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, 1142 BIGNUM *x, 1143 BIGNUM *y); 1144 1145 /** Encodes an EC_KEY public key to an allocated octet string 1146 * \param key key to encode 1147 * \param form point conversion form 1148 * \param pbuf returns pointer to allocated buffer 1149 * \param ctx BN_CTX object (optional) 1150 * \return the length of the encoded octet string or 0 if an error occurred 1151 */ 1152 OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_key2buf(const EC_KEY *key, 1153 point_conversion_form_t form, 1154 unsigned char **pbuf, BN_CTX *ctx); 1155 1156 /** Decodes a EC_KEY public key from a octet string 1157 * \param key key to decode 1158 * \param buf memory buffer with the encoded ec point 1159 * \param len length of the encoded ec point 1160 * \param ctx BN_CTX object (optional) 1161 * \return 1 on success and 0 if an error occurred 1162 */ 1163 1164 OSSL_DEPRECATEDIN_3_0 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, 1165 size_t len, BN_CTX *ctx); 1166 1167 /** Decodes an EC_KEY private key from an octet string 1168 * \param key key to decode 1169 * \param buf memory buffer with the encoded private key 1170 * \param len length of the encoded key 1171 * \return 1 on success and 0 if an error occurred 1172 */ 1173 1174 OSSL_DEPRECATEDIN_3_0 int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, 1175 size_t len); 1176 1177 /** Encodes a EC_KEY private key to an octet string 1178 * \param key key to encode 1179 * \param buf memory buffer for the result. If NULL the function returns 1180 * required buffer size. 1181 * \param len length of the memory buffer 1182 * \return the length of the encoded octet string or 0 if an error occurred 1183 */ 1184 1185 OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_priv2oct(const EC_KEY *key, 1186 unsigned char *buf, size_t len); 1187 1188 /** Encodes an EC_KEY private key to an allocated octet string 1189 * \param eckey key to encode 1190 * \param pbuf returns pointer to allocated buffer 1191 * \return the length of the encoded octet string or 0 if an error occurred 1192 */ 1193 OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_priv2buf(const EC_KEY *eckey, 1194 unsigned char **pbuf); 1195 1196 /********************************************************************/ 1197 /* de- and encoding functions for SEC1 ECPrivateKey */ 1198 /********************************************************************/ 1199 1200 /** Decodes a private key from a memory buffer. 1201 * \param key a pointer to a EC_KEY object which should be used (or NULL) 1202 * \param in pointer to memory with the DER encoded private key 1203 * \param len length of the DER encoded private key 1204 * \return the decoded private key or NULL if an error occurred. 1205 */ 1206 OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECPrivateKey(EC_KEY **key, 1207 const unsigned char **in, 1208 long len); 1209 1210 /** Encodes a private key object and stores the result in a buffer. 1211 * \param key the EC_KEY object to encode 1212 * \param out the buffer for the result (if NULL the function returns number 1213 * of bytes needed). 1214 * \return 1 on success and 0 if an error occurred. 1215 */ 1216 OSSL_DEPRECATEDIN_3_0 int i2d_ECPrivateKey(const EC_KEY *key, 1217 unsigned char **out); 1218 1219 /********************************************************************/ 1220 /* de- and encoding functions for EC parameters */ 1221 /********************************************************************/ 1222 1223 /** Decodes ec parameter from a memory buffer. 1224 * \param key a pointer to a EC_KEY object which should be used (or NULL) 1225 * \param in pointer to memory with the DER encoded ec parameters 1226 * \param len length of the DER encoded ec parameters 1227 * \return a EC_KEY object with the decoded parameters or NULL if an error 1228 * occurred. 1229 */ 1230 OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECParameters(EC_KEY **key, 1231 const unsigned char **in, 1232 long len); 1233 1234 /** Encodes ec parameter and stores the result in a buffer. 1235 * \param key the EC_KEY object with ec parameters to encode 1236 * \param out the buffer for the result (if NULL the function returns number 1237 * of bytes needed). 1238 * \return 1 on success and 0 if an error occurred. 1239 */ 1240 OSSL_DEPRECATEDIN_3_0 int i2d_ECParameters(const EC_KEY *key, 1241 unsigned char **out); 1242 1243 /********************************************************************/ 1244 /* de- and encoding functions for EC public key */ 1245 /* (octet string, not DER -- hence 'o2i' and 'i2o') */ 1246 /********************************************************************/ 1247 1248 /** Decodes an ec public key from a octet string. 1249 * \param key a pointer to a EC_KEY object which should be used 1250 * \param in memory buffer with the encoded public key 1251 * \param len length of the encoded public key 1252 * \return EC_KEY object with decoded public key or NULL if an error 1253 * occurred. 1254 */ 1255 OSSL_DEPRECATEDIN_3_0 EC_KEY *o2i_ECPublicKey(EC_KEY **key, 1256 const unsigned char **in, long len); 1257 1258 /** Encodes an ec public key in an octet string. 1259 * \param key the EC_KEY object with the public key 1260 * \param out the buffer for the result (if NULL the function returns number 1261 * of bytes needed). 1262 * \return 1 on success and 0 if an error occurred 1263 */ 1264 OSSL_DEPRECATEDIN_3_0 int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); 1265 1266 /** Prints out the ec parameters on human readable form. 1267 * \param bp BIO object to which the information is printed 1268 * \param key EC_KEY object 1269 * \return 1 on success and 0 if an error occurred 1270 */ 1271 OSSL_DEPRECATEDIN_3_0 int ECParameters_print(BIO *bp, const EC_KEY *key); 1272 1273 /** Prints out the contents of a EC_KEY object 1274 * \param bp BIO object to which the information is printed 1275 * \param key EC_KEY object 1276 * \param off line offset 1277 * \return 1 on success and 0 if an error occurred 1278 */ 1279 OSSL_DEPRECATEDIN_3_0 int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); 1280 1281 # ifndef OPENSSL_NO_STDIO 1282 /** Prints out the ec parameters on human readable form. 1283 * \param fp file descriptor to which the information is printed 1284 * \param key EC_KEY object 1285 * \return 1 on success and 0 if an error occurred 1286 */ 1287 OSSL_DEPRECATEDIN_3_0 int ECParameters_print_fp(FILE *fp, const EC_KEY *key); 1288 1289 /** Prints out the contents of a EC_KEY object 1290 * \param fp file descriptor to which the information is printed 1291 * \param key EC_KEY object 1292 * \param off line offset 1293 * \return 1 on success and 0 if an error occurred 1294 */ 1295 OSSL_DEPRECATEDIN_3_0 int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); 1296 # endif /* OPENSSL_NO_STDIO */ 1297 1298 OSSL_DEPRECATEDIN_3_0 const EC_KEY_METHOD *EC_KEY_OpenSSL(void); 1299 OSSL_DEPRECATEDIN_3_0 const EC_KEY_METHOD *EC_KEY_get_default_method(void); 1300 OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_default_method(const EC_KEY_METHOD *meth); 1301 OSSL_DEPRECATEDIN_3_0 const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); 1302 OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); 1303 OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_method(ENGINE *engine); 1304 1305 /** The old name for ecdh_KDF_X9_63 1306 * The ECDH KDF specification has been mistakenly attributed to ANSI X9.62, 1307 * it is actually specified in ANSI X9.63. 1308 * This identifier is retained for backwards compatibility 1309 */ 1310 OSSL_DEPRECATEDIN_3_0 int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, 1311 const unsigned char *Z, size_t Zlen, 1312 const unsigned char *sinfo, 1313 size_t sinfolen, const EVP_MD *md); 1314 1315 OSSL_DEPRECATEDIN_3_0 int ECDH_compute_key(void *out, size_t outlen, 1316 const EC_POINT *pub_key, 1317 const EC_KEY *ecdh, 1318 void *(*KDF)(const void *in, 1319 size_t inlen, void *out, 1320 size_t *outlen)); 1321 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 1322 1323 typedef struct ECDSA_SIG_st ECDSA_SIG; 1324 1325 /** Allocates and initialize a ECDSA_SIG structure 1326 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 1327 */ 1328 ECDSA_SIG *ECDSA_SIG_new(void); 1329 1330 /** frees a ECDSA_SIG structure 1331 * \param sig pointer to the ECDSA_SIG structure 1332 */ 1333 void ECDSA_SIG_free(ECDSA_SIG *sig); 1334 1335 /** i2d_ECDSA_SIG encodes content of ECDSA_SIG (note: this function modifies *pp 1336 * (*pp += length of the DER encoded signature)). 1337 * \param sig pointer to the ECDSA_SIG object 1338 * \param pp pointer to a unsigned char pointer for the output or NULL 1339 * \return the length of the DER encoded ECDSA_SIG object or a negative value 1340 * on error 1341 */ 1342 DECLARE_ASN1_ENCODE_FUNCTIONS_only(ECDSA_SIG, ECDSA_SIG) 1343 1344 /** d2i_ECDSA_SIG decodes an ECDSA signature (note: this function modifies *pp 1345 * (*pp += len)). 1346 * \param sig pointer to ECDSA_SIG pointer (may be NULL) 1347 * \param pp memory buffer with the DER encoded signature 1348 * \param len length of the buffer 1349 * \return pointer to the decoded ECDSA_SIG structure (or NULL) 1350 */ 1351 1352 /** Accessor for r and s fields of ECDSA_SIG 1353 * \param sig pointer to ECDSA_SIG structure 1354 * \param pr pointer to BIGNUM pointer for r (may be NULL) 1355 * \param ps pointer to BIGNUM pointer for s (may be NULL) 1356 */ 1357 void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); 1358 1359 /** Accessor for r field of ECDSA_SIG 1360 * \param sig pointer to ECDSA_SIG structure 1361 */ 1362 const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig); 1363 1364 /** Accessor for s field of ECDSA_SIG 1365 * \param sig pointer to ECDSA_SIG structure 1366 */ 1367 const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig); 1368 1369 /** Setter for r and s fields of ECDSA_SIG 1370 * \param sig pointer to ECDSA_SIG structure 1371 * \param r pointer to BIGNUM for r 1372 * \param s pointer to BIGNUM for s 1373 */ 1374 int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); 1375 1376 # ifndef OPENSSL_NO_DEPRECATED_3_0 1377 /** Computes the ECDSA signature of the given hash value using 1378 * the supplied private key and returns the created signature. 1379 * \param dgst pointer to the hash value 1380 * \param dgst_len length of the hash value 1381 * \param eckey EC_KEY object containing a private EC key 1382 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 1383 */ 1384 OSSL_DEPRECATEDIN_3_0 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, 1385 int dgst_len, EC_KEY *eckey); 1386 1387 /** Computes ECDSA signature of a given hash value using the supplied 1388 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 1389 * \param dgst pointer to the hash value to sign 1390 * \param dgstlen length of the hash value 1391 * \param kinv BIGNUM with a pre-computed inverse k (optional) 1392 * \param rp BIGNUM with a pre-computed rp value (optional), 1393 * see ECDSA_sign_setup 1394 * \param eckey EC_KEY object containing a private EC key 1395 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 1396 */ 1397 OSSL_DEPRECATEDIN_3_0 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, 1398 int dgstlen, const BIGNUM *kinv, 1399 const BIGNUM *rp, EC_KEY *eckey); 1400 1401 /** Verifies that the supplied signature is a valid ECDSA 1402 * signature of the supplied hash value using the supplied public key. 1403 * \param dgst pointer to the hash value 1404 * \param dgst_len length of the hash value 1405 * \param sig ECDSA_SIG structure 1406 * \param eckey EC_KEY object containing a public EC key 1407 * \return 1 if the signature is valid, 0 if the signature is invalid 1408 * and -1 on error 1409 */ 1410 OSSL_DEPRECATEDIN_3_0 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, 1411 const ECDSA_SIG *sig, EC_KEY *eckey); 1412 1413 /** Precompute parts of the signing operation 1414 * \param eckey EC_KEY object containing a private EC key 1415 * \param ctx BN_CTX object (optional) 1416 * \param kinv BIGNUM pointer for the inverse of k 1417 * \param rp BIGNUM pointer for x coordinate of k * generator 1418 * \return 1 on success and 0 otherwise 1419 */ 1420 OSSL_DEPRECATEDIN_3_0 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, 1421 BIGNUM **kinv, BIGNUM **rp); 1422 1423 /** Computes ECDSA signature of a given hash value using the supplied 1424 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 1425 * \param type this parameter is ignored 1426 * \param dgst pointer to the hash value to sign 1427 * \param dgstlen length of the hash value 1428 * \param sig memory for the DER encoded created signature 1429 * \param siglen pointer to the length of the returned signature 1430 * \param eckey EC_KEY object containing a private EC key 1431 * \return 1 on success and 0 otherwise 1432 */ 1433 OSSL_DEPRECATEDIN_3_0 int ECDSA_sign(int type, const unsigned char *dgst, 1434 int dgstlen, unsigned char *sig, 1435 unsigned int *siglen, EC_KEY *eckey); 1436 1437 /** Computes ECDSA signature of a given hash value using the supplied 1438 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 1439 * \param type this parameter is ignored 1440 * \param dgst pointer to the hash value to sign 1441 * \param dgstlen length of the hash value 1442 * \param sig buffer to hold the DER encoded signature 1443 * \param siglen pointer to the length of the returned signature 1444 * \param kinv BIGNUM with a pre-computed inverse k (optional) 1445 * \param rp BIGNUM with a pre-computed rp value (optional), 1446 * see ECDSA_sign_setup 1447 * \param eckey EC_KEY object containing a private EC key 1448 * \return 1 on success and 0 otherwise 1449 */ 1450 OSSL_DEPRECATEDIN_3_0 int ECDSA_sign_ex(int type, const unsigned char *dgst, 1451 int dgstlen, unsigned char *sig, 1452 unsigned int *siglen, const BIGNUM *kinv, 1453 const BIGNUM *rp, EC_KEY *eckey); 1454 1455 /** Verifies that the given signature is valid ECDSA signature 1456 * of the supplied hash value using the specified public key. 1457 * \param type this parameter is ignored 1458 * \param dgst pointer to the hash value 1459 * \param dgstlen length of the hash value 1460 * \param sig pointer to the DER encoded signature 1461 * \param siglen length of the DER encoded signature 1462 * \param eckey EC_KEY object containing a public EC key 1463 * \return 1 if the signature is valid, 0 if the signature is invalid 1464 * and -1 on error 1465 */ 1466 OSSL_DEPRECATEDIN_3_0 int ECDSA_verify(int type, const unsigned char *dgst, 1467 int dgstlen, const unsigned char *sig, 1468 int siglen, EC_KEY *eckey); 1469 1470 /** Returns the maximum length of the DER encoded signature 1471 * \param eckey EC_KEY object 1472 * \return numbers of bytes required for the DER encoded signature 1473 */ 1474 OSSL_DEPRECATEDIN_3_0 int ECDSA_size(const EC_KEY *eckey); 1475 1476 /********************************************************************/ 1477 /* EC_KEY_METHOD constructors, destructors, writers and accessors */ 1478 /********************************************************************/ 1479 1480 OSSL_DEPRECATEDIN_3_0 EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth); 1481 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_free(EC_KEY_METHOD *meth); 1482 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_init 1483 (EC_KEY_METHOD *meth, 1484 int (*init)(EC_KEY *key), 1485 void (*finish)(EC_KEY *key), 1486 int (*copy)(EC_KEY *dest, const EC_KEY *src), 1487 int (*set_group)(EC_KEY *key, const EC_GROUP *grp), 1488 int (*set_private)(EC_KEY *key, const BIGNUM *priv_key), 1489 int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)); 1490 1491 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, 1492 int (*keygen)(EC_KEY *key)); 1493 1494 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_compute_key 1495 (EC_KEY_METHOD *meth, 1496 int (*ckey)(unsigned char **psec, size_t *pseclen, 1497 const EC_POINT *pub_key, const EC_KEY *ecdh)); 1498 1499 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_sign 1500 (EC_KEY_METHOD *meth, 1501 int (*sign)(int type, const unsigned char *dgst, 1502 int dlen, unsigned char *sig, 1503 unsigned int *siglen, 1504 const BIGNUM *kinv, const BIGNUM *r, 1505 EC_KEY *eckey), 1506 int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, 1507 BIGNUM **kinvp, BIGNUM **rp), 1508 ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, 1509 int dgst_len, 1510 const BIGNUM *in_kinv, 1511 const BIGNUM *in_r, 1512 EC_KEY *eckey)); 1513 1514 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_set_verify 1515 (EC_KEY_METHOD *meth, 1516 int (*verify)(int type, const unsigned 1517 char *dgst, int dgst_len, 1518 const unsigned char *sigbuf, 1519 int sig_len, EC_KEY *eckey), 1520 int (*verify_sig)(const unsigned char *dgst, 1521 int dgst_len, const ECDSA_SIG *sig, 1522 EC_KEY *eckey)); 1523 1524 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_init 1525 (const EC_KEY_METHOD *meth, 1526 int (**pinit)(EC_KEY *key), 1527 void (**pfinish)(EC_KEY *key), 1528 int (**pcopy)(EC_KEY *dest, const EC_KEY *src), 1529 int (**pset_group)(EC_KEY *key, const EC_GROUP *grp), 1530 int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key), 1531 int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)); 1532 1533 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_keygen 1534 (const EC_KEY_METHOD *meth, int (**pkeygen)(EC_KEY *key)); 1535 1536 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_compute_key 1537 (const EC_KEY_METHOD *meth, 1538 int (**pck)(unsigned char **psec, 1539 size_t *pseclen, 1540 const EC_POINT *pub_key, 1541 const EC_KEY *ecdh)); 1542 1543 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_sign 1544 (const EC_KEY_METHOD *meth, 1545 int (**psign)(int type, const unsigned char *dgst, 1546 int dlen, unsigned char *sig, 1547 unsigned int *siglen, 1548 const BIGNUM *kinv, const BIGNUM *r, 1549 EC_KEY *eckey), 1550 int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, 1551 BIGNUM **kinvp, BIGNUM **rp), 1552 ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, 1553 int dgst_len, 1554 const BIGNUM *in_kinv, 1555 const BIGNUM *in_r, 1556 EC_KEY *eckey)); 1557 1558 OSSL_DEPRECATEDIN_3_0 void EC_KEY_METHOD_get_verify 1559 (const EC_KEY_METHOD *meth, 1560 int (**pverify)(int type, const unsigned 1561 char *dgst, int dgst_len, 1562 const unsigned char *sigbuf, 1563 int sig_len, EC_KEY *eckey), 1564 int (**pverify_sig)(const unsigned char *dgst, 1565 int dgst_len, 1566 const ECDSA_SIG *sig, 1567 EC_KEY *eckey)); 1568 # endif /* OPENSSL_NO_DEPRECATED_3_0 */ 1569 1570 # define EVP_EC_gen(curve) \ 1571 EVP_PKEY_Q_keygen(NULL, NULL, "EC", (char *)(strstr(curve, ""))) 1572 /* strstr is used to enable type checking for the variadic string arg */ 1573 # define ECParameters_dup(x) ASN1_dup_of(EC_KEY, i2d_ECParameters, \ 1574 d2i_ECParameters, x) 1575 1576 # ifndef __cplusplus 1577 # if defined(__SUNPRO_C) 1578 # if __SUNPRO_C >= 0x520 1579 # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) 1580 # endif 1581 # endif 1582 # endif 1583 1584 # endif 1585 # ifdef __cplusplus 1586 } 1587 # endif 1588 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |