2
0

EC_GROUP_new.pod 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. =pod
  2. =head1 NAME
  3. EC_GROUP_get_ecparameters,
  4. EC_GROUP_get_ecpkparameters,
  5. EC_GROUP_new_from_params,
  6. EC_GROUP_to_params,
  7. EC_GROUP_new_from_ecparameters,
  8. EC_GROUP_new_from_ecpkparameters,
  9. EC_GROUP_new,
  10. EC_GROUP_free,
  11. EC_GROUP_clear_free,
  12. EC_GROUP_new_curve_GFp,
  13. EC_GROUP_new_curve_GF2m,
  14. EC_GROUP_new_by_curve_name_ex,
  15. EC_GROUP_new_by_curve_name,
  16. EC_GROUP_set_curve,
  17. EC_GROUP_get_curve,
  18. EC_GROUP_set_curve_GFp,
  19. EC_GROUP_get_curve_GFp,
  20. EC_GROUP_set_curve_GF2m,
  21. EC_GROUP_get_curve_GF2m,
  22. EC_get_builtin_curves,
  23. OSSL_EC_curve_nid2name -
  24. Functions for creating and destroying EC_GROUP objects
  25. =head1 SYNOPSIS
  26. #include <openssl/ec.h>
  27. EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
  28. OSSL_LIB_CTX *libctx, const char *propq);
  29. OSSL_PARAM *EC_GROUP_to_params(const EC_GROUP *group, OSSL_LIB_CTX *libctx,
  30. const char *propq, BN_CTX *bnctx);
  31. EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params);
  32. EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params);
  33. void EC_GROUP_free(EC_GROUP *group);
  34. EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
  35. const BIGNUM *b, BN_CTX *ctx);
  36. EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
  37. const BIGNUM *b, BN_CTX *ctx);
  38. EC_GROUP *EC_GROUP_new_by_curve_name_ex(OSSL_LIB_CTX *libctx, const char *propq,
  39. int nid);
  40. EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
  41. int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
  42. const BIGNUM *b, BN_CTX *ctx);
  43. int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
  44. BN_CTX *ctx);
  45. ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
  46. ECPARAMETERS *params);
  47. ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group,
  48. ECPKPARAMETERS *params);
  49. size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
  50. const char *OSSL_EC_curve_nid2name(int nid);
  51. The following functions have been deprecated since OpenSSL 3.0, and can be
  52. hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
  53. see L<openssl_user_macros(7)>:
  54. EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
  55. void EC_GROUP_clear_free(EC_GROUP *group);
  56. int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p,
  57. const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  58. int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p,
  59. BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  60. int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p,
  61. const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  62. int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p,
  63. BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  64. =head1 DESCRIPTION
  65. Within the library there are two forms of elliptic curve that are of interest.
  66. The first form is those defined over the prime field Fp. The elements of Fp are
  67. the integers 0 to p-1, where p is a prime number. This gives us a revised
  68. elliptic curve equation as follows:
  69. y^2 mod p = x^3 +ax + b mod p
  70. The second form is those defined over a binary field F2^m where the elements of
  71. the field are integers of length at most m bits. For this form the elliptic
  72. curve equation is modified to:
  73. y^2 + xy = x^3 + ax^2 + b (where b != 0)
  74. Operations in a binary field are performed relative to an
  75. B<irreducible polynomial>. All such curves with OpenSSL use a trinomial or a
  76. pentanomial for this parameter.
  77. Although deprecated since OpenSSL 3.0 and should no longer be used,
  78. a new curve can be constructed by calling EC_GROUP_new(), using the
  79. implementation provided by I<meth> (see L<EC_GFp_simple_method(3)>) and
  80. associated with the library context I<ctx> (see L<OSSL_LIB_CTX(3)>).
  81. The I<ctx> parameter may be NULL in which case the default library context is
  82. used.
  83. It is then necessary to call EC_GROUP_set_curve() to set the curve parameters.
  84. Applications should instead use one of the other EC_GROUP_new_* constructors.
  85. EC_GROUP_new_from_params() creates a group with parameters specified by I<params>.
  86. The library context I<libctx> (see L<OSSL_LIB_CTX(3)>) and property query string
  87. I<propq> are used to fetch algorithms from providers.
  88. I<params> may be either a list of explicit params or a named group,
  89. The values for I<ctx> and I<propq> may be NULL.
  90. The I<params> that can be used are described in
  91. L<B<EVP_PKEY-EC>(7)|EVP_PKEY-EC(7)/Common EC parameters>.
  92. EC_GROUP_to_params creates an OSSL_PARAM array with the corresponding parameters
  93. describing the given EC_GROUP. The resulting parameters may contain parameters
  94. describing a named or explicit curve depending on the EC_GROUP.
  95. The library context I<libctx> (see L<OSSL_LIB_CTX(3)>) and property query string
  96. I<propq> are used to fetch algorithms from providers.
  97. I<bnctx> is an optional preallocated BN_CTX (to save the overhead of allocating
  98. and freeing the structure in a loop).
  99. The values for I<libctx>, I<propq> and I<bnctx> may be NULL.
  100. The caller is responsible for freeing the OSSL_PARAM pointer returned.
  101. EC_GROUP_new_from_ecparameters() will create a group from the
  102. specified I<params> and
  103. EC_GROUP_new_from_ecpkparameters() will create a group from the specific PK
  104. I<params>.
  105. EC_GROUP_set_curve() sets the curve parameters I<p>, I<a> and I<b>. For a curve
  106. over Fp I<p> is the prime for the field. For a curve over F2^m I<p> represents
  107. the irreducible polynomial - each bit represents a term in the polynomial.
  108. Therefore, there will either be three or five bits set dependent on whether the
  109. polynomial is a trinomial or a pentanomial.
  110. In either case, I<a> and I<b> represents the coefficients a and b from the
  111. relevant equation introduced above.
  112. EC_group_get_curve() obtains the previously set curve parameters.
  113. EC_GROUP_set_curve_GFp() and EC_GROUP_set_curve_GF2m() are synonyms for
  114. EC_GROUP_set_curve(). They are defined for backwards compatibility only and
  115. should not be used.
  116. EC_GROUP_get_curve_GFp() and EC_GROUP_get_curve_GF2m() are synonyms for
  117. EC_GROUP_get_curve(). They are defined for backwards compatibility only and
  118. should not be used.
  119. The functions EC_GROUP_new_curve_GFp() and EC_GROUP_new_curve_GF2m() are
  120. shortcuts for calling EC_GROUP_new() and then the EC_GROUP_set_curve() function.
  121. An appropriate default implementation method will be used.
  122. Whilst the library can be used to create any curve using the functions described
  123. above, there are also a number of predefined curves that are available. In order
  124. to obtain a list of all of the predefined curves, call the function
  125. EC_get_builtin_curves(). The parameter I<r> should be an array of
  126. EC_builtin_curve structures of size I<nitems>. The function will populate the
  127. I<r> array with information about the built-in curves. If I<nitems> is less than
  128. the total number of curves available, then the first I<nitems> curves will be
  129. returned. Otherwise the total number of curves will be provided. The return
  130. value is the total number of curves available (whether that number has been
  131. populated in I<r> or not). Passing a NULL I<r>, or setting I<nitems> to 0 will
  132. do nothing other than return the total number of curves available.
  133. The EC_builtin_curve structure is defined as follows:
  134. typedef struct {
  135. int nid;
  136. const char *comment;
  137. } EC_builtin_curve;
  138. Each EC_builtin_curve item has a unique integer id (I<nid>), and a human
  139. readable comment string describing the curve.
  140. In order to construct a built-in curve use the function
  141. EC_GROUP_new_by_curve_name_ex() and provide the I<nid> of the curve to
  142. be constructed, the associated library context to be used in I<ctx> (see
  143. L<OSSL_LIB_CTX(3)>) and any property query string in I<propq>. The I<ctx> value
  144. may be NULL in which case the default library context is used. The I<propq>
  145. value may also be NULL.
  146. EC_GROUP_new_by_curve_name() is the same as
  147. EC_GROUP_new_by_curve_name_ex() except that the default library context
  148. is always used along with a NULL property query string.
  149. EC_GROUP_free() frees the memory associated with the EC_GROUP.
  150. If I<group> is NULL nothing is done.
  151. EC_GROUP_clear_free() is deprecated: it was meant to destroy any sensitive data
  152. held within the EC_GROUP and then free its memory, but since all the data stored
  153. in the EC_GROUP is public anyway, this function is unnecessary.
  154. Its use can be safely replaced with EC_GROUP_free().
  155. If I<group> is NULL nothing is done.
  156. OSSL_EC_curve_nid2name() converts a curve I<nid> into the corresponding name.
  157. =head1 RETURN VALUES
  158. All EC_GROUP_new* functions return a pointer to the newly constructed group, or
  159. NULL on error.
  160. EC_get_builtin_curves() returns the number of built-in curves that are
  161. available.
  162. EC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(), EC_GROUP_set_curve_GF2m(),
  163. EC_GROUP_get_curve_GF2m() return 1 on success or 0 on error.
  164. OSSL_EC_curve_nid2name() returns a character string constant, or NULL on error.
  165. =head1 SEE ALSO
  166. L<crypto(7)>, L<EC_GROUP_copy(3)>,
  167. L<EC_POINT_new(3)>, L<EC_POINT_add(3)>, L<EC_KEY_new(3)>,
  168. L<EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)>,
  169. L<OSSL_LIB_CTX(3)>, L<EVP_PKEY-EC(7)>
  170. =head1 HISTORY
  171. =over 2
  172. =item *
  173. EC_GROUP_new() was deprecated in OpenSSL 3.0.
  174. EC_GROUP_new_by_curve_name_ex() and EC_GROUP_new_from_params() were
  175. added in OpenSSL 3.0.
  176. =item *
  177. EC_GROUP_clear_free() was deprecated in OpenSSL 3.0; use EC_GROUP_free()
  178. instead.
  179. =item *
  180. EC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(),
  181. EC_GROUP_set_curve_GF2m() and EC_GROUP_get_curve_GF2m() were deprecated in
  182. OpenSSL 3.0; use EC_GROUP_set_curve() and EC_GROUP_get_curve() instead.
  183. =back
  184. =head1 COPYRIGHT
  185. Copyright 2013-2023 The OpenSSL Project Authors. All Rights Reserved.
  186. Licensed under the Apache License 2.0 (the "License"). You may not use
  187. this file except in compliance with the License. You can obtain a copy
  188. in the file LICENSE in the source distribution or at
  189. L<https://www.openssl.org/source/license.html>.
  190. =cut