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_hash_core.vhd] - Blame information for rev 10

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_hash_core - RTL
6
-- Project Name:    sha256 processor
7
-- Target Devices:  Spartan-6
8
-- Tool versions:   ISE 14.7
9
-- Description: 
10
--
11
--      This is the 256bit single-cycle hash core processing logic for each of the 64 block steps. 
12
--      The combinational depth of this block is 8 layers of logic and adders.
13
--      This module will be the largest limitation of the synthesis top operating frequency.
14
--      If extra pipelining is needed, the control logic must account for the extra clock delays.
15
--
16
------------------------------ COPYRIGHT NOTICE -----------------------------------------------------------------------
17 10 jdoin
--                                                                   
18
--      This file is part of the SHA256 HASH CORE project http://opencores.org/project,sha256_hash_core
19
--                                                                   
20
--      Author(s):      Jonny Doin, jdoin@opencores.org, jonnydoin@gridvortex.com, jonnydoin@gmail.com
21
--                                                                   
22
--      Copyright (C) 2016 Jonny Doin
23
--      -----------------------------
24
--                                                                   
25
--      This source file may be used and distributed without restriction provided that this copyright statement is not    
26
--      removed from the file and that any derivative work contains the original copyright notice and the associated 
27
--      disclaimer. 
28
--                                                                   
29
--      This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
30
--      General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
31
--      (at your option) any later version.
32
--                                                                   
33
--      This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
34
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more  
35
--      details.
36
--
37
--      You should have received a copy of the GNU Lesser General Public License along with this source; if not, download 
38
--      it from http://www.gnu.org/licenses/lgpl.txt
39
--                                                                   
40 2 jdoin
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
41
--
42
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
43
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
44
-- 2016/06/05   v0.01.0095  [JD]    failed verification. misalignment of words in the datapath. 
45
-- 2016/06/06   v0.01.0100  [JD]    passed first simulation verification against NIST-FIPS-180-4 test vectors.
46
-- 2016/06/06   v0.01.0100  [JD]    passed first simulation verification against NIST-FIPS-180-4 test vectors.
47
-- 2016/06/07   v0.01.0105  [JD]    passed verification against all NIST-FIPS-180-4 test vectors.
48
-- 2016/06/11   v0.01.0105  [JD]    passed verification against NIST-SHA2_Additional test vectors #1 to #10.
49
--
50
-----------------------------------------------------------------------------------------------------------------------
51
--  TODO
52
--  ====
53
--
54
-----------------------------------------------------------------------------------------------------------------------
55
library ieee;
56
use ieee.std_logic_1164.all;
57
use ieee.numeric_std.all;
58
 
59
 
60
entity sha256_hash_core is
61
    port (
62
        clk_i : in std_logic := 'U';                                    -- system clock
63
        ce_i : in std_logic := 'U';                                     -- clock enable from control logic
64
        ld_i : in std_logic := 'U';                                     -- parallel load internal registers with input words
65
        A_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg A
66
        B_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg B
67
        C_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg C
68
        D_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg D
69
        E_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg E
70
        F_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg F
71
        G_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg G
72
        H_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg H
73
        A_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg A
74
        B_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg B
75
        C_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg C
76
        D_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg D
77
        E_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg E
78
        F_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg F
79
        G_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg G
80
        H_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg H
81
        Kt_i : in std_logic_vector (31 downto 0) := (others => 'U');    -- coefficients for the 64 steps of the message schedule
82
        Wt_i : in std_logic_vector (31 downto 0) := (others => 'U')     -- message schedule words for the 64 steps
83
    );
84
end sha256_hash_core;
85
 
86
architecture rtl of sha256_hash_core is
87
    -- core registers
88
    signal reg_a : unsigned (31 downto 0) := (others => '0');
89
    signal reg_b : unsigned (31 downto 0) := (others => '0');
90
    signal reg_c : unsigned (31 downto 0) := (others => '0');
91
    signal reg_d : unsigned (31 downto 0) := (others => '0');
92
    signal reg_e : unsigned (31 downto 0) := (others => '0');
93
    signal reg_f : unsigned (31 downto 0) := (others => '0');
94
    signal reg_g : unsigned (31 downto 0) := (others => '0');
95
    signal reg_h : unsigned (31 downto 0) := (others => '0');
96
    -- combinational inputs
97
    signal next_reg_a : unsigned (31 downto 0);
98
    signal next_reg_b : unsigned (31 downto 0);
99
    signal next_reg_c : unsigned (31 downto 0);
100
    signal next_reg_d : unsigned (31 downto 0);
101
    signal next_reg_e : unsigned (31 downto 0);
102
    signal next_reg_f : unsigned (31 downto 0);
103
    signal next_reg_g : unsigned (31 downto 0);
104
    signal next_reg_h : unsigned (31 downto 0);
105
    -- internal modulo adders
106
    signal sum0 : unsigned (31 downto 0);
107
    signal sum1 : unsigned (31 downto 0);
108
    signal sum2 : unsigned (31 downto 0);
109
    signal sum3 : unsigned (31 downto 0);
110
    signal sum4 : unsigned (31 downto 0);
111
    signal sum5 : unsigned (31 downto 0);
112
    signal sum6 : unsigned (31 downto 0);
113
    -- upper sigma functions
114
    signal SIG0 : unsigned (31 downto 0);
115
    signal SIG1 : unsigned (31 downto 0);
116
    -- Ch and Maj functions
117
    signal Ch : unsigned (31 downto 0);
118
    signal Maj : unsigned (31 downto 0);
119
begin
120
    --=============================================================================================
121
    -- HASH BLOCK CORE LOGIC
122
    --=============================================================================================
123
    -- The hash core block implements the hash kernel operation that is used in each of the 64 block hash steps. 
124
    -- All operations for a kernel step execute in a single clock cycle.
125
    -- The longest combinational path is the 'next_reg_a', with 12 logic layers total, including the upstream 
126
    -- datapath from the message scheduler. 
127
 
128
    -- core register transfer logic
129
    core_regs_proc: process (clk_i, ce_i) is
130
    begin
131
        if clk_i'event and clk_i = '1' then
132
            if ce_i = '1' then
133
                reg_a <= next_reg_a;
134
                reg_b <= next_reg_b;
135
                reg_c <= next_reg_c;
136
                reg_d <= next_reg_d;
137
                reg_e <= next_reg_e;
138
                reg_f <= next_reg_f;
139
                reg_g <= next_reg_g;
140
                reg_h <= next_reg_h;
141
            end if;
142
        end if;
143
    end process core_regs_proc;
144 10 jdoin
 
145
    --=============================================================================================
146
    --  COMBINATIONAL LOGIC
147
    --=============================================================================================
148
    -- word rotation and bit manipulation for each cycle
149 2 jdoin
 
150
    -- input muxes and word shifter wires
151
    next_reg_a_proc: next_reg_a <= unsigned(A_i) when ld_i = '1' else sum0;
152
    next_reg_b_proc: next_reg_b <= unsigned(B_i) when ld_i = '1' else reg_a;
153
    next_reg_c_proc: next_reg_c <= unsigned(C_i) when ld_i = '1' else reg_b;
154
    next_reg_d_proc: next_reg_d <= unsigned(D_i) when ld_i = '1' else reg_c;
155
    next_reg_e_proc: next_reg_e <= unsigned(E_i) when ld_i = '1' else sum2;
156
    next_reg_f_proc: next_reg_f <= unsigned(F_i) when ld_i = '1' else reg_e;
157
    next_reg_g_proc: next_reg_g <= unsigned(G_i) when ld_i = '1' else reg_f;
158
    next_reg_h_proc: next_reg_h <= unsigned(H_i) when ld_i = '1' else reg_g;
159
 
160
    -- adders for the ARX functions
161
    sum0_proc: sum0 <= sum1 + sum3;
162
    sum1_proc: sum1 <= SIG0 + Maj;
163
    sum2_proc: sum2 <= sum3 + reg_d;
164
    sum3_proc: sum3 <= sum4 + SIG1;
165
    sum4_proc: sum4 <= sum5 + unsigned(Wt_i);
166
    sum5_proc: sum5 <= sum6 + unsigned(Kt_i);
167
    sum6_proc: sum6 <= reg_h + Ch;
168
 
169
    -- upper sigma functions
170
    SIG0_proc: SIG0 <= (reg_a(1 downto 0) & reg_a(31 downto 2)) xor (reg_a(12 downto 0) & reg_a(31 downto 13)) xor (reg_a(21 downto 0) & reg_a(31 downto 22));
171
    SIG1_proc: SIG1 <= (reg_e(5 downto 0) & reg_e(31 downto 6)) xor (reg_e(10 downto 0) & reg_e(31 downto 11)) xor (reg_e(24 downto 0) & reg_e(31 downto 25));
172
 
173
    -- Maj and Ch functions
174
    Maj_proc: Maj <= (reg_a and reg_b) xor (reg_a and reg_c) xor (reg_b and reg_c);
175
    Ch_proc:  Ch <= (reg_e and reg_f) xor ((not reg_e) and reg_g);
176
 
177
    --=============================================================================================
178
    -- OUTPUT LOGIC
179
    --=============================================================================================
180
    -- connect output ports
181
    A_o_proc:       A_o <= std_logic_vector(reg_a);
182
    B_o_proc:       B_o <= std_logic_vector(reg_b);
183
    C_o_proc:       C_o <= std_logic_vector(reg_c);
184
    D_o_proc:       D_o <= std_logic_vector(reg_d);
185
    E_o_proc:       E_o <= std_logic_vector(reg_e);
186
    F_o_proc:       F_o <= std_logic_vector(reg_f);
187
    G_o_proc:       G_o <= std_logic_vector(reg_g);
188
    H_o_proc:       H_o <= std_logic_vector(reg_h);
189
end rtl;
190
 

powered by: WebSVN 2.1.0

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