ec2_proj.c revision f9fbec18f5b458b560ecf45d3db8e8bd56bf6942
/*
* ***** 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 binary polynomial 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.
*
* 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 "ec2.h"
#include "mplogic.h"
#include "mp_gf2m.h"
#ifndef _KERNEL
#include <stdlib.h>
#endif
#ifdef ECL_DEBUG
#include <assert.h>
#endif
/* by default, these routines are unused and thus don't need to be compiled */
#ifdef ECL_ENABLE_GF2M_PROJ
/* Converts a point P(px, py) from affine coordinates to projective
* coordinates R(rx, ry, rz). Assumes input is already field-encoded using
* field_enc, and returns output that is still field-encoded. */
{
}
return res;
}
/* Converts a point P(px, py, pz) from 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, py / pz^2) */
} else {
}
return res;
}
/* Checks if point P(px, py, pz) is at infinity. Uses projective
* coordinates. */
{
}
/* Sets P(px, py, pz) to be the point at infinity. Uses projective
* 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 projective-affine coordinates. Assumes input is already
* field-encoded using field_enc, and returns output that is still
* field-encoded. Uses equation (3) from Hankerson, Hernandez, Menezes.
* Software Implementation of Elliptic Curve Cryptography Over Binary
* Fields. */
{
mp_int A, B, C, D, E, F, G;
/* If either P or Q is the point at infinity, then return the other
* point */
}
}
MP_DIGITS(&A) = 0;
MP_DIGITS(&B) = 0;
MP_DIGITS(&C) = 0;
MP_DIGITS(&D) = 0;
MP_DIGITS(&E) = 0;
MP_DIGITS(&F) = 0;
MP_DIGITS(&G) = 0;
MP_CHECKOK(mp_init(&A));
MP_CHECKOK(mp_init(&B));
MP_CHECKOK(mp_init(&C));
MP_CHECKOK(mp_init(&D));
MP_CHECKOK(mp_init(&E));
MP_CHECKOK(mp_init(&F));
MP_CHECKOK(mp_init(&G));
/* D = pz^2 */
/* A = qy * pz^2 + py */
/* B = qx * pz + px */
/* C = pz * B */
/* D = B^2 * (C + a * pz^2) (using E as a temporary variable) */
/* rz = C^2 */
/* E = A * C */
/* rx = A^2 + D + E */
/* F = rx + qx * rz */
/* G = rx + qy * rz */
/* ry = E * F + rz * G (using G as a temporary variable) */
mp_clear(&A);
mp_clear(&B);
mp_clear(&C);
mp_clear(&D);
mp_clear(&E);
mp_clear(&F);
mp_clear(&G);
return res;
}
/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses
* projective coordinates.
*
* Assumes input is already field-encoded using field_enc, and returns
* output that is still field-encoded.
*
* Uses equation (3) from Hankerson, Hernandez, Menezes. Software
* Implementation of Elliptic Curve Cryptography Over Binary Fields.
*/
{
}
/* t0 = px^2 */
/* t1 = pz^2 */
/* rz = px^2 * pz^2 */
/* t0 = px^4 */
/* t1 = b * pz^4 */
/* rx = px^4 + b * pz^4 */
/* ry = b * pz^4 * rz + rx * (a * rz + py^2 + b * pz^4) */
/* t0 = a * rz */
/* t1 = b * pz^4 * rz */
return res;
}
/* 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 GF2m. Elliptic curve points P and R can be
* identical. Uses mixed projective-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;
/* initialize precomputation table */
t = precomp_arr;
for (i = 0; i < 16; i++) {
/* x co-ord */
*t = 0;
/* y co-ord */
*t = 0;
}
/* 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 */
return res;
}
#endif