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.

73 lines
2.1 KiB

  1. library ieee ;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use std.env.all;
  5. use work.uart_aes_ref.all;
  6. entity tb_uart_aes is
  7. end entity tb_uart_aes;
  8. architecture sim of tb_uart_aes is
  9. signal s_clk : std_logic := '1';
  10. signal s_rst_n : std_logic := '0';
  11. signal s_uart_rx : std_logic := '1';
  12. signal s_uart_tx : std_logic;
  13. constant c_baudrate : natural := 9600;
  14. constant c_period_ns : time := 1_000_000_000 / c_baudrate * ns;
  15. package uart_aes_sim_inst is new work.uart_aes_sim
  16. generic map (period_ns => c_period_ns);
  17. use uart_aes_sim_inst.all;
  18. begin
  19. dut : entity work.uart_aes
  20. port map (
  21. clk_i => s_clk,
  22. rst_n_i => s_rst_n,
  23. uart_rx_i => s_uart_rx,
  24. uart_tx_o => s_uart_tx
  25. );
  26. s_rst_n <= '1' after 120 ns;
  27. s_clk <= not s_clk after 50 ns;
  28. TestP : process is
  29. variable v_data : std_logic_vector(7 downto 0);
  30. variable v_uart_data : std_logic_vector(0 to 127);
  31. variable v_key : std_logic_vector(0 to 127);
  32. variable v_nonce : std_logic_vector(0 to 95);
  33. variable v_in_data : std_logic_vector(0 to 127);
  34. variable v_ref_data : std_logic_vector(0 to 127);
  35. begin
  36. wait until s_rst_n;
  37. wait until rising_edge(s_clk);
  38. wait for 200 us;
  39. v_key := x"0123456789ABCDEF0123456789ABCDEF";
  40. v_nonce := x"0123456789ABCDEF01234567";
  41. aes_setup(v_key, v_nonce, s_uart_rx);
  42. for i in 0 to 7 loop
  43. report "Test round " & to_string(i);
  44. v_in_data := x"0123456789ABCDEF0123456789ABCDEF";
  45. aes_write(v_in_data, s_uart_rx);
  46. aes_crypt(s_uart_rx, s_uart_tx);
  47. aes_read(v_uart_data, s_uart_rx, s_uart_tx);
  48. -- Calc reference data
  49. cryptData(swap(v_in_data), swap(v_key), swap(v_nonce & 32x"0"), i=0, i=7, v_ref_data, v_in_data'length/8);
  50. assert v_uart_data = swap(v_ref_data)
  51. report "Encryption error: Expected 0x" & to_hstring(swap(v_ref_data)) & ", got 0x" & to_hstring(v_uart_data)
  52. severity failure;
  53. end loop;
  54. wait for 100 us;
  55. report "Simulation finished without errors";
  56. stop(0);
  57. end process;
  58. end architecture;