History

avutil/tests/aes_ctr: also randomize the encryption key

And not just the IV.

James Almer committed 1 year ago

Commit 2daaafa1 parent 462d35d1 file · +24 −3Browse files

Unified · Split

libavutil/tests/aes_ctr.c+24−3
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818
1919 #include <string.h>
2020
21+#include "libavutil/random_seed.h"
2122 #include "libavutil/log.h"
2223 #include "libavutil/mem_internal.h"
2324 #include "libavutil/aes_ctr.h"
@@ -36,13 +37,20 @@ static const DECLARE_ALIGNED(8, uint8_t, fixed_iv)[] = { · 12 unmodified lines
3637 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef
3738 };
3839
40+static const DECLARE_ALIGNED(8, uint8_t, fixed_key)[] = {
41+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
42+ 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
43+};
44+
45+static DECLARE_ALIGNED(8, uint32_t, key)[4];
46+
3947 static DECLARE_ALIGNED(8, uint8_t, tmp)[20];
4048
4149 int main (void)
4250 {
4351 int ret = 1;
4452 struct AVAESCTR *ae, *ad;
45− const uint8_t *iv;
53+ const uint8_t *iv, *k;
4654
4755 for (int i = 0; i < 2; i++) {
4856 ae = av_aes_ctr_alloc();
@@ -51,10 +59,23 @@ int main (void) · 2 unmodified lines
5159 if (!ae || !ad)
5260 goto ERROR;
5361
54− if (av_aes_ctr_init(ae, (const uint8_t*)"0123456789abcdef") < 0)
62+ if (i)
63+ k = fixed_key;
64+ else {
65+ // Note: av_random_bytes() should be used in a real world scenario,
66+ // but since that function can fail, av_get_random_seed() is used
67+ // here for the purpose of this test, as its output is sufficient.
68+ key[0] = av_get_random_seed();
69+ key[1] = av_get_random_seed();
70+ key[2] = av_get_random_seed();
71+ key[3] = av_get_random_seed();
72+ k = (uint8_t *)key;
73+ }
74+
75+ if (av_aes_ctr_init(ae, k) < 0)
5576 goto ERROR;
5677
57− if (av_aes_ctr_init(ad, (const uint8_t*)"0123456789abcdef") < 0)
78+ if (av_aes_ctr_init(ad, k) < 0)
5879 goto ERROR;
5980
6081 if (i)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t