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.

128 lines
3.7 KiB

10 years ago
10 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_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. report "Test decryption";
  87. wait until rising_edge(s_clk);
  88. s_validin_dec <= '1';
  89. wait until s_acceptout_dec = '1' and rising_edge(s_clk);
  90. s_validin_dec <= '0';
  91. wait until s_validout_dec = '1' and rising_edge(s_clk);
  92. s_acceptin_dec <= '1';
  93. assert s_dataout_dec = x"3243f6a8885a308d313198a2e0370734"
  94. report "Decryption error"
  95. severity failure;
  96. wait until rising_edge(s_clk);
  97. s_acceptin_dec <= '0';
  98. wait for 100 ns;
  99. report "Tests successful";
  100. finish(0);
  101. end process;
  102. end architecture rtl;