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

Subversion Repositories sha256_hash_core

[/] [sha256_hash_core/] [trunk/] [syn/] [sha256/] [sha256_regs.vhd] - Blame information for rev 6

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

Line No. Rev Author Line
1 2 jdoin
-----------------------------------------------------------------------------------------------------------------------
2 6 jdoin
-- Author:          Jonny Doin, jdoin@opencores.org, jonnydoin@gmail.com, jonnydoin@gridvortex.com
3 2 jdoin
-- 
4 6 jdoin
-- Create Date:     09:56:30 05/06/2016  
5 2 jdoin
-- Module Name:     sha256_regs - RTL
6
-- Project Name:    sha256 processor
7
-- Target Devices:  Spartan-6
8
-- Tool versions:   ISE 14.7
9
-- Description: 
10
--
11
--      The regs block has the output result registers for the SHA256 processor.
12
--      It is a single-cycle 256bit Accumulator for the block hash results, and can be implemented
13
--      as a 32bit MUX and a 32bit carry chain for each register.
14
--
15
------------------------------ COPYRIGHT NOTICE -----------------------------------------------------------------------
16 6 jdoin
--                                                                   
17
--      This file is part of the SHA256 HASH CORE project http://opencores.org/project,sha256_hash_core
18
--                                                                   
19
--      Author(s):      Jonny Doin, jdoin@opencores.org, jonnydoin@gridvortex.com, jonnydoin@gmail.com
20
--                                                                   
21
--      Copyright (C) 2016 Jonny Doin
22
--      -----------------------------
23
--                                                                   
24
--      This source file may be used and distributed without restriction provided that this copyright statement is not    
25
--      removed from the file and that any derivative work contains the original copyright notice and the associated 
26
--      disclaimer. 
27
--                                                                   
28
--      This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
29
--      General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
30
--      (at your option) any later version.
31
--                                                                   
32
--      This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
33
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more  
34
--      details.
35
--
36
--      You should have received a copy of the GNU Lesser General Public License along with this source; if not, download 
37
--      it from http://www.gnu.org/licenses/lgpl.txt
38
--                                                                   
39 2 jdoin
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
40
--
41
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
42
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
43
-- 2016/06/05   v0.01.0095  [JD]    verification failed. misalignment of words in the datapath. 
44
-- 2016/06/06   v0.01.0100  [JD]    first simulation verification against NIST-FIPS-180-4 test vectors passed.
45
--
46
-----------------------------------------------------------------------------------------------------------------------
47
--  TODO
48
--  ====
49
--
50
-----------------------------------------------------------------------------------------------------------------------
51
library ieee;
52
use ieee.std_logic_1164.all;
53
use ieee.numeric_std.all;
54
 
55
entity sha256_regs is
56
    port (
57
        clk_i : in std_logic := 'X';                                            -- system clock
58
        ce_i : in std_logic := 'X';                                             -- clock enable from control logic
59
        ld_i : in std_logic := 'X';                                             -- internal mux selection from control logic
60
        A_i : in std_logic_vector (31 downto 0) := (others => 'X');
61
        B_i : in std_logic_vector (31 downto 0) := (others => 'X');
62
        C_i : in std_logic_vector (31 downto 0) := (others => 'X');
63
        D_i : in std_logic_vector (31 downto 0) := (others => 'X');
64
        E_i : in std_logic_vector (31 downto 0) := (others => 'X');
65
        F_i : in std_logic_vector (31 downto 0) := (others => 'X');
66
        G_i : in std_logic_vector (31 downto 0) := (others => 'X');
67
        H_i : in std_logic_vector (31 downto 0) := (others => 'X');
68
        K0_i : in std_logic_vector (31 downto 0) := (others => 'X');
69
        K1_i : in std_logic_vector (31 downto 0) := (others => 'X');
70
        K2_i : in std_logic_vector (31 downto 0) := (others => 'X');
71
        K3_i : in std_logic_vector (31 downto 0) := (others => 'X');
72
        K4_i : in std_logic_vector (31 downto 0) := (others => 'X');
73
        K5_i : in std_logic_vector (31 downto 0) := (others => 'X');
74
        K6_i : in std_logic_vector (31 downto 0) := (others => 'X');
75
        K7_i : in std_logic_vector (31 downto 0) := (others => 'X');
76
        N0_o : out std_logic_vector (31 downto 0) := (others => 'X');
77
        N1_o : out std_logic_vector (31 downto 0) := (others => 'X');
78
        N2_o : out std_logic_vector (31 downto 0) := (others => 'X');
79
        N3_o : out std_logic_vector (31 downto 0) := (others => 'X');
80
        N4_o : out std_logic_vector (31 downto 0) := (others => 'X');
81
        N5_o : out std_logic_vector (31 downto 0) := (others => 'X');
82
        N6_o : out std_logic_vector (31 downto 0) := (others => 'X');
83
        N7_o : out std_logic_vector (31 downto 0) := (others => 'X');
84
        H0_o : out std_logic_vector (31 downto 0) := (others => 'X');
85
        H1_o : out std_logic_vector (31 downto 0) := (others => 'X');
86
        H2_o : out std_logic_vector (31 downto 0) := (others => 'X');
87
        H3_o : out std_logic_vector (31 downto 0) := (others => 'X');
88
        H4_o : out std_logic_vector (31 downto 0) := (others => 'X');
89
        H5_o : out std_logic_vector (31 downto 0) := (others => 'X');
90
        H6_o : out std_logic_vector (31 downto 0) := (others => 'X');
91
        H7_o : out std_logic_vector (31 downto 0) := (others => 'X')
92
    );
93
end sha256_regs;
94
 
95
architecture rtl of sha256_regs is
96
    -- output result registers 
97
    signal reg_H0 : unsigned (31 downto 0) := (others => '0');
98
    signal reg_H1 : unsigned (31 downto 0) := (others => '0');
99
    signal reg_H2 : unsigned (31 downto 0) := (others => '0');
100
    signal reg_H3 : unsigned (31 downto 0) := (others => '0');
101
    signal reg_H4 : unsigned (31 downto 0) := (others => '0');
102
    signal reg_H5 : unsigned (31 downto 0) := (others => '0');
103
    signal reg_H6 : unsigned (31 downto 0) := (others => '0');
104
    signal reg_H7 : unsigned (31 downto 0) := (others => '0');
105
    -- word shifter wires
106
    signal next_reg_H0 : unsigned (31 downto 0) := (others => '0');
107
    signal next_reg_H1 : unsigned (31 downto 0) := (others => '0');
108
    signal next_reg_H2 : unsigned (31 downto 0) := (others => '0');
109
    signal next_reg_H3 : unsigned (31 downto 0) := (others => '0');
110
    signal next_reg_H4 : unsigned (31 downto 0) := (others => '0');
111
    signal next_reg_H5 : unsigned (31 downto 0) := (others => '0');
112
    signal next_reg_H6 : unsigned (31 downto 0) := (others => '0');
113
    signal next_reg_H7 : unsigned (31 downto 0) := (others => '0');
114
    -- internal modulo adders
115
    signal sum0 : unsigned (31 downto 0) := (others => '0');
116
    signal sum1 : unsigned (31 downto 0) := (others => '0');
117
    signal sum2 : unsigned (31 downto 0) := (others => '0');
118
    signal sum3 : unsigned (31 downto 0) := (others => '0');
119
    signal sum4 : unsigned (31 downto 0) := (others => '0');
120
    signal sum5 : unsigned (31 downto 0) := (others => '0');
121
    signal sum6 : unsigned (31 downto 0) := (others => '0');
122
    signal sum7 : unsigned (31 downto 0) := (others => '0');
123
begin
124
    --=============================================================================================
125
    -- OUTPUT RESULT REGISTERS LOGIC
126
    --=============================================================================================
127
    -- The output result registers hold the intermediate values for the hash update blocks, and also the final 256bit hash value. 
128
    --
