cryptography ip-cores in vhdl / verilog
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

558 lines
21 KiB

  1. -- ======================================================================
  2. -- CBC-DES encryption/decryption testbench
  3. -- tests according to NIST 800-17 special publication
  4. -- Copyright (C) 2011 Torsten Meissner
  5. -------------------------------------------------------------------------
  6. -- This program is free software; you can redistribute it and/or modify
  7. -- it under the terms of the GNU General Public License as published by
  8. -- the Free Software Foundation; either version 2 of the License, or
  9. -- (at your option) any later version.
  10. -- This program is distributed in the hope that it will be useful,
  11. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. -- GNU General Public License for more details.
  14. -- You should have received a copy of the GNU General Public License
  15. -- along with this program; if not, write to the Free Software
  16. -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. -- ======================================================================
  18. -- Revision 1.0 2011/09/23
  19. -- Initial release, variable plaintext known answer test integrated
  20. -- Revision 1.1 2011/09/25
  21. -- integrated all encryption tests of NIST 800-17 publication except the modes-tests
  22. -- Revision 1.2 2011/10/05
  23. -- integrated all decryption tests of NIST 800-17 publication except the modes-tests
  24. library ieee;
  25. use ieee.std_logic_1164.all;
  26. use ieee.numeric_std.all;
  27. use std.env.all;
  28. entity tb_cbcdes is
  29. end entity tb_cbcdes;
  30. architecture rtl of tb_cbcdes is
  31. type t_array is array (natural range <>) of std_logic_vector(0 to 63);
  32. constant c_variable_plaintext_known_answers : t_array(0 to 63) :=
  33. (x"95F8A5E5DD31D900", x"DD7F121CA5015619", x"2E8653104F3834EA",
  34. x"4BD388FF6CD81D4F", x"20B9E767B2FB1456", x"55579380D77138EF",
  35. x"6CC5DEFAAF04512F", x"0D9F279BA5D87260", x"D9031B0271BD5A0A",
  36. x"424250B37C3DD951", x"B8061B7ECD9A21E5", x"F15D0F286B65BD28",
  37. x"ADD0CC8D6E5DEBA1", x"E6D5F82752AD63D1", x"ECBFE3BD3F591A5E",
  38. x"F356834379D165CD", x"2B9F982F20037FA9", x"889DE068A16F0BE6",
  39. x"E19E275D846A1298", x"329A8ED523D71AEC", x"E7FCE22557D23C97",
  40. x"12A9F5817FF2D65D", x"A484C3AD38DC9C19", x"FBE00A8A1EF8AD72",
  41. x"750D079407521363", x"64FEED9C724C2FAF", x"F02B263B328E2B60",
  42. x"9D64555A9A10B852", x"D106FF0BED5255D7", x"E1652C6B138C64A5",
  43. x"E428581186EC8F46", x"AEB5F5EDE22D1A36", x"E943D7568AEC0C5C",
  44. x"DF98C8276F54B04B", x"B160E4680F6C696F", x"FA0752B07D9C4AB8",
  45. x"CA3A2B036DBC8502", x"5E0905517BB59BCF", x"814EEB3B91D90726",
  46. x"4D49DB1532919C9F", x"25EB5FC3F8CF0621", x"AB6A20C0620D1C6F",
  47. x"79E90DBC98F92CCA", x"866ECEDD8072BB0E", x"8B54536F2F3E64A8",
  48. x"EA51D3975595B86B", x"CAFFC6AC4542DE31", x"8DD45A2DDF90796C",
  49. x"1029D55E880EC2D0", x"5D86CB23639DBEA9", x"1D1CA853AE7C0C5F",
  50. x"CE332329248F3228", x"8405D1ABE24FB942", x"E643D78090CA4207",
  51. x"48221B9937748A23", x"DD7C0BBD61FAFD54", x"2FBC291A570DB5C4",
  52. x"E07C30D7E4E26E12", x"0953E2258E8E90A1", x"5B711BC4CEEBF2EE",
  53. x"CC083F1E6D9E85F6", x"D2FD8867D50D2DFE", x"06E7EA22CE92708F",
  54. x"166B40B44ABA4BD6");
  55. constant c_variable_key_known_answers : t_array(0 to 55) :=
  56. (x"95A8D72813DAA94D", x"0EEC1487DD8C26D5", x"7AD16FFB79C45926",
  57. x"D3746294CA6A6CF3", x"809F5F873C1FD761", x"C02FAFFEC989D1FC",
  58. x"4615AA1D33E72F10", x"2055123350C00858", x"DF3B99D6577397C8",
  59. x"31FE17369B5288C9", x"DFDD3CC64DAE1642", x"178C83CE2B399D94",
  60. x"50F636324A9B7F80", x"A8468EE3BC18F06D", x"A2DC9E92FD3CDE92",
  61. x"CAC09F797D031287", x"90BA680B22AEB525", x"CE7A24F350E280B6",
  62. x"882BFF0AA01A0B87", x"25610288924511C2", x"C71516C29C75D170",
  63. x"5199C29A52C9F059", x"C22F0A294A71F29F", x"EE371483714C02EA",
  64. x"A81FBD448F9E522F", x"4F644C92E192DFED", x"1AFA9A66A6DF92AE",
  65. x"B3C1CC715CB879D8", x"19D032E64AB0BD8B", x"3CFAA7A7DC8720DC",
  66. x"B7265F7F447AC6F3", x"9DB73B3C0D163F54", x"8181B65BABF4A975",
  67. x"93C9B64042EAA240", x"5570530829705592", x"8638809E878787A0",
  68. x"41B9A79AF79AC208", x"7A9BE42F2009A892", x"29038D56BA6D2745",
  69. x"5495C6ABF1E5DF51", x"AE13DBD561488933", x"024D1FFA8904E389",
  70. x"D1399712F99BF02E", x"14C1D7C1CFFEC79E", x"1DE5279DAE3BED6F",
  71. x"E941A33F85501303", x"DA99DBBC9A03F379", x"B7FC92F91D8E92E9",
  72. x"AE8E5CAA3CA04E85", x"9CC62DF43B6EED74", x"D863DBB5C59A91A0",
  73. x"A1AB2190545B91D7", x"0875041E64C570F7", x"5A594528BEBEF1CC",
  74. x"FCDB3291DE21F0C0", x"869EFD7F9F265A09");
  75. constant c_permutation_operation_known_answers_keys : t_array(0 to 31) :=
  76. (x"1046913489980131", x"1007103489988020", x"10071034C8980120",
  77. x"1046103489988020", x"1086911519190101", x"1086911519580101",
  78. x"5107B01519580101", x"1007B01519190101", x"3107915498080101",
  79. x"3107919498080101", x"10079115B9080140", x"3107911598080140",
  80. x"1007D01589980101", x"9107911589980101", x"9107D01589190101",
  81. x"1007D01598980120", x"1007940498190101", x"0107910491190401",
  82. x"0107910491190101", x"0107940491190401", x"19079210981A0101",
  83. x"1007911998190801", x"10079119981A0801", x"1007921098190101",
  84. x"100791159819010B", x"1004801598190101", x"1004801598190102",
  85. x"1004801598190108", x"1002911598100104", x"1002911598190104",
  86. x"1002911598100201", x"1002911698100101");
  87. constant c_permutation_operation_known_answers_cipher : t_array(0 to 31) :=
  88. (x"88D55E54F54C97B4", x"0C0CC00C83EA48FD", x"83BC8EF3A6570183",
  89. x"DF725DCAD94EA2E9", x"E652B53B550BE8B0", x"AF527120C485CBB0",
  90. x"0F04CE393DB926D5", x"C9F00FFC74079067", x"7CFD82A593252B4E",
  91. x"CB49A2F9E91363E3", x"00B588BE70D23F56", x"406A9A6AB43399AE",
  92. x"6CB773611DCA9ADA", x"67FD21C17DBB5D70", x"9592CB4110430787",
  93. x"A6B7FF68A318DDD3", x"4D102196C914CA16", x"2DFA9F4573594965",
  94. x"B46604816C0E0774", x"6E7E6221A4F34E87", x"AA85E74643233199",
  95. x"2E5A19DB4D1962D6", x"23A866A809D30894", x"D812D961F017D320",
  96. x"055605816E58608F", x"ABD88E8B1B7716F1", x"537AC95BE69DA1E1",
  97. x"AED0F6AE3C25CDD8", x"B3E35A5EE53E7B8D", x"61C79C71921A2EF8",
  98. x"E2F5728F0995013C", x"1AEAC39A61F0A464");
  99. constant c_substitution_table_test_keys : t_array(0 to 18) :=
  100. (x"7CA110454A1A6E57", x"0131D9619DC1376E", x"07A1133E4A0B2686",
  101. x"3849674C2602319E", x"04B915BA43FEB5B6", x"0113B970FD34F2CE",
  102. x"0170F175468FB5E6", x"43297FAD38E373FE", x"07A7137045DA2A16",
  103. x"04689104C2FD3B2F", x"37D06BB516CB7546", x"1F08260D1AC2465E",
  104. x"584023641ABA6176", x"025816164629B007", x"49793EBC79B3258F",
  105. x"4FB05E1515AB73A7", x"49E95D6D4CA229BF", x"018310DC409B26D6",
  106. x"1C587F1C13924FEF");
  107. constant c_substitution_table_test_plain : t_array(0 to 18) :=
  108. (x"01A1D6D039776742", x"5CD54CA83DEF57DA", x"0248D43806F67172",
  109. x"51454B582DDF440A", x"42FD443059577FA2", x"059B5E0851CF143A",
  110. x"0756D8E0774761D2", x"762514B829BF486A", x"3BDD119049372802",
  111. x"26955F6835AF609A", x"164D5E404F275232", x"6B056E18759F5CCA",
  112. x"004BD6EF09176062", x"480D39006EE762F2", x"437540C8698F3CFA",
  113. x"072D43A077075292", x"02FE55778117F12A", x"1D9D5C5018F728C2",
  114. x"305532286D6F295A");
  115. constant c_substitution_table_test_cipher : t_array(0 to 18) :=
  116. (x"690F5B0D9A26939B", x"7A389D10354BD271", x"868EBB51CAB4599A",
  117. x"7178876E01F19B2A", x"AF37FB421F8C4095", x"86A560F10EC6D85B",
  118. x"0CD3DA020021DC09", x"EA676B2CB7DB2B7A", x"DFD64A815CAF1A0F",
  119. x"5C513C9C4886C088", x"0A2AEEAE3FF4AB77", x"EF1BF03E5DFA575A",
  120. x"88BF0DB6D70DEE56", x"A1F9915541020B56", x"6FBF1CAFCFFD0556",
  121. x"2F22E49BAB7CA1AC", x"5A6B612CC26CCE4A", x"5F4C038ED12B2E41",
  122. x"63FAC0D034D9F793");
  123. signal s_cbc_answers : t_array(0 to 19);
  124. signal s_reset : std_logic := '0';
  125. signal s_clk : std_logic := '0';
  126. signal s_start : std_logic := '0';
  127. signal s_mode : std_logic := '0';
  128. signal s_key : std_logic_vector(0 to 63) := (others => '0');
  129. signal s_iv : std_logic_vector(0 to 63) := (others => '0');
  130. signal s_datain : std_logic_vector(0 to 63) := (others => '0');
  131. signal s_validin : std_logic := '0';
  132. signal s_acceptin : std_logic;
  133. signal s_dataout : std_logic_vector(0 to 63);
  134. signal s_validout : std_logic;
  135. signal s_acceptout : std_logic := '0';
  136. begin
  137. s_reset <= '1' after 100 ns;
  138. s_clk <= not(s_clk) after 10 ns;
  139. teststimuliP : process is
  140. begin
  141. -- ENCRYPTION TESTS
  142. s_start <= '0';
  143. s_mode <= '0';
  144. s_validin <= '0';
  145. s_iv <= (others => '0');
  146. s_key <= x"0101010101010101";
  147. s_datain <= x"8000000000000000";
  148. -- Variable plaintext known answer test
  149. for index in c_variable_plaintext_known_answers'range loop
  150. wait until rising_edge(s_clk);
  151. s_validin <= '1';
  152. s_start <= '1';
  153. if(index /= 0) then
  154. s_datain <= '0' & s_datain(0 to 62);
  155. end if;
  156. wait until rising_edge(s_clk) and s_acceptin = '1';
  157. s_validin <= '0';
  158. s_start <= '0';
  159. end loop;
  160. wait until rising_edge(s_clk);
  161. s_start <= '0';
  162. s_mode <= '0';
  163. s_validin <= '0';
  164. s_iv <= (others => '0');
  165. s_key <= (others => '0');
  166. s_datain <= (others => '0');
  167. wait for 1 us;
  168. -- Inverse permutation known answer test
  169. s_key <= x"0101010101010101";
  170. for index in c_variable_plaintext_known_answers'range loop
  171. wait until rising_edge(s_clk);
  172. s_validin <= '1';
  173. s_start <= '1';
  174. s_datain <= c_variable_plaintext_known_answers(index);
  175. wait until rising_edge(s_clk) and s_acceptin = '1';
  176. s_validin <= '0';
  177. s_start <= '0';
  178. end loop;
  179. wait until rising_edge(s_clk);
  180. s_start <= '0';
  181. s_mode <= '0';
  182. s_validin <= '0';
  183. s_iv <= (others => '0');
  184. s_key <= (others => '0');
  185. s_datain <= (others => '0');
  186. wait for 1 us;
  187. -- Variable key known answer test
  188. s_key <= x"8000000000000000";
  189. for index in c_variable_key_known_answers'range loop
  190. wait until rising_edge(s_clk);
  191. s_validin <= '1';
  192. s_start <= '1';
  193. if(index /= 0) then
  194. if(index = 7 or index = 14 or index = 21 or index = 28 or index = 35 or
  195. index = 42 or index = 49) then
  196. s_key <= "00" & s_key(0 to 61);
  197. else
  198. s_key <= '0' & s_key(0 to 62);
  199. end if;
  200. end if;
  201. wait until rising_edge(s_clk) and s_acceptin = '1';
  202. s_validin <= '0';
  203. s_start <= '0';
  204. end loop;
  205. wait until rising_edge(s_clk);
  206. s_start <= '0';
  207. s_mode <= '0';
  208. s_validin <= '0';
  209. s_iv <= (others => '0');
  210. s_key <= (others => '0');
  211. s_datain <= (others => '0');
  212. wait for 1 us;
  213. -- Permutation operation known answer test
  214. s_datain <= x"0000000000000000";
  215. for index in c_permutation_operation_known_answers_keys'range loop
  216. wait until rising_edge(s_clk);
  217. s_validin <= '1';
  218. s_start <= '1';
  219. s_key <= c_permutation_operation_known_answers_keys(index);
  220. wait until rising_edge(s_clk) and s_acceptin = '1';
  221. s_validin <= '0';
  222. s_start <= '0';
  223. end loop;
  224. wait until rising_edge(s_clk);
  225. s_start <= '0';
  226. s_mode <= '0';
  227. s_validin <= '0';
  228. s_iv <= (others => '0');
  229. s_key <= (others => '0');
  230. s_datain <= (others => '0');
  231. wait for 1 us;
  232. -- Substitution table known answer test
  233. for index in c_substitution_table_test_keys'range loop
  234. wait until rising_edge(s_clk);
  235. s_validin <= '1';
  236. s_start <= '1';
  237. s_key <= c_substitution_table_test_keys(index);
  238. s_datain <= c_substitution_table_test_plain(index);
  239. wait until rising_edge(s_clk) and s_acceptin = '1';
  240. s_validin <= '0';
  241. s_start <= '0';
  242. end loop;
  243. wait until rising_edge(s_clk);
  244. s_start <= '0';
  245. s_mode <= '0';
  246. s_validin <= '0';
  247. s_iv <= (others => '0');
  248. s_key <= (others => '0');
  249. s_datain <= (others => '0');
  250. wait for 1 us;
  251. -- cbc known answers test
  252. for index in c_substitution_table_test_keys'range loop
  253. wait until rising_edge(s_clk);
  254. if(index = 0) then
  255. s_start <= '1';
  256. s_key <= x"5555555555555555";
  257. s_iv <= x"DEADBEEFDEADBEEF";
  258. end if;
  259. s_validin <= '1';
  260. s_datain <= c_substitution_table_test_plain(index);
  261. wait until rising_edge(s_clk) and s_acceptin = '1';
  262. s_validin <= '0';
  263. s_start <= '0';
  264. end loop;
  265. wait until rising_edge(s_clk);
  266. -- DECRYPTION TESTS
  267. s_start <= '0';
  268. s_mode <= '0';
  269. s_validin <= '0';
  270. s_iv <= (others => '0');
  271. s_key <= (others => '0');
  272. s_datain <= (others => '0');
  273. wait for 1 us;
  274. -- Variable ciphertext known answer test
  275. s_key <= x"0101010101010101";
  276. for index in c_variable_plaintext_known_answers'range loop
  277. wait until rising_edge(s_clk);
  278. s_mode <= '1';
  279. s_start <= '1';
  280. s_validin <= '1';
  281. s_datain <= c_variable_plaintext_known_answers(index);
  282. wait until rising_edge(s_clk) and s_acceptin = '1';
  283. s_validin <= '0';
  284. s_start <= '0';
  285. s_mode <= '0';
  286. end loop;
  287. wait until rising_edge(s_clk);
  288. s_start <= '0';
  289. s_mode <= '0';
  290. s_validin <= '0';
  291. s_iv <= (others => '0');
  292. s_key <= (others => '0');
  293. s_datain <= (others => '0');
  294. wait for 1 us;
  295. -- Initial permutation known answer test
  296. s_key <= x"0101010101010101";
  297. s_datain <= x"8000000000000000";
  298. for index in c_variable_plaintext_known_answers'range loop
  299. wait until rising_edge(s_clk);
  300. s_mode <= '1';
  301. s_start <= '1';
  302. s_validin <= '1';
  303. if(index /= 0) then
  304. s_datain <= '0' & s_datain(0 to 62);
  305. end if;
  306. wait until rising_edge(s_clk) and s_acceptin = '1';
  307. s_validin <= '0';
  308. s_start <= '0';
  309. s_mode <= '0';
  310. end loop;
  311. wait until rising_edge(s_clk);
  312. s_start <= '0';
  313. s_mode <= '0';
  314. s_validin <= '0';
  315. s_iv <= (others => '0');
  316. s_key <= (others => '0');
  317. s_datain <= (others => '0');
  318. wait for 1 us;
  319. -- Variable key known answer test
  320. s_key <= x"8000000000000000";
  321. for index in c_variable_key_known_answers'range loop
  322. wait until rising_edge(s_clk);
  323. s_mode <= '1';
  324. s_start <= '1';
  325. s_validin <= '1';
  326. s_datain <= c_variable_key_known_answers(index);
  327. if(index /= 0) then
  328. if(index = 7 or index = 14 or index = 21 or index = 28 or index = 35 or
  329. index = 42 or index = 49) then
  330. s_key <= "00" & s_key(0 to 61);
  331. else
  332. s_key <= '0' & s_key(0 to 62);
  333. end if;
  334. end if;
  335. wait until rising_edge(s_clk) and s_acceptin = '1';
  336. s_validin <= '0';
  337. s_start <= '0';
  338. s_mode <= '0';
  339. end loop;
  340. wait until rising_edge(s_clk);
  341. s_start <= '0';
  342. s_mode <= '0';
  343. s_validin <= '0';
  344. s_iv <= (others => '0');
  345. s_key <= (others => '0');
  346. s_datain <= (others => '0');
  347. wait for 1 us;
  348. -- Permutation operation known answer test
  349. for index in c_permutation_operation_known_answers_keys'range loop
  350. wait until rising_edge(s_clk);
  351. s_mode <= '1';
  352. s_start <= '1';
  353. s_validin <= '1';
  354. s_datain <= c_permutation_operation_known_answers_cipher(index);
  355. s_key <= c_permutation_operation_known_answers_keys(index);
  356. wait until rising_edge(s_clk) and s_acceptin = '1';
  357. s_validin <= '0';
  358. s_start <= '0';
  359. s_mode <= '0';
  360. end loop;
  361. wait until rising_edge(s_clk);
  362. s_start <= '0';
  363. s_mode <= '0';
  364. s_validin <= '0';
  365. s_iv <= (others => '0');
  366. s_key <= (others => '0');
  367. s_datain <= (others => '0');
  368. wait for 1 us;
  369. -- Substitution table known answer test
  370. for index in c_substitution_table_test_keys'range loop
  371. wait until rising_edge(s_clk);
  372. s_mode <= '1';
  373. s_start <= '1';
  374. s_validin <= '1';
  375. s_key <= c_substitution_table_test_keys(index);
  376. s_datain <= c_substitution_table_test_cipher(index);
  377. wait until rising_edge(s_clk) and s_acceptin = '1';
  378. s_validin <= '0';
  379. s_start <= '0';
  380. s_mode <= '0';
  381. end loop;
  382. wait until rising_edge(s_clk);
  383. s_start <= '0';
  384. s_mode <= '0';
  385. s_validin <= '0';
  386. s_iv <= (others => '0');
  387. s_key <= (others => '0');
  388. s_datain <= (others => '0');
  389. wait for 1 us;
  390. -- cbc known answer test
  391. for index in c_substitution_table_test_keys'range loop
  392. wait until rising_edge(s_clk);
  393. if(index = 0) then
  394. s_mode <= '1';
  395. s_start <= '1';
  396. s_key <= x"5555555555555555";
  397. s_iv <= x"DEADBEEFDEADBEEF";
  398. end if;
  399. s_validin <= '1';
  400. s_datain <= s_cbc_answers(index);
  401. wait until rising_edge(s_clk) and s_acceptin = '1';
  402. s_validin <= '0';
  403. s_start <= '0';
  404. s_mode <= '0';
  405. end loop;
  406. wait until rising_edge(s_clk);
  407. s_start <= '0';
  408. s_mode <= '0';
  409. s_validin <= '0';
  410. s_iv <= (others => '0');
  411. s_key <= (others => '0');
  412. s_datain <= (others => '0');
  413. wait;
  414. end process teststimuliP;
  415. testcheckerP : process is
  416. variable v_plaintext : std_logic_vector(0 to 63) := x"8000000000000000";
  417. begin
  418. s_acceptout <= '1';
  419. report "# ENCRYPTION TESTS";
  420. report "# Variable plaintext known answer test";
  421. for index in c_variable_plaintext_known_answers'range loop
  422. wait until rising_edge(s_clk) and s_validout = '1';
  423. assert (s_dataout = c_variable_plaintext_known_answers(index))
  424. report "encryption error"
  425. severity error;
  426. end loop;
  427. report "# Inverse permutation known answer test";
  428. for index in c_variable_plaintext_known_answers'range loop
  429. wait until rising_edge(s_clk) and s_validout = '1';
  430. assert (s_dataout = v_plaintext)
  431. report "encryption error"
  432. severity error;
  433. v_plaintext := '0' & v_plaintext(0 to 62);
  434. end loop;
  435. report "# Variable key known answer test";
  436. for index in c_variable_key_known_answers'range loop
  437. wait until rising_edge(s_clk) and s_validout = '1';
  438. assert (s_dataout = c_variable_key_known_answers(index))
  439. report "encryption error"
  440. severity error;
  441. end loop;
  442. report "# Permutation operation known answer test";
  443. for index in c_permutation_operation_known_answers_cipher'range loop
  444. wait until rising_edge(s_clk) and s_validout = '1';
  445. assert (s_dataout = c_permutation_operation_known_answers_cipher(index))
  446. report "encryption error"
  447. severity error;
  448. end loop;
  449. report "# Substitution table known answer test";
  450. for index in c_substitution_table_test_cipher'range loop
  451. wait until rising_edge(s_clk) and s_validout = '1';
  452. assert (s_dataout = c_substitution_table_test_cipher(index))
  453. report "encryption error"
  454. severity error;
  455. end loop;
  456. for index in c_substitution_table_test_cipher'range loop
  457. wait until rising_edge(s_clk) and s_validout = '1';
  458. s_cbc_answers(index) <= s_dataout;
  459. end loop;
  460. report "# DECRYPTION TESTS";
  461. report "# Variable ciphertext known answer test";
  462. v_plaintext := x"8000000000000000";
  463. for index in c_variable_plaintext_known_answers'range loop
  464. wait until rising_edge(s_clk) and s_validout = '1';
  465. assert (s_dataout = v_plaintext)
  466. report "decryption error"
  467. severity error;
  468. v_plaintext := '0' & v_plaintext(0 to 62);
  469. end loop;
  470. report "# Initial permutation known answer test";
  471. for index in c_variable_plaintext_known_answers'range loop
  472. wait until rising_edge(s_clk) and s_validout = '1';
  473. assert (s_dataout = c_variable_plaintext_known_answers(index))
  474. report "decryption error"
  475. severity error;
  476. end loop;
  477. report "# Variable key known answer test";
  478. for index in c_variable_key_known_answers'range loop
  479. wait until rising_edge(s_clk) and s_validout = '1';
  480. assert (s_dataout = x"0000000000000000")
  481. report "decryption error"
  482. severity error;
  483. end loop;
  484. report "# Permutation operation known answer test";
  485. for index in c_permutation_operation_known_answers_keys'range loop
  486. wait until rising_edge(s_clk) and s_validout = '1';
  487. assert (s_dataout = x"0000000000000000")
  488. report "decryption error"
  489. severity error;
  490. end loop;
  491. report "# Substitution table known answer test";
  492. for index in c_substitution_table_test_cipher'range loop
  493. wait until rising_edge(s_clk) and s_validout = '1';
  494. assert (s_dataout = c_substitution_table_test_plain(index))
  495. report "decryption error"
  496. severity error;
  497. end loop;
  498. report "# cbc known answer test";
  499. for index in c_substitution_table_test_cipher'range loop
  500. wait until rising_edge(s_clk) and s_validout = '1';
  501. assert (s_dataout = c_substitution_table_test_plain(index))
  502. report "decryption error"
  503. severity error;
  504. end loop;
  505. report "# Successfully passed all tests";
  506. wait for 10 us;
  507. stop(0);
  508. end process testcheckerP;
  509. i_cbcdes : entity work.cbcdes
  510. port map (
  511. reset_i => s_reset,
  512. clk_i => s_clk,
  513. start_i => s_start,
  514. mode_i => s_mode,
  515. key_i => s_key,
  516. iv_i => s_iv,
  517. data_i => s_datain,
  518. valid_i => s_validin,
  519. accept_o => s_acceptin,
  520. data_o => s_dataout,
  521. valid_o => s_validout,
  522. accept_i => s_acceptout
  523. );
  524. end architecture rtl;