// 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.constSize = 16// The blocksize of MD4 in bytes.constBlockSize = 64const ( _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 { returnSize }func ( *digest) () int { returnBlockSize }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(, ) = [:]iflen() > 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. := .lenvar [64]byte [0] = 0x80if %64 < 56 { .Write([0 : 56-%64]) } else { .Write([0 : 64+56-%64]) }// Length in bits. <<= 3for := 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}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.