if (mode == bltestDSA) load_file_data(arena, &pt, filename, bltestBase64Encoded); else load_file_data(arena, &pt, filename, bltestBinary);
load_file_data(arena, &pt, filename, (mode == bltestDSA) ? bltestBase64Encoded : bltestBinary);
blapi_selftest(bltestCipherMode *modes, int numModes, int inoff, int outoff,               PRBool encrypt, PRBool decrypt){    bltestCipherInfo cipherInfo;    bltestIO pt, ct;    bltestCipherMode mode;    bltestParams *params;    int i, j, nummodes;    char *modestr;    char filename[256];    PRFileDesc *file;    PRArenaPool *arena;    SECItem item;    PRBool finished;    SECStatus rv = SECSuccess, srv;    PORT_Memset(&cipherInfo, 0, sizeof(cipherInfo));    arena = PORT_NewArena(BLTEST_DEFAULT_CHUNKSIZE);    cipherInfo.arena = arena;    finished = PR_FALSE;    nummodes = (numModes == 0) ? NUMMODES : numModes;    for (i=0; i < nummodes && !finished; i++) {	if (i == bltestRC5_ECB || i == bltestRC5_CBC) continue;	if (numModes > 0)	    mode = modes[i];	else	    mode = i;	if (mode == bltestINVALID) {	    fprintf(stderr, "%s: Skipping invalid mode.\n",progName);	    continue;	}	modestr = mode_strings[mode];	cipherInfo.mode = mode;	params = &cipherInfo.params;#ifdef TRACK_BLTEST_BUG	if (mode == bltestRSA) {	    fprintf(stderr, "[%s] Self-Testing RSA\n", __bltDBG);	}#endif	/* get the number of tests in the directory */	sprintf(filename, "%s/tests/%s/%s", testdir, modestr, "numtests");	file = PR_Open(filename, PR_RDONLY, 00660);	if (!file) {	    fprintf(stderr, "%s: File %s does not exist.\n", progName,filename);	    return SECFailure;	}	rv = SECU_FileToItem(&item, file);#ifdef TRACK_BLTEST_BUG	if (mode == bltestRSA) {	    fprintf(stderr, "[%s] Loaded data from %s\n", __bltDBG, filename);	}#endif	PR_Close(file);	/* loop over the tests in the directory */	for (j=0; j<(int)(item.data[0] - '0'); j++) { /* XXX bug when > 10 */#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Executing self-test #%d\n", __bltDBG, j);	    }#endif	    sprintf(filename, "%s/tests/%s/%s%d", testdir, modestr,			      "plaintext", j);	    if (mode == bltestDSA)	    load_file_data(arena, &pt, filename, bltestBase64Encoded);	    else	    load_file_data(arena, &pt, filename, bltestBinary);	    sprintf(filename, "%s/tests/%s/%s%d", testdir, modestr,			      "ciphertext", j);	    load_file_data(arena, &ct, filename, bltestBase64Encoded);#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Loaded data for  self-test #%d\n", __bltDBG, j);	    }#endif	    get_params(arena, params, mode, j);#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Got parameters for #%d\n", __bltDBG, j);	    }#endif	    /* Forward Operation (Encrypt/Sign/Hash)	    ** Align the input buffer (plaintext) according to request	    ** then perform operation and compare to ciphertext	    */	    /* XXX for now */	    rv = SECSuccess;	    if (encrypt) {		bltestCopyIO(arena, &cipherInfo.input, &pt);		misalignBuffer(arena, &cipherInfo.input, inoff);		memset(&cipherInfo.output.buf, 0, sizeof cipherInfo.output.buf);		rv |= cipherInit(&cipherInfo, PR_TRUE);		misalignBuffer(arena, &cipherInfo.output, outoff);#ifdef TRACK_BLTEST_BUG		if (mode == bltestRSA) {		    fprintf(stderr, "[%s] Inited cipher context and buffers for #%d\n", __bltDBG, j);		}#endif		rv |= cipherDoOp(&cipherInfo);#ifdef TRACK_BLTEST_BUG		if (mode == bltestRSA) {		    fprintf(stderr, "[%s] Performed encrypt for #%d\n", __bltDBG, j);		}#endif		rv |= cipherFinish(&cipherInfo);#ifdef TRACK_BLTEST_BUG		if (mode == bltestRSA) {		    fprintf(stderr, "[%s] Finished encrypt for #%d\n", __bltDBG, j);		}#endif		rv |= verify_self_test(&cipherInfo.output, 		                       &ct, mode, PR_TRUE, 0);#ifdef TRACK_BLTEST_BUG		if (mode == bltestRSA) {		    fprintf(stderr, "[%s] Verified self-test for #%d\n", __bltDBG, j);		}#endif		/* If testing hash, only one op to test */		if (is_hashCipher(mode))		    continue;		/*if (rv) return rv;*/	    }	    if (!decrypt)		continue;	    /* XXX for now */	    rv = SECSuccess;	    /* Reverse Operation (Decrypt/Verify)	    ** Align the input buffer (ciphertext) according to request	    ** then perform operation and compare to plaintext	    */	    if (mode != bltestDSA)		bltestCopyIO(arena, &cipherInfo.input, &ct);	    else		bltestCopyIO(arena, &cipherInfo.input, &pt);	    misalignBuffer(arena, &cipherInfo.input, inoff);	    memset(&cipherInfo.output.buf, 0, sizeof cipherInfo.output.buf);	    rv |= cipherInit(&cipherInfo, PR_FALSE);	    misalignBuffer(arena, &cipherInfo.output, outoff);#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Inited cipher context and buffers for #%d\n", __bltDBG, j);	    }#endif	    srv = SECSuccess;	    srv |= cipherDoOp(&cipherInfo);#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Performed decrypt for #%d\n", __bltDBG, j);	    }#endif	    rv |= cipherFinish(&cipherInfo);#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Finished decrypt for #%d\n", __bltDBG, j);	    }#endif	    rv |= verify_self_test(&cipherInfo.output, 	                           &pt, mode, PR_FALSE, srv);#ifdef TRACK_BLTEST_BUG	    if (mode == bltestRSA) {		fprintf(stderr, "[%s] Verified self-test for #%d\n", __bltDBG, j);	    }#endif	    /*if (rv) return rv;*/	}    }    return rv;}