OLD | NEW |
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 #ifdef NSS_ENABLE_ECC | 5 #ifdef NSS_ENABLE_ECC |
6 | 6 |
7 #include "blapi.h" | 7 #include "blapi.h" |
8 #include "secoid.h" | 8 #include "secoid.h" |
9 #include "secitem.h" | 9 #include "secitem.h" |
10 #include "secerr.h" | 10 #include "secerr.h" |
11 #include "ec.h" | 11 #include "ec.h" |
12 #include "ecl-curve.h" | 12 #include "ecl-curve.h" |
13 | 13 |
14 #define CHECK_OK(func) if (func == NULL) goto cleanup | 14 #define CHECK_OK(func) if (func == NULL) goto cleanup |
15 #define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup | 15 #define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup |
16 | 16 |
17 /* | 17 /* |
18 * Initializes a SECItem from a hexadecimal string | 18 * Initializes a SECItem from a hexadecimal string |
19 * | 19 * |
20 * Warning: This function ignores leading 00's, so any leading 00's | 20 * Warning: This function ignores leading 00's, so any leading 00's |
21 * in the hexadecimal string must be optional. | 21 * in the hexadecimal string must be optional. |
22 */ | 22 */ |
23 static SECItem * | 23 static SECItem * |
24 hexString2SECItem(PRArenaPool *arena, SECItem *item, const char *str) | 24 hexString2SECItem(PLArenaPool *arena, SECItem *item, const char *str) |
25 { | 25 { |
26 int i = 0; | 26 int i = 0; |
27 int byteval = 0; | 27 int byteval = 0; |
28 int tmp = PORT_Strlen(str); | 28 int tmp = PORT_Strlen(str); |
29 | 29 |
30 if ((tmp % 2) != 0) return NULL; | 30 if ((tmp % 2) != 0) return NULL; |
31 | 31 |
32 /* skip leading 00's unless the hex string is "00" */ | 32 /* skip leading 00's unless the hex string is "00" */ |
33 while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) { | 33 while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) { |
34 str += 2; | 34 str += 2; |
(...skipping 21 matching lines...) Expand all Loading... |
56 } | 56 } |
57 i++; | 57 i++; |
58 } | 58 } |
59 | 59 |
60 return item; | 60 return item; |
61 } | 61 } |
62 | 62 |
63 /* Copy all of the fields from srcParams into dstParams | 63 /* Copy all of the fields from srcParams into dstParams |
64 */ | 64 */ |
65 SECStatus | 65 SECStatus |
66 EC_CopyParams(PRArenaPool *arena, ECParams *dstParams, | 66 EC_CopyParams(PLArenaPool *arena, ECParams *dstParams, |
67 const ECParams *srcParams) | 67 const ECParams *srcParams) |
68 { | 68 { |
69 SECStatus rv = SECFailure; | 69 SECStatus rv = SECFailure; |
70 | 70 |
71 dstParams->arena = arena; | 71 dstParams->arena = arena; |
72 dstParams->type = srcParams->type; | 72 dstParams->type = srcParams->type; |
73 dstParams->fieldID.size = srcParams->fieldID.size; | 73 dstParams->fieldID.size = srcParams->fieldID.size; |
74 dstParams->fieldID.type = srcParams->fieldID.type; | 74 dstParams->fieldID.type = srcParams->fieldID.type; |
75 if (srcParams->fieldID.type == ec_field_GFp) { | 75 if (srcParams->fieldID.type == ec_field_GFp) { |
76 CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->fieldID.u.prime, | 76 CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->fieldID.u.prime, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 curveParams->order)); | 140 curveParams->order)); |
141 params->cofactor = curveParams->cofactor; | 141 params->cofactor = curveParams->cofactor; |
142 | 142 |
143 rv = SECSuccess; | 143 rv = SECSuccess; |
144 | 144 |
145 cleanup: | 145 cleanup: |
146 return rv; | 146 return rv; |
147 } | 147 } |
148 | 148 |
149 SECStatus | 149 SECStatus |
150 EC_FillParams(PRArenaPool *arena, const SECItem *encodedParams, | 150 EC_FillParams(PLArenaPool *arena, const SECItem *encodedParams, |
151 ECParams *params) | 151 ECParams *params) |
152 { | 152 { |
153 SECStatus rv = SECFailure; | 153 SECStatus rv = SECFailure; |
154 SECOidTag tag; | 154 SECOidTag tag; |
155 SECItem oid = { siBuffer, NULL, 0}; | 155 SECItem oid = { siBuffer, NULL, 0}; |
156 | 156 |
157 #if EC_DEBUG | 157 #if EC_DEBUG |
158 int i; | 158 int i; |
159 | 159 |
160 printf("Encoded params in EC_DecodeParams: "); | 160 printf("Encoded params in EC_DecodeParams: "); |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 printf("Unrecognized curve, returning NULL params\n"); | 564 printf("Unrecognized curve, returning NULL params\n"); |
565 #endif | 565 #endif |
566 } | 566 } |
567 | 567 |
568 return rv; | 568 return rv; |
569 } | 569 } |
570 | 570 |
571 SECStatus | 571 SECStatus |
572 EC_DecodeParams(const SECItem *encodedParams, ECParams **ecparams) | 572 EC_DecodeParams(const SECItem *encodedParams, ECParams **ecparams) |
573 { | 573 { |
574 PRArenaPool *arena; | 574 PLArenaPool *arena; |
575 ECParams *params; | 575 ECParams *params; |
576 SECStatus rv = SECFailure; | 576 SECStatus rv = SECFailure; |
577 | 577 |
578 /* Initialize an arena for the ECParams structure */ | 578 /* Initialize an arena for the ECParams structure */ |
579 if (!(arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE))) | 579 if (!(arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE))) |
580 return SECFailure; | 580 return SECFailure; |
581 | 581 |
582 params = (ECParams *)PORT_ArenaZAlloc(arena, sizeof(ECParams)); | 582 params = (ECParams *)PORT_ArenaZAlloc(arena, sizeof(ECParams)); |
583 if (!params) { | 583 if (!params) { |
584 PORT_FreeArena(arena, PR_TRUE); | 584 PORT_FreeArena(arena, PR_TRUE); |
(...skipping 12 matching lines...) Expand all Loading... |
597 if (rv == SECFailure) { | 597 if (rv == SECFailure) { |
598 PORT_FreeArena(arena, PR_TRUE); | 598 PORT_FreeArena(arena, PR_TRUE); |
599 return SECFailure; | 599 return SECFailure; |
600 } else { | 600 } else { |
601 *ecparams = params;; | 601 *ecparams = params;; |
602 return SECSuccess; | 602 return SECSuccess; |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 #endif /* NSS_ENABLE_ECC */ | 606 #endif /* NSS_ENABLE_ECC */ |
OLD | NEW |