1656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* crypto/ec/ec2_mult.c */ 2656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* ==================================================================== 3656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 4656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 5656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * The Elliptic Curve Public-Key Crypto Library (ECC Code) included 6656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * herein is developed by SUN MICROSYSTEMS, INC., and is contributed 7656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * to the OpenSSL project. 8656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * The ECC Code is licensed pursuant to the OpenSSL open source 10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * license provided below. 11656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * The software is originally written by Sheueling Chang Shantz and 13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Douglas Stebila of Sun Microsystems Laboratories. 14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 15656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 16656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* ==================================================================== 17656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 18656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Redistribution and use in source and binary forms, with or without 20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * modification, are permitted provided that the following conditions 21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * are met: 22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 1. Redistributions of source code must retain the above copyright 24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * notice, this list of conditions and the following disclaimer. 25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 26656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 27656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * notice, this list of conditions and the following disclaimer in 28656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * the documentation and/or other materials provided with the 29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * distribution. 30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 31656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 3. All advertising materials mentioning features or use of this 32656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * software must display the following acknowledgment: 33656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "This product includes software developed by the OpenSSL Project 34656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 35656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 36656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 37656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * endorse or promote products derived from this software without 38656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * prior written permission. For written permission, please contact 39656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * openssl-core@openssl.org. 40656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 41656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 5. Products derived from this software may not be called "OpenSSL" 42656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * nor may "OpenSSL" appear in their names without prior written 43656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * permission of the OpenSSL Project. 44656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 45656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 6. Redistributions of any form whatsoever must retain the following 46656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * acknowledgment: 47656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "This product includes software developed by the OpenSSL Project 48656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 49656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 50656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 51656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 53656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 54656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 55656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 56656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 57656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 59656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 60656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * OF THE POSSIBILITY OF SUCH DAMAGE. 62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ==================================================================== 63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This product includes cryptographic software written by Eric Young 65656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * (eay@cryptsoft.com). This product includes software written by Tim 66656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Hudson (tjh@cryptsoft.com). 67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 69656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 70656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/err.h> 71656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 72656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include "ec_lcl.h" 73656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 74392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom#ifndef OPENSSL_NO_EC2M 75392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 76656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 77656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery projective 78656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * coordinates. 79656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Uses algorithm Mdouble in appendix of 80656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over 81221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * GF(2^m) without precomputation" (CHES '99, LNCS 1717). 82656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * modified to not require precomputation of c=b^{2^{m-1}}. 83656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 84656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int gf2m_Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx) 85656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 86656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BIGNUM *t1; 87656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int ret = 0; 88656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 89656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* Since Mdouble is static we can guarantee that ctx != NULL. */ 90656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_start(ctx); 91656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project t1 = BN_CTX_get(ctx); 92656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (t1 == NULL) goto err; 93656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 94656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, x, x, ctx)) goto err; 95656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, t1, z, ctx)) goto err; 96656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, z, x, t1, ctx)) goto err; 97656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, x, x, ctx)) goto err; 98656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, t1, t1, ctx)) goto err; 99656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, t1, &group->b, t1, ctx)) goto err; 100656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(x, x, t1)) goto err; 101656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 102656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = 1; 103656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 104656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err: 105656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_end(ctx); 106656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ret; 107656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 108656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 109656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in Montgomery 110656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * projective coordinates. 111656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Uses algorithm Madd in appendix of 112221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over 113221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * GF(2^m) without precomputation" (CHES '99, LNCS 1717). 114656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 115656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int gf2m_Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1, 116656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx) 117656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 118656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BIGNUM *t1, *t2; 119656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int ret = 0; 120656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 121656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* Since Madd is static we can guarantee that ctx != NULL. */ 122656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_start(ctx); 123656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project t1 = BN_CTX_get(ctx); 124656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project t2 = BN_CTX_get(ctx); 125656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (t2 == NULL) goto err; 126656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 127656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_copy(t1, x)) goto err; 128656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, x1, x1, z2, ctx)) goto err; 129656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, z1, z1, x2, ctx)) goto err; 130656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, t2, x1, z1, ctx)) goto err; 131656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(z1, z1, x1)) goto err; 132656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, z1, z1, ctx)) goto err; 133656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, x1, z1, t1, ctx)) goto err; 134656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(x1, x1, t2)) goto err; 135656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 136656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = 1; 137656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 138656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err: 139656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_end(ctx); 140656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ret; 141656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 142656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 143656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Compute the x, y affine coordinates from the point (x1, z1) (x2, z2) 144656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * using Montgomery point multiplication algorithm Mxy() in appendix of 145221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over 146221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * GF(2^m) without precomputation" (CHES '99, LNCS 1717). 147656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Returns: 148656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 0 on error 149656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 1 if return value should be the point at infinity 150656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 2 otherwise 151656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 152656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int gf2m_Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1, 153656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BIGNUM *z1, BIGNUM *x2, BIGNUM *z2, BN_CTX *ctx) 154656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 155656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BIGNUM *t3, *t4, *t5; 156656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int ret = 0; 157656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 158656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (BN_is_zero(z1)) 159656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 160656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_zero(x2); 161656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_zero(z2); 162656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 163656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 164656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 165656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (BN_is_zero(z2)) 166656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 167656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_copy(x2, x)) return 0; 168656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(z2, x, y)) return 0; 169656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 2; 170656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 171656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 172656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* Since Mxy is static we can guarantee that ctx != NULL. */ 173656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_start(ctx); 174656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project t3 = BN_CTX_get(ctx); 175656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project t4 = BN_CTX_get(ctx); 176656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project t5 = BN_CTX_get(ctx); 177656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (t5 == NULL) goto err; 178656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 179656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_one(t5)) goto err; 180656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 181656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, t3, z1, z2, ctx)) goto err; 182656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 183656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, z1, z1, x, ctx)) goto err; 184656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(z1, z1, x1)) goto err; 185656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, z2, z2, x, ctx)) goto err; 186656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, x1, z2, x1, ctx)) goto err; 187656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(z2, z2, x2)) goto err; 188656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 189656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, z2, z2, z1, ctx)) goto err; 190656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, t4, x, ctx)) goto err; 191656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(t4, t4, y)) goto err; 192656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, t4, t4, t3, ctx)) goto err; 193656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(t4, t4, z2)) goto err; 194656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 195656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, t3, t3, x, ctx)) goto err; 196656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_div(group, t3, t5, t3, ctx)) goto err; 197656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, t4, t3, t4, ctx)) goto err; 198656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, x2, x1, t3, ctx)) goto err; 199656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(z2, x2, x)) goto err; 200656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 201656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_mul(group, z2, z2, t4, ctx)) goto err; 202656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(z2, z2, y)) goto err; 203656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 204656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = 2; 205656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 206656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err: 207656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_end(ctx); 208656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ret; 209656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 210656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 2117f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root 212656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Computes scalar*point and stores the result in r. 213656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * point can not equal r. 2147f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root * Uses a modified algorithm 2P of 215221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over 216221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * GF(2^m) without precomputation" (CHES '99, LNCS 1717). 2177f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root * 2187f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root * To protect against side-channel attack the function uses constant time swap, 2197f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root * avoiding conditional branches. 220656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 221656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 222656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project const EC_POINT *point, BN_CTX *ctx) 223656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 224656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BIGNUM *x1, *x2, *z1, *z2; 225221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom int ret = 0, i; 226221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom BN_ULONG mask,word; 227656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 228656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (r == point) 229656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 230656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT); 231656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 0; 232656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 233656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 234656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* if result should be point at infinity */ 235656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if ((scalar == NULL) || BN_is_zero(scalar) || (point == NULL) || 236656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project EC_POINT_is_at_infinity(group, point)) 237656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 238656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return EC_POINT_set_to_infinity(group, r); 239656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 240656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 241656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* only support affine coordinates */ 242656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!point->Z_is_one) return 0; 243656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 244656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* Since point_multiply is static we can guarantee that ctx != NULL. */ 245656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_start(ctx); 246656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project x1 = BN_CTX_get(ctx); 247656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project z1 = BN_CTX_get(ctx); 248656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (z1 == NULL) goto err; 249656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 250656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project x2 = &r->X; 251656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project z2 = &r->Y; 252656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 2537f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root bn_wexpand(x1, group->field.top); 2547f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root bn_wexpand(z1, group->field.top); 2557f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root bn_wexpand(x2, group->field.top); 2567f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root bn_wexpand(z2, group->field.top); 2577f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root 258656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_mod_arr(x1, &point->X, group->poly)) goto err; /* x1 = x */ 259656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_one(z1)) goto err; /* z1 = 1 */ 260656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, z2, x1, ctx)) goto err; /* z2 = x1^2 = x^2 */ 261656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->field_sqr(group, x2, z2, ctx)) goto err; 262656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_GF2m_add(x2, x2, &group->b)) goto err; /* x2 = x^4 + b */ 263656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 264656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* find top most bit and go one past it */ 265221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom i = scalar->top - 1; 266656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project mask = BN_TBIT; 267221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom word = scalar->d[i]; 268221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom while (!(word & mask)) mask >>= 1; 269221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom mask >>= 1; 270656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* if top most bit was at word break, go to next word */ 271656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!mask) 272656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 273221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom i--; 274656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project mask = BN_TBIT; 275656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 276656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 277656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (; i >= 0; i--) 278656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 279221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom word = scalar->d[i]; 280221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom while (mask) 281656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 2827f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root BN_consttime_swap(word & mask, x1, x2, group->field.top); 2837f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root BN_consttime_swap(word & mask, z1, z2, group->field.top); 2847f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root if (!gf2m_Madd(group, &point->X, x2, z2, x1, z1, ctx)) goto err; 2857f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root if (!gf2m_Mdouble(group, x1, z1, ctx)) goto err; 2867f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root BN_consttime_swap(word & mask, x1, x2, group->field.top); 2877f7ea2d72f2e316ba518e82f06513e3477840c15Kenny Root BN_consttime_swap(word & mask, z1, z2, group->field.top); 288656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project mask >>= 1; 289656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 290656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project mask = BN_TBIT; 291656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 292656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 293656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* convert out of "projective" coordinates */ 294656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project i = gf2m_Mxy(group, &point->X, &point->Y, x1, z1, x2, z2, ctx); 295656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (i == 0) goto err; 296656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project else if (i == 1) 297656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 298656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!EC_POINT_set_to_infinity(group, r)) goto err; 299656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 300656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project else 301656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 302656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!BN_one(&r->Z)) goto err; 303656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project r->Z_is_one = 1; 304656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 305656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 306656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* GF(2^m) field elements should always have BIGNUM::neg = 0 */ 307656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_set_negative(&r->X, 0); 308656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_set_negative(&r->Y, 0); 309656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 310656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = 1; 311656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 312656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err: 313656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_end(ctx); 314656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ret; 315656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 316656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 317656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 318656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Computes the sum 319656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1] 320656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * gracefully ignoring NULL scalar values. 321656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 322656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 323656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) 324656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 325656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX *new_ctx = NULL; 326656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int ret = 0; 327656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project size_t i; 328656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project EC_POINT *p=NULL; 32943c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom EC_POINT *acc = NULL; 330656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 331656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (ctx == NULL) 332656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 333656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ctx = new_ctx = BN_CTX_new(); 334656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (ctx == NULL) 335656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 0; 336656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 337656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 338656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* This implementation is more efficient than the wNAF implementation for 2 339656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * or fewer points. Use the ec_wNAF_mul implementation for 3 or more points, 340656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * or if we can perform a fast multiplication based on precomputation. 341656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 342656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if ((scalar && (num > 1)) || (num > 2) || (num == 0 && EC_GROUP_have_precompute_mult(group))) 343656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 344656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx); 345656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project goto err; 346656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 347656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 348656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if ((p = EC_POINT_new(group)) == NULL) goto err; 34943c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if ((acc = EC_POINT_new(group)) == NULL) goto err; 350656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 35143c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if (!EC_POINT_set_to_infinity(group, acc)) goto err; 352656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 353656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (scalar) 354656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 355656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err; 35643c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if (BN_is_negative(scalar)) 357656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->invert(group, p, ctx)) goto err; 35843c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if (!group->meth->add(group, acc, acc, p, ctx)) goto err; 359656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 360656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 361656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project for (i = 0; i < num; i++) 362656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 363656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err; 364656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (BN_is_negative(scalars[i])) 365656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (!group->meth->invert(group, p, ctx)) goto err; 36643c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if (!group->meth->add(group, acc, acc, p, ctx)) goto err; 367656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 368656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 36943c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if (!EC_POINT_copy(r, acc)) goto err; 37043c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom 371656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = 1; 372656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 373656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project err: 374656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (p) EC_POINT_free(p); 37543c12e3d4f9bbbbd4a8ba7b149686437514bc6b6Brian Carlstrom if (acc) EC_POINT_free(acc); 376656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (new_ctx != NULL) 377656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project BN_CTX_free(new_ctx); 378656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ret; 379656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 380656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 381656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 382656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Precomputation for point multiplication: fall back to wNAF methods 383656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * because ec_GF2m_simple_mul() uses ec_wNAF_mul() if appropriate */ 384656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 385656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx) 386656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 387656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ec_wNAF_precompute_mult(group, ctx); 388656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 389656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 390656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ec_GF2m_have_precompute_mult(const EC_GROUP *group) 391656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 392656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ec_wNAF_have_precompute_mult(group); 393656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 394392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom 395392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom#endif 396