1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/freebl/ecl/ecp.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef __ecp_h_ 1.9 +#define __ecp_h_ 1.10 + 1.11 +#include "ecl-priv.h" 1.12 + 1.13 +/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */ 1.14 +mp_err ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py); 1.15 + 1.16 +/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */ 1.17 +mp_err ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py); 1.18 + 1.19 +/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx, 1.20 + * qy). Uses affine coordinates. */ 1.21 +mp_err ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py, 1.22 + const mp_int *qx, const mp_int *qy, mp_int *rx, 1.23 + mp_int *ry, const ECGroup *group); 1.24 + 1.25 +/* Computes R = P - Q. Uses affine coordinates. */ 1.26 +mp_err ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py, 1.27 + const mp_int *qx, const mp_int *qy, mp_int *rx, 1.28 + mp_int *ry, const ECGroup *group); 1.29 + 1.30 +/* Computes R = 2P. Uses affine coordinates. */ 1.31 +mp_err ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx, 1.32 + mp_int *ry, const ECGroup *group); 1.33 + 1.34 +/* Validates a point on a GFp curve. */ 1.35 +mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group); 1.36 + 1.37 +#ifdef ECL_ENABLE_GFP_PT_MUL_AFF 1.38 +/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 1.39 + * a, b and p are the elliptic curve coefficients and the prime that 1.40 + * determines the field GFp. Uses affine coordinates. */ 1.41 +mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px, 1.42 + const mp_int *py, mp_int *rx, mp_int *ry, 1.43 + const ECGroup *group); 1.44 +#endif 1.45 + 1.46 +/* Converts a point P(px, py) from affine coordinates to Jacobian 1.47 + * projective coordinates R(rx, ry, rz). */ 1.48 +mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx, 1.49 + mp_int *ry, mp_int *rz, const ECGroup *group); 1.50 + 1.51 +/* Converts a point P(px, py, pz) from Jacobian projective coordinates to 1.52 + * affine coordinates R(rx, ry). */ 1.53 +mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py, 1.54 + const mp_int *pz, mp_int *rx, mp_int *ry, 1.55 + const ECGroup *group); 1.56 + 1.57 +/* Checks if point P(px, py, pz) is at infinity. Uses Jacobian 1.58 + * coordinates. */ 1.59 +mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py, 1.60 + const mp_int *pz); 1.61 + 1.62 +/* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian 1.63 + * coordinates. */ 1.64 +mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz); 1.65 + 1.66 +/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is 1.67 + * (qx, qy, qz). Uses Jacobian coordinates. */ 1.68 +mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py, 1.69 + const mp_int *pz, const mp_int *qx, 1.70 + const mp_int *qy, mp_int *rx, mp_int *ry, 1.71 + mp_int *rz, const ECGroup *group); 1.72 + 1.73 +/* Computes R = 2P. Uses Jacobian coordinates. */ 1.74 +mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py, 1.75 + const mp_int *pz, mp_int *rx, mp_int *ry, 1.76 + mp_int *rz, const ECGroup *group); 1.77 + 1.78 +#ifdef ECL_ENABLE_GFP_PT_MUL_JAC 1.79 +/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters 1.80 + * a, b and p are the elliptic curve coefficients and the prime that 1.81 + * determines the field GFp. Uses Jacobian coordinates. */ 1.82 +mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px, 1.83 + const mp_int *py, mp_int *rx, mp_int *ry, 1.84 + const ECGroup *group); 1.85 +#endif 1.86 + 1.87 +/* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator 1.88 + * (base point) of the group of points on the elliptic curve. Allows k1 = 1.89 + * NULL or { k2, P } = NULL. Implemented using mixed Jacobian-affine 1.90 + * coordinates. Input and output values are assumed to be NOT 1.91 + * field-encoded and are in affine form. */ 1.92 +mp_err 1.93 + ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px, 1.94 + const mp_int *py, mp_int *rx, mp_int *ry, 1.95 + const ECGroup *group); 1.96 + 1.97 +/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic 1.98 + * curve points P and R can be identical. Uses mixed Modified-Jacobian 1.99 + * co-ordinates for doubling and Chudnovsky Jacobian coordinates for 1.100 + * additions. Assumes input is already field-encoded using field_enc, and 1.101 + * returns output that is still field-encoded. Uses 5-bit window NAF 1.102 + * method (algorithm 11) for scalar-point multiplication from Brown, 1.103 + * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic 1.104 + * Curves Over Prime Fields. */ 1.105 +mp_err 1.106 + ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py, 1.107 + mp_int *rx, mp_int *ry, const ECGroup *group); 1.108 + 1.109 +#endif /* __ecp_h_ */