xref: /illumos-gate/usr/src/common/crypto/ecc/ec2.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 for binary polynomial field curves.
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 _EC2_H
46f9fbec18Smcpowers #define _EC2_H
47f9fbec18Smcpowers 
48f9fbec18Smcpowers #include "ecl-priv.h"
49f9fbec18Smcpowers 
50f9fbec18Smcpowers /* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
51f9fbec18Smcpowers mp_err ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py);
52f9fbec18Smcpowers 
53f9fbec18Smcpowers /* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
54f9fbec18Smcpowers mp_err ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py);
55f9fbec18Smcpowers 
56f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
57f9fbec18Smcpowers  * qy). Uses affine coordinates. */
58f9fbec18Smcpowers mp_err ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py,
59f9fbec18Smcpowers 						  const mp_int *qx, const mp_int *qy, mp_int *rx,
60f9fbec18Smcpowers 						  mp_int *ry, const ECGroup *group);
61f9fbec18Smcpowers 
62f9fbec18Smcpowers /* Computes R = P - Q.  Uses affine coordinates. */
63f9fbec18Smcpowers mp_err ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py,
64f9fbec18Smcpowers 						  const mp_int *qx, const mp_int *qy, mp_int *rx,
65f9fbec18Smcpowers 						  mp_int *ry, const ECGroup *group);
66f9fbec18Smcpowers 
67f9fbec18Smcpowers /* Computes R = 2P.  Uses affine coordinates. */
68f9fbec18Smcpowers mp_err ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
69f9fbec18Smcpowers 						  mp_int *ry, const ECGroup *group);
70f9fbec18Smcpowers 
71f9fbec18Smcpowers /* Validates a point on a GF2m curve. */
72f9fbec18Smcpowers mp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
73f9fbec18Smcpowers 
74f9fbec18Smcpowers /* by default, this routine is unused and thus doesn't need to be compiled */
75f9fbec18Smcpowers #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
76f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
77*c40a6cd7SToomas Soome  * a, b and p are the elliptic curve coefficients and the irreducible that
78f9fbec18Smcpowers  * determines the field GF2m.  Uses affine coordinates. */
79f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px,
80f9fbec18Smcpowers 						  const mp_int *py, mp_int *rx, mp_int *ry,
81f9fbec18Smcpowers 						  const ECGroup *group);
82f9fbec18Smcpowers #endif
83f9fbec18Smcpowers 
84f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
85*c40a6cd7SToomas Soome  * a, b and p are the elliptic curve coefficients and the irreducible that
86f9fbec18Smcpowers  * determines the field GF2m.  Uses Montgomery projective coordinates. */
87f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px,
88f9fbec18Smcpowers 						   const mp_int *py, mp_int *rx, mp_int *ry,
89f9fbec18Smcpowers 						   const ECGroup *group);
90f9fbec18Smcpowers 
91f9fbec18Smcpowers #ifdef ECL_ENABLE_GF2M_PROJ
92f9fbec18Smcpowers /* Converts a point P(px, py) from affine coordinates to projective
93f9fbec18Smcpowers  * coordinates R(rx, ry, rz). */
94f9fbec18Smcpowers mp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx,
95f9fbec18Smcpowers 						   mp_int *ry, mp_int *rz, const ECGroup *group);
96f9fbec18Smcpowers 
97f9fbec18Smcpowers /* Converts a point P(px, py, pz) from projective coordinates to affine
98f9fbec18Smcpowers  * coordinates R(rx, ry). */
99f9fbec18Smcpowers mp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py,
100f9fbec18Smcpowers 						   const mp_int *pz, mp_int *rx, mp_int *ry,
101f9fbec18Smcpowers 						   const ECGroup *group);
102f9fbec18Smcpowers 
103f9fbec18Smcpowers /* Checks if point P(px, py, pz) is at infinity.  Uses projective
104f9fbec18Smcpowers  * coordinates. */
105f9fbec18Smcpowers mp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py,
106f9fbec18Smcpowers 							  const mp_int *pz);
107f9fbec18Smcpowers 
108f9fbec18Smcpowers /* Sets P(px, py, pz) to be the point at infinity.  Uses projective
109f9fbec18Smcpowers  * coordinates. */
110f9fbec18Smcpowers mp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz);
111f9fbec18Smcpowers 
112f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
113f9fbec18Smcpowers  * (qx, qy, qz).  Uses projective coordinates. */
114f9fbec18Smcpowers mp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py,
115f9fbec18Smcpowers 						   const mp_int *pz, const mp_int *qx,
116f9fbec18Smcpowers 						   const mp_int *qy, mp_int *rx, mp_int *ry,
117f9fbec18Smcpowers 						   mp_int *rz, const ECGroup *group);
118f9fbec18Smcpowers 
119f9fbec18Smcpowers /* Computes R = 2P.  Uses projective coordinates. */
120f9fbec18Smcpowers mp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py,
121f9fbec18Smcpowers 						   const mp_int *pz, mp_int *rx, mp_int *ry,
122f9fbec18Smcpowers 						   mp_int *rz, const ECGroup *group);
123f9fbec18Smcpowers 
124f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
125f9fbec18Smcpowers  * a, b and p are the elliptic curve coefficients and the prime that
126f9fbec18Smcpowers  * determines the field GF2m.  Uses projective coordinates. */
127f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px,
128f9fbec18Smcpowers 						   const mp_int *py, mp_int *rx, mp_int *ry,
129f9fbec18Smcpowers 						   const ECGroup *group);
130f9fbec18Smcpowers #endif
131f9fbec18Smcpowers 
132f9fbec18Smcpowers #endif /* _EC2_H */
133