github.com/rohankumardubey/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/crypto/sha1/sha1block.go (about) 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. 4 5 // +build !amd64,!386 6 7 // SHA1 block step. 8 // In its own file so that a faster assembly or C version 9 // can be substituted easily. 10 11 package sha1 12 13 const ( 14 _K0 = 0x5A827999 15 _K1 = 0x6ED9EBA1 16 _K2 = 0x8F1BBCDC 17 _K3 = 0xCA62C1D6 18 ) 19 20 func block(dig *digest, p []byte) { 21 var w [16]uint32 22 23 h0, h1, h2, h3, h4 := dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4] 24 for len(p) >= chunk { 25 // Can interlace the computation of w with the 26 // rounds below if needed for speed. 27 for i := 0; i < 16; i++ { 28 j := i * 4 29 w[i] = uint32(p[j])<<24 | uint32(p[j+1])<<16 | uint32(p[j+2])<<8 | uint32(p[j+3]) 30 } 31 32 a, b, c, d, e := h0, h1, h2, h3, h4 33 34 // Each of the four 20-iteration rounds 35 // differs only in the computation of f and 36 // the choice of K (_K0, _K1, etc). 37 i := 0 38 for ; i < 16; i++ { 39 f := b&c | (^b)&d 40 a5 := a<<5 | a>>(32-5) 41 b30 := b<<30 | b>>(32-30) 42 t := a5 + f + e + w[i&0xf] + _K0 43 a, b, c, d, e = t, a, b30, c, d 44 } 45 for ; i < 20; i++ { 46 tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] 47 w[i&0xf] = tmp<<1 | tmp>>(32-1) 48 49 f := b&c | (^b)&d 50 a5 := a<<5 | a>>(32-5) 51 b30 := b<<30 | b>>(32-30) 52 t := a5 + f + e + w[i&0xf] + _K0 53 a, b, c, d, e = t, a, b30, c, d 54 } 55 for ; i < 40; i++ { 56 tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] 57 w[i&0xf] = tmp<<1 | tmp>>(32-1) 58 f := b ^ c ^ d 59 a5 := a<<5 | a>>(32-5) 60 b30 := b<<30 | b>>(32-30) 61 t := a5 + f + e + w[i&0xf] + _K1 62 a, b, c, d, e = t, a, b30, c, d 63 } 64 for ; i < 60; i++ { 65 tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] 66 w[i&0xf] = tmp<<1 | tmp>>(32-1) 67 f := ((b | c) & d) | (b & c) 68 69 a5 := a<<5 | a>>(32-5) 70 b30 := b<<30 | b>>(32-30) 71 t := a5 + f + e + w[i&0xf] + _K2 72 a, b, c, d, e = t, a, b30, c, d 73 } 74 for ; i < 80; i++ { 75 tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] 76 w[i&0xf] = tmp<<1 | tmp>>(32-1) 77 f := b ^ c ^ d 78 a5 := a<<5 | a>>(32-5) 79 b30 := b<<30 | b>>(32-30) 80 t := a5 + f + e + w[i&0xf] + _K3 81 a, b, c, d, e = t, a, b30, c, d 82 } 83 84 h0 += a 85 h1 += b 86 h2 += c 87 h3 += d 88 h4 += e 89 90 p = p[chunk:] 91 } 92 93 dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4] = h0, h1, h2, h3, h4 94 }