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
18 18
19#include <string.h>19#include <string.h>
20 20
21#include "libavutil/random_seed.h"
21#include "libavutil/log.h"22#include "libavutil/log.h"
22#include "libavutil/mem_internal.h"23#include "libavutil/mem_internal.h"
23#include "libavutil/aes_ctr.h"24#include "libavutil/aes_ctr.h"
@@ -36,13 +37,20 @@ static const DECLARE_ALIGNED(8, uint8_t, fixed_iv)[] = { · 12 unmodified lines
36 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef37 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef
37};38};
38 39
40static 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
45static DECLARE_ALIGNED(8, uint32_t, key)[4];
46
39static DECLARE_ALIGNED(8, uint8_t, tmp)[20];47static DECLARE_ALIGNED(8, uint8_t, tmp)[20];
40 48
41int main (void)49int main (void)
42{50{
43 int ret = 1;51 int ret = 1;
44 struct AVAESCTR *ae, *ad;52 struct AVAESCTR *ae, *ad;
45 const uint8_t *iv;53 const uint8_t *iv, *k;
46 54
47 for (int i = 0; i < 2; i++) {55 for (int i = 0; i < 2; i++) {
48 ae = av_aes_ctr_alloc();56 ae = av_aes_ctr_alloc();
@@ -51,10 +59,23 @@ int main (void) · 2 unmodified lines
51 if (!ae || !ad)59 if (!ae || !ad)
52 goto ERROR;60 goto ERROR;
53 61
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)
55 goto ERROR;76 goto ERROR;
56 77
57 if (av_aes_ctr_init(ad, (const uint8_t*)"0123456789abcdef") < 0)78 if (av_aes_ctr_init(ad, k) < 0)
58 goto ERROR;79 goto ERROR;
59 80
60 if (i)81 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