/*
* ***** 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):
* Stephen Fung <fungstep@hotmail.com>, Sun Microsystems Laboratories
*
* 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 "ecl-priv.h"
#include "mplogic.h"
#ifndef _KERNEL
#include <stdlib.h>
#endif
/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses
* Modified Jacobian coordinates.
*
* Assumes input is already field-encoded using field_enc, and returns
* output that is still field-encoded.
*
*/
{
M = &scratch[2];
S = &scratch[3];
#if MAX_SCRATCH < 4
#error "Scratch array defined too small "
#endif
/* Check for point at infinity */
/* Set r = pt at infinity by setting rz = 0 */
goto CLEANUP;
}
/* M = 3 (px^2) + a*(pz^4) */
/* rz = 2 * py * pz */
/* t0 = 2y^2 , t1 = 8y^4 */
/* S = 4 * px * py^2 = 2 * px * t0 */
/* rx = M^2 - 2S */
/* ry = M * (S - rx) - t1 */
/* ra*z^4 = 2*t1*(apz4) */
return res;
}
/* 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 Modified_Jacobian-affine coordinates. Assumes input is
* already field-encoded using field_enc, and returns output that is still
* field-encoded. */
{
A = &scratch[0];
B = &scratch[1];
C = &scratch[2];
D = &scratch[3];
#if MAX_SCRATCH < 6
#error "Scratch array defined too small "
#endif
/* 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 */
/* raz4 = a * rz^4 */
return res;
}
/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic
* curve points P and R can be identical. Uses mixed Modified-Jacobian
* co-ordinates for doubling and Chudnovsky Jacobian coordinates for
* additions. Assumes input is already field-encoded using field_enc, and
* returns output that is still field-encoded. Uses 5-bit window NAF
* method (algorithm 11) for scalar-point multiplication from Brown,
* Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic
* Curves Over Prime Fields. */
{
int i, orderBitSize;
for (i = 0; i < 16; i++) {
}
for (i = 0; i < MAX_SCRATCH; i++) {
}
/* initialize precomputation table */
for (i = 0; i < 16; i++) {
}
for (i = 0; i < MAX_SCRATCH; i++) {
}
/* Set out[8] = P */
/* Set (tpx, tpy) = 2P */
group));
/* Set 3P, 5P, ..., 15P */
for (i = 8; i < 15; i++) {
group));
}
/* Set -15P, -13P, ..., -P */
for (i = 0; i < 8; i++) {
}
/* R = inf */
/* Allocate memory for NAF */
#ifdef _KERNEL
#else
goto CLEANUP;
}
#endif
/* Compute 5NAF */
/* wNAF method */
for (i = orderBitSize; i >= 0; i--) {
/* R = 2R */
if (naf[i] != 0) {
}
}
/* convert result S to affine coordinates */
for (i = 0; i < MAX_SCRATCH; i++) {
}
for (i = 0; i < 16; i++) {
}
#ifdef _KERNEL
#else
#endif
return res;
}