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

Side by Side Diff: nss/lib/pk11wrap/pk11pbe.c

Issue 16132005: Allow NSS to be built with NO_NSPR_10_SUPPORT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « nss/lib/pk11wrap/pk11pars.c ('k') | nss/lib/pk11wrap/pk11pk12.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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"
11 #include "pkcs11t.h" 11 #include "pkcs11t.h"
12 #include "sechash.h" 12 #include "sechash.h"
13 #include "secasn1.h" 13 #include "secasn1.h"
14 #include "secder.h" 14 #include "secder.h"
15 #include "secoid.h" 15 #include "secoid.h"
16 #include "secerr.h" 16 #include "secerr.h"
17 #include "secmod.h" 17 #include "secmod.h"
18 #include "pk11func.h" 18 #include "pk11func.h"
19 #include "secpkcs5.h" 19 #include "secpkcs5.h"
20 #include "secmodi.h" 20 #include "secmodi.h"
21 #include "secmodti.h" 21 #include "secmodti.h"
22 #include "pkcs11.h" 22 #include "pkcs11.h"
23 #include "pk11func.h" 23 #include "pk11func.h"
24 #include "secitem.h" 24 #include "secitem.h"
25 #include "key.h" 25 #include "key.h"
26 26
27 typedef struct SEC_PKCS5PBEParameterStr SEC_PKCS5PBEParameter; 27 typedef struct SEC_PKCS5PBEParameterStr SEC_PKCS5PBEParameter;
28 struct SEC_PKCS5PBEParameterStr { 28 struct SEC_PKCS5PBEParameterStr {
29 PRArenaPool *poolp; 29 PLArenaPool *poolp;
30 SECItem salt; /* octet string */ 30 SECItem salt; /* octet string */
31 SECItem iteration; /* integer */ 31 SECItem iteration; /* integer */
32 SECItem keyLength; /* PKCS5v2 only */ 32 SECItem keyLength; /* PKCS5v2 only */
33 SECAlgorithmID *pPrfAlgId; /* PKCS5v2 only */ 33 SECAlgorithmID *pPrfAlgId; /* PKCS5v2 only */
34 SECAlgorithmID prfAlgId; /* PKCS5v2 only */ 34 SECAlgorithmID prfAlgId; /* PKCS5v2 only */
35 }; 35 };
36 36
37 /* PKCS5 V2 has an algorithm ID for the encryption and for 37 /* PKCS5 V2 has an algorithm ID for the encryption and for
38 * the key generation. This is valid for SEC_OID_PKCS5_PBES2 38 * the key generation. This is valid for SEC_OID_PKCS5_PBES2
39 * and SEC_OID_PKCS5_PBMAC1 39 * and SEC_OID_PKCS5_PBMAC1
40 */ 40 */
41 struct sec_pkcs5V2ParameterStr { 41 struct sec_pkcs5V2ParameterStr {
42 PRArenaPool *poolp; 42 PLArenaPool *poolp;
43 SECAlgorithmID pbeAlgId; /* real pbe algorithms */ 43 SECAlgorithmID pbeAlgId; /* real pbe algorithms */
44 SECAlgorithmID cipherAlgId; /* encryption/mac */ 44 SECAlgorithmID cipherAlgId; /* encryption/mac */
45 }; 45 };
46 46
47 typedef struct sec_pkcs5V2ParameterStr sec_pkcs5V2Parameter; 47 typedef struct sec_pkcs5V2ParameterStr sec_pkcs5V2Parameter;
48 48
49 49
50 /* template for PKCS 5 PBE Parameter. This template has been expanded 50 /* template for PKCS 5 PBE Parameter. This template has been expanded
51 * based upon the additions in PKCS 12. This should eventually be moved 51 * based upon the additions in PKCS 12. This should eventually be moved
52 * if RSA updates PKCS 5. 52 * if RSA updates PKCS 5.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 return SEC_OID_UNKNOWN; 139 return SEC_OID_UNKNOWN;
140 } 140 }
141 141
142 /* 142 /*
143 * get a new PKCS5 V2 Parameter from the algorithm id. 143 * get a new PKCS5 V2 Parameter from the algorithm id.
144 * if arena is passed in, use it, otherwise create a new arena. 144 * if arena is passed in, use it, otherwise create a new arena.
145 */ 145 */
146 sec_pkcs5V2Parameter * 146 sec_pkcs5V2Parameter *
147 sec_pkcs5_v2_get_v2_param(PRArenaPool *arena, SECAlgorithmID *algid) 147 sec_pkcs5_v2_get_v2_param(PLArenaPool *arena, SECAlgorithmID *algid)
148 { 148 {
149 PRArenaPool *localArena = NULL; 149 PLArenaPool *localArena = NULL;
150 sec_pkcs5V2Parameter *pbeV2_param; 150 sec_pkcs5V2Parameter *pbeV2_param;
151 SECStatus rv; 151 SECStatus rv;
152 152
153 if (arena == NULL) { 153 if (arena == NULL) {
154 localArena = arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); 154 localArena = arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);
155 if (arena == NULL) { 155 if (arena == NULL) {
156 return NULL; 156 return NULL;
157 } 157 }
158 } 158 }
159 pbeV2_param = PORT_ArenaZNew(arena, sec_pkcs5V2Parameter); 159 pbeV2_param = PORT_ArenaZNew(arena, sec_pkcs5V2Parameter);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return SEC_OID_UNKNOWN; 306 return SEC_OID_UNKNOWN;
307 } 307 }
308 308
309 /* 309 /*
310 * get the key length in bytes from a PKCS5 PBE 310 * get the key length in bytes from a PKCS5 PBE
311 */ 311 */
312 int 312 int
313 sec_pkcs5v2_key_length(SECAlgorithmID *algid) 313 sec_pkcs5v2_key_length(SECAlgorithmID *algid)
314 { 314 {
315 SECOidTag algorithm; 315 SECOidTag algorithm;
316 PRArenaPool *arena = NULL; 316 PLArenaPool *arena = NULL;
317 SEC_PKCS5PBEParameter p5_param; 317 SEC_PKCS5PBEParameter p5_param;
318 SECStatus rv; 318 SECStatus rv;
319 int length = -1; 319 int length = -1;
320 320
321 algorithm = SECOID_GetAlgorithmTag(algid); 321 algorithm = SECOID_GetAlgorithmTag(algid);
322 /* sanity check, they should all be PBKDF2 here */ 322 /* sanity check, they should all be PBKDF2 here */
323 if (algorithm != SEC_OID_PKCS5_PBKDF2) { 323 if (algorithm != SEC_OID_PKCS5_PBKDF2) {
324 return -1; 324 return -1;
325 } 325 }
326 326
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 * sec_pkcs5_destroy_pbe_parameter or SEC_PKCS5DestroyPBEParameter. 464 * sec_pkcs5_destroy_pbe_parameter or SEC_PKCS5DestroyPBEParameter.
465 */ 465 */
466 #define DEFAULT_SALT_LENGTH 16 466 #define DEFAULT_SALT_LENGTH 16
467 static SEC_PKCS5PBEParameter * 467 static SEC_PKCS5PBEParameter *
468 sec_pkcs5_create_pbe_parameter(SECOidTag algorithm, 468 sec_pkcs5_create_pbe_parameter(SECOidTag algorithm,
469 SECItem *salt, 469 SECItem *salt,
470 int iteration, 470 int iteration,
471 int keyLength, 471 int keyLength,
472 SECOidTag prfAlg) 472 SECOidTag prfAlg)
473 { 473 {
474 PRArenaPool *poolp = NULL; 474 PLArenaPool *poolp = NULL;
475 SEC_PKCS5PBEParameter *pbe_param = NULL; 475 SEC_PKCS5PBEParameter *pbe_param = NULL;
476 SECStatus rv= SECSuccess; 476 SECStatus rv= SECSuccess;
477 void *dummy = NULL; 477 void *dummy = NULL;
478 478
479 if(iteration < 0) { 479 if(iteration < 0) {
480 return NULL; 480 return NULL;
481 } 481 }
482 482
483 poolp = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); 483 poolp = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);
484 if(poolp == NULL) 484 if(poolp == NULL)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 */ 552 */
553 SECAlgorithmID * 553 SECAlgorithmID *
554 sec_pkcs5CreateAlgorithmID(SECOidTag algorithm, 554 sec_pkcs5CreateAlgorithmID(SECOidTag algorithm,
555 SECOidTag cipherAlgorithm, 555 SECOidTag cipherAlgorithm,
556 SECOidTag prfAlg, 556 SECOidTag prfAlg,
557 SECOidTag *pPbeAlgorithm, 557 SECOidTag *pPbeAlgorithm,
558 int keyLength, 558 int keyLength,
559 SECItem *salt, 559 SECItem *salt,
560 int iteration) 560 int iteration)
561 { 561 {
562 PRArenaPool *poolp = NULL; 562 PLArenaPool *poolp = NULL;
563 SECAlgorithmID *algid, *ret_algid = NULL; 563 SECAlgorithmID *algid, *ret_algid = NULL;
564 SECOidTag pbeAlgorithm = algorithm; 564 SECOidTag pbeAlgorithm = algorithm;
565 SECItem der_param; 565 SECItem der_param;
566 void *dummy; 566 void *dummy;
567 SECStatus rv = SECFailure; 567 SECStatus rv = SECFailure;
568 SEC_PKCS5PBEParameter *pbe_param = NULL; 568 SEC_PKCS5PBEParameter *pbe_param = NULL;
569 sec_pkcs5V2Parameter pbeV2_param; 569 sec_pkcs5V2Parameter pbeV2_param;
570 570
571 if(iteration <= 0) { 571 if(iteration <= 0) {
572 return NULL; 572 return NULL;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 733
734 return ret_algid; 734 return ret_algid;
735 } 735 }
736 736
737 SECStatus 737 SECStatus
738 pbe_PK11AlgidToParam(SECAlgorithmID *algid,SECItem *mech) 738 pbe_PK11AlgidToParam(SECAlgorithmID *algid,SECItem *mech)
739 { 739 {
740 SEC_PKCS5PBEParameter p5_param; 740 SEC_PKCS5PBEParameter p5_param;
741 SECItem *salt = NULL; 741 SECItem *salt = NULL;
742 SECOidTag algorithm = SECOID_GetAlgorithmTag(algid); 742 SECOidTag algorithm = SECOID_GetAlgorithmTag(algid);
743 PRArenaPool *arena = NULL; 743 PLArenaPool *arena = NULL;
744 SECStatus rv = SECFailure; 744 SECStatus rv = SECFailure;
745 unsigned char *paramData = NULL; 745 unsigned char *paramData = NULL;
746 unsigned char *pSalt = NULL; 746 unsigned char *pSalt = NULL;
747 CK_ULONG iterations; 747 CK_ULONG iterations;
748 int paramLen = 0; 748 int paramLen = 0;
749 int iv_len; 749 int iv_len;
750 750
751 751
752 arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); 752 arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);
753 if (arena == NULL) { 753 if (arena == NULL) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 return SECFailure; 861 return SECFailure;
862 } 862 }
863 863
864 /* 864 /*
865 * public, deprecated, not valid for pkcs5 v2 865 * public, deprecated, not valid for pkcs5 v2
866 * 866 *
867 * use PK11_CreatePBEV2AlgorithmID or PK11_CreatePBEAlgorithmID to create 867 * use PK11_CreatePBEV2AlgorithmID or PK11_CreatePBEAlgorithmID to create
868 * PBE algorithmID's directly. 868 * PBE algorithmID's directly.
869 */ 869 */
870 SECStatus 870 SECStatus
871 PBE_PK11ParamToAlgid(SECOidTag algTag, SECItem *param, PRArenaPool *arena, 871 PBE_PK11ParamToAlgid(SECOidTag algTag, SECItem *param, PLArenaPool *arena,
872 SECAlgorithmID *algId) 872 SECAlgorithmID *algId)
873 { 873 {
874 CK_PBE_PARAMS *pbe_param; 874 CK_PBE_PARAMS *pbe_param;
875 SECItem pbeSalt; 875 SECItem pbeSalt;
876 SECAlgorithmID *pbeAlgID = NULL; 876 SECAlgorithmID *pbeAlgID = NULL;
877 SECStatus rv; 877 SECStatus rv;
878 878
879 if(!param || !algId) { 879 if(!param || !algId) {
880 return SECFailure; 880 return SECFailure;
881 } 881 }
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 * 1423 *
1424 * This function returns both the mechanism and the parameter for the mechanism. 1424 * This function returns both the mechanism and the parameter for the mechanism.
1425 * The caller is responsible for freeing the parameter. 1425 * The caller is responsible for freeing the parameter.
1426 */ 1426 */
1427 CK_MECHANISM_TYPE 1427 CK_MECHANISM_TYPE
1428 PK11_GetPBECryptoMechanism(SECAlgorithmID *algid, SECItem **param, 1428 PK11_GetPBECryptoMechanism(SECAlgorithmID *algid, SECItem **param,
1429 SECItem *pbe_pwd) 1429 SECItem *pbe_pwd)
1430 { 1430 {
1431 return pk11_GetPBECryptoMechanism(algid, param, pbe_pwd, PR_FALSE); 1431 return pk11_GetPBECryptoMechanism(algid, param, pbe_pwd, PR_FALSE);
1432 } 1432 }
OLDNEW
« no previous file with comments | « nss/lib/pk11wrap/pk11pars.c ('k') | nss/lib/pk11wrap/pk11pk12.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698