mirleft / ocaml-nocrypto

OCaml cryptographic library
ISC License
111 stars 53 forks source link

CCM mode: assertion failure when a short nonce is used #167

Open emillon opened 5 years ago

emillon commented 5 years ago

Hi,

When encrypting in CCM mode, if the nonce is too short, it triggers an assertion failure.

In contrast, the corresponding error message when decrypting is a nicer invalid_arg "CCM: nonce length %d" nsize.

let () =
  let key =
    Nocrypto.Cipher_block.AES.CCM.of_secret ~maclen:16 (Cstruct.create 16)
  in
  let nonce = Cstruct.empty in
  ignore (Nocrypto.Cipher_block.AES.CCM.encrypt ~key ~nonce Cstruct.empty)

Output:

Fatal error: exception "Assert_failure src/ccm.ml:8:2"

Thanks!