Digest(3)
πΈ NAME β Digest(3) πΈ
okay so this page is from the OCaml library, and itβs all about Digest β Message digest. π
π§ Module π§
Module Digest β yup, thatβs the module, bestie. π«Ά
β¨ Documentation β¨
Module Digest : sig end
okay so Digest is the whole vibe: this module provides functions to compute βdigestsβ, also known as βhashesβ, of arbitrary-length strings or files. The supported hashing algorithms are BLAKE2 and MD5. β¨
π Basic functions π
The functions in this section use the MD5 hash function to produce 128-bit digests (16 bytes). MD5 is not cryptographically secure. Hence, these functions should not be used for security-sensitive applications. The BLAKE2 functions below are cryptographically secure. π«Ά
type t = stringβ the type of digests: 16-byte strings. π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 functioncomparelets the moduleDigestbe passed as an argument to the functorsSet.MakeandMap.Make. Since 4.00 β vintage but iconic.val equal : t -> t -> boolβ the equal function 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.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. RaisesInvalid_argumentif the argument is not exactly 16 bytes. π¨val of_hex : string -> tβ convert a hexadecimal representation back into the corresponding digest. Since 5.2 RaisesInvalid_argumentif 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, 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. 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
bestie, for real: MD5 is not cryptographically secure at all. Keep it for compatibility only, iykyk. π
β¨ okay thatβs the whole page, bestie! π Source/version: OCamldoc; date: 2026-06-22; page: Digest(3). Slay and stay hashed! π
π¦ 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