Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
ec.h1570 linesDownload Raw Back to openssl
1/*2 * Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved4 *5 * Licensed under the Apache License 2.0 (the "License").  You may not use6 * this file except in compliance with the License.  You can obtain a copy7 * in the file LICENSE in the source distribution or at8 * https://www.openssl.org/source/license.html9 */10 11#ifndef OPENSSL_EC_H12# define OPENSSL_EC_H13# pragma once14 15# include <openssl/macros.h>16# ifndef OPENSSL_NO_DEPRECATED_3_017#  define HEADER_EC_H18# endif19 20# include <openssl/opensslconf.h>21# include <openssl/types.h>22 23# include <string.h>24 25# ifdef  __cplusplus26extern "C" {27# endif28 29/* Values for EVP_PKEY_CTX_set_ec_param_enc() */30# define OPENSSL_EC_EXPLICIT_CURVE  0x00031# define OPENSSL_EC_NAMED_CURVE     0x00132 33int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);34int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc);35int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx, int cofactor_mode);36int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx);37 38int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX *ctx, int kdf);39int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX *ctx);40 41int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);42int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);43 44int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int len);45int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int *len);46 47int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,48                                   int len);49# ifndef OPENSSL_NO_DEPRECATED_3_050OSSL_DEPRECATEDIN_3_051int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);52# endif53 54# define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID    (EVP_PKEY_ALG_CTRL + 1)55# define EVP_PKEY_CTRL_EC_PARAM_ENC             (EVP_PKEY_ALG_CTRL + 2)56# define EVP_PKEY_CTRL_EC_ECDH_COFACTOR         (EVP_PKEY_ALG_CTRL + 3)57# define EVP_PKEY_CTRL_EC_KDF_TYPE              (EVP_PKEY_ALG_CTRL + 4)58# define EVP_PKEY_CTRL_EC_KDF_MD                (EVP_PKEY_ALG_CTRL + 5)59# define EVP_PKEY_CTRL_GET_EC_KDF_MD            (EVP_PKEY_ALG_CTRL + 6)60# define EVP_PKEY_CTRL_EC_KDF_OUTLEN            (EVP_PKEY_ALG_CTRL + 7)61# define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN        (EVP_PKEY_ALG_CTRL + 8)62# define EVP_PKEY_CTRL_EC_KDF_UKM               (EVP_PKEY_ALG_CTRL + 9)63# define EVP_PKEY_CTRL_GET_EC_KDF_UKM           (EVP_PKEY_ALG_CTRL + 10)64 65/* KDF types */66# define EVP_PKEY_ECDH_KDF_NONE                      167# define EVP_PKEY_ECDH_KDF_X9_63                     268/*69 * The old name for EVP_PKEY_ECDH_KDF_X9_6370 *  The ECDH KDF specification has been mistakenly attributed to ANSI X9.62,71 *  it is actually specified in ANSI X9.63.72 *  This identifier is retained for backwards compatibility73 */74# define EVP_PKEY_ECDH_KDF_X9_62   EVP_PKEY_ECDH_KDF_X9_6375 76/** Enum for the point conversion form as defined in X9.62 (ECDSA)77 *  for the encoding of a elliptic curve point (x,y) */78typedef enum {79        /** the point is encoded as z||x, where the octet z specifies80         *  which solution of the quadratic equation y is  */81    POINT_CONVERSION_COMPRESSED = 2,82        /** the point is encoded as z||x||y, where z is the octet 0x04  */83    POINT_CONVERSION_UNCOMPRESSED = 4,84        /** the point is encoded as z||x||y, where the octet z specifies85         *  which solution of the quadratic equation y is  */86    POINT_CONVERSION_HYBRID = 687} point_conversion_form_t;88 89const char *OSSL_EC_curve_nid2name(int nid);90 91# ifndef OPENSSL_NO_EC92#  include <openssl/asn1.h>93#  include <openssl/symhacks.h>94#  ifndef OPENSSL_NO_DEPRECATED_1_1_095#   include <openssl/bn.h>96#  endif97#  include <openssl/ecerr.h>98 99#  ifndef OPENSSL_ECC_MAX_FIELD_BITS100#   define OPENSSL_ECC_MAX_FIELD_BITS 661101#  endif102 103#  include <openssl/params.h>104#  ifndef OPENSSL_NO_DEPRECATED_3_0105typedef struct ec_method_st EC_METHOD;106#  endif107typedef struct ec_group_st EC_GROUP;108typedef struct ec_point_st EC_POINT;109typedef struct ecpk_parameters_st ECPKPARAMETERS;110typedef struct ec_parameters_st ECPARAMETERS;111 112/********************************************************************/113/*               EC_METHODs for curves over GF(p)                   */114/********************************************************************/115 116#  ifndef OPENSSL_NO_DEPRECATED_3_0117/** Returns the basic GFp ec methods which provides the basis for the118 *  optimized methods.119 *  \return  EC_METHOD object120 */121OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_simple_method(void);122 123/** Returns GFp methods using montgomery multiplication.124 *  \return  EC_METHOD object125 */126OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_mont_method(void);127 128/** Returns GFp methods using optimized methods for NIST recommended curves129 *  \return  EC_METHOD object130 */131OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nist_method(void);132 133#   ifndef OPENSSL_NO_EC_NISTP_64_GCC_128134/** Returns 64-bit optimized methods for nistp224135 *  \return  EC_METHOD object136 */137OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp224_method(void);138 139/** Returns 64-bit optimized methods for nistp256140 *  \return  EC_METHOD object141 */142OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp256_method(void);143 144/** Returns 64-bit optimized methods for nistp521145 *  \return  EC_METHOD object146 */147OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GFp_nistp521_method(void);148#   endif /* OPENSSL_NO_EC_NISTP_64_GCC_128 */149 150#   ifndef OPENSSL_NO_EC2M151/********************************************************************/152/*           EC_METHOD for curves over GF(2^m)                      */153/********************************************************************/154 155/** Returns the basic GF2m ec method156 *  \return  EC_METHOD object157 */158OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GF2m_simple_method(void);159 160#   endif161 162/********************************************************************/163/*                   EC_GROUP functions                             */164/********************************************************************/165 166/**167 *  Creates a new EC_GROUP object168 *  \param   meth   EC_METHOD to use169 *  \return  newly created EC_GROUP object or NULL in case of an error.170 */171OSSL_DEPRECATEDIN_3_0 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);172 173/** Clears and frees a EC_GROUP object174 *  \param  group  EC_GROUP object to be cleared and freed.175 */176OSSL_DEPRECATEDIN_3_0 void EC_GROUP_clear_free(EC_GROUP *group);177 178/** Returns the EC_METHOD of the EC_GROUP object.179 *  \param  group  EC_GROUP object180 *  \return EC_METHOD used in this EC_GROUP object.181 */182OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);183 184/** Returns the field type of the EC_METHOD.185 *  \param  meth  EC_METHOD object186 *  \return NID of the underlying field type OID.187 */188OSSL_DEPRECATEDIN_3_0 int EC_METHOD_get_field_type(const EC_METHOD *meth);189#  endif /* OPENSSL_NO_DEPRECATED_3_0 */190 191/** Frees a EC_GROUP object192 *  \param  group  EC_GROUP object to be freed.193 */194void EC_GROUP_free(EC_GROUP *group);195 196/** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.197 *  \param  dst  destination EC_GROUP object198 *  \param  src  source EC_GROUP object199 *  \return 1 on success and 0 if an error occurred.200 */201int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);202 203/** Creates a new EC_GROUP object and copies the content204 *  form src to the newly created EC_KEY object205 *  \param  src  source EC_GROUP object206 *  \return newly created EC_GROUP object or NULL in case of an error.207 */208EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);209 210/** Sets the generator and its order/cofactor of a EC_GROUP object.211 *  \param  group      EC_GROUP object212 *  \param  generator  EC_POINT object with the generator.213 *  \param  order      the order of the group generated by the generator.214 *  \param  cofactor   the index of the sub-group generated by the generator215 *                     in the group of all points on the elliptic curve.216 *  \return 1 on success and 0 if an error occurred217 */218int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,219                           const BIGNUM *order, const BIGNUM *cofactor);220 221/** Returns the generator of a EC_GROUP object.222 *  \param  group  EC_GROUP object223 *  \return the currently used generator (possibly NULL).224 */225const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);226 227/** Returns the montgomery data for order(Generator)228 *  \param  group  EC_GROUP object229 *  \return the currently used montgomery data (possibly NULL).230*/231BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group);232 233/** Gets the order of a EC_GROUP234 *  \param  group  EC_GROUP object235 *  \param  order  BIGNUM to which the order is copied236 *  \param  ctx    unused237 *  \return 1 on success and 0 if an error occurred238 */239int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);240 241/** Gets the order of an EC_GROUP242 *  \param  group  EC_GROUP object243 *  \return the group order244 */245const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);246 247/** Gets the number of bits of the order of an EC_GROUP248 *  \param  group  EC_GROUP object249 *  \return number of bits of group order.250 */251int EC_GROUP_order_bits(const EC_GROUP *group);252 253/** Gets the cofactor of a EC_GROUP254 *  \param  group     EC_GROUP object255 *  \param  cofactor  BIGNUM to which the cofactor is copied256 *  \param  ctx       unused257 *  \return 1 on success and 0 if an error occurred258 */259int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,260                          BN_CTX *ctx);261 262/** Gets the cofactor of an EC_GROUP263 *  \param  group  EC_GROUP object264 *  \return the group cofactor265 */266const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);267 268/** Sets the name of a EC_GROUP object269 *  \param  group  EC_GROUP object270 *  \param  nid    NID of the curve name OID271 */272void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);273 274/** Returns the curve name of a EC_GROUP object275 *  \param  group  EC_GROUP object276 *  \return NID of the curve name OID or 0 if not set.277 */278int EC_GROUP_get_curve_name(const EC_GROUP *group);279 280/** Gets the field of an EC_GROUP281 *  \param  group  EC_GROUP object282 *  \return the group field283 */284const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group);285 286/** Returns the field type of the EC_GROUP.287 *  \param  group  EC_GROUP object288 *  \return NID of the underlying field type OID.289 */290int EC_GROUP_get_field_type(const EC_GROUP *group);291 292void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);293int EC_GROUP_get_asn1_flag(const EC_GROUP *group);294 295void EC_GROUP_set_point_conversion_form(EC_GROUP *group,296                                        point_conversion_form_t form);297point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);298 299unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);300size_t EC_GROUP_get_seed_len(const EC_GROUP *);301size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);302 303/** Sets the parameters of an ec curve defined by y^2 = x^3 + a*x + b (for GFp)304 *  or y^2 + x*y = x^3 + a*x^2 + b (for GF2m)305 *  \param  group  EC_GROUP object306 *  \param  p      BIGNUM with the prime number (GFp) or the polynomial307 *                 defining the underlying field (GF2m)308 *  \param  a      BIGNUM with parameter a of the equation309 *  \param  b      BIGNUM with parameter b of the equation310 *  \param  ctx    BN_CTX object (optional)311 *  \return 1 on success and 0 if an error occurred312 */313int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,314                       const BIGNUM *b, BN_CTX *ctx);315 316/** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp)317 *  or y^2 + x*y = x^3 + a*x^2 + b (for GF2m)318 *  \param  group  EC_GROUP object319 *  \param  p      BIGNUM with the prime number (GFp) or the polynomial320 *                 defining the underlying field (GF2m)321 *  \param  a      BIGNUM for parameter a of the equation322 *  \param  b      BIGNUM for parameter b of the equation323 *  \param  ctx    BN_CTX object (optional)324 *  \return 1 on success and 0 if an error occurred325 */326int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,327                       BN_CTX *ctx);328 329#  ifndef OPENSSL_NO_DEPRECATED_3_0330/** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve331 *  \param  group  EC_GROUP object332 *  \param  p      BIGNUM with the prime number (GFp) or the polynomial333 *                 defining the underlying field (GF2m)334 *  \param  a      BIGNUM with parameter a of the equation335 *  \param  b      BIGNUM with parameter b of the equation336 *  \param  ctx    BN_CTX object (optional)337 *  \return 1 on success and 0 if an error occurred338 */339OSSL_DEPRECATEDIN_3_0 int EC_GROUP_set_curve_GFp(EC_GROUP *group,340                                                 const BIGNUM *p,341                                                 const BIGNUM *a,342                                                 const BIGNUM *b,343                                                 BN_CTX *ctx);344 345/** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve346 *  \param  group  EC_GROUP object347 *  \param  p      BIGNUM with the prime number (GFp) or the polynomial348 *                 defining the underlying field (GF2m)349 *  \param  a      BIGNUM for parameter a of the equation350 *  \param  b      BIGNUM for parameter b of the equation351 *  \param  ctx    BN_CTX object (optional)352 *  \return 1 on success and 0 if an error occurred353 */354OSSL_DEPRECATEDIN_3_0 int EC_GROUP_get_curve_GFp(const EC_GROUP *group,355                                                 BIGNUM *p,356                                                 BIGNUM *a, BIGNUM *b,357                                                 BN_CTX *ctx);358 359#   ifndef OPENSSL_NO_EC2M360/** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve361 *  \param  group  EC_GROUP object362 *  \param  p      BIGNUM with the prime number (GFp) or the polynomial363 *                 defining the underlying field (GF2m)364 *  \param  a      BIGNUM with parameter a of the equation365 *  \param  b      BIGNUM with parameter b of the equation366 *  \param  ctx    BN_CTX object (optional)367 *  \return 1 on success and 0 if an error occurred368 */369OSSL_DEPRECATEDIN_3_0 int EC_GROUP_set_curve_GF2m(EC_GROUP *group,370                                                  const BIGNUM *p,371                                                  const BIGNUM *a,372                                                  const BIGNUM *b,373                                                  BN_CTX *ctx);374 375/** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve376 *  \param  group  EC_GROUP object377 *  \param  p      BIGNUM with the prime number (GFp) or the polynomial378 *                 defining the underlying field (GF2m)379 *  \param  a      BIGNUM for parameter a of the equation380 *  \param  b      BIGNUM for parameter b of the equation381 *  \param  ctx    BN_CTX object (optional)382 *  \return 1 on success and 0 if an error occurred383 */384OSSL_DEPRECATEDIN_3_0 int EC_GROUP_get_curve_GF2m(const EC_GROUP *group,385                                                  BIGNUM *p,386                                                  BIGNUM *a, BIGNUM *b,387                                                  BN_CTX *ctx);388#   endif /* OPENSSL_NO_EC2M */389#  endif /* OPENSSL_NO_DEPRECATED_3_0 */390 391/** Returns the number of bits needed to represent a field element392 *  \param  group  EC_GROUP object393 *  \return number of bits needed to represent a field element394 */395int EC_GROUP_get_degree(const EC_GROUP *group);396 397/** Checks whether the parameter in the EC_GROUP define a valid ec group398 *  \param  group  EC_GROUP object399 *  \param  ctx    BN_CTX object (optional)400 *  \return 1 if group is a valid ec group and 0 otherwise401 */402int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);403 404/** Checks whether the discriminant of the elliptic curve is zero or not405 *  \param  group  EC_GROUP object406 *  \param  ctx    BN_CTX object (optional)407 *  \return 1 if the discriminant is not zero and 0 otherwise408 */409int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);410 411/** Compares two EC_GROUP objects412 *  \param  a    first EC_GROUP object413 *  \param  b    second EC_GROUP object414 *  \param  ctx  BN_CTX object (optional)415 *  \return 0 if the groups are equal, 1 if not, or -1 on error416 */417int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);418 419/*420 * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after421 * choosing an appropriate EC_METHOD422 */423 424/** Creates a new EC_GROUP object with the specified parameters defined425 *  over GFp (defined by the equation y^2 = x^3 + a*x + b)426 *  \param  p    BIGNUM with the prime number427 *  \param  a    BIGNUM with the parameter a of the equation428 *  \param  b    BIGNUM with the parameter b of the equation429 *  \param  ctx  BN_CTX object (optional)430 *  \return newly created EC_GROUP object with the specified parameters431 */432EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,433                                 const BIGNUM *b, BN_CTX *ctx);434#  ifndef OPENSSL_NO_EC2M435/** Creates a new EC_GROUP object with the specified parameters defined436 *  over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)437 *  \param  p    BIGNUM with the polynomial defining the underlying field438 *  \param  a    BIGNUM with the parameter a of the equation439 *  \param  b    BIGNUM with the parameter b of the equation440 *  \param  ctx  BN_CTX object (optional)441 *  \return newly created EC_GROUP object with the specified parameters442 */443EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,444                                  const BIGNUM *b, BN_CTX *ctx);445#  endif446 447/**448 * Creates a EC_GROUP object with a curve specified by parameters.449 * The parameters may be explicit or a named curve,450 *  \param  params A list of parameters describing the group.451 *  \param  libctx The associated library context or NULL for the default452 *                 context453 *  \param  propq  A property query string454 *  \return newly created EC_GROUP object with specified parameters or NULL455 *          if an error occurred456 */457EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],458                                   OSSL_LIB_CTX *libctx, const char *propq);459 460/**461 * Creates a EC_GROUP object with a curve specified by a NID462 *  \param  libctx The associated library context or NULL for the default463 *                 context464 *  \param  propq  A property query string465 *  \param  nid    NID of the OID of the curve name466 *  \return newly created EC_GROUP object with specified curve or NULL467 *          if an error occurred468 */469EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq,470                                        int nid);471 472/**473 * Creates a EC_GROUP object with a curve specified by a NID. Same as474 * EC_GROUP_new_by_curve_name_ex but the libctx and propq are always475 * NULL.476 *  \param  nid    NID of the OID of the curve name477 *  \return newly created EC_GROUP object with specified curve or NULL478 *          if an error occurred479 */480EC_GROUP *EC_GROUP_new_by_curve_name(int nid);481 482/** Creates a new EC_GROUP object from an ECPARAMETERS object483 *  \param  params  pointer to the ECPARAMETERS object484 *  \return newly created EC_GROUP object with specified curve or NULL485 *          if an error occurred486 */487EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params);488 489/** Creates an ECPARAMETERS object for the given EC_GROUP object.490 *  \param  group   pointer to the EC_GROUP object491 *  \param  params  pointer to an existing ECPARAMETERS object or NULL492 *  \return pointer to the new ECPARAMETERS object or NULL493 *          if an error occurred.494 */495ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,496                                        ECPARAMETERS *params);497 498/** Creates a new EC_GROUP object from an ECPKPARAMETERS object499 *  \param  params  pointer to an existing ECPKPARAMETERS object, or NULL500 *  \return newly created EC_GROUP object with specified curve, or NULL501 *          if an error occurred502 */503EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params);504 505/** Creates an ECPKPARAMETERS object for the given EC_GROUP object.506 *  \param  group   pointer to the EC_GROUP object507 *  \param  params  pointer to an existing ECPKPARAMETERS object or NULL508 *  \return pointer to the new ECPKPARAMETERS object or NULL509 *          if an error occurred.510 */511ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group,512                                            ECPKPARAMETERS *params);513 514/********************************************************************/515/*               handling of internal curves                        */516/********************************************************************/517 518typedef struct {519    int nid;520    const char *comment;521} EC_builtin_curve;522 523/*524 * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all525 * available curves or zero if a error occurred. In case r is not zero,526 * nitems EC_builtin_curve structures are filled with the data of the first527 * nitems internal groups528 */529size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);530 531const char *EC_curve_nid2nist(int nid);532int EC_curve_nist2nid(const char *name);533int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only,534                               BN_CTX *ctx);535 536/********************************************************************/537/*                    EC_POINT functions                            */538/********************************************************************/539 540/** Creates a new EC_POINT object for the specified EC_GROUP541 *  \param  group  EC_GROUP the underlying EC_GROUP object542 *  \return newly created EC_POINT object or NULL if an error occurred543 */544EC_POINT *EC_POINT_new(const EC_GROUP *group);545 546/** Frees a EC_POINT object547 *  \param  point  EC_POINT object to be freed548 */549void EC_POINT_free(EC_POINT *point);550 551/** Clears and frees a EC_POINT object552 *  \param  point  EC_POINT object to be cleared and freed553 */554void EC_POINT_clear_free(EC_POINT *point);555 556/** Copies EC_POINT object557 *  \param  dst  destination EC_POINT object558 *  \param  src  source EC_POINT object559 *  \return 1 on success and 0 if an error occurred560 */561int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);562 563/** Creates a new EC_POINT object and copies the content of the supplied564 *  EC_POINT565 *  \param  src    source EC_POINT object566 *  \param  group  underlying the EC_GROUP object567 *  \return newly created EC_POINT object or NULL if an error occurred568 */569EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);570 571/** Sets a point to infinity (neutral element)572 *  \param  group  underlying EC_GROUP object573 *  \param  point  EC_POINT to set to infinity574 *  \return 1 on success and 0 if an error occurred575 */576int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);577 578#  ifndef OPENSSL_NO_DEPRECATED_3_0579/** Returns the EC_METHOD used in EC_POINT object580 *  \param  point  EC_POINT object581 *  \return the EC_METHOD used582 */583OSSL_DEPRECATEDIN_3_0 const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);584 585/** Sets the jacobian projective coordinates of a EC_POINT over GFp586 *  \param  group  underlying EC_GROUP object587 *  \param  p      EC_POINT object588 *  \param  x      BIGNUM with the x-coordinate589 *  \param  y      BIGNUM with the y-coordinate590 *  \param  z      BIGNUM with the z-coordinate591 *  \param  ctx    BN_CTX object (optional)592 *  \return 1 on success and 0 if an error occurred593 */594OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_Jprojective_coordinates_GFp595                      (const EC_GROUP *group, EC_POINT *p,596                       const BIGNUM *x, const BIGNUM *y, const BIGNUM *z,597                       BN_CTX *ctx);598 599/** Gets the jacobian projective coordinates of a EC_POINT over GFp600 *  \param  group  underlying EC_GROUP object601 *  \param  p      EC_POINT object602 *  \param  x      BIGNUM for the x-coordinate603 *  \param  y      BIGNUM for the y-coordinate604 *  \param  z      BIGNUM for the z-coordinate605 *  \param  ctx    BN_CTX object (optional)606 *  \return 1 on success and 0 if an error occurred607 */608OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_Jprojective_coordinates_GFp609                      (const EC_GROUP *group, const EC_POINT *p,610                       BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);611#  endif /* OPENSSL_NO_DEPRECATED_3_0 */612 613/** Sets the affine coordinates of an EC_POINT614 *  \param  group  underlying EC_GROUP object615 *  \param  p      EC_POINT object616 *  \param  x      BIGNUM with the x-coordinate617 *  \param  y      BIGNUM with the y-coordinate618 *  \param  ctx    BN_CTX object (optional)619 *  \return 1 on success and 0 if an error occurred620 */621int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p,622                                    const BIGNUM *x, const BIGNUM *y,623                                    BN_CTX *ctx);624 625/** Gets the affine coordinates of an EC_POINT.626 *  \param  group  underlying EC_GROUP object627 *  \param  p      EC_POINT object628 *  \param  x      BIGNUM for the x-coordinate629 *  \param  y      BIGNUM for the y-coordinate630 *  \param  ctx    BN_CTX object (optional)631 *  \return 1 on success and 0 if an error occurred632 */633int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p,634                                    BIGNUM *x, BIGNUM *y, BN_CTX *ctx);635 636#  ifndef OPENSSL_NO_DEPRECATED_3_0637/** Sets the affine coordinates of an EC_POINT. A synonym of638 *  EC_POINT_set_affine_coordinates639 *  \param  group  underlying EC_GROUP object640 *  \param  p      EC_POINT object641 *  \param  x      BIGNUM with the x-coordinate642 *  \param  y      BIGNUM with the y-coordinate643 *  \param  ctx    BN_CTX object (optional)644 *  \return 1 on success and 0 if an error occurred645 */646OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_affine_coordinates_GFp647                      (const EC_GROUP *group, EC_POINT *p,648                       const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);649 650/** Gets the affine coordinates of an EC_POINT. A synonym of651 *  EC_POINT_get_affine_coordinates652 *  \param  group  underlying EC_GROUP object653 *  \param  p      EC_POINT object654 *  \param  x      BIGNUM for the x-coordinate655 *  \param  y      BIGNUM for the y-coordinate656 *  \param  ctx    BN_CTX object (optional)657 *  \return 1 on success and 0 if an error occurred658 */659OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_affine_coordinates_GFp660                      (const EC_GROUP *group, const EC_POINT *p,661                       BIGNUM *x, BIGNUM *y, BN_CTX *ctx);662#  endif /* OPENSSL_NO_DEPRECATED_3_0 */663 664/** Sets the x9.62 compressed coordinates of a EC_POINT665 *  \param  group  underlying EC_GROUP object666 *  \param  p      EC_POINT object667 *  \param  x      BIGNUM with x-coordinate668 *  \param  y_bit  integer with the y-Bit (either 0 or 1)669 *  \param  ctx    BN_CTX object (optional)670 *  \return 1 on success and 0 if an error occurred671 */672int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p,673                                        const BIGNUM *x, int y_bit,674                                        BN_CTX *ctx);675 676#  ifndef OPENSSL_NO_DEPRECATED_3_0677/** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of678 *  EC_POINT_set_compressed_coordinates679 *  \param  group  underlying EC_GROUP object680 *  \param  p      EC_POINT object681 *  \param  x      BIGNUM with x-coordinate682 *  \param  y_bit  integer with the y-Bit (either 0 or 1)683 *  \param  ctx    BN_CTX object (optional)684 *  \return 1 on success and 0 if an error occurred685 */686OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_compressed_coordinates_GFp687                      (const EC_GROUP *group, EC_POINT *p,688                       const BIGNUM *x, int y_bit, BN_CTX *ctx);689#   ifndef OPENSSL_NO_EC2M690/** Sets the affine coordinates of an EC_POINT. A synonym of691 *  EC_POINT_set_affine_coordinates692 *  \param  group  underlying EC_GROUP object693 *  \param  p      EC_POINT object694 *  \param  x      BIGNUM with the x-coordinate695 *  \param  y      BIGNUM with the y-coordinate696 *  \param  ctx    BN_CTX object (optional)697 *  \return 1 on success and 0 if an error occurred698 */699OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_affine_coordinates_GF2m700                      (const EC_GROUP *group, EC_POINT *p,701                       const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);702 703/** Gets the affine coordinates of an EC_POINT. A synonym of704 *  EC_POINT_get_affine_coordinates705 *  \param  group  underlying EC_GROUP object706 *  \param  p      EC_POINT object707 *  \param  x      BIGNUM for the x-coordinate708 *  \param  y      BIGNUM for the y-coordinate709 *  \param  ctx    BN_CTX object (optional)710 *  \return 1 on success and 0 if an error occurred711 */712OSSL_DEPRECATEDIN_3_0 int EC_POINT_get_affine_coordinates_GF2m713                      (const EC_GROUP *group, const EC_POINT *p,714                       BIGNUM *x, BIGNUM *y, BN_CTX *ctx);715 716/** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of717 *  EC_POINT_set_compressed_coordinates718 *  \param  group  underlying EC_GROUP object719 *  \param  p      EC_POINT object720 *  \param  x      BIGNUM with x-coordinate721 *  \param  y_bit  integer with the y-Bit (either 0 or 1)722 *  \param  ctx    BN_CTX object (optional)723 *  \return 1 on success and 0 if an error occurred724 */725OSSL_DEPRECATEDIN_3_0 int EC_POINT_set_compressed_coordinates_GF2m726                      (const EC_GROUP *group, EC_POINT *p,727                       const BIGNUM *x, int y_bit, BN_CTX *ctx);728#   endif729#  endif /* OPENSSL_NO_DEPRECATED_3_0 */730 731/** Encodes a EC_POINT object to a octet string732 *  \param  group  underlying EC_GROUP object733 *  \param  p      EC_POINT object734 *  \param  form   point conversion form735 *  \param  buf    memory buffer for the result. If NULL the function returns736 *                 required buffer size.737 *  \param  len    length of the memory buffer738 *  \param  ctx    BN_CTX object (optional)739 *  \return the length of the encoded octet string or 0 if an error occurred740 */741size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,742                          point_conversion_form_t form,743                          unsigned char *buf, size_t len, BN_CTX *ctx);744 745/** Decodes a EC_POINT from a octet string746 *  \param  group  underlying EC_GROUP object747 *  \param  p      EC_POINT object748 *  \param  buf    memory buffer with the encoded ec point749 *  \param  len    length of the encoded ec point750 *  \param  ctx    BN_CTX object (optional)751 *  \return 1 on success and 0 if an error occurred752 */753int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,754                       const unsigned char *buf, size_t len, BN_CTX *ctx);755 756/** Encodes an EC_POINT object to an allocated octet string757 *  \param  group  underlying EC_GROUP object758 *  \param  point  EC_POINT object759 *  \param  form   point conversion form760 *  \param  pbuf   returns pointer to allocated buffer761 *  \param  ctx    BN_CTX object (optional)762 *  \return the length of the encoded octet string or 0 if an error occurred763 */764size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,765                          point_conversion_form_t form,766                          unsigned char **pbuf, BN_CTX *ctx);767 768/* other interfaces to point2oct/oct2point: */769#  ifndef OPENSSL_NO_DEPRECATED_3_0770OSSL_DEPRECATEDIN_3_0 BIGNUM *EC_POINT_point2bn(const EC_GROUP *,771                                                const EC_POINT *,772                                                point_conversion_form_t form,773                                                BIGNUM *, BN_CTX *);774OSSL_DEPRECATEDIN_3_0 EC_POINT *EC_POINT_bn2point(const EC_GROUP *,775                                                  const BIGNUM *,776                                                  EC_POINT *, BN_CTX *);777#  endif /* OPENSSL_NO_DEPRECATED_3_0 */778 779char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,780                         point_conversion_form_t form, BN_CTX *);781EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,782                             EC_POINT *, BN_CTX *);783 784/********************************************************************/785/*         functions for doing EC_POINT arithmetic                  */786/********************************************************************/787 788/** Computes the sum of two EC_POINT789 *  \param  group  underlying EC_GROUP object790 *  \param  r      EC_POINT object for the result (r = a + b)791 *  \param  a      EC_POINT object with the first summand792 *  \param  b      EC_POINT object with the second summand793 *  \param  ctx    BN_CTX object (optional)794 *  \return 1 on success and 0 if an error occurred795 */796int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,797                 const EC_POINT *b, BN_CTX *ctx);798 799/** Computes the double of a EC_POINT800 *  \param  group  underlying EC_GROUP object801 *  \param  r      EC_POINT object for the result (r = 2 * a)802 *  \param  a      EC_POINT object803 *  \param  ctx    BN_CTX object (optional)804 *  \return 1 on success and 0 if an error occurred805 */806int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,807                 BN_CTX *ctx);808 809/** Computes the inverse of a EC_POINT810 *  \param  group  underlying EC_GROUP object811 *  \param  a      EC_POINT object to be inverted (it's used for the result as well)812 *  \param  ctx    BN_CTX object (optional)813 *  \return 1 on success and 0 if an error occurred814 */815int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);816 817/** Checks whether the point is the neutral element of the group818 *  \param  group  the underlying EC_GROUP object819 *  \param  p      EC_POINT object820 *  \return 1 if the point is the neutral element and 0 otherwise821 */822int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);823 824/** Checks whether the point is on the curve825 *  \param  group  underlying EC_GROUP object826 *  \param  point  EC_POINT object to check827 *  \param  ctx    BN_CTX object (optional)828 *  \return 1 if the point is on the curve, 0 if not, or -1 on error829 */830int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,831                         BN_CTX *ctx);832 833/** Compares two EC_POINTs834 *  \param  group  underlying EC_GROUP object835 *  \param  a      first EC_POINT object836 *  \param  b      second EC_POINT object837 *  \param  ctx    BN_CTX object (optional)838 *  \return 1 if the points are not equal, 0 if they are, or -1 on error839 */840int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,841                 BN_CTX *ctx);842 843#  ifndef OPENSSL_NO_DEPRECATED_3_0844OSSL_DEPRECATEDIN_3_0 int EC_POINT_make_affine(const EC_GROUP *group,845                                               EC_POINT *point, BN_CTX *ctx);846OSSL_DEPRECATEDIN_3_0 int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,847                                                EC_POINT *points[], BN_CTX *ctx);848 849/** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i]850 *  \param  group  underlying EC_GROUP object851 *  \param  r      EC_POINT object for the result852 *  \param  n      BIGNUM with the multiplier for the group generator (optional)853 *  \param  num    number further summands854 *  \param  p      array of size num of EC_POINT objects855 *  \param  m      array of size num of BIGNUM objects856 *  \param  ctx    BN_CTX object (optional)857 *  \return 1 on success and 0 if an error occurred858 */859OSSL_DEPRECATEDIN_3_0 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r,860                                        const BIGNUM *n, size_t num,861                                        const EC_POINT *p[], const BIGNUM *m[],862                                        BN_CTX *ctx);863#  endif /* OPENSSL_NO_DEPRECATED_3_0 */864 865/** Computes r = generator * n + q * m866 *  \param  group  underlying EC_GROUP object867 *  \param  r      EC_POINT object for the result868 *  \param  n      BIGNUM with the multiplier for the group generator (optional)869 *  \param  q      EC_POINT object with the first factor of the second summand870 *  \param  m      BIGNUM with the second factor of the second summand871 *  \param  ctx    BN_CTX object (optional)872 *  \return 1 on success and 0 if an error occurred873 */874int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,875                 const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);876 877#  ifndef OPENSSL_NO_DEPRECATED_3_0878/** Stores multiples of generator for faster point multiplication879 *  \param  group  EC_GROUP object880 *  \param  ctx    BN_CTX object (optional)881 *  \return 1 on success and 0 if an error occurred882 */883OSSL_DEPRECATEDIN_3_0 int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);884 885/** Reports whether a precomputation has been done886 *  \param  group  EC_GROUP object887 *  \return 1 if a pre-computation has been done and 0 otherwise888 */889OSSL_DEPRECATEDIN_3_0 int EC_GROUP_have_precompute_mult(const EC_GROUP *group);890#  endif /* OPENSSL_NO_DEPRECATED_3_0 */891 892/********************************************************************/893/*                       ASN1 stuff                                 */894/********************************************************************/895 896DECLARE_ASN1_ITEM(ECPKPARAMETERS)897DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS)898DECLARE_ASN1_ITEM(ECPARAMETERS)899DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS)900 901/*902 * EC_GROUP_get_basis_type() returns the NID of the basis type used to903 * represent the field elements904 */905int EC_GROUP_get_basis_type(const EC_GROUP *);906#  ifndef OPENSSL_NO_EC2M907int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);908int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,909                                   unsigned int *k2, unsigned int *k3);910#  endif911 912EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);913int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);914 915#  define d2i_ECPKParameters_bio(bp,x) \916    ASN1_d2i_bio_of(EC_GROUP, NULL, d2i_ECPKParameters, bp, x)917#  define i2d_ECPKParameters_bio(bp,x) \918    ASN1_i2d_bio_of(EC_GROUP, i2d_ECPKParameters, bp, x)919#  define d2i_ECPKParameters_fp(fp,x) \920    (EC_GROUP *)ASN1_d2i_fp(NULL, (d2i_of_void *)d2i_ECPKParameters, (fp), \921                            (void **)(x))922#  define i2d_ECPKParameters_fp(fp,x) \923    ASN1_i2d_fp((i2d_of_void *)i2d_ECPKParameters, (fp), (void *)(x))924 925#  ifndef OPENSSL_NO_DEPRECATED_3_0926OSSL_DEPRECATEDIN_3_0 int ECPKParameters_print(BIO *bp, const EC_GROUP *x,927                                               int off);928#   ifndef OPENSSL_NO_STDIO929OSSL_DEPRECATEDIN_3_0 int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x,930                                                  int off);931#   endif932#  endif /* OPENSSL_NO_DEPRECATED_3_0 */933 934/********************************************************************/935/*                      EC_KEY functions                            */936/********************************************************************/937 938/* some values for the encoding_flag */939#  define EC_PKEY_NO_PARAMETERS   0x001940#  define EC_PKEY_NO_PUBKEY       0x002941 942/* some values for the flags field */943#  define EC_FLAG_SM2_RANGE              0x0004944#  define EC_FLAG_COFACTOR_ECDH          0x1000945#  define EC_FLAG_CHECK_NAMED_GROUP      0x2000946#  define EC_FLAG_CHECK_NAMED_GROUP_NIST 0x4000947#  define EC_FLAG_CHECK_NAMED_GROUP_MASK \948    (EC_FLAG_CHECK_NAMED_GROUP | EC_FLAG_CHECK_NAMED_GROUP_NIST)949 950/* Deprecated flags -  it was using 0x01..0x02 */951#  define EC_FLAG_NON_FIPS_ALLOW         0x0000952#  define EC_FLAG_FIPS_CHECKED           0x0000953 954#  ifndef OPENSSL_NO_DEPRECATED_3_0955/**956 *  Creates a new EC_KEY object.957 *  \param  ctx  The library context for to use for this EC_KEY. May be NULL in958 *               which case the default library context is used.959 *  \return EC_KEY object or NULL if an error occurred.960 */961OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_ex(OSSL_LIB_CTX *ctx, const char *propq);962 963/**964 *  Creates a new EC_KEY object. Same as calling EC_KEY_new_ex with a965 *  NULL library context966 *  \return EC_KEY object or NULL if an error occurred.967 */968OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new(void);969 970OSSL_DEPRECATEDIN_3_0 int EC_KEY_get_flags(const EC_KEY *key);971 972OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_flags(EC_KEY *key, int flags);973 974OSSL_DEPRECATEDIN_3_0 void EC_KEY_clear_flags(EC_KEY *key, int flags);975 976OSSL_DEPRECATEDIN_3_0 int EC_KEY_decoded_from_explicit_params(const EC_KEY *key);977 978/**979 *  Creates a new EC_KEY object using a named curve as underlying980 *  EC_GROUP object.981 *  \param  ctx   The library context for to use for this EC_KEY. May be NULL in982 *                which case the default library context is used.983 *  \param  propq Any property query string984 *  \param  nid   NID of the named curve.985 *  \return EC_KEY object or NULL if an error occurred.986 */987OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_by_curve_name_ex(OSSL_LIB_CTX *ctx,988                                                          const char *propq,989                                                          int nid);990 991/**992 *  Creates a new EC_KEY object using a named curve as underlying993 *  EC_GROUP object. Same as calling EC_KEY_new_by_curve_name_ex with a NULL994 *  library context and property query string.995 *  \param  nid  NID of the named curve.996 *  \return EC_KEY object or NULL if an error occurred.997 */998OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_new_by_curve_name(int nid);999 1000/** Frees a EC_KEY object.1001 *  \param  key  EC_KEY object to be freed.1002 */1003OSSL_DEPRECATEDIN_3_0 void EC_KEY_free(EC_KEY *key);1004 1005/** Copies a EC_KEY object.1006 *  \param  dst  destination EC_KEY object1007 *  \param  src  src EC_KEY object1008 *  \return dst or NULL if an error occurred.1009 */1010OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);1011 1012/** Creates a new EC_KEY object and copies the content from src to it.1013 *  \param  src  the source EC_KEY object1014 *  \return newly created EC_KEY object or NULL if an error occurred.1015 */1016OSSL_DEPRECATEDIN_3_0 EC_KEY *EC_KEY_dup(const EC_KEY *src);1017 1018/** Increases the internal reference count of a EC_KEY object.1019 *  \param  key  EC_KEY object1020 *  \return 1 on success and 0 if an error occurred.1021 */1022OSSL_DEPRECATEDIN_3_0 int EC_KEY_up_ref(EC_KEY *key);1023 1024/** Returns the ENGINE object of a EC_KEY object1025 *  \param  eckey  EC_KEY object1026 *  \return the ENGINE object (possibly NULL).1027 */1028OSSL_DEPRECATEDIN_3_0 ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey);1029 1030/** Returns the EC_GROUP object of a EC_KEY object1031 *  \param  key  EC_KEY object1032 *  \return the EC_GROUP object (possibly NULL).1033 */1034OSSL_DEPRECATEDIN_3_0 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);1035 1036/** Sets the EC_GROUP of a EC_KEY object.1037 *  \param  key    EC_KEY object1038 *  \param  group  EC_GROUP to use in the EC_KEY object (note: the EC_KEY1039 *                 object will use an own copy of the EC_GROUP).1040 *  \return 1 on success and 0 if an error occurred.1041 */1042OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);1043 1044/** Returns the private key of a EC_KEY object.1045 *  \param  key  EC_KEY object1046 *  \return a BIGNUM with the private key (possibly NULL).1047 */1048OSSL_DEPRECATEDIN_3_0 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);1049 1050/** Sets the private key of a EC_KEY object.1051 *  \param  key  EC_KEY object1052 *  \param  prv  BIGNUM with the private key (note: the EC_KEY object1053 *               will use an own copy of the BIGNUM).1054 *  \return 1 on success and 0 if an error occurred.1055 */1056OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);1057 1058/** Returns the public key of a EC_KEY object.1059 *  \param  key  the EC_KEY object1060 *  \return a EC_POINT object with the public key (possibly NULL)1061 */1062OSSL_DEPRECATEDIN_3_0 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);1063 1064/** Sets the public key of a EC_KEY object.1065 *  \param  key  EC_KEY object1066 *  \param  pub  EC_POINT object with the public key (note: the EC_KEY object1067 *               will use an own copy of the EC_POINT object).1068 *  \return 1 on success and 0 if an error occurred.1069 */1070OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);1071 1072OSSL_DEPRECATEDIN_3_0 unsigned EC_KEY_get_enc_flags(const EC_KEY *key);1073OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);1074OSSL_DEPRECATEDIN_3_0 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);1075OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_conv_form(EC_KEY *eckey,1076                                                point_conversion_form_t cform);1077#  endif /*OPENSSL_NO_DEPRECATED_3_0 */1078 1079#  define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \1080    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)1081 1082#  ifndef OPENSSL_NO_DEPRECATED_3_01083OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg);1084OSSL_DEPRECATEDIN_3_0 void *EC_KEY_get_ex_data(const EC_KEY *key, int idx);1085 1086/* wrapper functions for the underlying EC_GROUP object */1087OSSL_DEPRECATEDIN_3_0 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);1088 1089/** Creates a table of pre-computed multiples of the generator to1090 *  accelerate further EC_KEY operations.1091 *  \param  key  EC_KEY object1092 *  \param  ctx  BN_CTX object (optional)1093 *  \return 1 on success and 0 if an error occurred.1094 */1095OSSL_DEPRECATEDIN_3_0 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);1096 1097/** Creates a new ec private (and optional a new public) key.1098 *  \param  key  EC_KEY object1099 *  \return 1 on success and 0 if an error occurred.1100 */1101OSSL_DEPRECATEDIN_3_0 int EC_KEY_generate_key(EC_KEY *key);1102 1103/** Verifies that a private and/or public key is valid.1104 *  \param  key  the EC_KEY object1105 *  \return 1 on success and 0 otherwise.1106 */1107OSSL_DEPRECATEDIN_3_0 int EC_KEY_check_key(const EC_KEY *key);1108 1109/** Indicates if an EC_KEY can be used for signing.1110 *  \param  eckey  the EC_KEY object1111 *  \return 1 if can can sign and 0 otherwise.1112 */1113OSSL_DEPRECATEDIN_3_0 int EC_KEY_can_sign(const EC_KEY *eckey);1114 1115/** Sets a public key from affine coordinates performing1116 *  necessary NIST PKV tests.1117 *  \param  key  the EC_KEY object1118 *  \param  x    public key x coordinate1119 *  \param  y    public key y coordinate1120 *  \return 1 on success and 0 otherwise.1121 */1122OSSL_DEPRECATEDIN_3_0 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key,1123                                                                   BIGNUM *x,1124                                                                   BIGNUM *y);1125 1126/** Encodes an EC_KEY public key to an allocated octet string1127 *  \param  key    key to encode1128 *  \param  form   point conversion form1129 *  \param  pbuf   returns pointer to allocated buffer1130 *  \param  ctx    BN_CTX object (optional)1131 *  \return the length of the encoded octet string or 0 if an error occurred1132 */1133OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_key2buf(const EC_KEY *key,1134                                            point_conversion_form_t form,1135                                            unsigned char **pbuf, BN_CTX *ctx);1136 1137/** Decodes a EC_KEY public key from a octet string1138 *  \param  key    key to decode1139 *  \param  buf    memory buffer with the encoded ec point1140 *  \param  len    length of the encoded ec point1141 *  \param  ctx    BN_CTX object (optional)1142 *  \return 1 on success and 0 if an error occurred1143 */1144 1145OSSL_DEPRECATEDIN_3_0 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf,1146                                         size_t len, BN_CTX *ctx);1147 1148/** Decodes an EC_KEY private key from an octet string1149 *  \param  key    key to decode1150 *  \param  buf    memory buffer with the encoded private key1151 *  \param  len    length of the encoded key1152 *  \return 1 on success and 0 if an error occurred1153 */1154 1155OSSL_DEPRECATEDIN_3_0 int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf,1156                                          size_t len);1157 1158/** Encodes a EC_KEY private key to an octet string1159 *  \param  key    key to encode1160 *  \param  buf    memory buffer for the result. If NULL the function returns1161 *                 required buffer size.1162 *  \param  len    length of the memory buffer1163 *  \return the length of the encoded octet string or 0 if an error occurred1164 */1165 1166OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_priv2oct(const EC_KEY *key,1167                                             unsigned char *buf, size_t len);1168 1169/** Encodes an EC_KEY private key to an allocated octet string1170 *  \param  eckey  key to encode1171 *  \param  pbuf   returns pointer to allocated buffer1172 *  \return the length of the encoded octet string or 0 if an error occurred1173 */1174OSSL_DEPRECATEDIN_3_0 size_t EC_KEY_priv2buf(const EC_KEY *eckey,1175                                             unsigned char **pbuf);1176 1177/********************************************************************/1178/*        de- and encoding functions for SEC1 ECPrivateKey          */1179/********************************************************************/1180 1181/** Decodes a private key from a memory buffer.1182 *  \param  key  a pointer to a EC_KEY object which should be used (or NULL)1183 *  \param  in   pointer to memory with the DER encoded private key1184 *  \param  len  length of the DER encoded private key1185 *  \return the decoded private key or NULL if an error occurred.1186 */1187OSSL_DEPRECATEDIN_3_0 EC_KEY *d2i_ECPrivateKey(EC_KEY **key,1188                                               const unsigned char **in,1189                                               long len);1190 1191/** Encodes a private key object and stores the result in a buffer.1192 *  \param  key  the EC_KEY object to encode1193 *  \param  out  the buffer for the result (if NULL the function returns number1194 *               of bytes needed).1195 *  \return 1 on success and 0 if an error occurred.1196 */1197OSSL_DEPRECATEDIN_3_0 int i2d_ECPrivateKey(const EC_KEY *key,1198                                           unsigned char **out);1199 1200/********************************************************************/

Showing the first 1,200 of 1570 lines. Download the file for the rest.

codekingpro/portable-devtools · Team Ai