OpenCores
URL https://opencores.org/ocsvn/camellia-vhdl/camellia-vhdl/trunk

Subversion Repositories camellia-vhdl

[/] [camellia-vhdl/] [trunk/] [looping/] [datapath.vhd] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 pfulgoni
 
2
--------------------------------------------------------------------------------
3
-- Designer:      Paolo Fulgoni <pfulgoni@opencores.org>
4
--
5
-- Create Date:   01/22/2008
6
-- Last Update:   03/04/2008
7
-- Project Name:  camellia-vhdl
8
-- Description:   Datapath
9
--
10
-- Copyright (C) 2008  Paolo Fulgoni
11
-- This file is part of camellia-vhdl.
12
-- camellia-vhdl is free software; you can redistribute it and/or modify
13
-- it under the terms of the GNU General Public License as published by
14
-- the Free Software Foundation; either version 3 of the License, or
15
-- (at your option) any later version.
16
-- camellia-vhdl is distributed in the hope that it will be useful,
17
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
-- GNU General Public License for more details.
20
-- You should have received a copy of the GNU General Public License
21
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
--
23
-- The Camellia cipher algorithm is 128 bit cipher developed by NTT and
24
-- Mitsubishi Electric researchers.
25
-- http://info.isl.ntt.co.jp/crypt/eng/camellia/
26
--------------------------------------------------------------------------------
27
library IEEE;
28
use IEEE.std_logic_1164.all;
29
 
30
entity datapath is
31
    port    (
32
            clk      : in STD_LOGIC;
33
            reset    : in STD_LOGIC;
34
            data_in  : in STD_LOGIC_VECTOR (0 to 127);
35
            k1       : in STD_LOGIC_VECTOR (0 to 63);
36
            k2       : in STD_LOGIC_VECTOR (0 to 63);
37
            newdata  : in STD_LOGIC;
38
            sel      : in STD_LOGIC;    -- 0 if F,  1 if FL
39
            pre_xor  : in STD_LOGIC_VECTOR (0 to 127);
40
            post_xor : in STD_LOGIC_VECTOR (0 to 127);
41
            data_out : out STD_LOGIC_VECTOR (0 to 127)
42
            );
43
end datapath;
44
 
45
architecture RTL of datapath is
46
 
47
    component F is
48
        port    (
49
                x     : in  STD_LOGIC_VECTOR (0 to 63);
50
                k     : in  STD_LOGIC_VECTOR (0 to 63);
51
                z     : out STD_LOGIC_VECTOR (0 to 63)
52
                );
53
    end component;
54
 
55
    component FL is
56
        port(
57
                fl_in   : in  STD_LOGIC_VECTOR (0 to 63);
58
                fli_in  : in  STD_LOGIC_VECTOR (0 to 63);
59
                fl_k    : in  STD_LOGIC_VECTOR (0 to 63);
60
                fli_k   : in  STD_LOGIC_VECTOR (0 to 63);
61
                fl_out  : out STD_LOGIC_VECTOR (0 to 63);
62
                fli_out : out STD_LOGIC_VECTOR (0 to 63)
63
                );
64
    end component;
65
 
66
    signal f_in    : STD_LOGIC_VECTOR (0 to 63);
67
    signal f_k     : STD_LOGIC_VECTOR (0 to 63);
68
    signal f_out   : STD_LOGIC_VECTOR (0 to 63);
69
    signal fl_in   : STD_LOGIC_VECTOR (0 to 63);
70
    signal fl_k    : STD_LOGIC_VECTOR (0 to 63);
71
    signal fl_out  : STD_LOGIC_VECTOR (0 to 63);
72
    signal fli_in  : STD_LOGIC_VECTOR (0 to 63);
73
    signal fli_k   : STD_LOGIC_VECTOR (0 to 63);
74
    signal fli_out : STD_LOGIC_VECTOR (0 to 63);
75
 
76
    signal data_in_sx : STD_LOGIC_VECTOR (0 to 63);
77
    signal data_in_dx : STD_LOGIC_VECTOR (0 to 63);
78
    signal pre_xor_sx : STD_LOGIC_VECTOR (0 to 63);
79
    signal pre_xor_dx : STD_LOGIC_VECTOR (0 to 63);
80
 
81
    signal mux1       : STD_LOGIC_VECTOR (0 to 63);
82
    signal mux1_pxor  : STD_LOGIC_VECTOR (0 to 63);
83
    signal mux2       : STD_LOGIC_VECTOR (0 to 63);
84
    signal mux2_pxor  : STD_LOGIC_VECTOR (0 to 63);
85
    signal f_out_xor  : STD_LOGIC_VECTOR (0 to 63);
86
 
87
    signal reg_fl_out    : STD_LOGIC_VECTOR (0 to 63);
88
    signal reg_fli_out   : STD_LOGIC_VECTOR (0 to 63);
89
    signal reg_f_out_xor : STD_LOGIC_VECTOR (0 to 63);
90
    signal reg_mux2_pxor : STD_LOGIC_VECTOR (0 to 63);
91
    signal reg_sel       : STD_LOGIC;
92
 
93
    constant SEL_F    : STD_LOGIC := '0';
94
    constant SEL_FL   : STD_LOGIC := '1';
95
 
96
begin
97
 
98
    F1  : F
99
        port map(f_in, f_k, f_out);
100
 
101
    FL1  : FL
102
        port map(fl_in, fli_in, fl_k, fli_k, fl_out, fli_out);
103
 
104
 
105
    data_in_sx <= data_in(0 to 63);
106
    data_in_dx <= data_in(64 to 127);
107
    pre_xor_sx <= pre_xor(0 to 63);
108
    pre_xor_dx <= pre_xor(64 to 127);
109
    f_in       <= mux2_pxor;
110
    f_k        <= k1;
111
    fl_in      <= reg_f_out_xor;
112
    fl_k       <= k1;
113
    fli_in     <= reg_mux2_pxor;
114
    fli_k      <= k2;
115
    f_out_xor  <= f_out xor mux1_pxor;
116
 
117
    mux1 <= reg_fli_out     when newdata='0' and reg_sel=SEL_FL else
118
            reg_mux2_pxor   when newdata='0' and reg_sel=SEL_F  else
119
            data_in_dx;
120
    mux2 <= reg_fl_out      when newdata='0' and reg_sel=SEL_FL else
121
            reg_f_out_xor   when newdata='0' and reg_sel=SEL_F  else
122
            data_in_sx;
123
 
124
    mux1_pxor  <= mux1 xor pre_xor_dx;
125
    mux2_pxor  <= mux2 xor pre_xor_sx;
126
 
127
    data_out   <= (f_out_xor & mux2_pxor) xor post_xor;
128
 
129
    REGISTERS: process(clk, reset)
130
    begin
131
 
132
        if (reset = '1') then
133
            reg_fl_out    <= (others=>'0');
134
            reg_fli_out   <= (others=>'0');
135
            reg_f_out_xor <= (others=>'0');
136
            reg_mux2_pxor <= (others=>'0');
137
            reg_sel       <= SEL_F;
138
        elsif (clk'event and clk='1') then
139
            reg_fl_out    <= fl_out;
140
            reg_fli_out   <= fli_out;
141
            reg_f_out_xor <= f_out_xor;
142
            reg_mux2_pxor <= mux2_pxor;
143
            reg_sel       <= sel;
144
        end if;
145
 
146
    end process;
147
 
148
end RTL;

powered by: WebSVN 2.1.0

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