• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..11-Apr-2017-

tests/H11-Apr-2017-532433

READMEH A D11-Apr-201710 KiB268201

curve25519_32.cH A D11-Apr-20178 KiB391305

curve25519_64.cH A D11-Apr-201714.9 KiB515394

ec_naf.cH A D11-Apr-20171.8 KiB6945

ecl-curve.hH A D11-Apr-20176.4 KiB124109

ecl-exp.hH A D11-Apr-20176.8 KiB168110

ecl-priv.hH A D11-Apr-201711.5 KiB258176

ecl.cH A D11-Apr-20178.7 KiB302250

ecl.hH A D11-Apr-20172.3 KiB6122

ecl_curve.cH A D11-Apr-20172.3 KiB9479

ecl_gf.cH A D11-Apr-201724.3 KiB959812

ecl_mult.cH A D11-Apr-201710.7 KiB306237

ecp.hH A D11-Apr-20174.8 KiB10747

ecp_25519.cH A D11-Apr-20174.3 KiB12196

ecp_256.cH A D11-Apr-201712.5 KiB402336

ecp_256_32.cH A D11-Apr-201752.4 KiB1,5361,028

ecp_384.cH A D11-Apr-20177.5 KiB259226

ecp_521.cH A D11-Apr-20174 KiB13898

ecp_aff.cH A D11-Apr-201710.1 KiB309234

ecp_jac.cH A D11-Apr-201718.4 KiB514369

ecp_jm.cH A D11-Apr-20179.5 KiB284184

ecp_mont.cH A D11-Apr-20174 KiB155110

uint128.cH A D11-Apr-20171.7 KiB8868

uint128.hH A D11-Apr-20171.1 KiB3629

README

