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 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_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
--                                                                   
15
--                                                                   
16
--      Author(s):      Jonny Doin, jonnydoin@gridvortex.com, jonnydoin@gmail.com
17
--                                                                   
18
--      Copyright (C) 2016 GridVortex, All Rights Reserved
19
--      --------------------------------------------------
20
--                                                                   
21
------------------------------ REVISION HISTORY -----------------------------------------------------------------------
22
--
23
-- 2016/05/22   v0.01.0010  [JD]    started development. design of blocks and port interfaces.
24
-- 2016/06/05   v0.01.0090  [JD]    all modules integrated. testbench for basic test vectors verification.
25
-- 2016/06/05   v0.01.0095  [JD]    verification failed. misalignment of words in the datapath. 
26
-- 2016/06/06   v0.01.0100  [JD]    first simulation verification against NIST-FIPS-180-4 test vectors passed.
27
--
28
-----------------------------------------------------------------------------------------------------------------------
29
--  TODO
30
--  ====
31
--
32
-----------------------------------------------------------------------------------------------------------------------
33
library ieee;
34
use ieee.std_logic_1164.all;
35
use ieee.numeric_std.all;
36
 
37
 
38
entity sha256_msg_sch is
39
    port (
40
        clk_i : in std_logic := 'U';                                            -- system clock
41
        ce_i : in std_logic := 'U';                                             -- clock enable from control logic
42
        ld_i : in std_logic := 'U';                                             -- internal mux selection from control logic
43
        M_i : in std_logic_vector (31 downto 0) := (others => 'U');             -- big endian input message words
44
        Wt_o : out std_logic_vector (31 downto 0)                               -- message schedule output words
45
    );
46
end sha256_msg_sch;
47
 
48
architecture rtl of sha256_msg_sch is
49
    -- datapath pipeline 
50
    signal r0 : unsigned (31 downto 0) := (others => '0');              -- internal message register
51
    signal r1 : unsigned (31 downto 0) := (others => '0');              -- internal message register
52
    signal r2 : unsigned (31 downto 0) := (others => '0');              -- internal message register
53
    signal r3 : unsigned (31 downto 0) := (others => '0');              -- internal message register
54
    signal r4 : unsigned (31 downto 0) := (others => '0');              -- internal message register
55
    signal r5 : unsigned (31 downto 0) := (others => '0');              -- internal message register
56
    signal r6 : unsigned (31 downto 0) := (others => '0');              -- internal message register
57
    signal r7 : unsigned (31 downto 0) := (others => '0');              -- internal message register
58
    signal r8 : unsigned (31 downto 0) := (others => '0');              -- internal message register
59
    signal r9 : unsigned (31 downto 0) := (others => '0');              -- internal message register
60
    signal r10 : unsigned (31 downto 0) := (others => '0');             -- internal message register
61
    signal r11 : unsigned (31 downto 0) := (others => '0');             -- internal message register
62
    signal r12 : unsigned (31 downto 0) := (others => '0');             -- internal message register
63
    signal r13 : unsigned (31 downto 0) := (others => '0');             -- internal message register
64
    signal r14 : unsigned (31 downto 0) := (others => '0');             -- internal message register
65
    signal r15 : unsigned (31 downto 0) := (others => '0');             -- internal message register
66
    -- input mux feedback
67
    signal next_M : unsigned (31 downto 0);                             -- sum feedback
68
    -- word shifter wires
69
    signal next_r0 : unsigned (31 downto 0);
70
    signal next_r1 : unsigned (31 downto 0);
71
    signal next_r2 : unsigned (31 downto 0);
72
    signal next_r3 : unsigned (31 downto 0);
73
    signal next_r4 : unsigned (31 downto 0);
74
    signal next_r5 : unsigned (31 downto 0);
75
    signal next_r6 : unsigned (31 downto 0);
76
    signal next_r7 : unsigned (31 downto 0);
77
    signal next_r8 : unsigned (31 downto 0);
78
    signal next_r9 : unsigned (31 downto 0);
79
    signal next_r10 : unsigned (31 downto 0);
