1 // Copyright 2009 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.
6 // In its own file so that a faster assembly or C version
7 // can be substituted easily.
11 // table[i] = int((1<<32) * abs(sin(i+1 radians))).
86 var shift1 = []uint{7, 12, 17, 22}
87 var shift2 = []uint{5, 9, 14, 20}
88 var shift3 = []uint{4, 11, 16, 23}
89 var shift4 = []uint{6, 10, 15, 21}
91 func _Block(dig *digest, p []byte) int {
98 for len(p) >= _Chunk {
99 aa, bb, cc, dd := a, b, c, d
102 for i := 0; i < 16; i++ {
103 X[i] = uint32(p[j]) | uint32(p[j+1])<<8 | uint32(p[j+2])<<16 | uint32(p[j+3])<<24
107 // If this needs to be made faster in the future,
108 // the usual trick is to unroll each of these
109 // loops by a factor of 4; that lets you replace
110 // the shift[] lookups with constants and,
111 // with suitable variable renaming in each
112 // unrolled body, delete the a, b, c, d = d, a, b, c
113 // (or you can let the optimizer do the renaming).
115 // The index variables are uint so that % by a power
116 // of two can be optimized easily by a compiler.
119 for i := uint(0); i < 16; i++ {
122 f := ((c ^ d) & b) ^ d
123 a += f + X[x] + table[i]
124 a = a<<s | a>>(32-s) + b
125 a, b, c, d = d, a, b, c
129 for i := uint(0); i < 16; i++ {
132 g := ((b ^ c) & d) ^ c
133 a += g + X[x] + table[i+16]
134 a = a<<s | a>>(32-s) + b
135 a, b, c, d = d, a, b, c
139 for i := uint(0); i < 16; i++ {
143 a += h + X[x] + table[i+32]
144 a = a<<s | a>>(32-s) + b
145 a, b, c, d = d, a, b, c
149 for i := uint(0); i < 16; i++ {
153 a += j + X[x] + table[i+48]
154 a = a<<s | a>>(32-s) + b
155 a, b, c, d = d, a, b, c