// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package md4 implements the MD4 hash algorithm as defined in RFC 1320. // // Deprecated: MD4 is cryptographically broken and should should only be used // where compatibility with legacy systems, not security, is the goal. Instead, // use a secure hash like SHA-256 (from crypto/sha256).
package md4 // import "golang.org/x/crypto/md4" import ( ) func init() { crypto.RegisterHash(crypto.MD4, New) } // The size of an MD4 checksum in bytes. const Size = 16 // The blocksize of MD4 in bytes. const BlockSize = 64 const ( _Chunk = 64 _Init0 = 0x67452301 _Init1 = 0xEFCDAB89 _Init2 = 0x98BADCFE _Init3 = 0x10325476 ) // digest represents the partial evaluation of a checksum. type digest struct { s [4]uint32 x [_Chunk]byte nx int len uint64 } func ( *digest) () { .s[0] = _Init0 .s[1] = _Init1 .s[2] = _Init2 .s[3] = _Init3 .nx = 0 .len = 0 } // New returns a new hash.Hash computing the MD4 checksum. func () hash.Hash { := new(digest) .Reset() return } func ( *digest) () int { return Size } func ( *digest) () int { return BlockSize } func ( *digest) ( []byte) ( int, error) { = len() .len += uint64() if .nx > 0 { := len() if > _Chunk-.nx { = _Chunk - .nx } for := 0; < ; ++ { .x[.nx+] = [] } .nx += if .nx == _Chunk { _Block(, .x[0:]) .nx = 0 } = [:] } := _Block(, ) = [:] if len() > 0 { .nx = copy(.x[:], ) } return } func ( *digest) ( []byte) []byte { // Make a copy of d0, so that caller can keep writing and summing. := new(digest) * = * // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. := .len var [64]byte [0] = 0x80 if %64 < 56 { .Write([0 : 56-%64]) } else { .Write([0 : 64+56-%64]) } // Length in bits. <<= 3 for := uint(0); < 8; ++ { [] = byte( >> (8 * )) } .Write([0:8]) if .nx != 0 { panic("d.nx != 0") } for , := range .s { = append(, byte(>>0)) = append(, byte(>>8)) = append(, byte(>>16)) = append(, byte(>>24)) } return }