80
    signal next_r11 : unsigned (31 downto 0);
81
    signal next_r12 : unsigned (31 downto 0);
82
    signal next_r13 : unsigned (31 downto 0);
83
    signal next_r14 : unsigned (31 downto 0);
84
    signal next_r15 : unsigned (31 downto 0);
85
    -- internal modulo adders
86
    signal sum0 : unsigned (31 downto 0);               -- modulo adder r1 + sum1
87
    signal sum1 : unsigned (31 downto 0);               -- modulo adder s0 + sum2
88
    signal sum2 : unsigned (31 downto 0);               -- modulo adder s1 + r10
89
    -- lower sigma functions
90
    signal s0 : unsigned (31 downto 0);                 -- lower sigma0 function
91
    signal s1 : unsigned (31 downto 0);                 -- lower sigma1 function
92
begin
93
    --=============================================================================================
94
    -- MESSAGE SCHEDULER LOGIC
95
    --=============================================================================================
96
    -- This logic implements the 256 bytes message schedule as a folded 16 word circular word shifter.
97
    -- The Add-Rotate-Xor functions s0 and s1 are implemented and fed back to the word shifter.
98
    -- To avoid a datapath pipeline delay insertion, the output is taken from the r0 input, rather than
99
    -- the registered r0 output. This lookahead reduces one clock cycle in the overall hash computation,
100
    -- but increases the combinational path from the input to the processor core.
101
    -- The next_r0 combinational function has 5 layers of logic, including 3 carry chains.
102
 
103
    -- word shifter register transfer logic
104
    word_shifter_proc: process (clk_i, ce_i) is
105
    begin
106
        if clk_i'event and clk_i = '1' then
107
            if ce_i = '1' then
108
                r0 <= next_r0;
109
                r1 <= next_r1;
110
                r2 <= next_r2;
111
                r3 <= next_r3;
112
                r4 <= next_r4;
113
                r5 <= next_r5;
114
                r6 <= next_r6;
115
                r7 <= next_r7;
116
                r8 <= next_r8;
117
                r9 <= next_r9;
118
                r10 <= next_r10;
119
                r11 <= next_r11;
120
                r12 <= next_r12;
121
                r13 <= next_r13;
122
                r14 <= next_r14;
123
                r15 <= next_r15;
124
            end if;
125
        end if;
126
    end process word_shifter_proc;
127
 
128
    -- input mux 
129
    next_r0_proc: next_r0 <= unsigned(M_i) when ld_i = '1' else next_M;
130
    next_m_proc:  next_M <= sum0;
131
 
132
    -- word shifter wires
133
    next_r15_proc: next_r15 <= r0;
134
    next_r14_proc: next_r14 <= r15;
135
    next_r13_proc: next_r13 <= r14;
136
    next_r12_proc: next_r12 <= r13;
137
    next_r11_proc: next_r11 <= r12;
138
    next_r10_proc: next_r10 <= r11;
139
    next_r9_proc: next_r9 <= r10;
140
    next_r8_proc: next_r8 <= r9;
141
    next_r7_proc: next_r7 <= r8;
142
    next_r6_proc: next_r6 <= r7;
143
    next_r5_proc: next_r5 <= r6;
144
    next_r4_proc: next_r4 <= r5;
145
    next_r3_proc: next_r3 <= r4;
146
    next_r2_proc: next_r2 <= r3;
147
    next_r1_proc: next_r1 <= r2;
148
 
149
    -- adders 
150
    sum0_proc: sum0 <= sum1 + r1;
151
    sum1_proc: sum1 <= sum2 + s0;
152
    sum2_proc: sum2 <= r10 + s1;
153
 
154
    -- lower sigma functions
155
    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));
156
    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));
157
 
158
    --=============================================================================================
159
    -- OUTPUT LOGIC
160
    --=============================================================================================
161
    -- connect output ports
162
    Wt_o_proc:      Wt_o <= std_logic_vector(next_r0);  -- message scheduler output look ahead
163
end rtl;
164
 

powered by: WebSVN 2.1.0

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