------------------------------------------------------------
-- Copyright: 2010 Integrated Sytems Laboratory, ETH Zurich
--            http://www.iis.ee.ethz.ch/~sha3
------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

package shabalPkg is

  -----------------------------------------------------------------------------
  -- Constants
  -----------------------------------------------------------------------------

  constant WWIDTH : integer := 32;
  -- constant r      : integer := 12;

  constant o1 : integer := 13;
  constant o2 : integer := 9;
  constant o3 : integer := 6;

  type blockA is array (0 to 11) of std_logic_vector (WWIDTH-1 downto 0);

  type blockB is array (0 to 15) of std_logic_vector (WWIDTH-1 downto 0);

  type blockW is array (0 to 1) of std_logic_vector (WWIDTH-1 downto 0);

  -----------------------------------------------------------------------------
  -- Initialization Vectors for Shabal-256
  -----------------------------------------------------------------------------
  -- first word in Ainit already in state after xor with W (+1)
  constant Ainit : blockA := ((x"52F84553"), (x"E54B7999"), (x"2D8EE3EC"), (x"B9645191"),
                              (x"E0078B86"), (x"BB7C44C9"), (x"D2B5C1CA"), (x"B0D2EB8C"),
                              (x"14CE5A45"), (x"22AF50DC"), (x"EFFDBC6B"), (x"EB21B74A"));

  constant Binit : blockB := ((x"B555C6EE"), (x"3E710596"), (x"A72A652F"), (x"9301515F"),
                              (x"DA28C1FA"), (x"696FD868"), (x"9CB6BF72"), (x"0AFE4002"),
                              (x"A6E03615"), (x"5138C1D4"), (x"BE216306"), (x"B38B8890"),
                              (x"3EA8B96B"), (x"3299ACE4"), (x"30924DD4"), (x"55CB34A5"));

  constant Cinit : blockB := ((x"B405F031"), (x"C4233EBA"), (x"B3733979"), (x"C0DD9D55"),
                              (x"C51C28AE"), (x"A327B8E1"), (x"56C56167"), (x"ED614433"),
                              (x"88B59D60"), (x"60E2CEBA"), (x"758B4B8B"), (x"83E82A7F"),
                              (x"BC968828"), (x"E6E00BF7"), (x"BA839E55"), (x"9B491C60"));


  -----------------------------------------------------------------------------
  -- Permutations
  -----------------------------------------------------------------------------

--  type perm is array (0 to 2, 0 to 11) of integer;

--  constant APCMATRIX : perm := ((3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
--                                (15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
--                                (11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6));

  function Rotl (
    DxDI  : std_logic_vector(WWIDTH-1 downto 0);
    SHIFT : integer)
    return std_logic_vector;

--  function Ufun (
--    DxDI : std_logic_vector(WWIDTH-1 downto 0))
--    return std_logic_vector;

--  function Vfun (
--    DxDI : std_logic_vector(WWIDTH-1 downto 0))
--    return std_logic_vector;
  
end shabalPkg;


package body shabalPkg is

  function Rotl (
    DxDI  : std_logic_vector(WWIDTH-1 downto 0);
    SHIFT : integer)
    return std_logic_vector is

    variable DxDO : std_logic_vector(WWIDTH-1 downto 0);
  begin

    DxDO  := DxDI(WWIDTH-SHIFT-1 downto 0) & DxDI(WWIDTH-1 downto WWIDTH-SHIFT);

    return DxDO;
    
  end Rotl;

--  function Ufun (
--    DxDI : std_logic_vector(WWIDTH-1 downto 0))
--    return std_logic_vector is

--    variable DxDO : std_logic_vector(WWIDTH-1 downto 0);
--    variable x, y : unsigned(WWIDTH-1 downto 0);
--  begin  -- Ufun

--    x    := unsigned(DxDI);
--    y    := unsigned(DxDI(30 downto 0) & '0');  -- shifted input
--    DxDO := std_logic_vector(x + y);
    
--    -- DxDO := std_logic_vector(x + x + x);

--    return DxDO;
    
--  end Ufun;

--  function Vfun (
--    DxDI : std_logic_vector(WWIDTH-1 downto 0))
--    return std_logic_vector is

--    variable DxDO : std_logic_vector(WWIDTH-1 downto 0);
--    variable x, y : unsigned(WWIDTH-1 downto 0);
--  begin  -- Ufun

--    x    := unsigned(DxDI);
--    y    := unsigned(DxDI(29 downto 0) & '0' & '0');  -- shifted input
--    DxDO := std_logic_vector(x + y);
    
--    -- y    := x + x;
--    -- DxDO := std_logic_vector(y + y + x);

--    return DxDO;
    
--  end Vfun;
    
end package body shabalPkg;

Generated on Fri Sep 24 10:39:12 CEST 2010
Home