package bls12-381-unix

  1. Overview
  2. Docs
UNIX version of BLS12-381 primitives implementing the virtual package bls12-381 with blst backend

Install

Dune Dependency

Authors

Maintainers

Sources

ocaml-bls12-381-2.0.1.tar.bz2
md5=493da0d50891299fb9577e6855653dca
sha512=994ac11cb76b0d83592cfb6b7a6d6f488a5d9c525d9bc1ccd81e797ee56c0e0b9a00d889118b4e5a01282d332d63d94d32ccbb6e063a28c1c53fecbea23dbef6

doc/src/bls12-381-unix/poseidon128.ml.html

Source file poseidon128.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
module Stubs = struct
  type ctxt

  external allocate_ctxt : unit -> ctxt = "caml_poseidon128_allocate_ctxt_stubs"

  external constants_init :
    Fr.t array -> Fr.t array array -> int -> int -> int -> int
    = "caml_poseidon128_constants_init_stubs"

  external init : ctxt -> Fr.t -> Fr.t -> Fr.t -> unit
    = "caml_poseidon128_init_stubs"

  external apply_perm : ctxt -> unit = "caml_poseidon128_apply_perm_stubs"

  external get_state : Fr.t -> Fr.t -> Fr.t -> ctxt -> unit
    = "caml_poseidon128_get_state_stubs"
end

type ctxt = Stubs.ctxt

let constants_init ark mds =
  let ark_len = Array.length ark in
  let mds_nb_rows = Array.length mds in
  assert (mds_nb_rows > 0) ;
  let mds_nb_cols = Array.length mds.(0) in
  assert (0 = Stubs.constants_init ark mds ark_len mds_nb_rows mds_nb_cols)

let init s =
  let ctxt = Stubs.allocate_ctxt () in
  Stubs.init ctxt s.(0) s.(1) s.(2) ;
  ctxt

let apply_perm ctxt = Stubs.apply_perm ctxt

let get ctxt =
  let a = Fr.Stubs.mallocate_fr () in
  let b = Fr.Stubs.mallocate_fr () in
  let c = Fr.Stubs.mallocate_fr () in
  Stubs.get_state a b c ctxt ;
  [| a; b; c |]
OCaml

Innovation. Community. Security.