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_msg_sch.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_msg_sch - RTL
6
-- Project Name:    sha256 processor
7
-- Target Devices:  Spartan-6
8
-- Tool versions:   ISE 14.7
9
-- Description: 
10
--
11
--      This is the message scheduler datapath for the sha256 processor.
12
--
13
------------------------------ COPYRIGHT NOTICE -----------------------------------------------------------------------
14 10 jdoin
--                                                                   
15
--      This file is part of the SHA256 HASH CORE project http://opencores.org/project,sha256_hash_core
16
--                                                                   
17
--      Author(s):      Jonny Doin, jdoin@opencores.org, jonnydoin@gridvortex.com, jonnydoin@gmail.com
18
--                                                                   
19
--      Copyright (C) 2016 Jonny Doin
20
--      -----------------------------
21
--                                                                   
22
--      This source file may be used and distributed without restriction provided that this copyright statement is not    
23
--      removed from the file and that any derivative work contains the original copyright notice and the associated 
24
--      disclaimer. 
25
--                                                                   
26
--      This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
27
--      General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
28
--      (at your option) any later version.
29
--                                                                   
30
--      This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
31
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more  
32
--      details.
33
--
34
--      You should have received a copy of the GNU Lesser General Public License along with this source; if not, download 
35
--      it from http://www.gnu.org/licenses/lgpl.txt
36
--                                                                   
37 2 jdoin
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
38
--
39
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
40
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
41
-- 2016/06/05   v0.01.0095  [JD]    verification failed. misalignment of words in the datapath. 
42
-- 2016/06/06   v0.01.0100  [JD]    first simulation verification against NIST-FIPS-180-4 test vectors passed.
43
--
44
-----------------------------------------------------------------------------------------------------------------------
45
--  TODO
46
--  ====
47
--
48
-----------------------------------------------------------------------------------------------------------------------
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.numeric_std.all;
52
 
53
 
54
entity sha256_msg_sch is
55
    port (
56
        clk_i : in std_logic := 'U';                                            -- system clock
57 10 jdoin
        ce_i : in std_logic := 'U';                                             -- clock input to word shifter
58
        ld_i : in std_logic := 'U';                                             -- transparent load input to output
59 2 jdoin
        M_i : in std_logic_vector (31 downto 0) := (others => 'U');             -- big endian input message words
60
        Wt_o : out std_logic_vector (31 downto 0)                               -- message schedule output words
61
    );
62
end sha256_msg_sch;
63
 
64
architecture rtl of sha256_msg_sch is
65
    -- datapath pipeline 
66
    signal r0 : unsigned (31 downto 0) := (others => '0');              -- internal message register
67
    signal r1 : unsigned (31 downto 0) := (others => '0');              -- internal message register
68
    signal r2 : unsigned (31 downto 0) := (others => '0');              -- internal message register
69
    signal r3 : unsigned (31 downto 0) := (others => '0');              -- internal message register
70
    signal r4 : unsigned (31 downto 0) := (others => '0');              -- internal message register
71
    signal r5 : unsigned (31 downto 0) := (others => '0');              -- internal message register
72
    signal r6 : unsigned (31 downto 0) := (others => '0');              -- internal message register
73
    signal r7 : unsigned (31 downto 0) := (others => '0');              -- internal message register
74
    signal r8 : unsigned (31 downto 0) := (others => '0');              -- internal message register
75
    signal r9 : unsigned (31 downto 0) := (others => '0');              -- internal message register
76
    signal r10 : unsigned (31 downto 0) := (others => '0');             -- internal message register
77
    signal r11 : unsigned (31 downto 0) := (others => '0');             -- internal message register
78
    signal r12 : unsigned (31 downto 0) := (others => '0');             -- internal message register
79
    signal r13 : unsigned (31 downto 0) := (others => '0');             -- internal message register
80
    signal r14 : unsigned (31 downto 0) := (others => '0');             -- internal message register
81
    signal r15 : unsigned (31 downto 0) := (others => '0');             -- internal message register
82
    -- input mux feedback
83
    signal next_M : unsigned (31 downto 0);                             -- sum feedback
84
    -- word shifter wires
85
    signal next_r0 : unsigned (31 downto 0);
86
    signal next_r1 : unsigned (31 downto 0);
87
    signal next_r2 : unsigned (31 downto 0);
88
    signal next_r3 : unsigned (31 downto 0);
89
    signal next_r4 : unsigned (31 downto 0);
90
    signal next_r5 : unsigned (31 downto 0);
91
    signal next_r6 : unsigned (31 downto 0);
92
    signal next_r7 : unsigned (31 downto 0);
