Professional Documents
Culture Documents
of P8 is
<=
<=
<=
<=
<=
<=
<=
<=
input(5);
input(2);
input(6);
input(3);
input(7);
input(4);
input(9);
input(8);
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity IP is
port (input: in std_logic_vector(0 to 7);
ip : out std_logic_vector(0 to 7));
end;
architecture
begin
ip(0) <=
ip(1) <=
ip(2) <=
ip(3) <=
ip(4) <=
ip(5) <=
ip(6) <=
ip(7) <=
IP of IP is
input(1);
input(5);
input(2);
input(0);
input(3);
input(7);
input(4);
input(6);
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity RIP is
port (input: in std_logic_vector(0 to 7);
rip : out std_logic_vector(0 to 7));
end;
architecture RIP of RIP is
begin
rip(0) <= input(3);
rip(1) <= input(0);
rip(2) <= input(2);
rip(3) <= input(4);
rip(4) <= input(6);
rip(5) <= input(1);
rip(6) <= input(7);
rip(7) <= input(5);
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity FKFSM is
port (clk, rst, en: in std_logic;
en_f: in std_logic;
out_en: out std_logic);
end;
architecture FKFSM of FKFSM is
type STATES is (INIT, SXOR, SFK);
signal state: STATES;
signal enable: std_logic;
begin
process (clk, rst, en)
begin
if (en='1') then
enable <= '1';
end if;
if (rst='0') then
state<=INIT;
enable<='0';
elsif rising_edge(clk) then
if (enable='1') then
case state is
when INIT=>
out_en <= '0';
state <= SFK;
when SFK=>
if(en_f='1') then
state <= SXOR;
end if;
when SXOR=>
out_en <= '1';
entity SW is
port (input: in std_logic_vector(0 to 7);
switched : out std_logic_vector(0 to 7));
end;
architecture SW
begin
switched(0)
switched(1)
switched(2)
switched(3)
switched(4)
switched(5)
switched(6)
switched(7)
end;
of SW is
<=
<=
<=
<=
<=
<=
<=
<=
input(4);
input(5);
input(6);
input(7);
input(0);
input(1);
input(2);
input(3);
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity S0 is
port(input: in std_logic_vector(0 to 3);
output: out std_logic_vector(0 to 1));
end;
architecture S0 of S0 is
type array_s is array (0 to 3,0 to 3) of std_logic_vector(0 to 1);
signal s_0 : array_s := (("01","00","11","10"),
("11","10","01","00"),
("00","10","01","11"),
("11","01","11","10"));
begin
output <= s_0(conv_integer(input(0) & input(3)),conv_integer(input(1 to 2)))
;
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity S1 is
port(input: in std_logic_vector(0 to 3);
output: out std_logic_vector(0 to 1));
end;
architecture S1 of S1 is
type array_s is array (0 to 3,0 to 3) of std_logic_vector(0 to 1);
signal s_1 : array_s := (("00","01","10","11"),
("10","00","01","11"),
("11","00","01","00"),
("10","01","00","11"));
begin
output <= s_1(conv_integer(input(0) & input(3)),conv_integer(input(1 to 2)))
;
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity EP is
port(input: in std_logic_vector(0 to 3);
eped: out std_logic_vector(0 to 7));
end;
architecture EP of EP is
begin
eped(0) <= input(3);
eped(1) <= input(0);
eped(2) <= input(1);
eped(3) <= input(2);
eped(4) <= input(1);
eped(5) <= input(2);
eped(6) <= input(3);
eped(7) <= input(0);
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity P4 is
port(input: in std_logic_vector(0 to 3);
p4ed: out std_logic_vector(0 to 3));
end;
architecture P4 of P4 is
begin
p4ed(0) <= input(1);
p4ed(1) <= input(3);
p4ed(2) <= input(2);
p4ed(3) <= input(0);
end;
library IEEE;
use IEEE.std_logic_1164.all;
entity reg10 is
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 9);
outp: out std_logic_vector(0 to 9));
end reg10;
architecture rtl of reg10 is
begin
seq: process (en,clk,inp)
begin
if en='1' then
if rising_edge(clk) then
outp<=inp;
end if;
end if;
end process;
end rtl;
library IEEE;
use IEEE.std_logic_1164.all;
entity reg8 is
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 7);
outp: out std_logic_vector(0 to 7));
end reg8;
architecture rtl of reg8 is
begin
seq: process (en,clk,inp)
begin
if en='1' then
if rising_edge(clk) then
outp<=inp;
end if;
end if;
end process;
end rtl;
library IEEE;
use IEEE.std_logic_1164.all;
entity reg4 is
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 3);
outp: out std_logic_vector(0 to 3));
end reg4;
architecture rtl of reg4 is
begin
seq: process (en,clk,inp)
begin
if en='1' then
if rising_edge(clk) then
outp<=inp;
end if;
end if;
end process;
end rtl;
library IEEE;
use IEEE.std_logic_1164.all;
entity reg2 is
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 1);
outp: out std_logic_vector(0 to 1));
end reg2;
architecture rtl of reg2 is
begin
seq: process (en,clk,inp)
begin
if en='1' then
if rising_edge(clk) then
outp<=inp;
end if;
end if;
end process;
end rtl;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity FFSM is
port (clk, rst, en_f: in std_logic;
sig_ep, sig_xor, sig_s0s1: out std_logic;
out_en: out std_logic);
end;
architecture FFSM of FFSM is
type STATES is (INIT, SEP, SXOR, SS0S1,SP4);
signal state: STATES;
signal enable: std_logic;
begin
process (clk, rst, en_f)
begin
if(en_f='1') then
enable <= '1';
end if;
if (rst='0') then
state<=INIT;
enable<='0';
elsif rising_edge(clk) then
if(enable='1') then
case state is
when INIT=>
sig_ep <= '0';
sig_xor <= '0';
sig_s0s1 <= '0';
out_en <= '0';
state <= SEP;
when SEP=>
sig_ep <= '1';
state <= SXOR;
when SXOR=>
sig_ep <= '0';
sig_xor <= '1';
state <= SS0S1;
when SS0S1=>
sig_xor <= '0';
sig_s0s1 <= '1';
state <= SP4;
when SP4=>
sig_s0s1 <= '0';
out_en <= '1';
--state <= INIT;
end case;
end if;
end if;
end process;
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity F is
port (clk, rst, en_f:in std_logic;
input: in std_logic_vector(0 to 3);
key: in std_logic_vector(0 to 7);
fed : out std_logic_vector(0 to 3);
outen_f: out std_logic);
end;
architecture F of F is
component S0
port(input: in std_logic_vector(0 to 3);
output: out std_logic_vector(0 to 1));
end component;
component S1
port(input: in std_logic_vector(0 to 3);
output: out std_logic_vector(0 to 1));
end component;
component EP
port(input: in std_logic_vector(0 to 3);
eped: out std_logic_vector(0 to 7));
end component;
component P4
port(input: in std_logic_vector(0 to 3);
p4ed: out std_logic_vector(0 to 3));
end component;
component reg2
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 1);
outp: out std_logic_vector(0 to 1));
end component;
component reg4
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 3);
outp: out std_logic_vector(0 to 3));
end component;
component reg8
port (
en,clk: in std_logic;
inp: in std_logic_vector(0 to 7);
outp: out std_logic_vector(0 to 7));
end component;
component XOR8
port (
inp1: in std_logic_vector(0 to 7);
inp2: in std_logic_vector(0 to 7);
outp: out std_logic_vector(0 to 7));
end component;
component FFSM
port (clk, rst, en_f: in std_logic;
sig_ep, sig_xor, sig_s0s1: out std_logic;
out_en: out std_logic);
end component;
signal eped, r_eped, xored, r_xored: std_logic_vector(0 to 7);
signal p4ed: std_logic_vector(0 to 3);
begin
ls1 <= input(1 to 4)&input(0)&input(6 to 9)&input(5);
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity LS2 is
port (input: in std_logic_vector(0 to 9);
ls2 : out std_logic_vector(0 to 9));
end;
architecture LS2 of LS2 is
begin
ls2 <= input(2 to 4)&input(0 to 1)&input(7 to 9)&input(5 to 6);
end;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity KFSM is
port (clk, rst: in std_logic;
sig_p10, sig_p8, sig_ls1, sig_ls2: out std_logic;
out_en: out std_logic);
end;
architecture KFSM of KFSM is
type STATES is (INIT, SP10, SLS1, SP81, SLS2, SP82);
signal state: STATES;
begin
process (clk, rst)
begin
if (rst='0') then
state<=INIT;
elsif rising_edge(clk) then
case state is
when INIT=>
out_en <= '0';
sig_p10 <= '0';
sig_p8 <= '0';
sig_ls1 <= '0';
sig_ls2 <= '0';
state <= SP10;
when SP10=>
sig_p10 <= '1';
state <= SLS1;
when SLS1=>
sig_p10 <= '0';
sig_ls1 <= '1';
state <= SP81;
when SP81=>
sig_ls1 <= '0';
sig_p8 <= '1';
state <= SLS2;
when SLS2=>
sig_p8 <= '0';
signal
signal
signal
signal
begin
KK: KEYGEN port map(clk,rst,key,keys, keys_ready);
IP_0: IP port map(input, iped);
R_81: reg8 port map(sig_ip,clk,iped,r_iped);
FK1: Fk port map(clk, rst, keys_ready, r_iped, keys(0 to 7), fked1, en_f
k1);
R_82: reg8 port map(en_fk1,clk,fked1,r_fked1);
SW_0: SW port map(r_fked1, switch);
R_83: reg8 port map(sig_sw,clk,switch,r_switch);
FK2: Fk port map(clk, rst, sig_sw, r_switch, keys(8 to 15), fked2, en_fk
2);
R_84: reg8 port map(en_fk2,clk,fked2,r_fked2);
RIP_0: RIP port map(r_fked2, riped);
R_85: reg8 port map(out_en,clk,riped,output);
ACTRL: SFSM port map(clk, rst, en_fk1, en_fk2, sig_ip, sig_sw, out_en);