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

Subversion Repositories camellia-vhdl

[/] [camellia-vhdl/] [trunk/] [pipelining/] [keysched128.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 pfulgoni
 
2
--------------------------------------------------------------------------------
3
-- Designer:      Paolo Fulgoni <pfulgoni@opencores.org>
4
--
5
-- Create Date:   09/14/2007
6 7 pfulgoni
-- Last Update:   04/09/2008
7 2 pfulgoni
-- Project Name:  camellia-vhdl
8
-- Description:   Key schedule only for 128-bit keys
9
--
10
-- Copyright (C) 2007  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
 
31
entity KEYSCHED128 is
32
    port    (
33
            reset  : in STD_LOGIC;
34
            clk    : in STD_LOGIC;
35
            kl_in  : in STD_LOGIC_VECTOR (0 to 127);
36
            kl_out : out STD_LOGIC_VECTOR (0 to 127);
37
            ka_out : out STD_LOGIC_VECTOR (0 to 127)
38
            );
39
end KEYSCHED128;
40
 
41
architecture RTL of KEYSCHED128 is
42
 
43
    component F is
44
        port    (
45
                reset : in STD_LOGIC;
46
                clk   : in STD_LOGIC;
47
                x     : in STD_LOGIC_VECTOR (0 to 63);
48
                k     : in STD_LOGIC_VECTOR (0 to 63);
49
                z     : out STD_LOGIC_VECTOR (0 to 63)
50
                );
51
    end component;
52
 
53
    -- f inputs
54
    signal f1_in  : STD_LOGIC_VECTOR (0 to 63);
55
    signal f2_in  : STD_LOGIC_VECTOR (0 to 63);
56
    signal f3_in  : STD_LOGIC_VECTOR (0 to 63);
57
    signal f4_in  : STD_LOGIC_VECTOR (0 to 63);
58
 
59
    -- f outputs
60
    signal f1_out : STD_LOGIC_VECTOR (0 to 63);
61
    signal f2_out : STD_LOGIC_VECTOR (0 to 63);
62
    signal f3_out : STD_LOGIC_VECTOR (0 to 63);
63
    signal f4_out : STD_LOGIC_VECTOR (0 to 63);
64
 
65
    -- intermediate registers
66
    signal reg1_l  : STD_LOGIC_VECTOR (0 to 63);
67
    signal reg1_r  : STD_LOGIC_VECTOR (0 to 63);
68
    signal reg1_kl : STD_LOGIC_VECTOR (0 to 127);
69
    signal reg2_l  : STD_LOGIC_VECTOR (0 to 63);
70
    signal reg2_r  : STD_LOGIC_VECTOR (0 to 63);
71
    signal reg2_kl : STD_LOGIC_VECTOR (0 to 127);
72
    signal reg3_l  : STD_LOGIC_VECTOR (0 to 63);
73
    signal reg3_r  : STD_LOGIC_VECTOR (0 to 63);
74
    signal reg3_kl : STD_LOGIC_VECTOR (0 to 127);
75
    signal reg4_l  : STD_LOGIC_VECTOR (0 to 63);
76
    signal reg4_r  : STD_LOGIC_VECTOR (0 to 63);
77
    signal reg4_kl : STD_LOGIC_VECTOR (0 to 127);
78
 
79
    -- constant keys
80
    constant k1 : STD_LOGIC_VECTOR (0 to 63) := X"A09E667F3BCC908B";
81
    constant k2 : STD_LOGIC_VECTOR (0 to 63) := X"B67AE8584CAA73B2";
82
    constant k3 : STD_LOGIC_VECTOR (0 to 63) := X"C6EF372FE94F82BE";
83
    constant k4 : STD_LOGIC_VECTOR (0 to 63) := X"54FF53A5F1D36F1C";
84
 
85
    -- intermediate signal
86
    signal inter   : STD_LOGIC_VECTOR (0 to 127);
87
 
88
begin
89
 
90
    F1 : F
91
        port map(reset, clk, f1_in, k1, f1_out);
92
    F2 : F
93
        port map(reset, clk, f2_in, k2, f2_out);
94
    F3 : F
95
        port map(reset, clk, f3_in, k3, f3_out);
96
    F4 : F
97
        port map(reset, clk, f4_in, k4, f4_out);
98
 
99
    REG : process(reset, clk)
100
    begin
101
 
102
        if (reset = '1') then
103
            reg1_l  <= (others=>'0');
104
            reg1_r  <= (others=>'0');
105
            reg1_kl <= (others=>'0');
106
            reg2_l  <= (others=>'0');
107
            reg2_r  <= (others=>'0');
108
            reg2_kl <= (others=>'0');
109
            reg3_l  <= (others=>'0');
110
            reg3_r  <= (others=>'0');
111
            reg3_kl <= (others=>'0');
112
            reg4_l  <= (others=>'0');
113
            reg4_r  <= (others=>'0');
114
            reg4_kl <= (others=>'0');
115
        else
116 7 pfulgoni
            if (rising_edge(clk)) then -- rising clock edge
117 2 pfulgoni
                reg1_l  <= f1_in;
118
                reg1_r  <= kl_in(64 to 127);
119
                reg1_kl <= kl_in;
120
                reg2_l  <= f2_in;
121
                reg2_r  <= reg1_l;
122
                reg2_kl <= reg1_kl;
123
                reg3_l  <= f3_in;
124
                reg3_r  <= inter(64 to 127);
125
                reg3_kl <= reg2_kl;
126
                reg4_l  <= f4_in;
127
                reg4_r  <= reg3_l;
128
                reg4_kl <= reg3_kl;
129
            end if;
130
        end if;
131
    end process;
132
 
133
    inter  <= ((f2_out xor reg2_r) & reg2_l) xor reg2_kl;
134
 
135
    -- f inputs
136
    f1_in <= kl_in(0 to 63);
137
    f2_in <= f1_out xor reg1_r;
138
    f3_in <= inter(0 to 63);
139
    f4_in <= f3_out xor reg3_r;
140
 
141
    -- output
142
    kl_out <= reg4_kl;
143
    ka_out <= (f4_out xor reg4_r) & reg4_l;
144
 
145
end RTL;

powered by: WebSVN 2.1.0

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