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 binary polynomial 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 _EC2_H 46*f9fbec18Smcpowers #define _EC2_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_GF2m_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_GF2m_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_GF2m_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_GF2m_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_GF2m_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 GF2m curve. */ 74*f9fbec18Smcpowers mp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group); 75*f9fbec18Smcpowers 76*f9fbec18Smcpowers /* by default, this routine is unused and thus doesn't need to be compiled */ 77*f9fbec18Smcpowers #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF 78*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 79*f9fbec18Smcpowers * a, b and p are the elliptic curve coefficients and the irreducible that 80*f9fbec18Smcpowers * determines the field GF2m. Uses affine coordinates. */ 81*f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px, 82*f9fbec18Smcpowers const mp_int *py, mp_int *rx, mp_int *ry, 83*f9fbec18Smcpowers const ECGroup *group); 84*f9fbec18Smcpowers #endif 85*f9fbec18Smcpowers 86*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 87*f9fbec18Smcpowers * a, b and p are the elliptic curve coefficients and the irreducible that 88*f9fbec18Smcpowers * determines the field GF2m. Uses Montgomery projective coordinates. */ 89*f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px, 90*f9fbec18Smcpowers const mp_int *py, mp_int *rx, mp_int *ry, 91*f9fbec18Smcpowers const ECGroup *group); 92*f9fbec18Smcpowers 93*f9fbec18Smcpowers #ifdef ECL_ENABLE_GF2M_PROJ 94*f9fbec18Smcpowers /* Converts a point P(px, py) from affine coordinates to projective 95*f9fbec18Smcpowers * coordinates R(rx, ry, rz). */ 96*f9fbec18Smcpowers mp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx, 97*f9fbec18Smcpowers mp_int *ry, mp_int *rz, const ECGroup *group); 98*f9fbec18Smcpowers 99*f9fbec18Smcpowers /* Converts a point P(px, py, pz) from projective coordinates to affine 100*f9fbec18Smcpowers * coordinates R(rx, ry). */ 101*f9fbec18Smcpowers mp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py, 102*f9fbec18Smcpowers const mp_int *pz, mp_int *rx, mp_int *ry, 103*f9fbec18Smcpowers const ECGroup *group); 104*f9fbec18Smcpowers 105*f9fbec18Smcpowers /* Checks if point P(px, py, pz) is at infinity. Uses projective 106*f9fbec18Smcpowers * coordinates. */ 107*f9fbec18Smcpowers mp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py, 108*f9fbec18Smcpowers const mp_int *pz); 109*f9fbec18Smcpowers 110*f9fbec18Smcpowers /* Sets P(px, py, pz) to be the point at infinity. Uses projective 111*f9fbec18Smcpowers * coordinates. */ 112*f9fbec18Smcpowers mp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz); 113*f9fbec18Smcpowers 114*f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is 115*f9fbec18Smcpowers * (qx, qy, qz). Uses projective coordinates. */ 116*f9fbec18Smcpowers mp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py, 117*f9fbec18Smcpowers const mp_int *pz, const mp_int *qx, 118*f9fbec18Smcpowers const mp_int *qy, mp_int *rx, mp_int *ry, 119*f9fbec18Smcpowers mp_int *rz, const ECGroup *group); 120*f9fbec18Smcpowers 121*f9fbec18Smcpowers /* Computes R = 2P. Uses projective coordinates. */ 122*f9fbec18Smcpowers mp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py, 123*f9fbec18Smcpowers const mp_int *pz, mp_int *rx, mp_int *ry, 124*f9fbec18Smcpowers mp_int *rz, const ECGroup *group); 125*f9fbec18Smcpowers 126*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 127*f9fbec18Smcpowers * a, b and p are the elliptic curve coefficients and the prime that 128*f9fbec18Smcpowers * determines the field GF2m. Uses projective coordinates. */ 129*f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px, 130*f9fbec18Smcpowers const mp_int *py, mp_int *rx, mp_int *ry, 131*f9fbec18Smcpowers const ECGroup *group); 132*f9fbec18Smcpowers #endif 133*f9fbec18Smcpowers 134*f9fbec18Smcpowers #endif /* _EC2_H */ 135