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

📄 sha1_top.vhd

📁 sha_1加密运算模块
💻 VHD
📖 第 1 页 / 共 4 页
字号:
----------------------------------------------------
--  
--  Library Name :  SHA1_LEAST
--  Unit    Name :  SHA1_CTRL
--  Unit    Type :  State Machine
--  
------------------------------------------------------
 library ieee;use ieee.STD_LOGIC_1164.all;use ieee.STD_LOGIC_ARITH.all;use ieee.STD_LOGIC_UNSIGNED.all;entity SHA1_CTRL is  port (        SCEN1 : out std_logic;        SCEN2 : out std_logic;        SCEN4 : out std_logic;        SWEN1 : out std_logic;        SWEN2 : out std_logic;        SWEN4 : out std_logic;        SADDR1 : out std_logic_vector(2 downto 0 );        SADDR2 : out std_logic_vector(2 downto 0 );        SADDR4 : out std_logic_vector(2 downto 0 );        RAM1_4S : out std_logic_vector(1 downto 0 );        A_LOGA_CTRL : out std_logic_vector(1 downto 0 );        A_LOGB_CTRL : out std_logic_vector(1 downto 0 );        NOT_CTRL : out std_logic;        REGIN_CTRL : out std_logic_vector(2 downto 0 );        CLK : in std_logic;        RST : in std_logic;        E1 : out std_logic;        E2 : out std_logic;        E3 : out std_logic;        E4 : out std_logic;        BUSY : out std_logic;        E : in std_logic;        OV : out std_logic        ); end SHA1_CTRL;  architecture SHA1_CTRL of SHA1_CTRL is   signal AD1 : std_logic_vector(2 downto 0 );  signal AD4 : std_logic_vector(2 downto 0 );  signal VIN : std_logic_vector(2 downto 0 );  signal CW : std_logic_vector(1 downto 0 );  signal LUN : std_logic_vector(1 downto 0 );  signal COUNT : std_logic_vector(4 downto 0 );   type visual_S0_states is (S0, S7, S15, S41, S17, S19, S22, S27, S28, S29, S31,                            S34, S36, S37, S45, S21, S38, S39, S20, S8, S44, S12                            , S9, S10, S11);  signal visual_S0_current : visual_S0_states;  begin     -- Synchronous process  SHA1_CTRL_S0:  process (CLK, RST)  begin     if (RST = '0') then      SCEN1<='1';SWEN1<='1';AD1<="000";      SCEN2<='1';SWEN2<='1';SADDR2<="000";      SCEN4<='1';SWEN4<='1';AD4<="000";      A_LOGA_CTRL<="00";A_LOGB_CTRL<="00";      NOT_CTRL<='0';REGIN_CTRL<="000";      E1<='0';E2<='0';E3<='0';E4<='0';      RAM1_4S<="00";VIN<="000";CW<="00";      LUN<="00";COUNT<="00000";OV<='0';      BUSY<='0';      visual_S0_current <= S0;    elsif (CLK'event and CLK = '0') then       case visual_S0_current is        when S0 =>          if (E = '1') then            BUSY<='1';            visual_S0_current <= S7;          else            visual_S0_current <= S0;          end if;         when S15 =>          SCEN1<='1';SWEN1<='1';          SCEN4<='1';SWEN4<='1';          visual_S0_current <= S17;         when S41 =>          SCEN1<='1';SWEN1<='1';AD1<="000";          SCEN2<='1';SWEN2<='1';SADDR2<="000";          SCEN4<='1';SWEN4<='1';AD4<="000";          A_LOGA_CTRL<="00";A_LOGB_CTRL<="00";          NOT_CTRL<='0';REGIN_CTRL<="000";          E1<='0';E2<='0';E3<='0';E4<='0';          RAM1_4S<="00";VIN<="000";CW<="00";          LUN<="00";COUNT<="00000";OV<='0';          BUSY<='0';          visual_S0_current <= S0;         when S7 =>          if (VIN = "100") then            A_LOGA_CTRL<="11";NOT_CTRL<='0';            REGIN_CTRL<="100";E3<='0';VIN<=VIN+1;            E4<='1';            visual_S0_current <= S7;          elsif (VIN = "001") then            A_LOGA_CTRL<="00";NOT_CTRL<='0';            REGIN_CTRL<="100";E1<='1';VIN<=VIN+1;            visual_S0_current <= S7;          elsif (VIN = "010") then            A_LOGA_CTRL<="01";NOT_CTRL<='0';            REGIN_CTRL<="100";E1<='0';VIN<=VIN+1;            E2<='1';            visual_S0_current <= S7;          elsif (VIN = "011") then            A_LOGA_CTRL<="10";NOT_CTRL<='0';            REGIN_CTRL<="100";E2<='0';VIN<=VIN+1;            E3<='1';            visual_S0_current <= S7;          elsif (VIN = "000") then            SCEN2<='0';SWEN2<='1';SADDR2<="000";            VIN<=VIN+1;RAM1_4S<="01";            visual_S0_current <= S7;          elsif (VIN = "101") then            E4<='0';SCEN1<='0';SWEN1<='0';AD1<="101";            SCEN4<='0';SWEN4<='0';AD4<="110";VIN<=VIN+1;            visual_S0_current <= S7;          elsif (VIN = "110") then            SCEN1<='1';SWEN1<='1';            SCEN4<='1';SWEN4<='1';VIN<=VIN+1;            SCEN2<='0';SWEN2<='1';RAM1_4S<="01";            SADDR2<="001";            visual_S0_current <= S7;          elsif (VIN = "111" and CW = "00") then            A_LOGA_CTRL<="00";NOT_CTRL<='0';            REGIN_CTRL<="100";E1<='1';CW<=CW+1;            visual_S0_current <= S7;          elsif (CW = "01") then            E1<='0';            SCEN4<='0';SWEN4<='0';AD4<="111";CW<=CW+1;            visual_S0_current <= S7;          elsif (CW = "10") then            SCEN4<='1';SWEN4<='1';            CW<="00";VIN<="000";            AD1<="000";AD4<="000";            visual_S0_current <= S20;          else            visual_S0_current <= S7;          end if;         when S17 =>          if (VIN = "000") then            SCEN1<='0';SWEN1<='1';AD1<="101";            RAM1_4S<="00";VIN<=VIN+1;            visual_S0_current <= S17;          elsif (VIN = "001") then            A_LOGA_CTRL<="00";REGIN_CTRL<="101";            E1<='1';VIN<=VIN+1;            visual_S0_current <= S17;          elsif (VIN = "010") then            E1<='0';VIN<=VIN+1;            visual_S0_current <= S17;          elsif (VIN = "011") then            SCEN1<='0';SWEN1<='0';AD1<="111";            VIN<=VIN+1;            visual_S0_current <= S17;          elsif (VIN = "100") then            SCEN1<='0';SWEN1<='1';AD1<="111";            SCEN2<='0';SWEN2<='1';SADDR2<="001";            RAM1_4S<="01";            VIN<=VIN+1;            visual_S0_current <= S17;          elsif (VIN = "101" and CW = "00") then            A_LOGA_CTRL<="00";A_LOGB_CTRL<="00";            REGIN_CTRL<="000";E1<='1';CW<=CW+1;            visual_S0_current <= S17;          elsif (VIN = "101" and CW = "01") then            SCEN1<='0';SWEN1<='0';AD1<="111";            E1<='0';CW<=CW+1;            visual_S0_current <= S17;          elsif (VIN = "101" and CW = "10") then            SCEN1<='0';SWEN1<='1';AD1<="111";            SCEN2<='0';SWEN2<='1';SADDR2<="010";            RAM1_4S<="01";CW<=CW+1;            visual_S0_current <= S17;          elsif (VIN = "101" and CW = "11") then            VIN<="000";CW<="00";A_LOGB_CTRL<="00";            REGIN_CTRL<="000";E1<='1';            if LUN=0 then A_LOGA_CTRL<="00";            elsif LUN=1 then A_LOGA_CTRL<="01";            elsif LUN=2 then A_LOGA_CTRL<="10";            elsif LUN=3 then A_LOGA_CTRL<="11";            end if;            visual_S0_current <= S19;          else            visual_S0_current <= S17;          end if;         when S19 =>          if (VIN = "000") then            SCEN2<='0';SWEN2<='0';SADDR2<="111";            E1<='0';VIN<=VIN+1;            visual_S0_current <= S19;          elsif (VIN = "001") then            SCEN2<='0';SWEN2<='1';SADDR2<="111";            SCEN1<='0';SWEN1<='1';RAM1_4S<="01";VIN<=VIN+1;            if COUNT=0 OR COUNT=1 OR COUNT=2 OR COUNT=3               then  AD1<="000";            elsif COUNT=4 OR COUNT=5 OR COUNT=6 OR COUNT=7               then  AD1<="001";            elsif COUNT=8 OR COUNT=9 OR COUNT=10 OR COUNT=11               then  AD1<="010";            elsif COUNT=12 OR COUNT=13 OR COUNT=14 OR COUNT=15               then  AD1<="011";            elsif COUNT=16 OR COUNT=17 OR COUNT=18 OR COUNT=19               then  AD1<="100";            end if;            visual_S0_current <= S19;          elsif (VIN = "010") then            A_LOGA_CTRL<="00";VIN<=VIN+1;            if COUNT=0 OR COUNT=4 OR COUNT=8 OR COUNT=12 OR COUNT=16              then A_LOGB_CTRL<="00";            elsif COUNT=1 OR COUNT=5 OR COUNT=9 OR COUNT=13 OR COUNT=17              then A_LOGB_CTRL<="01";            elsif COUNT=2 OR COUNT=6 OR COUNT=10 OR COUNT=14 OR COUNT=18              then A_LOGB_CTRL<="10";            elsif COUNT=3 OR COUNT=7 OR COUNT=11 OR COUNT=15 OR COUNT=19              then A_LOGB_CTRL<="11";            end if;            visual_S0_current <= S19;          elsif (VIN = "011") then            REGIN_CTRL<="000";E1<='1';            VIN<=VIN+1;            visual_S0_current <= S19;          elsif (VIN = "100") then            if (LUN = "00") then              SCEN1<='0';SWEN1<='0';AD1<="111";              E1<='0';VIN<="000";CW<="00";              visual_S0_current <= S22;            elsif (LUN = "01" or LUN = "11") then              SCEN1<='0';SWEN1<='0';AD1<="111";              E1<='0';VIN<="000";CW<="00";              visual_S0_current <= S27;            elsif (LUN = "10") then              SCEN1<='0';SWEN1<='0';AD1<="111";              E1<='0';VIN<="000";CW<="00";              visual_S0_current <= S28;            else              SCEN1<='0';SWEN1<='0';AD1<="111";              E1<='0';VIN<="000";CW<="00";              visual_S0_current <= S17;            end if;          else            visual_S0_current <= S19;          end if;         when S22 =>          if (VIN = "010") then            A_LOGA_CTRL<="01";REGIN_CTRL<="100";            NOT_CTRL<='1';VIN<=VIN+1;E1<='0';E2<='1';            visual_S0_current <= S22;          elsif (VIN = "000") then            SCEN1<='0';SWEN1<='1';AD1<="101";            VIN<=VIN+1;RAM1_4S<="00";            visual_S0_current <= S22;          elsif (CW = "01" and VIN = "101") then            SCEN1<='0';SWEN1<='0';E2<='0';AD1<="110";            CW<=CW+1;            visual_S0_current <= S22;          elsif (VIN = "011") then            E2<='0';SCEN2<='0';SWEN2<='0';SADDR2<="111";            VIN<=VIN+1;            visual_S0_current <= S22;          elsif (VIN = "100") then            SCEN1<='0';SWEN1<='1';AD1<="101";            SCEN2<='0';SWEN2<='1';SADDR2<="111";            RAM1_4S<="01";VIN<=VIN+1;            visual_S0_current <= S22;          elsif (VIN = "101" and CW = "00") then            A_LOGA_CTRL<="01";A_LOGB_CTRL<="11";REGIN_CTRL<="001";            CW<=CW+1;E2<='1';            visual_S0_current <= S22;          elsif (VIN = "001") then            A_LOGA_CTRL<="01";A_LOGB_CTRL<="10";            REGIN_CTRL<="001";E1<='1';VIN<=VIN+1;            visual_S0_current <= S22;          elsif (CW = "11" and VIN = "101") then            A_LOGA_CTRL<="00";A_LOGB_CTRL<="01";            REGIN_CTRL<="010";E1<='1';VIN<=VIN+1;            visual_S0_current <= S22;          elsif (VIN = "110") then            SCEN2<='0';SWEN2<='0';SADDR2<="110";            E1<='0';VIN<=VIN+1;            visual_S0_current <= S22;          elsif (VIN = "111") then            VIN<="000";CW<="00";            SCEN1<='0';SWEN1<='1';AD1<="111";            SCEN2<='0';SWEN2<='1';SADDR2<="110";            RAM1_4S<="01";            visual_S0_current <= S31;          elsif (CW = "10" and VIN = "101") then            SCEN1<='0';SWEN1<='1';AD1<="110";            CW<=CW+1;RAM1_4S<="00";            visual_S0_current <= S22;          else            visual_S0_current <= S22;          end if;         when S27 =>          if (VIN = "000") then            SCEN1<='0';SWEN1<='1';AD1<="101";            VIN<=VIN+1;RAM1_4S<="00";            visual_S0_current <= S27;          elsif (VIN = "001") then            A_LOGA_CTRL<="01";A_LOGB_CTRL<="10";            REGIN_CTRL<="011";E1<='1';VIN<=VIN+1;            visual_S0_current <= S27;          elsif (VIN = "010") then            SCEN1<='0';SWEN1<='0';AD1<="110";E1<='0';            VIN<=VIN+1;            visual_S0_current <= S27;          elsif (VIN = "011") then            SCEN1<='0';SWEN1<='1';AD1<="110";            SCEN2<='0';SWEN2<='1';SADDR2<="000";            RAM1_4S<="01";VIN<=VIN+1;            visual_S0_current <= S27;          elsif (VIN = "100") then            A_LOGA_CTRL<="11";A_LOGB_CTRL<="00";            REGIN_CTRL<="011";E1<='1';VIN<=VIN+1;            visual_S0_current <= S27;          elsif (VIN = "101") then            SCEN2<='0';SWEN2<='0';SADDR2<="110";            E1<='0';VIN<=VIN+1;            visual_S0_current <= S27;          elsif (VIN = "110") then            VIN<="000";            SCEN1<='0';SWEN1<='1';AD1<="111";            SCEN2<='0';SWEN2<='1';SADDR2<="110";            RAM1_4S<="01";            visual_S0_current <= S31;          else            visual_S0_current <= S27;          end if;         when S28 =>          if (VIN = "001") then            A_LOGA_CTRL<="01";A_LOGB_CTRL<="10";            REGIN_CTRL<="001";E1<='1';VIN<=VIN+1;            visual_S0_current <= S28;          elsif (VIN = "010") then            A_LOGA_CTRL<="01";A_LOGB_CTRL<="11";            REGIN_CTRL<="001";E2<='1';VIN<=VIN+1;E1<='0';            visual_S0_current <= S28;          elsif (CW = "01" and VIN = "101") then            A_LOGA_CTRL<="00";A_LOGB_CTRL<="01";            REGIN_CTRL<="010";E1<='1';CW<=CW+1;            visual_S0_current <= S28;          elsif (VIN = "011") then            A_LOGA_CTRL<="10";A_LOGB_CTRL<="11";            REGIN_CTRL<="001";E3<='1';VIN<=VIN+1;E2<='0';            visual_S0_current <= S28;          elsif (VIN = "100") then            E3<='0';SCEN1<='0';SWEN1<='0';            AD1<="110";VIN<=VIN+1;            visual_S0_current <= S28;          elsif (VIN = "000") then            SCEN1<='0';SWEN1<='1';AD1<="101";            RAM1_4S<="00";VIN<=VIN+1;            visual_S0_current <= S28;          elsif (VIN = "101" and CW = "00") then            SCEN1<='0';SWEN1<='1';AD1<="110";            RAM1_4S<="00";CW<=CW+1;            visual_S0_current <= S28;          elsif (CW = "10" and VIN = "101") then            SCEN1<='0';SWEN1<='0';AD1<="110";            E1<='0';CW<=CW+1;            visual_S0_current <= S28;          elsif (CW = "11" and VIN = "101") then            SCEN1<='0';SWEN1<='1';            AD1<="110";VIN<=VIN+1;            RAM1_4S<="00";            visual_S0_current <= S28;          elsif (VIN = "110") then            A_LOGA_CTRL<="00";A_LOGB_CTRL<="10";            REGIN_CTRL<="010";E1<='1';VIN<=VIN+1;            visual_S0_current <= S28;          elsif (VIN = "111") then            SCEN2<='0';SWEN2<='0';SADDR2<="110";            E1<='0';CW<="00";VIN<="000";            visual_S0_current <= S29;          else            visual_S0_current <= S28;          end if;         when S29 =>          SCEN1<='0';SWEN1<='1';AD1<="111";          SCEN2<='0';SWEN2<='1';SADDR2<="110";          RAM1_4S<="01";          visual_S0_current <= S31;         when S31 =>          if (VIN = "000") then            A_LOGA_CTRL<="00";A_LOGB_CTRL<="00";            REGIN_CTRL<="000";E1<='1';VIN<=VIN+1;            visual_S0_current <= S31;          elsif (VIN = "010" and CW = "11") then            A_LOGA_CTRL<="01";E4<='0';            REGIN_CTRL<="110";E3<='1';CW<="00";            VIN<=VIN+1;

⌨️ 快捷键说明

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