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.

127 lines
3.6 KiB

10 years ago
10 years ago
  1. -- ======================================================================
  2. -- AES encryption/decryption testbench
  3. -- tests according to NIST 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. library ieee;
  19. use ieee.std_logic_1164.all;
  20. use ieee.numeric_std.all;
  21. use std.env.all;
  22. use work.aes_pkg.all;
  23. entity tb_aes is
  24. end entity tb_aes;
  25. architecture rtl of tb_aes is
  26. signal s_reset : std_logic := '0';
  27. signal s_clk : std_logic := '0';
  28. signal s_mode : std_logic := '0';
  29. signal s_key : std_logic_vector(0 to 127) := (others => '0');
  30. signal s_datain : std_logic_vector(0 to 127) := (others => '0');
  31. signal s_validin_enc : std_logic := '0';
  32. signal s_acceptout_enc : std_logic;
  33. signal s_dataout_enc : std_logic_vector(0 to 127);
  34. signal s_validout_enc : std_logic;
  35. signal s_acceptin_enc : std_logic := '0';
  36. signal s_validin_dec : std_logic := '0';
  37. signal s_acceptout_dec : std_logic;
  38. signal s_dataout_dec : std_logic_vector(0 to 127);
  39. signal s_validout_dec : std_logic;
  40. signal s_acceptin_dec : std_logic := '0';
  41. begin
  42. s_clk <= not(s_clk) after 10 ns;
  43. s_reset <= '1' after 100 ns;
  44. i_aes_enc : aes_enc
  45. port map (
  46. reset_i => s_reset,
  47. clk_i => s_clk,
  48. key_i => s_key,
  49. data_i => s_datain,
  50. valid_i => s_validin_enc,
  51. accept_o => s_acceptout_enc,
  52. data_o => s_dataout_enc,
  53. valid_o => s_validout_enc,
  54. accept_i => s_acceptin_enc
  55. );
  56. i_aes_dec : aes_dec
  57. port map (
  58. reset_i => s_reset,
  59. clk_i => s_clk,
  60. key_i => s_key,
  61. data_i => s_datain,
  62. valid_i => s_validin_dec,
  63. accept_o => s_acceptout_dec,
  64. data_o => s_dataout_dec,
  65. valid_o => s_validout_dec,
  66. accept_i => s_acceptin_dec
  67. );
  68. process is
  69. begin
  70. wait until s_reset = '1';
  71. -- ENCRYPTION TEST
  72. wait until rising_edge(s_clk);
  73. s_validin_enc <= '1';
  74. s_datain <= x"3243f6a8885a308d313198a2e0370734";
  75. wait until s_acceptout_enc = '1' and rising_edge(s_clk);
  76. s_validin_enc <= '0';
  77. wait until s_validout_enc = '1' and rising_edge(s_clk);
  78. s_acceptin_enc <= '1';
  79. assert s_dataout_enc = x"3925841D02DC09FBDC118597196A0B32"
  80. report "Encryption error"
  81. severity failure;
  82. s_datain <= s_dataout_enc;
  83. wait until rising_edge(s_clk);
  84. s_acceptin_enc <= '0';
  85. -- DECRYPTION TEST
  86. wait until rising_edge(s_clk);
  87. s_validin_dec <= '1';
  88. wait until s_acceptout_dec = '1' and rising_edge(s_clk);
  89. s_validin_dec <= '0';
  90. wait until s_validout_dec = '1' and rising_edge(s_clk);
  91. s_acceptin_dec <= '1';
  92. assert s_dataout_dec = x"3243f6a8885a308d313198a2e0370734"
  93. report "Decryption error"
  94. severity failure;
  95. wait until rising_edge(s_clk);
  96. s_acceptin_dec <= '0';
  97. wait for 100 ns;
  98. finish(0);
  99. end process;
  100. end architecture rtl;