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

Subversion Repositories nfcc

[/] [nfcc/] [trunk/] [kasumi/] [keyschedule.vhdl] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 arif_endro
-- ------------------------------------------------------------------------
2
-- Copyright (C) 2010 Arif Endro Nugroho
3
-- All rights reserved.
4
-- 
5
-- Redistribution and use in source and binary forms, with or without
6
-- modification, are permitted provided that the following conditions
7
-- are met:
8
-- 
9
-- 1. Redistributions of source code must retain the above copyright
10
--    notice, this list of conditions and the following disclaimer.
11
-- 2. Redistributions in binary form must reproduce the above copyright
12
--    notice, this list of conditions and the following disclaimer in the
13
--    documentation and/or other materials provided with the distribution.
14
-- 
15
-- THIS SOFTWARE IS PROVIDED BY ARIF ENDRO NUGROHO "AS IS" AND ANY EXPRESS
16
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
-- DISCLAIMED. IN NO EVENT SHALL ARIF ENDRO NUGROHO BE LIABLE FOR ANY
19
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23
-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
-- POSSIBILITY OF SUCH DAMAGE.
26
-- 
27
-- End Of License.
28
-- ------------------------------------------------------------------------
29
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32
use ieee.std_logic_unsigned.all;
33
 
34
entity keyschedule is
35
  port (
36
  key              : in  bit_vector ( 63 downto 0);
37
  st               : in  bit_vector (  3 downto 0);
38
  ldk              : in  bit;
39
--probe
40
--keyreg1_prb      : out bit_vector (127 downto 0);
41
--keyreg2_prb      : out bit_vector (127 downto 0);
42
--probe
43
  rk               : out bit_vector ( 15 downto 0);
44
  clk              : in  bit;
45
  rst              : in  bit
46
  );
47
end keyschedule;
48
 
49
architecture phy of keyschedule is
50
  signal keyreg1   :     bit_vector (127 downto 0);
51
  signal keyreg2   :     bit_vector (127 downto 0);
52
  signal   k1      :     bit_vector ( 15 downto 0);
53
  signal   k2      :     bit_vector ( 15 downto 0);
54
  signal   k3      :     bit_vector ( 15 downto 0);
55
  signal   k4      :     bit_vector ( 15 downto 0);
56
  signal   k5      :     bit_vector ( 15 downto 0);
57
  signal   k6      :     bit_vector ( 15 downto 0);
58
  signal   k7      :     bit_vector ( 15 downto 0);
59
  signal   k8      :     bit_vector ( 15 downto 0);
60
  signal   c1      :     bit_vector ( 15 downto 0);
61
  signal   c2      :     bit_vector ( 15 downto 0);
62
  signal   c3      :     bit_vector ( 15 downto 0);
63
  signal   c4      :     bit_vector ( 15 downto 0);
64
  signal   c5      :     bit_vector ( 15 downto 0);
65
  signal   c6      :     bit_vector ( 15 downto 0);
66
  signal   c7      :     bit_vector ( 15 downto 0);
67
  signal   c8      :     bit_vector ( 15 downto 0);
68
--constant c1      :     bit_vector ( 15 downto 0) := X"0123";
69
--constant c2      :     bit_vector ( 15 downto 0) := X"4567";
70
--constant c3      :     bit_vector ( 15 downto 0) := X"89ab";
71
--constant c4      :     bit_vector ( 15 downto 0) := X"cdef";
72
--constant c5      :     bit_vector ( 15 downto 0) := X"fedc";
73
--constant c6      :     bit_vector ( 15 downto 0) := X"ba98";
74
--constant c7      :     bit_vector ( 15 downto 0) := X"7654";
75
--constant c8      :     bit_vector ( 15 downto 0) := X"3210";
76
  signal ikey      :     bit_vector ( 15 downto 0);
77
--signal st        :     bit_vector (  2 downto 0);
78
--signal ldk       :     bit;
79
 
80
begin
81
 
82
--probe
83
--keyreg1_prb      <= keyreg1;
84
--keyreg2_prb      <= keyreg2;
85
--probe
86
 
