forked from mitkof6/DataEncryptionStandard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KEY_SCHEDULE.vhd
66 lines (50 loc) · 1.43 KB
/
KEY_SCHEDULE.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use WORK.MY_ARRAY.ALL;
--key schedule
entity KEY_SCHEDULE is
Port ( key : in STD_LOGIC_VECTOR (0 to 63);
Kn : out ARRAY47);
end KEY_SCHEDULE;
architecture Behavioral of KEY_SCHEDULE is
--permuted choice 1
component PC1 is
Port ( i : in STD_LOGIC_VECTOR (0 to 63);
C, D : out STD_LOGIC_VECTOR (0 to 27));
end component;
--permuted choice 2
component PC2 is
Port ( i : in STD_LOGIC_VECTOR (0 to 55);
o : out STD_LOGIC_VECTOR (0 to 47));
end component;
--array (0 to 16) of std_logic_vector(0 to 28)
signal C, D : ARRAY28;
--array (0 to 15) of std_logic_vector(0 to 55)
signal CON : ARRAY55;
begin
PerCh10 : PC1 port map(key, C(0),D(0));
--generate C(i) D(i)
GEN_CD :
for i in 1 to 16 generate
GEN_CD_SINGLE:
if( i = 1 or i = 2 or i = 9 or i = 16) generate
C(i) <= C(i-1)(1 to 27) & C(i-1)(0);
D(i) <= D(i-1)(1 to 27) & D(i-1)(0);
end generate GEN_CD_SINGLE;
GEN_CD_DOUBLE:
if((i>2 and i<9) or (i>9 and i<16)) generate
C(i) <= C(i-1)(2 to 27) & C(i-1)(0) & C(i-1)(1);
D(i) <= D(i-1)(2 to 27) & D(i-1)(0) & D(i-1)(1);
end generate GEN_CD_DOUBLE;
end generate GEN_CD;
--generate concatenations
GEN_CON:
for i in 0 to 15 generate
CON(i) <= C(i+1) & D(i+1);
end generate GEN_CON;
--generate K1...K16
GEN_KEYS :
for i in 0 to 15 generate
PerCh2 : PC2 port map(CON(i), Kn(i));
end generate GEN_KEYS;
end Behavioral;