4272N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 4272N/A * Use is subject to license terms. 4272N/A * This library is free software; you can redistribute it and/or 4272N/A * modify it under the terms of the GNU Lesser General Public 4272N/A * License as published by the Free Software Foundation; either 4272N/A * version 2.1 of the License, or (at your option) any later version. 4272N/A * This library is distributed in the hope that it will be useful, 4272N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 4272N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 4272N/A * Lesser General Public License for more details. 4272N/A * You should have received a copy of the GNU Lesser General Public License 4272N/A * along with this library; if not, write to the Free Software Foundation, 4272N/A * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 4272N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4272N/A/* ********************************************************************* 1674N/A * The Original Code is the elliptic curve math library for prime field curves. 1674N/A * The Initial Developer of the Original Code is 1674N/A * Portions created by the Initial Developer are Copyright (C) 2003 1674N/A * the Initial Developer. All Rights Reserved. 1674N/A * Stephen Fung <fungstep@hotmail.com>, Sun Microsystems Laboratories 1674N/A *********************************************************************** */ 1674N/A/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses 1674N/A * Modified Jacobian coordinates. 1674N/A * Assumes input is already field-encoded using field_enc, and returns 1674N/A * output that is still field-encoded. 1674N/A /* Check for point at infinity */ 1674N/A /* Set r = pt at infinity by setting rz = 0 */ 1674N/A /* M = 3 (px^2) + a*(pz^4) */ 1674N/A /* t0 = 2y^2 , t1 = 8y^4 */ 1674N/A /* S = 4 * px * py^2 = 2 * px * t0 */ 1674N/A /* ry = M * (S - rx) - t1 */ 1674N/A/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is 1674N/A * (qx, qy, 1). Elliptic curve points P, Q, and R can all be identical. 1674N/A * Uses mixed Modified_Jacobian-affine coordinates. Assumes input is 1674N/A * already field-encoded using field_enc, and returns output that is still 1674N/A /* If either P or Q is the point at infinity, then return the other 1674N/A /* A = qx * pz^2, B = qy * pz^3 */ 1674N/A /* C = A - px, D = B - py */ 1674N/A /* rx = D^2 - (C^3 + 2 * (px * C^2)) */ 1674N/A /* ry = D * (px * C^2 - rx) - py * C^3 */ 1674N/A/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic 1674N/A * curve points P and R can be identical. Uses mixed Modified-Jacobian 1674N/A * co-ordinates for doubling and Chudnovsky Jacobian coordinates for 1674N/A * additions. Assumes input is already field-encoded using field_enc, and 1674N/A * returns output that is still field-encoded. Uses 5-bit window NAF 1674N/A * method (algorithm 11) for scalar-point multiplication from Brown, 1674N/A * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic 1674N/A * Curves Over Prime Fields. */ 1674N/A /* initialize precomputation table */ 1674N/A /* Set -15P, -13P, ..., -P */ 1674N/A /* Allocate memory for NAF */ 1674N/A /* convert result S to affine coordinates */