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.

129 lines
3.7 KiB

11 years ago
11 years ago
  1. -- ======================================================================
  2. -- AES encryption/decryption
  3. -- Copyright (C) 2019 Torsten Meissner
  4. -------------------------------------------------------------------------
  5. -- This program is free software; you can redistribute it and/or modify
  6. -- it under the terms of the GNU General Public License as published by
  7. -- the Free Software Foundation; either version 2 of the License, or
  8. -- (at your option) any later version.
  9. -- This program is distributed in the hope that it will be useful,
  10. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. -- GNU General Public License for more details.
  13. -- You should have received a copy of the GNU General Public License
  14. -- along with this program; if not, write to the Free Software
  15. -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. -- ======================================================================
  17. library ieee;
  18. use ieee.std_logic_1164.all;
  19. use ieee.numeric_std.all;
  20. use std.env.all;
  21. use work.aes_pkg.all;
  22. entity tb_aes is
  23. end entity tb_aes;
  24. architecture rtl of tb_aes is
  25. signal s_reset : std_logic := '0';
  26. signal s_clk : std_logic := '0';
  27. signal s_mode : std_logic := '0';
  28. signal s_key : std_logic_vector(0 to 127) := (others => '0');
  29. signal s_datain : std_logic_vector(0 to 127) := (others => '0');
  30. signal s_validin_enc : std_logic := '0';
  31. signal s_acceptout_enc : std_logic;
  32. signal s_dataout_enc : std_logic_vector(0 to 127);
  33. signal s_validout_enc : std_logic;
  34. signal s_acceptin_enc : std_logic := '0';
  35. signal s_validin_dec : std_logic := '0';
  36. signal s_acceptout_dec : std_logic;
  37. signal s_dataout_dec : std_logic_vector(0 to 127);
  38. signal s_validout_dec : std_logic;
  39. signal s_acceptin_dec : std_logic := '0';
  40. begin
  41. s_clk <= not(s_clk) after 10 ns;
  42. s_reset <= '1' after 100 ns;
  43. i_aes_enc : aes_enc
  44. port map (
  45. reset_i => s_reset,
  46. clk_i => s_clk,
  47. key_i => s_key,
  48. data_i => s_datain,
  49. valid_i => s_validin_enc,
  50. accept_o => s_acceptout_enc,
  51. data_o => s_dataout_enc,
  52. valid_o => s_validout_enc,
  53. accept_i => s_acceptin_enc
  54. );
  55. i_aes_dec : aes_dec
  56. port map (
  57. reset_i => s_reset,
  58. clk_i => s_clk,
  59. key_i => s_key,
  60. data_i => s_datain,
  61. valid_i => s_validin_dec,
  62. accept_o => s_acceptout_dec,
  63. data_o => s_dataout_dec,
  64. valid_o => s_validout_dec,
  65. accept_i => s_acceptin_dec
  66. );
  67. process is
  68. begin
  69. wait until s_reset = '1';
  70. -- ENCRYPTION TEST
  71. report "Test encryption";
  72. wait until rising_edge(s_clk);
  73. s_validin_enc <= '1';
  74. s_key <= x"2b7e151628aed2a6abf7158809cf4f3c";
  75. s_datain <= x"3243f6a8885a308d313198a2e0370734";
  76. wait until s_acceptout_enc = '1' and rising_edge(s_clk);
  77. s_validin_enc <= '0';
  78. wait until s_validout_enc = '1' and rising_edge(s_clk);
  79. s_acceptin_enc <= '1';
  80. assert s_dataout_enc = x"3925841D02DC09FBDC118597196A0B32"
  81. report "Encryption error"
  82. severity failure;
  83. s_datain <= s_dataout_enc;
  84. wait until rising_edge(s_clk);
  85. s_acceptin_enc <= '0';
  86. -- DECRYPTION TEST
  87. report "Test decryption";
  88. wait until rising_edge(s_clk);
  89. s_validin_dec <= '1';
  90. wait until s_acceptout_dec = '1' and rising_edge(s_clk);
  91. s_validin_dec <= '0';
  92. wait until s_validout_dec = '1' and rising_edge(s_clk);
  93. s_acceptin_dec <= '1';
  94. assert s_dataout_dec = x"3243f6a8885a308d313198a2e0370734"
  95. report "Decryption error"
  96. severity failure;
  97. wait until rising_edge(s_clk);
  98. s_acceptin_dec <= '0';
  99. wait for 100 ns;
  100. report "Tests successful";
  101. finish(0);
  102. end process;
  103. end architecture rtl;