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 2

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

Line No. Rev Author Line
1 2 jdoin
-----------------------------------------------------------------------------------------------------------------------
2
-- Author:          Jonny Doin, jdoin@opencores.org, jonnydoin@gmail.com
3
-- 
4
-- Create Date:     09:56:30 07/06/2011  
5
-- 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
--                                                                   
18
--                                                                   
19
--      Author(s):      Jonny Doin, jonnydoin@gridvortex.com, jonnydoin@gmail.com
20
--                                                                   
21
--      Copyright (C) 2016 GridVortex, All Rights Reserved
22
--      --------------------------------------------------
23
--                                                                   
24
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
25
--
26
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
27
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
28
-- 2016/06/05   v0.01.0095  [JD]    failed verification. misalignment of words in the datapath. 
29
-- 2016/06/06   v0.01.0100  [JD]    passed first simulation verification against NIST-FIPS-180-4 test vectors.
30
-- 2016/06/06   v0.01.0100  [JD]    passed first simulation verification against NIST-FIPS-180-4 test vectors.
31
-- 2016/06/07   v0.01.0105  [JD]    passed verification against all NIST-FIPS-180-4 test vectors.
32
-- 2016/06/11   v0.01.0105  [JD]    passed verification against NIST-SHA2_Additional test vectors #1 to #10.
33
--
34
-----------------------------------------------------------------------------------------------------------------------
35
--  TODO
36
--  ====
37
--
38
-----------------------------------------------------------------------------------------------------------------------
39
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.numeric_std.all;
42
 
43
 
44
entity sha256_hash_core is
45
    port (
46
        clk_i : in std_logic := 'U';                                    -- system clock
47
        ce_i : in std_logic := 'U';                                     -- clock enable from control logic
48
        ld_i : in std_logic := 'U';                                     -- parallel load internal registers with input words
49
        A_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg A
50
        B_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg B
51
        C_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg C
52
        D_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg D
53
        E_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg E
54
        F_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg F
55
        G_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg G
56
        H_i : in std_logic_vector (31 downto 0) := (others => 'U');     -- input for reg H
57
        A_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg A
58
        B_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg B
59
        C_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg C
60
        D_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg D
61
        E_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg E
62
        F_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg F
63
        G_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg G
64
        H_o : out std_logic_vector (31 downto 0) := (others => 'U');    -- output for reg H
65
        Kt_i : in std_logic_vector (31 downto 0) := (others => 'U');    -- coefficients for the 64 steps of the message schedule
66
        Wt_i : in std_logic_vector (31 downto 0) := (others => 'U')     -- message schedule words for the 64 steps
67
    );
68
end sha256_hash_core;
69
 
70
architecture rtl of sha256_hash_core is
71
    -- core registers
72
    signal reg_a : unsigned (31 downto 0) := (others => '0');
73
    signal reg_b : unsigned (31 downto 0) := (others => '0');
74
    signal reg_c : unsigned (31 downto 0) := (others => '0');
75
    signal reg_d : unsigned (31 downto 0) := (others => '0');
76
    signal reg_e : unsigned (31 downto 0) := (others => '0');
77
    signal reg_f : unsigned (31 downto 0) := (others => '0');
78
    signal reg_g : unsigned (31 downto 0) := (others => '0');
79
    signal reg_h : unsigned (31 downto 0) := (others => '0');
80
    -- combinational inputs
81
    signal next_reg_a : unsigned (31 downto 0);
82
    signal next_reg_b : unsigned (31 downto 0);
83
    signal next_reg_c : unsigned (31 downto 0);
84
    signal next_reg_d : unsigned (31 downto 0);
85
    signal next_reg_e : unsigned (31 downto 0);
86
    signal next_reg_f : unsigned (31 downto 0);
87
    signal next_reg_g : unsigned (31 downto 0);
88
    signal next_reg_h : unsigned (31 downto 0);
89
    -- internal modulo adders
90
    signal sum0 : unsigned (31 downto 0);
91
    signal sum1 : unsigned (31 downto 0);
92
    signal sum2 : unsigned (31 downto 0);
93
    signal sum3 : unsigned (31 downto 0);
94
    signal sum4 : unsigned (31 downto 0);
