¿AES_cbc_encrypt agrega relleno?
Considere el siguiente fragmento de código C ++:
#include <iostream>
#include <openssl/aes.h>
#define AES_KEY_LENGTH 32
using namespace std;
int main()
{
AES_KEY encryption_key;
AES_KEY decryption_key;
unsigned char key[AES_KEY_LENGTH] = {'t', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't'};
unsigned char iv[AES_BLOCK_SIZE] = {'t', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't', 't', 'e', 's', 't'};
unsigned char iv_enc[AES_BLOCK_SIZE];
unsigned char iv_dec[AES_BLOCK_SIZE];
memcpy(iv_enc, iv, AES_BLOCK_SIZE);
memcpy(iv_dec, iv, AES_BLOCK_SIZE);
AES_set_encrypt_key(key, AES_KEY_LENGTH * 8, &(encryption_key));
AES_set_decrypt_key(key, AES_KEY_LENGTH * 8, &(decryption_key));
char message[] = "Attack at dawn! Attack.";
unsigned char * encryption_output = new unsigned char[32];
encryption_output[31] = 3;
AES_cbc_encrypt((unsigned char *) message, encryption_output, sizeof(message), &encryption_key, iv_enc, AES_ENCRYPT);
unsigned char * decryption_output = new unsigned char[32];
AES_cbc_encrypt(encryption_output, decryption_output, 32, &decryption_key, iv_dec, AES_DECRYPT);
}
Lo que hago aquí es cifrar y luego descifrar un mensaje usando la biblioteca openssl aes. Lo que me preocupa es la longitud encriptación_salida. Hasta donde tengo entendido, dado que AES cifra en bloques de tamaño AES_BLOCK_SIZE (también conocido como 16 bytes), el número de bytes de salida debe ser igual al tamaño del mensaje, redondeado al múltiplo más cercano de AES_BLOCK_SIZE. ¿Es esto correcto? En particular, ¿qué sucede si extiendo el mensaje para que tenga exactamente 32 bytes de longitud? ¿Esto todavía funcionará, o se agregarán 16 bytes de relleno vacíos, causando una falla de segmentación al intentar escribir bytes 32 a 47 en encryption_output?