}  if (sigfile) { SECItem asciiSig; rv = SECU_FileToItem(&asciiSig, sigfile); CHECKERROR(rv, __LINE__); rv = atob(&asciiSig, &info.out); CHECKERROR(rv, __LINE__); }  if (seedfile) { SECItem asciiSeed; rv = SECU_FileToItem(&asciiSeed, seedfile); CHECKERROR(rv, __LINE__); rv = atob(&asciiSeed, &info.seed); CHECKERROR(rv, __LINE__); info.useseed = PR_TRUE; }  if (sigseedfile) { SECItem asciiSeed; rv = SECU_FileToItem(&asciiSeed, sigseedfile); CHECKERROR(rv, __LINE__); rv = atob(&asciiSeed, &info.sigseed); CHECKERROR(rv, __LINE__); info.usesigseed = PR_TRUE;
PR_Close(ifile);
int main(int argc, char **argv) {	PRFileDesc *infile, *outfile, *keyfile, *ivfile, *sigfile, *seedfile,	           *sigseedfile;	PRBool b64 = PR_TRUE;	blapitestInfo info;	blapitestCryptoFn cryptofn = NULL;	PLOptState *optstate;	PLOptStatus status;	PRBool dofips = PR_FALSE;	PRBool doselftest = PR_FALSE;	PRBool zerobuffer = PR_FALSE;	char *mode = NULL;	char *modesToTest[20];	int numModesToTest = 0;	SECStatus rv;	PORT_Memset(&info, 0, sizeof(info));	info.bufsize = 8;	info.keysize = DES_KEY_LENGTH;	info.rsapubexp = 17;	info.rounds = 10;	info.wordsize = 4;	infile=outfile=keyfile=ivfile=sigfile=seedfile=sigseedfile=NULL;	info.repetitions = 1;    progName = strrchr(argv[0], '/');    progName = progName ? progName+1 : argv[0];	optstate = 	  PL_CreateOptState(argc, argv, "DEFHSTVab:ce:g:i:o:p:k:m:t:qr:s:v:w:xyz:");	while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) {		switch (optstate->option) {		case 'D':  info.decrypt = PR_TRUE; break;		case 'E':  info.encrypt = PR_TRUE; break;		case 'F':  dofips = PR_TRUE; break;		case 'H':  info.hash = PR_TRUE; break;		case 'S':  info.sign = PR_TRUE; break;		case 'T':  doselftest = PR_TRUE; break;		case 'V':  info.verify = PR_TRUE; break;		case 'a':  b64 = PR_FALSE; break;		case 'b':  info.bufsize = PORT_Atoi(optstate->value); break;		case 'c':  info.multihash = PR_TRUE; break;		case 'e':  info.rsapubexp = PORT_Atoi(optstate->value); break;		case 'g':  info.keysize = PORT_Atoi(optstate->value); break;		case 'i':  infile  = PR_Open(optstate->value, PR_RDONLY, 00440); break;		case 'k':  keyfile = PR_Open(optstate->value, PR_RDONLY, 00440); break;		case 'm':  cryptofn = get_test_mode(optstate->value);		           mode = PL_strdup(optstate->value); 		           break;		case 'o':  outfile = PR_Open(optstate->value, PR_WRONLY|PR_CREATE_FILE,		                             00660); break;		case 'p':  info.performance = PR_TRUE; 			   info.repetitions = PORT_Atoi(optstate->value); 			   break;		case 'q':  zerobuffer = PR_TRUE; break;		case 'r':  info.rounds = PORT_Atoi(optstate->value); break;		case 's':  sigfile  = PR_Open(optstate->value, PR_RDONLY, 00440); break;		case 't':  sigseedfile=PR_Open(optstate->value, PR_RDONLY, 00440);break;		case 'w':  info.wordsize = PORT_Atoi(optstate->value); break;		case 'v':  ivfile  = PR_Open(optstate->value, PR_RDONLY, 00440); break;		case 'x':  info.useseed = PR_TRUE; break;		case 'y':  info.usesigseed = PR_TRUE; break;		case 'z':  seedfile  = PR_Open(optstate->value, PR_RDONLY,00440); break;		case '\0': modesToTest[numModesToTest++] = PL_strdup(optstate->value);		default: break;		}	}	if (doselftest) {		if (numModesToTest > 0) {			return blapi_selftest(modesToTest, numModesToTest);		} else {			return blapi_selftest(NULL, 0);		}	}	if (dofips) {		CK_RV foo = pk11_fipsPowerUpSelfTest();		PR_fprintf(PR_STDOUT, "CK_RV: %d.\n", foo);		return 0;	}	if (!info.encrypt && !info.decrypt && !info.hash && 	    !info.sign && !info.verify)		Usage();	if (!cryptofn) {		printmodes(&info);		return -1;	}	if (info.decrypt && !infile)		Usage();	RNG_RNGInit();	if (keyfile) {		SECItem asciiKey;		rv = SECU_FileToItem(&asciiKey, keyfile);		CHECKERROR(rv, __LINE__);		if (b64 || PL_strcmp(mode,"rsa")==0 || PL_strcmp(mode,"dsa")==0) {			rv = atob(&asciiKey, &info.key);		} else {			SECITEM_CopyItem(NULL, &info.key, &asciiKey);			if (info.key.data[info.key.len-1] == '\n')				info.key.len--;			}		CHECKERROR(rv, __LINE__);	}	if (ivfile) {		SECItem asciiIv;		rv = SECU_FileToItem(&asciiIv, ivfile);		CHECKERROR(rv, __LINE__);		if (b64) {			rv = atob(&asciiIv, &info.iv);		} else {			SECITEM_CopyItem(NULL, &info.iv, &asciiIv);			if (info.iv.data[info.iv.len-1] == '\n')				info.iv.len--;		}		CHECKERROR(rv, __LINE__);	}	if (infile) {		SECItem asciiFile;		rv = SECU_FileToItem(&asciiFile, infile);		CHECKERROR(rv, __LINE__);		if (b64) {			rv = atob(&asciiFile, &info.in);			CHECKERROR(rv, __LINE__);		} else {			SECITEM_CopyItem(NULL, &info.in, &asciiFile);			if (info.in.data[info.in.len-1] == '\n')				info.in.len--;		}		info.bufsize = info.in.len;	}	if (zerobuffer) {		info.in.len = info.bufsize;		info.in.data = PORT_ZAlloc(info.in.len);		infile = PR_Open("tmp.pt", PR_WRONLY|PR_CREATE_FILE, 00660);		rv = btoa_file(&info.in, infile);		CHECKERROR((rv < 0), __LINE__);	}	if (sigfile) {		SECItem asciiSig;		rv = SECU_FileToItem(&asciiSig, sigfile);		CHECKERROR(rv, __LINE__);		rv = atob(&asciiSig, &info.out);		CHECKERROR(rv, __LINE__);	}	if (seedfile) {		SECItem asciiSeed;		rv = SECU_FileToItem(&asciiSeed, seedfile);		CHECKERROR(rv, __LINE__);		rv = atob(&asciiSeed, &info.seed);		CHECKERROR(rv, __LINE__);		info.useseed = PR_TRUE;	}	if (sigseedfile) {		SECItem asciiSeed;		rv = SECU_FileToItem(&asciiSeed, sigseedfile);		CHECKERROR(rv, __LINE__);		rv = atob(&asciiSeed, &info.sigseed);		CHECKERROR(rv, __LINE__);		info.usesigseed = PR_TRUE;	}	rv = (*cryptofn)(&info);		CHECKERROR(rv, __LINE__);	if (!sigfile) {		if (!outfile)			outfile = PR_Open("tmp.out", PR_WRONLY|PR_CREATE_FILE, 00660);		rv = btoa_file(&info.out, outfile);		CHECKERROR((rv < 0), __LINE__);	}	RNG_RNGShutdown();	if (infile)		PR_Close(infile);	if (outfile)		PR_Close(outfile);	if (keyfile)		PR_Close(keyfile);	if (ivfile)		PR_Close(ivfile);	return SECSuccess;}