1 /* Copyright (c) 1998,2003-2005,2008 Apple Inc.
3 * pbeTest.c - test CSP PBE-style DeriveKey().
7 * 15 May 2000 Doug Mitchell
9 * 13 Aug 1998 Doug Mitchell at NeXT
16 #include <Security/cssm.h>
19 #include "cspdlTesting.h"
21 /* we need to know a little bit about AES for this test.... */
22 #define AES_BLOCK_SIZE 16 /* bytes */
28 #define MIN_PTEXT_SIZE AES_BLOCK_SIZE /* for non-padding tests */
29 #define MAX_PTEXT_SIZE 1000
30 #define MAX_PASSWORD_SIZE 64
31 #define MAX_SALT_SIZE 32
32 #define MIN_ITER_COUNT 1000
33 #define MAX_ITER_COUNT 2000
34 #define MAX_IV_SIZE AES_BLOCK_SIZE
36 /* min values not currently exported by CSP */
37 #define APPLE_PBE_MIN_PASSWORD 8
38 #define APPLE_PBE_MIN_SALT 8
40 /* static IV for derive algorithms which don't create one */
41 CSSM_DATA staticIv
= {MAX_IV_SIZE
, (uint8
*)"someIvOrOther..."};
44 * Enumerate algs our own way to allow iteration.
46 typedef unsigned privAlg
;
50 // other unsupported for now
66 #define PBE_ALG_FIRST pbe_pbkdf2
67 #define PBE_ALG_LAST pbe_pbkdf2
68 #define ENCR_ALG_FIRST pka_ASC
69 #define ENCR_ALG_LAST pka_AES
70 #define ENCR_ALG_LAST_EXPORT pka_RC5
73 * Args passed to each test
76 CSSM_CSP_HANDLE cspHand
;
77 CSSM_ALGORITHMS keyAlg
;
78 CSSM_ALGORITHMS encrAlg
;
80 uint32 effectiveKeySizeInBits
; // 0 means not used
81 const char *keyAlgStr
;
82 CSSM_ENCRYPT_MODE encrMode
;
84 CSSM_ALGORITHMS deriveAlg
;
85 const char *deriveAlgStr
;
87 CSSM_DATA_PTR password
;
90 CSSM_BOOL useInitVector
; // encrypt needs an IV
92 CSSM_BOOL genInitVector
; // DeriveKey generates an IV
97 static void usage(char **argv
)
99 printf("usage: %s [options]\n", argv
[0]);
100 printf(" Options:\n");
101 printf(" l=loops (default=%d; 0=forever)\n", LOOPS_DEF
);
102 printf(" e(xport)\n");
103 printf(" r(epeatOnly)\n");
104 printf(" z(ero length password)\n");
105 printf(" p(ause after each loop)\n");
106 printf(" D (CSP/DL; default = bare CSP)\n");
107 printf(" q(uiet)\n");
113 * Given a privAlg value, return various associated stuff.
115 static void algInfo(privAlg alg
, // pbe_MD5, etc.
116 CSSM_ALGORITHMS
*cdsaAlg
, // CSSM_ALGID_MD5_PBE, etc. RETURNED
117 // key alg for key gen algs
118 CSSM_ALGORITHMS
*encrAlg
, // encrypt/decrypt alg for key
120 CSSM_ENCRYPT_MODE
*mode
, // RETURNED
121 CSSM_PADDING
*padding
, // RETURNED
122 CSSM_BOOL
*useInitVector
, // RETURNED, for encrypt/decrypt
123 uint32
*ivSize
, // RETURNED, in bytes
124 CSSM_BOOL
*genInitVector
, // RETURNED, for deriveKey
125 const char **algStr
) // RETURNED
127 /* default or irrelevant fields */
128 *mode
= CSSM_ALGMODE_NONE
;
129 *useInitVector
= CSSM_FALSE
;
130 *genInitVector
= CSSM_FALSE
; // DeriveKey doesn't do this now
131 *padding
= CSSM_PADDING_PKCS1
;
132 *ivSize
= 8; // thje usual size, if needed
133 *encrAlg
= CSSM_ALGID_NONE
;
137 *cdsaAlg
= CSSM_ALGID_PKCS5_PBKDF2
;
140 /* these are not supported */
143 *cdsaAlg
= CSSM_ALGID_SHA1_PBE_PKCS12
;
147 *cdsaAlg
= CSSM_ALGID_MD5_PBE
;
151 *cdsaAlg
= CSSM_ALGID_MD2_PBE
;
155 *cdsaAlg
= CSSM_ALGID_SHA1_PBE
;
159 *cdsaAlg
= CSSM_ALGID_ASC
;
164 *cdsaAlg
= *encrAlg
= CSSM_ALGID_DES
;
165 *useInitVector
= CSSM_TRUE
;
166 *mode
= CSSM_ALGMODE_CBCPadIV8
;
170 *cdsaAlg
= CSSM_ALGID_3DES_3KEY
;
171 *encrAlg
= CSSM_ALGID_3DES_3KEY_EDE
;
172 *useInitVector
= CSSM_TRUE
;
173 *mode
= CSSM_ALGMODE_CBCPadIV8
;
177 *cdsaAlg
= *encrAlg
= CSSM_ALGID_AES
;
178 *useInitVector
= CSSM_TRUE
;
179 *mode
= CSSM_ALGMODE_CBCPadIV8
;
180 *padding
= CSSM_PADDING_PKCS5
;
181 *ivSize
= AES_BLOCK_SIZE
; // per the default block size
185 *cdsaAlg
= *encrAlg
= CSSM_ALGID_RC2
;
186 *useInitVector
= CSSM_TRUE
;
187 *mode
= CSSM_ALGMODE_CBCPadIV8
;
191 *cdsaAlg
= *encrAlg
= CSSM_ALGID_RC4
;
192 /* initVector false */
193 *mode
= CSSM_ALGMODE_NONE
;
197 *cdsaAlg
= *encrAlg
= CSSM_ALGID_RC5
;
199 *mode
= CSSM_ALGMODE_CBCPadIV8
;
200 *useInitVector
= CSSM_TRUE
;
203 *cdsaAlg
= *encrAlg
= CSSM_ALGID_ASC
;
204 /* initVector false */
206 *mode
= CSSM_ALGMODE_NONE
;
209 printf("BRRZZZT! Update algInfo()!\n");
210 testError(CSSM_TRUE
);
214 /* a handy "compare two CSSM_DATAs" ditty */
215 static CSSM_BOOL
compareData(const CSSM_DATA_PTR d1
,
216 const CSSM_DATA_PTR d2
)
218 if(d1
->Length
!= d2
->Length
) {
221 if(memcmp(d1
->Data
, d2
->Data
, d1
->Length
)) {
227 /* generate random one-bit byte */
228 static uint8
randBit()
230 return 1 << genRand(0, 7);
234 * Writer debug - assertion failure when ctext[1].Data is NULL
235 * but length is nonzero
237 #define SAFE_CTEXT_ARRAY 0
240 * Encrypt ptext using specified key, IV, effectiveKeySizeInBits
242 static int encryptCom(CSSM_CSP_HANDLE cspHand
,
243 const char *testName
,
247 CSSM_ENCRYPT_MODE mode
,
248 CSSM_PADDING padding
, // CSSM_PADDING_PKCS1, etc.
249 CSSM_DATA_PTR iv
, // may be NULL
250 uint32 effectiveKeySizeInBits
, // may be 0
251 CSSM_DATA_PTR ctext
, // RETURNED
254 CSSM_CC_HANDLE cryptHand
;
256 CSSM_SIZE bytesEncrypted
;
260 CSSM_DATA safeCtext
[2];
261 safeCtext
[0] = *ctext
;
262 safeCtext
[1].Data
= NULL
;
263 safeCtext
[1].Length
= 10; // lie, but shouldn't use this!
265 // printf("+++ ctext[0] = %d:0x%x; ctext[1] = %d:0x%x\n",
266 // ctext[0].Length, ctext[0].Data,
267 // ctext[1].Length, ctext[1].Data);
270 cryptHand
= genCryptHandle(cspHand
,
277 effectiveKeySizeInBits
,
280 return testError(quiet
);
285 crtn
= CSSM_EncryptData(cryptHand
,
297 *ctext
= safeCtext
[0];
301 printError("CSSM_EncryptData", crtn
);
302 rtn
= testError(quiet
);
305 if(remData
.Length
!= 0) {
306 //printf("***WARNING: nonzero remData on encrypt!\n");
307 /* new for CDSA2 - possible remData even if we ask the CSP to
309 ctext
->Data
= (uint8
*)appRealloc(ctext
->Data
, bytesEncrypted
, NULL
);
310 memmove(ctext
->Data
+ ctext
->Length
,
312 bytesEncrypted
- ctext
->Length
);
313 appFreeCssmData(&remData
, CSSM_FALSE
);
316 ctext
->Length
= bytesEncrypted
;
319 if(CSSM_DeleteContext(cryptHand
)) {
320 printError("CSSM_DeleteContext", 0);
327 * Decrypt ctext using specified key, IV, effectiveKeySizeInBits
329 static int decryptCom(CSSM_CSP_HANDLE cspHand
,
330 const char *testName
,
334 CSSM_ENCRYPT_MODE mode
,
335 CSSM_PADDING padding
,
336 CSSM_DATA_PTR iv
, // may be NULL
337 uint32 effectiveKeySizeInBits
, // may be 0
338 CSSM_DATA_PTR ptext
, // RETURNED
341 CSSM_CC_HANDLE cryptHand
;
343 CSSM_SIZE bytesDecrypted
;
347 cryptHand
= genCryptHandle(cspHand
,
354 effectiveKeySizeInBits
,
357 return testError(quiet
);
361 crtn
= CSSM_DecryptData(cryptHand
,
369 printError("CSSM_DecryptData", crtn
);
370 rtn
= testError(quiet
);
373 if(remData
.Length
!= 0) {
374 //printf("***WARNING: nonzero remData on decrypt!\n");
375 /* new for CDSA2 - possible remData even if we ask the CSP to
377 ptext
->Data
= (uint8
*)appRealloc(ptext
->Data
, bytesDecrypted
, NULL
);
378 memmove(ptext
->Data
+ ptext
->Length
,
380 bytesDecrypted
- ptext
->Length
);
381 appFreeCssmData(&remData
, CSSM_FALSE
);
384 ptext
->Length
= bytesDecrypted
;
387 if(CSSM_DeleteContext(cryptHand
)) {
388 printError("CSSM_DeleteContext", 0);
395 * Common test portion
396 * encrypt ptext with key1, iv1
397 * encrypt ptext with key2, iv2
398 * compare 2 ctexts; expect failure;
401 #define TRAP_WRITER_ERR 1
403 static int testCommon(CSSM_CSP_HANDLE cspHand
,
404 const char *testName
,
405 CSSM_ALGORITHMS encrAlg
,
406 CSSM_ENCRYPT_MODE encrMode
,
407 CSSM_PADDING encrPad
,
408 uint32 effectiveKeySizeInBits
,
422 if(encryptCom(cspHand
,
430 effectiveKeySizeInBits
,
436 if(ctext2
.Data
!= NULL
){
437 printf("Hey! encryptCom(ptext, ctext1 modified ctext2!\n");
438 if(testError(quiet
)) {
443 if(encryptCom(cspHand
,
451 effectiveKeySizeInBits
,
456 if(compareData(&ctext1
, &ctext2
)) {
457 printf("***%s: Unexpected Data compare!\n", testName
);
458 return testError(quiet
);
460 appFreeCssmData(&ctext1
, CSSM_FALSE
);
461 appFreeCssmData(&ctext2
, CSSM_FALSE
);
466 ** inidividual tests.
468 #define KEY_LABEL1 "noLabel1"
469 #define KEY_LABEL2 "noLabel2"
470 #define KEY_LABEL_LEN strlen(KEY_LABEL1)
471 #define REPEAT_ON_ERROR 1
473 /* test repeatability - the only test here which actually decrypts */
474 static int repeatTest(testArgs
*targs
)
477 generate two keys with same params;
478 encrypt ptext with key1;
479 decrypt ctext with key2;
480 compare; expect success;
490 CSSM_BOOL gotErr
= CSSM_FALSE
;
492 if(targs
->useInitVector
) {
493 if(targs
->genInitVector
) {
498 staticIv
.Length
= targs
->ivSize
;
499 ivp1
= ivp2
= &staticIv
;
505 /* these need to be init'd regardless */
515 key1
= cspDeriveKey(targs
->cspHand
,
521 targs
->keySizeInBits
,
528 return testError(targs
->quiet
);
530 key2
= cspDeriveKey(targs
->cspHand
,
536 targs
->keySizeInBits
,
543 return testError(targs
->quiet
);
546 if(encryptCom(targs
->cspHand
,
554 targs
->effectiveKeySizeInBits
,
559 if(decryptCom(targs
->cspHand
,
567 targs
->effectiveKeySizeInBits
,
572 if(gotErr
|| !compareData(targs
->ptext
, &rptext
)) {
573 printf("***Data miscompare in repeatTest\n");
574 if(REPEAT_ON_ERROR
) {
579 printf("Repeat enc/dec (r), repeat derive (d), continue (c), abort (any)? ");
583 appFreeCssmData(&ctext
, CSSM_FALSE
);
584 appFreeCssmData(&rptext
, CSSM_FALSE
);
587 appFreeCssmData(&ctext
, CSSM_FALSE
);
588 appFreeCssmData(&rptext
, CSSM_FALSE
);
589 appFreeCssmData(&iv1
, CSSM_FALSE
);
590 appFreeCssmData(&iv2
, CSSM_FALSE
);
591 cspFreeKey(targs
->cspHand
, key1
);
592 cspFreeKey(targs
->cspHand
, key2
);
601 return testError(targs
->quiet
);
604 appFreeCssmData(&ctext
, CSSM_FALSE
);
605 appFreeCssmData(&rptext
, CSSM_FALSE
);
606 appFreeCssmData(&iv1
, CSSM_FALSE
);
607 appFreeCssmData(&iv2
, CSSM_FALSE
);
608 cspFreeKey(targs
->cspHand
, key1
);
609 cspFreeKey(targs
->cspHand
, key2
);
615 /* ensure iterCount alters key */
616 static int iterTest(testArgs
*targs
)
619 generate key1(iterCount), key2(iterCount+1);
620 encrypt ptext with key1;
621 encrypt ptext with key2;
622 compare 2 ctexts; expect failure;
630 if(targs
->useInitVector
) {
631 if(targs
->genInitVector
) {
636 staticIv
.Length
= targs
->ivSize
;
637 ivp1
= ivp2
= &staticIv
;
643 /* these need to be init'd regardless */
648 key1
= cspDeriveKey(targs
->cspHand
,
654 targs
->keySizeInBits
,
661 return testError(targs
->quiet
);
663 key2
= cspDeriveKey(targs
->cspHand
,
669 targs
->keySizeInBits
,
673 targs
->iterCount
+ 1, // the changed param
676 return testError(targs
->quiet
);
678 if(testCommon(targs
->cspHand
,
683 targs
->effectiveKeySizeInBits
,
692 appFreeCssmData(&iv1
, CSSM_FALSE
);
693 appFreeCssmData(&iv2
, CSSM_FALSE
);
694 cspFreeKey(targs
->cspHand
, key1
);
695 cspFreeKey(targs
->cspHand
, key2
);
701 /* ensure password alters key */
702 static int passwordTest(testArgs
*targs
)
705 generate key1(password), key2(munged password);
706 encrypt ptext with key1;
707 encrypt ptext with key2;
708 compare 2 ctexts; expect failure;
718 if(targs
->useInitVector
) {
719 if(targs
->genInitVector
) {
724 staticIv
.Length
= targs
->ivSize
;
725 ivp1
= ivp2
= &staticIv
;
731 /* these need to be init'd regardless */
736 key1
= cspDeriveKey(targs
->cspHand
,
742 targs
->keySizeInBits
,
749 return testError(targs
->quiet
);
752 mungeDex
= genRand(0, targs
->password
->Length
- 1);
753 mungeBits
= randBit();
754 targs
->password
->Data
[mungeDex
] ^= mungeBits
;
755 key2
= cspDeriveKey(targs
->cspHand
,
761 targs
->keySizeInBits
,
763 targs
->password
, // the changed param
768 return testError(targs
->quiet
);
770 if(testCommon(targs
->cspHand
,
775 targs
->effectiveKeySizeInBits
,
785 targs
->password
->Data
[mungeDex
] ^= mungeBits
;
786 appFreeCssmData(&iv1
, CSSM_FALSE
);
787 appFreeCssmData(&iv2
, CSSM_FALSE
);
788 cspFreeKey(targs
->cspHand
, key1
);
789 cspFreeKey(targs
->cspHand
, key2
);
795 /* ensure salt alters key */
796 static int saltTest(testArgs
*targs
)
799 generate key1(seed), key2(munged seed);
800 encrypt ptext with key1;
801 encrypt ptext with key2;
802 compare 2 ctexts; expect failure;
812 if(targs
->useInitVector
) {
813 if(targs
->genInitVector
) {
818 staticIv
.Length
= targs
->ivSize
;
819 ivp1
= ivp2
= &staticIv
;
825 /* these need to be init'd regardless */
830 key1
= cspDeriveKey(targs
->cspHand
,
836 targs
->keySizeInBits
,
843 return testError(targs
->quiet
);
846 mungeDex
= genRand(0, targs
->salt
->Length
- 1);
847 mungeBits
= randBit();
848 targs
->salt
->Data
[mungeDex
] ^= mungeBits
;
849 key2
= cspDeriveKey(targs
->cspHand
,
855 targs
->keySizeInBits
,
858 targs
->salt
, // the changed param
862 return testError(targs
->quiet
);
864 if(testCommon(targs
->cspHand
,
869 targs
->effectiveKeySizeInBits
,
879 targs
->salt
->Data
[mungeDex
] ^= mungeBits
;
880 appFreeCssmData(&iv1
, CSSM_FALSE
);
881 appFreeCssmData(&iv2
, CSSM_FALSE
);
882 cspFreeKey(targs
->cspHand
, key1
);
883 cspFreeKey(targs
->cspHand
, key2
);
889 /* ensure initVector alters ctext. This isn't testing PBE per se, but
890 * it's a handy place to verify this function. */
891 static int initVectTest(testArgs
*targs
)
895 encrypt ptext with key1 and initVector;
896 encrypt ptext with key1 and munged initVector;
897 compare 2 ctexts; expect failure;
905 if(targs
->genInitVector
) {
912 key1
= cspDeriveKey(targs
->cspHand
,
918 targs
->keySizeInBits
,
925 return testError(targs
->quiet
);
928 /* get munged copy of iv */
929 iv2
.Data
= (uint8
*)CSSM_MALLOC(iv1
.Length
);
930 iv2
.Length
= iv1
.Length
;
931 memmove(iv2
.Data
, iv1
.Data
, iv1
.Length
);
932 mungeDex
= genRand(0, iv1
.Length
- 1);
933 mungeBits
= randBit();
934 iv2
.Data
[mungeDex
] ^= mungeBits
;
935 if(testCommon(targs
->cspHand
,
940 targs
->effectiveKeySizeInBits
,
945 &iv2
, // the changed param
949 if(targs
->genInitVector
) {
950 appFreeCssmData(&iv1
, CSSM_FALSE
);
952 appFreeCssmData(&iv2
, CSSM_FALSE
);
953 cspFreeKey(targs
->cspHand
, key1
);
959 /* only one algorithm supported */
960 /* ensure deriveAlg alters key */
961 static int deriveAlgTest(testArgs
*targs
)
964 generate key1(deriveAlg), key2(some other deriveAlg);
965 encrypt ptext with key1;
966 encrypt ptext with key2;
967 compare 2 ctexts; expect failure;
977 if(targs
->useInitVector
) {
978 if(targs
->genInitVector
) {
983 staticIv
.Length
= targs
->ivSize
;
984 ivp1
= ivp2
= &staticIv
;
991 /* these need to be init'd regardless */
996 key1
= cspDeriveKey(targs
->cspHand
,
1001 CSSM_KEYUSE_ENCRYPT
,
1002 targs
->keySizeInBits
,
1009 return testError(quiet
);
1012 /* munge deriveAlg */
1013 switch(targs
->deriveAlg
) {
1014 case CSSM_ALGID_MD5_PBE
:
1015 mungeAlg
= CSSM_ALGID_MD2_PBE
;
1017 case CSSM_ALGID_MD2_PBE
:
1018 mungeAlg
= CSSM_ALGID_SHA1_PBE
;
1020 case CSSM_ALGID_SHA1_PBE
:
1021 mungeAlg
= CSSM_ALGID_SHA1_PBE_PKCS12
;
1023 case CSSM_ALGID_SHA1_PBE_PKCS12
:
1024 mungeAlg
= CSSM_ALGID_MD5_PBE
;
1027 printf("BRRRZZZT! Update deriveAlgTest()!\n");
1028 return testError(quiet
);
1030 key2
= cspDeriveKey(targs
->cspHand
,
1031 mungeAlg
, // the changed param
1035 CSSM_KEYUSE_ENCRYPT
,
1036 targs
->keySizeInBits
,
1038 targs
->password
, // the changed param
1043 return testError(quiet
);
1045 if(testCommon(targs
->cspHand
,
1050 targs
->effectiveKeySizeInBits
,
1059 appFreeCssmData(&iv1
, CSSM_FALSE
);
1060 appFreeCssmData(&iv2
, CSSM_FALSE
);
1061 cspFreeKey(targs
->cspHand
, key1
);
1062 cspFreeKey(targs
->cspHand
, key2
);
1069 int main(int argc
, char **argv
)
1080 privAlg lastEncrAlg
;
1083 CSSM_BOOL refKeysOnly
= CSSM_FALSE
;
1087 * User-spec'd params
1089 unsigned loops
= LOOPS_DEF
;
1090 CSSM_BOOL quiet
= CSSM_FALSE
;
1091 CSSM_BOOL doPause
= CSSM_FALSE
;
1092 CSSM_BOOL doExport
= CSSM_FALSE
;
1093 CSSM_BOOL repeatOnly
= CSSM_FALSE
;
1094 CSSM_BOOL bareCsp
= CSSM_TRUE
;
1095 CSSM_BOOL zeroLenPassword
= CSSM_FALSE
;
1098 argc
= ccommand(&argv
);
1100 for(arg
=1; arg
<argc
; arg
++) {
1104 loops
= atoi(&argp
[2]);
1110 bareCsp
= CSSM_FALSE
;
1111 #if CSPDL_ALL_KEYS_ARE_REF
1112 refKeysOnly
= CSSM_TRUE
;
1116 doPause
= CSSM_TRUE
;
1119 doExport
= CSSM_TRUE
;
1122 repeatOnly
= CSSM_TRUE
;
1125 zeroLenPassword
= CSSM_TRUE
;
1133 /* statically allocate ptext, password and seed; data and length
1134 * change in test loop */
1135 pwd
.Data
= (uint8
*)CSSM_MALLOC(MAX_PASSWORD_SIZE
);
1136 ptext
.Data
= (uint8
*)CSSM_MALLOC(MAX_PTEXT_SIZE
);
1137 salt
.Data
= (uint8
*)CSSM_MALLOC(MAX_SALT_SIZE
);
1138 printf("Starting pbeTest; args: ");
1139 for(i
=1; i
<argc
; i
++) {
1140 printf("%s ", argv
[i
]);
1143 targs
.cspHand
= cspDlDbStartup(bareCsp
, NULL
);
1144 if(targs
.cspHand
== 0) {
1147 targs
.ptext
= &ptext
;
1148 targs
.password
= &pwd
;
1150 targs
.quiet
= quiet
;
1152 lastEncrAlg
= ENCR_ALG_LAST_EXPORT
;
1155 lastEncrAlg
= ENCR_ALG_LAST
;
1157 for(loop
=1; ; loop
++) {
1159 printf("...loop %d\n", loop
);
1161 /* change once per outer loop */
1162 simpleGenData(&ptext
, MIN_PTEXT_SIZE
, MAX_PTEXT_SIZE
);
1163 if(zeroLenPassword
) {
1164 pwd
.Length
= 0; // fixed
1167 simpleGenData(&pwd
, APPLE_PBE_MIN_PASSWORD
, MAX_PASSWORD_SIZE
);
1169 simpleGenData(&salt
, APPLE_PBE_MIN_SALT
, MAX_SALT_SIZE
);
1170 targs
.iterCount
= genRand(MIN_ITER_COUNT
, MAX_ITER_COUNT
);
1172 targs
.useRefKey
= CSSM_TRUE
;
1175 targs
.useRefKey
= (loop
& 1) ? CSSM_FALSE
: CSSM_TRUE
;
1178 for(encrAlg
=ENCR_ALG_FIRST
; encrAlg
<=lastEncrAlg
; encrAlg
++) {
1179 /* Cook up encryption-related args */
1185 &targs
.useInitVector
,
1187 &fooBool
, // genInitVector
1189 /* random key size */
1190 targs
.effectiveKeySizeInBits
= randKeySizeBits(targs
.keyAlg
, OT_Encrypt
);
1191 targs
.keySizeInBits
= (targs
.effectiveKeySizeInBits
+ 7) & ~7;
1192 if(targs
.keySizeInBits
== targs
.effectiveKeySizeInBits
) {
1193 /* same size, ignore effective */
1194 targs
.effectiveKeySizeInBits
= 0;
1197 printf(" ...Encrypt alg %s keySizeInBits %u effectKeySize %u\n",
1198 targs
.keyAlgStr
, (unsigned)targs
.keySizeInBits
,
1199 (unsigned)targs
.effectiveKeySizeInBits
);
1201 for(pbeAlg
=PBE_ALG_FIRST
; pbeAlg
<=PBE_ALG_LAST
; pbeAlg
++) {
1202 /* Cook up pbe-related args */
1209 &fooBool
, // useInitVector
1211 &targs
.genInitVector
,
1212 &targs
.deriveAlgStr
);
1214 printf(" ...PBE alg %s\n", targs
.deriveAlgStr
);
1216 /* grind thru the tests */
1217 if(repeatTest(&targs
)) {
1224 if(iterTest(&targs
)) {
1229 // not supported yet
1230 if(deriveAlgTest(&targs
)) {
1235 if(!zeroLenPassword
) {
1236 /* won't work with zero length password */
1237 if(passwordTest(&targs
)) {
1242 if(saltTest(&targs
)) {
1246 if(targs
.useInitVector
) {
1247 if(initVectTest(&targs
)) {
1255 if(testError(quiet
)) {
1259 if(loops
&& (loop
== loops
)) {
1265 CSSM_ModuleDetach(targs
.cspHand
);
1266 if(!quiet
&& (rtn
== 0)) {
1267 printf("%s test complete\n", argv
[0]);