From 533b235c39a77d7994f76cf697ee5c45210128ca Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Tue, 14 Jul 2026 14:15:58 +0200 Subject: [PATCH 1/4] Prepare v1.3.1 --- CHANGES.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4f6fbeb..3d1ecbd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +### v1.3.1 2026-07-14 Paris (France) + +- Remove DKML CI (@jonahbeckford, @dinosaure, #159, #160, #161) +- Fix documentation (@kit-ty-kate, @dinosaure, #162) +- Reject bad digest size for BLAKE2 implementation (@samoht, @dinosaure, #166) +- Delete old artifact for MirageOS 3.0 (@dinosaure, @vbgl, #165, #168) +- Be safe aligned on ARM architecture (@dinosaure, @hannesm, #169) + ### v1.3.0 2025-04-14 Paris (France) - Use `CAMLextern` rather than `extern` in `caml_*` forward declarations to From 3fc66fc108b171452b262dc8d6d71a81fc69d78e Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Wed, 15 Jul 2026 11:51:04 +0200 Subject: [PATCH 2/4] Update to ocamlformat.0.29.0 --- .ocamlformat | 2 +- src-c/digestif_native.ml | 122 +++++++++++++++++----------------- src-ocaml/baijiu_blake2b.ml | 7 +- src-ocaml/baijiu_blake2s.ml | 7 +- src-ocaml/baijiu_md5.ml | 7 +- src-ocaml/baijiu_rmd160.ml | 7 +- src-ocaml/baijiu_sha1.ml | 7 +- src-ocaml/baijiu_sha256.ml | 7 +- src-ocaml/baijiu_sha3.ml | 4 +- src-ocaml/baijiu_sha512.ml | 7 +- src-ocaml/baijiu_whirlpool.ml | 7 +- src/digestif.mli | 23 ++++--- test/test.ml | 86 ++++++++++++------------ 13 files changed, 141 insertions(+), 152 deletions(-) diff --git a/.ocamlformat b/.ocamlformat index 6624724..a1f98eb 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,4 +1,4 @@ -version = 0.21.0 +version = 0.29.0 break-infix = fit-or-vertical parse-docstrings = true indicate-multiline-delimiters=no diff --git a/src-c/digestif_native.ml b/src-c/digestif_native.ml index 7535e37..9b52772 100644 --- a/src-c/digestif_native.ml +++ b/src-c/digestif_native.ml @@ -34,7 +34,7 @@ module MD5 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_md5_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -42,11 +42,11 @@ module MD5 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_md5_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_md5_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_md5_ctx_size" [@@noalloc] @@ -63,7 +63,7 @@ module SHA1 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha1_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -71,11 +71,11 @@ module SHA1 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha1_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha1_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha1_ctx_size" [@@noalloc] @@ -92,7 +92,7 @@ module SHA224 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha224_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -100,11 +100,11 @@ module SHA224 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha224_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha224_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha224_ctx_size" [@@noalloc] @@ -121,7 +121,7 @@ module SHA256 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha256_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -129,11 +129,11 @@ module SHA256 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha256_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha256_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha256_ctx_size" [@@noalloc] @@ -150,7 +150,7 @@ module SHA384 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha384_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -158,11 +158,11 @@ module SHA384 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha384_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha384_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha384_ctx_size" [@@noalloc] @@ -179,7 +179,7 @@ module SHA512 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha512_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -187,11 +187,11 @@ module SHA512 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha512_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha512_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha512_ctx_size" [@@noalloc] @@ -208,7 +208,7 @@ module SHA3_224 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha3_224_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -216,15 +216,15 @@ module SHA3_224 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha3_224_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha3_224_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha3_224_ctx_size" - [@@noalloc] + [@@noalloc] end module SHA3_256 = struct @@ -238,7 +238,7 @@ module SHA3_256 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha3_256_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -246,15 +246,15 @@ module SHA3_256 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha3_256_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha3_256_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha3_256_ctx_size" - [@@noalloc] + [@@noalloc] end module KECCAK_256 = struct @@ -268,7 +268,7 @@ module KECCAK_256 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_keccak_256_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -276,15 +276,15 @@ module KECCAK_256 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha3_256_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_keccak_256_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha3_256_ctx_size" - [@@noalloc] + [@@noalloc] end module SHA3_384 = struct @@ -298,7 +298,7 @@ module SHA3_384 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha3_384_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -306,15 +306,15 @@ module SHA3_384 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha3_384_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha3_384_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha3_384_ctx_size" - [@@noalloc] + [@@noalloc] end module SHA3_512 = struct @@ -328,7 +328,7 @@ module SHA3_512 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_sha3_512_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -336,15 +336,15 @@ module SHA3_512 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_sha3_512_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_sha3_512_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_sha3_512_ctx_size" - [@@noalloc] + [@@noalloc] end module WHIRLPOOL = struct @@ -358,7 +358,7 @@ module WHIRLPOOL = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_whirlpool_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -366,15 +366,15 @@ module WHIRLPOOL = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_whirlpool_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_whirlpool_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_whirlpool_ctx_size" - [@@noalloc] + [@@noalloc] end module BLAKE2B = struct @@ -388,11 +388,11 @@ module BLAKE2B = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_blake2b_ba_finalize" - [@@noalloc] + [@@noalloc] external with_outlen_and_key : ctx -> size -> ba -> off -> size -> unit = "caml_digestif_blake2b_ba_init_with_outlen_and_key" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -400,25 +400,25 @@ module BLAKE2B = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_blake2b_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_blake2b_st_finalize" - [@@noalloc] + [@@noalloc] external with_outlen_and_key : ctx -> size -> st -> off -> size -> unit = "caml_digestif_blake2b_st_init_with_outlen_and_key" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_blake2b_ctx_size" [@@noalloc] external key_size : unit -> int = "caml_digestif_blake2b_key_size" [@@noalloc] external max_outlen : unit -> int = "caml_digestif_blake2b_max_outlen" - [@@noalloc] + [@@noalloc] external digest_size : ctx -> int = "caml_digestif_blake2b_digest_size" - [@@noalloc] + [@@noalloc] end module BLAKE2S = struct @@ -432,11 +432,11 @@ module BLAKE2S = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_blake2s_ba_finalize" - [@@noalloc] + [@@noalloc] external with_outlen_and_key : ctx -> size -> ba -> off -> size -> unit = "caml_digestif_blake2s_ba_init_with_outlen_and_key" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -444,25 +444,25 @@ module BLAKE2S = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_blake2s_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_blake2s_st_finalize" - [@@noalloc] + [@@noalloc] external with_outlen_and_key : ctx -> size -> st -> off -> size -> unit = "caml_digestif_blake2s_st_init_with_outlen_and_key" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_blake2s_ctx_size" [@@noalloc] external key_size : unit -> int = "caml_digestif_blake2s_key_size" [@@noalloc] external max_outlen : unit -> int = "caml_digestif_blake2s_max_outlen" - [@@noalloc] + [@@noalloc] external digest_size : ctx -> int = "caml_digestif_blake2s_digest_size" - [@@noalloc] + [@@noalloc] end module RMD160 = struct @@ -476,7 +476,7 @@ module RMD160 = struct external finalize : ctx -> ba -> off -> unit = "caml_digestif_rmd160_ba_finalize" - [@@noalloc] + [@@noalloc] end module Bytes = struct @@ -484,11 +484,11 @@ module RMD160 = struct external update : ctx -> st -> off -> size -> unit = "caml_digestif_rmd160_st_update" - [@@noalloc] + [@@noalloc] external finalize : ctx -> st -> off -> unit = "caml_digestif_rmd160_st_finalize" - [@@noalloc] + [@@noalloc] end external ctx_size : unit -> int = "caml_digestif_rmd160_ctx_size" [@@noalloc] @@ -500,7 +500,7 @@ module XOR = struct module Bigstring = struct external xor_into : ba -> off -> ba -> off -> size -> unit = "caml_digestif_ba_xor_into" - [@@noalloc] + [@@noalloc] let xor_into a b n = if n > imin (Bi.length a) (Bi.length b) @@ -518,7 +518,7 @@ module XOR = struct module Bytes = struct external xor_into : st -> off -> st -> off -> size -> unit = "caml_digestif_st_xor_into" - [@@noalloc] + [@@noalloc] let xor_into a b n = if n > imin (By.length a) (By.length b) diff --git a/src-ocaml/baijiu_blake2b.ml b/src-ocaml/baijiu_blake2b.ml index efc60f9..4358479 100644 --- a/src-ocaml/baijiu_blake2b.ml +++ b/src-ocaml/baijiu_blake2b.ml @@ -203,8 +203,8 @@ module Unsafe : S = struct [| 14; 10; 4; 8; 9; 15; 13; 6; 1; 12; 0; 2; 11; 7; 5; 3 |]; |] - let compress : - type a. le64_to_cpu:(a -> int -> int64) -> ctx -> a -> int -> unit = + let compress : type a. + le64_to_cpu:(a -> int -> int64) -> ctx -> a -> int -> unit = fun ~le64_to_cpu ctx block off -> let v = Array.make 16 0L in let m = Array.make 16 0L in @@ -260,8 +260,7 @@ module Unsafe : S = struct done ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> le64_to_cpu:(a -> int -> int64) -> ctx -> diff --git a/src-ocaml/baijiu_blake2s.ml b/src-ocaml/baijiu_blake2s.ml index d9be997..b94ea68 100644 --- a/src-ocaml/baijiu_blake2s.ml +++ b/src-ocaml/baijiu_blake2s.ml @@ -179,8 +179,8 @@ module Unsafe : S = struct [| 10; 2; 8; 4; 7; 6; 1; 5; 15; 11; 9; 14; 3; 12; 13; 0 |]; |] - let compress : - type a. le32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = + let compress : type a. + le32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = fun ~le32_to_cpu ctx block off -> let v = Array.make 16 0l in let m = Array.make 16 0l in @@ -234,8 +234,7 @@ module Unsafe : S = struct done ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> le32_to_cpu:(a -> int -> int32) -> ctx -> diff --git a/src-ocaml/baijiu_md5.ml b/src-ocaml/baijiu_md5.ml index e16290d..088e87d 100644 --- a/src-ocaml/baijiu_md5.ml +++ b/src-ocaml/baijiu_md5.ml @@ -53,8 +53,8 @@ module Unsafe : S = struct let f3 x y z = Int32.(x lxor y lxor z) let f4 x y z = Int32.(y lxor (x lor lnot z)) - let md5_do_chunk : - type a. le32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = + let md5_do_chunk : type a. + le32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = fun ~le32_to_cpu ctx buf off -> let a, b, c, d = (ref ctx.h.(0), ref ctx.h.(1), ref ctx.h.(2), ref ctx.h.(3)) in @@ -138,8 +138,7 @@ module Unsafe : S = struct ctx.h.(3) <- ctx.h.(3) + !d ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> le32_to_cpu:(a -> int -> int32) -> ctx -> diff --git a/src-ocaml/baijiu_rmd160.ml b/src-ocaml/baijiu_rmd160.ml index 88a86b9..b9587f0 100644 --- a/src-ocaml/baijiu_rmd160.ml +++ b/src-ocaml/baijiu_rmd160.ml @@ -116,8 +116,8 @@ module Unsafe : S = struct a := rol32 !a s + !e ; c := rol32 !c 10 - let rmd160_do_chunk : - type a. le32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = + let rmd160_do_chunk : type a. + le32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = fun ~le32_to_cpu ctx buff off -> let aa, bb, cc, dd, ee, aaa, bbb, ccc, ddd, eee = ( ref ctx.h.(0), @@ -306,8 +306,7 @@ module Unsafe : S = struct exception Leave - let feed : - type a. + let feed : type a. le32_to_cpu:(a -> int -> int32) -> blit:(a -> int -> By.t -> int -> int -> unit) -> ctx -> diff --git a/src-ocaml/baijiu_sha1.ml b/src-ocaml/baijiu_sha1.ml index 8c12bfa..17de8de 100644 --- a/src-ocaml/baijiu_sha1.ml +++ b/src-ocaml/baijiu_sha1.ml @@ -55,8 +55,8 @@ module Unsafe : S = struct let k3 = 0x8f1bbcdcl let k4 = 0xca62c1d6l - let sha1_do_chunk : - type a. be32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = + let sha1_do_chunk : type a. + be32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = fun ~be32_to_cpu ctx buf off -> let a = ref ctx.h.(0) in let b = ref ctx.h.(1) in @@ -170,8 +170,7 @@ module Unsafe : S = struct ctx.h.(4) <- Int32.add ctx.h.(4) !e ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> be32_to_cpu:(a -> int -> int32) -> ctx -> diff --git a/src-ocaml/baijiu_sha256.ml b/src-ocaml/baijiu_sha256.ml index 1c60397..4a0206f 100644 --- a/src-ocaml/baijiu_sha256.ml +++ b/src-ocaml/baijiu_sha256.ml @@ -73,8 +73,8 @@ module Unsafe : S = struct let s0 x = Int32.(ror32 x 7 lxor ror32 x 18 lxor (x lsr 3)) let s1 x = Int32.(ror32 x 17 lxor ror32 x 19 lxor (x lsr 10)) - let sha256_do_chunk : - type a. be32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = + let sha256_do_chunk : type a. + be32_to_cpu:(a -> int -> int32) -> ctx -> a -> int -> unit = fun ~be32_to_cpu ctx buf off -> let a, b, c, d, e, f, g, h, t1, t2 = ( ref ctx.h.(0), @@ -122,8 +122,7 @@ module Unsafe : S = struct ctx.h.(7) <- ctx.h.(7) + !h ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> be32_to_cpu:(a -> int -> int32) -> ctx -> diff --git a/src-ocaml/baijiu_sha3.ml b/src-ocaml/baijiu_sha3.ml index 2fe897b..cd1a54f 100644 --- a/src-ocaml/baijiu_sha3.ml +++ b/src-ocaml/baijiu_sha3.ml @@ -114,8 +114,8 @@ struct 0xff00ffffffffffffL; 0x00ffffffffffffffL; |] - let feed : - type a. get_uint8:(a -> int -> int) -> ctx -> a -> int -> int -> unit = + let feed : type a. + get_uint8:(a -> int -> int) -> ctx -> a -> int -> int -> unit = fun ~get_uint8 ctx buf off len -> let ( && ) = ( land ) in diff --git a/src-ocaml/baijiu_sha512.ml b/src-ocaml/baijiu_sha512.ml index 74bfb26..6f0a845 100644 --- a/src-ocaml/baijiu_sha512.ml +++ b/src-ocaml/baijiu_sha512.ml @@ -82,8 +82,8 @@ module Unsafe : S = struct let s0 x = Int64.(ror64 x 1 lxor ror64 x 8 lxor (x lsr 7)) let s1 x = Int64.(ror64 x 19 lxor ror64 x 61 lxor (x lsr 6)) - let sha512_do_chunk : - type a. be64_to_cpu:(a -> int -> int64) -> ctx -> a -> int -> unit = + let sha512_do_chunk : type a. + be64_to_cpu:(a -> int -> int64) -> ctx -> a -> int -> unit = fun ~be64_to_cpu ctx buf off -> let a, b, c, d, e, f, g, h, t1, t2 = ( ref ctx.h.(0), @@ -131,8 +131,7 @@ module Unsafe : S = struct ctx.h.(7) <- ctx.h.(7) + !h ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> be64_to_cpu:(a -> int -> int64) -> ctx -> diff --git a/src-ocaml/baijiu_whirlpool.ml b/src-ocaml/baijiu_whirlpool.ml index 03cb46f..4114b4e 100644 --- a/src-ocaml/baijiu_whirlpool.ml +++ b/src-ocaml/baijiu_whirlpool.ml @@ -744,8 +744,8 @@ module Unsafe : S = struct |]; |] - let whirlpool_do_chunk : - type a. be64_to_cpu:(a -> int -> int64) -> ctx -> a -> int -> unit = + let whirlpool_do_chunk : type a. + be64_to_cpu:(a -> int -> int64) -> ctx -> a -> int -> unit = fun ~be64_to_cpu ctx buf off -> let key = Array.init 2 (fun _ -> Array.make 8 Int64.zero) in let state = Array.init 2 (fun _ -> Array.make 8 Int64.zero) in @@ -790,8 +790,7 @@ module Unsafe : S = struct done ; () - let feed : - type a. + let feed : type a. blit:(a -> int -> By.t -> int -> int -> unit) -> be64_to_cpu:(a -> int -> int64) -> ctx -> diff --git a/src/digestif.mli b/src/digestif.mli index 3b2ee12..cafcc45 100644 --- a/src/digestif.mli +++ b/src/digestif.mli @@ -39,7 +39,7 @@ module type S = sig val feedi_bytes : ctx -> Bytes.t iter -> ctx (** [feedi_bytes t iter = let r = ref t in iter (fun msg -> r := feed !r msg); - !r] *) + !r] *) val feedi_string : ctx -> String.t iter -> ctx (** Same as {!feed_bytes} but for {!String.t}. *) @@ -56,8 +56,7 @@ module type S = sig val hmac_feed_bytes : hmac -> ?off:int -> ?len:int -> Bytes.t -> hmac (** [hmac_feed_bytes t msg] adds informations in [msg] to [t]. [hmac_feed] is analogous to appending: - [hmac_feed (hmac_feed t msg1) msg2 = hmac_feed t - (append msg1 msg2)] *) + [hmac_feed (hmac_feed t msg1) msg2 = hmac_feed t (append msg1 msg2)] *) val hmac_feed_string : hmac -> ?off:int -> ?len:int -> String.t -> hmac (** Same as {!hmac_feed_bytes} but for {!String.t}. *) @@ -66,8 +65,8 @@ module type S = sig (** Same as {!hmac_feed_bytes} but for {!bigstring}. *) val hmac_feedi_bytes : hmac -> Bytes.t iter -> hmac - (** [hmac_feedi_bytes t iter = let r = ref t in iter (fun msg -> r := hmac_feed !r msg); - !r] *) + (** [hmac_feedi_bytes t iter = let r = ref t in iter (fun msg -> r := + hmac_feed !r msg); !r] *) val hmac_feedi_string : hmac -> String.t iter -> hmac (** Same as {!hmac_feedi_bytes} but for {!String.t}. *) @@ -130,7 +129,8 @@ module type S = sig (** Same as {!hmaci_bytes} but for {!bigstring}. *) val hmacv_bytes : key:string -> Bytes.t list -> t - (** Specialization of {!hmaci_bytes} with a list of {!Bytes.t} (see {!iter}). *) + (** Specialization of {!hmaci_bytes} with a list of {!Bytes.t} (see {!iter}). + *) val hmacv_string : key:string -> String.t list -> t (** Same as {!hmacv_bytes} but for {!String.t}. *) @@ -161,7 +161,8 @@ module type S = sig (** [of_hex] tries to parse an hexadecimal representation of {!t}. [of_hex] returns [None] when input is malformed. We take only first {!digest_size} hexadecimal values and ignore rest of input. If it has not enough - hexadecimal values, trailing values of the output hash are zero ([\x00]). *) + hexadecimal values, trailing values of the output hash are zero ([\x00]). + *) val consistent_of_hex : string -> t (** [consistent_of_hex] tries to parse an hexadecimal representation of {!t}. @@ -198,10 +199,10 @@ module type S = sig It's equivalent to: {[ - let get_into_bytes ctx ?(off = 0) buf = - let t = get ctx in - let str = to_raw_string t in - Bytes.blit_string str 0 buf off digest_size + let get_into_bytes ctx ?(off = 0) buf = + let t = get ctx in + let str = to_raw_string t in + Bytes.blit_string str 0 buf off digest_size ]} except [get_into_bytes] does not allocate an intermediate string. *) diff --git a/test/test.ml b/test/test.ml index c8d5cdf..81bb218 100644 --- a/test/test.ml +++ b/test/test.ml @@ -3,8 +3,7 @@ type _ s = Bytes : Bytes.t s | String : String.t s | Bigstring : bigstring s and bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -let title : - type a k. +let title : type a k. [ `HMAC | `HMAC_feed | `Digest ] -> k Digestif.hash -> a s -> string = fun computation hash input -> let pp_computation ppf = function @@ -13,34 +12,34 @@ let title : | `Digest -> Fmt.string ppf "digest" in let pp_hash : type k. k Digestif.hash Fmt.t = fun ppf -> function - | Digestif.MD5 -> Fmt.string ppf "md5" - | Digestif.SHA1 -> Fmt.string ppf "sha1" - | Digestif.RMD160 -> Fmt.string ppf "rmd160" - | Digestif.SHA224 -> Fmt.string ppf "sha224" - | Digestif.SHA256 -> Fmt.string ppf "sha256" - | Digestif.SHA384 -> Fmt.string ppf "sha384" - | Digestif.SHA512 -> Fmt.string ppf "sha512" - | Digestif.SHA3_224 -> Fmt.string ppf "sha3_224" - | Digestif.SHA3_256 -> Fmt.string ppf "sha3_256" - | Digestif.KECCAK_256 -> Fmt.string ppf "keccak_256" - | Digestif.SHA3_384 -> Fmt.string ppf "sha3_384" - | Digestif.SHA3_512 -> Fmt.string ppf "sha3_512" - | Digestif.WHIRLPOOL -> Fmt.string ppf "whirlpool" - | Digestif.BLAKE2B -> Fmt.string ppf "blake2b" - | Digestif.BLAKE2S -> Fmt.string ppf "blake2s" in + | Digestif.MD5 -> Fmt.string ppf "md5" + | Digestif.SHA1 -> Fmt.string ppf "sha1" + | Digestif.RMD160 -> Fmt.string ppf "rmd160" + | Digestif.SHA224 -> Fmt.string ppf "sha224" + | Digestif.SHA256 -> Fmt.string ppf "sha256" + | Digestif.SHA384 -> Fmt.string ppf "sha384" + | Digestif.SHA512 -> Fmt.string ppf "sha512" + | Digestif.SHA3_224 -> Fmt.string ppf "sha3_224" + | Digestif.SHA3_256 -> Fmt.string ppf "sha3_256" + | Digestif.KECCAK_256 -> Fmt.string ppf "keccak_256" + | Digestif.SHA3_384 -> Fmt.string ppf "sha3_384" + | Digestif.SHA3_512 -> Fmt.string ppf "sha3_512" + | Digestif.WHIRLPOOL -> Fmt.string ppf "whirlpool" + | Digestif.BLAKE2B -> Fmt.string ppf "blake2b" + | Digestif.BLAKE2S -> Fmt.string ppf "blake2s" in let pp_input : type a. a s Fmt.t = fun ppf -> function - | Bytes -> Fmt.string ppf "bytes" - | String -> Fmt.string ppf "string" - | Bigstring -> Fmt.string ppf "bigstring" in + | Bytes -> Fmt.string ppf "bytes" + | String -> Fmt.string ppf "string" + | Bigstring -> Fmt.string ppf "bigstring" in Fmt.str "%a:%a:%a" pp_computation computation pp_hash hash pp_input input let bytes = Bytes let string = String let bigstring = Bigstring -let test_hmac : - type k a. a s -> k Digestif.hash -> string -> a -> k Digestif.t -> unit = +let test_hmac : type k a. + a s -> k Digestif.hash -> string -> a -> k Digestif.t -> unit = fun kind hash key input expect -> let title = title `HMAC hash kind in let test_hash = Alcotest.testable (Digestif.pp hash) (Digestif.equal hash) in @@ -55,8 +54,8 @@ let test_hmac : let result = Digestif.hmaci_bigstring hash ~key (fun f -> f input) in Alcotest.(check test_hash) title expect result -let test_hmac_feed : - type k a. a s -> k Digestif.hash -> string -> a -> k -> unit = +let test_hmac_feed : type k a. + a s -> k Digestif.hash -> string -> a -> k -> unit = fun kind hash key input expect -> let title = title `HMAC_feed hash kind in let module H = (val Digestif.module_of hash) in @@ -96,8 +95,7 @@ let test_digest : type k a. a s -> k Digestif.hash -> a -> k Digestif.t -> unit let result = Digestif.digesti_bigstring hash (fun f -> f input) in Alcotest.(check test_hash) title expect result -let make_hmac : - type a k. +let make_hmac : type a k. name:string -> a s -> k Digestif.hash -> @@ -108,8 +106,7 @@ let make_hmac : fun ~name kind hash key input expect -> (name, `Quick, fun () -> test_hmac kind hash key input expect) -let make_hmac_feed : - type a k. +let make_hmac_feed : type a k. name:string -> a s -> k Digestif.hash -> @@ -120,8 +117,7 @@ let make_hmac_feed : fun ~name kind hash key input expect -> (name, `Quick, fun () -> test_hmac_feed kind hash key input expect) -let make_digest : - type a k. +let make_digest : type a k. name:string -> a s -> k Digestif.hash -> @@ -170,7 +166,7 @@ let keys_by, keys_st, keys_bi = "La c'est un peu chaud en vrai"; ] |> List.map (fun s -> - (Bytes.unsafe_of_string s, s, to_bigstring (Bytes.unsafe_of_string s))) + (Bytes.unsafe_of_string s, s, to_bigstring (Bytes.unsafe_of_string s))) |> split3 let inputs_by, inputs_st, inputs_bi = @@ -188,7 +184,7 @@ let inputs_by, inputs_st, inputs_bi = rideaux."; ] |> List.map (fun s -> - (Bytes.unsafe_of_string s, s, to_bigstring (Bytes.unsafe_of_string s))) + (Bytes.unsafe_of_string s, s, to_bigstring (Bytes.unsafe_of_string s))) |> split3 let results_md5 = @@ -369,16 +365,16 @@ module BLAKE2 = struct (res, succ i, None)) (Bytes.create len, 0, None) hex - |> (function - | _, _, Some _ -> invalid_arg "of_hex" - | res, i, _ -> - if i = len - then res - else ( - for i = i to len - 1 do - Bytes.set res i '\000' - done ; - res)) + |> ( function + | _, _, Some _ -> invalid_arg "of_hex" + | res, i, _ -> + if i = len + then res + else ( + for i = i to len - 1 do + Bytes.set res i '\000' + done ; + res) ) |> Bytes.unsafe_to_string let parse kind ic = @@ -412,8 +408,7 @@ module BLAKE2 = struct | exception End_of_file -> List.rev acc in loop `In [] - let test_mac : - type k a. + let test_mac : type k a. a s -> k Digestif.hash -> (module Digestif.MAC) -> @@ -430,7 +425,8 @@ module BLAKE2 = struct (Obj.magic result) (* XXX(dinosaure): ok, this is really bad but I'm lazy to keep type equality on [Mac] - extend interface and play with [with type t = t] - anywhere. *) in + anywhere. *) + in match kind with | Bytes -> check @@ Mac.maci_bytes ~key (fun f -> f input) | String -> check @@ Mac.maci_string ~key (fun f -> f input) From b82851d4e6efdd45f926ae6e77ecbbc59c91910f Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Wed, 15 Jul 2026 11:51:43 +0200 Subject: [PATCH 3/4] Add .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..4bae49c --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Apply ocamlformat.0.29.0 +3fc66fc108b171452b262dc8d6d71a81fc69d78e From a2697d0ce0d6893982bfa21be464a5ae5f4ea75f Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Wed, 15 Jul 2026 11:54:49 +0200 Subject: [PATCH 4/4] Up our CI to OCaml 5.1.x --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90ceec8..641dd20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - ubuntu-latest - macos-latest ocaml-compiler: - - '4.13.x' + - '5.1.x' runs-on: ${{ matrix.os }} name: test-ocaml / ${{ matrix.os }}-${{ matrix.ocaml-compiler }} steps: