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.
5 // Package md5 implements the MD5 hash algorithm as defined in RFC 1321.
14 crypto.RegisterHash(crypto.MD5, New)
17 // The size of an MD5 checksum in bytes.
28 // digest represents the partial evaluation of a checksum.
36 func (d *digest) Reset() {
45 // New returns a new hash.Hash computing the MD5 checksum.
46 func New() hash.Hash {
52 func (d *digest) Size() int { return Size }
54 func (d *digest) Write(p []byte) (nn int, err error) {
62 for i := 0; i < n; i++ {
75 d.nx = copy(d.x[:], p)
80 func (d0 *digest) Sum(in []byte) []byte {
81 // Make a copy of d0 so that caller can keep writing and summing.
84 // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
89 d.Write(tmp[0 : 56-len%64])
91 d.Write(tmp[0 : 64+56-len%64])
96 for i := uint(0); i < 8; i++ {
97 tmp[i] = byte(len >> (8 * i))
105 var digest [Size]byte
106 for i, s := range d.s {
107 digest[i*4] = byte(s)
108 digest[i*4+1] = byte(s >> 8)
109 digest[i*4+2] = byte(s >> 16)
110 digest[i*4+3] = byte(s >> 24)
113 return append(in, digest[:]...)