1 // Copyright 2010 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.
5 // This package implements the RIPEMD-160 hash algorithm.
8 // RIPEMD-160 is designed by by Hans Dobbertin, Antoon Bosselaers, and Bart
9 // Preneel with specifications available at:
10 // http://homes.esat.kuleuven.be/~cosicart/pdf/AB-9601/AB-9601.pdf.
19 crypto.RegisterHash(crypto.RIPEMD160, New)
22 // The size of the checksum in bytes.
25 // The block size of the hash algorithm in bytes.
36 // digest represents the partial evaluation of a checksum.
38 s [5]uint32 // running context
39 x [BlockSize]byte // temporary buffer
40 nx int // index into x
41 tc uint64 // total count of bytes processed
44 func (d *digest) Reset() {
45 d.s[0], d.s[1], d.s[2], d.s[3], d.s[4] = _s0, _s1, _s2, _s3, _s4
50 // New returns a new hash.Hash computing the checksum.
51 func New() hash.Hash {
57 func (d *digest) Size() int { return Size }
59 func (d *digest) Write(p []byte) (nn int, err os.Error) {
64 if n > BlockSize-d.nx {
67 for i := 0; i < n; i++ {
71 if d.nx == BlockSize {
80 d.nx = copy(d.x[:], p)
85 func (d0 *digest) Sum() []byte {
86 // Make a copy of d0 so that caller can keep writing and summing.
90 // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
95 d.Write(tmp[0 : 56-tc%64])
97 d.Write(tmp[0 : 64+56-tc%64])
102 for i := uint(0); i < 8; i++ {
103 tmp[i] = byte(tc >> (8 * i))
111 p := make([]byte, 20)
113 for _, s := range d.s {
114 p[j], p[j+1], p[j+2], p[j+3] = byte(s), byte(s>>8), byte(s>>16), byte(s>>24)