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.

125 lines
3.3 KiB

  1. -- ======================================================================
  2. -- AES Counter mode testbench
  3. -- Copyright (C) 2020 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. library osvvm;
  21. use osvvm.RandomPkg.all;
  22. use std.env.all;
  23. entity tb_ctraes is
  24. end entity tb_ctraes;
  25. architecture sim of tb_ctraes is
  26. constant C_NONCE_WIDTH : natural range 64 to 96 := 96;
  27. signal s_reset : std_logic := '0';
  28. signal s_clk : std_logic := '0';
  29. signal s_start : std_logic := '0';
  30. signal s_nonce : std_logic_vector(0 to C_NONCE_WIDTH-1) := (others => '0');
  31. signal s_key : std_logic_vector(0 to 127) := (others => '0');
  32. signal s_datain : std_logic_vector(0 to 127) := (others => '0');
  33. signal s_validin : std_logic := '0';
  34. signal s_acceptin : std_logic;
  35. signal s_dataout : std_logic_vector(0 to 127);
  36. signal s_validout : std_logic := '0';
  37. signal s_acceptout : std_logic := '0';
  38. begin
  39. i_ctraes : entity work.ctraes
  40. generic map (
  41. NONCE_WIDTH => C_NONCE_WIDTH
  42. )
  43. port map (
  44. reset_i => s_reset,
  45. clk_i => s_clk,
  46. start_i => s_start,
  47. nonce_i => s_nonce,
  48. key_i => s_key,
  49. data_i => s_datain,
  50. valid_i => s_validin,
  51. accept_o => s_acceptin,
  52. data_o => s_dataout,
  53. valid_o => s_validout,
  54. accept_i => s_acceptout
  55. );
  56. s_clk <= not(s_clk) after 10 ns;
  57. s_reset <= '1' after 100 ns;
  58. process is
  59. variable v_random : RandomPType;
  60. begin
  61. v_random.InitSeed(v_random'instance_name);
  62. wait until s_reset = '1' and rising_edge(s_clk);
  63. -- ENCRYPTION TESTs
  64. report "Test encryption";
  65. for i in 0 to 31 loop
  66. if (i = 0) then
  67. s_start <= '1';
  68. s_nonce <= v_random.RandSlv(s_nonce'length);
  69. else
  70. s_start <= '0';
  71. end if;
  72. s_validin <= '1';
  73. s_key <= v_random.RandSlv(128);
  74. s_datain <= v_random.RandSlv(128);
  75. report "Test #" & to_string(i);
  76. wait until s_acceptin = '1' and rising_edge(s_clk);
  77. s_validin <= '0';
  78. end loop;
  79. -- Watchdog
  80. wait for 1 us;
  81. report "Watchdog error"
  82. severity failure;
  83. end process;
  84. process is
  85. begin
  86. s_acceptout <= '0';
  87. for i in 0 to 31 loop
  88. wait until s_validout = '1' and rising_edge(s_clk);
  89. s_acceptout <= '1';
  90. wait until rising_edge(s_clk);
  91. s_acceptout <= '0';
  92. end loop;
  93. report "Tests finished";
  94. wait for 100 ns;
  95. finish(0);
  96. end process;
  97. end architecture sim;