93
    signal next_r8 : unsigned (31 downto 0);
94
    signal next_r9 : unsigned (31 downto 0);
95
    signal next_r10 : unsigned (31 downto 0);
96
    signal next_r11 : unsigned (31 downto 0);
97
    signal next_r12 : unsigned (31 downto 0);
98
    signal next_r13 : unsigned (31 downto 0);
99
    signal next_r14 : unsigned (31 downto 0);
100
    signal next_r15 : unsigned (31 downto 0);
101
    -- internal modulo adders
102
    signal sum0 : unsigned (31 downto 0);               -- modulo adder r1 + sum1
103
    signal sum1 : unsigned (31 downto 0);               -- modulo adder s0 + sum2
104
    signal sum2 : unsigned (31 downto 0);               -- modulo adder s1 + r10
105
    -- lower sigma functions
106
    signal s0 : unsigned (31 downto 0);                 -- lower sigma0 function
107
    signal s1 : unsigned (31 downto 0);                 -- lower sigma1 function
108
begin
109
    --=============================================================================================
110
    -- MESSAGE SCHEDULER LOGIC
111
    --=============================================================================================
112
    -- This logic implements the 256 bytes message schedule as a folded 16 word circular word shifter.
113
    -- The Add-Rotate-Xor functions s0 and s1 are implemented and fed back to the word shifter.
114
    -- To avoid a datapath pipeline delay insertion, the output is taken from the r0 input, rather than
115
    -- the registered r0 output. This lookahead reduces one clock cycle in the overall hash computation,
116
    -- but increases the combinational path from the input to the processor core.
117
    -- The next_r0 combinational function has 5 layers of logic, including 3 carry chains.
118
 
119
    -- word shifter register transfer logic
120
    word_shifter_proc: process (clk_i, ce_i) is
121
    begin
122
        if clk_i'event and clk_i = '1' then
123
            if ce_i = '1' then
124
                r0 <= next_r0;
125
                r1 <= next_r1;
126
                r2 <= next_r2;
127
                r3 <= next_r3;
128
                r4 <= next_r4;
129
                r5 <= next_r5;
130
                r6 <= next_r6;
131
                r7 <= next_r7;
132
                r8 <= next_r8;
133
                r9 <= next_r9;
134
                r10 <= next_r10;
135
                r11 <= next_r11;
136
                r12 <= next_r12;
137
                r13 <= next_r13;
138
                r14 <= next_r14;
139
                r15 <= next_r15;
140
            end if;
141
        end if;
142
    end process word_shifter_proc;
143
 
144
    -- input mux 
145
    next_r0_proc: next_r0 <= unsigned(M_i) when ld_i = '1' else next_M;
146
    next_m_proc:  next_M <= sum0;
147
 
148
    -- word shifter wires
149
    next_r15_proc: next_r15 <= r0;
150
    next_r14_proc: next_r14 <= r15;
151
    next_r13_proc: next_r13 <= r14;
152
    next_r12_proc: next_r12 <= r13;
153
    next_r11_proc: next_r11 <= r12;
154
    next_r10_proc: next_r10 <= r11;
155
    next_r9_proc: next_r9 <= r10;
156
    next_r8_proc: next_r8 <= r9;
157
    next_r7_proc: next_r7 <= r8;
158
    next_r6_proc: next_r6 <= r7;
159
    next_r5_proc: next_r5 <= r6;
160
    next_r4_proc: next_r4 <= r5;
161
    next_r3_proc: next_r3 <= r4;
162
    next_r2_proc: next_r2 <= r3;
163
    next_r1_proc: next_r1 <= r2;
164
 
165
    -- adders 
166
    sum0_proc: sum0 <= sum1 + r1;
167
    sum1_proc: sum1 <= sum2 + s0;
168
    sum2_proc: sum2 <= r10 + s1;
169
 
170
    -- lower sigma functions
171
    s0_proc: s0 <= (B"000" & r2(31 downto 3)) xor (r2(17 downto 0) & r2(31 downto 18)) xor (r2(6 downto 0) & r2(31 downto 7));
172
    s1_proc: s1 <= (B"0000000000" & r15(31 downto 10)) xor (r15(18 downto 0) & r15(31 downto 19)) xor (r15(16 downto 0) & r15(31 downto 17));
173
 
174
    --=============================================================================================
175
    -- OUTPUT LOGIC
176
    --=============================================================================================
177
    -- connect output ports
178
    Wt_o_proc:      Wt_o <= std_logic_vector(next_r0);  -- message scheduler output look ahead
179
end rtl;
180
 

powered by: WebSVN 2.1.0

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