View Source Caustic.Md5 (Caustic v0.1.25)

Implementation of the MD5 hash.

Link to this section Summary

Functions

Clip a number to 32-bit.

The nonlinear function used in round 1 (of 4) of a block processing.

The nonlinear function used in round 2 (of 4) of a block processing.

The nonlinear function used in round 3 (of 4) of a block processing.

The nonlinear function used in round 4 (of 4) of a block processing.

Calculate the md5 hash of a message.

Examples

iex> Caustic.Md5.hex_to_uint32_little_endian("6036708e") 2389718624

Pad a binary and append original message length at the end.

Pad a binary with a single '1' bit and then with as much '0' bits as needed.

Link to this section Functions

Clip a number to 32-bit.

The nonlinear function used in round 1 (of 4) of a block processing.

The nonlinear function used in round 2 (of 4) of a block processing.

The nonlinear function used in round 3 (of 4) of a block processing.

The nonlinear function used in round 4 (of 4) of a block processing.

Calculate the md5 hash of a message.

examples

Examples

iex> Caustic.Md5.hash("The quick brown fox jumps over the lazy dog")
"9e107d9d372bb6826bd81d3542a419d6"

iex> Caustic.Md5.hash("The quick brown fox jumps over the lazy dog.")
"e4d909c290d0fb1ca068ffaddf22cbd0"

iex> Caustic.Md5.hash("The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.")
"f168d89e05b664041ee6745f050caa4b"

iex> Caustic.Md5.hash("")
"d41d8cd98f00b204e9800998ecf8427e"

iex> Caustic.Md5.hash("a")
"0cc175b9c0f1b6a831c399e269772661"

iex> Caustic.Md5.hash("abc")
"900150983cd24fb0d6963f7d28e17f72"

iex> Caustic.Md5.hash("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
"57edf4a22be3c955ac49da2e2107b67a"
Link to this function

hex_to_uint32_little_endian(str)

View Source

examples

Examples

iex> Caustic.Md5.hex_to_uint32_little_endian("6036708e") 2389718624

Link to this function

length_extension_attack(message, signature, secret_length_byte, append_message)

View Source

Perform a length extension attack. https://blog.skullsecurity.org/2012/everything-you-need-to-know-about-hash-length-extension-attacks

examples

Examples

iex> secret = "THE_SUPER_SECRET"
iex> secret_length = byte_size(secret)
iex> message = "action=delete&id=123"
iex> signature = Caustic.Md5.hash(secret <> message)
iex> append = "&id=999"
iex> message_attack = message <> <<0x80, 0x00 :: size(152), (secret_length + byte_size(message)) * 8 :: little-size(64)>> <> append
iex> signature_attack = Caustic.Md5.hash(secret <> message_attack)
iex> {message_attack, signature_attack} == Caustic.Md5.length_extension_attack(message, signature, secret_length, append)
true

Pad a binary and append original message length at the end.

The length field is a 64 bit in little endian encoding, so the written length is modulo 2^64.

md5 only works with a block size in multiple of 512 bit, so the message is optionally padded such that message <> padding <> length is in that multiple. The padding is a single '1' bit followed by as much '0' bits as needed.

Pad a binary with a single '1' bit and then with as much '0' bits as needed.