3 @c -----------------------------------------------------------------------------
4 @c NOTE: This template-standalone.texi shows how to create a texinfo file
5 @c that yields a stand-alone elliptic_curves.info file.
6 @c See template.texi for a texinfo file which is to be part of maxima.info.
8 @c NOTE: The content of this file was determined by tedious trial and error.
9 @c My advice is to keep all elements of this template, from \input to @bye,
10 @c otherwise you'll experience cryptic error messages, hair loss, etc.
12 @c makeinfo elliptic_curves.texi to make .info
13 @c texi2html elliptic_curves.texi to make .html
14 @c texi2pdf elliptic_curves.texi to make .pdf
15 @c -----------------------------------------------------------------------------
17 @setfilename elliptic_curves.info
18 @settitle elliptic_curves
26 @dircategory Mathematics/Maxima
28 * elliptic_curves: (maxima/elliptic_curves). Maxima share package elliptic_curves: elliptic curves over prime fields.
31 @node Top, Introduction to elliptic_curves, (dir), (dir)
34 * Introduction to elliptic_curves::
35 * Definitions for elliptic_curves::
36 * Function and variable index::
38 @chapter elliptic_curves
40 @node Introduction to elliptic_curves, Definitions for elliptic_curves, Top, Top
41 @section Introduction to elliptic_curves
43 @code{elliptic_curves} is a package for elliptic curves over prime fields
44 and provides some basic functions like addition and multiplication of curve points
45 given in affine coordinates. There are functions for computing point and group
46 orders and the package also contains example curve parameters from SEC and BRAINPOOL.
48 The trace of Frobenius is computed via Shanks-Mestre or Schoof-Elkies-Atkin,
49 where the database of precalculated modular polynomials is limited and the trace
50 can only be computed up to 256 bit examples.
52 Example: Plot of an elliptic curve with balanced points.
55 (%i1) load("elliptic_curves")$
56 (%i2) [p,a,b] : [13,-9,12]$
57 (%i3) ec_set_curve(p,a,b)$
58 (%i4) ord : p+1 - ec_trace();
60 (%i5) ec_point_p(pt : [5,1]);
62 (%i6) ec_point_order(pt,ord);
64 (%i7) ec_balanced : true$
65 (%i8) L : makelist(ec_mult(i,pt), i,1,ord-1)$
66 (%i9) plot2d([discrete, L],
67 [style, points], [x,-7,7], [y,-7,7],
69 "set size square; set grid; set xtics 1; set ytics 1;"])$
70 @c (%i9) plot2d([discrete, L], [gnuplot_term, dumb], [style, points])$
73 @c 6 +-G-G----------------+
81 @c 0 |+..................+|
89 @c -6 +-G-G----------------+
93 @image{figures/ec_Z13,10cm}
98 @code{elliptic_curves} contains some example parameters from SEC and BRAINPOOL.
100 Example: @code{secp112r2} has no prime order. The cofactor is 4: @code{ord = 4*n}.
103 (%i1) load("elliptic_curves")$
104 (%i2) [[p,a,b],base_pt,n] : secp112r2$
105 (%i3) ec_set_curve(p,a,b)$
106 (%i4) ord : p+1 - ec_trace();
107 (%o4) 4451685225093714699870930859147564
109 (%o5) [[2,2],[1112921306273428674967732714786891,1]]
110 (%i6) n = ec_point_order(base_pt,ord);
111 (%o6) 1112921306273428674967732714786891=1112921306273428674967732714786891
115 @node Definitions for elliptic_curves, Function and variable index, Introduction to elliptic_curves, Top
116 @section Definitions for elliptic_curves
118 @c -----------------------------------------------------------------------------
120 @c ec_add, ec_log, ec_mult, ec_point_order, ec_point_p, ec_random,
121 @c ec_set_curve, ec_trace, ec_twist_curve
124 @c ec_balanced, ec_sea_verbose
125 @c -----------------------------------------------------------------------------
127 @deffn {Function} ec_add (@var{pt1}, @var{pt2})
129 Adds two points on the current elliptic curve.
130 @code{ec_add} does not check if both points are indeed on the curve and will
131 return erroneous results if they are not.
133 The following example also shows the point at infinity @code{ec_inf}.
136 (%i1) load("elliptic_curves")$
137 (%i2) ec_set_curve(13,1,2)$
141 (%i5) ec_add(pt,ec_inf);
147 @c -----------------------------------------------------------------------------
149 @defvr {Variable} ec_balanced
150 Default value: @code{false}
152 When @code{ec_balanced} is @code{true},
153 a balanced modulus is applied when printing curve points.
154 E.g. this allows to create a symmetric discrete plot.
157 (%i1) load("elliptic_curves")$
158 (%i2) ec_balanced : true$
159 (%i3) ec_set_curve(13,1,2)$
160 (%i4) makelist(ec_mult(i, [1,11]), i,1,4);
161 (%o4) [[1,-2],[-1,0],[1,2],ec_inf]
166 @c -----------------------------------------------------------------------------
168 @deffn {Function} ec_log (@var{pt}, @var{gen})
170 Uses a simple baby-giant-algorithm to compute the discrete logarithm of @var{pt},
171 i.e. it solves the equation @code{gen^x = pt} on the current elliptic curve.
172 @var{gen} has to be a generator of the subgroup which contains @var{pt}.
173 Otherwise @code{ec_log} returns @code{false}.
175 @code{ec_log} does not check if both points are indeed on the curve and will
176 return erroneous results if they are not.
178 The algorithm is limited and prints an error if the characteristic exceeds
179 an integer length of 36 bit.
182 (%i1) load("elliptic_curves")$
183 (%i2) ec_set_curve(13,1,2)$
184 (%i3) ord : p+1 - ec_trace();
187 (%i5) makelist(ec_mult(i,gen), i,1,ec_point_order(gen,ord));
188 (%o5) [[2,5],[9,8],[12,0],[9,5],[2,8],ec_inf]
190 (%i7) ec_log(pt,gen);
193 (%i9) ec_log(pt,gen);
199 @c -----------------------------------------------------------------------------
201 @deffn {Function} ec_mult (@var{n}, @var{pt})
203 Returns @var{n} times the point @var{pt} of the elliptic curve, which was
204 previously set by @code{ec_set_curve}. @code{ec_mult} does not check if the
205 point is indeed on the curve and will return erroneous results if it is not.
208 (%i1) load("elliptic_curves")$
209 (%i2) ec_set_curve(13,1,2)$
211 (%i4) ec_mult(-1,pt);
217 @c -----------------------------------------------------------------------------
219 @deffn {Function} ec_point_order (@var{pt}, @var{ord})
220 @deffnx {Function} ec_point_order (@var{pt}, @var{ord}, [[@var{p1}, @var{e1}], @dots{}, [@var{pk}, @var{ek}]])
222 Computes the point order of @var{pt} on the current elliptic curve as a factor
223 of the known group order @var{ord} of the curve.
225 If the factorization of @var{ord} is known, it can be passed as an optional argument.
228 (%i1) load("elliptic_curves")$
229 (%i2) ec_set_curve(p:13, 1,2)$
230 (%i3) ord : p+1 - ec_trace();
232 (%i4) fs_ord : ifactors(ord);
235 (%i6) ec_point_order(pt,ord,fs_ord);
243 @c -----------------------------------------------------------------------------
245 @deffn {Function} ec_point_p (@var{pt})
247 Checks if @var{pt} is a point on the current elliptic curve, where the point at
248 infinity @code{ec_inf} is regarded as a point on the curve.
252 @c -----------------------------------------------------------------------------
254 @deffn {Function} ec_random ()
256 Returns a non-infinite random point on the current elliptic curve.
260 @c -----------------------------------------------------------------------------
262 @defvr {Variable} ec_sea_verbose
263 Default value: @code{false}
265 When @code{ec_sea_verbose} is @code{true} and the integer length of the
266 characteristic @var{p} is larger than 56,
267 @code{ec_trace} will print some information about the splitting type of the
268 modular polynomial and the resulting possible traces.
271 (%i1) load("elliptic_curves")$
272 (%i2) ec_sea_verbose : true$
273 (%i3) apply(ec_set_curve, secp112r1[1])$
279 atkin : [11, [4,5,6,7]]
282 atkin : [19, [2,4,6,9,10,13,15,17]]
284 atkin : [29, [10,19]]
288 atkin : [43, [1,4,6,7,8,10,14,17,18,20,23,25,26,29,33,35,36,37,39,42]]
289 atkin : [47, [1,4,5,8,14,16,19,23,24,28,31,33,39,42,43,46]]
290 (%o4) -4407293269000505
295 @c -----------------------------------------------------------------------------
297 @deffn {Function} ec_set_curve (@var{p}, @var{a}, @var{b})
299 Defines an elliptic curve (@var{a},@var{b}),
300 where @var{a} and @var{b} are elements of the prime field @code{F}@var{p} and
301 correspond to the Weierstrass equation @code{y^2 = x^3 + @var{a}*x + @var{b}}.
302 @var{a}, @var{b} and @var{p} are stored as global parameters and all elliptic
303 curve functions refer to them.
305 @code{ec_set_curve} returns @code{true} if the curve is not singular and
306 @code{false} otherwise. In this case no parameters are set.
308 The following example shows the definition of the curve @code{secp112r1} and the
309 computation of its group order.
312 (%i1) load("elliptic_curves")$
313 (%i2) p : 4451685225093714772084598273548427$
315 (%i4) b : 2061118396808653202902996166388514$
316 (%i5) ec_set_curve(p,a,b)$
317 (%i6) ord : p + 1 - ec_trace();
318 (%o6) 4451685225093714776491891542548933
323 @c -----------------------------------------------------------------------------
325 @deffn {Function} ec_trace ()
327 Returns the trace of Frobenius of the current elliptic curve.
328 @code{ec_trace} uses the Shanks-Mestre algorithm for integer lengths up to 56 bit
329 and the Schoof-Elkies-Atkin (SEA) algorithm otherwise. The database of modular
330 polynomials is limited and @code{ec_trace} will not work for parameters much larger
333 The following example uses the curve @code{secp128r1} from the file
334 @code{curve_parameters.mac}.
337 (%i1) load("elliptic_curves")$
338 (%i2) [p,a,b] : secp128r1[1]$
339 (%i3) ec_set_curve(p,a,b)$
340 (%i4) ord : p+1 - ec_trace();
341 (%o4) 340282366762482138443322565580356624661
346 See also @code{ec_sea_verbose}.
350 @c -----------------------------------------------------------------------------
352 @deffn {Function} ec_twist_curve ()
354 Returns a list with a quadratic non-residue n of the given field and the
355 parameters (a*n^2, b*n^3) of the twisted curve.
358 (%i1) load("elliptic_curves")$
359 (%i2) ec_set_curve(p:13, 1,2)$
360 (%i3) ord : p+1 - ec_trace();
362 (%i4) [n,at,bt] : ec_twist_curve();
364 (%i5) ec_set_curve(p, at,bt)$
365 (%i6) ordt : p+1 - ec_trace();
367 (%i7) is(ord + ordt = 2*p + 2);
373 @c -----------------------------------------------------------------------------
375 @node Function and variable index, , Definitions for elliptic_curves, Top
376 @appendix Function and variable index