------------------------------------------------------------
-- Copyright: 2011 George Mason University, Virginia USA
--            http://www.iis.ee.ethz.ch/~sha3
------------------------------------------------------------
-- =====================================================================

-- Copyright © 2010-2011 by Cryptographic Engineering Research Group (CERG),

-- ECE Department, George Mason University

-- Fairfax, VA, U.S.A.

-- =====================================================================


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use work.sha3_pkg.all;
use work.keccak_pkg.all;
	
-- implementation of Keccak round: there are two basic architectures of Keccak function

-- Guido Bertoni implementation of Keccak round - streightforward

-- Marcin Rogawski implementation of Keccak round - based on C implementation 

-- Marcin Rogawski implementation is smaller and faster on Altera (Stratix II-IV, Cyclone II-IV)

-- and Xilinx (Virtex 4-6, Spartan 3 and 6)	devices than Guido Bertoni implementation

entity keccak_round is
port (
    rin     			: in std_logic_vector(KECCAK_STATE-1 downto 0);
    rc			   	 	: in std_logic_vector(63 downto 0);
    rout    			: out std_logic_vector(KECCAK_STATE-1 downto 0));
end keccak_round;

architecture gbertoni_round of keccak_round is

signal theta_in, theta_out, pi_in, pi_out, rho_in, rho_out, 
chi_in, chi_out, iota_in, iota_out, round_in, round_out : state;
signal sum_sheet: plane;
  
begin  

in_outer_gen : for i in 0 to 4 generate 
	in_inner_gen : for j in 0 to 4 generate 
	  round_in(i)(j) <= rin((1599 - 320*i - 64*j) downto (1536 - 320*i - 64*j));
	end generate;	
end generate;	

out_outer_gen : for i in 0 to 4 generate 
	out_inner_gen : for j in 0 to 4 generate 
	 rout((1599 - 320*i - 64*j) downto (1536 - 320*i - 64*j)) <=  round_out(i)(j);
	end generate;	
end generate;	
	
	theta_in<=round_in;
	pi_in<=rho_out;
	rho_in<=theta_out;
	chi_in<=pi_out;
	iota_in<=chi_out;
	round_out<=iota_out;



chi01_gen: for y in 0 to 4 generate
	chi02_gen: for x in 0 to 2 generate
		chi03_gen: for i in 0 to 63 generate
			chi_out(y)(x)(i)<=chi_in(y)(x)(i) xor  ( not(chi_in (y)(x+1)(i))and chi_in (y)(x+2)(i));
		end generate;	
	end generate;
end generate;

chi11_gen: for y in 0 to 4 generate
	chi12_gen: for i in 0 to 63 generate
		chi_out(y)(3)(i)<=chi_in(y)(3)(i) xor  ( not(chi_in (y)(4)(i))and chi_in (y)(0)(i));
	end generate;	
end generate;
	
chi21_gen: for y in 0 to 4 generate
	chi21_gen: for i in 0 to 63 generate
		chi_out(y)(4)(i)<=chi_in(y)(4)(i) xor  ( not(chi_in (y)(0)(i))and chi_in (y)(1)(i));		
	end generate;	
end generate;

theta01_gen: for x in 0 to 4 generate
	theta02_gen: for i in 0 to 63 generate
		sum_sheet(x)(i)<=theta_in(0)(x)(i) xor theta_in(1)(x)(i) xor theta_in(2)(x)(i) xor theta_in(3)(x)(i) xor theta_in(4)(x)(i);
	end generate;	
end generate;

theta11_gen: for y in 0 to 4 generate
	theta12_gen: for x in 1 to 3 generate
		theta_out(y)(x)(0)<=theta_in(y)(x)(0) xor sum_sheet(x-1)(0) xor sum_sheet(x+1)(63);
		theta13_gen: for i in 1 to 63 generate
			theta_out(y)(x)(i)<=theta_in(y)(x)(i) xor sum_sheet(x-1)(i) xor sum_sheet(x+1)(i-1);
		end generate;	
	end generate;
end generate;

theta21_gen: for y in 0 to 4 generate
	theta_out(y)(0)(0)<=theta_in(y)(0)(0) xor sum_sheet(4)(0) xor sum_sheet(1)(63);
	theta22_gen: for i in 1 to 63 generate
		theta_out(y)(0)(i)<=theta_in(y)(0)(i) xor sum_sheet(4)(i) xor sum_sheet(1)(i-1);
	end generate;	
end generate;

theta31_gen: for y in 0 to 4 generate
	theta_out(y)(4)(0)<=theta_in(y)(4)(0) xor sum_sheet(3)(0) xor sum_sheet(0)(63);
	theta32_gen: for i in 1 to 63 generate
		theta_out(y)(4)(i)<=theta_in(y)(4)(i) xor sum_sheet(3)(i) xor sum_sheet(0)(i-1);
	end generate;	
end generate;

pi01_gen: for y in 0 to 4 generate
	pi02_gen: for x in 0 to 4 generate
		pi03_gen: for i in 0 to 63 generate
			pi_out((2*x+3*y) mod 5)(0*x+1*y)(i)<=pi_in(y) (x)(i);
		end generate;	
	end generate;
end generate;

rho01_gen: for i in 0 to 63 generate
	rho_out(0)(0)(i)<=rho_in(0)(0)(i);
end generate;	

rho11_gen: for i in 0 to 63 generate
	rho_out(0)(1)(i)<=rho_in(0)(1)((i-1)mod 64);
end generate;

rho21_gen: for i in 0 to 63 generate
	rho_out(0)(2)(i)<=rho_in(0)(2)((i-62)mod 64);
end generate;

rho31_gen: for i in 0 to 63 generate
	rho_out(0)(3)(i)<=rho_in(0)(3)((i-28)mod 64);
end generate;

rho41_gen: for i in 0 to 63 generate
	rho_out(0)(4)(i)<=rho_in(0)(4)((i-27)mod 64);
end generate;

rho51_gen: for i in 0 to 63 generate
	rho_out(1)(0)(i)<=rho_in(1)(0)((i-36)mod 64);
end generate;	

rho61_gen: for i in 0 to 63 generate
	rho_out(1)(1)(i)<=rho_in(1)(1)((i-44)mod 64);
end generate;

rho71_gen: for i in 0 to 63 generate
	rho_out(1)(2)(i)<=rho_in(1)(2)((i-6)mod 64);
end generate;

rho81_gen: for i in 0 to 63 generate
	rho_out(1)(3)(i)<=rho_in(1)(3)((i-55)mod 64);
end generate;

rho91_gen: for i in 0 to 63 generate
	rho_out(1)(4)(i)<=rho_in(1)(4)((i-20)mod 64);
end generate;

rhoa1_gen: for i in 0 to 63 generate
	rho_out(2)(0)(i)<=rho_in(2)(0)((i-3)mod 64);
end generate;	

rhob1_gen: for i in 0 to 63 generate
	rho_out(2)(1)(i)<=rho_in(2)(1)((i-10)mod 64);
end generate;

rhoc1_gen: for i in 0 to 63 generate
	rho_out(2)(2)(i)<=rho_in(2)(2)((i-43)mod 64);
end generate;

rhod1_gen: for i in 0 to 63 generate
	rho_out(2)(3)(i)<=rho_in(2)(3)((i-25)mod 64);
end generate;

rhoe1_gen: for i in 0 to 63 generate
	rho_out(2)(4)(i)<=rho_in(2)(4)((i-39)mod 64);
end generate;

rhof1_gen: for i in 0 to 63 generate
	rho_out(3)(0)(i)<=rho_in(3)(0)((i-41)mod 64);
end generate;	

rhog1_gen: for i in 0 to 63 generate
	rho_out(3)(1)(i)<=rho_in(3)(1)((i-45)mod 64);
end generate;

rhoh1_gen: for i in 0 to 63 generate
	rho_out(3)(2)(i)<=rho_in(3)(2)((i-15)mod 64);
end generate;

rhoi1_gen: for i in 0 to 63 generate
	rho_out(3)(3)(i)<=rho_in(3)(3)((i-21)mod 64);
end generate;

rhoj1_gen: for i in 0 to 63 generate
	rho_out(3)(4)(i)<=rho_in(3)(4)((i-8)mod 64);
end generate;

rhok1_gen: for i in 0 to 63 generate
	rho_out(4)(0)(i)<=rho_in(4)(0)((i-18)mod 64);
end generate;	

rhol1_gen: for i in 0 to 63 generate
	rho_out(4)(1)(i)<=rho_in(4)(1)((i-2)mod 64);
end generate;

rhom1_gen: for i in 0 to 63 generate
	rho_out(4)(2)(i)<=rho_in(4)(2)((i-61)mod 64);
end generate;

rhon1_gen: for i in 0 to 63 generate
	rho_out(4)(3)(i)<=rho_in(4)(3)((i-56)mod 64);
end generate;

rhoo1_gen: for i in 0 to 63 generate
	rho_out(4)(4)(i)<=rho_in(4)(4)((i-14)mod 64);
end generate;

iota01_gen: for y in 1 to 4 generate
	iota02_gen: for x in 0 to 4 generate
		iota03_gen: for i in 0 to 63 generate
			iota_out(y)(x)(i)<=iota_in(y)(x)(i);
		end generate;	
	end generate;
end generate;


iota11_gen: for x in 1 to 4 generate
	iota12_gen: for i in 0 to 63 generate
		iota_out(0)(x)(i)<=iota_in(0)(x)(i);
	end generate;	
end generate;

iota21_gen: for i in 0 to 63 generate
	iota_out(0)(0)(i)<=iota_in(0)(0)(i) xor rc(i);
end generate;	

end gbertoni_round;




Generated on Tue Nov 22 15:16:34 CET 2011
Home