annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/openssl/ec.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 /*
jpayne@69 2 * Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
jpayne@69 3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
jpayne@69 4 *
jpayne@69 5 * Licensed under the OpenSSL license (the "License"). You may not use
jpayne@69 6 * this file except in compliance with the License. You can obtain a copy
jpayne@69 7 * in the file LICENSE in the source distribution or at
jpayne@69 8 * https://www.openssl.org/source/license.html
jpayne@69 9 */
jpayne@69 10
jpayne@69 11 #ifndef HEADER_EC_H
jpayne@69 12 # define HEADER_EC_H
jpayne@69 13
jpayne@69 14 # include <openssl/opensslconf.h>
jpayne@69 15
jpayne@69 16 # ifndef OPENSSL_NO_EC
jpayne@69 17 # include <openssl/asn1.h>
jpayne@69 18 # include <openssl/symhacks.h>
jpayne@69 19 # if OPENSSL_API_COMPAT < 0x10100000L
jpayne@69 20 # include <openssl/bn.h>
jpayne@69 21 # endif
jpayne@69 22 # include <openssl/ecerr.h>
jpayne@69 23 # ifdef __cplusplus
jpayne@69 24 extern "C" {
jpayne@69 25 # endif
jpayne@69 26
jpayne@69 27 # ifndef OPENSSL_ECC_MAX_FIELD_BITS
jpayne@69 28 # define OPENSSL_ECC_MAX_FIELD_BITS 661
jpayne@69 29 # endif
jpayne@69 30
jpayne@69 31 /** Enum for the point conversion form as defined in X9.62 (ECDSA)
jpayne@69 32 * for the encoding of a elliptic curve point (x,y) */
jpayne@69 33 typedef enum {
jpayne@69 34 /** the point is encoded as z||x, where the octet z specifies
jpayne@69 35 * which solution of the quadratic equation y is */
jpayne@69 36 POINT_CONVERSION_COMPRESSED = 2,
jpayne@69 37 /** the point is encoded as z||x||y, where z is the octet 0x04 */
jpayne@69 38 POINT_CONVERSION_UNCOMPRESSED = 4,
jpayne@69 39 /** the point is encoded as z||x||y, where the octet z specifies
jpayne@69 40 * which solution of the quadratic equation y is */
jpayne@69 41 POINT_CONVERSION_HYBRID = 6
jpayne@69 42 } point_conversion_form_t;
jpayne@69 43
jpayne@69 44 typedef struct ec_method_st EC_METHOD;
jpayne@69 45 typedef struct ec_group_st EC_GROUP;
jpayne@69 46 typedef struct ec_point_st EC_POINT;
jpayne@69 47 typedef struct ecpk_parameters_st ECPKPARAMETERS;
jpayne@69 48 typedef struct ec_parameters_st ECPARAMETERS;
jpayne@69 49
jpayne@69 50 /********************************************************************/
jpayne@69 51 /* EC_METHODs for curves over GF(p) */
jpayne@69 52 /********************************************************************/
jpayne@69 53
jpayne@69 54 /** Returns the basic GFp ec methods which provides the basis for the
jpayne@69 55 * optimized methods.
jpayne@69 56 * \return EC_METHOD object
jpayne@69 57 */
jpayne@69 58 const EC_METHOD *EC_GFp_simple_method(void);
jpayne@69 59
jpayne@69 60 /** Returns GFp methods using montgomery multiplication.
jpayne@69 61 * \return EC_METHOD object
jpayne@69 62 */
jpayne@69 63 const EC_METHOD *EC_GFp_mont_method(void);
jpayne@69 64
jpayne@69 65 /** Returns GFp methods using optimized methods for NIST recommended curves
jpayne@69 66 * \return EC_METHOD object
jpayne@69 67 */
jpayne@69 68 const EC_METHOD *EC_GFp_nist_method(void);
jpayne@69 69
jpayne@69 70 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
jpayne@69 71 /** Returns 64-bit optimized methods for nistp224
jpayne@69 72 * \return EC_METHOD object
jpayne@69 73 */
jpayne@69 74 const EC_METHOD *EC_GFp_nistp224_method(void);
jpayne@69 75
jpayne@69 76 /** Returns 64-bit optimized methods for nistp256
jpayne@69 77 * \return EC_METHOD object
jpayne@69 78 */
jpayne@69 79 const EC_METHOD *EC_GFp_nistp256_method(void);
jpayne@69 80
jpayne@69 81 /** Returns 64-bit optimized methods for nistp521
jpayne@69 82 * \return EC_METHOD object
jpayne@69 83 */
jpayne@69 84 const EC_METHOD *EC_GFp_nistp521_method(void);
jpayne@69 85 # endif
jpayne@69 86
jpayne@69 87 # ifndef OPENSSL_NO_EC2M
jpayne@69 88 /********************************************************************/
jpayne@69 89 /* EC_METHOD for curves over GF(2^m) */
jpayne@69 90 /********************************************************************/
jpayne@69 91
jpayne@69 92 /** Returns the basic GF2m ec method
jpayne@69 93 * \return EC_METHOD object
jpayne@69 94 */
jpayne@69 95 const EC_METHOD *EC_GF2m_simple_method(void);
jpayne@69 96
jpayne@69 97 # endif
jpayne@69 98
jpayne@69 99 /********************************************************************/
jpayne@69 100 /* EC_GROUP functions */
jpayne@69 101 /********************************************************************/
jpayne@69 102
jpayne@69 103 /** Creates a new EC_GROUP object
jpayne@69 104 * \param meth EC_METHOD to use
jpayne@69 105 * \return newly created EC_GROUP object or NULL in case of an error.
jpayne@69 106 */
jpayne@69 107 EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
jpayne@69 108
jpayne@69 109 /** Frees a EC_GROUP object
jpayne@69 110 * \param group EC_GROUP object to be freed.
jpayne@69 111 */
jpayne@69 112 void EC_GROUP_free(EC_GROUP *group);
jpayne@69 113
jpayne@69 114 /** Clears and frees a EC_GROUP object
jpayne@69 115 * \param group EC_GROUP object to be cleared and freed.
jpayne@69 116 */
jpayne@69 117 void EC_GROUP_clear_free(EC_GROUP *group);
jpayne@69 118
jpayne@69 119 /** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
jpayne@69 120 * \param dst destination EC_GROUP object
jpayne@69 121 * \param src source EC_GROUP object
jpayne@69 122 * \return 1 on success and 0 if an error occurred.
jpayne@69 123 */
jpayne@69 124 int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
jpayne@69 125
jpayne@69 126 /** Creates a new EC_GROUP object and copies the copies the content
jpayne@69 127 * form src to the newly created EC_KEY object
jpayne@69 128 * \param src source EC_GROUP object
jpayne@69 129 * \return newly created EC_GROUP object or NULL in case of an error.
jpayne@69 130 */
jpayne@69 131 EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
jpayne@69 132
jpayne@69 133 /** Returns the EC_METHOD of the EC_GROUP object.
jpayne@69 134 * \param group EC_GROUP object
jpayne@69 135 * \return EC_METHOD used in this EC_GROUP object.
jpayne@69 136 */
jpayne@69 137 const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
jpayne@69 138
jpayne@69 139 /** Returns the field type of the EC_METHOD.
jpayne@69 140 * \param meth EC_METHOD object
jpayne@69 141 * \return NID of the underlying field type OID.
jpayne@69 142 */
jpayne@69 143 int EC_METHOD_get_field_type(const EC_METHOD *meth);
jpayne@69 144
jpayne@69 145 /** Sets the generator and its order/cofactor of a EC_GROUP object.
jpayne@69 146 * \param group EC_GROUP object
jpayne@69 147 * \param generator EC_POINT object with the generator.
jpayne@69 148 * \param order the order of the group generated by the generator.
jpayne@69 149 * \param cofactor the index of the sub-group generated by the generator
jpayne@69 150 * in the group of all points on the elliptic curve.
jpayne@69 151 * \return 1 on success and 0 if an error occurred
jpayne@69 152 */
jpayne@69 153 int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
jpayne@69 154 const BIGNUM *order, const BIGNUM *cofactor);
jpayne@69 155
jpayne@69 156 /** Returns the generator of a EC_GROUP object.
jpayne@69 157 * \param group EC_GROUP object
jpayne@69 158 * \return the currently used generator (possibly NULL).
jpayne@69 159 */
jpayne@69 160 const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
jpayne@69 161
jpayne@69 162 /** Returns the montgomery data for order(Generator)
jpayne@69 163 * \param group EC_GROUP object
jpayne@69 164 * \return the currently used montgomery data (possibly NULL).
jpayne@69 165 */
jpayne@69 166 BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group);
jpayne@69 167
jpayne@69 168 /** Gets the order of a EC_GROUP
jpayne@69 169 * \param group EC_GROUP object
jpayne@69 170 * \param order BIGNUM to which the order is copied
jpayne@69 171 * \param ctx unused
jpayne@69 172 * \return 1 on success and 0 if an error occurred
jpayne@69 173 */
jpayne@69 174 int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
jpayne@69 175
jpayne@69 176 /** Gets the order of an EC_GROUP
jpayne@69 177 * \param group EC_GROUP object
jpayne@69 178 * \return the group order
jpayne@69 179 */
jpayne@69 180 const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
jpayne@69 181
jpayne@69 182 /** Gets the number of bits of the order of an EC_GROUP
jpayne@69 183 * \param group EC_GROUP object
jpayne@69 184 * \return number of bits of group order.
jpayne@69 185 */
jpayne@69 186 int EC_GROUP_order_bits(const EC_GROUP *group);
jpayne@69 187
jpayne@69 188 /** Gets the cofactor of a EC_GROUP
jpayne@69 189 * \param group EC_GROUP object
jpayne@69 190 * \param cofactor BIGNUM to which the cofactor is copied
jpayne@69 191 * \param ctx unused
jpayne@69 192 * \return 1 on success and 0 if an error occurred
jpayne@69 193 */
jpayne@69 194 int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
jpayne@69 195 BN_CTX *ctx);
jpayne@69 196
jpayne@69 197 /** Gets the cofactor of an EC_GROUP
jpayne@69 198 * \param group EC_GROUP object
jpayne@69 199 * \return the group cofactor
jpayne@69 200 */
jpayne@69 201 const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);
jpayne@69 202
jpayne@69 203 /** Sets the name of a EC_GROUP object
jpayne@69 204 * \param group EC_GROUP object
jpayne@69 205 * \param nid NID of the curve name OID
jpayne@69 206 */
jpayne@69 207 void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
jpayne@69 208
jpayne@69 209 /** Returns the curve name of a EC_GROUP object
jpayne@69 210 * \param group EC_GROUP object
jpayne@69 211 * \return NID of the curve name OID or 0 if not set.
jpayne@69 212 */
jpayne@69 213 int EC_GROUP_get_curve_name(const EC_GROUP *group);
jpayne@69 214
jpayne@69 215 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
jpayne@69 216 int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
jpayne@69 217
jpayne@69 218 void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
jpayne@69 219 point_conversion_form_t form);
jpayne@69 220 point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
jpayne@69 221
jpayne@69 222 unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
jpayne@69 223 size_t EC_GROUP_get_seed_len(const EC_GROUP *);
jpayne@69 224 size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
jpayne@69 225
jpayne@69 226 /** Sets the parameters of a ec curve defined by y^2 = x^3 + a*x + b (for GFp)
jpayne@69 227 * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m)
jpayne@69 228 * \param group EC_GROUP object
jpayne@69 229 * \param p BIGNUM with the prime number (GFp) or the polynomial
jpayne@69 230 * defining the underlying field (GF2m)
jpayne@69 231 * \param a BIGNUM with parameter a of the equation
jpayne@69 232 * \param b BIGNUM with parameter b of the equation
jpayne@69 233 * \param ctx BN_CTX object (optional)
jpayne@69 234 * \return 1 on success and 0 if an error occurred
jpayne@69 235 */
jpayne@69 236 int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
jpayne@69 237 const BIGNUM *b, BN_CTX *ctx);
jpayne@69 238
jpayne@69 239 /** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp)
jpayne@69 240 * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m)
jpayne@69 241 * \param group EC_GROUP object
jpayne@69 242 * \param p BIGNUM with the prime number (GFp) or the polynomial
jpayne@69 243 * defining the underlying field (GF2m)
jpayne@69 244 * \param a BIGNUM for parameter a of the equation
jpayne@69 245 * \param b BIGNUM for parameter b of the equation
jpayne@69 246 * \param ctx BN_CTX object (optional)
jpayne@69 247 * \return 1 on success and 0 if an error occurred
jpayne@69 248 */
jpayne@69 249 int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
jpayne@69 250 BN_CTX *ctx);
jpayne@69 251
jpayne@69 252 /** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve
jpayne@69 253 * \param group EC_GROUP object
jpayne@69 254 * \param p BIGNUM with the prime number (GFp) or the polynomial
jpayne@69 255 * defining the underlying field (GF2m)
jpayne@69 256 * \param a BIGNUM with parameter a of the equation
jpayne@69 257 * \param b BIGNUM with parameter b of the equation
jpayne@69 258 * \param ctx BN_CTX object (optional)
jpayne@69 259 * \return 1 on success and 0 if an error occurred
jpayne@69 260 */
jpayne@69 261 DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p,
jpayne@69 262 const BIGNUM *a, const BIGNUM *b,
jpayne@69 263 BN_CTX *ctx))
jpayne@69 264
jpayne@69 265 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve
jpayne@69 266 * \param group EC_GROUP object
jpayne@69 267 * \param p BIGNUM with the prime number (GFp) or the polynomial
jpayne@69 268 * defining the underlying field (GF2m)
jpayne@69 269 * \param a BIGNUM for parameter a of the equation
jpayne@69 270 * \param b BIGNUM for parameter b of the equation
jpayne@69 271 * \param ctx BN_CTX object (optional)
jpayne@69 272 * \return 1 on success and 0 if an error occurred
jpayne@69 273 */
jpayne@69 274 DEPRECATEDIN_1_2_0(int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p,
jpayne@69 275 BIGNUM *a, BIGNUM *b,
jpayne@69 276 BN_CTX *ctx))
jpayne@69 277
jpayne@69 278 # ifndef OPENSSL_NO_EC2M
jpayne@69 279 /** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve
jpayne@69 280 * \param group EC_GROUP object
jpayne@69 281 * \param p BIGNUM with the prime number (GFp) or the polynomial
jpayne@69 282 * defining the underlying field (GF2m)
jpayne@69 283 * \param a BIGNUM with parameter a of the equation
jpayne@69 284 * \param b BIGNUM with parameter b of the equation
jpayne@69 285 * \param ctx BN_CTX object (optional)
jpayne@69 286 * \return 1 on success and 0 if an error occurred
jpayne@69 287 */
jpayne@69 288 DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p,
jpayne@69 289 const BIGNUM *a, const BIGNUM *b,
jpayne@69 290 BN_CTX *ctx))
jpayne@69 291
jpayne@69 292 /** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve
jpayne@69 293 * \param group EC_GROUP object
jpayne@69 294 * \param p BIGNUM with the prime number (GFp) or the polynomial
jpayne@69 295 * defining the underlying field (GF2m)
jpayne@69 296 * \param a BIGNUM for parameter a of the equation
jpayne@69 297 * \param b BIGNUM for parameter b of the equation
jpayne@69 298 * \param ctx BN_CTX object (optional)
jpayne@69 299 * \return 1 on success and 0 if an error occurred
jpayne@69 300 */
jpayne@69 301 DEPRECATEDIN_1_2_0(int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p,
jpayne@69 302 BIGNUM *a, BIGNUM *b,
jpayne@69 303 BN_CTX *ctx))
jpayne@69 304 # endif
jpayne@69 305 /** Returns the number of bits needed to represent a field element
jpayne@69 306 * \param group EC_GROUP object
jpayne@69 307 * \return number of bits needed to represent a field element
jpayne@69 308 */
jpayne@69 309 int EC_GROUP_get_degree(const EC_GROUP *group);
jpayne@69 310
jpayne@69 311 /** Checks whether the parameter in the EC_GROUP define a valid ec group
jpayne@69 312 * \param group EC_GROUP object
jpayne@69 313 * \param ctx BN_CTX object (optional)
jpayne@69 314 * \return 1 if group is a valid ec group and 0 otherwise
jpayne@69 315 */
jpayne@69 316 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
jpayne@69 317
jpayne@69 318 /** Checks whether the discriminant of the elliptic curve is zero or not
jpayne@69 319 * \param group EC_GROUP object
jpayne@69 320 * \param ctx BN_CTX object (optional)
jpayne@69 321 * \return 1 if the discriminant is not zero and 0 otherwise
jpayne@69 322 */
jpayne@69 323 int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
jpayne@69 324
jpayne@69 325 /** Compares two EC_GROUP objects
jpayne@69 326 * \param a first EC_GROUP object
jpayne@69 327 * \param b second EC_GROUP object
jpayne@69 328 * \param ctx BN_CTX object (optional)
jpayne@69 329 * \return 0 if the groups are equal, 1 if not, or -1 on error
jpayne@69 330 */
jpayne@69 331 int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
jpayne@69 332
jpayne@69 333 /*
jpayne@69 334 * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after
jpayne@69 335 * choosing an appropriate EC_METHOD
jpayne@69 336 */
jpayne@69 337
jpayne@69 338 /** Creates a new EC_GROUP object with the specified parameters defined
jpayne@69 339 * over GFp (defined by the equation y^2 = x^3 + a*x + b)
jpayne@69 340 * \param p BIGNUM with the prime number
jpayne@69 341 * \param a BIGNUM with the parameter a of the equation
jpayne@69 342 * \param b BIGNUM with the parameter b of the equation
jpayne@69 343 * \param ctx BN_CTX object (optional)
jpayne@69 344 * \return newly created EC_GROUP object with the specified parameters
jpayne@69 345 */
jpayne@69 346 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
jpayne@69 347 const BIGNUM *b, BN_CTX *ctx);
jpayne@69 348 # ifndef OPENSSL_NO_EC2M
jpayne@69 349 /** Creates a new EC_GROUP object with the specified parameters defined
jpayne@69 350 * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b)
jpayne@69 351 * \param p BIGNUM with the polynomial defining the underlying field
jpayne@69 352 * \param a BIGNUM with the parameter a of the equation
jpayne@69 353 * \param b BIGNUM with the parameter b of the equation
jpayne@69 354 * \param ctx BN_CTX object (optional)
jpayne@69 355 * \return newly created EC_GROUP object with the specified parameters
jpayne@69 356 */
jpayne@69 357 EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
jpayne@69 358 const BIGNUM *b, BN_CTX *ctx);
jpayne@69 359 # endif
jpayne@69 360
jpayne@69 361 /** Creates a EC_GROUP object with a curve specified by a NID
jpayne@69 362 * \param nid NID of the OID of the curve name
jpayne@69 363 * \return newly created EC_GROUP object with specified curve or NULL
jpayne@69 364 * if an error occurred
jpayne@69 365 */
jpayne@69 366 EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
jpayne@69 367
jpayne@69 368 /** Creates a new EC_GROUP object from an ECPARAMETERS object
jpayne@69 369 * \param params pointer to the ECPARAMETERS object
jpayne@69 370 * \return newly created EC_GROUP object with specified curve or NULL
jpayne@69 371 * if an error occurred
jpayne@69 372 */
jpayne@69 373 EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params);
jpayne@69 374
jpayne@69 375 /** Creates an ECPARAMETERS object for the given EC_GROUP object.
jpayne@69 376 * \param group pointer to the EC_GROUP object
jpayne@69 377 * \param params pointer to an existing ECPARAMETERS object or NULL
jpayne@69 378 * \return pointer to the new ECPARAMETERS object or NULL
jpayne@69 379 * if an error occurred.
jpayne@69 380 */
jpayne@69 381 ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
jpayne@69 382 ECPARAMETERS *params);
jpayne@69 383
jpayne@69 384 /** Creates a new EC_GROUP object from an ECPKPARAMETERS object
jpayne@69 385 * \param params pointer to an existing ECPKPARAMETERS object, or NULL
jpayne@69 386 * \return newly created EC_GROUP object with specified curve, or NULL
jpayne@69 387 * if an error occurred
jpayne@69 388 */
jpayne@69 389 EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params);
jpayne@69 390
jpayne@69 391 /** Creates an ECPKPARAMETERS object for the given EC_GROUP object.
jpayne@69 392 * \param group pointer to the EC_GROUP object
jpayne@69 393 * \param params pointer to an existing ECPKPARAMETERS object or NULL
jpayne@69 394 * \return pointer to the new ECPKPARAMETERS object or NULL
jpayne@69 395 * if an error occurred.
jpayne@69 396 */
jpayne@69 397 ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group,
jpayne@69 398 ECPKPARAMETERS *params);
jpayne@69 399
jpayne@69 400 /********************************************************************/
jpayne@69 401 /* handling of internal curves */
jpayne@69 402 /********************************************************************/
jpayne@69 403
jpayne@69 404 typedef struct {
jpayne@69 405 int nid;
jpayne@69 406 const char *comment;
jpayne@69 407 } EC_builtin_curve;
jpayne@69 408
jpayne@69 409 /*
jpayne@69 410 * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all
jpayne@69 411 * available curves or zero if a error occurred. In case r is not zero,
jpayne@69 412 * nitems EC_builtin_curve structures are filled with the data of the first
jpayne@69 413 * nitems internal groups
jpayne@69 414 */
jpayne@69 415 size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
jpayne@69 416
jpayne@69 417 const char *EC_curve_nid2nist(int nid);
jpayne@69 418 int EC_curve_nist2nid(const char *name);
jpayne@69 419
jpayne@69 420 /********************************************************************/
jpayne@69 421 /* EC_POINT functions */
jpayne@69 422 /********************************************************************/
jpayne@69 423
jpayne@69 424 /** Creates a new EC_POINT object for the specified EC_GROUP
jpayne@69 425 * \param group EC_GROUP the underlying EC_GROUP object
jpayne@69 426 * \return newly created EC_POINT object or NULL if an error occurred
jpayne@69 427 */
jpayne@69 428 EC_POINT *EC_POINT_new(const EC_GROUP *group);
jpayne@69 429
jpayne@69 430 /** Frees a EC_POINT object
jpayne@69 431 * \param point EC_POINT object to be freed
jpayne@69 432 */
jpayne@69 433 void EC_POINT_free(EC_POINT *point);
jpayne@69 434
jpayne@69 435 /** Clears and frees a EC_POINT object
jpayne@69 436 * \param point EC_POINT object to be cleared and freed
jpayne@69 437 */
jpayne@69 438 void EC_POINT_clear_free(EC_POINT *point);
jpayne@69 439
jpayne@69 440 /** Copies EC_POINT object
jpayne@69 441 * \param dst destination EC_POINT object
jpayne@69 442 * \param src source EC_POINT object
jpayne@69 443 * \return 1 on success and 0 if an error occurred
jpayne@69 444 */
jpayne@69 445 int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
jpayne@69 446
jpayne@69 447 /** Creates a new EC_POINT object and copies the content of the supplied
jpayne@69 448 * EC_POINT
jpayne@69 449 * \param src source EC_POINT object
jpayne@69 450 * \param group underlying the EC_GROUP object
jpayne@69 451 * \return newly created EC_POINT object or NULL if an error occurred
jpayne@69 452 */
jpayne@69 453 EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
jpayne@69 454
jpayne@69 455 /** Returns the EC_METHOD used in EC_POINT object
jpayne@69 456 * \param point EC_POINT object
jpayne@69 457 * \return the EC_METHOD used
jpayne@69 458 */
jpayne@69 459 const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
jpayne@69 460
jpayne@69 461 /** Sets a point to infinity (neutral element)
jpayne@69 462 * \param group underlying EC_GROUP object
jpayne@69 463 * \param point EC_POINT to set to infinity
jpayne@69 464 * \return 1 on success and 0 if an error occurred
jpayne@69 465 */
jpayne@69 466 int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
jpayne@69 467
jpayne@69 468 /** Sets the jacobian projective coordinates of a EC_POINT over GFp
jpayne@69 469 * \param group underlying EC_GROUP object
jpayne@69 470 * \param p EC_POINT object
jpayne@69 471 * \param x BIGNUM with the x-coordinate
jpayne@69 472 * \param y BIGNUM with the y-coordinate
jpayne@69 473 * \param z BIGNUM with the z-coordinate
jpayne@69 474 * \param ctx BN_CTX object (optional)
jpayne@69 475 * \return 1 on success and 0 if an error occurred
jpayne@69 476 */
jpayne@69 477 int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
jpayne@69 478 EC_POINT *p, const BIGNUM *x,
jpayne@69 479 const BIGNUM *y, const BIGNUM *z,
jpayne@69 480 BN_CTX *ctx);
jpayne@69 481
jpayne@69 482 /** Gets the jacobian projective coordinates of a EC_POINT over GFp
jpayne@69 483 * \param group underlying EC_GROUP object
jpayne@69 484 * \param p EC_POINT object
jpayne@69 485 * \param x BIGNUM for the x-coordinate
jpayne@69 486 * \param y BIGNUM for the y-coordinate
jpayne@69 487 * \param z BIGNUM for the z-coordinate
jpayne@69 488 * \param ctx BN_CTX object (optional)
jpayne@69 489 * \return 1 on success and 0 if an error occurred
jpayne@69 490 */
jpayne@69 491 int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
jpayne@69 492 const EC_POINT *p, BIGNUM *x,
jpayne@69 493 BIGNUM *y, BIGNUM *z,
jpayne@69 494 BN_CTX *ctx);
jpayne@69 495
jpayne@69 496 /** Sets the affine coordinates of an EC_POINT
jpayne@69 497 * \param group underlying EC_GROUP object
jpayne@69 498 * \param p EC_POINT object
jpayne@69 499 * \param x BIGNUM with the x-coordinate
jpayne@69 500 * \param y BIGNUM with the y-coordinate
jpayne@69 501 * \param ctx BN_CTX object (optional)
jpayne@69 502 * \return 1 on success and 0 if an error occurred
jpayne@69 503 */
jpayne@69 504 int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p,
jpayne@69 505 const BIGNUM *x, const BIGNUM *y,
jpayne@69 506 BN_CTX *ctx);
jpayne@69 507
jpayne@69 508 /** Gets the affine coordinates of an EC_POINT.
jpayne@69 509 * \param group underlying EC_GROUP object
jpayne@69 510 * \param p EC_POINT object
jpayne@69 511 * \param x BIGNUM for the x-coordinate
jpayne@69 512 * \param y BIGNUM for the y-coordinate
jpayne@69 513 * \param ctx BN_CTX object (optional)
jpayne@69 514 * \return 1 on success and 0 if an error occurred
jpayne@69 515 */
jpayne@69 516 int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p,
jpayne@69 517 BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
jpayne@69 518
jpayne@69 519 /** Sets the affine coordinates of an EC_POINT. A synonym of
jpayne@69 520 * EC_POINT_set_affine_coordinates
jpayne@69 521 * \param group underlying EC_GROUP object
jpayne@69 522 * \param p EC_POINT object
jpayne@69 523 * \param x BIGNUM with the x-coordinate
jpayne@69 524 * \param y BIGNUM with the y-coordinate
jpayne@69 525 * \param ctx BN_CTX object (optional)
jpayne@69 526 * \return 1 on success and 0 if an error occurred
jpayne@69 527 */
jpayne@69 528 DEPRECATEDIN_1_2_0(int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
jpayne@69 529 EC_POINT *p,
jpayne@69 530 const BIGNUM *x,
jpayne@69 531 const BIGNUM *y,
jpayne@69 532 BN_CTX *ctx))
jpayne@69 533
jpayne@69 534 /** Gets the affine coordinates of an EC_POINT. A synonym of
jpayne@69 535 * EC_POINT_get_affine_coordinates
jpayne@69 536 * \param group underlying EC_GROUP object
jpayne@69 537 * \param p EC_POINT object
jpayne@69 538 * \param x BIGNUM for the x-coordinate
jpayne@69 539 * \param y BIGNUM for the y-coordinate
jpayne@69 540 * \param ctx BN_CTX object (optional)
jpayne@69 541 * \return 1 on success and 0 if an error occurred
jpayne@69 542 */
jpayne@69 543 DEPRECATEDIN_1_2_0(int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
jpayne@69 544 const EC_POINT *p,
jpayne@69 545 BIGNUM *x,
jpayne@69 546 BIGNUM *y,
jpayne@69 547 BN_CTX *ctx))
jpayne@69 548
jpayne@69 549 /** Sets the x9.62 compressed coordinates of a EC_POINT
jpayne@69 550 * \param group underlying EC_GROUP object
jpayne@69 551 * \param p EC_POINT object
jpayne@69 552 * \param x BIGNUM with x-coordinate
jpayne@69 553 * \param y_bit integer with the y-Bit (either 0 or 1)
jpayne@69 554 * \param ctx BN_CTX object (optional)
jpayne@69 555 * \return 1 on success and 0 if an error occurred
jpayne@69 556 */
jpayne@69 557 int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p,
jpayne@69 558 const BIGNUM *x, int y_bit,
jpayne@69 559 BN_CTX *ctx);
jpayne@69 560
jpayne@69 561 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
jpayne@69 562 * EC_POINT_set_compressed_coordinates
jpayne@69 563 * \param group underlying EC_GROUP object
jpayne@69 564 * \param p EC_POINT object
jpayne@69 565 * \param x BIGNUM with x-coordinate
jpayne@69 566 * \param y_bit integer with the y-Bit (either 0 or 1)
jpayne@69 567 * \param ctx BN_CTX object (optional)
jpayne@69 568 * \return 1 on success and 0 if an error occurred
jpayne@69 569 */
jpayne@69 570 DEPRECATEDIN_1_2_0(int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group,
jpayne@69 571 EC_POINT *p,
jpayne@69 572 const BIGNUM *x,
jpayne@69 573 int y_bit,
jpayne@69 574 BN_CTX *ctx))
jpayne@69 575 # ifndef OPENSSL_NO_EC2M
jpayne@69 576 /** Sets the affine coordinates of an EC_POINT. A synonym of
jpayne@69 577 * EC_POINT_set_affine_coordinates
jpayne@69 578 * \param group underlying EC_GROUP object
jpayne@69 579 * \param p EC_POINT object
jpayne@69 580 * \param x BIGNUM with the x-coordinate
jpayne@69 581 * \param y BIGNUM with the y-coordinate
jpayne@69 582 * \param ctx BN_CTX object (optional)
jpayne@69 583 * \return 1 on success and 0 if an error occurred
jpayne@69 584 */
jpayne@69 585 DEPRECATEDIN_1_2_0(int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group,
jpayne@69 586 EC_POINT *p,
jpayne@69 587 const BIGNUM *x,
jpayne@69 588 const BIGNUM *y,
jpayne@69 589 BN_CTX *ctx))
jpayne@69 590
jpayne@69 591 /** Gets the affine coordinates of an EC_POINT. A synonym of
jpayne@69 592 * EC_POINT_get_affine_coordinates
jpayne@69 593 * \param group underlying EC_GROUP object
jpayne@69 594 * \param p EC_POINT object
jpayne@69 595 * \param x BIGNUM for the x-coordinate
jpayne@69 596 * \param y BIGNUM for the y-coordinate
jpayne@69 597 * \param ctx BN_CTX object (optional)
jpayne@69 598 * \return 1 on success and 0 if an error occurred
jpayne@69 599 */
jpayne@69 600 DEPRECATEDIN_1_2_0(int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
jpayne@69 601 const EC_POINT *p,
jpayne@69 602 BIGNUM *x,
jpayne@69 603 BIGNUM *y,
jpayne@69 604 BN_CTX *ctx))
jpayne@69 605
jpayne@69 606 /** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of
jpayne@69 607 * EC_POINT_set_compressed_coordinates
jpayne@69 608 * \param group underlying EC_GROUP object
jpayne@69 609 * \param p EC_POINT object
jpayne@69 610 * \param x BIGNUM with x-coordinate
jpayne@69 611 * \param y_bit integer with the y-Bit (either 0 or 1)
jpayne@69 612 * \param ctx BN_CTX object (optional)
jpayne@69 613 * \return 1 on success and 0 if an error occurred
jpayne@69 614 */
jpayne@69 615 DEPRECATEDIN_1_2_0(int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
jpayne@69 616 EC_POINT *p,
jpayne@69 617 const BIGNUM *x,
jpayne@69 618 int y_bit,
jpayne@69 619 BN_CTX *ctx))
jpayne@69 620 # endif
jpayne@69 621 /** Encodes a EC_POINT object to a octet string
jpayne@69 622 * \param group underlying EC_GROUP object
jpayne@69 623 * \param p EC_POINT object
jpayne@69 624 * \param form point conversion form
jpayne@69 625 * \param buf memory buffer for the result. If NULL the function returns
jpayne@69 626 * required buffer size.
jpayne@69 627 * \param len length of the memory buffer
jpayne@69 628 * \param ctx BN_CTX object (optional)
jpayne@69 629 * \return the length of the encoded octet string or 0 if an error occurred
jpayne@69 630 */
jpayne@69 631 size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
jpayne@69 632 point_conversion_form_t form,
jpayne@69 633 unsigned char *buf, size_t len, BN_CTX *ctx);
jpayne@69 634
jpayne@69 635 /** Decodes a EC_POINT from a octet string
jpayne@69 636 * \param group underlying EC_GROUP object
jpayne@69 637 * \param p EC_POINT object
jpayne@69 638 * \param buf memory buffer with the encoded ec point
jpayne@69 639 * \param len length of the encoded ec point
jpayne@69 640 * \param ctx BN_CTX object (optional)
jpayne@69 641 * \return 1 on success and 0 if an error occurred
jpayne@69 642 */
jpayne@69 643 int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
jpayne@69 644 const unsigned char *buf, size_t len, BN_CTX *ctx);
jpayne@69 645
jpayne@69 646 /** Encodes an EC_POINT object to an allocated octet string
jpayne@69 647 * \param group underlying EC_GROUP object
jpayne@69 648 * \param point EC_POINT object
jpayne@69 649 * \param form point conversion form
jpayne@69 650 * \param pbuf returns pointer to allocated buffer
jpayne@69 651 * \param ctx BN_CTX object (optional)
jpayne@69 652 * \return the length of the encoded octet string or 0 if an error occurred
jpayne@69 653 */
jpayne@69 654 size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
jpayne@69 655 point_conversion_form_t form,
jpayne@69 656 unsigned char **pbuf, BN_CTX *ctx);
jpayne@69 657
jpayne@69 658 /* other interfaces to point2oct/oct2point: */
jpayne@69 659 BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
jpayne@69 660 point_conversion_form_t form, BIGNUM *, BN_CTX *);
jpayne@69 661 EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
jpayne@69 662 EC_POINT *, BN_CTX *);
jpayne@69 663 char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
jpayne@69 664 point_conversion_form_t form, BN_CTX *);
jpayne@69 665 EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
jpayne@69 666 EC_POINT *, BN_CTX *);
jpayne@69 667
jpayne@69 668 /********************************************************************/
jpayne@69 669 /* functions for doing EC_POINT arithmetic */
jpayne@69 670 /********************************************************************/
jpayne@69 671
jpayne@69 672 /** Computes the sum of two EC_POINT
jpayne@69 673 * \param group underlying EC_GROUP object
jpayne@69 674 * \param r EC_POINT object for the result (r = a + b)
jpayne@69 675 * \param a EC_POINT object with the first summand
jpayne@69 676 * \param b EC_POINT object with the second summand
jpayne@69 677 * \param ctx BN_CTX object (optional)
jpayne@69 678 * \return 1 on success and 0 if an error occurred
jpayne@69 679 */
jpayne@69 680 int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
jpayne@69 681 const EC_POINT *b, BN_CTX *ctx);
jpayne@69 682
jpayne@69 683 /** Computes the double of a EC_POINT
jpayne@69 684 * \param group underlying EC_GROUP object
jpayne@69 685 * \param r EC_POINT object for the result (r = 2 * a)
jpayne@69 686 * \param a EC_POINT object
jpayne@69 687 * \param ctx BN_CTX object (optional)
jpayne@69 688 * \return 1 on success and 0 if an error occurred
jpayne@69 689 */
jpayne@69 690 int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
jpayne@69 691 BN_CTX *ctx);
jpayne@69 692
jpayne@69 693 /** Computes the inverse of a EC_POINT
jpayne@69 694 * \param group underlying EC_GROUP object
jpayne@69 695 * \param a EC_POINT object to be inverted (it's used for the result as well)
jpayne@69 696 * \param ctx BN_CTX object (optional)
jpayne@69 697 * \return 1 on success and 0 if an error occurred
jpayne@69 698 */
jpayne@69 699 int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
jpayne@69 700
jpayne@69 701 /** Checks whether the point is the neutral element of the group
jpayne@69 702 * \param group the underlying EC_GROUP object
jpayne@69 703 * \param p EC_POINT object
jpayne@69 704 * \return 1 if the point is the neutral element and 0 otherwise
jpayne@69 705 */
jpayne@69 706 int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
jpayne@69 707
jpayne@69 708 /** Checks whether the point is on the curve
jpayne@69 709 * \param group underlying EC_GROUP object
jpayne@69 710 * \param point EC_POINT object to check
jpayne@69 711 * \param ctx BN_CTX object (optional)
jpayne@69 712 * \return 1 if the point is on the curve, 0 if not, or -1 on error
jpayne@69 713 */
jpayne@69 714 int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
jpayne@69 715 BN_CTX *ctx);
jpayne@69 716
jpayne@69 717 /** Compares two EC_POINTs
jpayne@69 718 * \param group underlying EC_GROUP object
jpayne@69 719 * \param a first EC_POINT object
jpayne@69 720 * \param b second EC_POINT object
jpayne@69 721 * \param ctx BN_CTX object (optional)
jpayne@69 722 * \return 1 if the points are not equal, 0 if they are, or -1 on error
jpayne@69 723 */
jpayne@69 724 int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
jpayne@69 725 BN_CTX *ctx);
jpayne@69 726
jpayne@69 727 int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);
jpayne@69 728 int EC_POINTs_make_affine(const EC_GROUP *group, size_t num,
jpayne@69 729 EC_POINT *points[], BN_CTX *ctx);
jpayne@69 730
jpayne@69 731 /** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i]
jpayne@69 732 * \param group underlying EC_GROUP object
jpayne@69 733 * \param r EC_POINT object for the result
jpayne@69 734 * \param n BIGNUM with the multiplier for the group generator (optional)
jpayne@69 735 * \param num number further summands
jpayne@69 736 * \param p array of size num of EC_POINT objects
jpayne@69 737 * \param m array of size num of BIGNUM objects
jpayne@69 738 * \param ctx BN_CTX object (optional)
jpayne@69 739 * \return 1 on success and 0 if an error occurred
jpayne@69 740 */
jpayne@69 741 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
jpayne@69 742 size_t num, const EC_POINT *p[], const BIGNUM *m[],
jpayne@69 743 BN_CTX *ctx);
jpayne@69 744
jpayne@69 745 /** Computes r = generator * n + q * m
jpayne@69 746 * \param group underlying EC_GROUP object
jpayne@69 747 * \param r EC_POINT object for the result
jpayne@69 748 * \param n BIGNUM with the multiplier for the group generator (optional)
jpayne@69 749 * \param q EC_POINT object with the first factor of the second summand
jpayne@69 750 * \param m BIGNUM with the second factor of the second summand
jpayne@69 751 * \param ctx BN_CTX object (optional)
jpayne@69 752 * \return 1 on success and 0 if an error occurred
jpayne@69 753 */
jpayne@69 754 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n,
jpayne@69 755 const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
jpayne@69 756
jpayne@69 757 /** Stores multiples of generator for faster point multiplication
jpayne@69 758 * \param group EC_GROUP object
jpayne@69 759 * \param ctx BN_CTX object (optional)
jpayne@69 760 * \return 1 on success and 0 if an error occurred
jpayne@69 761 */
jpayne@69 762 int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
jpayne@69 763
jpayne@69 764 /** Reports whether a precomputation has been done
jpayne@69 765 * \param group EC_GROUP object
jpayne@69 766 * \return 1 if a pre-computation has been done and 0 otherwise
jpayne@69 767 */
jpayne@69 768 int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
jpayne@69 769
jpayne@69 770 /********************************************************************/
jpayne@69 771 /* ASN1 stuff */
jpayne@69 772 /********************************************************************/
jpayne@69 773
jpayne@69 774 DECLARE_ASN1_ITEM(ECPKPARAMETERS)
jpayne@69 775 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS)
jpayne@69 776 DECLARE_ASN1_ITEM(ECPARAMETERS)
jpayne@69 777 DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS)
jpayne@69 778
jpayne@69 779 /*
jpayne@69 780 * EC_GROUP_get_basis_type() returns the NID of the basis type used to
jpayne@69 781 * represent the field elements
jpayne@69 782 */
jpayne@69 783 int EC_GROUP_get_basis_type(const EC_GROUP *);
jpayne@69 784 # ifndef OPENSSL_NO_EC2M
jpayne@69 785 int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
jpayne@69 786 int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
jpayne@69 787 unsigned int *k2, unsigned int *k3);
jpayne@69 788 # endif
jpayne@69 789
jpayne@69 790 # define OPENSSL_EC_EXPLICIT_CURVE 0x000
jpayne@69 791 # define OPENSSL_EC_NAMED_CURVE 0x001
jpayne@69 792
jpayne@69 793 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
jpayne@69 794 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
jpayne@69 795
jpayne@69 796 # define d2i_ECPKParameters_bio(bp,x) \
jpayne@69 797 ASN1_d2i_bio_of(EC_GROUP, NULL, d2i_ECPKParameters, bp, x)
jpayne@69 798 # define i2d_ECPKParameters_bio(bp,x) \
jpayne@69 799 ASN1_i2d_bio_of_const(EC_GROUP, i2d_ECPKParameters, bp, x)
jpayne@69 800 # define d2i_ECPKParameters_fp(fp,x) \
jpayne@69 801 (EC_GROUP *)ASN1_d2i_fp(NULL, (d2i_of_void *)d2i_ECPKParameters, (fp), \
jpayne@69 802 (void **)(x))
jpayne@69 803 # define i2d_ECPKParameters_fp(fp,x) \
jpayne@69 804 ASN1_i2d_fp((i2d_of_void *)i2d_ECPKParameters, (fp), (void *)(x))
jpayne@69 805
jpayne@69 806 int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
jpayne@69 807 # ifndef OPENSSL_NO_STDIO
jpayne@69 808 int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
jpayne@69 809 # endif
jpayne@69 810
jpayne@69 811 /********************************************************************/
jpayne@69 812 /* EC_KEY functions */
jpayne@69 813 /********************************************************************/
jpayne@69 814
jpayne@69 815 /* some values for the encoding_flag */
jpayne@69 816 # define EC_PKEY_NO_PARAMETERS 0x001
jpayne@69 817 # define EC_PKEY_NO_PUBKEY 0x002
jpayne@69 818
jpayne@69 819 /* some values for the flags field */
jpayne@69 820 # define EC_FLAG_NON_FIPS_ALLOW 0x1
jpayne@69 821 # define EC_FLAG_FIPS_CHECKED 0x2
jpayne@69 822 # define EC_FLAG_COFACTOR_ECDH 0x1000
jpayne@69 823
jpayne@69 824 /** Creates a new EC_KEY object.
jpayne@69 825 * \return EC_KEY object or NULL if an error occurred.
jpayne@69 826 */
jpayne@69 827 EC_KEY *EC_KEY_new(void);
jpayne@69 828
jpayne@69 829 int EC_KEY_get_flags(const EC_KEY *key);
jpayne@69 830
jpayne@69 831 void EC_KEY_set_flags(EC_KEY *key, int flags);
jpayne@69 832
jpayne@69 833 void EC_KEY_clear_flags(EC_KEY *key, int flags);
jpayne@69 834
jpayne@69 835 int EC_KEY_decoded_from_explicit_params(const EC_KEY *key);
jpayne@69 836
jpayne@69 837 /** Creates a new EC_KEY object using a named curve as underlying
jpayne@69 838 * EC_GROUP object.
jpayne@69 839 * \param nid NID of the named curve.
jpayne@69 840 * \return EC_KEY object or NULL if an error occurred.
jpayne@69 841 */
jpayne@69 842 EC_KEY *EC_KEY_new_by_curve_name(int nid);
jpayne@69 843
jpayne@69 844 /** Frees a EC_KEY object.
jpayne@69 845 * \param key EC_KEY object to be freed.
jpayne@69 846 */
jpayne@69 847 void EC_KEY_free(EC_KEY *key);
jpayne@69 848
jpayne@69 849 /** Copies a EC_KEY object.
jpayne@69 850 * \param dst destination EC_KEY object
jpayne@69 851 * \param src src EC_KEY object
jpayne@69 852 * \return dst or NULL if an error occurred.
jpayne@69 853 */
jpayne@69 854 EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
jpayne@69 855
jpayne@69 856 /** Creates a new EC_KEY object and copies the content from src to it.
jpayne@69 857 * \param src the source EC_KEY object
jpayne@69 858 * \return newly created EC_KEY object or NULL if an error occurred.
jpayne@69 859 */
jpayne@69 860 EC_KEY *EC_KEY_dup(const EC_KEY *src);
jpayne@69 861
jpayne@69 862 /** Increases the internal reference count of a EC_KEY object.
jpayne@69 863 * \param key EC_KEY object
jpayne@69 864 * \return 1 on success and 0 if an error occurred.
jpayne@69 865 */
jpayne@69 866 int EC_KEY_up_ref(EC_KEY *key);
jpayne@69 867
jpayne@69 868 /** Returns the ENGINE object of a EC_KEY object
jpayne@69 869 * \param eckey EC_KEY object
jpayne@69 870 * \return the ENGINE object (possibly NULL).
jpayne@69 871 */
jpayne@69 872 ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey);
jpayne@69 873
jpayne@69 874 /** Returns the EC_GROUP object of a EC_KEY object
jpayne@69 875 * \param key EC_KEY object
jpayne@69 876 * \return the EC_GROUP object (possibly NULL).
jpayne@69 877 */
jpayne@69 878 const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
jpayne@69 879
jpayne@69 880 /** Sets the EC_GROUP of a EC_KEY object.
jpayne@69 881 * \param key EC_KEY object
jpayne@69 882 * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY
jpayne@69 883 * object will use an own copy of the EC_GROUP).
jpayne@69 884 * \return 1 on success and 0 if an error occurred.
jpayne@69 885 */
jpayne@69 886 int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
jpayne@69 887
jpayne@69 888 /** Returns the private key of a EC_KEY object.
jpayne@69 889 * \param key EC_KEY object
jpayne@69 890 * \return a BIGNUM with the private key (possibly NULL).
jpayne@69 891 */
jpayne@69 892 const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
jpayne@69 893
jpayne@69 894 /** Sets the private key of a EC_KEY object.
jpayne@69 895 * \param key EC_KEY object
jpayne@69 896 * \param prv BIGNUM with the private key (note: the EC_KEY object
jpayne@69 897 * will use an own copy of the BIGNUM).
jpayne@69 898 * \return 1 on success and 0 if an error occurred.
jpayne@69 899 */
jpayne@69 900 int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
jpayne@69 901
jpayne@69 902 /** Returns the public key of a EC_KEY object.
jpayne@69 903 * \param key the EC_KEY object
jpayne@69 904 * \return a EC_POINT object with the public key (possibly NULL)
jpayne@69 905 */
jpayne@69 906 const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
jpayne@69 907
jpayne@69 908 /** Sets the public key of a EC_KEY object.
jpayne@69 909 * \param key EC_KEY object
jpayne@69 910 * \param pub EC_POINT object with the public key (note: the EC_KEY object
jpayne@69 911 * will use an own copy of the EC_POINT object).
jpayne@69 912 * \return 1 on success and 0 if an error occurred.
jpayne@69 913 */
jpayne@69 914 int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
jpayne@69 915
jpayne@69 916 unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
jpayne@69 917 void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
jpayne@69 918 point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
jpayne@69 919 void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
jpayne@69 920
jpayne@69 921 #define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \
jpayne@69 922 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef)
jpayne@69 923 int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg);
jpayne@69 924 void *EC_KEY_get_ex_data(const EC_KEY *key, int idx);
jpayne@69 925
jpayne@69 926 /* wrapper functions for the underlying EC_GROUP object */
jpayne@69 927 void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
jpayne@69 928
jpayne@69 929 /** Creates a table of pre-computed multiples of the generator to
jpayne@69 930 * accelerate further EC_KEY operations.
jpayne@69 931 * \param key EC_KEY object
jpayne@69 932 * \param ctx BN_CTX object (optional)
jpayne@69 933 * \return 1 on success and 0 if an error occurred.
jpayne@69 934 */
jpayne@69 935 int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
jpayne@69 936
jpayne@69 937 /** Creates a new ec private (and optional a new public) key.
jpayne@69 938 * \param key EC_KEY object
jpayne@69 939 * \return 1 on success and 0 if an error occurred.
jpayne@69 940 */
jpayne@69 941 int EC_KEY_generate_key(EC_KEY *key);
jpayne@69 942
jpayne@69 943 /** Verifies that a private and/or public key is valid.
jpayne@69 944 * \param key the EC_KEY object
jpayne@69 945 * \return 1 on success and 0 otherwise.
jpayne@69 946 */
jpayne@69 947 int EC_KEY_check_key(const EC_KEY *key);
jpayne@69 948
jpayne@69 949 /** Indicates if an EC_KEY can be used for signing.
jpayne@69 950 * \param eckey the EC_KEY object
jpayne@69 951 * \return 1 if can can sign and 0 otherwise.
jpayne@69 952 */
jpayne@69 953 int EC_KEY_can_sign(const EC_KEY *eckey);
jpayne@69 954
jpayne@69 955 /** Sets a public key from affine coordinates performing
jpayne@69 956 * necessary NIST PKV tests.
jpayne@69 957 * \param key the EC_KEY object
jpayne@69 958 * \param x public key x coordinate
jpayne@69 959 * \param y public key y coordinate
jpayne@69 960 * \return 1 on success and 0 otherwise.
jpayne@69 961 */
jpayne@69 962 int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
jpayne@69 963 BIGNUM *y);
jpayne@69 964
jpayne@69 965 /** Encodes an EC_KEY public key to an allocated octet string
jpayne@69 966 * \param key key to encode
jpayne@69 967 * \param form point conversion form
jpayne@69 968 * \param pbuf returns pointer to allocated buffer
jpayne@69 969 * \param ctx BN_CTX object (optional)
jpayne@69 970 * \return the length of the encoded octet string or 0 if an error occurred
jpayne@69 971 */
jpayne@69 972 size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form,
jpayne@69 973 unsigned char **pbuf, BN_CTX *ctx);
jpayne@69 974
jpayne@69 975 /** Decodes a EC_KEY public key from a octet string
jpayne@69 976 * \param key key to decode
jpayne@69 977 * \param buf memory buffer with the encoded ec point
jpayne@69 978 * \param len length of the encoded ec point
jpayne@69 979 * \param ctx BN_CTX object (optional)
jpayne@69 980 * \return 1 on success and 0 if an error occurred
jpayne@69 981 */
jpayne@69 982
jpayne@69 983 int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
jpayne@69 984 BN_CTX *ctx);
jpayne@69 985
jpayne@69 986 /** Decodes an EC_KEY private key from an octet string
jpayne@69 987 * \param key key to decode
jpayne@69 988 * \param buf memory buffer with the encoded private key
jpayne@69 989 * \param len length of the encoded key
jpayne@69 990 * \return 1 on success and 0 if an error occurred
jpayne@69 991 */
jpayne@69 992
jpayne@69 993 int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len);
jpayne@69 994
jpayne@69 995 /** Encodes a EC_KEY private key to an octet string
jpayne@69 996 * \param key key to encode
jpayne@69 997 * \param buf memory buffer for the result. If NULL the function returns
jpayne@69 998 * required buffer size.
jpayne@69 999 * \param len length of the memory buffer
jpayne@69 1000 * \return the length of the encoded octet string or 0 if an error occurred
jpayne@69 1001 */
jpayne@69 1002
jpayne@69 1003 size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len);
jpayne@69 1004
jpayne@69 1005 /** Encodes an EC_KEY private key to an allocated octet string
jpayne@69 1006 * \param eckey key to encode
jpayne@69 1007 * \param pbuf returns pointer to allocated buffer
jpayne@69 1008 * \return the length of the encoded octet string or 0 if an error occurred
jpayne@69 1009 */
jpayne@69 1010 size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf);
jpayne@69 1011
jpayne@69 1012 /********************************************************************/
jpayne@69 1013 /* de- and encoding functions for SEC1 ECPrivateKey */
jpayne@69 1014 /********************************************************************/
jpayne@69 1015
jpayne@69 1016 /** Decodes a private key from a memory buffer.
jpayne@69 1017 * \param key a pointer to a EC_KEY object which should be used (or NULL)
jpayne@69 1018 * \param in pointer to memory with the DER encoded private key
jpayne@69 1019 * \param len length of the DER encoded private key
jpayne@69 1020 * \return the decoded private key or NULL if an error occurred.
jpayne@69 1021 */
jpayne@69 1022 EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
jpayne@69 1023
jpayne@69 1024 /** Encodes a private key object and stores the result in a buffer.
jpayne@69 1025 * \param key the EC_KEY object to encode
jpayne@69 1026 * \param out the buffer for the result (if NULL the function returns number
jpayne@69 1027 * of bytes needed).
jpayne@69 1028 * \return 1 on success and 0 if an error occurred.
jpayne@69 1029 */
jpayne@69 1030 int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
jpayne@69 1031
jpayne@69 1032 /********************************************************************/
jpayne@69 1033 /* de- and encoding functions for EC parameters */
jpayne@69 1034 /********************************************************************/
jpayne@69 1035
jpayne@69 1036 /** Decodes ec parameter from a memory buffer.
jpayne@69 1037 * \param key a pointer to a EC_KEY object which should be used (or NULL)
jpayne@69 1038 * \param in pointer to memory with the DER encoded ec parameters
jpayne@69 1039 * \param len length of the DER encoded ec parameters
jpayne@69 1040 * \return a EC_KEY object with the decoded parameters or NULL if an error
jpayne@69 1041 * occurred.
jpayne@69 1042 */
jpayne@69 1043 EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
jpayne@69 1044
jpayne@69 1045 /** Encodes ec parameter and stores the result in a buffer.
jpayne@69 1046 * \param key the EC_KEY object with ec parameters to encode
jpayne@69 1047 * \param out the buffer for the result (if NULL the function returns number
jpayne@69 1048 * of bytes needed).
jpayne@69 1049 * \return 1 on success and 0 if an error occurred.
jpayne@69 1050 */
jpayne@69 1051 int i2d_ECParameters(EC_KEY *key, unsigned char **out);
jpayne@69 1052
jpayne@69 1053 /********************************************************************/
jpayne@69 1054 /* de- and encoding functions for EC public key */
jpayne@69 1055 /* (octet string, not DER -- hence 'o2i' and 'i2o') */
jpayne@69 1056 /********************************************************************/
jpayne@69 1057
jpayne@69 1058 /** Decodes a ec public key from a octet string.
jpayne@69 1059 * \param key a pointer to a EC_KEY object which should be used
jpayne@69 1060 * \param in memory buffer with the encoded public key
jpayne@69 1061 * \param len length of the encoded public key
jpayne@69 1062 * \return EC_KEY object with decoded public key or NULL if an error
jpayne@69 1063 * occurred.
jpayne@69 1064 */
jpayne@69 1065 EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
jpayne@69 1066
jpayne@69 1067 /** Encodes a ec public key in an octet string.
jpayne@69 1068 * \param key the EC_KEY object with the public key
jpayne@69 1069 * \param out the buffer for the result (if NULL the function returns number
jpayne@69 1070 * of bytes needed).
jpayne@69 1071 * \return 1 on success and 0 if an error occurred
jpayne@69 1072 */
jpayne@69 1073 int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out);
jpayne@69 1074
jpayne@69 1075 /** Prints out the ec parameters on human readable form.
jpayne@69 1076 * \param bp BIO object to which the information is printed
jpayne@69 1077 * \param key EC_KEY object
jpayne@69 1078 * \return 1 on success and 0 if an error occurred
jpayne@69 1079 */
jpayne@69 1080 int ECParameters_print(BIO *bp, const EC_KEY *key);
jpayne@69 1081
jpayne@69 1082 /** Prints out the contents of a EC_KEY object
jpayne@69 1083 * \param bp BIO object to which the information is printed
jpayne@69 1084 * \param key EC_KEY object
jpayne@69 1085 * \param off line offset
jpayne@69 1086 * \return 1 on success and 0 if an error occurred
jpayne@69 1087 */
jpayne@69 1088 int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
jpayne@69 1089
jpayne@69 1090 # ifndef OPENSSL_NO_STDIO
jpayne@69 1091 /** Prints out the ec parameters on human readable form.
jpayne@69 1092 * \param fp file descriptor to which the information is printed
jpayne@69 1093 * \param key EC_KEY object
jpayne@69 1094 * \return 1 on success and 0 if an error occurred
jpayne@69 1095 */
jpayne@69 1096 int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
jpayne@69 1097
jpayne@69 1098 /** Prints out the contents of a EC_KEY object
jpayne@69 1099 * \param fp file descriptor to which the information is printed
jpayne@69 1100 * \param key EC_KEY object
jpayne@69 1101 * \param off line offset
jpayne@69 1102 * \return 1 on success and 0 if an error occurred
jpayne@69 1103 */
jpayne@69 1104 int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
jpayne@69 1105
jpayne@69 1106 # endif
jpayne@69 1107
jpayne@69 1108 const EC_KEY_METHOD *EC_KEY_OpenSSL(void);
jpayne@69 1109 const EC_KEY_METHOD *EC_KEY_get_default_method(void);
jpayne@69 1110 void EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
jpayne@69 1111 const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key);
jpayne@69 1112 int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
jpayne@69 1113 EC_KEY *EC_KEY_new_method(ENGINE *engine);
jpayne@69 1114
jpayne@69 1115 /** The old name for ecdh_KDF_X9_63
jpayne@69 1116 * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
jpayne@69 1117 * it is actually specified in ANSI X9.63.
jpayne@69 1118 * This identifier is retained for backwards compatibility
jpayne@69 1119 */
jpayne@69 1120 int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
jpayne@69 1121 const unsigned char *Z, size_t Zlen,
jpayne@69 1122 const unsigned char *sinfo, size_t sinfolen,
jpayne@69 1123 const EVP_MD *md);
jpayne@69 1124
jpayne@69 1125 int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
jpayne@69 1126 const EC_KEY *ecdh,
jpayne@69 1127 void *(*KDF) (const void *in, size_t inlen,
jpayne@69 1128 void *out, size_t *outlen));
jpayne@69 1129
jpayne@69 1130 typedef struct ECDSA_SIG_st ECDSA_SIG;
jpayne@69 1131
jpayne@69 1132 /** Allocates and initialize a ECDSA_SIG structure
jpayne@69 1133 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
jpayne@69 1134 */
jpayne@69 1135 ECDSA_SIG *ECDSA_SIG_new(void);
jpayne@69 1136
jpayne@69 1137 /** frees a ECDSA_SIG structure
jpayne@69 1138 * \param sig pointer to the ECDSA_SIG structure
jpayne@69 1139 */
jpayne@69 1140 void ECDSA_SIG_free(ECDSA_SIG *sig);
jpayne@69 1141
jpayne@69 1142 /** DER encode content of ECDSA_SIG object (note: this function modifies *pp
jpayne@69 1143 * (*pp += length of the DER encoded signature)).
jpayne@69 1144 * \param sig pointer to the ECDSA_SIG object
jpayne@69 1145 * \param pp pointer to a unsigned char pointer for the output or NULL
jpayne@69 1146 * \return the length of the DER encoded ECDSA_SIG object or a negative value
jpayne@69 1147 * on error
jpayne@69 1148 */
jpayne@69 1149 int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
jpayne@69 1150
jpayne@69 1151 /** Decodes a DER encoded ECDSA signature (note: this function changes *pp
jpayne@69 1152 * (*pp += len)).
jpayne@69 1153 * \param sig pointer to ECDSA_SIG pointer (may be NULL)
jpayne@69 1154 * \param pp memory buffer with the DER encoded signature
jpayne@69 1155 * \param len length of the buffer
jpayne@69 1156 * \return pointer to the decoded ECDSA_SIG structure (or NULL)
jpayne@69 1157 */
jpayne@69 1158 ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
jpayne@69 1159
jpayne@69 1160 /** Accessor for r and s fields of ECDSA_SIG
jpayne@69 1161 * \param sig pointer to ECDSA_SIG structure
jpayne@69 1162 * \param pr pointer to BIGNUM pointer for r (may be NULL)
jpayne@69 1163 * \param ps pointer to BIGNUM pointer for s (may be NULL)
jpayne@69 1164 */
jpayne@69 1165 void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
jpayne@69 1166
jpayne@69 1167 /** Accessor for r field of ECDSA_SIG
jpayne@69 1168 * \param sig pointer to ECDSA_SIG structure
jpayne@69 1169 */
jpayne@69 1170 const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
jpayne@69 1171
jpayne@69 1172 /** Accessor for s field of ECDSA_SIG
jpayne@69 1173 * \param sig pointer to ECDSA_SIG structure
jpayne@69 1174 */
jpayne@69 1175 const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
jpayne@69 1176
jpayne@69 1177 /** Setter for r and s fields of ECDSA_SIG
jpayne@69 1178 * \param sig pointer to ECDSA_SIG structure
jpayne@69 1179 * \param r pointer to BIGNUM for r (may be NULL)
jpayne@69 1180 * \param s pointer to BIGNUM for s (may be NULL)
jpayne@69 1181 */
jpayne@69 1182 int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
jpayne@69 1183
jpayne@69 1184 /** Computes the ECDSA signature of the given hash value using
jpayne@69 1185 * the supplied private key and returns the created signature.
jpayne@69 1186 * \param dgst pointer to the hash value
jpayne@69 1187 * \param dgst_len length of the hash value
jpayne@69 1188 * \param eckey EC_KEY object containing a private EC key
jpayne@69 1189 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
jpayne@69 1190 */
jpayne@69 1191 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
jpayne@69 1192 EC_KEY *eckey);
jpayne@69 1193
jpayne@69 1194 /** Computes ECDSA signature of a given hash value using the supplied
jpayne@69 1195 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
jpayne@69 1196 * \param dgst pointer to the hash value to sign
jpayne@69 1197 * \param dgstlen length of the hash value
jpayne@69 1198 * \param kinv BIGNUM with a pre-computed inverse k (optional)
jpayne@69 1199 * \param rp BIGNUM with a pre-computed rp value (optional),
jpayne@69 1200 * see ECDSA_sign_setup
jpayne@69 1201 * \param eckey EC_KEY object containing a private EC key
jpayne@69 1202 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred
jpayne@69 1203 */
jpayne@69 1204 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
jpayne@69 1205 const BIGNUM *kinv, const BIGNUM *rp,
jpayne@69 1206 EC_KEY *eckey);
jpayne@69 1207
jpayne@69 1208 /** Verifies that the supplied signature is a valid ECDSA
jpayne@69 1209 * signature of the supplied hash value using the supplied public key.
jpayne@69 1210 * \param dgst pointer to the hash value
jpayne@69 1211 * \param dgst_len length of the hash value
jpayne@69 1212 * \param sig ECDSA_SIG structure
jpayne@69 1213 * \param eckey EC_KEY object containing a public EC key
jpayne@69 1214 * \return 1 if the signature is valid, 0 if the signature is invalid
jpayne@69 1215 * and -1 on error
jpayne@69 1216 */
jpayne@69 1217 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
jpayne@69 1218 const ECDSA_SIG *sig, EC_KEY *eckey);
jpayne@69 1219
jpayne@69 1220 /** Precompute parts of the signing operation
jpayne@69 1221 * \param eckey EC_KEY object containing a private EC key
jpayne@69 1222 * \param ctx BN_CTX object (optional)
jpayne@69 1223 * \param kinv BIGNUM pointer for the inverse of k
jpayne@69 1224 * \param rp BIGNUM pointer for x coordinate of k * generator
jpayne@69 1225 * \return 1 on success and 0 otherwise
jpayne@69 1226 */
jpayne@69 1227 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
jpayne@69 1228
jpayne@69 1229 /** Computes ECDSA signature of a given hash value using the supplied
jpayne@69 1230 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
jpayne@69 1231 * \param type this parameter is ignored
jpayne@69 1232 * \param dgst pointer to the hash value to sign
jpayne@69 1233 * \param dgstlen length of the hash value
jpayne@69 1234 * \param sig memory for the DER encoded created signature
jpayne@69 1235 * \param siglen pointer to the length of the returned signature
jpayne@69 1236 * \param eckey EC_KEY object containing a private EC key
jpayne@69 1237 * \return 1 on success and 0 otherwise
jpayne@69 1238 */
jpayne@69 1239 int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
jpayne@69 1240 unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
jpayne@69 1241
jpayne@69 1242 /** Computes ECDSA signature of a given hash value using the supplied
jpayne@69 1243 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
jpayne@69 1244 * \param type this parameter is ignored
jpayne@69 1245 * \param dgst pointer to the hash value to sign
jpayne@69 1246 * \param dgstlen length of the hash value
jpayne@69 1247 * \param sig buffer to hold the DER encoded signature
jpayne@69 1248 * \param siglen pointer to the length of the returned signature
jpayne@69 1249 * \param kinv BIGNUM with a pre-computed inverse k (optional)
jpayne@69 1250 * \param rp BIGNUM with a pre-computed rp value (optional),
jpayne@69 1251 * see ECDSA_sign_setup
jpayne@69 1252 * \param eckey EC_KEY object containing a private EC key
jpayne@69 1253 * \return 1 on success and 0 otherwise
jpayne@69 1254 */
jpayne@69 1255 int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
jpayne@69 1256 unsigned char *sig, unsigned int *siglen,
jpayne@69 1257 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
jpayne@69 1258
jpayne@69 1259 /** Verifies that the given signature is valid ECDSA signature
jpayne@69 1260 * of the supplied hash value using the specified public key.
jpayne@69 1261 * \param type this parameter is ignored
jpayne@69 1262 * \param dgst pointer to the hash value
jpayne@69 1263 * \param dgstlen length of the hash value
jpayne@69 1264 * \param sig pointer to the DER encoded signature
jpayne@69 1265 * \param siglen length of the DER encoded signature
jpayne@69 1266 * \param eckey EC_KEY object containing a public EC key
jpayne@69 1267 * \return 1 if the signature is valid, 0 if the signature is invalid
jpayne@69 1268 * and -1 on error
jpayne@69 1269 */
jpayne@69 1270 int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
jpayne@69 1271 const unsigned char *sig, int siglen, EC_KEY *eckey);
jpayne@69 1272
jpayne@69 1273 /** Returns the maximum length of the DER encoded signature
jpayne@69 1274 * \param eckey EC_KEY object
jpayne@69 1275 * \return numbers of bytes required for the DER encoded signature
jpayne@69 1276 */
jpayne@69 1277 int ECDSA_size(const EC_KEY *eckey);
jpayne@69 1278
jpayne@69 1279 /********************************************************************/
jpayne@69 1280 /* EC_KEY_METHOD constructors, destructors, writers and accessors */
jpayne@69 1281 /********************************************************************/
jpayne@69 1282
jpayne@69 1283 EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth);
jpayne@69 1284 void EC_KEY_METHOD_free(EC_KEY_METHOD *meth);
jpayne@69 1285 void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth,
jpayne@69 1286 int (*init)(EC_KEY *key),
jpayne@69 1287 void (*finish)(EC_KEY *key),
jpayne@69 1288 int (*copy)(EC_KEY *dest, const EC_KEY *src),
jpayne@69 1289 int (*set_group)(EC_KEY *key, const EC_GROUP *grp),
jpayne@69 1290 int (*set_private)(EC_KEY *key,
jpayne@69 1291 const BIGNUM *priv_key),
jpayne@69 1292 int (*set_public)(EC_KEY *key,
jpayne@69 1293 const EC_POINT *pub_key));
jpayne@69 1294
jpayne@69 1295 void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
jpayne@69 1296 int (*keygen)(EC_KEY *key));
jpayne@69 1297
jpayne@69 1298 void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
jpayne@69 1299 int (*ckey)(unsigned char **psec,
jpayne@69 1300 size_t *pseclen,
jpayne@69 1301 const EC_POINT *pub_key,
jpayne@69 1302 const EC_KEY *ecdh));
jpayne@69 1303
jpayne@69 1304 void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth,
jpayne@69 1305 int (*sign)(int type, const unsigned char *dgst,
jpayne@69 1306 int dlen, unsigned char *sig,
jpayne@69 1307 unsigned int *siglen,
jpayne@69 1308 const BIGNUM *kinv, const BIGNUM *r,
jpayne@69 1309 EC_KEY *eckey),
jpayne@69 1310 int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
jpayne@69 1311 BIGNUM **kinvp, BIGNUM **rp),
jpayne@69 1312 ECDSA_SIG *(*sign_sig)(const unsigned char *dgst,
jpayne@69 1313 int dgst_len,
jpayne@69 1314 const BIGNUM *in_kinv,
jpayne@69 1315 const BIGNUM *in_r,
jpayne@69 1316 EC_KEY *eckey));
jpayne@69 1317
jpayne@69 1318 void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth,
jpayne@69 1319 int (*verify)(int type, const unsigned
jpayne@69 1320 char *dgst, int dgst_len,
jpayne@69 1321 const unsigned char *sigbuf,
jpayne@69 1322 int sig_len, EC_KEY *eckey),
jpayne@69 1323 int (*verify_sig)(const unsigned char *dgst,
jpayne@69 1324 int dgst_len,
jpayne@69 1325 const ECDSA_SIG *sig,
jpayne@69 1326 EC_KEY *eckey));
jpayne@69 1327
jpayne@69 1328 void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth,
jpayne@69 1329 int (**pinit)(EC_KEY *key),
jpayne@69 1330 void (**pfinish)(EC_KEY *key),
jpayne@69 1331 int (**pcopy)(EC_KEY *dest, const EC_KEY *src),
jpayne@69 1332 int (**pset_group)(EC_KEY *key,
jpayne@69 1333 const EC_GROUP *grp),
jpayne@69 1334 int (**pset_private)(EC_KEY *key,
jpayne@69 1335 const BIGNUM *priv_key),
jpayne@69 1336 int (**pset_public)(EC_KEY *key,
jpayne@69 1337 const EC_POINT *pub_key));
jpayne@69 1338
jpayne@69 1339 void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth,
jpayne@69 1340 int (**pkeygen)(EC_KEY *key));
jpayne@69 1341
jpayne@69 1342 void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth,
jpayne@69 1343 int (**pck)(unsigned char **psec,
jpayne@69 1344 size_t *pseclen,
jpayne@69 1345 const EC_POINT *pub_key,
jpayne@69 1346 const EC_KEY *ecdh));
jpayne@69 1347
jpayne@69 1348 void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth,
jpayne@69 1349 int (**psign)(int type, const unsigned char *dgst,
jpayne@69 1350 int dlen, unsigned char *sig,
jpayne@69 1351 unsigned int *siglen,
jpayne@69 1352 const BIGNUM *kinv, const BIGNUM *r,
jpayne@69 1353 EC_KEY *eckey),
jpayne@69 1354 int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
jpayne@69 1355 BIGNUM **kinvp, BIGNUM **rp),
jpayne@69 1356 ECDSA_SIG *(**psign_sig)(const unsigned char *dgst,
jpayne@69 1357 int dgst_len,
jpayne@69 1358 const BIGNUM *in_kinv,
jpayne@69 1359 const BIGNUM *in_r,
jpayne@69 1360 EC_KEY *eckey));
jpayne@69 1361
jpayne@69 1362 void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
jpayne@69 1363 int (**pverify)(int type, const unsigned
jpayne@69 1364 char *dgst, int dgst_len,
jpayne@69 1365 const unsigned char *sigbuf,
jpayne@69 1366 int sig_len, EC_KEY *eckey),
jpayne@69 1367 int (**pverify_sig)(const unsigned char *dgst,
jpayne@69 1368 int dgst_len,
jpayne@69 1369 const ECDSA_SIG *sig,
jpayne@69 1370 EC_KEY *eckey));
jpayne@69 1371
jpayne@69 1372 # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
jpayne@69 1373
jpayne@69 1374 # ifndef __cplusplus
jpayne@69 1375 # if defined(__SUNPRO_C)
jpayne@69 1376 # if __SUNPRO_C >= 0x520
jpayne@69 1377 # pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
jpayne@69 1378 # endif
jpayne@69 1379 # endif
jpayne@69 1380 # endif
jpayne@69 1381
jpayne@69 1382 # define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
jpayne@69 1383 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1384 EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
jpayne@69 1385 EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
jpayne@69 1386
jpayne@69 1387 # define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \
jpayne@69 1388 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1389 EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \
jpayne@69 1390 EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL)
jpayne@69 1391
jpayne@69 1392 # define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \
jpayne@69 1393 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1394 EVP_PKEY_OP_DERIVE, \
jpayne@69 1395 EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL)
jpayne@69 1396
jpayne@69 1397 # define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \
jpayne@69 1398 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1399 EVP_PKEY_OP_DERIVE, \
jpayne@69 1400 EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL)
jpayne@69 1401
jpayne@69 1402 # define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \
jpayne@69 1403 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1404 EVP_PKEY_OP_DERIVE, \
jpayne@69 1405 EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL)
jpayne@69 1406
jpayne@69 1407 # define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \
jpayne@69 1408 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1409 EVP_PKEY_OP_DERIVE, \
jpayne@69 1410 EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL)
jpayne@69 1411
jpayne@69 1412 # define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \
jpayne@69 1413 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1414 EVP_PKEY_OP_DERIVE, \
jpayne@69 1415 EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)(md))
jpayne@69 1416
jpayne@69 1417 # define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \
jpayne@69 1418 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1419 EVP_PKEY_OP_DERIVE, \
jpayne@69 1420 EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)(pmd))
jpayne@69 1421
jpayne@69 1422 # define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \
jpayne@69 1423 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1424 EVP_PKEY_OP_DERIVE, \
jpayne@69 1425 EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL)
jpayne@69 1426
jpayne@69 1427 # define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \
jpayne@69 1428 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1429 EVP_PKEY_OP_DERIVE, \
jpayne@69 1430 EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, \
jpayne@69 1431 (void *)(plen))
jpayne@69 1432
jpayne@69 1433 # define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \
jpayne@69 1434 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1435 EVP_PKEY_OP_DERIVE, \
jpayne@69 1436 EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)(p))
jpayne@69 1437
jpayne@69 1438 # define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \
jpayne@69 1439 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \
jpayne@69 1440 EVP_PKEY_OP_DERIVE, \
jpayne@69 1441 EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)(p))
jpayne@69 1442
jpayne@69 1443 /* SM2 will skip the operation check so no need to pass operation here */
jpayne@69 1444 # define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \
jpayne@69 1445 EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
jpayne@69 1446 EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id))
jpayne@69 1447
jpayne@69 1448 # define EVP_PKEY_CTX_get1_id(ctx, id) \
jpayne@69 1449 EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
jpayne@69 1450 EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id))
jpayne@69 1451
jpayne@69 1452 # define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \
jpayne@69 1453 EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
jpayne@69 1454 EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len))
jpayne@69 1455
jpayne@69 1456 # define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
jpayne@69 1457 # define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2)
jpayne@69 1458 # define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3)
jpayne@69 1459 # define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4)
jpayne@69 1460 # define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5)
jpayne@69 1461 # define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6)
jpayne@69 1462 # define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7)
jpayne@69 1463 # define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8)
jpayne@69 1464 # define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9)
jpayne@69 1465 # define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10)
jpayne@69 1466 # define EVP_PKEY_CTRL_SET1_ID (EVP_PKEY_ALG_CTRL + 11)
jpayne@69 1467 # define EVP_PKEY_CTRL_GET1_ID (EVP_PKEY_ALG_CTRL + 12)
jpayne@69 1468 # define EVP_PKEY_CTRL_GET1_ID_LEN (EVP_PKEY_ALG_CTRL + 13)
jpayne@69 1469 /* KDF types */
jpayne@69 1470 # define EVP_PKEY_ECDH_KDF_NONE 1
jpayne@69 1471 # define EVP_PKEY_ECDH_KDF_X9_63 2
jpayne@69 1472 /** The old name for EVP_PKEY_ECDH_KDF_X9_63
jpayne@69 1473 * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
jpayne@69 1474 * it is actually specified in ANSI X9.63.
jpayne@69 1475 * This identifier is retained for backwards compatibility
jpayne@69 1476 */
jpayne@69 1477 # define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63
jpayne@69 1478
jpayne@69 1479
jpayne@69 1480 # ifdef __cplusplus
jpayne@69 1481 }
jpayne@69 1482 # endif
jpayne@69 1483 # endif
jpayne@69 1484 #endif