xref: /onnv-gate/usr/src/common/crypto/ecc/ecl_mult.c (revision 5697:324be5104707)
1*5697Smcpowers /*
2*5697Smcpowers  * ***** BEGIN LICENSE BLOCK *****
3*5697Smcpowers  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4*5697Smcpowers  *
5*5697Smcpowers  * The contents of this file are subject to the Mozilla Public License Version
6*5697Smcpowers  * 1.1 (the "License"); you may not use this file except in compliance with
7*5697Smcpowers  * the License. You may obtain a copy of the License at
8*5697Smcpowers  * http://www.mozilla.org/MPL/
9*5697Smcpowers  *
10*5697Smcpowers  * Software distributed under the License is distributed on an "AS IS" basis,
11*5697Smcpowers  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12*5697Smcpowers  * for the specific language governing rights and limitations under the
13*5697Smcpowers  * License.
14*5697Smcpowers  *
15*5697Smcpowers  * The Original Code is the elliptic curve math library.
16*5697Smcpowers  *
17*5697Smcpowers  * The Initial Developer of the Original Code is
18*5697Smcpowers  * Sun Microsystems, Inc.
19*5697Smcpowers  * Portions created by the Initial Developer are Copyright (C) 2003
20*5697Smcpowers  * the Initial Developer. All Rights Reserved.
21*5697Smcpowers  *
22*5697Smcpowers  * Contributor(s):
23*5697Smcpowers  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
24*5697Smcpowers  *
25*5697Smcpowers  * Alternatively, the contents of this file may be used under the terms of
26*5697Smcpowers  * either the GNU General Public License Version 2 or later (the "GPL"), or
27*5697Smcpowers  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28*5697Smcpowers  * in which case the provisions of the GPL or the LGPL are applicable instead
29*5697Smcpowers  * of those above. If you wish to allow use of your version of this file only
30*5697Smcpowers  * under the terms of either the GPL or the LGPL, and not to allow others to
31*5697Smcpowers  * use your version of this file under the terms of the MPL, indicate your
32*5697Smcpowers  * decision by deleting the provisions above and replace them with the notice
33*5697Smcpowers  * and other provisions required by the GPL or the LGPL. If you do not delete
34*5697Smcpowers  * the provisions above, a recipient may use your version of this file under
35*5697Smcpowers  * the terms of any one of the MPL, the GPL or the LGPL.
36*5697Smcpowers  *
37*5697Smcpowers  * ***** END LICENSE BLOCK ***** */
38*5697Smcpowers /*
39*5697Smcpowers  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
40*5697Smcpowers  * Use is subject to license terms.
41*5697Smcpowers  *
42*5697Smcpowers  * Sun elects to use this software under the MPL license.
43*5697Smcpowers  */
44*5697Smcpowers 
45*5697Smcpowers #pragma ident	"%Z%%M%	%I%	%E% SMI"
46*5697Smcpowers 
47*5697Smcpowers #include "mpi.h"
48*5697Smcpowers #include "mplogic.h"
49*5697Smcpowers #include "ecl.h"
50*5697Smcpowers #include "ecl-priv.h"
51*5697Smcpowers #ifndef _KERNEL
52*5697Smcpowers #include <stdlib.h>
53*5697Smcpowers #endif
54*5697Smcpowers 
55*5697Smcpowers /* Elliptic curve scalar-point multiplication. Computes R(x, y) = k * P(x,
56*5697Smcpowers  * y).  If x, y = NULL, then P is assumed to be the generator (base point)
57*5697Smcpowers  * of the group of points on the elliptic curve. Input and output values
58*5697Smcpowers  * are assumed to be NOT field-encoded. */
59*5697Smcpowers mp_err
ECPoint_mul(const ECGroup * group,const mp_int * k,const mp_int * px,const mp_int * py,mp_int * rx,mp_int * ry)60*5697Smcpowers ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px,
61*5697Smcpowers 			const mp_int *py, mp_int *rx, mp_int *ry)
62*5697Smcpowers {
63*5697Smcpowers 	mp_err res = MP_OKAY;
64*5697Smcpowers 	mp_int kt;
65*5697Smcpowers 
66*5697Smcpowers 	ARGCHK((k != NULL) && (group != NULL), MP_BADARG);
67*5697Smcpowers 	MP_DIGITS(&kt) = 0;
68*5697Smcpowers 
69*5697Smcpowers 	/* want scalar to be less than or equal to group order */
70*5697Smcpowers 	if (mp_cmp(k, &group->order) > 0) {
71*5697Smcpowers 		MP_CHECKOK(mp_init(&kt, FLAG(k)));
72*5697Smcpowers 		MP_CHECKOK(mp_mod(k, &group->order, &kt));
73*5697Smcpowers 	} else {
74*5697Smcpowers 		MP_SIGN(&kt) = MP_ZPOS;
75*5697Smcpowers 		MP_USED(&kt) = MP_USED(k);
76*5697Smcpowers 		MP_ALLOC(&kt) = MP_ALLOC(k);
77*5697Smcpowers 		MP_DIGITS(&kt) = MP_DIGITS(k);
78*5697Smcpowers 	}
79*5697Smcpowers 
80*5697Smcpowers 	if ((px == NULL) || (py == NULL)) {
81*5697Smcpowers 		if (group->base_point_mul) {
82*5697Smcpowers 			MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group));
83*5697Smcpowers 		} else {
84*5697Smcpowers 			MP_CHECKOK(group->
85*5697Smcpowers 					   point_mul(&kt, &group->genx, &group->geny, rx, ry,
86*5697Smcpowers 								 group));
87*5697Smcpowers 		}
88*5697Smcpowers 	} else {
89*5697Smcpowers 		if (group->meth->field_enc) {
90*5697Smcpowers 			MP_CHECKOK(group->meth->field_enc(px, rx, group->meth));
91*5697Smcpowers 			MP_CHECKOK(group->meth->field_enc(py, ry, group->meth));
92*5697Smcpowers 			MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group));
93*5697Smcpowers 		} else {
94*5697Smcpowers 			MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group));
95*5697Smcpowers 		}
96*5697Smcpowers 	}
97*5697Smcpowers 	if (group->meth->field_dec) {
98*5697Smcpowers 		MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
99*5697Smcpowers 		MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
100*5697Smcpowers 	}
101*5697Smcpowers 
102*5697Smcpowers   CLEANUP:
103*5697Smcpowers 	if (MP_DIGITS(&kt) != MP_DIGITS(k)) {
104*5697Smcpowers 		mp_clear(&kt);
105*5697Smcpowers 	}
106*5697Smcpowers 	return res;
107*5697Smcpowers }
108*5697Smcpowers 
109*5697Smcpowers /* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
110*5697Smcpowers  * k2 * P(x, y), where G is the generator (base point) of the group of
111*5697Smcpowers  * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
112*5697Smcpowers  * Input and output values are assumed to be NOT field-encoded. */
113*5697Smcpowers mp_err
ec_pts_mul_basic(const mp_int * k1,const mp_int * k2,const mp_int * px,const mp_int * py,mp_int * rx,mp_int * ry,const ECGroup * group)114*5697Smcpowers ec_pts_mul_basic(const mp_int *k1, const mp_int *k2, const mp_int *px,
115*5697Smcpowers 				 const mp_int *py, mp_int *rx, mp_int *ry,
116*5697Smcpowers 				 const ECGroup *group)
117*5697Smcpowers {
118*5697Smcpowers 	mp_err res = MP_OKAY;
119*5697Smcpowers 	mp_int sx, sy;
120*5697Smcpowers 
121*5697Smcpowers 	ARGCHK(group != NULL, MP_BADARG);
122*5697Smcpowers 	ARGCHK(!((k1 == NULL)
123*5697Smcpowers 			 && ((k2 == NULL) || (px == NULL)
124*5697Smcpowers 				 || (py == NULL))), MP_BADARG);
125*5697Smcpowers 
126*5697Smcpowers 	/* if some arguments are not defined used ECPoint_mul */
127*5697Smcpowers 	if (k1 == NULL) {
128*5697Smcpowers 		return ECPoint_mul(group, k2, px, py, rx, ry);
129*5697Smcpowers 	} else if ((k2 == NULL) || (px == NULL) || (py == NULL)) {
130*5697Smcpowers 		return ECPoint_mul(group, k1, NULL, NULL, rx, ry);
131*5697Smcpowers 	}
132*5697Smcpowers 
133*5697Smcpowers 	MP_DIGITS(&sx) = 0;
134*5697Smcpowers 	MP_DIGITS(&sy) = 0;
135*5697Smcpowers 	MP_CHECKOK(mp_init(&sx, FLAG(k1)));
136*5697Smcpowers 	MP_CHECKOK(mp_init(&sy, FLAG(k1)));
137*5697Smcpowers 
138*5697Smcpowers 	MP_CHECKOK(ECPoint_mul(group, k1, NULL, NULL, &sx, &sy));
139*5697Smcpowers 	MP_CHECKOK(ECPoint_mul(group, k2, px, py, rx, ry));
140*5697Smcpowers 
141*5697Smcpowers 	if (group->meth->field_enc) {
142*5697Smcpowers 		MP_CHECKOK(group->meth->field_enc(&sx, &sx, group->meth));
143*5697Smcpowers 		MP_CHECKOK(group->meth->field_enc(&sy, &sy, group->meth));
144*5697Smcpowers 		MP_CHECKOK(group->meth->field_enc(rx, rx, group->meth));
145*5697Smcpowers 		MP_CHECKOK(group->meth->field_enc(ry, ry, group->meth));
146*5697Smcpowers 	}
147*5697Smcpowers 
148*5697Smcpowers 	MP_CHECKOK(group->point_add(&sx, &sy, rx, ry, rx, ry, group));
149*5697Smcpowers 
150*5697Smcpowers 	if (group->meth->field_dec) {
151*5697Smcpowers 		MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
152*5697Smcpowers 		MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
153*5697Smcpowers 	}
154*5697Smcpowers 
155*5697Smcpowers   CLEANUP:
156*5697Smcpowers 	mp_clear(&sx);
157*5697Smcpowers 	mp_clear(&sy);
158*5697Smcpowers 	return res;
159*5697Smcpowers }
160*5697Smcpowers 
161*5697Smcpowers /* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
162*5697Smcpowers  * k2 * P(x, y), where G is the generator (base point) of the group of
163*5697Smcpowers  * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
164*5697Smcpowers  * Input and output values are assumed to be NOT field-encoded. Uses
165*5697Smcpowers  * algorithm 15 (simultaneous multiple point multiplication) from Brown,
166*5697Smcpowers  * Hankerson, Lopez, Menezes. Software Implementation of the NIST
167*5697Smcpowers  * Elliptic Curves over Prime Fields. */
168*5697Smcpowers mp_err
ec_pts_mul_simul_w2(const mp_int * k1,const mp_int * k2,const mp_int * px,const mp_int * py,mp_int * rx,mp_int * ry,const ECGroup * group)169*5697Smcpowers ec_pts_mul_simul_w2(const mp_int *k1, const mp_int *k2, const mp_int *px,
170*5697Smcpowers 					const mp_int *py, mp_int *rx, mp_int *ry,
171*5697Smcpowers 					const ECGroup *group)
172*5697Smcpowers {
173*5697Smcpowers 	mp_err res = MP_OKAY;
174*5697Smcpowers 	mp_int precomp[4][4][2];
175*5697Smcpowers 	const mp_int *a, *b;
176*5697Smcpowers 	int i, j;
177*5697Smcpowers 	int ai, bi, d;
178*5697Smcpowers 
179*5697Smcpowers 	ARGCHK(group != NULL, MP_BADARG);
180*5697Smcpowers 	ARGCHK(!((k1 == NULL)
181*5697Smcpowers 			 && ((k2 == NULL) || (px == NULL)
182*5697Smcpowers 				 || (py == NULL))), MP_BADARG);
183*5697Smcpowers 
184*5697Smcpowers 	/* if some arguments are not defined used ECPoint_mul */
185*5697Smcpowers 	if (k1 == NULL) {
186*5697Smcpowers 		return ECPoint_mul(group, k2, px, py, rx, ry);
187*5697Smcpowers 	} else if ((k2 == NULL) || (px == NULL) || (py == NULL)) {
188*5697Smcpowers 		return ECPoint_mul(group, k1, NULL, NULL, rx, ry);
189*5697Smcpowers 	}
190*5697Smcpowers 
191*5697Smcpowers 	/* initialize precomputation table */
192*5697Smcpowers 	for (i = 0; i < 4; i++) {
193*5697Smcpowers 		for (j = 0; j < 4; j++) {
194*5697Smcpowers 			MP_DIGITS(&precomp[i][j][0]) = 0;
195*5697Smcpowers 			MP_DIGITS(&precomp[i][j][1]) = 0;
196*5697Smcpowers 		}
197*5697Smcpowers 	}
198*5697Smcpowers 	for (i = 0; i < 4; i++) {
199*5697Smcpowers 		for (j = 0; j < 4; j++) {
200*5697Smcpowers 			 MP_CHECKOK( mp_init_size(&precomp[i][j][0],
201*5697Smcpowers 					 ECL_MAX_FIELD_SIZE_DIGITS, FLAG(k1)) );
202*5697Smcpowers 			 MP_CHECKOK( mp_init_size(&precomp[i][j][1],
203*5697Smcpowers 					 ECL_MAX_FIELD_SIZE_DIGITS, FLAG(k1)) );
204*5697Smcpowers 		}
205*5697Smcpowers 	}
206*5697Smcpowers 
207*5697Smcpowers 	/* fill precomputation table */
208*5697Smcpowers 	/* assign {k1, k2} = {a, b} such that len(a) >= len(b) */
209*5697Smcpowers 	if (mpl_significant_bits(k1) < mpl_significant_bits(k2)) {
210*5697Smcpowers 		a = k2;
211*5697Smcpowers 		b = k1;
212*5697Smcpowers 		if (group->meth->field_enc) {
213*5697Smcpowers 			MP_CHECKOK(group->meth->
214*5697Smcpowers 					   field_enc(px, &precomp[1][0][0], group->meth));
215*5697Smcpowers 			MP_CHECKOK(group->meth->
216*5697Smcpowers 					   field_enc(py, &precomp[1][0][1], group->meth));
217*5697Smcpowers 		} else {
218*5697Smcpowers 			MP_CHECKOK(mp_copy(px, &precomp[1][0][0]));
219*5697Smcpowers 			MP_CHECKOK(mp_copy(py, &precomp[1][0][1]));
220*5697Smcpowers 		}
221*5697Smcpowers 		MP_CHECKOK(mp_copy(&group->genx, &precomp[0][1][0]));
222*5697Smcpowers 		MP_CHECKOK(mp_copy(&group->geny, &precomp[0][1][1]));
223*5697Smcpowers 	} else {
224*5697Smcpowers 		a = k1;
225*5697Smcpowers 		b = k2;
226*5697Smcpowers 		MP_CHECKOK(mp_copy(&group->genx, &precomp[1][0][0]));
227*5697Smcpowers 		MP_CHECKOK(mp_copy(&group->geny, &precomp[1][0][1]));
228*5697Smcpowers 		if (group->meth->field_enc) {
229*5697Smcpowers 			MP_CHECKOK(group->meth->
230*5697Smcpowers 					   field_enc(px, &precomp[0][1][0], group->meth));
231*5697Smcpowers 			MP_CHECKOK(group->meth->
232*5697Smcpowers 					   field_enc(py, &precomp[0][1][1], group->meth));
233*5697Smcpowers 		} else {
234*5697Smcpowers 			MP_CHECKOK(mp_copy(px, &precomp[0][1][0]));
235*5697Smcpowers 			MP_CHECKOK(mp_copy(py, &precomp[0][1][1]));
236*5697Smcpowers 		}
237*5697Smcpowers 	}
238*5697Smcpowers 	/* precompute [*][0][*] */
239*5697Smcpowers 	mp_zero(&precomp[0][0][0]);
240*5697Smcpowers 	mp_zero(&precomp[0][0][1]);
241*5697Smcpowers 	MP_CHECKOK(group->
242*5697Smcpowers 			   point_dbl(&precomp[1][0][0], &precomp[1][0][1],
243*5697Smcpowers 						 &precomp[2][0][0], &precomp[2][0][1], group));
244*5697Smcpowers 	MP_CHECKOK(group->
245*5697Smcpowers 			   point_add(&precomp[1][0][0], &precomp[1][0][1],
246*5697Smcpowers 						 &precomp[2][0][0], &precomp[2][0][1],
247*5697Smcpowers 						 &precomp[3][0][0], &precomp[3][0][1], group));
248*5697Smcpowers 	/* precompute [*][1][*] */
249*5697Smcpowers 	for (i = 1; i < 4; i++) {
250*5697Smcpowers 		MP_CHECKOK(group->
251*5697Smcpowers 				   point_add(&precomp[0][1][0], &precomp[0][1][1],
252*5697Smcpowers 							 &precomp[i][0][0], &precomp[i][0][1],
253*5697Smcpowers 							 &precomp[i][1][0], &precomp[i][1][1], group));
254*5697Smcpowers 	}
255*5697Smcpowers 	/* precompute [*][2][*] */
256*5697Smcpowers 	MP_CHECKOK(group->
257*5697Smcpowers 			   point_dbl(&precomp[0][1][0], &precomp[0][1][1],
258*5697Smcpowers 						 &precomp[0][2][0], &precomp[0][2][1], group));
259*5697Smcpowers 	for (i = 1; i < 4; i++) {
260*5697Smcpowers 		MP_CHECKOK(group->
261*5697Smcpowers 				   point_add(&precomp[0][2][0], &precomp[0][2][1],
262*5697Smcpowers 							 &precomp[i][0][0], &precomp[i][0][1],
263*5697Smcpowers 							 &precomp[i][2][0], &precomp[i][2][1], group));
264*5697Smcpowers 	}
265*5697Smcpowers 	/* precompute [*][3][*] */
266*5697Smcpowers 	MP_CHECKOK(group->
267*5697Smcpowers 			   point_add(&precomp[0][1][0], &precomp[0][1][1],
268*5697Smcpowers 						 &precomp[0][2][0], &precomp[0][2][1],
269*5697Smcpowers 						 &precomp[0][3][0], &precomp[0][3][1], group));
270*5697Smcpowers 	for (i = 1; i < 4; i++) {
271*5697Smcpowers 		MP_CHECKOK(group->
272*5697Smcpowers 				   point_add(&precomp[0][3][0], &precomp[0][3][1],
273*5697Smcpowers 							 &precomp[i][0][0], &precomp[i][0][1],
274*5697Smcpowers 							 &precomp[i][3][0], &precomp[i][3][1], group));
275*5697Smcpowers 	}
276*5697Smcpowers 
277*5697Smcpowers 	d = (mpl_significant_bits(a) + 1) / 2;
278*5697Smcpowers 
279*5697Smcpowers 	/* R = inf */
280*5697Smcpowers 	mp_zero(rx);
281*5697Smcpowers 	mp_zero(ry);
282*5697Smcpowers 
283*5697Smcpowers 	for (i = d - 1; i >= 0; i--) {
284*5697Smcpowers 		ai = MP_GET_BIT(a, 2 * i + 1);
285*5697Smcpowers 		ai <<= 1;
286*5697Smcpowers 		ai |= MP_GET_BIT(a, 2 * i);
287*5697Smcpowers 		bi = MP_GET_BIT(b, 2 * i + 1);
288*5697Smcpowers 		bi <<= 1;
289*5697Smcpowers 		bi |= MP_GET_BIT(b, 2 * i);
290*5697Smcpowers 		/* R = 2^2 * R */
291*5697Smcpowers 		MP_CHECKOK(group->point_dbl(rx, ry, rx, ry, group));
292*5697Smcpowers 		MP_CHECKOK(group->point_dbl(rx, ry, rx, ry, group));
293*5697Smcpowers 		/* R = R + (ai * A + bi * B) */
294*5697Smcpowers 		MP_CHECKOK(group->
295*5697Smcpowers 				   point_add(rx, ry, &precomp[ai][bi][0],
296*5697Smcpowers 							 &precomp[ai][bi][1], rx, ry, group));
297*5697Smcpowers 	}
298*5697Smcpowers 
299*5697Smcpowers 	if (group->meth->field_dec) {
300*5697Smcpowers 		MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth));
301*5697Smcpowers 		MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth));
302*5697Smcpowers 	}
303*5697Smcpowers 
304*5697Smcpowers   CLEANUP:
305*5697Smcpowers 	for (i = 0; i < 4; i++) {
306*5697Smcpowers 		for (j = 0; j < 4; j++) {
307*5697Smcpowers 			mp_clear(&precomp[i][j][0]);
308*5697Smcpowers 			mp_clear(&precomp[i][j][1]);
309*5697Smcpowers 		}
310*5697Smcpowers 	}
311*5697Smcpowers 	return res;
312*5697Smcpowers }
313*5697Smcpowers 
314*5697Smcpowers /* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
315*5697Smcpowers  * k2 * P(x, y), where G is the generator (base point) of the group of
316*5697Smcpowers  * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
317*5697Smcpowers  * Input and output values are assumed to be NOT field-encoded. */
318*5697Smcpowers mp_err
ECPoints_mul(const ECGroup * group,const mp_int * k1,const mp_int * k2,const mp_int * px,const mp_int * py,mp_int * rx,mp_int * ry)319*5697Smcpowers ECPoints_mul(const ECGroup *group, const mp_int *k1, const mp_int *k2,
320*5697Smcpowers 			 const mp_int *px, const mp_int *py, mp_int *rx, mp_int *ry)
321*5697Smcpowers {
322*5697Smcpowers 	mp_err res = MP_OKAY;
323*5697Smcpowers 	mp_int k1t, k2t;
324*5697Smcpowers 	const mp_int *k1p, *k2p;
325*5697Smcpowers 
326*5697Smcpowers 	MP_DIGITS(&k1t) = 0;
327*5697Smcpowers 	MP_DIGITS(&k2t) = 0;
328*5697Smcpowers 
329*5697Smcpowers 	ARGCHK(group != NULL, MP_BADARG);
330*5697Smcpowers 
331*5697Smcpowers 	/* want scalar to be less than or equal to group order */
332*5697Smcpowers 	if (k1 != NULL) {
333*5697Smcpowers 		if (mp_cmp(k1, &group->order) >= 0) {
334*5697Smcpowers 			MP_CHECKOK(mp_init(&k1t, FLAG(k1)));
335*5697Smcpowers 			MP_CHECKOK(mp_mod(k1, &group->order, &k1t));
336*5697Smcpowers 			k1p = &k1t;
337*5697Smcpowers 		} else {
338*5697Smcpowers 			k1p = k1;
339*5697Smcpowers 		}
340*5697Smcpowers 	} else {
341*5697Smcpowers 		k1p = k1;
342*5697Smcpowers 	}
343*5697Smcpowers 	if (k2 != NULL) {
344*5697Smcpowers 		if (mp_cmp(k2, &group->order) >= 0) {
345*5697Smcpowers 			MP_CHECKOK(mp_init(&k2t, FLAG(k2)));
346*5697Smcpowers 			MP_CHECKOK(mp_mod(k2, &group->order, &k2t));
347*5697Smcpowers 			k2p = &k2t;
348*5697Smcpowers 		} else {
349*5697Smcpowers 			k2p = k2;
350*5697Smcpowers 		}
351*5697Smcpowers 	} else {
352*5697Smcpowers 		k2p = k2;
353*5697Smcpowers 	}
354*5697Smcpowers 
355*5697Smcpowers 	/* if points_mul is defined, then use it */
356*5697Smcpowers 	if (group->points_mul) {
357*5697Smcpowers 		res = group->points_mul(k1p, k2p, px, py, rx, ry, group);
358*5697Smcpowers 	} else {
359*5697Smcpowers 		res = ec_pts_mul_simul_w2(k1p, k2p, px, py, rx, ry, group);
360*5697Smcpowers 	}
361*5697Smcpowers 
362*5697Smcpowers   CLEANUP:
363*5697Smcpowers 	mp_clear(&k1t);
364*5697Smcpowers 	mp_clear(&k2t);
365*5697Smcpowers 	return res;
366*5697Smcpowers }
367