Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCM mode: decrypting an empty ciphertext fails #168

Open
emillon opened this issue Sep 25, 2019 · 0 comments
Open

CCM mode: decrypting an empty ciphertext fails #168

emillon opened this issue Sep 25, 2019 · 0 comments

Comments

@emillon
Copy link

emillon commented Sep 25, 2019

Hi,

It looks like CCM decryption does not correctly handle the case when the ciphertext is empty. This happens when there is AAD and when there is not.

In the following example, I would expect Some Cstruct.empty to be returned:

let () =
  let key =
    Cstruct.of_hex "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"
    |> Nocrypto.Cipher_block.AES.CCM.of_secret ~maclen:16
  in
  let nonce = Cstruct.of_hex "00 01 02 03 04 05 06 07" in
  let adata = Cstruct.of_string "hello" in
  let recovered =
    Cstruct.empty
    |> Nocrypto.Cipher_block.AES.CCM.encrypt ~key ~nonce ~adata
    |> Nocrypto.Cipher_block.AES.CCM.decrypt ~key ~nonce ~adata
  in
  match recovered with
  | Some cs -> Cstruct.hexdump cs
  | None -> print_endline "None"

Output:

None

Thanks!

@emillon emillon changed the title CCM mode: CCM mode: decrypting an empty ciphertext fails Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant