mirage-crypto

Simple symmetric cryptography for the modern age
IN THIS PACKAGE
Module type Mirage_crypto . Cipher_block . S . CBC
type key
val of_secret : Cstruct.t -> key

Construct the encryption key corresponding to secret.

  • raises Invalid_argument

    if the length of secret is not in key_sizes.

val key_sizes : int array

Key sizes allowed with this cipher.

val block_size : int

The size of a single block.

val encrypt : key:key -> iv:Cstruct.t -> Cstruct.t -> Cstruct.t

encrypt ~key ~iv msg is msg encrypted under key, using iv as the CBC initialization vector.

  • raises Invalid_argument

    if iv is not block_size, or msg is not k * block_size long.

val decrypt : key:key -> iv:Cstruct.t -> Cstruct.t -> Cstruct.t

decrypt ~key ~iv msg is the inverse of encrypt.

  • raises Invalid_argument

    if iv is not block_size, or msg is not k * block_size long.

val next_iv : iv:Cstruct.t -> Cstruct.t -> Cstruct.t

next_iv ~iv ciphertext is the first iv following the encryption that used iv to produce ciphertext.

For protocols which perform inter-message chaining, this is the iv for the next message.

It is either iv, when len ciphertext = 0, or the last block of ciphertext. Note that

encrypt ~iv msg1 || encrypt ~iv:(next_iv ~iv (encrypt ~iv msg1)) msg2
== encrypt ~iv (msg1 || msg2)
  • raises Invalid_argument

    if the length of iv is not block_size, or the length of ciphertext is not k * block_size for some k.