OpenCores
URL https://opencores.org/ocsvn/present/present/trunk

Subversion Repositories present

[/] [present/] [trunk/] [DecodeTesting/] [rtl/] [vhdl/] [PresentDec.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 gajos
-----------------------------------------------------------------------
2
----                                                               ----
3
---- Present - a lightweight block cipher project                  ----
4
----                                                               ----
5
---- This file is part of the Present - a lightweight block        ----
6
---- cipher project                                                ----
7
---- http://www.http://opencores.org/project,present               ----
8
----                                                               ----
9
---- Description:                                                  ----
10
----     Top level of present decoder. It contains 'Key generator' ----
11
---- from encoder and 'inverse Present' for decoding the cipher.   ----
12
---- For more information see                                      ----
13
---- http://homes.esat.kuleuven.be/~abogdano/papers/               ----
14
---- present_ches07.pdf                                            ----
15
---- To Do:                                                        ----
16
----                                                               ----
17
---- Author(s):                                                    ----
18
---- - Krzysztof Gajewski, gajos@opencores.org                     ----
19
----                       k.gajewski@gmail.com                    ----
20
----                                                               ----
21
-----------------------------------------------------------------------
22
----                                                               ----
23
---- Copyright (C) 2013 Authors and OPENCORES.ORG                  ----
24
----                                                               ----
25
---- This source file may be used and distributed without          ----
26
---- restriction provided that this copyright statement is not     ----
27
---- removed from the file and that any derivative work contains   ----
28
---- the original copyright notice and the associated disclaimer.  ----
29
----                                                               ----
30
---- This source file is free software; you can redistribute it    ----
31
---- and-or modify it under the terms of the GNU Lesser General    ----
32
---- Public License as published by the Free Software Foundation;  ----
33
---- either version 2.1 of the License, or (at your option) any    ----
34
---- later version.                                                ----
35
----                                                               ----
36
---- This source is distributed in the hope that it will be        ----
37
---- useful, but WITHOUT ANY WARRANTY; without even the implied    ----
38
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       ----
39
---- PURPOSE. See the GNU Lesser General Public License for more   ----
40
---- details.                                                      ----
41
----                                                               ----
42
---- You should have received a copy of the GNU Lesser General     ----
43
---- Public License along with this source; if not, download it    ----
44
---- from http://www.opencores.org/lgpl.shtml                      ----
45
----                                                               ----
46
-----------------------------------------------------------------------
47 3 gajos
library IEEE;
48
use IEEE.STD_LOGIC_1164.ALL;
49
use IEEE.STD_LOGIC_ARITH.ALL;
50
use IEEE.STD_LOGIC_UNSIGNED.ALL;
51
use IEEE.NUMERIC_STD.ALL;
52
 
53
entity PresentDec is
54
        generic (
55
                        w_2: integer := 2;
56
                        w_4: integer := 4;
57
                        w_5: integer := 5;
58
                        w_32: integer := 32;
59
                        w_64: integer := 64;
60
                        w_80: integer := 80
61
        );
62
        port(
63
                plaintext  : in std_logic_vector(w_64 - 1 downto 0);
64
                key               : in std_logic_vector(w_80 - 1 downto 0);
65
                ciphertext : out std_logic_vector(w_64 - 1 downto 0);
66
                start, clk, reset : in std_logic;
67
                ready : out std_logic
68
        );
69
end PresentDec;
70
 
71
architecture Behavioral of PresentDec is
72
 
73
        component Reg is
74
                generic(width : integer := w_64);
75
                port(
76
                        input  : in  STD_LOGIC_VECTOR(width - 1 downto 0);
77
                        output : out STD_LOGIC_VECTOR(width - 1 downto 0);
78
                        enable : in  STD_LOGIC;
79
                        clk    : in  STD_LOGIC;
80
                        reset  : in  STD_LOGIC
81
                );
82
        end component Reg;
83
 
84
        component AsyncMux is
85
                generic (
86
                        width : integer := 64
87
        );
88
        port (
89
                input0 : in  STD_LOGIC_VECTOR(width - 1 downto 0);
90
                input1 : in  STD_LOGIC_VECTOR(width - 1 downto 0);
91
                ctrl   : in  STD_LOGIC;
92
                output : out STD_LOGIC_VECTOR(width - 1 downto 0)
93
        );
94
        end component AsyncMux;
95
 
96
        component PresentDecStateMachine is
97
                generic (
98
                        w_5 : integer := 5
99
                );
100
                port (
101
                        clk, reset, start : in std_logic;
102
                        ready, cnt_res, ctrl_mux, RegEn: out std_logic;
103
                        num : in std_logic_vector (w_5-1 downto 0)
104
                );
105
        end component;
106
 
107 4 gajos
        -- INVERSE substitution layer for decoding
108 3 gajos
        component slayer_inv is
109
                generic (
110
                                w_4 : integer := 4
111
                );
112
                port (
113
                        input : in std_logic_vector(w_4-1 downto 0);
114
                        output : out std_logic_vector(w_4-1 downto 0)
115
                );
116
        end component;
117
 
118 4 gajos
        -- INVERSE permutation layer for decoding
119 3 gajos
        component pLayer_inv is
120
                generic(w_64 : integer := 64);
121
                port(
122
                        input : in std_logic_vector(w_64-1 downto 0);
123
                        output : out std_logic_vector(w_64-1 downto 0)
124
                );
125
        end component;
126
 
127 4 gajos
        -- INVERSE key update for decoding
128 3 gajos
        component keyupd_inv is
129
                generic(
130
                        w_5 : integer := 5;
131
                        w_80: integer := 80
132
                );
133
                port(
134
                        num : in std_logic_vector(w_5-1 downto 0);
135
                        key : in std_logic_vector(w_80-1 downto 0);
136
                        keyout : out std_logic_vector(w_80-1 downto 0)
137
                );
138
        end component;
139
 
140 4 gajos
        -- INVERSE counter for decoding. It is counting down!!!
141 3 gajos
        component counter_inv is
142
                generic (
143
                        w_5 : integer := 5
144
                );
145
                port (
146
                        clk, reset, cnt_res : in std_logic;
147
                        num : out std_logic_vector (w_5-1 downto 0)
148
                );
149
        end component;
150
 
151 4 gajos
        -- signals
152 3 gajos
        signal keynum : std_logic_vector (w_5-1 downto 0);
153
        signal toXor, ciph, P, Pout, textToReg : std_logic_vector (w_64-1 downto 0);
154
        signal keyfout, kupd, keyToReg : std_logic_vector (w_80-1 downto 0);
155
        signal ready_sig, mux_ctrl,  cnt_res, RegEn : std_logic;
156
 
157
        begin
158 4 gajos
 
159
            -- connections
160 3 gajos
                mux_64: AsyncMux generic map(width => w_64) port map(
161
                        input0 => plaintext,
162
                        input1 => Pout,
163
                        ctrl => mux_ctrl,
164
                        output => textToReg
165
                );
166
                regText : Reg generic map(width => w_64) port map(
167
                        input  => textToReg,
168
                        output  => toXor,
169
                        enable  => RegEn,
170
                        clk  => clk,
171
                        reset  => reset
172
                );
173
                mux_80: AsyncMux generic map(width => w_80) port map(
174
                        input0 => key,
175
                        input1 => kupd,
176
                        ctrl => mux_ctrl,
177
                        output => keyToReg
178
                );
179
                regKey : Reg generic map(width => w_80) port map(
180
                        input  => keyToReg,
181
                        output  => keyfout,
182
                        enable  => RegEn,
183
                        clk  => clk,
184
                        reset  => reset
185
                );
186
                slayers_inv : for N in 15 downto 0 generate
187
                        s_x: slayer_inv port map(
188
                                input => P(4*N+3 downto 4*N),
189
                                output => Pout(4*N+3 downto 4*N)
190
                        );
191
                end generate slayers_inv;
192
                p1: pLayer_inv port map(
193
                        input => ciph,
194
                        output => P
195
                );
196
                mixer: keyupd_inv port map(
197
                        key => keyfout,
198
                        num => keynum,
199
                        keyout => kupd
200
                );
201
                SM: PresentDecStateMachine port map(
202
                        start => start,
203
                        reset => reset,
204
                        ready => ready_sig,
205
                        cnt_res => cnt_res,
206
                        ctrl_mux => mux_ctrl,
207
                        clk => clk,
208
                        num => keynum,
209
                        RegEn => RegEn
210
                );
211
                count: counter_inv port map(
212
                        clk => clk,
213
                        reset => reset,
214
                        cnt_res => cnt_res,
215
                        num => keynum
216
                );
217
                ciph <= toXor xor keyfout(79 downto 16);
218
                ciphertext <= ciph;
219
                ready <= ready_sig;
220
end Behavioral;

powered by: WebSVN 2.1.0

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