------------------------------------------------------------------------------- -- An 8-bit Maximal Length Linear Feedback Shift Register (LFSR) -- Author : Tam Paredes -- File Name : shift_reg8.vhd -- Architecture : Behavioural -- Description : This shift register is initialized with a key. Every clock -- cycle, all of the bits in the register are shifted such -- that the least significant bit is output. The new most -- significant bit is computed from the XOR of certain bits in -- the register. This shift register is rising edge triggered -- with an active-high enable and active-high reset. ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; library work; use work.stream_cipher_pkg.all; entity shift_reg8 is port(clock,reset,enable : in std_logic; output : out std_logic ); end shift_reg8; architecture behavioural of shift_reg8 is signal new_bit: std_logic; signal internal_reg: std_logic_vector(degreeC-1 downto 0); signal internal_reg_next: std_logic_vector(degreeC-1 downto 0); begin -- XOR bits 8, 4, 3, and 2 -- Note that indexing starts from 0 new_bit <= internal_reg(7) xor internal_reg(3) xor internal_reg(2) xor internal_reg(1); -- Output is least significant bit (LSB) in register output <= internal_reg(0); -- To get new register value, shift bits to the right and -- place newly calculated bit in most significant position internal_reg_next <= new_bit & internal_reg(degreeC-1 downto 1); process(clock,reset) begin if (reset = '1') then -- Reset internal_state to the original hard-coded key -- Any key is acceptable except all zeros internal_reg <= "00001000"; elsif rising_edge(clock) then if(enable = '1') then -- Determine new value in register internal_reg <= internal_reg_next; end if; end if; end process; end behavioural;