EC_GROUP_new.pod 7.8 KB

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