Select the types of activity you want to include in your feed.
fix(crypto): add E405 value docs and apply dune fmt
Add documentation for all undocumented public values in native.mli and test .mli files. Apply dune fmt formatting (camelCase to snake_case in wycheproof and test files).
···408408 (* number must not be in montgomery domain*)
409409 let y_struct2 = rev_string y_struct2 in
410410 let ident = String.get_uint8 pk 0 in
411411- let signY = 2 + (String.get_uint8 y_struct (P.byte_length - 1) land 1) in
412412- let res = if Int.equal signY ident then y_struct else y_struct2 in
411411+ let sign_y = 2 + (String.get_uint8 y_struct (P.byte_length - 1) land 1) in
412412+ let res = if Int.equal sign_y ident then y_struct else y_struct2 in
413413 let out = Bytes.create ((P.byte_length * 2) + 1) in
414414 Bytes.set out 0 '\004';
415415 Bytes.unsafe_blit_string pk 1 out 1 P.byte_length;
···703703 let q = S.scalar_mult_base d in
704704 (d, q)
705705706706- let x_of_finite_point_mod_n p =
706706+ let x_of_point_mod_n p =
707707 match P.to_affine_raw p with
708708 | None -> None
709709 | Some (x, _) ->
···730730 (* if no k is provided, this cannot happen since K_gen_*.gen already preserves the Scalar invariants *)
731731 in
732732 let point = S.scalar_mult_base ksc in
733733- match x_of_finite_point_mod_n point with
733733+ match x_of_point_mod_n point with
734734 | None -> again ()
735735 | Some r ->
736736 let r_mon = F.from_be_octets r in
···767767 with
768768 | Ok u1, Ok u2 ->
769769 let point = P.add (S.scalar_mult_base u1) (S.scalar_mult u2 key) in
770770- begin match x_of_finite_point_mod_n point with
770770+ begin match x_of_point_mod_n point with
771771 | None -> false (* point is infinity *)
772772 | Some r' -> String.equal r r'
773773 end
···88 external enc : string -> int -> bytes -> int -> string -> int -> int -> unit
99 = "mc_aes_enc_bc" "mc_aes_enc"
1010 [@@noalloc]
1111+ (** [enc src src_off dst dst_off rk rk_off blocks] encrypts [blocks] AES
1212+ blocks from [src] into [dst] using round keys [rk]. *)
11131214 external dec : string -> int -> bytes -> int -> string -> int -> int -> unit
1315 = "mc_aes_dec_bc" "mc_aes_dec"
1416 [@@noalloc]
1717+ (** [dec src src_off dst dst_off rk rk_off blocks] decrypts [blocks] AES
1818+ blocks from [src] into [dst] using round keys [rk]. *)
15191620 external derive_e : string -> bytes -> int -> unit = "mc_aes_derive_e_key"
1721 [@@noalloc]
2222+ (** [derive_e key rk rounds] derives the encryption round-key schedule from
2323+ [key] into [rk]. *)
18241925 external derive_d : string -> bytes -> int -> string option -> unit
2026 = "mc_aes_derive_d_key"
2127 [@@noalloc]
2828+ (** [derive_d key rk rounds ekey] derives the decryption round-key schedule.
2929+ If [ekey] is provided, it is used as a precomputed encryption schedule. *)
22302323- external rk_s : int -> int = "mc_aes_rk_size" [@@noalloc]
2424- external mode : unit -> int = "mc_aes_mode" [@@noalloc]
3131+ external rk_s : int -> int = "mc_aes_rk_size"
3232+ [@@noalloc]
3333+ (** [rk_s rounds] is the round-key buffer size in bytes for [rounds] rounds.
3434+ *)
3535+3636+ external mode : unit -> int = "mc_aes_mode"
3737+ [@@noalloc]
3838+ (** [mode ()] detects the AES implementation: [0] for generic, [1] for AES-NI.
3939+ *)
2540end
26412742(** Triple DES block cipher. *)
···2944 external ddes : string -> int -> bytes -> int -> int -> string -> unit
3045 = "mc_des_ddes_bc" "mc_des_ddes"
3146 [@@noalloc]
4747+ (** [ddes src src_off dst dst_off blocks ks] encrypts or decrypts [blocks] DES
4848+ blocks using key schedule [ks]. *)
32493350 external des3key : bytes -> int -> bytes -> unit = "mc_des_des3key"
3451 [@@noalloc]
5252+ (** [des3key key mode ks] derives a Triple-DES key schedule from [key] into
5353+ [ks]. [mode] selects encryption or decryption. *)
35543636- external k_s : unit -> int = "mc_des_key_size" [@@noalloc]
5555+ external k_s : unit -> int = "mc_des_key_size"
5656+ [@@noalloc]
5757+ (** [k_s ()] is the key-schedule buffer size in bytes. *)
3758end
38593960(** ChaCha20 stream cipher. *)
4061module Chacha : sig
4162 external round : int -> bytes -> bytes -> int -> unit = "mc_chacha_round"
4263 [@@noalloc]
6464+ (** [round count state dst off] performs [count] ChaCha20 rounds on [state],
6565+ writing output into [dst] at offset [off]. *)
4366end
44674568(** Poly1305 message authentication. *)
4669module Poly1305 : sig
4747- external init : bytes -> string -> unit = "mc_poly1305_init" [@@noalloc]
7070+ external init : bytes -> string -> unit = "mc_poly1305_init"
7171+ [@@noalloc]
7272+ (** [init ctx key] initialises the Poly1305 context [ctx] with [key]. *)
48734974 external update : bytes -> string -> int -> int -> unit = "mc_poly1305_update"
5075 [@@noalloc]
7676+ (** [update ctx data off len] feeds [len] bytes from [data] at [off] into
7777+ [ctx]. *)
51785279 external finalize : bytes -> bytes -> int -> unit = "mc_poly1305_finalize"
5380 [@@noalloc]
8181+ (** [finalize ctx mac off] writes the final MAC tag into [mac] at [off]. *)
54825555- external ctx_size : unit -> int = "mc_poly1305_ctx_size" [@@noalloc]
5656- external mac_size : unit -> int = "mc_poly1305_mac_size" [@@noalloc]
8383+ external ctx_size : unit -> int = "mc_poly1305_ctx_size"
8484+ [@@noalloc]
8585+ (** [ctx_size ()] is the Poly1305 context size in bytes. *)
8686+8787+ external mac_size : unit -> int = "mc_poly1305_mac_size"
8888+ [@@noalloc]
8989+ (** [mac_size ()] is the MAC tag size in bytes (16). *)
5790end
58915992(** GHASH universal hash for GCM. *)
6093module GHASH : sig
6161- external keysize : unit -> int = "mc_ghash_key_size" [@@noalloc]
6262- external keyinit : string -> bytes -> unit = "mc_ghash_init_key" [@@noalloc]
9494+ external keysize : unit -> int = "mc_ghash_key_size"
9595+ [@@noalloc]
9696+ (** [keysize ()] is the GHASH key buffer size in bytes. *)
9797+9898+ external keyinit : string -> bytes -> unit = "mc_ghash_init_key"
9999+ [@@noalloc]
100100+ (** [keyinit key buf] derives the GHASH subkey into [buf]. *)
6310164102 external ghash : string -> bytes -> string -> int -> int -> unit = "mc_ghash"
65103 [@@noalloc]
104104+ (** [ghash key hash data off len] updates [hash] with [len] bytes from [data]
105105+ at [off] using the GHASH [key]. *)
661066767- external mode : unit -> int = "mc_ghash_mode" [@@noalloc]
107107+ external mode : unit -> int = "mc_ghash_mode"
108108+ [@@noalloc]
109109+ (** [mode ()] detects the GHASH implementation: [0] for generic, [1] for
110110+ PCLMULQDQ. *)
68111end
6911270113external xor_into_bytes : string -> int -> bytes -> int -> int -> unit
+3
tests/test_base.mli
···11+(** Base encoding and utility tests. *)
22+13val suite : string * unit Alcotest.test_case list
44+(** [suite] is the Alcotest test suite for base encoding operations. *)
+3
tests/test_cipher.mli
···11+(** Symmetric cipher tests. *)
22+13val suite : string * unit Alcotest.test_case list
44+(** [suite] is the Alcotest test suite for symmetric ciphers. *)
+3
tests/test_dh.mli
···11+(** Diffie-Hellman key exchange tests. *)
22+13val suite : string * unit Alcotest.test_case list
44+(** [suite] is the Alcotest test suite for Diffie-Hellman operations. *)
+3
tests/test_dsa.mli
···11+(** DSA signature tests. *)
22+13val suite : string * unit Alcotest.test_case list
44+(** [suite] is the Alcotest test suite for DSA signature operations. *)
+15-13
tests/test_ec_wycheproof.ml
···8787 end
8888 | _ -> assert false)
89899090-let interpret_test ~tcId curve { public_key; raw_private_key; expected } () =
9090+let interpret_test ~tc_id curve { public_key; raw_private_key; expected } () =
9191 match perform_key_exchange curve ~public_key ~raw_private_key with
9292 | Ok got -> Alcotest.check hex __LOC__ expected got
9393 | Error err ->
9494- Printf.ksprintf (fun s -> Alcotest.fail s) "While parsing %d: %s" tcId err
9494+ Printf.ksprintf
9595+ (fun s -> Alcotest.fail s)
9696+ "While parsing %d: %s" tc_id err
95979698type invalid_test = { public : string; private_ : string }
9799···111113 let ignored_flags = [ "UnnamedCurve" ] in
112114 let curve_compression_test curve =
113115 let curves = [ "secp256r1"; "secp384r1"; "secp521r1" ] in
114114- test.tcId = 2 && List.exists (fun x -> String.equal x curve) curves
116116+ test.tc_id = 2 && List.exists (fun x -> String.equal x curve) curves
115117 in
116118 match test.result with
117119 | _ when has_ignored_flag test ~ignored_flags -> Ok Skip
···128130 Ok (Test { public_key; raw_private_key; expected = test.shared })
129131130132let to_ecdh_tests curve (x : ecdh_test) =
131131- let name = Printf.sprintf "%d - %s" x.tcId x.comment in
133133+ let name = Printf.sprintf "%d - %s" x.tc_id x.comment in
132134 match make_ecdh_test curve x with
133133- | Ok (Test t) -> [ (name, `Quick, interpret_test ~tcId:x.tcId curve t) ]
135135+ | Ok (Test t) -> [ (name, `Quick, interpret_test ~tc_id:x.tc_id curve t) ]
134136 | Ok (Invalid_test t) -> [ (name, `Quick, interpret_invalid_test curve t) ]
135137 | Ok Skip -> []
136136- | Error e -> Printf.ksprintf failwith "While parsing %d: %s" x.tcId e
138138+ | Error e -> Printf.ksprintf failwith "While parsing %d: %s" x.tc_id e
137139138140let ecdh_tests file =
139141 let data = load_file_exn file in
140142 let groups : ecdh_test_group list =
141141- List.map ecdh_test_group_exn data.testGroups
143143+ List.map ecdh_test_group_exn data.test_groups
142144 in
143145 List.concat_map
144146 (fun (group : ecdh_test_group) ->
···146148 groups
147149148150let make_ecdsa_test curve key hash (tst : dsa_test) =
149149- let name = Printf.sprintf "%d - %s" tst.tcId tst.comment in
151151+ let name = Printf.sprintf "%d - %s" tst.tc_id tst.comment in
150152 let size = len curve in
151153 let msg =
152154 let dgst =
···200202let ecdsa_tests file =
201203 let data = load_file_exn file in
202204 let groups : ecdsa_test_group list =
203203- List.map ecdsa_test_group_exn data.testGroups
205205+ List.map ecdsa_test_group_exn data.test_groups
204206 in
205207 List.concat_map to_ecdsa_tests groups
206208207209let to_x25519_test (x : ecdh_test) =
208208- let name = Printf.sprintf "%d - %s" x.tcId x.comment
210210+ let name = Printf.sprintf "%d - %s" x.tc_id x.comment
209211 and priv =
210212 match X25519.secret_of_octets x.private_ with
211213 | Ok (p, _) -> p
···243245let x25519_tests =
244246 let data = load_file_exn "x25519_test.json" in
245247 let groups : ecdh_test_group list =
246246- List.map ecdh_test_group_exn data.testGroups
248248+ List.map ecdh_test_group_exn data.test_groups
247249 in
248250 List.concat_map
249251 (fun (group : ecdh_test_group) -> List.map to_x25519_test group.tests)
250252 groups
251253252254let to_ed25519_test (priv, pub) (x : dsa_test) =
253253- let name = Printf.sprintf "%d - %s" x.tcId x.comment in
255255+ let name = Printf.sprintf "%d - %s" x.tc_id x.comment in
254256 match x.result with
255257 | Invalid ->
256258 let f () =
···280282let ed25519_tests =
281283 let data = load_file_exn "eddsa_test.json" in
282284 let groups : eddsa_test_group list =
283283- List.map eddsa_test_group_exn data.testGroups
285285+ List.map eddsa_test_group_exn data.test_groups
284286 in
285287 List.concat_map
286288 (fun (group : eddsa_test_group) ->
+3
tests/test_numeric.mli
···11+(** Numeric and big-integer utility tests. *)
22+13val suite : string * unit Alcotest.test_case list
44+(** [suite] is the Alcotest test suite for numeric utilities. *)
+4-4
tests/test_rsa.ml
···4343 (* expected since there's no multiplicative inverse of e with p and q (e is not coprime to q-1) *)
4444 | Ok _ -> Alcotest.fail "expected an error")
45454646-let rsa_priv_of_primes_regression_62 =
4646+let priv_of_primes_regr_62 =
4747 Alcotest.test_case "priv_of_primes regression #62" `Quick (fun () ->
4848 (* reported in https://github.com/mirage/mirage-crypto/issues/62 *)
4949 let e = Z.of_string "65537"
···6363 | Ok priv ->
6464 if not (Z.equal d priv.Rsa.d) then Alcotest.fail "d is not equal")
65656666-let rsa_priv_of_primes_regression_openssl =
6666+let priv_of_primes_regr_openssl =
6767 Alcotest.test_case "priv_of_primes regression openssl" `Quick (fun () ->
6868 let e = Z.of_string "65537"
6969 and d =
···400400 (* RSA-regression *)
401401 [
402402 rsa_priv_of_primes_regression;
403403- rsa_priv_of_primes_regression_62;
404404- rsa_priv_of_primes_regression_openssl;
403403+ priv_of_primes_regr_62;
404404+ priv_of_primes_regr_openssl;
405405 ];
406406 ] )
+3
tests/test_rsa.mli
···11+(** RSA encryption and signature tests. *)
22+13val suite : string * unit Alcotest.test_case list
44+(** [suite] is the Alcotest test suite for RSA operations. *)