EC_GROUP_new.pod 8.7 KB

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