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

Subversion Repositories camellia-vhdl

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

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

Line No. Rev Author Line
1 4 pfulgoni
 
2
--------------------------------------------------------------------------------
3
-- Designer:      Paolo Fulgoni <pfulgoni@opencores.org>
4
--
5
-- Create Date:   03/25/2008
6 6 pfulgoni
-- Last Update:   04/02/2008
7 4 pfulgoni
-- Project Name:  camellia-vhdl
8
-- Description:   Interface to the Camellia core
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
use IEEE.std_logic_unsigned.all;
30
use IEEE.std_logic_arith.all;
31
 
32
entity CAMELLIA_IF is
33
    port    (
34
            clk       : in  STD_LOGIC;
35
            reset     : in  STD_LOGIC;
36
            data_in   : in  STD_LOGIC_VECTOR (0 to 15);
37
            enc_dec   : in  STD_LOGIC;
38
            en_data   : in  STD_LOGIC;
39
            next_data : out STD_LOGIC;
40
            key_in    : in  STD_LOGIC_VECTOR (0 to 15);
41
            k_len     : in  STD_LOGIC_VECTOR (0 to 1);
42
            en_key    : in  STD_LOGIC;
43
            next_key  : out STD_LOGIC;
44
            data_out  : out STD_LOGIC_VECTOR (0 to 15);
45
            out_rdy   : out STD_LOGIC
46
            );
47
end CAMELLIA_IF;
48
 
49
architecture RTL of CAMELLIA_IF is
50
 
51
    component CAMELLIA is
52
        port  (
53
                clk        : in  STD_LOGIC;
54
                reset      : in  STD_LOGIC;
55
                data_in    : in  STD_LOGIC_VECTOR (0 to 127);
56
                enc_dec    : in  STD_LOGIC;
57
                data_rdy   : in  STD_LOGIC;
58
                data_acq   : out STD_LOGIC;
59
                key        : in  STD_LOGIC_VECTOR (0 to 255);
60
                k_len      : in  STD_LOGIC_VECTOR (0 to 1);
61
                key_rdy    : in  STD_LOGIC;
62
                key_acq    : out STD_LOGIC;
63
                data_out   : out STD_LOGIC_VECTOR (0 to 127);
64
                output_rdy : out STD_LOGIC
65
                );
66
    end component;
67
 
68
    signal  s_clk        : STD_LOGIC;
69
    signal  s_reset      : STD_LOGIC;
70
    signal  s_data_in    : STD_LOGIC_VECTOR (0 to 127);
71
    signal  s_enc_dec    : STD_LOGIC;
72
    signal  s_data_rdy   : STD_LOGIC;
73
    signal  s_data_acq   : STD_LOGIC;
74
    signal  s_key        : STD_LOGIC_VECTOR (0 to 255);
75
    signal  s_k_len      : STD_LOGIC_VECTOR (0 to 1);
76
    signal  s_key_rdy    : STD_LOGIC;
77
    signal  s_key_acq    : STD_LOGIC;
78
    signal  s_data_out   : STD_LOGIC_VECTOR (0 to 127);
79
    signal  s_output_rdy : STD_LOGIC;
80
 
81 6 pfulgoni
    signal  key_count     : STD_LOGIC_VECTOR (3 downto 0);
82
    signal  din_count     : STD_LOGIC_VECTOR (2 downto 0);
83
    signal  dout_count    : STD_LOGIC_VECTOR (2 downto 0);
84 4 pfulgoni
 
85 6 pfulgoni
    signal  reg_key       : STD_LOGIC_VECTOR (0 to 255);
86
    signal  reg_din       : STD_LOGIC_VECTOR (0 to 127);
87
    signal  reg_dout      : STD_LOGIC_VECTOR (0 to 127);
88
    signal  reg_next_data : STD_LOGIC;
89
    signal  reg_next_key  : STD_LOGIC;
90 4 pfulgoni
 
91 6 pfulgoni
    signal  int_out_rdy   : STD_LOGIC;
92 4 pfulgoni
 
93
    -- input constant
94
    constant KLEN_128 : STD_LOGIC_VECTOR (0 to 1) := "00";
95
    constant KLEN_192 : STD_LOGIC_VECTOR (0 to 1) := "01";
96
    constant KLEN_256 : STD_LOGIC_VECTOR (0 to 1) := "10";
97
 
98
begin
99
 
100
    -- S-FUNCTION
101
    core : CAMELLIA
102
        port map(s_clk, s_reset, s_data_in, s_enc_dec, s_data_rdy,
103
                 s_data_acq, s_key, s_k_len, s_key_rdy, s_key_acq,
104
                 s_data_out, s_output_rdy);
