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 "ecl.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
60 |
#include "ecl-curve.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
61 |
#include "ecl-priv.h" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
62 |
#ifndef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
63 |
#include <stdlib.h> |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
64 |
#include <string.h> |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
65 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
66 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
67 |
#define CHECK(func) if ((func) == NULL) { res = 0; goto CLEANUP; } |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
68 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
69 |
/* Duplicates an ECCurveParams */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
70 |
ECCurveParams * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
71 |
ECCurveParams_dup(const ECCurveParams * params, int kmflag) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
72 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
73 |
int res = 1; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
74 |
ECCurveParams *ret = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
75 |
|
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 |
ret = (ECCurveParams *) kmem_zalloc(sizeof(ECCurveParams), 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 |
CHECK(ret = (ECCurveParams *) calloc(1, sizeof(ECCurveParams))); |
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 (params->text != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
82 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
83 |
ret->text = kmem_alloc(strlen(params->text) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
84 |
bcopy(params->text, ret->text, strlen(params->text) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
85 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
86 |
CHECK(ret->text = strdup(params->text)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
87 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
88 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
89 |
ret->field = params->field; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
90 |
ret->size = params->size; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
91 |
if (params->irr != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
92 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
93 |
ret->irr = kmem_alloc(strlen(params->irr) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
94 |
bcopy(params->irr, ret->irr, strlen(params->irr) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
95 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
96 |
CHECK(ret->irr = strdup(params->irr)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
97 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
98 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
99 |
if (params->curvea != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
100 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
101 |
ret->curvea = kmem_alloc(strlen(params->curvea) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
102 |
bcopy(params->curvea, ret->curvea, strlen(params->curvea) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
103 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
104 |
CHECK(ret->curvea = strdup(params->curvea)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
105 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
106 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
107 |
if (params->curveb != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
108 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
109 |
ret->curveb = kmem_alloc(strlen(params->curveb) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
110 |
bcopy(params->curveb, ret->curveb, strlen(params->curveb) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
111 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
112 |
CHECK(ret->curveb = strdup(params->curveb)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
113 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
114 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
115 |
if (params->genx != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
116 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
117 |
ret->genx = kmem_alloc(strlen(params->genx) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
118 |
bcopy(params->genx, ret->genx, strlen(params->genx) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
119 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
120 |
CHECK(ret->genx = strdup(params->genx)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
121 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
122 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
123 |
if (params->geny != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
124 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
125 |
ret->geny = kmem_alloc(strlen(params->geny) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
126 |
bcopy(params->geny, ret->geny, strlen(params->geny) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
127 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
128 |
CHECK(ret->geny = strdup(params->geny)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
129 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
130 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
131 |
if (params->order != NULL) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
132 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
133 |
ret->order = kmem_alloc(strlen(params->order) + 1, kmflag); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
134 |
bcopy(params->order, ret->order, strlen(params->order) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
135 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
136 |
CHECK(ret->order = strdup(params->order)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
137 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
138 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
139 |
ret->cofactor = params->cofactor; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
140 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
141 |
CLEANUP: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
142 |
if (res != 1) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
143 |
EC_FreeCurveParams(ret); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
144 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
145 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
146 |
return ret; |
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 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
149 |
#undef CHECK |
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 ECCurveParams from an ECCurveName */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
152 |
ECCurveParams * |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
153 |
EC_GetNamedCurveParams(const ECCurveName name, int kmflag) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
154 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
155 |
if ((name <= ECCurve_noName) || (ECCurve_pastLastCurve <= name) || |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
156 |
(ecCurve_map[name] == NULL)) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
157 |
return NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
158 |
} else { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
159 |
return ECCurveParams_dup(ecCurve_map[name], kmflag); |
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 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
162 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
163 |
/* Free the memory allocated (if any) to an ECCurveParams object. */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
164 |
void |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
165 |
EC_FreeCurveParams(ECCurveParams * params) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
166 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
167 |
if (params == NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
168 |
return; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
169 |
if (params->text != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
170 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
171 |
kmem_free(params->text, strlen(params->text) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
172 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
173 |
free(params->text); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
174 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
175 |
if (params->irr != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
176 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
177 |
kmem_free(params->irr, strlen(params->irr) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
178 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
179 |
free(params->irr); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
180 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
181 |
if (params->curvea != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
182 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
183 |
kmem_free(params->curvea, strlen(params->curvea) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
184 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
185 |
free(params->curvea); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
186 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
187 |
if (params->curveb != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
188 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
189 |
kmem_free(params->curveb, strlen(params->curveb) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
190 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
191 |
free(params->curveb); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
192 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
193 |
if (params->genx != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
194 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
195 |
kmem_free(params->genx, strlen(params->genx) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
196 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
197 |
free(params->genx); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
198 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
199 |
if (params->geny != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
200 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
201 |
kmem_free(params->geny, strlen(params->geny) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
202 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
203 |
free(params->geny); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
204 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
205 |
if (params->order != NULL) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
206 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
207 |
kmem_free(params->order, strlen(params->order) + 1); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
208 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
209 |
free(params->order); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
210 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
211 |
#ifdef _KERNEL |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
212 |
kmem_free(params, sizeof(ECCurveParams)); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
213 |
#else |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
214 |
free(params); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
215 |
#endif |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
216 |
} |