OpenCores
URL https://opencores.org/ocsvn/tiny_encryption_algorithm/tiny_encryption_algorithm/trunk

Subversion Repositories tiny_encryption_algorithm

[/] [tiny_encryption_algorithm/] [trunk/] [tea1.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feketebv
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
use ieee.std_logic_unsigned.all;
5
 
6
entity tea1 is
7
   port(
8
      clock, reset : in std_logic;
9
      start : in std_logic;
10
      ready : out std_logic;
11
      key : in std_logic_vector(127 downto 0);
12
      text : in std_logic_vector(63 downto 0);
13
      cipher : out std_logic_vector(63 downto 0)
14
      );
15
end tea1;
16
 
17
architecture Behavioral of tea1 is
18
   signal cnt : std_logic_vector(6 downto 0);
19
   signal k0,k1,k2,k3,v0,v1,sum,feistelOut,feistelKey0,feistelKey1 : std_logic_vector(31 downto 0);
20
begin
21
 
22
   fcontrolling_fsm:process(reset, clock)
23
   begin
24
      if rising_edge(clock) then
25
         if reset = '1' then
26
            cnt <= (others => '1');
27
         elsif cnt(6) = '1' then
28
            if start = '1' then
29
               cnt <= (others => '0');
30
            end if;
31
         else
32
            cnt <= cnt + '1';
33
         end if;
34
      end if;
35
   end process;
36
 
37
   encryption:process(clock)
38
   begin
39
      if rising_edge(clock) then
40
         if cnt(6) = '1' then
41
            sum  <= x"9e3779b9";
42
            k0 <= key(31  downto  0);
43
            k1 <= key(63  downto 32);
44
            k2 <= key(95  downto 64);
45
            k3 <= key(127 downto 96);
46
            v0 <= text(31  downto  0);
47
            v1 <= text(63  downto 32);
48
         else
49
            if cnt(0) = '1' then
50
               sum <= sum + x"9e3779b9";
51
            end if;
52
            v1 <= v0 + feistelOut;
53
            v0 <= v1;
54
         end if;
55
      end if;
56
   end process;
57
 
58
   --encryption asynchron parts
59
   feistelKey0 <= k0 when cnt(0) = '0' else k2;
60
   feistelKey1 <= k1 when cnt(0) = '0' else k3;
61
   feistelOut <= (v1 + sum) xor ((v1(27 downto 0) & "0000") + feistelKey0) xor (("00000" & v1(31 downto 5)) + feistelKey1);
62
 
63
   --output   
64
   cipher <= v1 & v0;
65
   ready <= cnt(6);
66
 
67
end Behavioral;
68
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.