Back to index

lightning-sunbird  0.9+nobinonly
ecl.h
Go to the documentation of this file.
00001 /* 
00002  * ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the elliptic curve math library.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Sun Microsystems, Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /* Although this is not an exported header file, code which uses elliptic
00040  * curve point operations will need to include it. */
00041 
00042 #ifndef __ecl_h_
00043 #define __ecl_h_
00044 
00045 #include "ecl-exp.h"
00046 #include "mpi.h"
00047 
00048 struct ECGroupStr;
00049 typedef struct ECGroupStr ECGroup;
00050 
00051 /* Construct ECGroup from hexadecimal representations of parameters. */
00052 ECGroup *ECGroup_fromHex(const ECCurveParams * params);
00053 
00054 /* Construct ECGroup from named parameters. */
00055 ECGroup *ECGroup_fromName(const ECCurveName name);
00056 
00057 /* Free an allocated ECGroup. */
00058 void ECGroup_free(ECGroup *group);
00059 
00060 /* Construct ECCurveParams from an ECCurveName */
00061 ECCurveParams *EC_GetNamedCurveParams(const ECCurveName name);
00062 
00063 /* Duplicates an ECCurveParams */
00064 ECCurveParams *ECCurveParams_dup(const ECCurveParams * params);
00065 
00066 /* Free an allocated ECCurveParams */
00067 void EC_FreeCurveParams(ECCurveParams * params);
00068 
00069 /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k * P(x, 
00070  * y).  If x, y = NULL, then P is assumed to be the generator (base point) 
00071  * of the group of points on the elliptic curve. Input and output values
00072  * are assumed to be NOT field-encoded. */
00073 mp_err ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px,
00074                                const mp_int *py, mp_int *qx, mp_int *qy);
00075 
00076 /* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k1 * G + 
00077  * k2 * P(x, y), where G is the generator (base point) of the group of
00078  * points on the elliptic curve. Input and output values are assumed to
00079  * be NOT field-encoded. */
00080 mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1,
00081                                    const mp_int *k2, const mp_int *px, const mp_int *py,
00082                                    mp_int *qx, mp_int *qy);
00083 
00084 /* Validates an EC public key as described in Section 5.2.2 of X9.62.
00085  * Returns MP_YES if the public key is valid, MP_NO if the public key
00086  * is invalid, or an error code if the validation could not be
00087  * performed. */
00088 mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const 
00089                                    mp_int *py);
00090 
00091 #endif                                           /* __ecl_h_ */