ec.pod 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. =pod
  2. =head1 NAME
  3. ec - Elliptic Curve functions
  4. =head1 SYNOPSIS
  5. #include <openssl/ec.h>
  6. #include <openssl/bn.h>
  7. const EC_METHOD *EC_GFp_simple_method(void);
  8. const EC_METHOD *EC_GFp_mont_method(void);
  9. const EC_METHOD *EC_GFp_nist_method(void);
  10. const EC_METHOD *EC_GFp_nistp224_method(void);
  11. const EC_METHOD *EC_GFp_nistp256_method(void);
  12. const EC_METHOD *EC_GFp_nistp521_method(void);
  13. const EC_METHOD *EC_GF2m_simple_method(void);
  14. EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
  15. void EC_GROUP_free(EC_GROUP *group);
  16. void EC_GROUP_clear_free(EC_GROUP *group);
  17. int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
  18. EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
  19. const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
  20. int EC_METHOD_get_field_type(const EC_METHOD *meth);
  21. int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
  22. const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
  23. int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
  24. int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);
  25. void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
  26. int EC_GROUP_get_curve_name(const EC_GROUP *group);
  27. void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
  28. int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
  29. void EC_GROUP_set_point_conversion_form(EC_GROUP *group, point_conversion_form_t form);
  30. point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
  31. unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
  32. size_t EC_GROUP_get_seed_len(const EC_GROUP *);
  33. size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
  34. int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  35. int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  36. int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  37. int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
  38. int EC_GROUP_get_degree(const EC_GROUP *group);
  39. int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
  40. int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
  41. int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
  42. EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  43. EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
  44. EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
  45. size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
  46. EC_POINT *EC_POINT_new(const EC_GROUP *group);
  47. void EC_POINT_free(EC_POINT *point);
  48. void EC_POINT_clear_free(EC_POINT *point);
  49. int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
  50. EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
  51. const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
  52. int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
  53. int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  54. const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx);
  55. int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
  56. const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
  57. int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  58. const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
  59. int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
  60. const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
  61. int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
  62. const BIGNUM *x, int y_bit, BN_CTX *ctx);
  63. int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
  64. const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
  65. int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
  66. const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
  67. int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
  68. const BIGNUM *x, int y_bit, BN_CTX *ctx);
  69. size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
  70. point_conversion_form_t form,
  71. unsigned char *buf, size_t len, BN_CTX *ctx);
  72. int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
  73. const unsigned char *buf, size_t len, BN_CTX *ctx);
  74. BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
  75. point_conversion_form_t form, BIGNUM *, BN_CTX *);
  76. EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
  77. EC_POINT *, BN_CTX *);
  78. char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
  79. point_conversion_form_t form, BN_CTX *);
  80. EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
  81. EC_POINT *, BN_CTX *);
  82. int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
  83. int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx);
  84. int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
  85. int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
  86. int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx);
  87. int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
  88. int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);
  89. int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx);
  90. int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, size_t num, const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx);
  91. int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
  92. int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
  93. int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
  94. int EC_GROUP_get_basis_type(const EC_GROUP *);
  95. int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
  96. int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
  97. unsigned int *k2, unsigned int *k3);
  98. EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
  99. int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
  100. #define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
  101. #define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
  102. #define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
  103. (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
  104. #define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
  105. (unsigned char *)(x))
  106. int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
  107. int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
  108. EC_KEY *EC_KEY_new(void);
  109. int EC_KEY_get_flags(const EC_KEY *key);
  110. void EC_KEY_set_flags(EC_KEY *key, int flags);
  111. void EC_KEY_clear_flags(EC_KEY *key, int flags);
  112. EC_KEY *EC_KEY_new_by_curve_name(int nid);
  113. void EC_KEY_free(EC_KEY *key);
  114. EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
  115. EC_KEY *EC_KEY_dup(const EC_KEY *src);
  116. int EC_KEY_up_ref(EC_KEY *key);
  117. const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
  118. int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
  119. const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
  120. int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
  121. const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
  122. int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
  123. unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
  124. void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
  125. point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
  126. void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
  127. void *EC_KEY_get_key_method_data(EC_KEY *key,
  128. void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
  129. void EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
  130. void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
  131. void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
  132. int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
  133. int EC_KEY_generate_key(EC_KEY *key);
  134. int EC_KEY_check_key(const EC_KEY *key);
  135. int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y);
  136. EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
  137. int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
  138. EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
  139. int i2d_ECParameters(EC_KEY *key, unsigned char **out);
  140. EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
  141. int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
  142. int ECParameters_print(BIO *bp, const EC_KEY *key);
  143. int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
  144. int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
  145. int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
  146. #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
  147. #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \
  148. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \
  149. EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
  150. =head1 DESCRIPTION
  151. This library provides an extensive set of functions for performing operations on elliptic curves over finite fields.
  152. In general an elliptic curve is one with an equation of the form:
  153. y^2 = x^3 + ax + b
  154. An B<EC_GROUP> structure is used to represent the definition of an elliptic curve. Points on a curve are stored using an
  155. B<EC_POINT> structure. An B<EC_KEY> is used to hold a private/public key pair, where a private key is simply a BIGNUM and a
  156. public key is a point on a curve (represented by an B<EC_POINT>).
  157. The library contains a number of alternative implementations of the different functions. Each implementation is optimised
  158. for different scenarios. No matter which implementation is being used, the interface remains the same. The library
  159. handles calling the correct implementation when an interface function is invoked. An implementation is represented by
  160. an B<EC_METHOD> structure.
  161. The creation and destruction of B<EC_GROUP> objects is described in L<EC_GROUP_new(3)|EC_GROUP_new(3)>. Functions for
  162. manipulating B<EC_GROUP> objects are described in L<EC_GROUP_copy(3)|EC_GROUP_copy(3)>.
  163. Functions for creating, destroying and manipulating B<EC_POINT> objects are explained in L<EC_POINT_new(3)|EC_POINT_new(3)>,
  164. whilst functions for performing mathematical operations and tests on B<EC_POINTs> are coverd in L<EC_POINT_add(3)|EC_POINT_add(3)>.
  165. For working with private and public keys refer to L<EC_KEY_new(3)|EC_KEY_new(3)>. Implementations are covered in
  166. L<EC_GFp_simple_method(3)|EC_GFp_simple_method(3)>.
  167. For information on encoding and decoding curve parameters to and from ASN1 see L<d2i_ECPKParameters(3)|d2i_ECPKParameters(3)>.
  168. =head1 SEE ALSO
  169. L<crypto(3)|crypto(3)>, L<EC_GROUP_new(3)|EC_GROUP_new(3)>, L<EC_GROUP_copy(3)|EC_GROUP_copy(3)>,
  170. L<EC_POINT_new(3)|EC_POINT_new(3)>, L<EC_POINT_add(3)|EC_POINT_add(3)>, L<EC_KEY_new(3)|EC_KEY_new(3)>,
  171. L<EC_GFp_simple_method(3)|EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)|d2i_ECPKParameters(3)>
  172. =cut