1 |
2 |
entactogen |
|
2 |
|
|
-- Copyright (c) 2013 Antonio de la Piedra
|
3 |
|
|
|
4 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
5 |
|
|
-- it under the terms of the GNU General Public License as published by
|
6 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
7 |
|
|
-- (at your option) any later version.
|
8 |
|
|
|
9 |
|
|
-- This program is distributed in the hope that it will be useful,
|
10 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
-- GNU General Public License for more details.
|
13 |
|
|
|
14 |
|
|
-- You should have received a copy of the GNU General Public License
|
15 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 |
|
|
|
17 |
|
|
library IEEE;
|
18 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
19 |
|
|
|
20 |
|
|
package sha_fun is
|
21 |
|
|
|
22 |
|
|
function sigma_0 (signal x : in std_logic_vector) return std_logic_vector;
|
23 |
|
|
function sigma_1 (signal x : in std_logic_vector) return std_logic_vector;
|
24 |
|
|
|
25 |
|
|
function sum_0 (signal x : in std_logic_vector) return std_logic_vector;
|
26 |
|
|
function sum_1 (signal x : in std_logic_vector) return std_logic_vector;
|
27 |
|
|
|
28 |
|
|
function chi (signal x : in std_logic_vector;
|
29 |
|
|
signal y : in std_logic_vector;
|
30 |
|
|
signal z : in std_logic_vector) return std_logic_vector;
|
31 |
|
|
|
32 |
|
|
function maj (signal x : in std_logic_vector;
|
33 |
|
|
signal y : in std_logic_vector;
|
34 |
|
|
signal z : in std_logic_vector) return std_logic_vector;
|
35 |
|
|
end sha_fun;
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
package body sha_fun is
|
39 |
|
|
|
40 |
|
|
function sigma_0 (signal x : in std_logic_vector) return std_logic_vector is
|
41 |
|
|
variable tmp_0 : std_logic_vector(31 downto 0);
|
42 |
|
|
variable tmp_1 : std_logic_vector(31 downto 0);
|
43 |
|
|
variable tmp_2 : std_logic_vector(31 downto 0);
|
44 |
|
|
|
45 |
|
|
variable r : std_logic_vector(31 downto 0);
|
46 |
|
|
begin
|
47 |
|
|
tmp_0 := x(6 downto 0) & x(31 downto 7);
|
48 |
|
|
tmp_1 := x(17 downto 0) & x(31 downto 18);
|
49 |
|
|
tmp_2 := "000" & x(31 downto 3);
|
50 |
|
|
|
51 |
|
|
r := tmp_0 xor tmp_1 xor tmp_2;
|
52 |
|
|
|
53 |
|
|
return r;
|
54 |
|
|
end sigma_0;
|
55 |
|
|
|
56 |
|
|
function sigma_1 (signal x : in std_logic_vector) return std_logic_vector is
|
57 |
|
|
variable tmp_0 : std_logic_vector(31 downto 0);
|
58 |
|
|
variable tmp_1 : std_logic_vector(31 downto 0);
|
59 |
|
|
variable tmp_2 : std_logic_vector(31 downto 0);
|
60 |
|
|
|
61 |
|
|
variable r : std_logic_vector(31 downto 0);
|
62 |
|
|
begin
|
63 |
|
|
tmp_0 := x(16 downto 0) & x(31 downto 17);
|
64 |
|
|
tmp_1 := x(18 downto 0) & x(31 downto 19);
|
65 |
|
|
tmp_2 := "0000000000" & x(31 downto 10);
|
66 |
|
|
|
67 |
|
|
r := tmp_0 xor tmp_1 xor tmp_2;
|
68 |
|
|
|
69 |
|
|
return r;
|
70 |
|
|
end sigma_1;
|
71 |
|
|
|
72 |
|
|
function chi (signal x : in std_logic_vector;
|
73 |
|
|
signal y : in std_logic_vector;
|
74 |
|
|
signal z : in std_logic_vector) return std_logic_vector is
|
75 |
|
|
|
76 |
|
|
variable r : std_logic_vector(31 downto 0);
|
77 |
|
|
|
78 |
|
|
begin
|
79 |
|
|
r := (x and y) xor (not(x) and z);
|
80 |
|
|
|
81 |
|
|
return r;
|
82 |
|
|
end chi;
|
83 |
|
|
|
84 |
|
|
function maj (signal x : in std_logic_vector;
|
85 |
|
|
signal y : in std_logic_vector;
|
86 |
|
|
signal z : in std_logic_vector) return std_logic_vector is
|
87 |
|
|
variable r : std_logic_vector(31 downto 0);
|
88 |
|
|
|
89 |
|
|
begin
|
90 |
|
|
r := (x and y) xor (x and z) xor (y and z);
|
91 |
|
|
|
92 |
|
|
return r;
|
93 |
|
|
|
94 |
|
|
end maj;
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
function sum_0 (signal x : in std_logic_vector) return std_logic_vector is
|
98 |
|
|
variable tmp_0 : std_logic_vector(31 downto 0);
|
99 |
|
|
variable tmp_1 : std_logic_vector(31 downto 0);
|
100 |
|
|
variable tmp_2 : std_logic_vector(31 downto 0);
|
101 |
|
|
|
102 |
|
|
variable r : std_logic_vector(31 downto 0);
|
103 |
|
|
begin
|
104 |
|
|
tmp_0 := x(1 downto 0) & x(31 downto 2);
|
105 |
|
|
tmp_1 := x(12 downto 0) & x(31 downto 13);
|
106 |
|
|
tmp_2 := x(21 downto 0) & x(31 downto 22);
|
107 |
|
|
|
108 |
|
|
r := tmp_0 xor tmp_1 xor tmp_2;
|
109 |
|
|
|
110 |
|
|
return r;
|
111 |
|
|
|
112 |
|
|
end sum_0;
|
113 |
|
|
|
114 |
|
|
function sum_1 (signal x : in std_logic_vector) return std_logic_vector is
|
115 |
|
|
variable tmp_0 : std_logic_vector(31 downto 0);
|
116 |
|
|
variable tmp_1 : std_logic_vector(31 downto 0);
|
117 |
|
|
variable tmp_2 : std_logic_vector(31 downto 0);
|
118 |
|
|
|
119 |
|
|
variable r : std_logic_vector(31 downto 0);
|
120 |
|
|
begin
|
121 |
|
|
|
122 |
|
|
tmp_0 := x(5 downto 0) & x(31 downto 6);
|
123 |
|
|
tmp_1 := x(10 downto 0) & x(31 downto 11);
|
124 |
|
|
tmp_2 := x(24 downto 0) & x(31 downto 25);
|
125 |
|
|
|
126 |
|
|
r := tmp_0 xor tmp_1 xor tmp_2;
|
127 |
|
|
|
128 |
|
|
return r;
|
129 |
|
|
end sum_1;
|
130 |
|
|
|
131 |
|
|
end sha_fun;
|