129
 
130
    -- output register transfer logic
131
    out_regs_proc: process (clk_i, ce_i) is
132
    begin
133
        if clk_i'event and clk_i = '1' then
134
            if ce_i = '1' then
135
                reg_H0 <= next_reg_H0;
136
                reg_H1 <= next_reg_H1;
137
                reg_H2 <= next_reg_H2;
138
                reg_H3 <= next_reg_H3;
139
                reg_H4 <= next_reg_H4;
140
                reg_H5 <= next_reg_H5;
141
                reg_H6 <= next_reg_H6;
142
                reg_H7 <= next_reg_H7;
143
            end if;
144
        end if;
145
    end process out_regs_proc;
146
 
147
    -- input muxes
148
    next_reg_H0_proc: next_reg_H0 <= unsigned(K0_i) when ld_i = '1' else sum0;
149
    next_reg_H1_proc: next_reg_H1 <= unsigned(K1_i) when ld_i = '1' else sum1;
150
    next_reg_H2_proc: next_reg_H2 <= unsigned(K2_i) when ld_i = '1' else sum2;
151
    next_reg_H3_proc: next_reg_H3 <= unsigned(K3_i) when ld_i = '1' else sum3;
152
    next_reg_H4_proc: next_reg_H4 <= unsigned(K4_i) when ld_i = '1' else sum4;
153
    next_reg_H5_proc: next_reg_H5 <= unsigned(K5_i) when ld_i = '1' else sum5;
154
    next_reg_H6_proc: next_reg_H6 <= unsigned(K6_i) when ld_i = '1' else sum6;
155
    next_reg_H7_proc: next_reg_H7 <= unsigned(K7_i) when ld_i = '1' else sum7;
156
 
157
    -- adders 
158
    sum0_proc: sum0 <= reg_H0 + unsigned(A_i);
159
    sum1_proc: sum1 <= reg_H1 + unsigned(B_i);
160
    sum2_proc: sum2 <= reg_H2 + unsigned(C_i);
161
    sum3_proc: sum3 <= reg_H3 + unsigned(D_i);
162
    sum4_proc: sum4 <= reg_H4 + unsigned(E_i);
163
    sum5_proc: sum5 <= reg_H5 + unsigned(F_i);
164
    sum6_proc: sum6 <= reg_H6 + unsigned(G_i);
165
    sum7_proc: sum7 <= reg_H7 + unsigned(H_i);
166
 
167
    --=============================================================================================
168
    -- OUTPUT LOGIC
169
    --=============================================================================================
170
    -- connect output ports
171
    H0_o_proc:      H0_o <= std_logic_vector(reg_H0);
172
    H1_o_proc:      H1_o <= std_logic_vector(reg_H1);
173
    H2_o_proc:      H2_o <= std_logic_vector(reg_H2);
174
    H3_o_proc:      H3_o <= std_logic_vector(reg_H3);
175
    H4_o_proc:      H4_o <= std_logic_vector(reg_H4);
176
    H5_o_proc:      H5_o <= std_logic_vector(reg_H5);
177
    H6_o_proc:      H6_o <= std_logic_vector(reg_H6);
178
    H7_o_proc:      H7_o <= std_logic_vector(reg_H7);
179
 
180
    N0_o_proc:      N0_o <= std_logic_vector(next_reg_H0);
181
    N1_o_proc:      N1_o <= std_logic_vector(next_reg_H1);
182
    N2_o_proc:      N2_o <= std_logic_vector(next_reg_H2);
183
    N3_o_proc:      N3_o <= std_logic_vector(next_reg_H3);
184
    N4_o_proc:      N4_o <= std_logic_vector(next_reg_H4);
185
    N5_o_proc:      N5_o <= std_logic_vector(next_reg_H5);
186
    N6_o_proc:      N6_o <= std_logic_vector(next_reg_H6);
187
    N7_o_proc:      N7_o <= std_logic_vector(next_reg_H7);
188
end rtl;
189
 

powered by: WebSVN 2.1.0

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