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