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