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