~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/pkg/crypto/sha1/sha1block.go

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
 
 
5
// +build !amd64,!386
 
6
 
5
7
// SHA1 block step.
6
8
// In its own file so that a faster assembly or C version
7
9
// can be substituted easily.
15
17
        _K3 = 0xCA62C1D6
16
18
)
17
19
 
18
 
func _Block(dig *digest, p []byte) int {
19
 
        var w [80]uint32
 
20
func block(dig *digest, p []byte) {
 
21
        var w [16]uint32
20
22
 
21
 
        n := 0
22
23
        h0, h1, h2, h3, h4 := dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4]
23
 
        for len(p) >= _Chunk {
 
24
        for len(p) >= chunk {
24
25
                // Can interlace the computation of w with the
25
26
                // rounds below if needed for speed.
26
27
                for i := 0; i < 16; i++ {
27
28
                        j := i * 4
28
29
                        w[i] = uint32(p[j])<<24 | uint32(p[j+1])<<16 | uint32(p[j+2])<<8 | uint32(p[j+3])
29
30
                }
30
 
                for i := 16; i < 80; i++ {
31
 
                        tmp := w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]
32
 
                        w[i] = tmp<<1 | tmp>>(32-1)
33
 
                }
34
31
 
35
32
                a, b, c, d, e := h0, h1, h2, h3, h4
36
33
 
37
34
                // Each of the four 20-iteration rounds
38
35
                // differs only in the computation of f and
39
36
                // the choice of K (_K0, _K1, etc).
40
 
                for i := 0; i < 20; i++ {
41
 
                        f := b&c | (^b)&d
42
 
                        a5 := a<<5 | a>>(32-5)
43
 
                        b30 := b<<30 | b>>(32-30)
44
 
                        t := a5 + f + e + w[i] + _K0
45
 
                        a, b, c, d, e = t, a, b30, c, d
46
 
                }
47
 
                for i := 20; i < 40; i++ {
48
 
                        f := b ^ c ^ d
49
 
                        a5 := a<<5 | a>>(32-5)
50
 
                        b30 := b<<30 | b>>(32-30)
51
 
                        t := a5 + f + e + w[i] + _K1
52
 
                        a, b, c, d, e = t, a, b30, c, d
53
 
                }
54
 
                for i := 40; i < 60; i++ {
55
 
                        f := b&c | b&d | c&d
56
 
                        a5 := a<<5 | a>>(32-5)
57
 
                        b30 := b<<30 | b>>(32-30)
58
 
                        t := a5 + f + e + w[i] + _K2
59
 
                        a, b, c, d, e = t, a, b30, c, d
60
 
                }
61
 
                for i := 60; i < 80; i++ {
62
 
                        f := b ^ c ^ d
63
 
                        a5 := a<<5 | a>>(32-5)
64
 
                        b30 := b<<30 | b>>(32-30)
65
 
                        t := a5 + f + e + w[i] + _K3
 
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
66
81
                        a, b, c, d, e = t, a, b30, c, d
67
82
                }
68
83
 
72
87
                h3 += d
73
88
                h4 += e
74
89
 
75
 
                p = p[_Chunk:]
76
 
                n += _Chunk
 
90
                p = p[chunk:]
77
91
        }
78
92
 
79
93
        dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4] = h0, h1, h2, h3, h4
80
 
        return n
81
94
}