1*f9fbec18Smcpowers /* 2*f9fbec18Smcpowers * ***** BEGIN LICENSE BLOCK ***** 3*f9fbec18Smcpowers * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4*f9fbec18Smcpowers * 5*f9fbec18Smcpowers * The contents of this file are subject to the Mozilla Public License Version 6*f9fbec18Smcpowers * 1.1 (the "License"); you may not use this file except in compliance with 7*f9fbec18Smcpowers * the License. You may obtain a copy of the License at 8*f9fbec18Smcpowers * http://www.mozilla.org/MPL/ 9*f9fbec18Smcpowers * 10*f9fbec18Smcpowers * Software distributed under the License is distributed on an "AS IS" basis, 11*f9fbec18Smcpowers * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12*f9fbec18Smcpowers * for the specific language governing rights and limitations under the 13*f9fbec18Smcpowers * License. 14*f9fbec18Smcpowers * 15*f9fbec18Smcpowers * The Original Code is the elliptic curve math library for prime field curves. 16*f9fbec18Smcpowers * 17*f9fbec18Smcpowers * The Initial Developer of the Original Code is 18*f9fbec18Smcpowers * Sun Microsystems, Inc. 19*f9fbec18Smcpowers * Portions created by the Initial Developer are Copyright (C) 2003 20*f9fbec18Smcpowers * the Initial Developer. All Rights Reserved. 21*f9fbec18Smcpowers * 22*f9fbec18Smcpowers * Contributor(s): 23*f9fbec18Smcpowers * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories 24*f9fbec18Smcpowers * 25*f9fbec18Smcpowers * Alternatively, the contents of this file may be used under the terms of 26*f9fbec18Smcpowers * either the GNU General Public License Version 2 or later (the "GPL"), or 27*f9fbec18Smcpowers * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28*f9fbec18Smcpowers * in which case the provisions of the GPL or the LGPL are applicable instead 29*f9fbec18Smcpowers * of those above. If you wish to allow use of your version of this file only 30*f9fbec18Smcpowers * under the terms of either the GPL or the LGPL, and not to allow others to 31*f9fbec18Smcpowers * use your version of this file under the terms of the MPL, indicate your 32*f9fbec18Smcpowers * decision by deleting the provisions above and replace them with the notice 33*f9fbec18Smcpowers * and other provisions required by the GPL or the LGPL. If you do not delete 34*f9fbec18Smcpowers * the provisions above, a recipient may use your version of this file under 35*f9fbec18Smcpowers * the terms of any one of the MPL, the GPL or the LGPL. 36*f9fbec18Smcpowers * 37*f9fbec18Smcpowers * ***** END LICENSE BLOCK ***** */ 38*f9fbec18Smcpowers /* 39*f9fbec18Smcpowers * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 40*f9fbec18Smcpowers * Use is subject to license terms. 41*f9fbec18Smcpowers * 42*f9fbec18Smcpowers * Sun elects to use this software under the MPL license. 43*f9fbec18Smcpowers */ 44*f9fbec18Smcpowers 45*f9fbec18Smcpowers #ifndef _ECP_H 46*f9fbec18Smcpowers #define _ECP_H 47*f9fbec18Smcpowers 48*f9fbec18Smcpowers #pragma ident "%Z%%M% %I% %E% SMI" 49*f9fbec18Smcpowers 50*f9fbec18Smcpowers #include "ecl-priv.h" 51*f9fbec18Smcpowers 52*f9fbec18Smcpowers /* Checks if point P(px, py) is at infinity. Uses affine coordinates. */ 53*f9fbec18Smcpowers mp_err ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py); 54*f9fbec18Smcpowers 55*f9fbec18Smcpowers /* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */ 56*f9fbec18Smcpowers mp_err ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py); 57*f9fbec18Smcpowers 58*f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx, 59*f9fbec18Smcpowers * qy). Uses affine coordinates. */ 60*f9fbec18Smcpowers mp_err ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py, 61*f9fbec18Smcpowers const mp_int *qx, const mp_int *qy, mp_int *rx, 62*f9fbec18Smcpowers mp_int *ry, const ECGroup *group); 63*f9fbec18Smcpowers 64*f9fbec18Smcpowers /* Computes R = P - Q. Uses affine coordinates. */ 65*f9fbec18Smcpowers mp_err ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py, 66*f9fbec18Smcpowers const mp_int *qx, const mp_int *qy, mp_int *rx, 67*f9fbec18Smcpowers mp_int *ry, const ECGroup *group); 68*f9fbec18Smcpowers 69*f9fbec18Smcpowers /* Computes R = 2P. Uses affine coordinates. */ 70*f9fbec18Smcpowers mp_err ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx, 71*f9fbec18Smcpowers mp_int *ry, const ECGroup *group); 72*f9fbec18Smcpowers 73*f9fbec18Smcpowers /* Validates a point on a GFp curve. */ 74*f9fbec18Smcpowers mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group); 75*f9fbec18Smcpowers 76*f9fbec18Smcpowers #ifdef ECL_ENABLE_GFP_PT_MUL_AFF 77*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 78*f9fbec18Smcpowers * a, b and p are the elliptic curve coefficients and the prime that 79*f9fbec18Smcpowers * determines the field GFp. Uses affine coordinates. */ 80*f9fbec18Smcpowers mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px, 81*f9fbec18Smcpowers const mp_int *py, mp_int *rx, mp_int *ry, 82*f9fbec18Smcpowers const ECGroup *group); 83*f9fbec18Smcpowers #endif 84*f9fbec18Smcpowers 85*f9fbec18Smcpowers /* Converts a point P(px, py) from affine coordinates to Jacobian 86*f9fbec18Smcpowers * projective coordinates R(rx, ry, rz). */ 87*f9fbec18Smcpowers mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx, 88*f9fbec18Smcpowers mp_int *ry, mp_int *rz, const ECGroup *group); 89*f9fbec18Smcpowers 90*f9fbec18Smcpowers /* Converts a point P(px, py, pz) from Jacobian projective coordinates to 91*f9fbec18Smcpowers * affine coordinates R(rx, ry). */ 92*f9fbec18Smcpowers mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py, 93*f9fbec18Smcpowers const mp_int *pz, mp_int *rx, mp_int *ry, 94*f9fbec18Smcpowers const ECGroup *group); 95*f9fbec18Smcpowers 96*f9fbec18Smcpowers /* Checks if point P(px, py, pz) is at infinity. Uses Jacobian 97*f9fbec18Smcpowers * coordinates. */ 98*f9fbec18Smcpowers mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py, 99*f9fbec18Smcpowers const mp_int *pz); 100*f9fbec18Smcpowers 101*f9fbec18Smcpowers /* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian 102*f9fbec18Smcpowers * coordinates. */ 103*f9fbec18Smcpowers mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz); 104*f9fbec18Smcpowers 105*f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is 106*f9fbec18Smcpowers * (qx, qy, qz). Uses Jacobian coordinates. */ 107*f9fbec18Smcpowers mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py, 108*f9fbec18Smcpowers const mp_int *pz, const mp_int *qx, 109*f9fbec18Smcpowers const mp_int *qy, mp_int *rx, mp_int *ry, 110*f9fbec18Smcpowers mp_int *rz, const ECGroup *group); 111*f9fbec18Smcpowers 112*f9fbec18Smcpowers /* Computes R = 2P. Uses Jacobian coordinates. */ 113*f9fbec18Smcpowers mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py, 114*f9fbec18Smcpowers const mp_int *pz, mp_int *rx, mp_int *ry, 115*f9fbec18Smcpowers mp_int *rz, const ECGroup *group); 116*f9fbec18Smcpowers 117*f9fbec18Smcpowers #ifdef ECL_ENABLE_GFP_PT_MUL_JAC 118*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 119*f9fbec18Smcpowers * a, b and p are the elliptic curve coefficients and the prime that 120*f9fbec18Smcpowers * determines the field GFp. Uses Jacobian coordinates. */ 121*f9fbec18Smcpowers mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px, 122*f9fbec18Smcpowers const mp_int *py, mp_int *rx, mp_int *ry, 123*f9fbec18Smcpowers const ECGroup *group); 124*f9fbec18Smcpowers #endif 125*f9fbec18Smcpowers 126*f9fbec18Smcpowers /* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator 127*f9fbec18Smcpowers * (base point) of the group of points on the elliptic curve. Allows k1 = 128*f9fbec18Smcpowers * NULL or { k2, P } = NULL. Implemented using mixed Jacobian-affine 129*f9fbec18Smcpowers * coordinates. Input and output values are assumed to be NOT 130*f9fbec18Smcpowers * field-encoded and are in affine form. */ 131*f9fbec18Smcpowers mp_err 132*f9fbec18Smcpowers ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px, 133*f9fbec18Smcpowers const mp_int *py, mp_int *rx, mp_int *ry, 134*f9fbec18Smcpowers const ECGroup *group); 135*f9fbec18Smcpowers 136*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic 137*f9fbec18Smcpowers * curve points P and R can be identical. Uses mixed Modified-Jacobian 138*f9fbec18Smcpowers * co-ordinates for doubling and Chudnovsky Jacobian coordinates for 139*f9fbec18Smcpowers * additions. Assumes input is already field-encoded using field_enc, and 140*f9fbec18Smcpowers * returns output that is still field-encoded. Uses 5-bit window NAF 141*f9fbec18Smcpowers * method (algorithm 11) for scalar-point multiplication from Brown, 142*f9fbec18Smcpowers * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic 143*f9fbec18Smcpowers * Curves Over Prime Fields. */ 144*f9fbec18Smcpowers mp_err 145*f9fbec18Smcpowers ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py, 146*f9fbec18Smcpowers mp_int *rx, mp_int *ry, const ECGroup *group); 147*f9fbec18Smcpowers 148*f9fbec18Smcpowers #endif /* _ECP_H */ 149