named-data-iot/ndn-lite

ndn_gen_encrypted_payload used_size differs from ndn_probe_encrypted_payload_length

Opened this issue · 1 comments

In ndn_gen_encrypted_payload, the used_size output parameter is calculated as:

*used_size = 0;
// probe the length of result
*used_size += encoder_probe_block_size(TLV_AC_AES_IV, NDN_AES_BLOCK_SIZE);
*used_size += encoder_probe_block_size(TLV_AC_KEYID, 4);
*used_size += encoder_probe_block_size(TLV_AC_ENCRYPTED_PAYLOAD, ndn_aes_probe_padding_size(input_size));

However, ndn_probe_encrypted_payload_length calculates its result differently:

return encoder_probe_block_size(TLV_AC_AES_IV, NDN_AES_BLOCK_SIZE)
+ encoder_probe_block_size(TLV_AC_KEYID, 4)
+ encoder_probe_block_size(TLV_AC_ENCRYPTED_PAYLOAD, ndn_aes_probe_padding_size(input_size) + NDN_AES_BLOCK_SIZE);

They differ in + NDN_AES_BLOCK_SIZE on the last line.
Please explain why there's this difference.

I don't know the detail of this piece @Zhiyi-Zhang . But I suppose ndn_gen_encrypted_payload doesn't calculate used_size correctly.