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