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

Subversion Repositories deflatecore

[/] [deflatecore/] [trunk/] [HashChain.vhd] - Blame information for rev 18

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 smallcode
--------------------------------------------------------------------------------
2
-- Create Date:    03:46:54 10/31/05
3
-- Design Name:    
4
-- Module Name:    Hash - Behavioral
5
-- Project Name:   Deflate
6
-- Revision:
7 9 smallcode
-- Revision 0.25 - Only one hash algorithm
8 2 smallcode
-- Additional Comments:
9 9 smallcode
-- The remarked comments for synchronous reser result in the use of more 192 slices witn a maximum frequency of 129 Mhz
10
--      But if the code is commented as it is now the number of slices utlised is 5 without a known clock , need to specifiy that as a compile time constraint.
11 4 smallcode
-- TO DO: 
12
-- Wishbone interface
13
-- Concurrent Hashkey generation
14 2 smallcode
--------------------------------------------------------------------------------
15
library IEEE;
16
use IEEE.STD_LOGIC_1164.ALL;
17
use IEEE.STD_LOGIC_ARITH.ALL;
18
use IEEE.STD_LOGIC_UNSIGNED.ALL;
19 13 smallcode
 
20 2 smallcode
entity HashChain is
21 4 smallcode
    Generic
22
              (                                                                                                                                                                   -- Data bus width currently set at 8
23
                         Data_Width : natural := 8;                                                                                               -- Width of the hash key generated now at 32 bits
24
                         Hash_Width : natural := 32
25
         );
26 13 smallcode
    Port ( Hash_O   : inout std_logic_vector (Hash_Width - 1 downto 0);   -- Hash value of previous data
27 4 smallcode
           Data_in  : in  std_logic_vector (Data_Width-1 downto 0);       -- Data input from byte stream
28
                          Clock,                                                                                                                            -- Clock
29 12 smallcode
                          Reset,
30 13 smallcode
                          Start,                                                                                                                            -- Reset
31 12 smallcode
                          O_E : in  bit ;                                                                            -- Output Enable
32
           Busy,
33
                          Done : out bit                                                                                                                   -- Enabled when the hash key has been generated
34 9 smallcode
                          );
35 2 smallcode
end HashChain;
36 7 smallcode
 
37 2 smallcode
--An algorithm produced by Professor Daniel J. Bernstein and 
38
--shown first to the world on the usenet newsgroup comp.lang.c. 
39
--It is one of the most efficient hash functions ever published
40
--Actual function hash(i) = hash(i - 1) * 33 + str[i];
41 6 smallcode
--Function now implemented using XOR hash(i) = hash(i - 1) * 33 ^ str[i];
42
architecture DJB2 of HashChain is
43 13 smallcode
signal mode: integer := 0;
44
signal tempval, hash:std_logic_vector (Hash_Width - 1 downto 0):= X"00000000" ;
45
signal multiplier:std_logic_vector (39 downto 0):= X"0000000000" ;
46 6 smallcode
begin
47
 
48 9 smallcode
 
49 13 smallcode
mealymachine: process (Clock)
50
begin
51
        if Reset = '1' and Clock = '1' then          -- Reset
52
                     mode <= 0;
53
        elsif start = '1' and Clock = '1' then    -- Start
54
                     mode <= 1;                                                                   -- Multiply previous key by 33          ( Clock = 1 )
55
                  elsif mode = 1 then
56
                     mode <= 2;                                                                   -- Ex-OR input with existing key ( Clock = 0 )
57
                  elsif mode = 2 then
58
                     mode <= 3;                                                                   -- Latch output                  ( Clock = 1 )
59
                  else
60
                     mode <= 4;
61
        end if;
62
end process mealymachine;
63 9 smallcode
 
64 13 smallcode
hash <= X"000016c7"  when mode = 0 else                     --initialise the hash key to 5831
65
                  multiplier(31 downto 0) xor tempval   when mode = 2 else          --Ex or with the current input
66
                  hash;                                                                                            --keep current value
67
 
68
multiplier <= hash * X"21" when mode = 1 else                 --Multiply by 33
69
                                  X"0000000000";
70
 
71
tempval <= X"00000000" when mode /= 1 else                 --Temporary value to be able to Exor the input with the hash key
72 12 smallcode
           tempval+ Data_in;
73 6 smallcode
 
74 13 smallcode
busy <= '1' when mode > 0 and mode < 3 else                 --Indicates that the key is being generated
75
        '0' ;
76 6 smallcode
 
77
 
78 13 smallcode
Hash_O <= hash when mode = 3 and O_E = '1' else   --Output buffer
79
          Hash_O;                                 --Hash op bufffer
80
 
81
 
82
done <= '1' when mode = 3 else                    --1 after hash key has been calculated 
83 12 smallcode
        '0';
84
 
85
 
86
end DJB2;
87
 
88 6 smallcode
Configuration djb2_hash of hashchain is
89
for djb2
90
end for;
91
end djb2_hash;

powered by: WebSVN 2.1.0

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