EC_GROUP_new.pod 9.2 KB

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