105
 
106
    KEY_PROC: process (reset, clk)
107
    begin
108
 
109
        if (reset = '1') then
110 6 pfulgoni
            reg_next_key  <= '1';
111 4 pfulgoni
            key_count <= "0000";
112
            reg_key   <= (others=>'0');
113 6 pfulgoni
            s_key_rdy <= '0';
114 4 pfulgoni
        elsif (clk'event and clk = '1') then
115
 
116
            if (en_key = '1') then
117 6 pfulgoni
                reg_next_key <= '0';
118 4 pfulgoni
                key_count <= key_count + "0001";
119
                case k_len is
120
                    when KLEN_128 =>
121
                        reg_key <= reg_key(16 to 127) & key_in & X"00000000000000000000000000000000";
122
                    when KLEN_192 =>
123
                        reg_key <= reg_key(16 to 191) & key_in & X"0000000000000000";
124
                    when others =>
125
                        reg_key <= reg_key(16 to 255) & key_in;
126
                end case;
127
            else
128
                key_count <= "0000";
129 6 pfulgoni
                if (s_key_acq = '1') then
130
                    reg_next_key  <= '1';
131
                else
132
                    reg_next_key  <= reg_next_key;
133
                end if;
134
            end if;
135
 
136
            if ((key_count = "0111" and k_len = KLEN_128) or
137
                (key_count = "1100" and k_len = KLEN_192) or
138
                 key_count = "1111") then
139
                s_key_rdy <= '1';
140
            elsif (s_key_acq = '1') then
141
                s_key_rdy <= '0';
142
            else
143
                s_key_rdy <= s_key_rdy;
144
            end if;
145 4 pfulgoni
 
146
        end if;
147
 
148
    end process;
149
 
150
    DATA_IN_PROC: process (reset, clk)
151
    begin
152
 
153
        if (reset = '1') then
154 6 pfulgoni
            reg_next_data <= '1';
155 4 pfulgoni
            din_count <= "000";
156
            reg_din   <= (others=>'0');
157 6 pfulgoni
            s_data_rdy <= '0';
158 4 pfulgoni
        elsif (clk'event and clk = '1') then
159 6 pfulgoni
 
160
            if (en_data = '1') then
161
                reg_next_data <= '0';
162
                din_count <= din_count + "001";
163
                reg_din   <= reg_din(16 to 127) & data_in;
164
            else
165
                din_count <= "000";
166
                if (s_data_acq = '1') then
167
                    reg_next_data  <= '1';
168
                else
169
                    reg_next_data  <= reg_next_data;
170
                end if;
171
            end if;
172
 
173 4 pfulgoni
            if (din_count = "111") then
174
                s_data_rdy <= '1';
175
            elsif (s_data_acq = '1') then
176
                s_data_rdy <= '0';
177 6 pfulgoni
            else
178
                s_data_rdy <= s_data_rdy;
179 4 pfulgoni
            end if;
180
 
181
        end if;
182
 
183
    end process;
184
 
185
    DATA_OUT_PROC: process (reset, clk)
186
    begin
187
 
188
        if (reset = '1') then
189
            dout_count  <= "000";
190
            int_out_rdy <= '0';
191
            reg_dout    <= (others=>'0');
192
        elsif (clk'event and clk = '1') then
193
 
194
            if (int_out_rdy = '1') then
195
                if (dout_count /= "111") then
196
                    dout_count <= dout_count + "001";
197
                    reg_dout   <= reg_dout(16 to 127) & X"0000"; -- <<< 16
198
                else
199
                    int_out_rdy <= '0';
200
                end if;
201 6 pfulgoni
            else
202
                if (s_output_rdy = '1') then
203
                    dout_count <= "000";
204
                    reg_dout <= s_data_out;
205
                    int_out_rdy<= '1';
206
                end if;
207 4 pfulgoni
            end if;
208
        end if;
209
 
210
    end process;
211
 
212
    s_clk     <= clk;
213
    s_reset   <= reset;
214
    s_data_in <= reg_din;
215
    s_enc_dec <= enc_dec;
216
    s_key     <= reg_key;
217
    s_k_len   <= k_len;
218
    data_out  <= reg_dout(0 to 15);
219
    out_rdy   <= int_out_rdy;
220 6 pfulgoni
    next_key  <= reg_next_key;
221
    next_data <= reg_next_data;
222 4 pfulgoni
 
223
end RTL;
224
 

powered by: WebSVN 2.1.0

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