fips_desmovs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* ====================================================================
  2. * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * 3. All advertising materials mentioning features or use of this
  17. * software must display the following acknowledgment:
  18. * "This product includes software developed by the OpenSSL Project
  19. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  20. *
  21. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  22. * endorse or promote products derived from this software without
  23. * prior written permission. For written permission, please contact
  24. * openssl-core@openssl.org.
  25. *
  26. * 5. Products derived from this software may not be called "OpenSSL"
  27. * nor may "OpenSSL" appear in their names without prior written
  28. * permission of the OpenSSL Project.
  29. *
  30. * 6. Redistributions of any form whatsoever must retain the following
  31. * acknowledgment:
  32. * "This product includes software developed by the OpenSSL Project
  33. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  36. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46. * OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. /*---------------------------------------------
  50. NIST DES Modes of Operation Validation System
  51. Test Program
  52. Based on the AES Validation Suite, which was:
  53. Donated to OpenSSL by:
  54. V-ONE Corporation
  55. 20250 Century Blvd, Suite 300
  56. Germantown, MD 20874
  57. U.S.A.
  58. ----------------------------------------------*/
  59. #define OPENSSL_FIPSAPI
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62. #include <string.h>
  63. #include <errno.h>
  64. #include <assert.h>
  65. #include <ctype.h>
  66. #include <openssl/crypto.h>
  67. #include <openssl/des.h>
  68. #include <openssl/evp.h>
  69. #include <openssl/bn.h>
  70. #include <openssl/err.h>
  71. #include "e_os.h"
  72. #ifndef OPENSSL_FIPS
  73. int main(int argc, char *argv[])
  74. {
  75. printf("No FIPS DES support\n");
  76. return(0);
  77. }
  78. #else
  79. #include "fips_utl.h"
  80. #include <openssl/fips.h>
  81. #define DES_BLOCK_SIZE 8
  82. #define VERBOSE 0
  83. static int DESTest(EVP_CIPHER_CTX *ctx,
  84. char *amode, int akeysz, unsigned char *aKey,
  85. unsigned char *iVec,
  86. int dir, /* 0 = decrypt, 1 = encrypt */
  87. unsigned char *out, unsigned char *in, int len)
  88. {
  89. const EVP_CIPHER *cipher = NULL;
  90. if (akeysz != 192)
  91. {
  92. printf("Invalid key size: %d\n", akeysz);
  93. EXIT(1);
  94. }
  95. if (strcasecmp(amode, "CBC") == 0)
  96. cipher = EVP_des_ede3_cbc();
  97. else if (strcasecmp(amode, "ECB") == 0)
  98. cipher = EVP_des_ede3_ecb();
  99. else if (strcasecmp(amode, "CFB64") == 0)
  100. cipher = EVP_des_ede3_cfb64();
  101. else if (strncasecmp(amode, "OFB", 3) == 0)
  102. cipher = EVP_des_ede3_ofb();
  103. else if(!strcasecmp(amode,"CFB8"))
  104. cipher = EVP_des_ede3_cfb8();
  105. else if(!strcasecmp(amode,"CFB1"))
  106. cipher = EVP_des_ede3_cfb1();
  107. else
  108. {
  109. printf("Unknown mode: %s\n", amode);
  110. EXIT(1);
  111. }
  112. if (FIPS_cipherinit(ctx, cipher, aKey, iVec, dir) <= 0)
  113. return 0;
  114. if(!strcasecmp(amode,"CFB1"))
  115. M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS);
  116. FIPS_cipher(ctx, out, in, len);
  117. return 1;
  118. }
  119. #if 0
  120. static void DebugValue(char *tag, unsigned char *val, int len)
  121. {
  122. char obuf[2048];
  123. int olen;
  124. olen = bin2hex(val, len, obuf);
  125. printf("%s = %.*s\n", tag, olen, obuf);
  126. }
  127. #endif
  128. static void shiftin(unsigned char *dst,unsigned char *src,int nbits)
  129. {
  130. int n;
  131. /* move the bytes... */
  132. memmove(dst,dst+nbits/8,3*8-nbits/8);
  133. /* append new data */
  134. memcpy(dst+3*8-nbits/8,src,(nbits+7)/8);
  135. /* left shift the bits */
  136. if(nbits%8)
  137. for(n=0 ; n < 3*8 ; ++n)
  138. dst[n]=(dst[n] << (nbits%8))|(dst[n+1] >> (8-nbits%8));
  139. }
  140. /*-----------------------------------------------*/
  141. char *t_tag[2] = {"PLAINTEXT", "CIPHERTEXT"};
  142. char *t_mode[6] = {"CBC","ECB","OFB","CFB1","CFB8","CFB64"};
  143. enum Mode {CBC, ECB, OFB, CFB1, CFB8, CFB64};
  144. int Sizes[6]={64,64,64,1,8,64};
  145. static void do_mct(char *amode,
  146. int akeysz, int numkeys, unsigned char *akey,unsigned char *ivec,
  147. int dir, unsigned char *text, int len,
  148. FILE *rfp)
  149. {
  150. int i,imode;
  151. unsigned char nk[4*8]; /* longest key+8 */
  152. unsigned char text0[8];
  153. for (imode=0 ; imode < 6 ; ++imode)
  154. if(!strcmp(amode,t_mode[imode]))
  155. break;
  156. if (imode == 6)
  157. {
  158. printf("Unrecognized mode: %s\n", amode);
  159. EXIT(1);
  160. }
  161. for(i=0 ; i < 400 ; ++i)
  162. {
  163. int j;
  164. int n;
  165. int kp=akeysz/64;
  166. unsigned char old_iv[8];
  167. EVP_CIPHER_CTX ctx;
  168. FIPS_cipher_ctx_init(&ctx);
  169. fprintf(rfp,"\nCOUNT = %d\n",i);
  170. if(kp == 1)
  171. OutputValue("KEY",akey,8,rfp,0);
  172. else
  173. for(n=0 ; n < kp ; ++n)
  174. {
  175. fprintf(rfp,"KEY%d",n+1);
  176. OutputValue("",akey+n*8,8,rfp,0);
  177. }
  178. if(imode != ECB)
  179. OutputValue("IV",ivec,8,rfp,0);
  180. OutputValue(t_tag[dir^1],text,len,rfp,imode == CFB1);
  181. #if 0
  182. /* compensate for endianness */
  183. if(imode == CFB1)
  184. text[0]<<=7;
  185. #endif
  186. memcpy(text0,text,8);
  187. for(j=0 ; j < 10000 ; ++j)
  188. {
  189. unsigned char old_text[8];
  190. memcpy(old_text,text,8);
  191. if(j == 0)
  192. {
  193. memcpy(old_iv,ivec,8);
  194. DESTest(&ctx,amode,akeysz,akey,ivec,dir,text,text,len);
  195. }
  196. else
  197. {
  198. memcpy(old_iv,ctx.iv,8);
  199. FIPS_cipher(&ctx,text,text,len);
  200. }
  201. if(j == 9999)
  202. {
  203. OutputValue(t_tag[dir],text,len,rfp,imode == CFB1);
  204. /* memcpy(ivec,text,8); */
  205. }
  206. /* DebugValue("iv",ctx.iv,8); */
  207. /* accumulate material for the next key */
  208. shiftin(nk,text,Sizes[imode]);
  209. /* DebugValue("nk",nk,24);*/
  210. if((dir && (imode == CFB1 || imode == CFB8 || imode == CFB64
  211. || imode == CBC)) || imode == OFB)
  212. memcpy(text,old_iv,8);
  213. if(!dir && (imode == CFB1 || imode == CFB8 || imode == CFB64))
  214. {
  215. /* the test specifies using the output of the raw DES operation
  216. which we don't have, so reconstruct it... */
  217. for(n=0 ; n < 8 ; ++n)
  218. text[n]^=old_text[n];
  219. }
  220. }
  221. for(n=0 ; n < 8 ; ++n)
  222. akey[n]^=nk[16+n];
  223. for(n=0 ; n < 8 ; ++n)
  224. akey[8+n]^=nk[8+n];
  225. for(n=0 ; n < 8 ; ++n)
  226. akey[16+n]^=nk[n];
  227. if(numkeys < 3)
  228. memcpy(&akey[2*8],akey,8);
  229. if(numkeys < 2)
  230. memcpy(&akey[8],akey,8);
  231. DES_set_odd_parity((DES_cblock *)akey);
  232. DES_set_odd_parity((DES_cblock *)(akey+8));
  233. DES_set_odd_parity((DES_cblock *)(akey+16));
  234. memcpy(ivec,ctx.iv,8);
  235. /* pointless exercise - the final text doesn't depend on the
  236. initial text in OFB mode, so who cares what it is? (Who
  237. designed these tests?) */
  238. if(imode == OFB)
  239. for(n=0 ; n < 8 ; ++n)
  240. text[n]=text0[n]^old_iv[n];
  241. }
  242. }
  243. static int proc_file(char *rqfile, char *rspfile)
  244. {
  245. char afn[256], rfn[256];
  246. FILE *afp = NULL, *rfp = NULL;
  247. char ibuf[2048], tbuf[2048];
  248. int ilen, len, ret = 0;
  249. char amode[8] = "";
  250. char atest[100] = "";
  251. int akeysz=0;
  252. unsigned char iVec[20], aKey[40];
  253. int dir = -1, err = 0, step = 0;
  254. unsigned char plaintext[2048];
  255. unsigned char ciphertext[2048];
  256. char *rp;
  257. EVP_CIPHER_CTX ctx;
  258. int numkeys=1;
  259. FIPS_cipher_ctx_init(&ctx);
  260. if (!rqfile || !(*rqfile))
  261. {
  262. printf("No req file\n");
  263. return -1;
  264. }
  265. strcpy(afn, rqfile);
  266. if ((afp = fopen(afn, "r")) == NULL)
  267. {
  268. printf("Cannot open file: %s, %s\n",
  269. afn, strerror(errno));
  270. return -1;
  271. }
  272. if (!rspfile)
  273. {
  274. strcpy(rfn,afn);
  275. rp=strstr(rfn,"req/");
  276. #ifdef OPENSSL_SYS_WIN32
  277. if (!rp)
  278. rp=strstr(rfn,"req\\");
  279. #endif
  280. assert(rp);
  281. memcpy(rp,"rsp",3);
  282. rp = strstr(rfn, ".req");
  283. memcpy(rp, ".rsp", 4);
  284. rspfile = rfn;
  285. }
  286. if ((rfp = fopen(rspfile, "w")) == NULL)
  287. {
  288. printf("Cannot open file: %s, %s\n",
  289. rfn, strerror(errno));
  290. fclose(afp);
  291. afp = NULL;
  292. return -1;
  293. }
  294. while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
  295. {
  296. tidy_line(tbuf, ibuf);
  297. ilen = strlen(ibuf);
  298. /* printf("step=%d ibuf=%s",step,ibuf);*/
  299. if(step == 3 && !strcmp(amode,"ECB"))
  300. {
  301. memset(iVec, 0, sizeof(iVec));
  302. step = (dir)? 4: 5; /* no ivec for ECB */
  303. }
  304. switch (step)
  305. {
  306. case 0: /* read preamble */
  307. if (ibuf[0] == '\n')
  308. { /* end of preamble */
  309. if (*amode == '\0')
  310. {
  311. printf("Missing Mode\n");
  312. err = 1;
  313. }
  314. else
  315. {
  316. fputs(ibuf, rfp);
  317. ++ step;
  318. }
  319. }
  320. else if (ibuf[0] != '#')
  321. {
  322. printf("Invalid preamble item: %s\n", ibuf);
  323. err = 1;
  324. }
  325. else
  326. { /* process preamble */
  327. char *xp, *pp = ibuf+2;
  328. int n;
  329. if(*amode)
  330. { /* insert current time & date */
  331. time_t rtim = time(0);
  332. fprintf(rfp, "# %s", ctime(&rtim));
  333. }
  334. else
  335. {
  336. fputs(ibuf, rfp);
  337. if(!strncmp(pp,"INVERSE ",8) || !strncmp(pp,"DES ",4)
  338. || !strncmp(pp,"TDES ",5)
  339. || !strncmp(pp,"PERMUTATION ",12)
  340. || !strncmp(pp,"SUBSTITUTION ",13)
  341. || !strncmp(pp,"VARIABLE ",9))
  342. {
  343. /* get test type */
  344. if(!strncmp(pp,"DES ",4))
  345. pp+=4;
  346. else if(!strncmp(pp,"TDES ",5))
  347. pp+=5;
  348. xp = strchr(pp, ' ');
  349. n = xp-pp;
  350. strncpy(atest, pp, n);
  351. atest[n] = '\0';
  352. /* get mode */
  353. xp = strrchr(pp, ' '); /* get mode" */
  354. n = strlen(xp+1)-1;
  355. strncpy(amode, xp+1, n);
  356. amode[n] = '\0';
  357. /* amode[3] = '\0'; */
  358. if (VERBOSE)
  359. printf("Test=%s, Mode=%s\n",atest,amode);
  360. }
  361. }
  362. }
  363. break;
  364. case 1: /* [ENCRYPT] | [DECRYPT] */
  365. if(ibuf[0] == '\n')
  366. break;
  367. if (ibuf[0] == '[')
  368. {
  369. fputs(ibuf, rfp);
  370. ++step;
  371. if (strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
  372. dir = 1;
  373. else if (strncasecmp(ibuf, "[DECRYPT]", 9) == 0)
  374. dir = 0;
  375. else
  376. {
  377. printf("Invalid keyword: %s\n", ibuf);
  378. err = 1;
  379. }
  380. break;
  381. }
  382. else if (dir == -1)
  383. {
  384. err = 1;
  385. printf("Missing ENCRYPT/DECRYPT keyword\n");
  386. break;
  387. }
  388. else
  389. step = 2;
  390. case 2: /* KEY = xxxx */
  391. if(*ibuf == '\n')
  392. {
  393. fputs(ibuf, rfp);
  394. break;
  395. }
  396. if(!strncasecmp(ibuf,"COUNT = ",8))
  397. {
  398. fputs(ibuf, rfp);
  399. break;
  400. }
  401. if(!strncasecmp(ibuf,"COUNT=",6))
  402. {
  403. fputs(ibuf, rfp);
  404. break;
  405. }
  406. if(!strncasecmp(ibuf,"NumKeys = ",10))
  407. {
  408. numkeys=atoi(ibuf+10);
  409. break;
  410. }
  411. fputs(ibuf, rfp);
  412. if(!strncasecmp(ibuf,"KEY = ",6))
  413. {
  414. akeysz=64;
  415. len = hex2bin((char*)ibuf+6, aKey);
  416. if (len < 0)
  417. {
  418. printf("Invalid KEY\n");
  419. err=1;
  420. break;
  421. }
  422. PrintValue("KEY", aKey, len);
  423. ++step;
  424. }
  425. else if(!strncasecmp(ibuf,"KEYs = ",7))
  426. {
  427. akeysz=64*3;
  428. len=hex2bin(ibuf+7,aKey);
  429. if(len != 8)
  430. {
  431. printf("Invalid KEY\n");
  432. err=1;
  433. break;
  434. }
  435. memcpy(aKey+8,aKey,8);
  436. memcpy(aKey+16,aKey,8);
  437. ibuf[4]='\0';
  438. PrintValue("KEYs",aKey,len);
  439. ++step;
  440. }
  441. else if(!strncasecmp(ibuf,"KEY",3))
  442. {
  443. int n=ibuf[3]-'1';
  444. akeysz=64*3;
  445. len=hex2bin(ibuf+7,aKey+n*8);
  446. if(len != 8)
  447. {
  448. printf("Invalid KEY\n");
  449. err=1;
  450. break;
  451. }
  452. ibuf[4]='\0';
  453. PrintValue(ibuf,aKey,len);
  454. if(n == 2)
  455. ++step;
  456. }
  457. else
  458. {
  459. printf("Missing KEY\n");
  460. err = 1;
  461. }
  462. break;
  463. case 3: /* IV = xxxx */
  464. fputs(ibuf, rfp);
  465. if (strncasecmp(ibuf, "IV = ", 5) != 0)
  466. {
  467. printf("Missing IV\n");
  468. err = 1;
  469. }
  470. else
  471. {
  472. len = hex2bin((char*)ibuf+5, iVec);
  473. if (len < 0)
  474. {
  475. printf("Invalid IV\n");
  476. err =1;
  477. break;
  478. }
  479. PrintValue("IV", iVec, len);
  480. step = (dir)? 4: 5;
  481. }
  482. break;
  483. case 4: /* PLAINTEXT = xxxx */
  484. fputs(ibuf, rfp);
  485. if (strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
  486. {
  487. printf("Missing PLAINTEXT\n");
  488. err = 1;
  489. }
  490. else
  491. {
  492. int nn = strlen(ibuf+12);
  493. if(!strcmp(amode,"CFB1"))
  494. len=bint2bin(ibuf+12,nn-1,plaintext);
  495. else
  496. len=hex2bin(ibuf+12, plaintext);
  497. if (len < 0)
  498. {
  499. printf("Invalid PLAINTEXT: %s", ibuf+12);
  500. err =1;
  501. break;
  502. }
  503. if (len >= (int)sizeof(plaintext))
  504. {
  505. printf("Buffer overflow\n");
  506. }
  507. PrintValue("PLAINTEXT", (unsigned char*)plaintext, len);
  508. if (strcmp(atest, "Monte") == 0) /* Monte Carlo Test */
  509. {
  510. do_mct(amode,akeysz,numkeys,aKey,iVec,dir,plaintext,len,rfp);
  511. }
  512. else
  513. {
  514. assert(dir == 1);
  515. ret = DESTest(&ctx, amode, akeysz, aKey, iVec,
  516. dir, /* 0 = decrypt, 1 = encrypt */
  517. ciphertext, plaintext, len);
  518. OutputValue("CIPHERTEXT",ciphertext,len,rfp,
  519. !strcmp(amode,"CFB1"));
  520. }
  521. step = 6;
  522. }
  523. break;
  524. case 5: /* CIPHERTEXT = xxxx */
  525. fputs(ibuf, rfp);
  526. if (strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
  527. {
  528. printf("Missing KEY\n");
  529. err = 1;
  530. }
  531. else
  532. {
  533. if(!strcmp(amode,"CFB1"))
  534. len=bint2bin(ibuf+13,strlen(ibuf+13)-1,ciphertext);
  535. else
  536. len = hex2bin(ibuf+13,ciphertext);
  537. if (len < 0)
  538. {
  539. printf("Invalid CIPHERTEXT\n");
  540. err =1;
  541. break;
  542. }
  543. PrintValue("CIPHERTEXT", ciphertext, len);
  544. if (strcmp(atest, "Monte") == 0) /* Monte Carlo Test */
  545. {
  546. do_mct(amode, akeysz, numkeys, aKey, iVec,
  547. dir, ciphertext, len, rfp);
  548. }
  549. else
  550. {
  551. assert(dir == 0);
  552. ret = DESTest(&ctx, amode, akeysz, aKey, iVec,
  553. dir, /* 0 = decrypt, 1 = encrypt */
  554. plaintext, ciphertext, len);
  555. OutputValue("PLAINTEXT",(unsigned char *)plaintext,len,rfp,
  556. !strcmp(amode,"CFB1"));
  557. }
  558. step = 6;
  559. }
  560. break;
  561. case 6:
  562. if (ibuf[0] != '\n')
  563. {
  564. err = 1;
  565. printf("Missing terminator\n");
  566. }
  567. else if (strcmp(atest, "MCT") != 0)
  568. { /* MCT already added terminating nl */
  569. fputs(ibuf, rfp);
  570. }
  571. step = 1;
  572. break;
  573. }
  574. }
  575. if (rfp)
  576. fclose(rfp);
  577. if (afp)
  578. fclose(afp);
  579. return err;
  580. }
  581. /*--------------------------------------------------
  582. Processes either a single file or
  583. a set of files whose names are passed in a file.
  584. A single file is specified as:
  585. aes_test -f xxx.req
  586. A set of files is specified as:
  587. aes_test -d xxxxx.xxx
  588. The default is: -d req.txt
  589. --------------------------------------------------*/
  590. int main(int argc, char **argv)
  591. {
  592. char *rqlist = "req.txt", *rspfile = NULL;
  593. FILE *fp = NULL;
  594. char fn[250] = "", rfn[256] = "";
  595. int f_opt = 0, d_opt = 1;
  596. fips_algtest_init();
  597. if (argc > 1)
  598. {
  599. if (strcasecmp(argv[1], "-d") == 0)
  600. {
  601. d_opt = 1;
  602. }
  603. else if (strcasecmp(argv[1], "-f") == 0)
  604. {
  605. f_opt = 1;
  606. d_opt = 0;
  607. }
  608. else
  609. {
  610. printf("Invalid parameter: %s\n", argv[1]);
  611. return 0;
  612. }
  613. if (argc < 3)
  614. {
  615. printf("Missing parameter\n");
  616. return 0;
  617. }
  618. if (d_opt)
  619. rqlist = argv[2];
  620. else
  621. {
  622. strcpy(fn, argv[2]);
  623. rspfile = argv[3];
  624. }
  625. }
  626. if (d_opt)
  627. { /* list of files (directory) */
  628. if (!(fp = fopen(rqlist, "r")))
  629. {
  630. printf("Cannot open req list file\n");
  631. return -1;
  632. }
  633. while (fgets(fn, sizeof(fn), fp))
  634. {
  635. strtok(fn, "\r\n");
  636. strcpy(rfn, fn);
  637. printf("Processing: %s\n", rfn);
  638. if (proc_file(rfn, rspfile))
  639. {
  640. printf(">>> Processing failed for: %s <<<\n", rfn);
  641. EXIT(1);
  642. }
  643. }
  644. fclose(fp);
  645. }
  646. else /* single file */
  647. {
  648. if (VERBOSE)
  649. printf("Processing: %s\n", fn);
  650. if (proc_file(fn, rspfile))
  651. {
  652. printf(">>> Processing failed for: %s <<<\n", fn);
  653. }
  654. }
  655. EXIT(0);
  656. return 0;
  657. }
  658. #endif