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 ascompareand the implementation shared withString.compare. Along with the typet, this functioncompareis what lets the moduleDigestbe passed as an argument to the functorsSet.MakeandMap.Make. Slay. β¨ Since 4.00val equal : t -> t -> boolβ theequalfunction for 16-byte digests. π Since 4.03val string : string -> tβ return the digest of the given string.val bytes : bytes -> tβ return the digest of the given byte sequence. π¦ Since 4.02val substring : string -> int -> int -> tβDigest.substring s ofs lenreturns the digest of the substring ofsstarting at indexofsand containinglencharacters.val subbytes : bytes -> int -> int -> tβDigest.subbytes s ofs lenreturns the digest of the subsequence ofsstarting at indexofsand containinglenbytes. π Since 4.02val channel : in_channel -> int -> tβ iflenis nonnegative,Digest.channel ic lenreadslencharacters from channelicand returns their digest, or raisesEnd_of_fileif end-of-file is reached beforelencharacters are read. Iflenis negative,Digest.channel ic lenreads all characters fromicuntil 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 asDigest.of_hex. π Since 4.00
π§ Generic interface π§
module type S = sig endβ the signature for a hash function that produces digests of lengthhash_lengthfrom character strings, byte arrays, and files. π Since 5.2
π₯ Specific hash functions π₯
module BLAKE128 : SβBLAKE128is 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 in2{^64}attempts. π Since 5.2module BLAKE256 : SβBLAKE256is 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.2module BLAKE512 : SβBLAKE512is 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.2module MD5 : SβMD5is 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
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms