Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/security/ec/impl/ecp.h
38918 views
/*1* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.2* Use is subject to license terms.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public6* License as published by the Free Software Foundation; either7* version 2.1 of the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public License15* along with this library; if not, write to the Free Software Foundation,16* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* *********************************************************************24*25* The Original Code is the elliptic curve math library for prime field curves.26*27* The Initial Developer of the Original Code is28* Sun Microsystems, Inc.29* Portions created by the Initial Developer are Copyright (C) 200330* the Initial Developer. All Rights Reserved.31*32* Contributor(s):33* Douglas Stebila <[email protected]>, Sun Microsystems Laboratories34*35* Last Modified Date from the Original Code: May 201736*********************************************************************** */3738#ifndef _ECP_H39#define _ECP_H4041#include "ecl-priv.h"4243/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */44mp_err ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py);4546/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */47mp_err ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py);4849/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,50* qy). Uses affine coordinates. */51mp_err ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py,52const mp_int *qx, const mp_int *qy, mp_int *rx,53mp_int *ry, const ECGroup *group);5455/* Computes R = P - Q. Uses affine coordinates. */56mp_err ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py,57const mp_int *qx, const mp_int *qy, mp_int *rx,58mp_int *ry, const ECGroup *group);5960/* Computes R = 2P. Uses affine coordinates. */61mp_err ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,62mp_int *ry, const ECGroup *group);6364/* Validates a point on a GFp curve. */65mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);6667#ifdef ECL_ENABLE_GFP_PT_MUL_AFF68/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters69* a, b and p are the elliptic curve coefficients and the prime that70* determines the field GFp. Uses affine coordinates. */71mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px,72const mp_int *py, mp_int *rx, mp_int *ry,73const ECGroup *group);74#endif7576/* Converts a point P(px, py) from affine coordinates to Jacobian77* projective coordinates R(rx, ry, rz). */78mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx,79mp_int *ry, mp_int *rz, const ECGroup *group);8081/* Converts a point P(px, py, pz) from Jacobian projective coordinates to82* affine coordinates R(rx, ry). */83mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py,84const mp_int *pz, mp_int *rx, mp_int *ry,85const ECGroup *group);8687/* Checks if point P(px, py, pz) is at infinity. Uses Jacobian88* coordinates. */89mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py,90const mp_int *pz);9192/* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian93* coordinates. */94mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz);9596/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is97* (qx, qy, qz). Uses Jacobian coordinates. */98mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py,99const mp_int *pz, const mp_int *qx,100const mp_int *qy, mp_int *rx, mp_int *ry,101mp_int *rz, const ECGroup *group);102103/* Computes R = 2P. Uses Jacobian coordinates. */104mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py,105const mp_int *pz, mp_int *rx, mp_int *ry,106mp_int *rz, const ECGroup *group);107108#ifdef ECL_ENABLE_GFP_PT_MUL_JAC109/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters110* a, b and p are the elliptic curve coefficients and the prime that111* determines the field GFp. Uses Jacobian coordinates. */112mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px,113const mp_int *py, mp_int *rx, mp_int *ry,114const ECGroup *group);115#endif116117/* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator118* (base point) of the group of points on the elliptic curve. Allows k1 =119* NULL or { k2, P } = NULL. Implemented using mixed Jacobian-affine120* coordinates. Input and output values are assumed to be NOT121* field-encoded and are in affine form. */122mp_err123ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px,124const mp_int *py, mp_int *rx, mp_int *ry,125const ECGroup *group, int timing);126127/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic128* curve points P and R can be identical. Uses mixed Modified-Jacobian129* co-ordinates for doubling and Chudnovsky Jacobian coordinates for130* additions. Assumes input is already field-encoded using field_enc, and131* returns output that is still field-encoded. Uses 5-bit window NAF132* method (algorithm 11) for scalar-point multiplication from Brown,133* Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic134* Curves Over Prime Fields. The implementation includes a countermeasure135* that attempts to hide the size of n from timing channels. This counter-136* measure is enabled using the timing argument. The high-rder bits of timing137* must be uniformly random in order for this countermeasure to work. */138mp_err139ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py,140mp_int *rx, mp_int *ry, const ECGroup *group,141int timing);142143#endif /* _ECP_H */144145146