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