upstream: https://github.com/mirage/mirage-crypto

fix(lint): resolve E205 in gen_tables.ml, replace open Format with Fmt

+15 -19
+15 -19
ec/gen_tables/gen_tables.ml
··· 1 - open Format 2 - 3 let print_header name = 4 - printf 5 {| 6 /* 7 Pre-computed %d-bit multiples of the generator point G for the curve %s, ··· 12 Sys.word_size name Sys.argv.(0) 13 14 let pp_array elem_fmt fmt arr = 15 - let fout = fprintf fmt in 16 let len = Array.length arr in 17 fout "@[<2>{@\n"; 18 for i = 0 to len - 1 do 19 elem_fmt fmt arr.(i); 20 - if i < len - 1 then printf ",@ " else printf "" 21 done; 22 fout "@]@,}" 23 ··· 29 (* Truncate at the beginning (little-endian) *) 30 let bytes = Bytes.unsafe_of_string str in 31 (* let bytes = rev_str_bytes str in *) 32 - fprintf fmt "@[<2>{@\n"; 33 for i = 0 to limbs - 1 do 34 let index = i * (wordsize / 8) in 35 (if wordsize = 64 then 36 let w = Bytes.get_int64_le bytes index in 37 - fprintf fmt "%#016Lx" w 38 else 39 let w = Bytes.get_int32_le bytes index in 40 - fprintf fmt "%#08lx" w); 41 - if i < limbs - 1 then printf ",@ " else printf "" 42 done; 43 - fprintf fmt "@]@,}" 44 45 let check_shape tables = 46 let fe_len = String.length tables.(0).(0).(0) in ··· 58 59 let print_tables tables ~wordsize = 60 let fe_len = String.length tables.(0).(0).(0) in 61 - printf "@[<2>static WORD generator_table[%d][15][3][LIMBS] = @," (fe_len * 2); 62 pp_array 63 (pp_array (pp_array (pp_string_words ~wordsize))) 64 - std_formatter tables; 65 - printf "@];@," 66 67 let print_toplevel name wordsize (module P : Crypto_ec.Dh_dsa) = 68 let tables = P.Dsa.Precompute.generator_tables () in ··· 70 check_shape tables; 71 print_header name; 72 if wordsize = 64 then 73 - printf 74 "@[<v>#ifndef ARCH_64BIT@,\ 75 #error \"Cannot use 64-bit tables on a 32-bit architecture\"@,\ 76 #endif@,\ 77 @]" 78 else 79 - printf 80 "@[<v>#ifdef ARCH_64BIT@,\ 81 #error \"Cannot use 32-bit tables on a 64-bit architecture\"@,\ 82 #endif@,\ ··· 92 ] 93 94 let usage () = 95 - printf "Usage: gen_tables [%a] [64 | 32]@." 96 - (pp_print_list 97 - ~pp_sep:(fun fmt () -> pp_print_string fmt " | ") 98 - pp_print_string) 99 (List.map fst curves) 100 101 let go =
··· 1 let print_header name = 2 + Fmt.pr 3 {| 4 /* 5 Pre-computed %d-bit multiples of the generator point G for the curve %s, ··· 10 Sys.word_size name Sys.argv.(0) 11 12 let pp_array elem_fmt fmt arr = 13 + let fout = Fmt.pf fmt in 14 let len = Array.length arr in 15 fout "@[<2>{@\n"; 16 for i = 0 to len - 1 do 17 elem_fmt fmt arr.(i); 18 + if i < len - 1 then Fmt.pr ",@ " else Fmt.pr "" 19 done; 20 fout "@]@,}" 21 ··· 27 (* Truncate at the beginning (little-endian) *) 28 let bytes = Bytes.unsafe_of_string str in 29 (* let bytes = rev_str_bytes str in *) 30 + Fmt.pf fmt "@[<2>{@\n"; 31 for i = 0 to limbs - 1 do 32 let index = i * (wordsize / 8) in 33 (if wordsize = 64 then 34 let w = Bytes.get_int64_le bytes index in 35 + Fmt.pf fmt "%#016Lx" w 36 else 37 let w = Bytes.get_int32_le bytes index in 38 + Fmt.pf fmt "%#08lx" w); 39 + if i < limbs - 1 then Fmt.pr ",@ " else Fmt.pr "" 40 done; 41 + Fmt.pf fmt "@]@,}" 42 43 let check_shape tables = 44 let fe_len = String.length tables.(0).(0).(0) in ··· 56 57 let print_tables tables ~wordsize = 58 let fe_len = String.length tables.(0).(0).(0) in 59 + Fmt.pr "@[<2>static WORD generator_table[%d][15][3][LIMBS] = @," (fe_len * 2); 60 pp_array 61 (pp_array (pp_array (pp_string_words ~wordsize))) 62 + Format.std_formatter tables; 63 + Fmt.pr "@];@," 64 65 let print_toplevel name wordsize (module P : Crypto_ec.Dh_dsa) = 66 let tables = P.Dsa.Precompute.generator_tables () in ··· 68 check_shape tables; 69 print_header name; 70 if wordsize = 64 then 71 + Fmt.pr 72 "@[<v>#ifndef ARCH_64BIT@,\ 73 #error \"Cannot use 64-bit tables on a 32-bit architecture\"@,\ 74 #endif@,\ 75 @]" 76 else 77 + Fmt.pr 78 "@[<v>#ifdef ARCH_64BIT@,\ 79 #error \"Cannot use 32-bit tables on a 64-bit architecture\"@,\ 80 #endif@,\ ··· 90 ] 91 92 let usage () = 93 + Fmt.pr "Usage: gen_tables [%a] [64 | 32]@." 94 + (Fmt.list ~sep:(Fmt.any " | ") Fmt.string) 95 (List.map fst curves) 96 97 let go =