87
--process (clk)
88
--begin
89
--if ((clk = '1') and clk'event) then
90
--  if (rst = '1') then
91
--    rk           <= (others => '0');
92
--  else
93
      rk               <= ikey;
94
--  end if;
95
--end if;
96
--end process;
97
 
98
  process (clk)
99
  begin
100
    if ((clk = '1') and clk'event) then
101
      if (rst = '1') then
102
        keyreg1    <= (others => '0');
103
        keyreg2    <= X"0123456789abcdeffedcba9876543210";
104
      elsif (ldk  = '1') then
105
        keyreg1    <= keyreg1( 63 downto 0) & key;
106
        keyreg2    <= X"0123456789abcdeffedcba9876543210";
107
      elsif (st = X"f") then
108
        keyreg1    <= keyreg1( 95 downto 0) & keyreg1(127 downto  96);
109
        keyreg2    <= keyreg2( 95 downto 0) & keyreg2(127 downto  96);
110
      end if;
111
    end if;
112
  end process;
113
 
114
  k1               <= keyreg1(127 downto 112);
115
  k2               <= keyreg1(111 downto  96);
116
  k3               <= keyreg1( 95 downto  80);
117
  k4               <= keyreg1( 79 downto  64);
118
  k5               <= keyreg1( 63 downto  48);
119
  k6               <= keyreg1( 47 downto  32);
120
  k7               <= keyreg1( 31 downto  16);
121
  k8               <= keyreg1( 15 downto   0);
122
 
123
  c1               <= keyreg2(127 downto 112);
124
  c2               <= keyreg2(111 downto  96);
125
  c3               <= keyreg2( 95 downto  80);
126
  c4               <= keyreg2( 79 downto  64);
127
  c5               <= keyreg2( 63 downto  48);
128
  c6               <= keyreg2( 47 downto  32);
129
  c7               <= keyreg2( 31 downto  16);
130
  c8               <= keyreg2( 15 downto   0);
131
 
132
  process (st,rst,k1,k2,k3,k4,k5,k6,k7,k8,c1,c3,c4,c5,c6,c8)
133
  begin
134
    if (rst = '1') then
135
      ikey         <= (others => '0');
136
    else
137
      case st is
138
        when X"0"  =>                                                     --KLi,1
139
          ikey     <= k1(14 downto 0) & k1(15);
140
        when X"1" =>                                                      --KLi,2
141
          ikey     <= k3 xor c3;
142
        when X"2" =>                                                      --KOi,1
143
          ikey     <= k2(10 downto 0) & k2(15 downto 11);
144
        when X"3" =>                                                      --KIi,1
145
          ikey     <= k5 xor c5;
146
        when X"4" =>                                                      --KOi,2
147
          ikey     <= k6( 7 downto 0) & k6(15 downto  8);
148
        when X"5" =>                                                      --KIi,2
149
          ikey     <= k4 xor c4;
150
        when X"6" =>                                                      --KOi,3
151
          ikey     <= k7( 2 downto 0) & k7(15 downto  3);
152
        when X"7" =>                                                      --KIi,3
153
          ikey     <= k8 xor c8;
154
        when X"8" =>                                                      --KOi,1
155
          ikey     <= k3(10 downto 0) & k3(15 downto 11);
156
        when X"9" =>                                                      --KIi,1
157
          ikey     <= k6 xor c6;
158
        when X"a" =>                                                      --KOi,2
159
          ikey     <= k7( 7 downto 0) & k7(15 downto  8);
160
        when X"b" =>                                                      --KIi,2
161
          ikey     <= k5 xor c5;
162
        when X"c" =>                                                      --KOi,3
163
          ikey     <= k8( 2 downto 0) & k8(15 downto  3);
164
        when X"d" =>                                                      --KIi,3
165
          ikey     <= k1 xor c1;
166
        when X"e"  =>                                                     --KLi,1
167
          ikey     <= k2(14 downto 0) & k2(15);
168
        when X"f" =>                                                      --KLi,2
169
          ikey     <= k4 xor c4;
170
      end case;
171
    end if;
172
  end process;
173
 
174
end phy;
175
 

powered by: WebSVN 2.1.0

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