⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testbench_small.vhd

📁 基于 xinlinx 写的DES加密算法
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

package destest_lib is


  component des_small_testbench
  end component;


  function random32 (din:std_logic_vector(31 downto 0))
                     return std_logic_vector;
  function random56 (din:std_logic_vector(55 downto 0))
                     return std_logic_vector;
  function random64 (din:std_logic_vector(63 downto 0))
                     return std_logic_vector;
end destest_lib;

                     
----------------------------------------------------------------------------
----------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
library work;
use work.destest_lib.all;

package body destest_lib is
  function random32 (din:std_logic_vector(31 downto 0))
                     return std_logic_vector is
    variable val	:std_logic_vector (31 downto 0);
  begin
    val := (din(31) xor din(6) xor din(4) xor din(2) xor din(1)) & din(31 downto 1);
    return (val);
  end random32;

  function random56 (din:std_logic_vector(55 downto 0))
                     return std_logic_vector is
    variable val	:std_logic_vector (55 downto 0);
  begin
    val := (din(55) xor din(6) xor din(3) xor din(1)) & din(55 downto 1);
    return (val);
  end random56;

  function random64 (din:std_logic_vector(63 downto 0))
                     return std_logic_vector is
    variable val	:std_logic_vector (63 downto 0);
  begin
    val := (din(63) xor din(3) xor din(2) xor din(0)) & din(63 downto 1);
    return (val);
  end random64;

end destest_lib;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
library work;
use work.des_lib.all;
use work.destest_lib.all;


entity des_small_testbench is
--  port();
end des_small_testbench;


architecture arch_des_small_testbench of des_small_testbench is
  signal clk		:std_logic := '1';
  signal reset		:std_logic := '1';
  signal key		:std_logic_vector (55 downto 0) := "00000000000000000000000000000000000000000000000000000000";
  signal din		:std_logic_vector (63 downto 0) := "0000000000000000000000000000000000000000000000000000000000000000";
  signal din_valid	:std_logic := '0'; 
  signal dout1		:std_logic_vector (63 downto 0) := "0000000000000000000000000000000000000000000000000000000000000000";
  signal dout2		:std_logic_vector (63 downto 0) := "0000000000000000000000000000000000000000000000000000000000000000";
  signal dout_valid1	:std_logic := '0';
  signal dout_valid2	:std_logic := '0';
  signal encrypt_flag	:std_logic := '1';
  signal decrypt_flag   :std_logic := '0';
  signal busy1		:std_logic := '1';
  signal busy2		:std_logic := '1';
  
begin
  process (clk)
  begin
    if clk='1' then
      clk <= '0' after 20ns, '1' after 40ns;
    end if;
  end process;

  reset <= '1' after 0ns, '0' after 125ns;

  -- Generate the random key's and random data
  process (reset, clk, busy1, busy2)
  begin
    if reset='1' then
      din_valid <= '0';
      din <= "0010100100110110001001011011001111001011001001100010010100011001";
      key <= "10100101010010010100101010001101010001011001111110000111";
    elsif clk'event and clk='1' then
      --if dout_valid2='1' then
      if din_valid='0' and busy1='0' and busy2='0' and dout_valid1='0' and dout_valid2='0' then
        din_valid <= '1';
        din <= random64(din);
        key <= random56(key);
      else
        din_valid <= '0';
      end if;     
    end if;
  end process;
    

  -- Do the DES encryption/decryption blocks
  encrypt_flag <= '1';
  decrypt_flag <= '0';
  DES0:  des_small port map (clk, reset, encrypt_flag, key, din,   din_valid,   busy1, dout1, dout_valid1);
  DES1:  des_small port map (clk, reset, decrypt_flag, key, dout1, dout_valid1, busy2, dout2, dout_valid2);


  -- Verify the unencrypted output
  process (clk, din, dout_valid2)
    variable check  :std_logic_vector (63 downto 0);
  begin
    if clk'event and clk='1' then
      if dout_valid2='1' then
        if din/=dout2 then         
          assert 1=0
            report "Simulation Ended, DES Small Failed!!!!!!!!!!!!!!!!!!!!!!!!!"
            severity failure;
        end if;
      end if;
    end if;
  end process;

end arch_des_small_testbench;











⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -