package mirage-crypto-pk

  1. Overview
  2. Docs

Z Convert Z to big endian string and generate random Z values.

Conversion to and from string

val of_octets_be : ?bits:int -> string -> Z.t

of_octets_be ~bits buf interprets the bit pattern of buf as a t in big-endian.

If ~bits is not given, the operation considers the entire buf, otherwise the initial min ~bits (bit-length buf) bits of buf.

Assuming n is the number of bits to extract, the n-bit in buf is always the least significant bit of the result. Therefore:

  • if the bit size k of t is larger than n, k - n most significant bits in the result are 0; and
  • if k is smaller than n, the result contains k last of the n first bits of buf.
val to_octets_be : ?size:int -> Z.t -> string

to_octets_be ~size t is the big-endian representation of t.

If ~size is not given, it defaults to the minimal number of bytes needed to represent t, which is bits t / 8 rounded up.

The least-significant bit of t is always the last bit in the result. If the size is larger than needed, the output is padded with zero bits. If it is smaller, the high bits in t are dropped.

val into_octets_be : Z.t -> bytes -> unit

into_octets_be t buf writes the big-endian representation of t into buf. It behaves like to_octets_be, with ~size spanning the entire buf.

Random generation

val gen : ?g:Mirage_crypto_rng.g -> Z.t -> Z.t

gen ~g n picks a value in the interval [0, n - 1] uniformly at random.

val gen_r : ?g:Mirage_crypto_rng.g -> Z.t -> Z.t -> Z.t

gen_r ~g low high picks a value from the interval [low, high - 1] uniformly at random.

OCaml

Innovation. Community. Security.