package octez-libs
A package that contains multiple base libraries used by the Octez suite
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-18.1.tar.gz
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a
doc/src/octez-libs.mec/marvellous.ml.html
Source file marvellous.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
module type PARAMETERS = sig (** The state size *) val width : int (** The number of rounds *) val rounds : int (** The round constants, given in decimal representation *) val round_constants : string array (** The MDS matrix, given in decimal representation *) val mds_matrix : string array array val alpha : Z.t val alphainv : Z.t end module Make (Param : PARAMETERS) (Scalar : Bls12_381.Ff_sig.PRIME) = struct open Param (* Verify the constants are consistent *) let () = assert (Array.length mds_matrix = width) ; assert (Array.for_all (fun line -> Array.length line = width) mds_matrix) let mds_matrix = Array.map (Array.map Scalar.of_string) mds_matrix let round_constants = Array.map Scalar.of_string round_constants (* Initialize only once an array for the MDS matrix multiplication *) let res = Array.make width Scalar.zero type state = {mutable i_round_key : int; state : Scalar.t array} let init state = if Array.length state != width then failwith (Printf.sprintf "State length is %d, but the width of the strategy is %d" (Array.length state) width) else {i_round_key = 0; state = Array.copy state} let get_next_round_key s = let v = round_constants.(s.i_round_key) in s.i_round_key <- s.i_round_key + 1 ; v (* Functions prefixed with apply_ are modifying the state given in parameters *) let apply_round_key s = let state = s.state in for i = 0 to Array.length state - 1 do state.(i) <- Scalar.(get_next_round_key s + state.(i)) done let apply_nonlinear_alpha s = let s = s.state in for i = 0 to Array.length s - 1 do s.(i) <- Scalar.pow s.(i) alpha done let apply_nonlinear_alphainv s = let s = s.state in for i = 0 to Array.length s - 1 do s.(i) <- Scalar.pow s.(i) alphainv done let apply_linear m v = let v = v.state in for j = 0 to width - 1 do for k = 0 to width - 1 do res.(k) <- Scalar.(res.(k) + (m.(k).(j) * v.(j))) done done ; for j = 0 to width - 1 do v.(j) <- res.(j) ; res.(j) <- Scalar.zero done let apply_round s = apply_nonlinear_alpha s ; apply_linear mds_matrix s ; apply_round_key s ; apply_nonlinear_alphainv s ; apply_linear mds_matrix s ; apply_round_key s let apply s = s.i_round_key <- 0 ; for _i = 0 to rounds - 1 do apply_round s done let get s = Array.copy s.state end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>