1// DO NOT EDIT.
2// Generate with: go run gen.go -full | gofmt >md5block.go
3
4// +build !amd64,!386,!arm
5
6package md5
7
8import (
9	"runtime"
10	"unsafe"
11)
12
13const x86 = runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
14
15var littleEndian bool
16
17func init() {
18	x := uint32(0x04030201)
19	y := [4]byte{0x1, 0x2, 0x3, 0x4}
20	littleEndian = *(*[4]byte)(unsafe.Pointer(&x)) == y
21}
22
23func block(dig *digest, p []byte) {
24	a := dig.s[0]
25	b := dig.s[1]
26	c := dig.s[2]
27	d := dig.s[3]
28	var X *[16]uint32
29	var xbuf [16]uint32
30	for len(p) >= chunk {
31		aa, bb, cc, dd := a, b, c, d
32
33		// This is a constant condition - it is not evaluated on each iteration.
34		if x86 {
35			// MD5 was designed so that x86 processors can just iterate
36			// over the block data directly as uint32s, and we generate
37			// less code and run 1.3x faster if we take advantage of that.
38			// My apologies.
39			X = (*[16]uint32)(unsafe.Pointer(&p[0]))
40		} else if littleEndian && uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32(0))-1) == 0 {
41			X = (*[16]uint32)(unsafe.Pointer(&p[0]))
42		} else {
43			X = &xbuf
44			j := 0
45			for i := 0; i < 16; i++ {
46				X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uint32(p[j+2])<<16 | uint32(p[j+3])<<24
47				j += 4
48			}
49		}
50
51		// Round 1.
52
53		a += (((c ^ d) & b) ^ d) + X[0] + 3614090360
54		a = a<<7 | a>>(32-7) + b
55
56		d += (((b ^ c) & a) ^ c) + X[1] + 3905402710
57		d = d<<12 | d>>(32-12) + a
58
59		c += (((a ^ b) & d) ^ b) + X[2] + 606105819
60		c = c<<17 | c>>(32-17) + d
61
62		b += (((d ^ a) & c) ^ a) + X[3] + 3250441966
63		b = b<<22 | b>>(32-22) + c
64
65		a += (((c ^ d) & b) ^ d) + X[4] + 4118548399
66		a = a<<7 | a>>(32-7) + b
67
68		d += (((b ^ c) & a) ^ c) + X[5] + 1200080426
69		d = d<<12 | d>>(32-12) + a
70
71		c += (((a ^ b) & d) ^ b) + X[6] + 2821735955
72		c = c<<17 | c>>(32-17) + d
73
74		b += (((d ^ a) & c) ^ a) + X[7] + 4249261313
75		b = b<<22 | b>>(32-22) + c
76
77		a += (((c ^ d) & b) ^ d) + X[8] + 1770035416
78		a = a<<7 | a>>(32-7) + b
79
80		d += (((b ^ c) & a) ^ c) + X[9] + 2336552879
81		d = d<<12 | d>>(32-12) + a
82
83		c += (((a ^ b) & d) ^ b) + X[10] + 4294925233
84		c = c<<17 | c>>(32-17) + d
85
86		b += (((d ^ a) & c) ^ a) + X[11] + 2304563134
87		b = b<<22 | b>>(32-22) + c
88
89		a += (((c ^ d) & b) ^ d) + X[12] + 1804603682
90		a = a<<7 | a>>(32-7) + b
91
92		d += (((b ^ c) & a) ^ c) + X[13] + 4254626195
93		d = d<<12 | d>>(32-12) + a
94
95		c += (((a ^ b) & d) ^ b) + X[14] + 2792965006
96		c = c<<17 | c>>(32-17) + d
97
98		b += (((d ^ a) & c) ^ a) + X[15] + 1236535329
99		b = b<<22 | b>>(32-22) + c
100
101		// Round 2.
102
103		a += (((b ^ c) & d) ^ c) + X[(1+5*0)&15] + 4129170786
104		a = a<<5 | a>>(32-5) + b
105
106		d += (((a ^ b) & c) ^ b) + X[(1+5*1)&15] + 3225465664
107		d = d<<9 | d>>(32-9) + a
108
109		c += (((d ^ a) & b) ^ a) + X[(1+5*2)&15] + 643717713
110		c = c<<14 | c>>(32-14) + d
111
112		b += (((c ^ d) & a) ^ d) + X[(1+5*3)&15] + 3921069994
113		b = b<<20 | b>>(32-20) + c
114
115		a += (((b ^ c) & d) ^ c) + X[(1+5*4)&15] + 3593408605
116		a = a<<5 | a>>(32-5) + b
117
118		d += (((a ^ b) & c) ^ b) + X[(1+5*5)&15] + 38016083
119		d = d<<9 | d>>(32-9) + a
120
121		c += (((d ^ a) & b) ^ a) + X[(1+5*6)&15] + 3634488961
122		c = c<<14 | c>>(32-14) + d
123
124		b += (((c ^ d) & a) ^ d) + X[(1+5*7)&15] + 3889429448
125		b = b<<20 | b>>(32-20) + c
126
127		a += (((b ^ c) & d) ^ c) + X[(1+5*8)&15] + 568446438
128		a = a<<5 | a>>(32-5) + b
129
130		d += (((a ^ b) & c) ^ b) + X[(1+5*9)&15] + 3275163606
131		d = d<<9 | d>>(32-9) + a
132
133		c += (((d ^ a) & b) ^ a) + X[(1+5*10)&15] + 4107603335
134		c = c<<14 | c>>(32-14) + d
135
136		b += (((c ^ d) & a) ^ d) + X[(1+5*11)&15] + 1163531501
137		b = b<<20 | b>>(32-20) + c
138
139		a += (((b ^ c) & d) ^ c) + X[(1+5*12)&15] + 2850285829
140		a = a<<5 | a>>(32-5) + b
141
142		d += (((a ^ b) & c) ^ b) + X[(1+5*13)&15] + 4243563512
143		d = d<<9 | d>>(32-9) + a
144
145		c += (((d ^ a) & b) ^ a) + X[(1+5*14)&15] + 1735328473
146		c = c<<14 | c>>(32-14) + d
147
148		b += (((c ^ d) & a) ^ d) + X[(1+5*15)&15] + 2368359562
149		b = b<<20 | b>>(32-20) + c
150
151		// Round 3.
152
153		a += (b ^ c ^ d) + X[(5+3*0)&15] + 4294588738
154		a = a<<4 | a>>(32-4) + b
155
156		d += (a ^ b ^ c) + X[(5+3*1)&15] + 2272392833
157		d = d<<11 | d>>(32-11) + a
158
159		c += (d ^ a ^ b) + X[(5+3*2)&15] + 1839030562
160		c = c<<16 | c>>(32-16) + d
161
162		b += (c ^ d ^ a) + X[(5+3*3)&15] + 4259657740
163		b = b<<23 | b>>(32-23) + c
164
165		a += (b ^ c ^ d) + X[(5+3*4)&15] + 2763975236
166		a = a<<4 | a>>(32-4) + b
167
168		d += (a ^ b ^ c) + X[(5+3*5)&15] + 1272893353
169		d = d<<11 | d>>(32-11) + a
170
171		c += (d ^ a ^ b) + X[(5+3*6)&15] + 4139469664
172		c = c<<16 | c>>(32-16) + d
173
174		b += (c ^ d ^ a) + X[(5+3*7)&15] + 3200236656
175		b = b<<23 | b>>(32-23) + c
176
177		a += (b ^ c ^ d) + X[(5+3*8)&15] + 681279174
178		a = a<<4 | a>>(32-4) + b
179
180		d += (a ^ b ^ c) + X[(5+3*9)&15] + 3936430074
181		d = d<<11 | d>>(32-11) + a
182
183		c += (d ^ a ^ b) + X[(5+3*10)&15] + 3572445317
184		c = c<<16 | c>>(32-16) + d
185
186		b += (c ^ d ^ a) + X[(5+3*11)&15] + 76029189
187		b = b<<23 | b>>(32-23) + c
188
189		a += (b ^ c ^ d) + X[(5+3*12)&15] + 3654602809
190		a = a<<4 | a>>(32-4) + b
191
192		d += (a ^ b ^ c) + X[(5+3*13)&15] + 3873151461
193		d = d<<11 | d>>(32-11) + a
194
195		c += (d ^ a ^ b) + X[(5+3*14)&15] + 530742520
196		c = c<<16 | c>>(32-16) + d
197
198		b += (c ^ d ^ a) + X[(5+3*15)&15] + 3299628645
199		b = b<<23 | b>>(32-23) + c
200
201		// Round 4.
202
203		a += (c ^ (b | ^d)) + X[(7*0)&15] + 4096336452
204		a = a<<6 | a>>(32-6) + b
205
206		d += (b ^ (a | ^c)) + X[(7*1)&15] + 1126891415
207		d = d<<10 | d>>(32-10) + a
208
209		c += (a ^ (d | ^b)) + X[(7*2)&15] + 2878612391
210		c = c<<15 | c>>(32-15) + d
211
212		b += (d ^ (c | ^a)) + X[(7*3)&15] + 4237533241
213		b = b<<21 | b>>(32-21) + c
214
215		a += (c ^ (b | ^d)) + X[(7*4)&15] + 1700485571
216		a = a<<6 | a>>(32-6) + b
217
218		d += (b ^ (a | ^c)) + X[(7*5)&15] + 2399980690
219		d = d<<10 | d>>(32-10) + a
220
221		c += (a ^ (d | ^b)) + X[(7*6)&15] + 4293915773
222		c = c<<15 | c>>(32-15) + d
223
224		b += (d ^ (c | ^a)) + X[(7*7)&15] + 2240044497
225		b = b<<21 | b>>(32-21) + c
226
227		a += (c ^ (b | ^d)) + X[(7*8)&15] + 1873313359
228		a = a<<6 | a>>(32-6) + b
229
230		d += (b ^ (a | ^c)) + X[(7*9)&15] + 4264355552
231		d = d<<10 | d>>(32-10) + a
232
233		c += (a ^ (d | ^b)) + X[(7*10)&15] + 2734768916
234		c = c<<15 | c>>(32-15) + d
235
236		b += (d ^ (c | ^a)) + X[(7*11)&15] + 1309151649
237		b = b<<21 | b>>(32-21) + c
238
239		a += (c ^ (b | ^d)) + X[(7*12)&15] + 4149444226
240		a = a<<6 | a>>(32-6) + b
241
242		d += (b ^ (a | ^c)) + X[(7*13)&15] + 3174756917
243		d = d<<10 | d>>(32-10) + a
244
245		c += (a ^ (d | ^b)) + X[(7*14)&15] + 718787259
246		c = c<<15 | c>>(32-15) + d
247
248		b += (d ^ (c | ^a)) + X[(7*15)&15] + 3951481745
249		b = b<<21 | b>>(32-21) + c
250
251		a += aa
252		b += bb
253		c += cc
254		d += dd
255
256		p = p[chunk:]
257	}
258
259	dig.s[0] = a
260	dig.s[1] = b
261	dig.s[2] = c
262	dig.s[3] = d
263}
264