Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Marco

Pages: [1]
1
Encryption / AES CBC/PKCS7 encryption of empty msg fails
« on: December 19, 2017, 05:51:49 AM »
Following C code:

CkCrypt2 c;
c.UnlockComponent(CHILKAT_CRYPT_UNLOCK);
c.put_CryptAlgorithm("aes");
c.put_CipherMode("cbc");
c.put_KeyLength(256);   // key length in bits
c.put_PaddingScheme(0);   // PKCS7 padding

// set key
CkByteData _key;
_key.append2(&key[0], key.size());
c.put_SecretKey(_key);

// set IV
CkByteData _iv;
std::vector<std::uint8_t> rnd_iv(16);
crypt::random::rand(rnd_iv, 16);
_iv.append2(&rnd_iv[0], 16);
c.put_IV(_iv);

// encrypt data
CkByteData _cipher, _plain;
if (plain.size()) {
  _plain.append2(&plain[0], plain.size());
}
if (!c.EncryptBytes(_plain, _cipher)) {
  return false;
}

Problem is, when plain (and _plain) has size zero, returned _cipher has size zero, too.
So it's not possible to encrypt empty messages.
Expected: Padding must pad the first block with 16 x 0x10, XOR it with the IV and return an encrypted 16 byte block.

Is something wrong here?

Pages: [1]