f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/*
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * ***** BEGIN LICENSE BLOCK *****
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Version: MPL 1.1/GPL 2.0/LGPL 2.1
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * The contents of this file are subject to the Mozilla Public License Version
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * 1.1 (the "License"); you may not use this file except in compliance with
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * the License. You may obtain a copy of the License at
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * http://www.mozilla.org/MPL/
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Software distributed under the License is distributed on an "AS IS" basis,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * for the specific language governing rights and limitations under the
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * License.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * The Original Code is the elliptic curve math library for binary polynomial field curves.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * The Initial Developer of the Original Code is
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Sun Microsystems, Inc.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Portions created by the Initial Developer are Copyright (C) 2003
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * the Initial Developer. All Rights Reserved.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Contributor(s):
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Alternatively, the contents of this file may be used under the terms of
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * either the GNU General Public License Version 2 or later (the "GPL"), or
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * in which case the provisions of the GPL or the LGPL are applicable instead
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * of those above. If you wish to allow use of your version of this file only
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * under the terms of either the GPL or the LGPL, and not to allow others to
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * use your version of this file under the terms of the MPL, indicate your
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * decision by deleting the provisions above and replace them with the notice
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * and other provisions required by the GPL or the LGPL. If you do not delete
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * the provisions above, a recipient may use your version of this file under
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * the terms of any one of the MPL, the GPL or the LGPL.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * ***** END LICENSE BLOCK ***** */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/*
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Use is subject to license terms.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers *
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * Sun elects to use this software under the MPL license.
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#ifndef _EC2_H
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#define _EC2_H
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#pragma ident "%Z%%M% %I% %E% SMI"
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#include "ecl-priv.h"
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * qy). Uses affine coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *qx, const mp_int *qy, mp_int *rx,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers mp_int *ry, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = P - Q. Uses affine coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *qx, const mp_int *qy, mp_int *rx,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers mp_int *ry, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = 2P. Uses affine coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers mp_int *ry, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Validates a point on a GF2m curve. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* by default, this routine is unused and thus doesn't need to be compiled */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * a, b and p are the elliptic curve coefficients and the irreducible that
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * determines the field GF2m. Uses affine coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *py, mp_int *rx, mp_int *ry,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#endif
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * a, b and p are the elliptic curve coefficients and the irreducible that
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * determines the field GF2m. Uses Montgomery projective coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *py, mp_int *rx, mp_int *ry,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#ifdef ECL_ENABLE_GF2M_PROJ
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Converts a point P(px, py) from affine coordinates to projective
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * coordinates R(rx, ry, rz). */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers mp_int *ry, mp_int *rz, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Converts a point P(px, py, pz) from projective coordinates to affine
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * coordinates R(rx, ry). */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *pz, mp_int *rx, mp_int *ry,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Checks if point P(px, py, pz) is at infinity. Uses projective
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *pz);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Sets P(px, py, pz) to be the point at infinity. Uses projective
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * (qx, qy, qz). Uses projective coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *pz, const mp_int *qx,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *qy, mp_int *rx, mp_int *ry,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers mp_int *rz, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = 2P. Uses projective coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *pz, mp_int *rx, mp_int *ry,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers mp_int *rz, const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * a, b and p are the elliptic curve coefficients and the prime that
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers * determines the field GF2m. Uses projective coordinates. */
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowersmp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const mp_int *py, mp_int *rx, mp_int *ry,
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers const ECGroup *group);
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#endif
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers
f9fbec18f5b458b560ecf45d3db8e8bd56bf6942mcpowers#endif /* _EC2_H */