#### mirage-crypto-pk

## Conversion to and from Cstruct.t

`of_cstruct_be ~bits cs`

interprets the bit pattern of `cs`

as a `t`

in big-endian.

If `~bits`

is not given, the operation considers the entire `cs`

, otherwise the initial `min ~bits (bit-length cs)`

bits of `cs`

.

Assuming `n`

is the number of bits to extract, the `n`

-bit in `cs`

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`cs`

.

`to_cstruct_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.

`into_cstruct_be t cs`

writes the big-endian representation of `t`

into `cs`

. It behaves like `to_cstruct_be`

, with `~size`

spanning the entire `cs`

.

## 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.