Stdlib.Digest(3)

🌸 NAME 🌸

Stdlib.Digest β€” no description πŸ’… (that's literally what it says, bestie, the manpage gives us nothing here)


πŸ¦‹ Module

Module Stdlib.Digest

πŸ““ Documentation

Module Digest : (module Stdlib__Digest)


✨ Basic functions ✨

Okay so the functions in this section use the MD5 hash function to make 128-bit digests (16 bytes). MD5 is not cryptographically secure β€” no cap, it's just not. So like, do not use these for security-sensitive applications, fr fr. The BLAKE2 functions further down are cryptographically secure, those are the ones you want for that 🫢

  • type t = string β€” the type of digests: 16-byte strings. That's the whole vibe.
  • val compare : t -> t -> int β€” the comparison function for 16-byte digests, with the same specification as compare and the implementation shared with String.compare. Along with the type t, this function compare is what lets the module Digest be passed as an argument to the functors Set.Make and Map.Make. Slay. ✨ Since 4.00
  • val equal : t -> t -> bool β€” the equal function for 16-byte digests. πŸŽ€ Since 4.03
  • val string : string -> t β€” return the digest of the given string.
  • val bytes : bytes -> t β€” return the digest of the given byte sequence. πŸ¦‹ Since 4.02
  • val substring : string -> int -> int -> t β€” Digest.substring s ofs len returns the digest of the substring of s starting at index ofs and containing len characters.
  • val subbytes : bytes -> int -> int -> t β€” Digest.subbytes s ofs len returns the digest of the subsequence of s starting at index ofs and containing len bytes. πŸ’œ Since 4.02
  • val channel : in_channel -> int -> t β€” if len is nonnegative, Digest.channel ic len reads len characters from channel ic and returns their digest, or raises End_of_file if end-of-file is reached before len characters are read. If len is negative, Digest.channel ic len reads all characters from ic until end-of-file is reached and returns their digest. iykyk 😌
  • val file : string -> t β€” return the digest of the file whose name is given.
  • val output : out_channel -> t -> unit β€” write a digest on the given output channel.
  • val input : in_channel -> t β€” read a digest from the given input channel.
  • val to_hex : t -> string β€” return the printable hexadecimal representation of the given digest.
Raises Invalid_argument if the argument is not exactly 16 bytes. ⚠️ like, exactly 16, no negotiations.
  • val of_hex : string -> t β€” convert a hexadecimal representation back into the corresponding digest. 🌈 Since 5.2
Raises Invalid_argument if the argument is not exactly 32 hexadecimal characters. 🫠
  • val from_hex : string -> t β€” same function as Digest.of_hex. πŸ“ Since 4.00

🧚 Generic interface 🧚

  • module type S = sig end β€” the signature for a hash function that produces digests of length hash_length from character strings, byte arrays, and files. πŸ‘‘ Since 5.2

πŸ”₯ Specific hash functions πŸ”₯

  • module BLAKE128 : S β€” BLAKE128 is the BLAKE2b hash function producing 128-bit (16-byte) digests. It is cryptographically secure. However β€” and this is the important bit, bestie β€” the small size of the digests enables brute-force attacks in 2{^64} attempts. πŸ’€ Since 5.2
  • module BLAKE256 : S β€” BLAKE256 is the BLAKE2b hash function producing 256-bit (32-byte) digests. It is cryptographically secure, and the digests are large enough to thwart brute-force attacks. main character energy honestly πŸ’– Since 5.2
  • module BLAKE512 : S β€” BLAKE512 is the BLAKE2b hash function producing 512-bit (64-byte) digests. It is cryptographically secure, and the digests are large enough to thwart brute-force attacks. ✨ Since 5.2
  • module MD5 : S β€” MD5 is the MD5 hash function. It produces 128-bit (16-byte) digests and is not cryptographically secure at all. It should be used only for compatibility with earlier designs that mandate the use of MD5. πŸ™ˆ Since 5.2

okay that's the whole page, bestie β€” no behind-the-scenes lore, no secret extra functions, this is the entire vibe check πŸ’…

this iconic little doc was served up by OCamldoc on 2026-06-22, for Stdlib.Digest(3) β€” stay hydrated and hash responsibly 🫢✨

πŸ“¦ where this page comes from