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

📄 rijndaelimplemetation.vhdl

📁 rijndael算法的一个vhdl语言编写的程序,可供学习者参考交流
💻 VHDL
📖 第 1 页 / 共 4 页
字号:
      when "1110"=>         temp1    := (b(6 downto 0) & '0') xor (("00011011") and and_mask);         and_mask := temp1(7) & temp1(7) & temp1(7) & temp1(7) &                      temp1(7) & temp1(7) & temp1(7) & temp1(7);         temp2    := (temp1(6 downto 0) & '0') xor (("00011011") and and_mask);         and_mask := temp2(7) & temp2(7) & temp2(7) & temp2(7) &                      temp2(7) & temp2(7) & temp2(7) & temp2(7);         temp3    := (temp2(6 downto 0) & '0') xor (("00011011") and and_mask);         temp     := temp1 xor temp2 xor temp3;      when others =>         temp := ( others => '0' );   end case;   return temp; end POLY_MULTD_FUNCT;-- ==========================================================================----  function ADD_ROUNDKEY_FUNCT----  Performs the roundkey addition function implemented as combinational --  logic as described in the RIJNDAEL algorithm specification.---- ==========================================================================function ADD_ROUNDKEY_FUNCT ( roundkey : KEY_TYPE;                              state    : STATE_TYPE)                              return STATE_TYPE is-- pragma map_to_operator ADD_ROUNDKEY_FUNCT_dw_op-- pragma return_port_name ADD_ROUNDKEY_FUNCT_outvariable row    : integer range 0 to 3;variable column : integer range 0 to 3;variable b      : STATE_TYPE;begin   for row in 0 to 3 loop      for column in 0 to 3 loop         b(row)(column) := state(row)(column) xor roundkey(row)(column);      end loop;   end loop;   return b;end ADD_ROUNDKEY_FUNCT;-- ==========================================================================-- ==========================================================================----  procedure ADD_ROUNDKEY----  Wrapper for ROUND_KEY function---- ==========================================================================procedure ADD_ROUNDKEY ( state     :  in STATE_TYPE;                         roundkey  :  in KEY_TYPE;                  signal state_out :  out STATE_TYPE ) isbegin   state_out <= ADD_ROUNDKEY_FUNCT ( roundkey, state );end ADD_ROUNDKEY;-- ==========================================================================----  procedure PRE_ADD----  Wrapper for PRE_ADD function---- ==========================================================================procedure PRE_ADD ( state     : in STATE_TYPE;                    encrypt   : in std_logic;                    roundkey  : in KEY_TYPE;             signal state_out : out STATE_TYPE ) isbegin   if encrypt = '1' then      state_out <= ADD_ROUNDKEY_FUNCT ( roundkey, state );   else      state_out <= state;   end if;end PRE_ADD;-- ==========================================================================----  procedure POST_ADD----  Wrapper for POST_ADD function---- ==========================================================================procedure POST_ADD ( state     : in STATE_TYPE;                     encrypt   : in std_logic;                     roundkey  : in KEY_TYPE;              signal state_out : out STATE_TYPE ) isbegin   if encrypt = '0' then      state_out <= ADD_ROUNDKEY_FUNCT ( roundkey, state );   else      state_out <= state;   end if;end POST_ADD;-- ==========================================================================----  function RIJNDAEL_ROUND_FUNCT----  Performs one round of the RIJNDAEL block cipher. Encryption or decryption--  is performed based on the 'encrypt' signal.---- ==========================================================================function RIJNDAEL_ROUND_FUNCT ( encrypt  : std_logic;                                roundkey : KEY_TYPE;                                state    : STATE_TYPE )                                return STATE_TYPE is-- pragma map_to_operator RIJNDAEL_ROUND_FUNCT_dw_op-- pragma return_port_name RIJNDAEL_ROUND_FUNCT_outvariable temp_state : STATE_TYPE;begin-- ===========================================================================-- ============================== Encryption =================================-- ===========================================================================   if encrypt = '1' then      temp_state := BYTE_SUB_FUNCT ( state );      temp_state := SHIFT_ROW_FUNCT ( temp_state );      temp_state := MIX_COLUMN_FUNCT ( temp_state );      temp_state := ADD_ROUNDKEY_FUNCT (  roundkey, temp_state );-- ===========================================================================-- ============================== Decryption =================================-- ===========================================================================   else      temp_state := ADD_ROUNDKEY_FUNCT ( roundkey, state );      temp_state := INV_MIX_COLUMN_FUNCT ( temp_state );      temp_state := INV_BYTE_SUB_FUNCT ( temp_state );      temp_state := INV_SHIFT_ROW_FUNCT ( temp_state );   end if; -- encrypt = '1'   return temp_state;end RIJNDAEL_ROUND_FUNCT;-- ==========================================================================----  procedure RIJNDAEL_ROUND----  Performs one round of the RIJNDAEL block cipher. Encryption or decryption--  is performed based on the 'encrypt' signal.---- ==========================================================================procedure RIJNDAEL_ROUND ( state     : in STATE_TYPE;                           encrypt   : in std_logic;                           roundkey  : in KEY_TYPE;                    signal state_out : out STATE_TYPE ) isbegin   state_out <= RIJNDAEL_ROUND_FUNCT (encrypt, roundkey, state );end RIJNDAEL_ROUND;-- ==========================================================================----  function INITIAL_ROUND_FUNCT----  Performs the initial round of the RIJNDAEL block cipher. Encryption or--  decryption is performed based on the 'encrypt' signal.---- ==========================================================================function INITIAL_ROUND_FUNCT ( encrypt  : std_logic;                               roundkey : KEY_TYPE;                               state    : STATE_TYPE )                               return STATE_TYPE is-- pragma map_to_operator INITIAL_ROUND_FUNCT_dw_op-- pragma return_port_name INITIAL_ROUND_FUNCT_outvariable temp_state : STATE_TYPE;begin-- ===========================================================================-- ============================== Encryption =================================-- ===========================================================================   if encrypt = '1' then      temp_state := BYTE_SUB_FUNCT ( state );      temp_state := SHIFT_ROW_FUNCT ( temp_state );      temp_state := MIX_COLUMN_FUNCT ( temp_state );      temp_state := ADD_ROUNDKEY_FUNCT ( roundkey, temp_state );-- ===========================================================================-- ============================== Decryption =================================-- ===========================================================================   else      temp_state := ADD_ROUNDKEY_FUNCT ( roundkey, state );      temp_state := INV_BYTE_SUB_FUNCT ( temp_state );      temp_state := INV_SHIFT_ROW_FUNCT ( temp_state );   end if; -- encrypt = '1'   return temp_state;end INITIAL_ROUND_FUNCT;-- ==========================================================================----  procedure INITIAL_ROUND----  Wrapper for the INITIAL_ROUND function.---- ==========================================================================procedure INITIAL_ROUND ( state     : in STATE_TYPE;                          encrypt   : in std_logic;                          roundkey  : in KEY_TYPE;                   signal state_out : out STATE_TYPE ) isbegin   state_out <= INITIAL_ROUND_FUNCT ( encrypt, roundkey, state );end INITIAL_ROUND;-- ==========================================================================----  function FINAL_ROUND_FUNCT----  Performs the final round of the RIJNDAEL block cipher. Encryption or--  decryption is performed based on the 'encrypt' signal.---- ==========================================================================function FINAL_ROUND_FUNCT ( encrypt  : std_logic;                             roundkey : KEY_TYPE;                             state    : STATE_TYPE )                             return STATE_TYPE is-- pragma map_to_operator FINAL_ROUND_FUNCT_dw_op-- pragma return_port_name FINAL_ROUND_FUNCT_outvariable temp_state : STATE_TYPE;begin-- ===========================================================================-- ============================== Encryption =================================-- ===========================================================================   if encrypt = '1' then      temp_state := BYTE_SUB_FUNCT ( state );      temp_state := SHIFT_ROW_FUNCT ( temp_state );      temp_state := ADD_ROUNDKEY_FUNCT ( roundkey, temp_state );-- ===========================================================================-- ============================== Decryption =================================-- ===========================================================================   else      temp_state := ADD_ROUNDKEY_FUNCT ( roundkey, state );      temp_state := INV_MIX_COLUMN_FUNCT ( temp_state );      temp_state := INV_BYTE_SUB_FUNCT ( temp_state );      temp_state := INV_SHIFT_ROW_FUNCT ( temp_state );   end if; -- encrypt = '1'   return temp_state;end FINAL_ROUND_FUNCT;-- ==========================================================================----  procedure FINAL_ROUND----  Wrapper for the FINAL_ROUND function.---- ==========================================================================procedure FINAL_ROUND ( state     : in STATE_TYPE;                        encrypt   : in std_logic;                        roundkey  : in KEY_TYPE;                 signal state_out : out STATE_TYPE ) isbegin   state_out <= FINAL_ROUND_FUNCT ( encrypt, roundkey, state );end FINAL_ROUND;-- ==========================================================================-- =============== Definitions for the Key Schedule section =================-- ==========================================================================-- ==========================================================================---- function EXPANSION_FUNCT---- Performs the initial key expansion implemented as combinational -- logic as described in the RIJNDAEL algorithm specification.---- ==========================================================================function EXPANSION_FUNCT ( cv_in   : SLV_256;                            cv_size : SLV_2;                            round   : SLV_6;                            w_in    : W_TYPE )                                 return W_TYPE is-- pragma map_to_operator EXPANSION_FUNCT_dw_op-- pragma return_port_name EXPANSION_FUNCT_outvariable new_w    : W_TYPE;variable w_output : W_TYPE;variable bank : integer;begin   bank := TO_INTEGER(unsigned(round));    case cv_size is      when "00" =>         new_w(-4) := KS_SBOX_FUNCT( cv_size,                                         '1',            std_logic_vector(TO_UNSIGNED(bank,16)),                                         w_in(-4),                                         w_in(-1) );         new_w(-3) := new_w(-4) xor w_in(-3);         new_w(-2) := new_w(-3) xor w_in(-2);         new_w(-1) := new_w(-2) xor w_in(-1);

⌨️ 快捷键说明

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