EC_GROUP_new.pod 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. =pod
  2. =head1 NAME
  3. EC_GROUP_get_ecparameters,
  4. EC_GROUP_get_ecpkparameters,
  5. EC_GROUP_new,
  6. EC_GROUP_new_from_ecparameters,
  7. EC_GROUP_new_from_ecpkparameters,
  8. EC_GROUP_free,
  9. EC_GROUP_clear_free,
  10. EC_GROUP_new_curve_GFp,
  11. EC_GROUP_new_curve_GF2m,
  12. EC_GROUP_new_by_curve_name,
  13. EC_GROUP_set_curve,
  14. EC_GROUP_get_curve,
  15. EC_GROUP_set_curve_GFp,
  16. EC_GROUP_get_curve_GFp,
  17. EC_GROUP_set_curve_GF2m,
  18. EC_GROUP_get_curve_GF2m,
  19. EC_get_builtin_curves - Functions for creating and destroying EC_GROUP
  20. objects
  21. =head1 SYNOPSIS
  22. #include <openssl/ec.h>
  23. EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
  24. EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
  25. EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params)
  26. void EC_GROUP_free(EC_GROUP *group);
  27. void EC_GROUP_clear_free(EC_GROUP *group);
  28. EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
  29. const BIGNUM *b, BN_CTX *ctx);
  30. EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a,
  31. const BIGNUM *b, BN_CTX *ctx);
  32. EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
  33. int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
  34. const BIGNUM *b, BN_CTX *ctx);
  35. int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
  36. BN_CTX *ctx);
  37. int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p,
  38. const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  39. int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p,
  40. BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  41. int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p,
  42. const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  43. int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p,
  44. BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  45. ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, ECPARAMETERS *params)
  46. ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, ECPKPARAMETERS *params)
  47. size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
  48. =head1 DESCRIPTION
  49. Within the library there are two forms of elliptic curve that are of interest.
  50. The first form is those defined over the prime field Fp. The elements of Fp are
  51. the integers 0 to p-1, where p is a prime number. This gives us a revised
  52. elliptic curve equation as follows:
  53. y^2 mod p = x^3 +ax + b mod p
  54. The second form is those defined over a binary field F2^m where the elements of
  55. the field are integers of length at most m bits. For this form the elliptic
  56. curve equation is modified to:
  57. y^2 + xy = x^3 + ax^2 + b (where b != 0)
  58. Operations in a binary field are performed relative to an B<irreducible
  59. polynomial>. All such curves with OpenSSL use a trinomial or a pentanomial for
  60. this parameter.
  61. A new curve can be constructed by calling EC_GROUP_new(), using the
  62. implementation provided by B<meth> (see L<EC_GFp_simple_method(3)>). It is then
  63. necessary to call EC_GROUP_set_curve() to set the curve parameters.
  64. EC_GROUP_new_from_ecparameters() will create a group from the specified
  65. B<params> and EC_GROUP_new_from_ecpkparameters() will create a group from the
  66. specific PK B<params>.
  67. EC_GROUP_set_curve() sets the curve parameters B<p>, B<a> and B<b>. For a curve
  68. over Fp B<p> is the prime for the field. For a curve over F2^m B<p> represents
  69. the irreducible polynomial - each bit represents a term in the polynomial.
  70. Therefore, there will either be three or five bits set dependent on whether the
  71. polynomial is a trinomial or a pentanomial.
  72. In either case, B<a> and B<b> represents the coefficients a and b from the
  73. relevant equation introduced above.
  74. EC_group_get_curve() obtains the previously set curve parameters.
  75. EC_GROUP_set_curve_GFp() and EC_GROUP_set_curve_GF2m() are synonyms for
  76. EC_GROUP_set_curve(). They are defined for backwards compatibility only and
  77. should not be used.
  78. EC_GROUP_get_curve_GFp() and EC_GROUP_get_curve_GF2m() are synonyms for
  79. EC_GROUP_get_curve(). They are defined for backwards compatibility only and
  80. should not be used.
  81. The functions EC_GROUP_new_curve_GFp() and EC_GROUP_new_curve_GF2m() are
  82. shortcuts for calling EC_GROUP_new() and then the EC_GROUP_set_curve() function.
  83. An appropriate default implementation method will be used.
  84. Whilst the library can be used to create any curve using the functions described
  85. above, there are also a number of predefined curves that are available. In order
  86. to obtain a list of all of the predefined curves, call the function
  87. EC_get_builtin_curves(). The parameter B<r> should be an array of
  88. EC_builtin_curve structures of size B<nitems>. The function will populate the
  89. B<r> array with information about the builtin curves. If B<nitems> is less than
  90. the total number of curves available, then the first B<nitems> curves will be
  91. returned. Otherwise the total number of curves will be provided. The return
  92. value is the total number of curves available (whether that number has been
  93. populated in B<r> or not). Passing a NULL B<r>, or setting B<nitems> to 0 will
  94. do nothing other than return the total number of curves available.
  95. The EC_builtin_curve structure is defined as follows:
  96. typedef struct {
  97. int nid;
  98. const char *comment;
  99. } EC_builtin_curve;
  100. Each EC_builtin_curve item has a unique integer id (B<nid>), and a human
  101. readable comment string describing the curve.
  102. In order to construct a builtin curve use the function
  103. EC_GROUP_new_by_curve_name() and provide the B<nid> of the curve to
  104. be constructed.
  105. EC_GROUP_free() frees the memory associated with the EC_GROUP.
  106. If B<group> is NULL nothing is done.
  107. EC_GROUP_clear_free() destroys any sensitive data held within the EC_GROUP and
  108. then frees its memory. If B<group> is NULL nothing is done.
  109. =head1 RETURN VALUES
  110. All EC_GROUP_new* functions return a pointer to the newly constructed group, or
  111. NULL on error.
  112. EC_get_builtin_curves() returns the number of builtin curves that are available.
  113. EC_GROUP_set_curve_GFp(), EC_GROUP_get_curve_GFp(), EC_GROUP_set_curve_GF2m(),
  114. EC_GROUP_get_curve_GF2m() return 1 on success or 0 on error.
  115. =head1 SEE ALSO
  116. L<crypto(7)>, L<EC_GROUP_copy(3)>,
  117. L<EC_POINT_new(3)>, L<EC_POINT_add(3)>, L<EC_KEY_new(3)>,
  118. L<EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)>
  119. =head1 COPYRIGHT
  120. Copyright 2013-2020 The OpenSSL Project Authors. All Rights Reserved.
  121. Licensed under the OpenSSL license (the "License"). You may not use
  122. this file except in compliance with the License. You can obtain a copy
  123. in the file LICENSE in the source distribution or at
  124. L<https://www.openssl.org/source/license.html>.
  125. =cut