1*f9fbec18Smcpowers /* 2*f9fbec18Smcpowers * ***** BEGIN LICENSE BLOCK ***** 3*f9fbec18Smcpowers * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4*f9fbec18Smcpowers * 5*f9fbec18Smcpowers * The contents of this file are subject to the Mozilla Public License Version 6*f9fbec18Smcpowers * 1.1 (the "License"); you may not use this file except in compliance with 7*f9fbec18Smcpowers * the License. You may obtain a copy of the License at 8*f9fbec18Smcpowers * http://www.mozilla.org/MPL/ 9*f9fbec18Smcpowers * 10*f9fbec18Smcpowers * Software distributed under the License is distributed on an "AS IS" basis, 11*f9fbec18Smcpowers * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12*f9fbec18Smcpowers * for the specific language governing rights and limitations under the 13*f9fbec18Smcpowers * License. 14*f9fbec18Smcpowers * 15*f9fbec18Smcpowers * The Original Code is the elliptic curve math library. 16*f9fbec18Smcpowers * 17*f9fbec18Smcpowers * The Initial Developer of the Original Code is 18*f9fbec18Smcpowers * Sun Microsystems, Inc. 19*f9fbec18Smcpowers * Portions created by the Initial Developer are Copyright (C) 2003 20*f9fbec18Smcpowers * the Initial Developer. All Rights Reserved. 21*f9fbec18Smcpowers * 22*f9fbec18Smcpowers * Contributor(s): 23*f9fbec18Smcpowers * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories 24*f9fbec18Smcpowers * 25*f9fbec18Smcpowers * Alternatively, the contents of this file may be used under the terms of 26*f9fbec18Smcpowers * either the GNU General Public License Version 2 or later (the "GPL"), or 27*f9fbec18Smcpowers * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28*f9fbec18Smcpowers * in which case the provisions of the GPL or the LGPL are applicable instead 29*f9fbec18Smcpowers * of those above. If you wish to allow use of your version of this file only 30*f9fbec18Smcpowers * under the terms of either the GPL or the LGPL, and not to allow others to 31*f9fbec18Smcpowers * use your version of this file under the terms of the MPL, indicate your 32*f9fbec18Smcpowers * decision by deleting the provisions above and replace them with the notice 33*f9fbec18Smcpowers * and other provisions required by the GPL or the LGPL. If you do not delete 34*f9fbec18Smcpowers * the provisions above, a recipient may use your version of this file under 35*f9fbec18Smcpowers * the terms of any one of the MPL, the GPL or the LGPL. 36*f9fbec18Smcpowers * 37*f9fbec18Smcpowers * ***** END LICENSE BLOCK ***** */ 38*f9fbec18Smcpowers /* 39*f9fbec18Smcpowers * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 40*f9fbec18Smcpowers * Use is subject to license terms. 41*f9fbec18Smcpowers * 42*f9fbec18Smcpowers * Sun elects to use this software under the MPL license. 43*f9fbec18Smcpowers */ 44*f9fbec18Smcpowers 45*f9fbec18Smcpowers #ifndef _ECL_H 46*f9fbec18Smcpowers #define _ECL_H 47*f9fbec18Smcpowers 48*f9fbec18Smcpowers #pragma ident "%Z%%M% %I% %E% SMI" 49*f9fbec18Smcpowers 50*f9fbec18Smcpowers /* Although this is not an exported header file, code which uses elliptic 51*f9fbec18Smcpowers * curve point operations will need to include it. */ 52*f9fbec18Smcpowers 53*f9fbec18Smcpowers #include "ecl-exp.h" 54*f9fbec18Smcpowers #include "mpi.h" 55*f9fbec18Smcpowers 56*f9fbec18Smcpowers struct ECGroupStr; 57*f9fbec18Smcpowers typedef struct ECGroupStr ECGroup; 58*f9fbec18Smcpowers 59*f9fbec18Smcpowers /* Construct ECGroup from hexadecimal representations of parameters. */ 60*f9fbec18Smcpowers ECGroup *ECGroup_fromHex(const ECCurveParams * params, int kmflag); 61*f9fbec18Smcpowers 62*f9fbec18Smcpowers /* Construct ECGroup from named parameters. */ 63*f9fbec18Smcpowers ECGroup *ECGroup_fromName(const ECCurveName name, int kmflag); 64*f9fbec18Smcpowers 65*f9fbec18Smcpowers /* Free an allocated ECGroup. */ 66*f9fbec18Smcpowers void ECGroup_free(ECGroup *group); 67*f9fbec18Smcpowers 68*f9fbec18Smcpowers /* Construct ECCurveParams from an ECCurveName */ 69*f9fbec18Smcpowers ECCurveParams *EC_GetNamedCurveParams(const ECCurveName name, int kmflag); 70*f9fbec18Smcpowers 71*f9fbec18Smcpowers /* Duplicates an ECCurveParams */ 72*f9fbec18Smcpowers ECCurveParams *ECCurveParams_dup(const ECCurveParams * params, int kmflag); 73*f9fbec18Smcpowers 74*f9fbec18Smcpowers /* Free an allocated ECCurveParams */ 75*f9fbec18Smcpowers void EC_FreeCurveParams(ECCurveParams * params); 76*f9fbec18Smcpowers 77*f9fbec18Smcpowers /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k * P(x, 78*f9fbec18Smcpowers * y). If x, y = NULL, then P is assumed to be the generator (base point) 79*f9fbec18Smcpowers * of the group of points on the elliptic curve. Input and output values 80*f9fbec18Smcpowers * are assumed to be NOT field-encoded. */ 81*f9fbec18Smcpowers mp_err ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px, 82*f9fbec18Smcpowers const mp_int *py, mp_int *qx, mp_int *qy); 83*f9fbec18Smcpowers 84*f9fbec18Smcpowers /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k1 * G + 85*f9fbec18Smcpowers * k2 * P(x, y), where G is the generator (base point) of the group of 86*f9fbec18Smcpowers * points on the elliptic curve. Input and output values are assumed to 87*f9fbec18Smcpowers * be NOT field-encoded. */ 88*f9fbec18Smcpowers mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1, 89*f9fbec18Smcpowers const mp_int *k2, const mp_int *px, const mp_int *py, 90*f9fbec18Smcpowers mp_int *qx, mp_int *qy); 91*f9fbec18Smcpowers 92*f9fbec18Smcpowers /* Validates an EC public key as described in Section 5.2.2 of X9.62. 93*f9fbec18Smcpowers * Returns MP_YES if the public key is valid, MP_NO if the public key 94*f9fbec18Smcpowers * is invalid, or an error code if the validation could not be 95*f9fbec18Smcpowers * performed. */ 96*f9fbec18Smcpowers mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const 97*f9fbec18Smcpowers mp_int *py); 98*f9fbec18Smcpowers 99*f9fbec18Smcpowers #endif /* _ECL_H */ 100