annotate src/share/native/sun/security/ec/impl/ecp.h @ 1674:845fefff00a4

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