libgo: Merge to master revision 19184.
[official-gcc.git] / libgo / go / crypto / md5 / md5block.go
blobe2a17677757e55ac0b07d2477513fb38734524ba
1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // DO NOT EDIT.
6 // Generate with: go run gen.go -full | gofmt >md5block.go
8 package md5
10 import (
11 "runtime"
12 "unsafe"
15 const x86 = runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
17 var littleEndian bool
19 func init() {
20 x := uint32(0x04030201)
21 y := [4]byte{0x1, 0x2, 0x3, 0x4}
22 littleEndian = *(*[4]byte)(unsafe.Pointer(&x)) == y
25 func blockGeneric(dig *digest, p []byte) {
26 a := dig.s[0]
27 b := dig.s[1]
28 c := dig.s[2]
29 d := dig.s[3]
30 var X *[16]uint32
31 var xbuf [16]uint32
32 for len(p) >= chunk {
33 aa, bb, cc, dd := a, b, c, d
35 // This is a constant condition - it is not evaluated on each iteration.
36 if x86 {
37 // MD5 was designed so that x86 processors can just iterate
38 // over the block data directly as uint32s, and we generate
39 // less code and run 1.3x faster if we take advantage of that.
40 // My apologies.
41 X = (*[16]uint32)(unsafe.Pointer(&p[0]))
42 } else if littleEndian && uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32(0))-1) == 0 {
43 X = (*[16]uint32)(unsafe.Pointer(&p[0]))
44 } else {
45 X = &xbuf
46 j := 0
47 for i := 0; i < 16; i++ {
48 X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uint32(p[j+2])<<16 | uint32(p[j+3])<<24
49 j += 4
53 // Round 1.
55 a += (((c ^ d) & b) ^ d) + X[0] + 3614090360
56 a = a<<7 | a>>(32-7) + b
58 d += (((b ^ c) & a) ^ c) + X[1] + 3905402710
59 d = d<<12 | d>>(32-12) + a
61 c += (((a ^ b) & d) ^ b) + X[2] + 606105819
62 c = c<<17 | c>>(32-17) + d
64 b += (((d ^ a) & c) ^ a) + X[3] + 3250441966
65 b = b<<22 | b>>(32-22) + c
67 a += (((c ^ d) & b) ^ d) + X[4] + 4118548399
68 a = a<<7 | a>>(32-7) + b
70 d += (((b ^ c) & a) ^ c) + X[5] + 1200080426
71 d = d<<12 | d>>(32-12) + a
73 c += (((a ^ b) & d) ^ b) + X[6] + 2821735955
74 c = c<<17 | c>>(32-17) + d
76 b += (((d ^ a) & c) ^ a) + X[7] + 4249261313
77 b = b<<22 | b>>(32-22) + c
79 a += (((c ^ d) & b) ^ d) + X[8] + 1770035416
80 a = a<<7 | a>>(32-7) + b
82 d += (((b ^ c) & a) ^ c) + X[9] + 2336552879
83 d = d<<12 | d>>(32-12) + a
85 c += (((a ^ b) & d) ^ b) + X[10] + 4294925233
86 c = c<<17 | c>>(32-17) + d
88 b += (((d ^ a) & c) ^ a) + X[11] + 2304563134
89 b = b<<22 | b>>(32-22) + c
91 a += (((c ^ d) & b) ^ d) + X[12] + 1804603682
92 a = a<<7 | a>>(32-7) + b
94 d += (((b ^ c) & a) ^ c) + X[13] + 4254626195
95 d = d<<12 | d>>(32-12) + a
97 c += (((a ^ b) & d) ^ b) + X[14] + 2792965006
98 c = c<<17 | c>>(32-17) + d
100 b += (((d ^ a) & c) ^ a) + X[15] + 1236535329
101 b = b<<22 | b>>(32-22) + c
103 // Round 2.
105 a += (((b ^ c) & d) ^ c) + X[(1+5*0)&15] + 4129170786
106 a = a<<5 | a>>(32-5) + b
108 d += (((a ^ b) & c) ^ b) + X[(1+5*1)&15] + 3225465664
109 d = d<<9 | d>>(32-9) + a
111 c += (((d ^ a) & b) ^ a) + X[(1+5*2)&15] + 643717713
112 c = c<<14 | c>>(32-14) + d
114 b += (((c ^ d) & a) ^ d) + X[(1+5*3)&15] + 3921069994
115 b = b<<20 | b>>(32-20) + c
117 a += (((b ^ c) & d) ^ c) + X[(1+5*4)&15] + 3593408605
118 a = a<<5 | a>>(32-5) + b
120 d += (((a ^ b) & c) ^ b) + X[(1+5*5)&15] + 38016083
121 d = d<<9 | d>>(32-9) + a
123 c += (((d ^ a) & b) ^ a) + X[(1+5*6)&15] + 3634488961
124 c = c<<14 | c>>(32-14) + d
126 b += (((c ^ d) & a) ^ d) + X[(1+5*7)&15] + 3889429448
127 b = b<<20 | b>>(32-20) + c
129 a += (((b ^ c) & d) ^ c) + X[(1+5*8)&15] + 568446438
130 a = a<<5 | a>>(32-5) + b
132 d += (((a ^ b) & c) ^ b) + X[(1+5*9)&15] + 3275163606
133 d = d<<9 | d>>(32-9) + a
135 c += (((d ^ a) & b) ^ a) + X[(1+5*10)&15] + 4107603335
136 c = c<<14 | c>>(32-14) + d
138 b += (((c ^ d) & a) ^ d) + X[(1+5*11)&15] + 1163531501
139 b = b<<20 | b>>(32-20) + c
141 a += (((b ^ c) & d) ^ c) + X[(1+5*12)&15] + 2850285829
142 a = a<<5 | a>>(32-5) + b
144 d += (((a ^ b) & c) ^ b) + X[(1+5*13)&15] + 4243563512
145 d = d<<9 | d>>(32-9) + a
147 c += (((d ^ a) & b) ^ a) + X[(1+5*14)&15] + 1735328473
148 c = c<<14 | c>>(32-14) + d
150 b += (((c ^ d) & a) ^ d) + X[(1+5*15)&15] + 2368359562
151 b = b<<20 | b>>(32-20) + c
153 // Round 3.
155 a += (b ^ c ^ d) + X[(5+3*0)&15] + 4294588738
156 a = a<<4 | a>>(32-4) + b
158 d += (a ^ b ^ c) + X[(5+3*1)&15] + 2272392833
159 d = d<<11 | d>>(32-11) + a
161 c += (d ^ a ^ b) + X[(5+3*2)&15] + 1839030562
162 c = c<<16 | c>>(32-16) + d
164 b += (c ^ d ^ a) + X[(5+3*3)&15] + 4259657740
165 b = b<<23 | b>>(32-23) + c
167 a += (b ^ c ^ d) + X[(5+3*4)&15] + 2763975236
168 a = a<<4 | a>>(32-4) + b
170 d += (a ^ b ^ c) + X[(5+3*5)&15] + 1272893353
171 d = d<<11 | d>>(32-11) + a
173 c += (d ^ a ^ b) + X[(5+3*6)&15] + 4139469664
174 c = c<<16 | c>>(32-16) + d
176 b += (c ^ d ^ a) + X[(5+3*7)&15] + 3200236656
177 b = b<<23 | b>>(32-23) + c
179 a += (b ^ c ^ d) + X[(5+3*8)&15] + 681279174
180 a = a<<4 | a>>(32-4) + b
182 d += (a ^ b ^ c) + X[(5+3*9)&15] + 3936430074
183 d = d<<11 | d>>(32-11) + a
185 c += (d ^ a ^ b) + X[(5+3*10)&15] + 3572445317
186 c = c<<16 | c>>(32-16) + d
188 b += (c ^ d ^ a) + X[(5+3*11)&15] + 76029189
189 b = b<<23 | b>>(32-23) + c
191 a += (b ^ c ^ d) + X[(5+3*12)&15] + 3654602809
192 a = a<<4 | a>>(32-4) + b
194 d += (a ^ b ^ c) + X[(5+3*13)&15] + 3873151461
195 d = d<<11 | d>>(32-11) + a
197 c += (d ^ a ^ b) + X[(5+3*14)&15] + 530742520
198 c = c<<16 | c>>(32-16) + d
200 b += (c ^ d ^ a) + X[(5+3*15)&15] + 3299628645
201 b = b<<23 | b>>(32-23) + c
203 // Round 4.
205 a += (c ^ (b | ^d)) + X[(7*0)&15] + 4096336452
206 a = a<<6 | a>>(32-6) + b
208 d += (b ^ (a | ^c)) + X[(7*1)&15] + 1126891415
209 d = d<<10 | d>>(32-10) + a
211 c += (a ^ (d | ^b)) + X[(7*2)&15] + 2878612391
212 c = c<<15 | c>>(32-15) + d
214 b += (d ^ (c | ^a)) + X[(7*3)&15] + 4237533241
215 b = b<<21 | b>>(32-21) + c
217 a += (c ^ (b | ^d)) + X[(7*4)&15] + 1700485571
218 a = a<<6 | a>>(32-6) + b
220 d += (b ^ (a | ^c)) + X[(7*5)&15] + 2399980690
221 d = d<<10 | d>>(32-10) + a
223 c += (a ^ (d | ^b)) + X[(7*6)&15] + 4293915773
224 c = c<<15 | c>>(32-15) + d
226 b += (d ^ (c | ^a)) + X[(7*7)&15] + 2240044497
227 b = b<<21 | b>>(32-21) + c
229 a += (c ^ (b | ^d)) + X[(7*8)&15] + 1873313359
230 a = a<<6 | a>>(32-6) + b
232 d += (b ^ (a | ^c)) + X[(7*9)&15] + 4264355552
233 d = d<<10 | d>>(32-10) + a
235 c += (a ^ (d | ^b)) + X[(7*10)&15] + 2734768916
236 c = c<<15 | c>>(32-15) + d
238 b += (d ^ (c | ^a)) + X[(7*11)&15] + 1309151649
239 b = b<<21 | b>>(32-21) + c
241 a += (c ^ (b | ^d)) + X[(7*12)&15] + 4149444226
242 a = a<<6 | a>>(32-6) + b
244 d += (b ^ (a | ^c)) + X[(7*13)&15] + 3174756917
245 d = d<<10 | d>>(32-10) + a
247 c += (a ^ (d | ^b)) + X[(7*14)&15] + 718787259
248 c = c<<15 | c>>(32-15) + d
250 b += (d ^ (c | ^a)) + X[(7*15)&15] + 3951481745
251 b = b<<21 | b>>(32-21) + c
253 a += aa
254 b += bb
255 c += cc
256 d += dd
258 p = p[chunk:]
261 dig.s[0] = a
262 dig.s[1] = b
263 dig.s[2] = c
264 dig.s[3] = d