md4

package module
v0.0.0-...-2271f34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 3 Imported by: 0

README

go-md4

Package md4 implements the MD4 cryptographic hash algorithm as per IETF RFC-1320, for the Go programming language.

Note that MD4 is no longer considered secure. However, it may still be useful for some non-secure (and historical) use-cases.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-md4

GoDoc

Examples

Here is a simple example of calculating the MD4 digest of data contained in a []byte:

import "github.com/reiver/go-md4"

// ...

var data []byte = []byte("Hello world!")

digest := md4.Sum(data)

Here is a more complex example of putting data into the an MD4 hasher in multiple pieces.

import "github.com/reiver/go-md4"

// ...

hasher := md4.New()

// This is equivalent to writing:
//
//	[]byte("once+twice-thrice_fource")
hasher.Write([]byte("once"))
hasher.Write([]byte("+"))
hasher.Write([]byte("twice"))
hasher.Write([]byte("-"))
hasher.Write([]byte("thrice"))
hasher.Write([]byte("_"))
hasher.Write([]byte("fource"))

digest := hasher.Sum(nil)

Import

To import package md4 use import code like the following:

import "github.com/reiver/go-md4"

Installation

To install package md4 do the following:

GOPROXY=direct go get github.com/reiver/go-md4

Author

Package md4 was written by Charles Iliya Krempeaux

Documentation

Index

Examples

Constants

View Source
const BlockSize = 64

BlockSize is the size of an MD4 block measured in bytes.

The size of an MD4 block 64 bytes (i.e., 512 bits).

View Source
const Size = 16

Size is the size of an MD4 digest (checksum) measured in bytes.

The size of an MD4 digest 16 bytes (i.e., 128 bits). For example:

//          1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16
[16]byte{0x31,0xd6,0xcf,0xe0,0xd1,0x6a,0xe9,0x31,0xb7,0x3c,0x59,0xd7,0xe0,0xc0,0x89,0xc0}

Note that if you are representing an MD4 digest in hexadecimal, then it will double the number of characters to 32 bytes. For example:

"31d6cfe0d16ae931b73c59d7e0c089c0"

Or, if you include the "0x" prefix in front of the hexadecimal representation, then it will be 32+2=34 bytes long:

0x31d6cfe0d16ae931b73c59d7e0c089c0

Size represents the length of the MD4 digest in a binary representation.

Variables

This section is empty.

Functions

func New

func New() hash.Hash

New returns a hash.Hash that calculates an MD4 digest (checksum) using the MD4 cryptographic hash-function.

Example
hasher := md4.New()

// “Yesterday I was clever, so I wanted to change the world. Today I am wise, so I am changing myself.”
// ⸺ Rumi
io.WriteString(hasher, "“")
io.WriteString(hasher, "Yesterday I was clever, so I wanted to change the world.")
io.WriteString(hasher, " ")
io.WriteString(hasher, "Today I am wise, so I am changing myself.")
io.WriteString(hasher, "”")
io.WriteString(hasher, "\n")
io.WriteString(hasher, "”")
io.WriteString(hasher, "⸺")
io.WriteString(hasher, " ")
io.WriteString(hasher, "Rumi")

digest := hasher.Sum(nil)

fmt.Printf("MD4-DIGEST: 0x%032X\n", digest)
Output:

MD4-DIGEST: 0xA2D6BDF512B93A4DAD4556D8F9495E5B

func Sum

func Sum(data []byte) [Size]byte

Sum returns the MD4 digest (checksum) of `data` calculated using the MD4 hash-function.

Example
var data []byte = []byte("Hello world!")

digest := md4.Sum(data)

fmt.Printf("MD4-DIGEST: 0x%032X\n", digest)
Output:

MD4-DIGEST: 0x0D7A9DB5A3BED4AE5738EE6D1909649C

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL