1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
. if \nF \{
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "ec 3"
.TH ec 3 "2016-09-26" "1.0.2j" "OpenSSL"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
ec \- Elliptic Curve functions
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& #include <openssl/ec.h>
\& #include <openssl/bn.h>
\&
\& const EC_METHOD *EC_GFp_simple_method(void);
\& const EC_METHOD *EC_GFp_mont_method(void);
\& const EC_METHOD *EC_GFp_nist_method(void);
\& const EC_METHOD *EC_GFp_nistp224_method(void);
\& const EC_METHOD *EC_GFp_nistp256_method(void);
\& const EC_METHOD *EC_GFp_nistp521_method(void);
\&
\& const EC_METHOD *EC_GF2m_simple_method(void);
\&
\& EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
\& void EC_GROUP_free(EC_GROUP *group);
\& void EC_GROUP_clear_free(EC_GROUP *group);
\& int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
\& EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
\& const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
\& int EC_METHOD_get_field_type(const EC_METHOD *meth);
\& int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
\& const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
\& int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
\& int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);
\& void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
\& int EC_GROUP_get_curve_name(const EC_GROUP *group);
\& void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
\& int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
\& void EC_GROUP_set_point_conversion_form(EC_GROUP *group, point_conversion_form_t form);
\& point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
\& unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x);
\& size_t EC_GROUP_get_seed_len(const EC_GROUP *);
\& size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
\& int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
\& int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
\& int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
\& int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
\& int EC_GROUP_get_degree(const EC_GROUP *group);
\& int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
\& int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
\& int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
\& EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
\& EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
\& EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
\&
\& size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
\&
\& EC_POINT *EC_POINT_new(const EC_GROUP *group);
\& void EC_POINT_free(EC_POINT *point);
\& void EC_POINT_clear_free(EC_POINT *point);
\& int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
\& EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
\& const EC_METHOD *EC_POINT_method_of(const EC_POINT *point);
\& int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point);
\& int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
\& const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx);
\& int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
\& const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
\& int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
\& const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
\& int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
\& const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
\& int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *p,
\& const BIGNUM *x, int y_bit, BN_CTX *ctx);
\& int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
\& const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx);
\& int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group,
\& const EC_POINT *p, BIGNUM *x, BIGNUM *y, BN_CTX *ctx);
\& int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p,
\& const BIGNUM *x, int y_bit, BN_CTX *ctx);
\& size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p,
\& point_conversion_form_t form,
\& unsigned char *buf, size_t len, BN_CTX *ctx);
\& int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p,
\& const unsigned char *buf, size_t len, BN_CTX *ctx);
\& BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
\& point_conversion_form_t form, BIGNUM *, BN_CTX *);
\& EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
\& EC_POINT *, BN_CTX *);
\& char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
\& point_conversion_form_t form, BN_CTX *);
\& EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
\& EC_POINT *, BN_CTX *);
\&
\& int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
\& int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx);
\& int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
\& int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
\& int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx);
\& int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx);
\& int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx);
\& int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx);
\& 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);
\& int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx);
\& int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
\& int EC_GROUP_have_precompute_mult(const EC_GROUP *group);
\&
\& int EC_GROUP_get_basis_type(const EC_GROUP *);
\& int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
\& int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
\& unsigned int *k2, unsigned int *k3);
\& EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
\& int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
\& #define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
\& #define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
\& #define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \e
\& (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
\& #define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \e
\& (unsigned char *)(x))
\& int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
\& int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
\&
\& EC_KEY *EC_KEY_new(void);
\& int EC_KEY_get_flags(const EC_KEY *key);
\& void EC_KEY_set_flags(EC_KEY *key, int flags);
\& void EC_KEY_clear_flags(EC_KEY *key, int flags);
\& EC_KEY *EC_KEY_new_by_curve_name(int nid);
\& void EC_KEY_free(EC_KEY *key);
\& EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
\& EC_KEY *EC_KEY_dup(const EC_KEY *src);
\& int EC_KEY_up_ref(EC_KEY *key);
\& const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
\& int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
\& const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
\& int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
\& const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
\& int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
\& unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
\& void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags);
\& point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
\& void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
\& void *EC_KEY_get_key_method_data(EC_KEY *key,
\& void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
\& void EC_KEY_insert_key_method_data(EC_KEY *key, void *data,
\& void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
\& void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
\& int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);
\& int EC_KEY_generate_key(EC_KEY *key);
\& int EC_KEY_check_key(const EC_KEY *key);
\& int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y);
\&
\& EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len);
\& int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out);
\&
\& EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len);
\& int i2d_ECParameters(EC_KEY *key, unsigned char **out);
\&
\& EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len);
\& int i2o_ECPublicKey(EC_KEY *key, unsigned char **out);
\& int ECParameters_print(BIO *bp, const EC_KEY *key);
\& int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
\& int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
\& int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);
\& #define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
\& #define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \e
\& EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, EVP_PKEY_OP_PARAMGEN, \e
\& EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL)
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This library provides an extensive set of functions for performing operations on elliptic curves over finite fields.
In general an elliptic curve is one with an equation of the form:
.PP
y^2 = x^3 + ax + b
.PP
An \fB\s-1EC_GROUP\s0\fR structure is used to represent the definition of an elliptic curve. Points on a curve are stored using an
\&\fB\s-1EC_POINT\s0\fR structure. An \fB\s-1EC_KEY\s0\fR is used to hold a private/public key pair, where a private key is simply a \s-1BIGNUM\s0 and a
public key is a point on a curve (represented by an \fB\s-1EC_POINT\s0\fR).
.PP
The library contains a number of alternative implementations of the different functions. Each implementation is optimised
for different scenarios. No matter which implementation is being used, the interface remains the same. The library
handles calling the correct implementation when an interface function is invoked. An implementation is represented by
an \fB\s-1EC_METHOD\s0\fR structure.
.PP
The creation and destruction of \fB\s-1EC_GROUP\s0\fR objects is described in \fIEC_GROUP_new\fR\|(3). Functions for
manipulating \fB\s-1EC_GROUP\s0\fR objects are described in \fIEC_GROUP_copy\fR\|(3).
.PP
Functions for creating, destroying and manipulating \fB\s-1EC_POINT\s0\fR objects are explained in \fIEC_POINT_new\fR\|(3),
whilst functions for performing mathematical operations and tests on \fBEC_POINTs\fR are coverd in \fIEC_POINT_add\fR\|(3).
.PP
For working with private and public keys refer to \fIEC_KEY_new\fR\|(3). Implementations are covered in
\&\fIEC_GFp_simple_method\fR\|(3).
.PP
For information on encoding and decoding curve parameters to and from \s-1ASN1\s0 see \fId2i_ECPKParameters\fR\|(3).
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIcrypto\fR\|(3), \fIEC_GROUP_new\fR\|(3), \fIEC_GROUP_copy\fR\|(3),
\&\fIEC_POINT_new\fR\|(3), \fIEC_POINT_add\fR\|(3), \fIEC_KEY_new\fR\|(3),
\&\fIEC_GFp_simple_method\fR\|(3), \fId2i_ECPKParameters\fR\|(3)
|