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