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.

117 lines
3.5 KiB

  1. -- ======================================================================
  2. -- CBC-MAC-AES
  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. use work.aes_pkg.all;
  21. entity cbcmac_aes is
  22. port (
  23. reset_i : in std_logic; -- low active async reset
  24. clk_i : in std_logic; -- clock
  25. start_i : in std_logic; -- start cbc
  26. key_i : in std_logic_vector(0 to 127); -- key input
  27. data_i : in std_logic_vector(0 to 127); -- data input
  28. valid_i : in std_logic; -- input key/data valid flag
  29. accept_o : out std_logic; -- input accept
  30. data_o : out std_logic_vector(0 tO 127); -- data output
  31. valid_o : out std_logic; -- output data valid flag
  32. accept_i : in std_logic -- output accept
  33. );
  34. end entity cbcmac_aes;
  35. architecture rtl of cbcmac_aes is
  36. -- CBCMAC must have fix IV for security reasons
  37. constant C_IV : std_logic_vector(0 to 127) := (others => '0');
  38. signal s_aes_datain : std_logic_vector(0 to 127);
  39. signal s_aes_dataout : std_logic_vector(0 to 127);
  40. signal s_aes_dataout_d : std_logic_vector(0 to 127);
  41. signal s_aes_key : std_logic_vector(0 to 127);
  42. signal s_key : std_logic_vector(0 to 127);
  43. signal s_aes_accept : std_logic;
  44. signal s_aes_validout : std_logic;
  45. begin
  46. s_aes_datain <= C_IV xor data_i when start_i = '1' else
  47. s_aes_dataout_d xor data_i;
  48. data_o <= s_aes_dataout;
  49. s_aes_key <= key_i when start_i = '1' else s_key;
  50. accept_o <= s_aes_accept;
  51. valid_o <= s_aes_validout;
  52. inputregister : process (clk_i, reset_i) is
  53. begin
  54. if (reset_i = '0') then
  55. s_key <= (others => '0');
  56. elsif (rising_edge(clk_i)) then
  57. if (valid_i = '1' and s_aes_accept = '1' and start_i = '1') then
  58. s_key <= key_i;
  59. end if;
  60. end if;
  61. end process inputregister;
  62. outputregister : process (clk_i, reset_i) is
  63. begin
  64. if (reset_i = '0') then
  65. s_aes_dataout_d <= (others => '0');
  66. elsif (rising_edge(clk_i)) then
  67. if (s_aes_validout = '1') then
  68. s_aes_dataout_d <= s_aes_dataout;
  69. end if;
  70. end if;
  71. end process outputregister;
  72. i_aes : aes_enc
  73. generic map (
  74. design_type => "ITER"
  75. )
  76. port map (
  77. reset_i => reset_i,
  78. clk_i => clk_i,
  79. key_i => s_aes_key,
  80. data_i => s_aes_datain,
  81. valid_i => valid_i,
  82. accept_o => s_aes_accept,
  83. data_o => s_aes_dataout,
  84. valid_o => s_aes_validout,
  85. accept_i => accept_i
  86. );
  87. end architecture rtl;