author | vinnie |
Mon, 30 May 2011 16:37:42 +0100 | |
changeset 9774 | 50a2b28ca54c |
parent 9035 | 1255eb81cc2f |
permissions | -rw-r--r-- |
9774
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
1 |
/* |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
2 |
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
3 |
* Use is subject to license terms. |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
4 |
* |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
5 |
* This library is free software; you can redistribute it and/or |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
6 |
* modify it under the terms of the GNU Lesser General Public |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
7 |
* License as published by the Free Software Foundation; either |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
8 |
* version 2.1 of the License, or (at your option) any later version. |
3863
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
9 |
* |
9774
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
10 |
* This library is distributed in the hope that it will be useful, |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
13 |
* Lesser General Public License for more details. |
3863
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
14 |
* |
9774
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
15 |
* You should have received a copy of the GNU Lesser General Public License |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
16 |
* along with this library; if not, write to the Free Software Foundation, |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
17 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
3863
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
18 |
* |
9774
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
21 |
* questions. |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
22 |
*/ |
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
23 |
|
50a2b28ca54c
7049173: Replace the software license for ECC native code
vinnie
parents:
9035
diff
changeset
|
24 |
/* ********************************************************************* |
3863
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
25 |
* |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
26 |
* The Original Code is the elliptic curve math library for binary polynomial field curves. |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
27 |
* |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
28 |
* The Initial Developer of the Original Code is |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
29 |
* Sun Microsystems, Inc. |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
30 |
* Portions created by the Initial Developer are Copyright (C) 2003 |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
31 |
* the Initial Developer. All Rights Reserved. |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
32 |
* |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
33 |
* Contributor(s): |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
34 |
* Sheueling Chang-Shantz <sheueling.chang@sun.com>, |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
35 |
* Stephen Fung <fungstep@hotmail.com>, and |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
36 |
* Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories. |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
37 |
* |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
38 |
*********************************************************************** */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
39 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
40 |
#include "ec2.h" |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
41 |
#include "mplogic.h" |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
42 |
#include "mp_gf2m.h" |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
43 |
#ifndef _KERNEL |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
44 |
#include <stdlib.h> |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
45 |
#endif |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
46 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
47 |
/* Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
48 |
* projective coordinates. Uses algorithm Mdouble in appendix of Lopez, J. |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
49 |
* and Dahab, R. "Fast multiplication on elliptic curves over GF(2^m) |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
50 |
* without precomputation". modified to not require precomputation of |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
51 |
* c=b^{2^{m-1}}. */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
52 |
static mp_err |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
53 |
gf2m_Mdouble(mp_int *x, mp_int *z, const ECGroup *group, int kmflag) |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
54 |
{ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
55 |
mp_err res = MP_OKAY; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
56 |
mp_int t1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
57 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
58 |
MP_DIGITS(&t1) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
59 |
MP_CHECKOK(mp_init(&t1, kmflag)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
60 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
61 |
MP_CHECKOK(group->meth->field_sqr(x, x, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
62 |
MP_CHECKOK(group->meth->field_sqr(z, &t1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
63 |
MP_CHECKOK(group->meth->field_mul(x, &t1, z, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
64 |
MP_CHECKOK(group->meth->field_sqr(x, x, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
65 |
MP_CHECKOK(group->meth->field_sqr(&t1, &t1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
66 |
MP_CHECKOK(group->meth-> |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
67 |
field_mul(&group->curveb, &t1, &t1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
68 |
MP_CHECKOK(group->meth->field_add(x, &t1, x, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
69 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
70 |
CLEANUP: |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
71 |
mp_clear(&t1); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
72 |
return res; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
73 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
74 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
75 |
/* Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
76 |
* Montgomery projective coordinates. Uses algorithm Madd in appendix of |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
77 |
* Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
78 |
* GF(2^m) without precomputation". */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
79 |
static mp_err |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
80 |
gf2m_Madd(const mp_int *x, mp_int *x1, mp_int *z1, mp_int *x2, mp_int *z2, |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
81 |
const ECGroup *group, int kmflag) |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
82 |
{ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
83 |
mp_err res = MP_OKAY; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
84 |
mp_int t1, t2; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
85 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
86 |
MP_DIGITS(&t1) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
87 |
MP_DIGITS(&t2) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
88 |
MP_CHECKOK(mp_init(&t1, kmflag)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
89 |
MP_CHECKOK(mp_init(&t2, kmflag)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
90 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
91 |
MP_CHECKOK(mp_copy(x, &t1)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
92 |
MP_CHECKOK(group->meth->field_mul(x1, z2, x1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
93 |
MP_CHECKOK(group->meth->field_mul(z1, x2, z1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
94 |
MP_CHECKOK(group->meth->field_mul(x1, z1, &t2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
95 |
MP_CHECKOK(group->meth->field_add(z1, x1, z1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
96 |
MP_CHECKOK(group->meth->field_sqr(z1, z1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
97 |
MP_CHECKOK(group->meth->field_mul(z1, &t1, x1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
98 |
MP_CHECKOK(group->meth->field_add(x1, &t2, x1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
99 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
100 |
CLEANUP: |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
101 |
mp_clear(&t1); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
102 |
mp_clear(&t2); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
103 |
return res; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
104 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
105 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
106 |
/* Compute the x, y affine coordinates from the point (x1, z1) (x2, z2) |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
107 |
* using Montgomery point multiplication algorithm Mxy() in appendix of |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
108 |
* Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
109 |
* GF(2^m) without precomputation". Returns: 0 on error 1 if return value |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
110 |
* should be the point at infinity 2 otherwise */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
111 |
static int |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
112 |
gf2m_Mxy(const mp_int *x, const mp_int *y, mp_int *x1, mp_int *z1, |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
113 |
mp_int *x2, mp_int *z2, const ECGroup *group) |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
114 |
{ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
115 |
mp_err res = MP_OKAY; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
116 |
int ret = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
117 |
mp_int t3, t4, t5; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
118 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
119 |
MP_DIGITS(&t3) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
120 |
MP_DIGITS(&t4) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
121 |
MP_DIGITS(&t5) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
122 |
MP_CHECKOK(mp_init(&t3, FLAG(x2))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
123 |
MP_CHECKOK(mp_init(&t4, FLAG(x2))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
124 |
MP_CHECKOK(mp_init(&t5, FLAG(x2))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
125 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
126 |
if (mp_cmp_z(z1) == 0) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
127 |
mp_zero(x2); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
128 |
mp_zero(z2); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
129 |
ret = 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
130 |
goto CLEANUP; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
131 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
132 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
133 |
if (mp_cmp_z(z2) == 0) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
134 |
MP_CHECKOK(mp_copy(x, x2)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
135 |
MP_CHECKOK(group->meth->field_add(x, y, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
136 |
ret = 2; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
137 |
goto CLEANUP; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
138 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
139 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
140 |
MP_CHECKOK(mp_set_int(&t5, 1)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
141 |
if (group->meth->field_enc) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
142 |
MP_CHECKOK(group->meth->field_enc(&t5, &t5, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
143 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
144 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
145 |
MP_CHECKOK(group->meth->field_mul(z1, z2, &t3, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
146 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
147 |
MP_CHECKOK(group->meth->field_mul(z1, x, z1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
148 |
MP_CHECKOK(group->meth->field_add(z1, x1, z1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
149 |
MP_CHECKOK(group->meth->field_mul(z2, x, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
150 |
MP_CHECKOK(group->meth->field_mul(z2, x1, x1, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
151 |
MP_CHECKOK(group->meth->field_add(z2, x2, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
152 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
153 |
MP_CHECKOK(group->meth->field_mul(z2, z1, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
154 |
MP_CHECKOK(group->meth->field_sqr(x, &t4, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
155 |
MP_CHECKOK(group->meth->field_add(&t4, y, &t4, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
156 |
MP_CHECKOK(group->meth->field_mul(&t4, &t3, &t4, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
157 |
MP_CHECKOK(group->meth->field_add(&t4, z2, &t4, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
158 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
159 |
MP_CHECKOK(group->meth->field_mul(&t3, x, &t3, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
160 |
MP_CHECKOK(group->meth->field_div(&t5, &t3, &t3, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
161 |
MP_CHECKOK(group->meth->field_mul(&t3, &t4, &t4, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
162 |
MP_CHECKOK(group->meth->field_mul(x1, &t3, x2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
163 |
MP_CHECKOK(group->meth->field_add(x2, x, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
164 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
165 |
MP_CHECKOK(group->meth->field_mul(z2, &t4, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
166 |
MP_CHECKOK(group->meth->field_add(z2, y, z2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
167 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
168 |
ret = 2; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
169 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
170 |
CLEANUP: |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
171 |
mp_clear(&t3); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
172 |
mp_clear(&t4); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
173 |
mp_clear(&t5); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
174 |
if (res == MP_OKAY) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
175 |
return ret; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
176 |
} else { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
177 |
return 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
178 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
179 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
180 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
181 |
/* Computes R = nP based on algorithm 2P of Lopex, J. and Dahab, R. "Fast |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
182 |
* multiplication on elliptic curves over GF(2^m) without |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
183 |
* precomputation". Elliptic curve points P and R can be identical. Uses |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
184 |
* Montgomery projective coordinates. */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
185 |
mp_err |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
186 |
ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px, const mp_int *py, |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
187 |
mp_int *rx, mp_int *ry, const ECGroup *group) |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
188 |
{ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
189 |
mp_err res = MP_OKAY; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
190 |
mp_int x1, x2, z1, z2; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
191 |
int i, j; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
192 |
mp_digit top_bit, mask; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
193 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
194 |
MP_DIGITS(&x1) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
195 |
MP_DIGITS(&x2) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
196 |
MP_DIGITS(&z1) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
197 |
MP_DIGITS(&z2) = 0; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
198 |
MP_CHECKOK(mp_init(&x1, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
199 |
MP_CHECKOK(mp_init(&x2, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
200 |
MP_CHECKOK(mp_init(&z1, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
201 |
MP_CHECKOK(mp_init(&z2, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
202 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
203 |
/* if result should be point at infinity */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
204 |
if ((mp_cmp_z(n) == 0) || (ec_GF2m_pt_is_inf_aff(px, py) == MP_YES)) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
205 |
MP_CHECKOK(ec_GF2m_pt_set_inf_aff(rx, ry)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
206 |
goto CLEANUP; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
207 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
208 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
209 |
MP_CHECKOK(mp_copy(px, &x1)); /* x1 = px */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
210 |
MP_CHECKOK(mp_set_int(&z1, 1)); /* z1 = 1 */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
211 |
MP_CHECKOK(group->meth->field_sqr(&x1, &z2, group->meth)); /* z2 = |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
212 |
* x1^2 = |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
213 |
* px^2 */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
214 |
MP_CHECKOK(group->meth->field_sqr(&z2, &x2, group->meth)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
215 |
MP_CHECKOK(group->meth->field_add(&x2, &group->curveb, &x2, group->meth)); /* x2 |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
216 |
* = |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
217 |
* px^4 |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
218 |
* + |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
219 |
* b |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
220 |
*/ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
221 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
222 |
/* find top-most bit and go one past it */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
223 |
i = MP_USED(n) - 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
224 |
j = MP_DIGIT_BIT - 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
225 |
top_bit = 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
226 |
top_bit <<= MP_DIGIT_BIT - 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
227 |
mask = top_bit; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
228 |
while (!(MP_DIGITS(n)[i] & mask)) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
229 |
mask >>= 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
230 |
j--; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
231 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
232 |
mask >>= 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
233 |
j--; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
234 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
235 |
/* if top most bit was at word break, go to next word */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
236 |
if (!mask) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
237 |
i--; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
238 |
j = MP_DIGIT_BIT - 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
239 |
mask = top_bit; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
240 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
241 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
242 |
for (; i >= 0; i--) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
243 |
for (; j >= 0; j--) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
244 |
if (MP_DIGITS(n)[i] & mask) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
245 |
MP_CHECKOK(gf2m_Madd(px, &x1, &z1, &x2, &z2, group, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
246 |
MP_CHECKOK(gf2m_Mdouble(&x2, &z2, group, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
247 |
} else { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
248 |
MP_CHECKOK(gf2m_Madd(px, &x2, &z2, &x1, &z1, group, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
249 |
MP_CHECKOK(gf2m_Mdouble(&x1, &z1, group, FLAG(n))); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
250 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
251 |
mask >>= 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
252 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
253 |
j = MP_DIGIT_BIT - 1; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
254 |
mask = top_bit; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
255 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
256 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
257 |
/* convert out of "projective" coordinates */ |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
258 |
i = gf2m_Mxy(px, py, &x1, &z1, &x2, &z2, group); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
259 |
if (i == 0) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
260 |
res = MP_BADARG; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
261 |
goto CLEANUP; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
262 |
} else if (i == 1) { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
263 |
MP_CHECKOK(ec_GF2m_pt_set_inf_aff(rx, ry)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
264 |
} else { |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
265 |
MP_CHECKOK(mp_copy(&x2, rx)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
266 |
MP_CHECKOK(mp_copy(&z2, ry)); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
267 |
} |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
268 |
|
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
269 |
CLEANUP: |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
270 |
mp_clear(&x1); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
271 |
mp_clear(&x2); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
272 |
mp_clear(&z1); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
273 |
mp_clear(&z2); |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
274 |
return res; |
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
275 |
} |