Skip to content

Crypto.AES.CCM Documentation Lacks IV Truncation Information

Hi,

Crypto.AES.CCM currently raises an exception if a too-short (less than 7-octets) IV is set using state->set_iv().

According to https://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/Nettle/BlockCipher/CTR/State/set_iv.html, "iv must have the length reported by iv_size().".

However, a too-long IV set using set_iv() does not raise an exception, and is instead simply truncated to 13-octets:

   if (iv_len < 7) {
     Pike_error("Too short nonce for CCM. Must be at least 7 bytes.\n");
   }
   if (THIS->nonce) {
     free_string(THIS->nonce);
     THIS->nonce = NULL;
   }
   if (iv_len > 13) {
     THIS->nonce = string_slice(iv, 0, 12);
     iv_len = 13;
   } else {
     add_ref(THIS->nonce = iv);
   }

As far as I can tell, this truncation is undocumented, and personally, I see no reason for it to be truncated over an exception being raised.

Can the documentation be changed and/or an exception be raised instead?

Thank you.