/*
* Use is subject to license terms.
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* *********************************************************************
*
* The Original Code is the elliptic curve math library for prime field curves.
*
* The Initial Developer of the Original Code is
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Sheueling Chang-Shantz <sheueling.chang@sun.com>,
* Stephen Fung <fungstep@hotmail.com>, and
* Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories.
* Bodo Moeller <moeller@cdc.informatik.tu-darmstadt.de>,
* Nils Larsch <nla@trustcenter.de>, and
* Lenka Fibikova <fibikova@exp-math.uni-essen.de>, the OpenSSL Project
*
*********************************************************************** */
#include "ecp.h"
#include "mplogic.h"
#ifndef _KERNEL
#include <stdlib.h>
#endif
#ifdef ECL_DEBUG
#include <assert.h>
#endif
/* Converts a point P(px, py) from affine coordinates to Jacobian
* projective coordinates R(rx, ry, rz). Assumes input is already
* field-encoded using field_enc, and returns output that is still
* field-encoded. */
{
} else {
}
}
return res;
}
/* Converts a point P(px, py, pz) from Jacobian projective coordinates to
* affine coordinates R(rx, ry). P and R can share x and y coordinates.
* Assumes input is already field-encoded using field_enc, and returns
* output that is still field-encoded. */
{
/* if point at infinity, then set point at infinity and exit */
goto CLEANUP;
}
/* transform (px, py, pz) into (px / pz^2, py / pz^3) */
} else {
}
return res;
}
/* Checks if point P(px, py, pz) is at infinity. Uses Jacobian
* coordinates. */
{
}
/* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian
* coordinates. */
{
return MP_OKAY;
}
/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
* (qx, qy, 1). Elliptic curve points P, Q, and R can all be identical.
* Uses mixed Jacobian-affine coordinates. Assumes input is already
* field-encoded using field_enc, and returns output that is still
* field-encoded. Uses equation (2) from Brown, Hankerson, Lopez, and
* Menezes. Software Implementation of the NIST Elliptic Curves Over Prime
* Fields. */
{
MP_DIGITS(&A) = 0;
MP_DIGITS(&B) = 0;
MP_DIGITS(&C) = 0;
MP_DIGITS(&D) = 0;
/* If either P or Q is the point at infinity, then return the other
* point */
goto CLEANUP;
}
goto CLEANUP;
}
/* A = qx * pz^2, B = qy * pz^3 */
/* C = A - px, D = B - py */
/* C2 = C^2, C3 = C^3 */
/* rz = pz * C */
/* C = px * C^2 */
/* A = D^2 */
/* rx = D^2 - (C^3 + 2 * (px * C^2)) */
/* C3 = py * C^3 */
/* ry = D * (px * C^2 - rx) - py * C^3 */
mp_clear(&A);
mp_clear(&B);
mp_clear(&C);
mp_clear(&D);
return res;
}
/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses
* Jacobian coordinates.
*
* Assumes input is already field-encoded using field_enc, and returns
* output that is still field-encoded.
*
* This routine implements Point Doubling in the Jacobian Projective
* space as described in the paper "Efficient elliptic curve exponentiation
* using mixed coordinates", by H. Cohen, A Miyaji, T. Ono.
*/
{
MP_DIGITS(&M) = 0;
MP_DIGITS(&S) = 0;
goto CLEANUP;
}
/* M = 3 * px^2 + a */
/* M = 3 * (px + pz^2) * (px - pz^2) */
} else {
/* M = 3 * (px^2) + a * (pz^4) */
}
/* rz = 2 * py * pz */
/* t0 = 4 * py^2 */
} else {
}
/* S = 4 * px * py^2 = px * (2 * py)^2 */
/* rx = M^2 - 2 * S */
/* ry = M * (S - rx) - 8 * py^4 */
}
mp_clear(&M);
mp_clear(&S);
return res;
}
/* by default, this routine is unused and thus doesn't need to be compiled */
#ifdef ECL_ENABLE_GFP_PT_MUL_JAC
/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
* a, b and p are the elliptic curve coefficients and the prime that
* determines the field GFp. Elliptic curve points P and R can be
* identical. Uses mixed Jacobian-affine coordinates. Assumes input is
* already field-encoded using field_enc, and returns output that is still
* field-encoded. Uses 4-bit window method. */
{
int i, ni, d;
for (i = 0; i < 16; i++) {
}
/* initialize precomputation table */
for (i = 0; i < 16; i++) {
}
/* fill precomputation table */
for (i = 2; i < 16; i++) {
}
/* R = inf */
for (i = d - 1; i >= 0; i--) {
/* compute window ni */
ni <<= 1;
ni <<= 1;
ni <<= 1;
/* R = 2^4 * R */
/* R = R + (ni * P) */
}
/* convert result S to affine coordinates */
for (i = 0; i < 16; i++) {
}
return res;
}
#endif
/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G +
* k2 * P(x, y), where G is the generator (base point) of the group of
* points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL.
* Uses mixed Jacobian-affine coordinates. Input and output values are
* assumed to be NOT field-encoded. Uses algorithm 15 (simultaneous
* multiple point multiplication) from Brown, Hankerson, Lopez, Menezes.
* Software Implementation of the NIST Elliptic Curves over Prime Fields. */
{
const mp_int *a, *b;
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
}
}
/* if some arguments are not defined used ECPoint_mul */
}
/* initialize precomputation table */
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
}
}
/* fill precomputation table */
/* assign {k1, k2} = {a, b} such that len(a) >= len(b) */
a = k2;
b = k1;
} else {
}
} else {
a = k1;
b = k2;
} else {
}
}
/* precompute [*][0][*] */
/* precompute [*][1][*] */
for (i = 1; i < 4; i++) {
}
/* precompute [*][2][*] */
for (i = 1; i < 4; i++) {
}
/* precompute [*][3][*] */
for (i = 1; i < 4; i++) {
}
/* R = inf */
for (i = d - 1; i >= 0; i--) {
ai <<= 1;
bi <<= 1;
/* R = 2^2 * R */
/* R = R + (ai * A + bi * B) */
}
}
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
}
}
return res;
}