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 #include "plarena.h" | 5 #include "plarena.h" |
6 | 6 |
7 #include "seccomon.h" | 7 #include "seccomon.h" |
8 #include "secitem.h" | 8 #include "secitem.h" |
9 #include "secport.h" | 9 #include "secport.h" |
10 #include "hasht.h" | 10 #include "hasht.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 #define NSSPBE_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y)) | 419 #define NSSPBE_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y)) |
420 #define NSSPBE_MIN(x,y) ((x) < (y) ? (x) : (y)) | 420 #define NSSPBE_MIN(x,y) ((x) < (y) ? (x) : (y)) |
421 /* | 421 /* |
422 * This is the extended PBE function defined by the final PKCS #12 spec. | 422 * This is the extended PBE function defined by the final PKCS #12 spec. |
423 */ | 423 */ |
424 static SECItem * | 424 static SECItem * |
425 nsspkcs5_PKCS12PBE(const SECHashObject *hashObject, | 425 nsspkcs5_PKCS12PBE(const SECHashObject *hashObject, |
426 NSSPKCS5PBEParameter *pbe_param, SECItem *pwitem, | 426 NSSPKCS5PBEParameter *pbe_param, SECItem *pwitem, |
427 PBEBitGenID bitGenPurpose, unsigned int bytesNeeded) | 427 PBEBitGenID bitGenPurpose, unsigned int bytesNeeded) |
428 { | 428 { |
429 PRArenaPool *arena = NULL; | 429 PLArenaPool *arena = NULL; |
430 unsigned int SLen,PLen; | 430 unsigned int SLen,PLen; |
431 unsigned int hashLength = hashObject->length; | 431 unsigned int hashLength = hashObject->length; |
432 unsigned char *S, *P; | 432 unsigned char *S, *P; |
433 SECItem *A = NULL, B, D, I; | 433 SECItem *A = NULL, B, D, I; |
434 SECItem *salt = &pbe_param->salt; | 434 SECItem *salt = &pbe_param->salt; |
435 unsigned int c,i = 0; | 435 unsigned int c,i = 0; |
436 unsigned int hashLen; | 436 unsigned int hashLen; |
437 int iter; | 437 int iter; |
438 unsigned char *iterBuf; | 438 unsigned char *iterBuf; |
439 void *hash = NULL; | 439 void *hash = NULL; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 } | 734 } |
735 | 735 |
736 return SECSuccess; | 736 return SECSuccess; |
737 } | 737 } |
738 | 738 |
739 /* decode the algid and generate a PKCS 5 parameter from it | 739 /* decode the algid and generate a PKCS 5 parameter from it |
740 */ | 740 */ |
741 NSSPKCS5PBEParameter * | 741 NSSPKCS5PBEParameter * |
742 nsspkcs5_NewParam(SECOidTag alg, SECItem *salt, int iterator) | 742 nsspkcs5_NewParam(SECOidTag alg, SECItem *salt, int iterator) |
743 { | 743 { |
744 PRArenaPool *arena = NULL; | 744 PLArenaPool *arena = NULL; |
745 NSSPKCS5PBEParameter *pbe_param = NULL; | 745 NSSPKCS5PBEParameter *pbe_param = NULL; |
746 SECStatus rv = SECFailure; | 746 SECStatus rv = SECFailure; |
747 | 747 |
748 arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); | 748 arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); |
749 if (arena == NULL) | 749 if (arena == NULL) |
750 return NULL; | 750 return NULL; |
751 | 751 |
752 /* allocate memory for the parameter */ | 752 /* allocate memory for the parameter */ |
753 pbe_param = (NSSPKCS5PBEParameter *)PORT_ArenaZAlloc(arena, | 753 pbe_param = (NSSPKCS5PBEParameter *)PORT_ArenaZAlloc(arena, |
754 sizeof(NSSPKCS5PBEParameter)); | 754 sizeof(NSSPKCS5PBEParameter)); |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 | 1270 |
1271 /* creates a algorithm ID containing the PBE algorithm and appropriate | 1271 /* creates a algorithm ID containing the PBE algorithm and appropriate |
1272 * parameters. the required parameter is the algorithm. if salt is | 1272 * parameters. the required parameter is the algorithm. if salt is |
1273 * not specified, it is generated randomly. if IV is specified, it overrides | 1273 * not specified, it is generated randomly. if IV is specified, it overrides |
1274 * the PKCS 5 generation of the IV. | 1274 * the PKCS 5 generation of the IV. |
1275 * | 1275 * |
1276 * the returned SECAlgorithmID should be destroyed using | 1276 * the returned SECAlgorithmID should be destroyed using |
1277 * SECOID_DestroyAlgorithmID | 1277 * SECOID_DestroyAlgorithmID |
1278 */ | 1278 */ |
1279 SECAlgorithmID * | 1279 SECAlgorithmID * |
1280 nsspkcs5_CreateAlgorithmID(PRArenaPool *arena, SECOidTag algorithm, | 1280 nsspkcs5_CreateAlgorithmID(PLArenaPool *arena, SECOidTag algorithm, |
1281 NSSPKCS5PBEParameter *pbe_param) | 1281 NSSPKCS5PBEParameter *pbe_param) |
1282 { | 1282 { |
1283 SECAlgorithmID *algid, *ret_algid = NULL; | 1283 SECAlgorithmID *algid, *ret_algid = NULL; |
1284 SECItem der_param; | 1284 SECItem der_param; |
1285 nsspkcs5V2PBEParameter pkcs5v2_param; | 1285 nsspkcs5V2PBEParameter pkcs5v2_param; |
1286 | 1286 |
1287 SECStatus rv = SECFailure; | 1287 SECStatus rv = SECFailure; |
1288 void *dummy = NULL; | 1288 void *dummy = NULL; |
1289 | 1289 |
1290 if (arena == NULL) { | 1290 if (arena == NULL) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 rv = SECOID_CopyAlgorithmID(NULL, ret_algid, algid); | 1369 rv = SECOID_CopyAlgorithmID(NULL, ret_algid, algid); |
1370 if (rv != SECSuccess) { | 1370 if (rv != SECSuccess) { |
1371 SECOID_DestroyAlgorithmID(ret_algid, PR_TRUE); | 1371 SECOID_DestroyAlgorithmID(ret_algid, PR_TRUE); |
1372 ret_algid = NULL; | 1372 ret_algid = NULL; |
1373 } | 1373 } |
1374 | 1374 |
1375 loser: | 1375 loser: |
1376 | 1376 |
1377 return ret_algid; | 1377 return ret_algid; |
1378 } | 1378 } |
OLD | NEW |