/*
* 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
/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */
{
return MP_YES;
} else {
return MP_NO;
}
}
/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */
{
return MP_OKAY;
}
/* Computes R = P + Q based on IEEE P1363 A.10.1. Elliptic curve points P,
* Q, and R can all be identical. Uses affine coordinates. Assumes input
* is already field-encoded using field_enc, and returns output that is
* still field-encoded. */
{
/* if P = inf, then R = Q */
goto CLEANUP;
}
/* if Q = inf, then R = P */
goto CLEANUP;
}
/* if px != qx, then lambda = (py-qy) / (px-qx) */
} else {
/* if py != qy or qy = 0, then R = inf */
goto CLEANUP;
}
/* lambda = (3qx^2+a) / (2qy) */
}
}
}
/* rx = lambda^2 - px - qx */
/* ry = (x1-x2) * lambda - y1 */
return res;
}
/* Computes R = P - Q. Elliptic curve points P, Q, and R can all be
* identical. Uses affine coordinates. Assumes input is already
* field-encoded using field_enc, and returns output that is still
* field-encoded. */
{
/* nqy = -qy */
return res;
}
/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses
* affine coordinates. Assumes input is already field-encoded using
* field_enc, and returns output that is still field-encoded. */
{
}
/* by default, this routine is unused and thus doesn't need to be compiled */
#ifdef ECL_ENABLE_GFP_PT_MUL_AFF
/* Computes R = nP based on IEEE P1363 A.10.3. Elliptic curve points P and
* R can be identical. Uses affine coordinates. Assumes input is already
* field-encoded using field_enc, and returns output that is still
* field-encoded. */
{
MP_DIGITS(&k) = 0;
MP_CHECKOK(mp_init(&k));
/* if n = 0 then r = inf */
if (mp_cmp_z(n) == 0) {
goto CLEANUP;
}
/* Q = P, k = n */
MP_CHECKOK(mp_copy(n, &k));
/* if n < 0 then Q = -Q, k = -k */
if (mp_cmp_z(n) < 0) {
MP_CHECKOK(mp_neg(&k, &k));
}
#ifdef ECL_DEBUG /* basic double and add method */
l = mpl_significant_bits(&k) - 1;
for (i = l - 1; i >= 0; i--) {
/* S = 2S */
/* if k_i = 1, then S = S + Q */
if (mpl_get_bit(&k, i) != 0) {
}
}
* standard */
/* k3 = 3 * k */
/* S = Q */
/* l = index of high order bit in binary representation of 3*k */
/* for i = l-1 downto 1 */
for (i = l - 1; i >= 1; i--) {
/* S = 2S */
b1 = MP_GET_BIT(&k, i);
/* if k3_i = 1 and k_i = 0, then S = S + Q */
/* if k3_i = 0 and k_i = 1, then S = S - Q */
}
}
#endif
/* output S */
mp_clear(&k);
return res;
}
#endif
/* Validates a point on a GFp curve. */
{
/* 1: Verify that publicValue is not the point at infinity */
goto CLEANUP;
}
/* 2: Verify that the coordinates of publicValue are elements
* of the field.
*/
goto CLEANUP;
}
/* 3: Verify that publicValue is on the curve. */
} else {
}
/* left-hand side: y^2 */
/* right-hand side: x^3 + a*x + b */
/* check LHS - RHS == 0 */
goto CLEANUP;
}
/* 4: Verify that the order of the curve times the publicValue
* is the point at infinity.
*/
goto CLEANUP;
}
return res;
}