1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-09-16 08:36:51 +02:00

avutil/tests/aes_ctr: extend the test to cover payloads smaller than a block

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2025-09-09 11:32:17 -03:00
parent 335ba4a649
commit 799c133273

View File

@@ -19,18 +19,23 @@
#include <string.h>
#include "libavutil/random_seed.h"
#include "libavutil/lfg.h"
#include "libavutil/log.h"
#include "libavutil/mem_internal.h"
#include "libavutil/aes_ctr.h"
static const DECLARE_ALIGNED(8, uint8_t, plain)[] = {
0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f,
0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f,
0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f,
0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f
};
static const DECLARE_ALIGNED(8, uint8_t, encrypted)[] = {
0x95, 0xcd, 0x9a, 0x8a, 0x83, 0xa2, 0x1a, 0x84, 0x92, 0xed,
0xd6, 0xf2, 0x57, 0x2f, 0x61, 0x98, 0xbc, 0x20, 0x98, 0xee
0xd6, 0xf2, 0x57, 0x2f, 0x61, 0x98, 0xbc, 0x20, 0x98, 0xee,
0x6c, 0xed, 0x53, 0xae, 0x2f, 0xc4, 0x18, 0x7c, 0xeb, 0x62,
0xbb, 0x3a, 0x71, 0x24, 0x22, 0x8c, 0xd9, 0xfa, 0xee, 0x10
};
static const DECLARE_ALIGNED(8, uint8_t, fixed_iv)[] = {
@@ -44,14 +49,17 @@ static const DECLARE_ALIGNED(8, uint8_t, fixed_key)[] = {
static DECLARE_ALIGNED(8, uint32_t, key)[4];
static DECLARE_ALIGNED(8, uint8_t, tmp)[20];
static DECLARE_ALIGNED(8, uint8_t, tmp)[40];
int main (void)
{
int ret = 1;
AVLFG lfg;
struct AVAESCTR *ae, *ad;
const uint8_t *iv, *k;
av_lfg_init(&lfg, av_get_random_seed());
for (int i = 0; i < 2; i++) {
ae = av_aes_ctr_alloc();
ad = av_aes_ctr_alloc();
@@ -85,13 +93,30 @@ int main (void)
iv = av_aes_ctr_get_iv(ae);
av_aes_ctr_set_full_iv(ad, iv);
av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp));
uint8_t *dst = tmp;
const uint8_t *src = plain;
int left = sizeof(plain);
while (left > 0) {
int count = (av_lfg_get(&lfg) % left) + 1;
av_aes_ctr_crypt(ae, dst, src, count);
dst += count;
src += count;
left -= count;
}
if (i && memcmp(tmp, encrypted, sizeof(tmp)) != 0) {
av_log(NULL, AV_LOG_ERROR, "test failed\n");
goto ERROR;
}
av_aes_ctr_crypt(ad, tmp, tmp, sizeof(tmp));
dst = tmp;
left = sizeof(plain);
while (left > 0) {
int count = (av_lfg_get(&lfg) % left) + 1;
av_aes_ctr_crypt(ad, dst, dst, count);
dst += count;
left -= count;
}
if (memcmp(tmp, plain, sizeof(tmp)) != 0){
av_log(NULL, AV_LOG_ERROR, "test failed\n");
goto ERROR;