1This Source Code Form is subject to the terms of the Mozilla Public
2License, v. 2.0. If a copy of the MPL was not distributed with this
3file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5The ECL exposes routines for constructing and converting curve
6parameters for internal use.
7
8
9HEADER FILES
10============
11
12ecl-exp.h - Exports data structures and curve names. For use by code
13that does not have access to mp_ints.
14
15ecl-curve.h - Provides hex encodings (in the form of ECCurveParams
16structs) of standardizes elliptic curve domain parameters and mappings
17from ECCurveName to ECCurveParams. For use by code that does not have
18access to mp_ints.
19
20ecl.h - Interface to constructors for curve parameters and group object,
21and point multiplication operations. Used by higher level algorithms
22(like ECDH and ECDSA) to actually perform elliptic curve cryptography.
23
24ecl-priv.h - Data structures and functions for internal use within the
25library.
26
27ecp.h - Internal header file that contains all functions for point
28arithmetic over prime fields.
29
30DATA STRUCTURES AND TYPES
31=========================
32
33ECCurveName (from ecl-exp.h) - Opaque name for standardized elliptic
34curve domain parameters.
35
36ECCurveParams (from ecl-exp.h) - Provides hexadecimal encoding
37of elliptic curve domain parameters. Can be generated by a user
38and passed to ECGroup_fromHex or can be generated from a name by
39EC_GetNamedCurveParams. ecl-curve.h contains ECCurveParams structs for
40the standardized curves defined by ECCurveName.
41
42ECGroup (from ecl.h and ecl-priv.h) - Opaque data structure that
43represents a group of elliptic curve points for a particular set of
44elliptic curve domain parameters. Contains all domain parameters (curve
45a and b, field, base point) as well as pointers to the functions that
46should be used for point arithmetic and the underlying field GFMethod.
47Generated by either ECGroup_fromHex or ECGroup_fromName.
48
49GFMethod (from ecl-priv.h) - Represents a field underlying a set of
50elliptic curve domain parameters. Contains the irreducible that defines
51the field (either the prime or the binary polynomial) as well as
52pointers to the functions that should be used for field arithmetic.
53
54ARITHMETIC FUNCTIONS
55====================
56
57Higher-level algorithms (like ECDH and ECDSA) should call ECPoint_mul
58or ECPoints_mul (from ecl.h) to do point arithmetic. These functions
59will choose which underlying algorithms to use, based on the ECGroup
60structure.
61
62Point Multiplication
63--------------------
64
65ecl_mult.c provides the ECPoints_mul and ECPoint_mul wrappers.
66It also provides two implementations for the pts_mul operation -
67ec_pts_mul_basic (which computes kP, lQ, and then adds kP + lQ) and
68ec_pts_mul_simul_w2 (which does a simultaneous point multiplication
69using a table with window size 2*2).
70
71ec_naf.c provides an implementation of an algorithm to calculate a
72non-adjacent form of a scalar, minimizing the number of point
73additions that need to be done in a point multiplication.
74
75Point Arithmetic over Prime Fields
76----------------------------------
77
78ecp_aff.c provides point arithmetic using affine coordinates.
79
80ecp_jac.c provides point arithmetic using Jacobian projective
81coordinates and mixed Jacobian-affine coordinates. (Jacobian projective
82coordinates represent a point (x, y) as (X, Y, Z), where x=X/Z^2,
83y=Y/Z^3).
84
85ecp_jm.c provides point arithmetic using Modified Jacobian
86coordinates and mixed Modified_Jacobian-affine coordinates.
87(Modified Jacobian coordinates represent a point (x, y)
88as (X, Y, Z, a*Z^4), where x=X/Z^2, y=Y/Z^3, and a is
89the linear coefficient in the curve defining equation).
90
91ecp_192.c and ecp_224.c provide optimized field arithmetic.
92
93Point Arithmetic over Binary Polynomial Fields
94----------------------------------------------
95
96ec2_aff.c provides point arithmetic using affine coordinates.
97
98ec2_proj.c provides point arithmetic using projective coordinates.
99(Projective coordinates represent a point (x, y) as (X, Y, Z), where
100x=X/Z, y=Y/Z^2).
101
102ec2_mont.c provides point multiplication using Montgomery projective
103coordinates.
104
105ec2_163.c, ec2_193.c, and ec2_233.c provide optimized field arithmetic.
106
107Field Arithmetic
108----------------
109
110ecl_gf.c provides constructors for field objects (GFMethod) with the
111functions GFMethod_cons*. It also provides wrappers around the basic
112field operations.
113
114Prime Field Arithmetic
115----------------------
116
117The mpi library provides the basic prime field arithmetic.
118
119ecp_mont.c provides wrappers around the Montgomery multiplication
120functions from the mpi library and adds encoding and decoding functions.
121It also provides the function to construct a GFMethod object using
122Montgomery multiplication.
123
124ecp_192.c and ecp_224.c provide optimized modular reduction for the
125fields defined by nistp192 and nistp224 primes.
126
127ecl_gf.c provides wrappers around the basic field operations.
128
129Binary Polynomial Field Arithmetic
130----------------------------------
131
132../mpi/mp_gf2m.c provides basic binary polynomial field arithmetic,
133including addition, multiplication, squaring, mod, and division, as well
134as conversion ob polynomial representations between bitstring and int[].
135
136ec2_163.c, ec2_193.c, and ec2_233.c provide optimized field mod, mul,
137and sqr operations.
138
139ecl_gf.c provides wrappers around the basic field operations.
140
141Field Encoding
142--------------
143
144By default, field elements are encoded in their basic form. It is
145possible to use an alternative encoding, however. For example, it is
146possible to Montgomery representation of prime field elements and
147take advantage of the fast modular multiplication that Montgomery
148representation provides. The process of converting from basic form to
149Montgomery representation is called field encoding, and the opposite
150process would be field decoding. All internal point operations assume
151that the operands are field encoded as appropriate. By rewiring the
152underlying field arithmetic to perform operations on these encoded
153values, the same overlying point arithmetic operations can be used
154regardless of field representation.
155
156ALGORITHM WIRING
157================
158
159The EC library allows point and field arithmetic algorithms to be
160substituted ("wired-in") on a fine-grained basis. This allows for
161generic algorithms and algorithms that are optimized for a particular
162curve, field, or architecture, to coexist and to be automatically
163selected at runtime.
164
165Wiring Mechanism
166----------------
167
168The ECGroup and GFMethod structure contain pointers to the point and
169field arithmetic functions, respectively, that are to be used in
170operations.
171
172The selection of algorithms to use is handled in the function
173ecgroup_fromNameAndHex in ecl.c.
174
175Default Wiring
176--------------
177
178Curves over prime fields by default use montgomery field arithmetic,
179point multiplication using 5-bit window non-adjacent-form with
180Modified Jacobian coordinates, and 2*2-bit simultaneous point
181multiplication using Jacobian coordinates.
182(Wiring in function ECGroup_consGFp_mont in ecl.c.)
183
184Curves over prime fields that have optimized modular reduction (i.e.,
185secp160r1, nistp192, and nistp224) do not use Montgomery field
186arithmetic. Instead, they use basic field arithmetic with their
187optimized reduction (as in ecp_192.c and ecp_224.c). They
188use the same point multiplication and simultaneous point multiplication
189algorithms as other curves over prime fields.
190
191Curves over binary polynomial fields by default use generic field
192arithmetic with montgomery point multiplication and basic kP + lQ
193computation (multiply, multiply, and add). (Wiring in function
194ECGroup_cons_GF2m in ecl.c.)
195
196Curves over binary polynomial fields that have optimized field
197arithmetic (i.e., any 163-, 193, or 233-bit field) use their optimized
198field arithmetic. They use the same point multiplication and
199simultaneous point multiplication algorithms as other curves over binary
200fields.
201
202Example
203-------
204
205We provide an example for plugging in an optimized implementation for
206the Koblitz curve nistk163.
207
208Suppose the file ec2_k163.c contains the optimized implementation. In
209particular it contains a point multiplication function:
210
211	mp_err ec_GF2m_nistk163_pt_mul(const mp_int *n, const mp_int *px,
212		const mp_int *py, mp_int *rx, mp_int *ry, const ECGroup *group);
213
214Since only a pt_mul function is provided, the generic pt_add function
215will be used.
216
217There are two options for handling the optimized field arithmetic used
218by the ..._pt_mul function. Say the optimized field arithmetic includes
219the following functions:
220
221	mp_err ec_GF2m_nistk163_add(const mp_int *a, const mp_int *b,
222		mp_int *r, const GFMethod *meth);
223	mp_err ec_GF2m_nistk163_mul(const mp_int *a, const mp_int *b,
224		mp_int *r, const GFMethod *meth);
225	mp_err ec_GF2m_nistk163_sqr(const mp_int *a, const mp_int *b,
226		mp_int *r, const GFMethod *meth);
227	mp_err ec_GF2m_nistk163_div(const mp_int *a, const mp_int *b,
228		mp_int *r, const GFMethod *meth);
229
230First, the optimized field arithmetic could simply be called directly
231by the ..._pt_mul function. This would be accomplished by changing
232the ecgroup_fromNameAndHex function in ecl.c to include the following
233statements:
234
235	if (name == ECCurve_NIST_K163) {
236		group = ECGroup_consGF2m(&irr, NULL, &curvea, &curveb, &genx,
237			&geny, &order, params->cofactor);
238		if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
239		MP_CHECKOK( ec_group_set_nistk163(group) );
240	}
241
242and including in ec2_k163.c the following function:
243
244	mp_err ec_group_set_nistk163(ECGroup *group) {
245		group->point_mul = &ec_GF2m_nistk163_pt_mul;
246		return MP_OKAY;
247	}
248
249As a result, ec_GF2m_pt_add and similar functions would use the
250basic binary polynomial field arithmetic ec_GF2m_add, ec_GF2m_mul,
251ec_GF2m_sqr, and ec_GF2m_div.
252
253Alternatively, the optimized field arithmetic could be wired into the
254group's GFMethod. This would be accomplished by putting the following
255function in ec2_k163.c:
256
257	mp_err ec_group_set_nistk163(ECGroup *group) {
258		group->meth->field_add = &ec_GF2m_nistk163_add;
259		group->meth->field_mul = &ec_GF2m_nistk163_mul;
260		group->meth->field_sqr = &ec_GF2m_nistk163_sqr;
261		group->meth->field_div = &ec_GF2m_nistk163_div;
262		group->point_mul = &ec_GF2m_nistk163_pt_mul;
263		return MP_OKAY;
264	}
265
266For an example of functions that use special field encodings, take a
267look at ecp_mont.c.
268