|
1 | | -//go:build ignore |
2 | | -// +build ignore |
3 | | - |
4 | 1 | package main |
5 | 2 |
|
6 | 3 | import ( |
7 | 4 | . "github.com/mmcloughlin/avo/build" |
8 | 5 | "github.com/mmcloughlin/avo/buildtags" |
9 | 6 | . "github.com/mmcloughlin/avo/operand" |
10 | 7 | . "github.com/mmcloughlin/avo/reg" |
11 | | - shared "github.com/pjbgf/sha1cd/internal" |
12 | 8 | ) |
13 | 9 |
|
14 | | -//go:generate go run sha1cdblock_amd64_asm.go -out sha1cdblock_amd64.s |
| 10 | +const ( |
| 11 | + // Constants for the SHA-1 hash function. |
| 12 | + RoundConst0 = 0x5A827999 |
| 13 | + RoundConst1 = 0x6ED9EBA1 |
| 14 | + RoundConst2 = 0x8F1BBCDC |
| 15 | + RoundConst3 = 0xCA62C1D6 |
| 16 | + |
| 17 | + // SHA1 processes the input data in chunks. Each chunk contains 64 bytes. |
| 18 | + Chunk = 64 |
| 19 | +) |
15 | 20 |
|
16 | 21 | func main() { |
17 | 22 | Constraint(buildtags.Not("noasm").ToConstraint()) |
@@ -61,7 +66,7 @@ func main() { |
61 | 66 | } |
62 | 67 |
|
63 | 68 | // Store message values on the stack. |
64 | | - w := AllocLocal(shared.Chunk) |
| 69 | + w := AllocLocal(Chunk) |
65 | 70 | W := func(r int) Mem { return w.Offset((r % 16) * 4) } |
66 | 71 |
|
67 | 72 | Comment("len(p) >= chunk") |
@@ -161,39 +166,39 @@ func main() { |
161 | 166 | Commentf("ROUND1(%d)", index) |
162 | 167 | LOAD(index) |
163 | 168 | FUNC1(a, b, c, d, e) |
164 | | - MIX(a, b, c, d, e, shared.K0) |
| 169 | + MIX(a, b, c, d, e, RoundConst0) |
165 | 170 | LOADM1(index) |
166 | 171 | } |
167 | 172 |
|
168 | 173 | ROUND1x := func(a, b, c, d, e GPVirtual, index int) { |
169 | 174 | Commentf("ROUND1x(%d)", index) |
170 | 175 | SHUFFLE(index) |
171 | 176 | FUNC1(a, b, c, d, e) |
172 | | - MIX(a, b, c, d, e, shared.K0) |
| 177 | + MIX(a, b, c, d, e, RoundConst0) |
173 | 178 | LOADM1(index) |
174 | 179 | } |
175 | 180 |
|
176 | 181 | ROUND2 := func(a, b, c, d, e GPVirtual, index int) { |
177 | 182 | Commentf("ROUND2(%d)", index) |
178 | 183 | SHUFFLE(index) |
179 | 184 | FUNC2(a, b, c, d, e) |
180 | | - MIX(a, b, c, d, e, shared.K1) |
| 185 | + MIX(a, b, c, d, e, RoundConst1) |
181 | 186 | LOADM1(index) |
182 | 187 | } |
183 | 188 |
|
184 | 189 | ROUND3 := func(a, b, c, d, e GPVirtual, index int) { |
185 | 190 | Commentf("ROUND3(%d)", index) |
186 | 191 | SHUFFLE(index) |
187 | 192 | FUNC3(a, b, c, d, e) |
188 | | - MIX(a, b, c, d, e, shared.K2) |
| 193 | + MIX(a, b, c, d, e, RoundConst2) |
189 | 194 | LOADM1(index) |
190 | 195 | } |
191 | 196 |
|
192 | 197 | ROUND4 := func(a, b, c, d, e GPVirtual, index int) { |
193 | 198 | Commentf("ROUND4(%d)", index) |
194 | 199 | SHUFFLE(index) |
195 | 200 | FUNC4(a, b, c, d, e) |
196 | | - MIX(a, b, c, d, e, shared.K3) |
| 201 | + MIX(a, b, c, d, e, RoundConst3) |
197 | 202 | LOADM1(index) |
198 | 203 | } |
199 | 204 |
|
@@ -297,7 +302,7 @@ func main() { |
297 | 302 | ADDL(r, hash[i]) |
298 | 303 | } |
299 | 304 |
|
300 | | - ADDQ(I8(shared.Chunk), p_base) |
| 305 | + ADDQ(I8(Chunk), p_base) |
301 | 306 | CMPQ(p_base, di64) |
302 | 307 | JB(LabelRef("loop")) |
303 | 308 |
|
|
0 commit comments