diff options
Diffstat (limited to 'libavutil/tests/aes.c')
-rw-r--r-- | libavutil/tests/aes.c | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/libavutil/tests/aes.c b/libavutil/tests/aes.c index 49ca553e0a..1291ad6633 100644 --- a/libavutil/tests/aes.c +++ b/libavutil/tests/aes.c @@ -1,32 +1,33 @@ /* - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/aes.c" - +// LCOV_EXCL_START #include <string.h> +#include "libavutil/aes.h" #include "libavutil/lfg.h" #include "libavutil/log.h" +#include "libavutil/mem.h" int main(int argc, char **argv) { int i, j; - AVAES b; + struct AVAES *b; static const uint8_t rkey[2][16] = { { 0 }, { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, @@ -43,14 +44,20 @@ int main(int argc, char **argv) { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 } }; - uint8_t pt[16], temp[16]; + uint8_t pt[32]; + uint8_t temp[32]; + uint8_t iv[2][16]; int err = 0; + b = av_aes_alloc(); + if (!b) + return 1; + av_log_set_level(AV_LOG_DEBUG); for (i = 0; i < 2; i++) { - av_aes_init(&b, rkey[i], 128, 1); - av_aes_crypt(&b, temp, rct[i], 1, NULL, 1); + av_aes_init(b, rkey[i], 128, 1); + av_aes_crypt(b, temp, rct[i], 1, NULL, 1); for (j = 0; j < 16; j++) { if (rpt[i][j] != temp[j]) { av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", @@ -59,25 +66,42 @@ int main(int argc, char **argv) } } } + av_free(b); if (argc > 1 && !strcmp(argv[1], "-t")) { - AVAES ae, ad; + struct AVAES *ae, *ad; AVLFG prng; - av_aes_init(&ae, "PI=3.141592654..", 128, 0); - av_aes_init(&ad, "PI=3.141592654..", 128, 1); + ae = av_aes_alloc(); + ad = av_aes_alloc(); + + if (!ae || !ad) { + av_free(ae); + av_free(ad); + return 1; + } + + av_aes_init(ae, (const uint8_t*)"PI=3.141592654..", 128, 0); + av_aes_init(ad, (const uint8_t*)"PI=3.141592654..", 128, 1); av_lfg_init(&prng, 1); for (i = 0; i < 10000; i++) { - for (j = 0; j < 16; j++) + for (j = 0; j < 32; j++) pt[j] = av_lfg_get(&prng); + for (j = 0; j < 16; j++) + iv[0][j] = iv[1][j] = av_lfg_get(&prng); { START_TIMER; - av_aes_crypt(&ae, temp, pt, 1, NULL, 0); + av_aes_crypt(ae, temp, pt, 2, iv[0], 0); + if (!(i & (i - 1))) + av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", + temp[0], temp[5], temp[10], temp[15]); + av_aes_crypt(ad, temp, temp, 2, iv[1], 1); + av_aes_crypt(ae, temp, pt, 2, NULL, 0); if (!(i & (i - 1))) av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]); - av_aes_crypt(&ad, temp, temp, 1, NULL, 1); + av_aes_crypt(ad, temp, temp, 2, NULL, 1); STOP_TIMER("aes"); } for (j = 0; j < 16; j++) { @@ -87,6 +111,9 @@ int main(int argc, char **argv) } } } + av_free(ae); + av_free(ad); } return err; } +// LCOV_EXCL_STOP |