1 /*
2 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
3 * Use is subject to license terms.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* *********************************************************************
25 *
26 * The Original Code is the Elliptic Curve Cryptography library.
27 *
28 * The Initial Developer of the Original Code is
29 * Sun Microsystems, Inc.
30 * Portions created by the Initial Developer are Copyright (C) 2003
31 * the Initial Developer. All Rights Reserved.
32 *
33 * Contributor(s):
34 * Dr Vipul Gupta <vipul.gupta@sun.com> and
35 * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
36 *
37 * Last Modified Date from the Original Code: March 2012
38 *********************************************************************** */
39
40 #include <sys/types.h>
41
42 #ifndef _WIN32
43 #if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
44 #include <sys/systm.h>
45 #endif /* __linux__ || _ALLBSD_SOURCE */
46 #include <sys/param.h>
47 #endif /* _WIN32 */
48
49 #ifdef _KERNEL
50 #include <sys/kmem.h>
51 #else
52 #include <string.h>
53 #endif
54 #include "ec.h"
55 #include "ecl-curve.h"
56 #include "ecc_impl.h"
57
102 i++;
103 }
104
105 return item;
106 }
107
108 static SECStatus
109 gf_populate_params(ECCurveName name, ECFieldType field_type, ECParams *params,
110 int kmflag)
111 {
112 SECStatus rv = SECFailure;
113 const ECCurveParams *curveParams;
114 /* 2 ['0'+'4'] + MAX_ECKEY_LEN * 2 [x,y] * 2 [hex string] + 1 ['\0'] */
115 char genenc[3 + 2 * 2 * MAX_ECKEY_LEN];
116
117 if (((int)name < ECCurve_noName) || (name > ECCurve_pastLastCurve))
118 goto cleanup;
119 params->name = name;
120 curveParams = ecCurve_map[params->name];
121 CHECK_OK(curveParams);
122 params->fieldID.size = curveParams->size;
123 params->fieldID.type = field_type;
124 if (field_type == ec_field_GFp) {
125 CHECK_OK(hexString2SECItem(NULL, ¶ms->fieldID.u.prime,
126 curveParams->irr, kmflag));
127 } else {
128 CHECK_OK(hexString2SECItem(NULL, ¶ms->fieldID.u.poly,
129 curveParams->irr, kmflag));
130 }
131 CHECK_OK(hexString2SECItem(NULL, ¶ms->curve.a,
132 curveParams->curvea, kmflag));
133 CHECK_OK(hexString2SECItem(NULL, ¶ms->curve.b,
134 curveParams->curveb, kmflag));
135 genenc[0] = '0';
136 genenc[1] = '4';
137 genenc[2] = '\0';
138 strcat(genenc, curveParams->genx);
139 strcat(genenc, curveParams->geny);
140 CHECK_OK(hexString2SECItem(NULL, ¶ms->base, genenc, kmflag));
141 CHECK_OK(hexString2SECItem(NULL, ¶ms->order,
|
1 /*
2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
3 * Use is subject to license terms.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* *********************************************************************
25 *
26 * The Original Code is the Elliptic Curve Cryptography library.
27 *
28 * The Initial Developer of the Original Code is
29 * Sun Microsystems, Inc.
30 * Portions created by the Initial Developer are Copyright (C) 2003
31 * the Initial Developer. All Rights Reserved.
32 *
33 * Contributor(s):
34 * Dr Vipul Gupta <vipul.gupta@sun.com> and
35 * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
36 *
37 * Last Modified Date from the Original Code: Nov 2016
38 *********************************************************************** */
39
40 #include <sys/types.h>
41
42 #ifndef _WIN32
43 #if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
44 #include <sys/systm.h>
45 #endif /* __linux__ || _ALLBSD_SOURCE */
46 #include <sys/param.h>
47 #endif /* _WIN32 */
48
49 #ifdef _KERNEL
50 #include <sys/kmem.h>
51 #else
52 #include <string.h>
53 #endif
54 #include "ec.h"
55 #include "ecl-curve.h"
56 #include "ecc_impl.h"
57
102 i++;
103 }
104
105 return item;
106 }
107
108 static SECStatus
109 gf_populate_params(ECCurveName name, ECFieldType field_type, ECParams *params,
110 int kmflag)
111 {
112 SECStatus rv = SECFailure;
113 const ECCurveParams *curveParams;
114 /* 2 ['0'+'4'] + MAX_ECKEY_LEN * 2 [x,y] * 2 [hex string] + 1 ['\0'] */
115 char genenc[3 + 2 * 2 * MAX_ECKEY_LEN];
116
117 if (((int)name < ECCurve_noName) || (name > ECCurve_pastLastCurve))
118 goto cleanup;
119 params->name = name;
120 curveParams = ecCurve_map[params->name];
121 CHECK_OK(curveParams);
122 if ((strlen(curveParams->genx) + strlen(curveParams->geny)) > 2 * 2 * MAX_ECKEY_LEN) {
123 goto cleanup;
124 }
125 params->fieldID.size = curveParams->size;
126 params->fieldID.type = field_type;
127 if (field_type == ec_field_GFp) {
128 CHECK_OK(hexString2SECItem(NULL, ¶ms->fieldID.u.prime,
129 curveParams->irr, kmflag));
130 } else {
131 CHECK_OK(hexString2SECItem(NULL, ¶ms->fieldID.u.poly,
132 curveParams->irr, kmflag));
133 }
134 CHECK_OK(hexString2SECItem(NULL, ¶ms->curve.a,
135 curveParams->curvea, kmflag));
136 CHECK_OK(hexString2SECItem(NULL, ¶ms->curve.b,
137 curveParams->curveb, kmflag));
138 genenc[0] = '0';
139 genenc[1] = '4';
140 genenc[2] = '\0';
141 strcat(genenc, curveParams->genx);
142 strcat(genenc, curveParams->geny);
143 CHECK_OK(hexString2SECItem(NULL, ¶ms->base, genenc, kmflag));
144 CHECK_OK(hexString2SECItem(NULL, ¶ms->order,
|