1160814Ssimon/* crypto/ec/ec2_mult.c */
2160814Ssimon/* ====================================================================
3160814Ssimon * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4160814Ssimon *
5160814Ssimon * The Elliptic Curve Public-Key Crypto Library (ECC Code) included
6160814Ssimon * herein is developed by SUN MICROSYSTEMS, INC., and is contributed
7160814Ssimon * to the OpenSSL project.
8160814Ssimon *
9160814Ssimon * The ECC Code is licensed pursuant to the OpenSSL open source
10160814Ssimon * license provided below.
11160814Ssimon *
12160814Ssimon * The software is originally written by Sheueling Chang Shantz and
13160814Ssimon * Douglas Stebila of Sun Microsystems Laboratories.
14160814Ssimon *
15160814Ssimon */
16160814Ssimon/* ====================================================================
17160814Ssimon * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
18160814Ssimon *
19160814Ssimon * Redistribution and use in source and binary forms, with or without
20160814Ssimon * modification, are permitted provided that the following conditions
21160814Ssimon * are met:
22160814Ssimon *
23160814Ssimon * 1. Redistributions of source code must retain the above copyright
24296341Sdelphij *    notice, this list of conditions and the following disclaimer.
25160814Ssimon *
26160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright
27160814Ssimon *    notice, this list of conditions and the following disclaimer in
28160814Ssimon *    the documentation and/or other materials provided with the
29160814Ssimon *    distribution.
30160814Ssimon *
31160814Ssimon * 3. All advertising materials mentioning features or use of this
32160814Ssimon *    software must display the following acknowledgment:
33160814Ssimon *    "This product includes software developed by the OpenSSL Project
34160814Ssimon *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
35160814Ssimon *
36160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
37160814Ssimon *    endorse or promote products derived from this software without
38160814Ssimon *    prior written permission. For written permission, please contact
39160814Ssimon *    openssl-core@openssl.org.
40160814Ssimon *
41160814Ssimon * 5. Products derived from this software may not be called "OpenSSL"
42160814Ssimon *    nor may "OpenSSL" appear in their names without prior written
43160814Ssimon *    permission of the OpenSSL Project.
44160814Ssimon *
45160814Ssimon * 6. Redistributions of any form whatsoever must retain the following
46160814Ssimon *    acknowledgment:
47160814Ssimon *    "This product includes software developed by the OpenSSL Project
48160814Ssimon *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
49160814Ssimon *
50160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
51160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53160814Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
54160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
57160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
59160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
61160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
62160814Ssimon * ====================================================================
63160814Ssimon *
64160814Ssimon * This product includes cryptographic software written by Eric Young
65160814Ssimon * (eay@cryptsoft.com).  This product includes software written by Tim
66160814Ssimon * Hudson (tjh@cryptsoft.com).
67160814Ssimon *
68160814Ssimon */
69160814Ssimon
70160814Ssimon#include <openssl/err.h>
71160814Ssimon
72160814Ssimon#include "ec_lcl.h"
73160814Ssimon
74238405Sjkim#ifndef OPENSSL_NO_EC2M
75160814Ssimon
76296341Sdelphij/*-
77296341Sdelphij * Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery projective
78160814Ssimon * coordinates.
79296341Sdelphij * Uses algorithm Mdouble in appendix of
80296341Sdelphij *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over
81238405Sjkim *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
82160814Ssimon * modified to not require precomputation of c=b^{2^{m-1}}.
83160814Ssimon */
84296341Sdelphijstatic int gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z,
85296341Sdelphij                        BN_CTX *ctx)
86296341Sdelphij{
87296341Sdelphij    BIGNUM *t1;
88296341Sdelphij    int ret = 0;
89160814Ssimon
90296341Sdelphij    /* Since Mdouble is static we can guarantee that ctx != NULL. */
91296341Sdelphij    BN_CTX_start(ctx);
92296341Sdelphij    t1 = BN_CTX_get(ctx);
93296341Sdelphij    if (t1 == NULL)
94296341Sdelphij        goto err;
95160814Ssimon
96296341Sdelphij    if (!group->meth->field_sqr(group, x, x, ctx))
97296341Sdelphij        goto err;
98296341Sdelphij    if (!group->meth->field_sqr(group, t1, z, ctx))
99296341Sdelphij        goto err;
100296341Sdelphij    if (!group->meth->field_mul(group, z, x, t1, ctx))
101296341Sdelphij        goto err;
102296341Sdelphij    if (!group->meth->field_sqr(group, x, x, ctx))
103296341Sdelphij        goto err;
104296341Sdelphij    if (!group->meth->field_sqr(group, t1, t1, ctx))
105296341Sdelphij        goto err;
106296341Sdelphij    if (!group->meth->field_mul(group, t1, &group->b, t1, ctx))
107296341Sdelphij        goto err;
108296341Sdelphij    if (!BN_GF2m_add(x, x, t1))
109296341Sdelphij        goto err;
110160814Ssimon
111296341Sdelphij    ret = 1;
112296341Sdelphij
113160814Ssimon err:
114296341Sdelphij    BN_CTX_end(ctx);
115296341Sdelphij    return ret;
116296341Sdelphij}
117160814Ssimon
118296341Sdelphij/*-
119296341Sdelphij * Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in Montgomery
120160814Ssimon * projective coordinates.
121296341Sdelphij * Uses algorithm Madd in appendix of
122296341Sdelphij *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over
123238405Sjkim *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
124160814Ssimon */
125296341Sdelphijstatic int gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1,
126296341Sdelphij                     BIGNUM *z1, const BIGNUM *x2, const BIGNUM *z2,
127296341Sdelphij                     BN_CTX *ctx)
128296341Sdelphij{
129296341Sdelphij    BIGNUM *t1, *t2;
130296341Sdelphij    int ret = 0;
131160814Ssimon
132296341Sdelphij    /* Since Madd is static we can guarantee that ctx != NULL. */
133296341Sdelphij    BN_CTX_start(ctx);
134296341Sdelphij    t1 = BN_CTX_get(ctx);
135296341Sdelphij    t2 = BN_CTX_get(ctx);
136296341Sdelphij    if (t2 == NULL)
137296341Sdelphij        goto err;
138160814Ssimon
139296341Sdelphij    if (!BN_copy(t1, x))
140296341Sdelphij        goto err;
141296341Sdelphij    if (!group->meth->field_mul(group, x1, x1, z2, ctx))
142296341Sdelphij        goto err;
143296341Sdelphij    if (!group->meth->field_mul(group, z1, z1, x2, ctx))
144296341Sdelphij        goto err;
145296341Sdelphij    if (!group->meth->field_mul(group, t2, x1, z1, ctx))
146296341Sdelphij        goto err;
147296341Sdelphij    if (!BN_GF2m_add(z1, z1, x1))
148296341Sdelphij        goto err;
149296341Sdelphij    if (!group->meth->field_sqr(group, z1, z1, ctx))
150296341Sdelphij        goto err;
151296341Sdelphij    if (!group->meth->field_mul(group, x1, z1, t1, ctx))
152296341Sdelphij        goto err;
153296341Sdelphij    if (!BN_GF2m_add(x1, x1, t2))
154296341Sdelphij        goto err;
155160814Ssimon
156296341Sdelphij    ret = 1;
157296341Sdelphij
158160814Ssimon err:
159296341Sdelphij    BN_CTX_end(ctx);
160296341Sdelphij    return ret;
161296341Sdelphij}
162160814Ssimon
163296341Sdelphij/*-
164296341Sdelphij * Compute the x, y affine coordinates from the point (x1, z1) (x2, z2)
165296341Sdelphij * using Montgomery point multiplication algorithm Mxy() in appendix of
166296341Sdelphij *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over
167238405Sjkim *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
168160814Ssimon * Returns:
169160814Ssimon *     0 on error
170160814Ssimon *     1 if return value should be the point at infinity
171160814Ssimon *     2 otherwise
172160814Ssimon */
173296341Sdelphijstatic int gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y,
174296341Sdelphij                    BIGNUM *x1, BIGNUM *z1, BIGNUM *x2, BIGNUM *z2,
175296341Sdelphij                    BN_CTX *ctx)
176296341Sdelphij{
177296341Sdelphij    BIGNUM *t3, *t4, *t5;
178296341Sdelphij    int ret = 0;
179160814Ssimon
180296341Sdelphij    if (BN_is_zero(z1)) {
181296341Sdelphij        BN_zero(x2);
182296341Sdelphij        BN_zero(z2);
183296341Sdelphij        return 1;
184296341Sdelphij    }
185160814Ssimon
186296341Sdelphij    if (BN_is_zero(z2)) {
187296341Sdelphij        if (!BN_copy(x2, x))
188296341Sdelphij            return 0;
189296341Sdelphij        if (!BN_GF2m_add(z2, x, y))
190296341Sdelphij            return 0;
191296341Sdelphij        return 2;
192296341Sdelphij    }
193160814Ssimon
194296341Sdelphij    /* Since Mxy is static we can guarantee that ctx != NULL. */
195296341Sdelphij    BN_CTX_start(ctx);
196296341Sdelphij    t3 = BN_CTX_get(ctx);
197296341Sdelphij    t4 = BN_CTX_get(ctx);
198296341Sdelphij    t5 = BN_CTX_get(ctx);
199296341Sdelphij    if (t5 == NULL)
200296341Sdelphij        goto err;
201160814Ssimon
202296341Sdelphij    if (!BN_one(t5))
203296341Sdelphij        goto err;
204160814Ssimon
205296341Sdelphij    if (!group->meth->field_mul(group, t3, z1, z2, ctx))
206296341Sdelphij        goto err;
207160814Ssimon
208296341Sdelphij    if (!group->meth->field_mul(group, z1, z1, x, ctx))
209296341Sdelphij        goto err;
210296341Sdelphij    if (!BN_GF2m_add(z1, z1, x1))
211296341Sdelphij        goto err;
212296341Sdelphij    if (!group->meth->field_mul(group, z2, z2, x, ctx))
213296341Sdelphij        goto err;
214296341Sdelphij    if (!group->meth->field_mul(group, x1, z2, x1, ctx))
215296341Sdelphij        goto err;
216296341Sdelphij    if (!BN_GF2m_add(z2, z2, x2))
217296341Sdelphij        goto err;
218160814Ssimon
219296341Sdelphij    if (!group->meth->field_mul(group, z2, z2, z1, ctx))
220296341Sdelphij        goto err;
221296341Sdelphij    if (!group->meth->field_sqr(group, t4, x, ctx))
222296341Sdelphij        goto err;
223296341Sdelphij    if (!BN_GF2m_add(t4, t4, y))
224296341Sdelphij        goto err;
225296341Sdelphij    if (!group->meth->field_mul(group, t4, t4, t3, ctx))
226296341Sdelphij        goto err;
227296341Sdelphij    if (!BN_GF2m_add(t4, t4, z2))
228296341Sdelphij        goto err;
229160814Ssimon
230296341Sdelphij    if (!group->meth->field_mul(group, t3, t3, x, ctx))
231296341Sdelphij        goto err;
232296341Sdelphij    if (!group->meth->field_div(group, t3, t5, t3, ctx))
233296341Sdelphij        goto err;
234296341Sdelphij    if (!group->meth->field_mul(group, t4, t3, t4, ctx))
235296341Sdelphij        goto err;
236296341Sdelphij    if (!group->meth->field_mul(group, x2, x1, t3, ctx))
237296341Sdelphij        goto err;
238296341Sdelphij    if (!BN_GF2m_add(z2, x2, x))
239296341Sdelphij        goto err;
240296341Sdelphij
241296341Sdelphij    if (!group->meth->field_mul(group, z2, z2, t4, ctx))
242296341Sdelphij        goto err;
243296341Sdelphij    if (!BN_GF2m_add(z2, z2, y))
244296341Sdelphij        goto err;
245296341Sdelphij
246296341Sdelphij    ret = 2;
247296341Sdelphij
248160814Ssimon err:
249296341Sdelphij    BN_CTX_end(ctx);
250296341Sdelphij    return ret;
251296341Sdelphij}
252160814Ssimon
253296341Sdelphij/*-
254296341Sdelphij * Computes scalar*point and stores the result in r.
255160814Ssimon * point can not equal r.
256264266Sdelphij * Uses a modified algorithm 2P of
257296341Sdelphij *     Lopez, J. and Dahab, R.  "Fast multiplication on elliptic curves over
258238405Sjkim *     GF(2^m) without precomputation" (CHES '99, LNCS 1717).
259264266Sdelphij *
260264266Sdelphij * To protect against side-channel attack the function uses constant time swap,
261264266Sdelphij * avoiding conditional branches.
262160814Ssimon */
263296341Sdelphijstatic int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group,
264296341Sdelphij                                             EC_POINT *r,
265296341Sdelphij                                             const BIGNUM *scalar,
266296341Sdelphij                                             const EC_POINT *point,
267296341Sdelphij                                             BN_CTX *ctx)
268296341Sdelphij{
269296341Sdelphij    BIGNUM *x1, *x2, *z1, *z2;
270296341Sdelphij    int ret = 0, i;
271296341Sdelphij    BN_ULONG mask, word;
272160814Ssimon
273296341Sdelphij    if (r == point) {
274296341Sdelphij        ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT);
275296341Sdelphij        return 0;
276296341Sdelphij    }
277160814Ssimon
278296341Sdelphij    /* if result should be point at infinity */
279296341Sdelphij    if ((scalar == NULL) || BN_is_zero(scalar) || (point == NULL) ||
280296341Sdelphij        EC_POINT_is_at_infinity(group, point)) {
281296341Sdelphij        return EC_POINT_set_to_infinity(group, r);
282296341Sdelphij    }
283160814Ssimon
284296341Sdelphij    /* only support affine coordinates */
285296341Sdelphij    if (!point->Z_is_one)
286296341Sdelphij        return 0;
287160814Ssimon
288296341Sdelphij    /*
289296341Sdelphij     * Since point_multiply is static we can guarantee that ctx != NULL.
290296341Sdelphij     */
291296341Sdelphij    BN_CTX_start(ctx);
292296341Sdelphij    x1 = BN_CTX_get(ctx);
293296341Sdelphij    z1 = BN_CTX_get(ctx);
294296341Sdelphij    if (z1 == NULL)
295296341Sdelphij        goto err;
296160814Ssimon
297296341Sdelphij    x2 = &r->X;
298296341Sdelphij    z2 = &r->Y;
299264266Sdelphij
300296341Sdelphij    bn_wexpand(x1, group->field.top);
301296341Sdelphij    bn_wexpand(z1, group->field.top);
302296341Sdelphij    bn_wexpand(x2, group->field.top);
303296341Sdelphij    bn_wexpand(z2, group->field.top);
304160814Ssimon
305296341Sdelphij    if (!BN_GF2m_mod_arr(x1, &point->X, group->poly))
306296341Sdelphij        goto err;               /* x1 = x */
307296341Sdelphij    if (!BN_one(z1))
308296341Sdelphij        goto err;               /* z1 = 1 */
309296341Sdelphij    if (!group->meth->field_sqr(group, z2, x1, ctx))
310296341Sdelphij        goto err;               /* z2 = x1^2 = x^2 */
311296341Sdelphij    if (!group->meth->field_sqr(group, x2, z2, ctx))
312296341Sdelphij        goto err;
313296341Sdelphij    if (!BN_GF2m_add(x2, x2, &group->b))
314296341Sdelphij        goto err;               /* x2 = x^4 + b */
315160814Ssimon
316296341Sdelphij    /* find top most bit and go one past it */
317296341Sdelphij    i = scalar->top - 1;
318296341Sdelphij    mask = BN_TBIT;
319296341Sdelphij    word = scalar->d[i];
320296341Sdelphij    while (!(word & mask))
321296341Sdelphij        mask >>= 1;
322296341Sdelphij    mask >>= 1;
323296341Sdelphij    /* if top most bit was at word break, go to next word */
324296341Sdelphij    if (!mask) {
325296341Sdelphij        i--;
326296341Sdelphij        mask = BN_TBIT;
327296341Sdelphij    }
328160814Ssimon
329296341Sdelphij    for (; i >= 0; i--) {
330296341Sdelphij        word = scalar->d[i];
331296341Sdelphij        while (mask) {
332296341Sdelphij            BN_consttime_swap(word & mask, x1, x2, group->field.top);
333296341Sdelphij            BN_consttime_swap(word & mask, z1, z2, group->field.top);
334296341Sdelphij            if (!gf2m_Madd(group, &point->X, x2, z2, x1, z1, ctx))
335296341Sdelphij                goto err;
336296341Sdelphij            if (!gf2m_Mdouble(group, x1, z1, ctx))
337296341Sdelphij                goto err;
338296341Sdelphij            BN_consttime_swap(word & mask, x1, x2, group->field.top);
339296341Sdelphij            BN_consttime_swap(word & mask, z1, z2, group->field.top);
340296341Sdelphij            mask >>= 1;
341296341Sdelphij        }
342296341Sdelphij        mask = BN_TBIT;
343296341Sdelphij    }
344160814Ssimon
345296341Sdelphij    /* convert out of "projective" coordinates */
346296341Sdelphij    i = gf2m_Mxy(group, &point->X, &point->Y, x1, z1, x2, z2, ctx);
347296341Sdelphij    if (i == 0)
348296341Sdelphij        goto err;
349296341Sdelphij    else if (i == 1) {
350296341Sdelphij        if (!EC_POINT_set_to_infinity(group, r))
351296341Sdelphij            goto err;
352296341Sdelphij    } else {
353296341Sdelphij        if (!BN_one(&r->Z))
354296341Sdelphij            goto err;
355296341Sdelphij        r->Z_is_one = 1;
356296341Sdelphij    }
357160814Ssimon
358296341Sdelphij    /* GF(2^m) field elements should always have BIGNUM::neg = 0 */
359296341Sdelphij    BN_set_negative(&r->X, 0);
360296341Sdelphij    BN_set_negative(&r->Y, 0);
361160814Ssimon
362296341Sdelphij    ret = 1;
363296341Sdelphij
364160814Ssimon err:
365296341Sdelphij    BN_CTX_end(ctx);
366296341Sdelphij    return ret;
367296341Sdelphij}
368160814Ssimon
369296341Sdelphij/*-
370296341Sdelphij * Computes the sum
371160814Ssimon *     scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1]
372160814Ssimon * gracefully ignoring NULL scalar values.
373160814Ssimon */
374296341Sdelphijint ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r,
375296341Sdelphij                       const BIGNUM *scalar, size_t num,
376296341Sdelphij                       const EC_POINT *points[], const BIGNUM *scalars[],
377296341Sdelphij                       BN_CTX *ctx)
378296341Sdelphij{
379296341Sdelphij    BN_CTX *new_ctx = NULL;
380296341Sdelphij    int ret = 0;
381296341Sdelphij    size_t i;
382296341Sdelphij    EC_POINT *p = NULL;
383296341Sdelphij    EC_POINT *acc = NULL;
384160814Ssimon
385296341Sdelphij    if (ctx == NULL) {
386296341Sdelphij        ctx = new_ctx = BN_CTX_new();
387296341Sdelphij        if (ctx == NULL)
388296341Sdelphij            return 0;
389296341Sdelphij    }
390160814Ssimon
391296341Sdelphij    /*
392296341Sdelphij     * This implementation is more efficient than the wNAF implementation for
393296341Sdelphij     * 2 or fewer points.  Use the ec_wNAF_mul implementation for 3 or more
394296341Sdelphij     * points, or if we can perform a fast multiplication based on
395296341Sdelphij     * precomputation.
396296341Sdelphij     */
397296341Sdelphij    if ((scalar && (num > 1)) || (num > 2)
398296341Sdelphij        || (num == 0 && EC_GROUP_have_precompute_mult(group))) {
399296341Sdelphij        ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
400296341Sdelphij        goto err;
401296341Sdelphij    }
402160814Ssimon
403296341Sdelphij    if ((p = EC_POINT_new(group)) == NULL)
404296341Sdelphij        goto err;
405296341Sdelphij    if ((acc = EC_POINT_new(group)) == NULL)
406296341Sdelphij        goto err;
407160814Ssimon
408296341Sdelphij    if (!EC_POINT_set_to_infinity(group, acc))
409296341Sdelphij        goto err;
410160814Ssimon
411296341Sdelphij    if (scalar) {
412296341Sdelphij        if (!ec_GF2m_montgomery_point_multiply
413296341Sdelphij            (group, p, scalar, group->generator, ctx))
414296341Sdelphij            goto err;
415296341Sdelphij        if (BN_is_negative(scalar))
416296341Sdelphij            if (!group->meth->invert(group, p, ctx))
417296341Sdelphij                goto err;
418296341Sdelphij        if (!group->meth->add(group, acc, acc, p, ctx))
419296341Sdelphij            goto err;
420296341Sdelphij    }
421160814Ssimon
422296341Sdelphij    for (i = 0; i < num; i++) {
423296341Sdelphij        if (!ec_GF2m_montgomery_point_multiply
424296341Sdelphij            (group, p, scalars[i], points[i], ctx))
425296341Sdelphij            goto err;
426296341Sdelphij        if (BN_is_negative(scalars[i]))
427296341Sdelphij            if (!group->meth->invert(group, p, ctx))
428296341Sdelphij                goto err;
429296341Sdelphij        if (!group->meth->add(group, acc, acc, p, ctx))
430296341Sdelphij            goto err;
431296341Sdelphij    }
432160814Ssimon
433296341Sdelphij    if (!EC_POINT_copy(r, acc))
434296341Sdelphij        goto err;
435215697Ssimon
436296341Sdelphij    ret = 1;
437160814Ssimon
438296341Sdelphij err:
439296341Sdelphij    if (p)
440296341Sdelphij        EC_POINT_free(p);
441296341Sdelphij    if (acc)
442296341Sdelphij        EC_POINT_free(acc);
443296341Sdelphij    if (new_ctx != NULL)
444296341Sdelphij        BN_CTX_free(new_ctx);
445296341Sdelphij    return ret;
446296341Sdelphij}
447160814Ssimon
448296341Sdelphij/*
449296341Sdelphij * Precomputation for point multiplication: fall back to wNAF methods because
450296341Sdelphij * ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate
451296341Sdelphij */
452160814Ssimon
453160814Ssimonint ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
454296341Sdelphij{
455296341Sdelphij    return ec_wNAF_precompute_mult(group, ctx);
456296341Sdelphij}
457160814Ssimon
458160814Ssimonint ec_GF2m_have_precompute_mult(const EC_GROUP *group)
459296341Sdelphij{
460296341Sdelphij    return ec_wNAF_have_precompute_mult(group);
461296341Sdelphij}
462238405Sjkim
463238405Sjkim#endif
464