author | vinnie |
Tue, 11 Aug 2009 16:52:26 +0100 | |
changeset 3492 | e549cea58864 |
permissions | -rw-r--r-- |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
1 |
/* ********************************************************************* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
2 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
3 |
* Sun elects to have this file available under and governed by the |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
4 |
* Mozilla Public License Version 1.1 ("MPL") (see |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
5 |
* http://www.mozilla.org/MPL/ for full license text). For the avoidance |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
6 |
* of doubt and subject to the following, Sun also elects to allow |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
7 |
* licensees to use this file under the MPL, the GNU General Public |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
8 |
* License version 2 only or the Lesser General Public License version |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
9 |
* 2.1 only. Any references to the "GNU General Public License version 2 |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
10 |
* or later" or "GPL" in the following shall be construed to mean the |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
11 |
* GNU General Public License version 2 only. Any references to the "GNU |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
12 |
* Lesser General Public License version 2.1 or later" or "LGPL" in the |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
13 |
* following shall be construed to mean the GNU Lesser General Public |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
14 |
* License version 2.1 only. However, the following notice accompanied |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
15 |
* the original version of this file: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
16 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
17 |
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
18 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
19 |
* The contents of this file are subject to the Mozilla Public License Version |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
20 |
* 1.1 (the "License"); you may not use this file except in compliance with |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
21 |
* the License. You may obtain a copy of the License at |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
22 |
* http://www.mozilla.org/MPL/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
23 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
24 |
* Software distributed under the License is distributed on an "AS IS" basis, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
25 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
26 |
* for the specific language governing rights and limitations under the |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
27 |
* License. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
28 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
29 |
* The Original Code is the elliptic curve math library. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
30 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
31 |
* The Initial Developer of the Original Code is |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
32 |
* Sun Microsystems, Inc. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
33 |
* Portions created by the Initial Developer are Copyright (C) 2003 |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
34 |
* the Initial Developer. All Rights Reserved. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
35 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
36 |
* Contributor(s): |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
37 |
* Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
38 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
39 |
* Alternatively, the contents of this file may be used under the terms of |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
40 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
41 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
42 |
* in which case the provisions of the GPL or the LGPL are applicable instead |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
43 |
* of those above. If you wish to allow use of your version of this file only |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
44 |
* under the terms of either the GPL or the LGPL, and not to allow others to |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
45 |
* use your version of this file under the terms of the MPL, indicate your |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
46 |
* decision by deleting the provisions above and replace them with the notice |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
47 |
* and other provisions required by the GPL or the LGPL. If you do not delete |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
48 |
* the provisions above, a recipient may use your version of this file under |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
49 |
* the terms of any one of the MPL, the GPL or the LGPL. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
50 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
51 |
*********************************************************************** */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
52 |
/* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
53 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
54 |
* Use is subject to license terms. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
55 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
56 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
57 |
#pragma ident "%Z%%M% %I% %E% SMI" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
58 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
59 |
#include "mpi.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
60 |
#include "mplogic.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
61 |
#include "ecl.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
62 |
#include "ecl-priv.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
63 |
#include "ec2.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
64 |
#include "ecp.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
65 |
#ifndef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
66 |
#include <stdlib.h> |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
67 |
#include <string.h> |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
68 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
69 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
70 |
/* Allocate memory for a new ECGroup object. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
71 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
72 |
ECGroup_new(int kmflag) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
73 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
74 |
mp_err res = MP_OKAY; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
75 |
ECGroup *group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
76 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
77 |
group = (ECGroup *) kmem_alloc(sizeof(ECGroup), kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
78 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
79 |
group = (ECGroup *) malloc(sizeof(ECGroup)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
80 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
81 |
if (group == NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
82 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
83 |
group->constructed = MP_YES; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
84 |
group->meth = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
85 |
group->text = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
86 |
MP_DIGITS(&group->curvea) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
87 |
MP_DIGITS(&group->curveb) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
88 |
MP_DIGITS(&group->genx) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
89 |
MP_DIGITS(&group->geny) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
90 |
MP_DIGITS(&group->order) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
91 |
group->base_point_mul = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
92 |
group->points_mul = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
93 |
group->validate_point = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
94 |
group->extra1 = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
95 |
group->extra2 = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
96 |
group->extra_free = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
97 |
MP_CHECKOK(mp_init(&group->curvea, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
98 |
MP_CHECKOK(mp_init(&group->curveb, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
99 |
MP_CHECKOK(mp_init(&group->genx, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
100 |
MP_CHECKOK(mp_init(&group->geny, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
101 |
MP_CHECKOK(mp_init(&group->order, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
102 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
103 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
104 |
if (res != MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
105 |
ECGroup_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
106 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
107 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
108 |
return group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
109 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
110 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
111 |
/* Construct a generic ECGroup for elliptic curves over prime fields. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
112 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
113 |
ECGroup_consGFp(const mp_int *irr, const mp_int *curvea, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
114 |
const mp_int *curveb, const mp_int *genx, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
115 |
const mp_int *geny, const mp_int *order, int cofactor) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
116 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
117 |
mp_err res = MP_OKAY; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
118 |
ECGroup *group = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
119 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
120 |
group = ECGroup_new(FLAG(irr)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
121 |
if (group == NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
122 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
123 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
124 |
group->meth = GFMethod_consGFp(irr); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
125 |
if (group->meth == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
126 |
res = MP_MEM; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
127 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
128 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
129 |
MP_CHECKOK(mp_copy(curvea, &group->curvea)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
130 |
MP_CHECKOK(mp_copy(curveb, &group->curveb)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
131 |
MP_CHECKOK(mp_copy(genx, &group->genx)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
132 |
MP_CHECKOK(mp_copy(geny, &group->geny)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
133 |
MP_CHECKOK(mp_copy(order, &group->order)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
134 |
group->cofactor = cofactor; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
135 |
group->point_add = &ec_GFp_pt_add_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
136 |
group->point_sub = &ec_GFp_pt_sub_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
137 |
group->point_dbl = &ec_GFp_pt_dbl_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
138 |
group->point_mul = &ec_GFp_pt_mul_jm_wNAF; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
139 |
group->base_point_mul = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
140 |
group->points_mul = &ec_GFp_pts_mul_jac; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
141 |
group->validate_point = &ec_GFp_validate_point; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
142 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
143 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
144 |
if (res != MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
145 |
ECGroup_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
146 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
147 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
148 |
return group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
149 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
150 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
151 |
/* Construct a generic ECGroup for elliptic curves over prime fields with |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
152 |
* field arithmetic implemented in Montgomery coordinates. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
153 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
154 |
ECGroup_consGFp_mont(const mp_int *irr, const mp_int *curvea, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
155 |
const mp_int *curveb, const mp_int *genx, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
156 |
const mp_int *geny, const mp_int *order, int cofactor) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
157 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
158 |
mp_err res = MP_OKAY; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
159 |
ECGroup *group = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
160 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
161 |
group = ECGroup_new(FLAG(irr)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
162 |
if (group == NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
163 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
164 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
165 |
group->meth = GFMethod_consGFp_mont(irr); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
166 |
if (group->meth == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
167 |
res = MP_MEM; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
168 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
169 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
170 |
MP_CHECKOK(group->meth-> |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
171 |
field_enc(curvea, &group->curvea, group->meth)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
172 |
MP_CHECKOK(group->meth-> |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
173 |
field_enc(curveb, &group->curveb, group->meth)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
174 |
MP_CHECKOK(group->meth->field_enc(genx, &group->genx, group->meth)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
175 |
MP_CHECKOK(group->meth->field_enc(geny, &group->geny, group->meth)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
176 |
MP_CHECKOK(mp_copy(order, &group->order)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
177 |
group->cofactor = cofactor; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
178 |
group->point_add = &ec_GFp_pt_add_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
179 |
group->point_sub = &ec_GFp_pt_sub_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
180 |
group->point_dbl = &ec_GFp_pt_dbl_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
181 |
group->point_mul = &ec_GFp_pt_mul_jm_wNAF; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
182 |
group->base_point_mul = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
183 |
group->points_mul = &ec_GFp_pts_mul_jac; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
184 |
group->validate_point = &ec_GFp_validate_point; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
185 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
186 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
187 |
if (res != MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
188 |
ECGroup_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
189 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
190 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
191 |
return group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
192 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
193 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
194 |
#ifdef NSS_ECC_MORE_THAN_SUITE_B |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
195 |
/* Construct a generic ECGroup for elliptic curves over binary polynomial |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
196 |
* fields. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
197 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
198 |
ECGroup_consGF2m(const mp_int *irr, const unsigned int irr_arr[5], |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
199 |
const mp_int *curvea, const mp_int *curveb, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
200 |
const mp_int *genx, const mp_int *geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
201 |
const mp_int *order, int cofactor) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
202 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
203 |
mp_err res = MP_OKAY; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
204 |
ECGroup *group = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
205 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
206 |
group = ECGroup_new(FLAG(irr)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
207 |
if (group == NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
208 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
209 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
210 |
group->meth = GFMethod_consGF2m(irr, irr_arr); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
211 |
if (group->meth == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
212 |
res = MP_MEM; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
213 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
214 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
215 |
MP_CHECKOK(mp_copy(curvea, &group->curvea)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
216 |
MP_CHECKOK(mp_copy(curveb, &group->curveb)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
217 |
MP_CHECKOK(mp_copy(genx, &group->genx)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
218 |
MP_CHECKOK(mp_copy(geny, &group->geny)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
219 |
MP_CHECKOK(mp_copy(order, &group->order)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
220 |
group->cofactor = cofactor; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
221 |
group->point_add = &ec_GF2m_pt_add_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
222 |
group->point_sub = &ec_GF2m_pt_sub_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
223 |
group->point_dbl = &ec_GF2m_pt_dbl_aff; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
224 |
group->point_mul = &ec_GF2m_pt_mul_mont; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
225 |
group->base_point_mul = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
226 |
group->points_mul = &ec_pts_mul_basic; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
227 |
group->validate_point = &ec_GF2m_validate_point; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
228 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
229 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
230 |
if (res != MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
231 |
ECGroup_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
232 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
233 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
234 |
return group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
235 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
236 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
237 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
238 |
/* Construct ECGroup from hex parameters and name, if any. Called by |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
239 |
* ECGroup_fromHex and ECGroup_fromName. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
240 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
241 |
ecgroup_fromNameAndHex(const ECCurveName name, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
242 |
const ECCurveParams * params, int kmflag) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
243 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
244 |
mp_int irr, curvea, curveb, genx, geny, order; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
245 |
int bits; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
246 |
ECGroup *group = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
247 |
mp_err res = MP_OKAY; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
248 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
249 |
/* initialize values */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
250 |
MP_DIGITS(&irr) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
251 |
MP_DIGITS(&curvea) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
252 |
MP_DIGITS(&curveb) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
253 |
MP_DIGITS(&genx) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
254 |
MP_DIGITS(&geny) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
255 |
MP_DIGITS(&order) = 0; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
256 |
MP_CHECKOK(mp_init(&irr, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
257 |
MP_CHECKOK(mp_init(&curvea, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
258 |
MP_CHECKOK(mp_init(&curveb, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
259 |
MP_CHECKOK(mp_init(&genx, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
260 |
MP_CHECKOK(mp_init(&geny, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
261 |
MP_CHECKOK(mp_init(&order, kmflag)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
262 |
MP_CHECKOK(mp_read_radix(&irr, params->irr, 16)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
263 |
MP_CHECKOK(mp_read_radix(&curvea, params->curvea, 16)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
264 |
MP_CHECKOK(mp_read_radix(&curveb, params->curveb, 16)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
265 |
MP_CHECKOK(mp_read_radix(&genx, params->genx, 16)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
266 |
MP_CHECKOK(mp_read_radix(&geny, params->geny, 16)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
267 |
MP_CHECKOK(mp_read_radix(&order, params->order, 16)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
268 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
269 |
/* determine number of bits */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
270 |
bits = mpl_significant_bits(&irr) - 1; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
271 |
if (bits < MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
272 |
res = bits; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
273 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
274 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
275 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
276 |
/* determine which optimizations (if any) to use */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
277 |
if (params->field == ECField_GFp) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
278 |
#ifdef NSS_ECC_MORE_THAN_SUITE_B |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
279 |
switch (name) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
280 |
#ifdef ECL_USE_FP |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
281 |
case ECCurve_SECG_PRIME_160R1: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
282 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
283 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
284 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
285 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
286 |
MP_CHECKOK(ec_group_set_secp160r1_fp(group)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
287 |
break; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
288 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
289 |
case ECCurve_SECG_PRIME_192R1: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
290 |
#ifdef ECL_USE_FP |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
291 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
292 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
293 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
294 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
295 |
MP_CHECKOK(ec_group_set_nistp192_fp(group)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
296 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
297 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
298 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
299 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
300 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
301 |
MP_CHECKOK(ec_group_set_gfp192(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
302 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
303 |
break; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
304 |
case ECCurve_SECG_PRIME_224R1: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
305 |
#ifdef ECL_USE_FP |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
306 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
307 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
308 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
309 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
310 |
MP_CHECKOK(ec_group_set_nistp224_fp(group)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
311 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
312 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
313 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
314 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
315 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
316 |
MP_CHECKOK(ec_group_set_gfp224(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
317 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
318 |
break; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
319 |
case ECCurve_SECG_PRIME_256R1: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
320 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
321 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
322 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
323 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
324 |
MP_CHECKOK(ec_group_set_gfp256(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
325 |
break; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
326 |
case ECCurve_SECG_PRIME_521R1: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
327 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
328 |
ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
329 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
330 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
331 |
MP_CHECKOK(ec_group_set_gfp521(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
332 |
break; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
333 |
default: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
334 |
/* use generic arithmetic */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
335 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
336 |
group = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
337 |
ECGroup_consGFp_mont(&irr, &curvea, &curveb, &genx, &geny, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
338 |
&order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
339 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
340 |
#ifdef NSS_ECC_MORE_THAN_SUITE_B |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
341 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
342 |
} else if (params->field == ECField_GF2m) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
343 |
group = ECGroup_consGF2m(&irr, NULL, &curvea, &curveb, &genx, &geny, &order, params->cofactor); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
344 |
if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
345 |
if ((name == ECCurve_NIST_K163) || |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
346 |
(name == ECCurve_NIST_B163) || |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
347 |
(name == ECCurve_SECG_CHAR2_163R1)) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
348 |
MP_CHECKOK(ec_group_set_gf2m163(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
349 |
} else if ((name == ECCurve_SECG_CHAR2_193R1) || |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
350 |
(name == ECCurve_SECG_CHAR2_193R2)) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
351 |
MP_CHECKOK(ec_group_set_gf2m193(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
352 |
} else if ((name == ECCurve_NIST_K233) || |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
353 |
(name == ECCurve_NIST_B233)) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
354 |
MP_CHECKOK(ec_group_set_gf2m233(group, name)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
355 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
356 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
357 |
} else { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
358 |
res = MP_UNDEF; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
359 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
360 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
361 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
362 |
/* set name, if any */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
363 |
if ((group != NULL) && (params->text != NULL)) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
364 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
365 |
int n = strlen(params->text) + 1; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
366 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
367 |
group->text = kmem_alloc(n, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
368 |
if (group->text == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
369 |
res = MP_MEM; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
370 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
371 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
372 |
bcopy(params->text, group->text, n); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
373 |
group->text_len = n; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
374 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
375 |
group->text = strdup(params->text); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
376 |
if (group->text == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
377 |
res = MP_MEM; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
378 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
379 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
380 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
381 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
382 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
383 |
mp_clear(&irr); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
384 |
mp_clear(&curvea); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
385 |
mp_clear(&curveb); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
386 |
mp_clear(&genx); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
387 |
mp_clear(&geny); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
388 |
mp_clear(&order); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
389 |
if (res != MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
390 |
ECGroup_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
391 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
392 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
393 |
return group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
394 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
395 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
396 |
/* Construct ECGroup from hexadecimal representations of parameters. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
397 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
398 |
ECGroup_fromHex(const ECCurveParams * params, int kmflag) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
399 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
400 |
return ecgroup_fromNameAndHex(ECCurve_noName, params, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
401 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
402 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
403 |
/* Construct ECGroup from named parameters. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
404 |
ECGroup * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
405 |
ECGroup_fromName(const ECCurveName name, int kmflag) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
406 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
407 |
ECGroup *group = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
408 |
ECCurveParams *params = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
409 |
mp_err res = MP_OKAY; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
410 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
411 |
params = EC_GetNamedCurveParams(name, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
412 |
if (params == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
413 |
res = MP_UNDEF; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
414 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
415 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
416 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
417 |
/* construct actual group */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
418 |
group = ecgroup_fromNameAndHex(name, params, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
419 |
if (group == NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
420 |
res = MP_UNDEF; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
421 |
goto CLEANUP; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
422 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
423 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
424 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
425 |
EC_FreeCurveParams(params); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
426 |
if (res != MP_OKAY) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
427 |
ECGroup_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
428 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
429 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
430 |
return group; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
431 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
432 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
433 |
/* Validates an EC public key as described in Section 5.2.2 of X9.62. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
434 |
mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
435 |
mp_int *py) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
436 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
437 |
/* 1: Verify that publicValue is not the point at infinity */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
438 |
/* 2: Verify that the coordinates of publicValue are elements |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
439 |
* of the field. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
440 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
441 |
/* 3: Verify that publicValue is on the curve. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
442 |
/* 4: Verify that the order of the curve times the publicValue |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
443 |
* is the point at infinity. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
444 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
445 |
return group->validate_point(px, py, group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
446 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
447 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
448 |
/* Free the memory allocated (if any) to an ECGroup object. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
449 |
void |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
450 |
ECGroup_free(ECGroup *group) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
451 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
452 |
if (group == NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
453 |
return; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
454 |
GFMethod_free(group->meth); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
455 |
if (group->constructed == MP_NO) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
456 |
return; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
457 |
mp_clear(&group->curvea); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
458 |
mp_clear(&group->curveb); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
459 |
mp_clear(&group->genx); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
460 |
mp_clear(&group->geny); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
461 |
mp_clear(&group->order); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
462 |
if (group->text != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
463 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
464 |
kmem_free(group->text, group->text_len); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
465 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
466 |
free(group->text); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
467 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
468 |
if (group->extra_free != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
469 |
group->extra_free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
470 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
471 |
kmem_free(group, sizeof (ECGroup)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
472 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
473 |
free(group); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
474 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
475 |
} |