95
    signal sum5 : unsigned (31 downto 0);
96
    signal sum6 : unsigned (31 downto 0);
97
    -- upper sigma functions
98
    signal SIG0 : unsigned (31 downto 0);
99
    signal SIG1 : unsigned (31 downto 0);
100
    -- Ch and Maj functions
101
    signal Ch : unsigned (31 downto 0);
102
    signal Maj : unsigned (31 downto 0);
103
begin
104
    --=============================================================================================
105
    -- HASH BLOCK CORE LOGIC
106
    --=============================================================================================
107
    -- The hash core block implements the hash kernel operation that is used in each of the 64 block hash steps. 
108
    -- All operations for a kernel step execute in a single clock cycle.
109
    -- The longest combinational path is the 'next_reg_a', with 12 logic layers total, including the upstream 
110
    -- datapath from the message scheduler. 
111
 
112
    -- core register transfer logic
113
    core_regs_proc: process (clk_i, ce_i) is
114
    begin
115
        if clk_i'event and clk_i = '1' then
116
            if ce_i = '1' then
117
                reg_a <= next_reg_a;
118
                reg_b <= next_reg_b;
119
                reg_c <= next_reg_c;
120
                reg_d <= next_reg_d;
121
                reg_e <= next_reg_e;
122
                reg_f <= next_reg_f;
123
                reg_g <= next_reg_g;
124
                reg_h <= next_reg_h;
125
            end if;
126
        end if;
127
    end process core_regs_proc;
128
 
129
    -- input muxes and word shifter wires
130
    next_reg_a_proc: next_reg_a <= unsigned(A_i) when ld_i = '1' else sum0;
131
    next_reg_b_proc: next_reg_b <= unsigned(B_i) when ld_i = '1' else reg_a;
132
    next_reg_c_proc: next_reg_c <= unsigned(C_i) when ld_i = '1' else reg_b;
133
    next_reg_d_proc: next_reg_d <= unsigned(D_i) when ld_i = '1' else reg_c;
134
    next_reg_e_proc: next_reg_e <= unsigned(E_i) when ld_i = '1' else sum2;
135
    next_reg_f_proc: next_reg_f <= unsigned(F_i) when ld_i = '1' else reg_e;
136
    next_reg_g_proc: next_reg_g <= unsigned(G_i) when ld_i = '1' else reg_f;
137
    next_reg_h_proc: next_reg_h <= unsigned(H_i) when ld_i = '1' else reg_g;
138
 
139
    -- adders for the ARX functions
140
    sum0_proc: sum0 <= sum1 + sum3;
141
    sum1_proc: sum1 <= SIG0 + Maj;
142
    sum2_proc: sum2 <= sum3 + reg_d;
143
    sum3_proc: sum3 <= sum4 + SIG1;
144
    sum4_proc: sum4 <= sum5 + unsigned(Wt_i);
145
    sum5_proc: sum5 <= sum6 + unsigned(Kt_i);
146
    sum6_proc: sum6 <= reg_h + Ch;
147
 
148
    -- upper sigma functions
149
    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));
150
    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));
151
 
152
    -- Maj and Ch functions
153
    Maj_proc: Maj <= (reg_a and reg_b) xor (reg_a and reg_c) xor (reg_b and reg_c);
154
    Ch_proc:  Ch <= (reg_e and reg_f) xor ((not reg_e) and reg_g);
155
 
156
    --=============================================================================================
157
    -- OUTPUT LOGIC
158
    --=============================================================================================
159
    -- connect output ports
160
    A_o_proc:       A_o <= std_logic_vector(reg_a);
161
    B_o_proc:       B_o <= std_logic_vector(reg_b);
162
    C_o_proc:       C_o <= std_logic_vector(reg_c);
163
    D_o_proc:       D_o <= std_logic_vector(reg_d);
164
    E_o_proc:       E_o <= std_logic_vector(reg_e);
165
    F_o_proc:       F_o <= std_logic_vector(reg_f);
166
    G_o_proc:       G_o <= std_logic_vector(reg_g);
167
    H_o_proc:       H_o <= std_logic_vector(reg_h);
168
end rtl;
169
 

powered by: WebSVN 2.1.0

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