/*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* 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
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Sun elects to use this software under the MPL license.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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;
}