2
0

mkfipsscr.pl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. #!/usr/local/bin/perl -w
  2. # Quick & dirty utility to generate a script for executing the
  3. # FIPS 140-2 CMVP algorithm tests based on the pathnames of
  4. # input algorithm test files actually present (the unqualified
  5. # file names are consistent but the pathnames are not).
  6. #
  7. # List of all the unqualified file names we expect.
  8. my %fips_tests = (
  9. # FIPS test definitions
  10. # DSA tests
  11. "PQGGen" => "fips_dssvs pqg",
  12. "KeyPair" => "fips_dssvs keypair",
  13. "SigGen" => "fips_dssvs siggen",
  14. "SigVer" => "fips_dssvs sigver",
  15. # SHA tests
  16. "SHA1LongMsg" => "fips_shatest",
  17. "SHA1Monte" => "fips_shatest",
  18. "SHA1ShortMsg" => "fips_shatest",
  19. "SHA224LongMsg" => "fips_shatest",
  20. "SHA224Monte" => "fips_shatest",
  21. "SHA224ShortMsg" => "fips_shatest",
  22. "SHA256LongMsg" => "fips_shatest",
  23. "SHA256Monte" => "fips_shatest",
  24. "SHA256ShortMsg" => "fips_shatest",
  25. "SHA384LongMsg" => "fips_shatest",
  26. "SHA384Monte" => "fips_shatest",
  27. "SHA384ShortMsg" => "fips_shatest",
  28. "SHA512LongMsg" => "fips_shatest",
  29. "SHA512Monte" => "fips_shatest",
  30. "SHA512ShortMsg" => "fips_shatest",
  31. # HMAC
  32. "HMAC" => "fips_hmactest",
  33. # RAND tests
  34. "ANSI931_AES128MCT" => "fips_rngvs mct",
  35. "ANSI931_AES192MCT" => "fips_rngvs mct",
  36. "ANSI931_AES256MCT" => "fips_rngvs mct",
  37. "ANSI931_AES128VST" => "fips_rngvs vst",
  38. "ANSI931_AES192VST" => "fips_rngvs vst",
  39. "ANSI931_AES256VST" => "fips_rngvs vst",
  40. # RSA tests
  41. "SigGen15" => "fips_rsastest",
  42. "SigVer15" => "fips_rsavtest",
  43. "SigGenPSS" => "fips_rsastest -saltlen SALT",
  44. "SigVerPSS" => "fips_rsavtest -saltlen SALT",
  45. "SigGenRSA" => "fips_rsastest -x931",
  46. "SigVerRSA" => "fips_rsavtest -x931",
  47. "KeyGenRSA" => "fips_rsagtest",
  48. # AES tests
  49. "CBCGFSbox128" => "fips_aesavs -f",
  50. "CBCGFSbox192" => "fips_aesavs -f",
  51. "CBCGFSbox256" => "fips_aesavs -f",
  52. "CBCKeySbox128" => "fips_aesavs -f",
  53. "CBCKeySbox192" => "fips_aesavs -f",
  54. "CBCKeySbox256" => "fips_aesavs -f",
  55. "CBCMCT128" => "fips_aesavs -f",
  56. "CBCMCT192" => "fips_aesavs -f",
  57. "CBCMCT256" => "fips_aesavs -f",
  58. "CBCMMT128" => "fips_aesavs -f",
  59. "CBCMMT192" => "fips_aesavs -f",
  60. "CBCMMT256" => "fips_aesavs -f",
  61. "CBCVarKey128" => "fips_aesavs -f",
  62. "CBCVarKey192" => "fips_aesavs -f",
  63. "CBCVarKey256" => "fips_aesavs -f",
  64. "CBCVarTxt128" => "fips_aesavs -f",
  65. "CBCVarTxt192" => "fips_aesavs -f",
  66. "CBCVarTxt256" => "fips_aesavs -f",
  67. "CFB128GFSbox128" => "fips_aesavs -f",
  68. "CFB128GFSbox192" => "fips_aesavs -f",
  69. "CFB128GFSbox256" => "fips_aesavs -f",
  70. "CFB128KeySbox128" => "fips_aesavs -f",
  71. "CFB128KeySbox192" => "fips_aesavs -f",
  72. "CFB128KeySbox256" => "fips_aesavs -f",
  73. "CFB128MCT128" => "fips_aesavs -f",
  74. "CFB128MCT192" => "fips_aesavs -f",
  75. "CFB128MCT256" => "fips_aesavs -f",
  76. "CFB128MMT128" => "fips_aesavs -f",
  77. "CFB128MMT192" => "fips_aesavs -f",
  78. "CFB128MMT256" => "fips_aesavs -f",
  79. "CFB128VarKey128" => "fips_aesavs -f",
  80. "CFB128VarKey192" => "fips_aesavs -f",
  81. "CFB128VarKey256" => "fips_aesavs -f",
  82. "CFB128VarTxt128" => "fips_aesavs -f",
  83. "CFB128VarTxt192" => "fips_aesavs -f",
  84. "CFB128VarTxt256" => "fips_aesavs -f",
  85. "CFB8GFSbox128" => "fips_aesavs -f",
  86. "CFB8GFSbox192" => "fips_aesavs -f",
  87. "CFB8GFSbox256" => "fips_aesavs -f",
  88. "CFB8KeySbox128" => "fips_aesavs -f",
  89. "CFB8KeySbox192" => "fips_aesavs -f",
  90. "CFB8KeySbox256" => "fips_aesavs -f",
  91. "CFB8MCT128" => "fips_aesavs -f",
  92. "CFB8MCT192" => "fips_aesavs -f",
  93. "CFB8MCT256" => "fips_aesavs -f",
  94. "CFB8MMT128" => "fips_aesavs -f",
  95. "CFB8MMT192" => "fips_aesavs -f",
  96. "CFB8MMT256" => "fips_aesavs -f",
  97. "CFB8VarKey128" => "fips_aesavs -f",
  98. "CFB8VarKey192" => "fips_aesavs -f",
  99. "CFB8VarKey256" => "fips_aesavs -f",
  100. "CFB8VarTxt128" => "fips_aesavs -f",
  101. "CFB8VarTxt192" => "fips_aesavs -f",
  102. "CFB8VarTxt256" => "fips_aesavs -f",
  103. #"CFB1GFSbox128" => "fips_aesavs -f",
  104. #"CFB1GFSbox192" => "fips_aesavs -f",
  105. #"CFB1GFSbox256" => "fips_aesavs -f",
  106. #"CFB1KeySbox128" => "fips_aesavs -f",
  107. #"CFB1KeySbox192" => "fips_aesavs -f",
  108. #"CFB1KeySbox256" => "fips_aesavs -f",
  109. #"CFB1MCT128" => "fips_aesavs -f",
  110. #"CFB1MCT192" => "fips_aesavs -f",
  111. #"CFB1MCT256" => "fips_aesavs -f",
  112. #"CFB1MMT128" => "fips_aesavs -f",
  113. #"CFB1MMT192" => "fips_aesavs -f",
  114. #"CFB1MMT256" => "fips_aesavs -f",
  115. #"CFB1VarKey128" => "fips_aesavs -f",
  116. #"CFB1VarKey192" => "fips_aesavs -f",
  117. #"CFB1VarKey256" => "fips_aesavs -f",
  118. #"CFB1VarTxt128" => "fips_aesavs -f",
  119. #"CFB1VarTxt192" => "fips_aesavs -f",
  120. #"CFB1VarTxt256" => "fips_aesavs -f",
  121. "ECBGFSbox128" => "fips_aesavs -f",
  122. "ECBGFSbox192" => "fips_aesavs -f",
  123. "ECBGFSbox256" => "fips_aesavs -f",
  124. "ECBKeySbox128" => "fips_aesavs -f",
  125. "ECBKeySbox192" => "fips_aesavs -f",
  126. "ECBKeySbox256" => "fips_aesavs -f",
  127. "ECBMCT128" => "fips_aesavs -f",
  128. "ECBMCT192" => "fips_aesavs -f",
  129. "ECBMCT256" => "fips_aesavs -f",
  130. "ECBMMT128" => "fips_aesavs -f",
  131. "ECBMMT192" => "fips_aesavs -f",
  132. "ECBMMT256" => "fips_aesavs -f",
  133. "ECBVarKey128" => "fips_aesavs -f",
  134. "ECBVarKey192" => "fips_aesavs -f",
  135. "ECBVarKey256" => "fips_aesavs -f",
  136. "ECBVarTxt128" => "fips_aesavs -f",
  137. "ECBVarTxt192" => "fips_aesavs -f",
  138. "ECBVarTxt256" => "fips_aesavs -f",
  139. "OFBGFSbox128" => "fips_aesavs -f",
  140. "OFBGFSbox192" => "fips_aesavs -f",
  141. "OFBGFSbox256" => "fips_aesavs -f",
  142. "OFBKeySbox128" => "fips_aesavs -f",
  143. "OFBKeySbox192" => "fips_aesavs -f",
  144. "OFBKeySbox256" => "fips_aesavs -f",
  145. "OFBMCT128" => "fips_aesavs -f",
  146. "OFBMCT192" => "fips_aesavs -f",
  147. "OFBMCT256" => "fips_aesavs -f",
  148. "OFBMMT128" => "fips_aesavs -f",
  149. "OFBMMT192" => "fips_aesavs -f",
  150. "OFBMMT256" => "fips_aesavs -f",
  151. "OFBVarKey128" => "fips_aesavs -f",
  152. "OFBVarKey192" => "fips_aesavs -f",
  153. "OFBVarKey256" => "fips_aesavs -f",
  154. "OFBVarTxt128" => "fips_aesavs -f",
  155. "OFBVarTxt192" => "fips_aesavs -f",
  156. "OFBVarTxt256" => "fips_aesavs -f",
  157. # Triple DES tests
  158. "TCBCinvperm" => "fips_desmovs -f",
  159. "TCBCMMT1" => "fips_desmovs -f",
  160. "TCBCMMT2" => "fips_desmovs -f",
  161. "TCBCMMT3" => "fips_desmovs -f",
  162. "TCBCMonte1" => "fips_desmovs -f",
  163. "TCBCMonte2" => "fips_desmovs -f",
  164. "TCBCMonte3" => "fips_desmovs -f",
  165. "TCBCpermop" => "fips_desmovs -f",
  166. "TCBCsubtab" => "fips_desmovs -f",
  167. "TCBCvarkey" => "fips_desmovs -f",
  168. "TCBCvartext" => "fips_desmovs -f",
  169. "TCFB64invperm" => "fips_desmovs -f",
  170. "TCFB64MMT1" => "fips_desmovs -f",
  171. "TCFB64MMT2" => "fips_desmovs -f",
  172. "TCFB64MMT3" => "fips_desmovs -f",
  173. "TCFB64Monte1" => "fips_desmovs -f",
  174. "TCFB64Monte2" => "fips_desmovs -f",
  175. "TCFB64Monte3" => "fips_desmovs -f",
  176. "TCFB64permop" => "fips_desmovs -f",
  177. "TCFB64subtab" => "fips_desmovs -f",
  178. "TCFB64varkey" => "fips_desmovs -f",
  179. "TCFB64vartext" => "fips_desmovs -f",
  180. "TCFB8invperm" => "fips_desmovs -f",
  181. "TCFB8MMT1" => "fips_desmovs -f",
  182. "TCFB8MMT2" => "fips_desmovs -f",
  183. "TCFB8MMT3" => "fips_desmovs -f",
  184. "TCFB8Monte1" => "fips_desmovs -f",
  185. "TCFB8Monte2" => "fips_desmovs -f",
  186. "TCFB8Monte3" => "fips_desmovs -f",
  187. "TCFB8permop" => "fips_desmovs -f",
  188. "TCFB8subtab" => "fips_desmovs -f",
  189. "TCFB8varkey" => "fips_desmovs -f",
  190. "TCFB8vartext" => "fips_desmovs -f",
  191. "TECBinvperm" => "fips_desmovs -f",
  192. "TECBMMT1" => "fips_desmovs -f",
  193. "TECBMMT2" => "fips_desmovs -f",
  194. "TECBMMT3" => "fips_desmovs -f",
  195. "TECBMonte1" => "fips_desmovs -f",
  196. "TECBMonte2" => "fips_desmovs -f",
  197. "TECBMonte3" => "fips_desmovs -f",
  198. "TECBpermop" => "fips_desmovs -f",
  199. "TECBsubtab" => "fips_desmovs -f",
  200. "TECBvarkey" => "fips_desmovs -f",
  201. "TECBvartext" => "fips_desmovs -f",
  202. "TOFBinvperm" => "fips_desmovs -f",
  203. "TOFBMMT1" => "fips_desmovs -f",
  204. "TOFBMMT2" => "fips_desmovs -f",
  205. "TOFBMMT3" => "fips_desmovs -f",
  206. "TOFBMonte1" => "fips_desmovs -f",
  207. "TOFBMonte2" => "fips_desmovs -f",
  208. "TOFBMonte3" => "fips_desmovs -f",
  209. "TOFBpermop" => "fips_desmovs -f",
  210. "TOFBsubtab" => "fips_desmovs -f",
  211. "TOFBvarkey" => "fips_desmovs -f",
  212. "TOFBvartext" => "fips_desmovs -f",
  213. "TCBCinvperm" => "fips_desmovs -f",
  214. "TCBCMMT1" => "fips_desmovs -f",
  215. "TCBCMMT2" => "fips_desmovs -f",
  216. "TCBCMMT3" => "fips_desmovs -f",
  217. "TCBCMonte1" => "fips_desmovs -f",
  218. "TCBCMonte2" => "fips_desmovs -f",
  219. "TCBCMonte3" => "fips_desmovs -f",
  220. "TCBCpermop" => "fips_desmovs -f",
  221. "TCBCsubtab" => "fips_desmovs -f",
  222. "TCBCvarkey" => "fips_desmovs -f",
  223. "TCBCvartext" => "fips_desmovs -f",
  224. "TCFB64invperm" => "fips_desmovs -f",
  225. "TCFB64MMT1" => "fips_desmovs -f",
  226. "TCFB64MMT2" => "fips_desmovs -f",
  227. "TCFB64MMT3" => "fips_desmovs -f",
  228. "TCFB64Monte1" => "fips_desmovs -f",
  229. "TCFB64Monte2" => "fips_desmovs -f",
  230. "TCFB64Monte3" => "fips_desmovs -f",
  231. "TCFB64permop" => "fips_desmovs -f",
  232. "TCFB64subtab" => "fips_desmovs -f",
  233. "TCFB64varkey" => "fips_desmovs -f",
  234. "TCFB64vartext" => "fips_desmovs -f",
  235. "TCFB8invperm" => "fips_desmovs -f",
  236. "TCFB8MMT1" => "fips_desmovs -f",
  237. "TCFB8MMT2" => "fips_desmovs -f",
  238. "TCFB8MMT3" => "fips_desmovs -f",
  239. "TCFB8Monte1" => "fips_desmovs -f",
  240. "TCFB8Monte2" => "fips_desmovs -f",
  241. "TCFB8Monte3" => "fips_desmovs -f",
  242. "TCFB8permop" => "fips_desmovs -f",
  243. "TCFB8subtab" => "fips_desmovs -f",
  244. "TCFB8varkey" => "fips_desmovs -f",
  245. "TCFB8vartext" => "fips_desmovs -f",
  246. "TECBinvperm" => "fips_desmovs -f",
  247. "TECBMMT1" => "fips_desmovs -f",
  248. "TECBMMT2" => "fips_desmovs -f",
  249. "TECBMMT3" => "fips_desmovs -f",
  250. "TECBMonte1" => "fips_desmovs -f",
  251. "TECBMonte2" => "fips_desmovs -f",
  252. "TECBMonte3" => "fips_desmovs -f",
  253. "TECBpermop" => "fips_desmovs -f",
  254. "TECBsubtab" => "fips_desmovs -f",
  255. "TECBvarkey" => "fips_desmovs -f",
  256. "TECBvartext" => "fips_desmovs -f",
  257. "TOFBinvperm" => "fips_desmovs -f",
  258. "TOFBMMT1" => "fips_desmovs -f",
  259. "TOFBMMT2" => "fips_desmovs -f",
  260. "TOFBMMT3" => "fips_desmovs -f",
  261. "TOFBMonte1" => "fips_desmovs -f",
  262. "TOFBMonte2" => "fips_desmovs -f",
  263. "TOFBMonte3" => "fips_desmovs -f",
  264. "TOFBpermop" => "fips_desmovs -f",
  265. "TOFBsubtab" => "fips_desmovs -f",
  266. "TOFBvarkey" => "fips_desmovs -f",
  267. "TOFBvartext" => "fips_desmovs -f"
  268. );
  269. my %salt_names = (
  270. "SigVerPSS (salt 0)" => "SigVerPSS",
  271. "SigVerPSS (salt 62)" => "SigVerPSS",
  272. "SigGenPSS (salt 0)" => "SigGenPSS",
  273. "SigGenPSS (salt 62)" => "SigGenPSS",
  274. );
  275. my $win32 = $^O =~ m/mswin/i;
  276. my $onedir = 0;
  277. my $filter = "";
  278. my $tvdir;
  279. my $tprefix;
  280. my $shwrap_prefix;
  281. my $shwrap;
  282. my $rmcmd = "rm -rf";
  283. my $mkcmd = "mkdir";
  284. my $debug = 0;
  285. my $quiet = 0;
  286. my $rspdir = "rsp";
  287. my $rspignore = 0;
  288. my @bogus = (); # list of unmatched *.rsp files
  289. my $bufout = '';
  290. my $bufdir = '';
  291. my %_programs = (); # list of external programs to check
  292. foreach (@ARGV)
  293. {
  294. if ($_ eq "--win32")
  295. {
  296. $win32 = 1;
  297. }
  298. elsif ($_ eq "--onedir")
  299. {
  300. $onedir = 1;
  301. }
  302. elsif ($_ eq "--debug")
  303. {
  304. $debug = 1;
  305. }
  306. elsif ($_ eq "--quiet")
  307. {
  308. $quiet = 1;
  309. }
  310. elsif (/--dir=(.*)$/)
  311. {
  312. $tvdir = $1;
  313. }
  314. elsif (/--rspdir=(.*)$/)
  315. {
  316. $rspdir = $1;
  317. }
  318. elsif (/--noshwrap$/)
  319. {
  320. $shwrap = "";
  321. }
  322. elsif (/--rspignore$/)
  323. {
  324. $rspignore = 1;
  325. }
  326. elsif (/--tprefix=(.*)$/)
  327. {
  328. $tprefix = $1;
  329. }
  330. elsif (/--shwrap_prefix=(.*)$/)
  331. {
  332. $shwrap_prefix = $1;
  333. }
  334. elsif (/--filter=(.*)$/)
  335. {
  336. $filter = $1;
  337. }
  338. elsif (/--mkdir=(.*)$/)
  339. {
  340. $mkcmd = $1;
  341. }
  342. elsif (/--rm=(.*)$/)
  343. {
  344. $rmcmd = $1;
  345. }
  346. elsif (/--outfile=(.*)$/)
  347. {
  348. $outfile = $1;
  349. }
  350. else
  351. {
  352. &Help();
  353. exit(1);
  354. }
  355. }
  356. $tvdir = "." unless defined $tvdir;
  357. if ($win32)
  358. {
  359. if (!defined $tprefix)
  360. {
  361. if ($onedir)
  362. {
  363. $tprefix = ".\\";
  364. }
  365. else
  366. {
  367. $tprefix = "..\\out32dll\\";
  368. }
  369. }
  370. $bufinit .= <<END;
  371. \@echo off
  372. rem Test vector run script
  373. rem Auto generated by mkfipsscr.pl script
  374. rem Do not edit
  375. END
  376. }
  377. else
  378. {
  379. if ($onedir)
  380. {
  381. $tprefix = "./" unless defined $tprefix;
  382. $shwrap_prefix = "./" unless defined $shwrap_prefix;
  383. }
  384. else
  385. {
  386. $tprefix = "../test/" unless defined $tprefix;
  387. $shwrap_prefix = "../util/" unless defined $shwrap_prefix;
  388. }
  389. $shwrap = "${shwrap_prefix}shlib_wrap.sh " unless defined $shwrap;
  390. $bufinit .= <<END;
  391. #!/bin/sh
  392. # Test vector run script
  393. # Auto generated by mkfipsscr.pl script
  394. # Do not edit
  395. RM="$rmcmd"
  396. MKDIR="$mkcmd"
  397. TPREFIX=$tprefix
  398. END
  399. }
  400. my %fips_found;
  401. foreach (keys %fips_tests)
  402. {
  403. $fips_found{$_} = 0;
  404. }
  405. my %saltPSS;
  406. for (keys %salt_names)
  407. {
  408. $salt_found{$_} = 0;
  409. }
  410. recurse_test($win32, $tprefix, $filter, $tvdir);
  411. while (($key, $value) = each %salt_found)
  412. {
  413. &countentry($key, $value);
  414. delete $fips_found{$salt_names{$key}};
  415. }
  416. while (($key, $value) = each %fips_found)
  417. {
  418. &countentry($key, $value);
  419. }
  420. # If no fatal errors write out the script file
  421. $outfile = "fipstests.sh" unless defined $outfile;
  422. open(OUT, ">$outfile") || die "Error opening $outfile: $!";
  423. print OUT $bufinit;
  424. if (!$rspignore && @bogus)
  425. {
  426. print STDERR "ERROR: please remove bogus *.rsp files\n";
  427. print OUT <<EOF;
  428. echo $outfile generation failed due to presence of bogus *.rsp files
  429. EOF
  430. }
  431. else
  432. {
  433. print OUT $bufout;
  434. }
  435. close OUT;
  436. # Check for external programs
  437. for (keys %_programs)
  438. {
  439. s/ .*$//;
  440. -x $_ || print STDERR "WARNING: program $_ not found\n";
  441. }
  442. #--------------------------------
  443. sub Help {
  444. (my $cmd) = ($0 =~ m#([^/]+)$#);
  445. print <<EOF;
  446. $cmd: generate script for CMVP algorithm tests
  447. --debug Enable debug output
  448. --dir=<dirname> Optional root for *.req file search
  449. --filter=<regexp>
  450. --onedir <dirname> Assume all components in current directory
  451. --outfile=<filename> Optional name of output script, default fipstests.{sh|bat}
  452. --rspdir=<dirname> Name of subdirectories containing *.rsp files, default "resp"
  453. --rspignore Ignore any bogus *.rsp files
  454. --shwrap_prefix=<prefix>
  455. --tprefix=<prefix>
  456. --quiet Shhh....
  457. --win32 Generate script for Win32 environment
  458. EOF
  459. }
  460. #--------------------------------
  461. sub countentry {
  462. my ($key,$value) = @_;
  463. if ($value == 0)
  464. {
  465. print STDERR "WARNING: test file $key not found\n" unless $quiet;
  466. }
  467. elsif ($value > 1)
  468. {
  469. print STDERR "WARNING: test file $key found $value times\n" unless $quiet;
  470. }
  471. else
  472. {
  473. print STDERR "Found test file $key\n" if $debug;
  474. }
  475. }
  476. #--------------------------------
  477. sub recurse_test
  478. {
  479. my ($win32, $tprefix, $filter, $dir) = @_;
  480. my $dirh;
  481. opendir($dirh, $dir);
  482. while ($_ = readdir($dirh))
  483. {
  484. next if ($_ eq "." || $_ eq "..");
  485. $_ = "$dir/$_";
  486. if (-f "$_")
  487. {
  488. if (/\/([^\/]*)\.rsp$/)
  489. {
  490. if (exists $fips_tests{$1})
  491. {
  492. $debug && print "DEBUG: $1 found, will be overwritten\n";
  493. }
  494. else
  495. {
  496. print STDERR "ERROR: bogus file $_\n";
  497. push @bogus, $_;
  498. }
  499. }
  500. next unless /$filter.*\.req$/i;
  501. if (/\/([^\/]*)\.req$/ && exists $fips_tests{$1})
  502. {
  503. $fips_found{$1}++;
  504. test_line($win32, $_, $tprefix, $1);
  505. }
  506. elsif (! /SHAmix\.req$/)
  507. {
  508. print STDERR "WARNING: unrecognized filename $_\n";
  509. }
  510. }
  511. elsif (-d "$_")
  512. {
  513. if (/$filter.*req$/i)
  514. {
  515. test_dir($win32, $_);
  516. }
  517. recurse_test($win32, $tprefix, $filter, $_);
  518. }
  519. }
  520. closedir($dirh);
  521. }
  522. #--------------------------------
  523. sub test_dir
  524. {
  525. my ($win32, $req) = @_;
  526. my $rsp = $req;
  527. $rsp =~ s/req$/$rspdir/;
  528. if ($win32)
  529. {
  530. $rsp =~ tr|/|\\|;
  531. $req =~ tr|/|\\|;
  532. $bufdir = <<END;
  533. echo Running tests in $req
  534. if exist "$rsp" rd /s /q "$rsp"
  535. md "$rsp"
  536. END
  537. }
  538. else
  539. {
  540. $bufdir = <<END;
  541. echo Running tests in "$req"
  542. \$RM "$rsp"
  543. \$MKDIR "$rsp"
  544. END
  545. }
  546. }
  547. #--------------------------------
  548. sub test_line
  549. {
  550. my ($win32, $req, $tprefix, $tnam) = @_;
  551. my $rsp = $req;
  552. my $tcmd = $fips_tests{$tnam};
  553. $bufout .= $bufdir;
  554. $bufdir = "";
  555. $rsp =~ s/req\/([^\/]*).req$/$rspdir\/$1.rsp/;
  556. if ($tcmd =~ /-f$/)
  557. {
  558. if ($win32)
  559. {
  560. $req =~ tr|/|\\|;
  561. $rsp =~ tr|/|\\|;
  562. $bufout .= "$tprefix$tcmd \"$req\" \"$rsp\"\n";
  563. $_programs{"$tprefix$tcmd.exe"} = 1;
  564. }
  565. else
  566. {
  567. $bufout .= <<END;
  568. ${shwrap}\${TPREFIX}$tcmd "$req" "$rsp" || { echo "$req failure" ; exit 1
  569. }
  570. END
  571. $_programs{"${shwrap_prefix}shlib_wrap.sh"} = 1;
  572. $_programs{"$tprefix$tcmd"} = 1;
  573. }
  574. return;
  575. }
  576. if ($tcmd =~ /SALT$/)
  577. {
  578. open (IN, $req) || die "Can't Open File $req";
  579. my $saltlen;
  580. while (<IN>)
  581. {
  582. if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i)
  583. {
  584. my $sl = $1;
  585. print STDERR "$req salt length $sl\n" if $debug;
  586. $tcmd =~ s/SALT$/$sl/;
  587. $salt_found{"$tnam (salt $sl)"}++;
  588. last;
  589. }
  590. }
  591. close IN;
  592. if ($tcmd =~ /SALT$/)
  593. {
  594. die "Can't detect salt length for $req";
  595. }
  596. }
  597. if ($win32)
  598. {
  599. $req =~ tr|/|\\|;
  600. $rsp =~ tr|/|\\|;
  601. $bufout .= "$tprefix$tcmd < \"$req\" > \"$rsp\"\n";
  602. $_programs{"$tprefix$tcmd.exe"} = 1;
  603. }
  604. else
  605. {
  606. $bufout .= <<END;
  607. ${shwrap}\${TPREFIX}$tcmd < "$req" > "$rsp" || { echo "$req failure" ; exit 1; }
  608. END
  609. $_programs{"$tprefix$tcmd"} = 1;
  610. }
  611. }