Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: mozilla/security/nss/lib/freebl/ecl/ecl.c

Issue 12042100: Add an optimized 32-bit implementation of the NIST P-256 elliptic curve. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 #include "mpi.h" 5 #include "mpi.h"
6 #include "mplogic.h" 6 #include "mplogic.h"
7 #include "ecl.h" 7 #include "ecl.h"
8 #include "ecl-priv.h" 8 #include "ecl-priv.h"
9 #include "ec2.h" 9 #include "ec2.h"
10 #include "ecp.h" 10 #include "ecp.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 /* determine number of bits */ 209 /* determine number of bits */
210 bits = mpl_significant_bits(&irr) - 1; 210 bits = mpl_significant_bits(&irr) - 1;
211 if (bits < MP_OKAY) { 211 if (bits < MP_OKAY) {
212 res = bits; 212 res = bits;
213 goto CLEANUP; 213 goto CLEANUP;
214 } 214 }
215 215
216 /* determine which optimizations (if any) to use */ 216 /* determine which optimizations (if any) to use */
217 if (params->field == ECField_GFp) { 217 if (params->field == ECField_GFp) {
218 switch (name) {
218 #ifdef NSS_ECC_MORE_THAN_SUITE_B 219 #ifdef NSS_ECC_MORE_THAN_SUITE_B
219 switch (name) {
220 #ifdef ECL_USE_FP 220 #ifdef ECL_USE_FP
221 case ECCurve_SECG_PRIME_160R1: 221 case ECCurve_SECG_PRIME_160R1:
222 group = 222 group =
223 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny, 223 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny,
224 &order, params-> cofactor); 224 &order, params-> cofactor);
225 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } 225 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
226 MP_CHECKOK(ec_group_set_secp160r1_fp(group)); 226 MP_CHECKOK(ec_group_set_secp160r1_fp(group));
227 break; 227 break;
228 #endif 228 #endif
229 case ECCurve_SECG_PRIME_192R1: 229 case ECCurve_SECG_PRIME_192R1:
(...skipping 19 matching lines...) Expand all
249 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } 249 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
250 MP_CHECKOK(ec_group_set_nistp224_fp(group)); 250 MP_CHECKOK(ec_group_set_nistp224_fp(group));
251 #else 251 #else
252 group = 252 group =
253 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny, 253 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny,
254 &order, params-> cofactor); 254 &order, params-> cofactor);
255 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } 255 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
256 MP_CHECKOK(ec_group_set_gfp224(group, name)); 256 MP_CHECKOK(ec_group_set_gfp224(group, name));
257 #endif 257 #endif
258 break; 258 break;
259 case ECCurve_SECG_PRIME_256R1:
260 group =
261 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny,
262 &order, params-> cofactor);
263 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
264 MP_CHECKOK(ec_group_set_gfp256(group, name));
265 break;
266 case ECCurve_SECG_PRIME_521R1: 259 case ECCurve_SECG_PRIME_521R1:
267 group = 260 group =
268 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny, 261 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny,
269 &order, params-> cofactor); 262 &order, params-> cofactor);
270 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } 263 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
271 MP_CHECKOK(ec_group_set_gfp521(group, name)); 264 MP_CHECKOK(ec_group_set_gfp521(group, name));
272 break; 265 break;
266 #endif /* NSS_ECC_MORE_THAN_SUITE_B */
wtc 2013/01/25 02:32:49 I added a comment after this #endif to indicate th
267 case ECCurve_SECG_PRIME_256R1:
268 group =
269 ECGroup_consGFp(&irr, &curvea, &curveb, &genx, & geny,
270 &order, params-> cofactor);
271 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
272 MP_CHECKOK(ec_group_set_gfp256(group, name));
273 break;
Ryan Sleevi 2013/01/25 03:50:36 Why move this out of the MORE_THAN_SUITE_B? Is tha
agl 2013/01/25 16:04:03 P-256 is part of Suite B, no? I'm not sure why it
wtc 2013/01/27 00:11:17 In patch set 2, I eliminated the need for ecp_256.
273 default: 274 default:
274 /* use generic arithmetic */ 275 /* use generic arithmetic */
275 #endif
276 group = 276 group =
277 ECGroup_consGFp_mont(&irr, &curvea, &curveb, &ge nx, &geny, 277 ECGroup_consGFp_mont(&irr, &curvea, &curveb, &ge nx, &geny,
278 &order, params->cofactor); 278 &order, params->cofactor);
279 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } 279 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
280 }
280 #ifdef NSS_ECC_MORE_THAN_SUITE_B 281 #ifdef NSS_ECC_MORE_THAN_SUITE_B
281 }
282 } else if (params->field == ECField_GF2m) { 282 } else if (params->field == ECField_GF2m) {
283 group = ECGroup_consGF2m(&irr, NULL, &curvea, &curveb, &genx, &g eny, &order, params->cofactor); 283 group = ECGroup_consGF2m(&irr, NULL, &curvea, &curveb, &genx, &g eny, &order, params->cofactor);
284 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } 284 if (group == NULL) { res = MP_UNDEF; goto CLEANUP; }
285 if ((name == ECCurve_NIST_K163) || 285 if ((name == ECCurve_NIST_K163) ||
286 (name == ECCurve_NIST_B163) || 286 (name == ECCurve_NIST_B163) ||
287 (name == ECCurve_SECG_CHAR2_163R1)) { 287 (name == ECCurve_SECG_CHAR2_163R1)) {
288 MP_CHECKOK(ec_group_set_gf2m163(group, name)); 288 MP_CHECKOK(ec_group_set_gf2m163(group, name));
289 } else if ((name == ECCurve_SECG_CHAR2_193R1) || 289 } else if ((name == ECCurve_SECG_CHAR2_193R1) ||
290 (name == ECCurve_SECG_CHAR2_193R2)) { 290 (name == ECCurve_SECG_CHAR2_193R2)) {
291 MP_CHECKOK(ec_group_set_gf2m193(group, name)); 291 MP_CHECKOK(ec_group_set_gf2m193(group, name));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 mp_clear(&group->curveb); 386 mp_clear(&group->curveb);
387 mp_clear(&group->genx); 387 mp_clear(&group->genx);
388 mp_clear(&group->geny); 388 mp_clear(&group->geny);
389 mp_clear(&group->order); 389 mp_clear(&group->order);
390 if (group->text != NULL) 390 if (group->text != NULL)
391 free(group->text); 391 free(group->text);
392 if (group->extra_free != NULL) 392 if (group->extra_free != NULL)
393 group->extra_free(group); 393 group->extra_free(group);
394 free(group); 394 free(group);
395 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698