OLD | NEW |
1 package md5 | 1 package md5 |
2 | 2 |
3 import ( | 3 import ( |
4 "runtime" | 4 "runtime" |
5 "unsafe" | 5 "unsafe" |
6 ) | 6 ) |
7 | 7 |
8 func block(dig *digest, p []byte) { | 8 func block(dig *digest, p []byte) { |
9 a := dig.s[0] | 9 a := dig.s[0] |
10 b := dig.s[1] | 10 b := dig.s[1] |
11 c := dig.s[2] | 11 c := dig.s[2] |
12 d := dig.s[3] | 12 d := dig.s[3] |
13 var X *[16]uint32 | 13 var X *[16]uint32 |
14 var xbuf [16]uint32 | 14 var xbuf [16]uint32 |
15 for len(p) >= chunk { | 15 for len(p) >= chunk { |
16 aa, bb, cc, dd := a, b, c, d | 16 aa, bb, cc, dd := a, b, c, d |
17 | 17 |
18 // This is a constant condition - it is not evaluated on each it
eration. | 18 // This is a constant condition - it is not evaluated on each it
eration. |
19 if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" { | 19 if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" { |
20 // MD5 was designed so that x86 processors can just iter
ate | 20 // MD5 was designed so that x86 processors can just iter
ate |
21 // over the block data directly as uint32s, and we gener
ate | 21 // over the block data directly as uint32s, and we gener
ate |
22 // less code and run 1.3x faster if we take advantage of
that. | 22 // less code and run 1.3x faster if we take advantage of
that. |
23 // My apologies. | 23 // My apologies. |
24 X = (*[16]uint32)(unsafe.Pointer(&p[0])) | 24 X = (*[16]uint32)(unsafe.Pointer(&p[0])) |
| 25 } else if uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32(
0))-1) == 0 { |
| 26 X = (*[16]uint32)(unsafe.Pointer(&p[0])) |
25 } else { | 27 } else { |
26 X = &xbuf | 28 X = &xbuf |
27 j := 0 | 29 j := 0 |
28 for i := 0; i < 16; i++ { | 30 for i := 0; i < 16; i++ { |
29 X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uin
t32(p[j+2])<<16 | uint32(p[j+3])<<24 | 31 X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uin
t32(p[j+2])<<16 | uint32(p[j+3])<<24 |
30 j += 4 | 32 j += 4 |
31 } | 33 } |
32 } | 34 } |
33 | 35 |
34 // Round 1. | 36 // Round 1. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 d += dd | 239 d += dd |
238 | 240 |
239 p = p[chunk:] | 241 p = p[chunk:] |
240 } | 242 } |
241 | 243 |
242 dig.s[0] = a | 244 dig.s[0] = a |
243 dig.s[1] = b | 245 dig.s[1] = b |
244 dig.s[2] = c | 246 dig.s[2] = c |
245 dig.s[3] = d | 247 dig.s[3] = d |
246 } | 248 } |
OLD | NEW |