crypto_bench comparison for AES-128-ECB: lavu_aesni AES-128-ECB size: 1048576 runs: 1024 time: 0.596 +- 0.081 lavu_c AES-128-ECB size: 1048576 runs: 1024 time: 17.007 +- 2.131 crypto AES-128-ECB size: 1048576 runs: 1024 time: 0.612 +- 1.857 gcrypt AES-128-ECB size: 1048576 runs: 1024 time: 1.123 +- 0.224 tomcrypt AES-128-ECB size: 1048576 runs: 1024 time: 9.038 +- 0.790
Unified · Split
| @@ -208,6 +208,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) · 207 unmodified lines | ||
| 208 | 208 | uint8_t alog8[512]; |
| 209 | 209 | |
| 210 | 210 | a->crypt = decrypt ? aes_decrypt : aes_encrypt; |
| 211 | + if (ARCH_X86) | |
| 212 | + ff_init_aes_x86(a, decrypt); | |
| 211 | 213 | |
| 212 | 214 | if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) { |
| 213 | 215 | j = 1; |
| @@ -40,4 +40,6 @@ typedef struct AVAES { · 39 unmodified lines | ||
| 40 | 40 | void (*crypt)(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int rounds); |
| 41 | 41 | } AVAES; |
| 42 | 42 | |
| 43 | +void ff_init_aes_x86(AVAES *a, int decrypt); | |
| 44 | + | |
| 43 | 45 | #endif /* AVUTIL_AES_INTERNAL_H */ |
| @@ -1,4 +1,5 @@ | ||
| 1 | −OBJS += x86/cpu.o \ | |
| 1 | +OBJS += x86/aes_init.o \ | |
| 2 | + x86/cpu.o \ | |
| 2 | 3 | x86/fixed_dsp_init.o \ |
| 3 | 4 | x86/float_dsp_init.o \ |
| 4 | 5 | x86/imgutils_init.o \ |
| @@ -10,7 +11,8 @@ OBJS-$(CONFIG_PIXELUTILS) += x86/pixelutils_init.o \ · 5 unmodified lines | ||
| 10 | 11 | |
| 11 | 12 | EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o |
| 12 | 13 | |
| 13 | −X86ASM-OBJS += x86/cpuid.o \ | |
| 14 | +X86ASM-OBJS += x86/aes.o \ | |
| 15 | + x86/cpuid.o \ | |
| 14 | 16 | $(EMMS_OBJS__yes_) \ |
| 15 | 17 | x86/fixed_dsp.o \ |
| 16 | 18 | x86/float_dsp.o \ |
| @@ -0,0 +1,95 @@ | ||
| 1 | +;***************************************************************************** | |
| 2 | +;* Copyright (c) 2015 Rodger Combs <rodger.combs@gmail.com> | |
| 3 | +;* | |
| 4 | +;* This file is part of FFmpeg. | |
| 5 | +;* | |
| 6 | +;* FFmpeg is free software; you can redistribute it and/or | |
| 7 | +;* modify it under the terms of the GNU Lesser General Public | |
| 8 | +;* License as published by the Free Software Foundation; either | |
| 9 | +;* version 2.1 of the License, or (at your option) any later version. | |
| 10 | +;* | |
| 11 | +;* FFmpeg is distributed in the hope that it will be useful, | |
| 12 | +;* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | +;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | +;* Lesser General Public License for more details. | |
| 15 | +;* | |
| 16 | +;* You should have received a copy of the GNU Lesser General Public | |
| 17 | +;* License along with FFmpeg; if not, write to the Free Software | |
| 18 | +;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 19 | +;****************************************************************************** | |
| 20 | + | |
| 21 | +%include "x86util.asm" | |
| 22 | + | |
| 23 | +SECTION .text | |
| 24 | + | |
| 25 | +;----------------------------------------------------------------------------- | |
| 26 | +; void ff_aes_decrypt(AVAES *a, uint8_t *dst, const uint8_t *src, | |
| 27 | +; int count, uint8_t *iv, int rounds) | |
| 28 | +;----------------------------------------------------------------------------- | |
| 29 | +%macro AES_CRYPT 1 | |
| 30 | +cglobal aes_%1rypt, 6,6,2 | |
| 31 | + test r3, r3 | |
| 32 | + je .ret | |
| 33 | + shl r3d, 4 | |
| 34 | + add r5d, r5d | |
| 35 | + add r0, 0x60 | |
| 36 | + add r2, r3 | |
| 37 | + add r1, r3 | |
| 38 | + neg r3 | |
| 39 | + pxor m1, m1 | |
| 40 | + test r4, r4 | |
| 41 | + je .block | |
| 42 | + movu m1, [r4] ; iv | |
| 43 | +.block: | |
| 44 | + movu m0, [r2+r3] ; state | |
| 45 | +%ifidn %1, enc | |
| 46 | + pxor m0, m1 | |
| 47 | +%endif | |
| 48 | + pxor m0, [r0+8*r5-0x60] | |
| 49 | + cmp r5d, 24 | |
| 50 | + je .rounds12 | |
| 51 | + jl .rounds10 | |
| 52 | + aes%1 m0, [r0+0x70] | |
| 53 | + aes%1 m0, [r0+0x60] | |
| 54 | +.rounds12: | |
| 55 | + aes%1 m0, [r0+0x50] | |
| 56 | + aes%1 m0, [r0+0x40] | |
| 57 | +.rounds10: | |
| 58 | + aes%1 m0, [r0+0x30] | |
| 59 | + aes%1 m0, [r0+0x20] | |
| 60 | + aes%1 m0, [r0+0x10] | |
| 61 | + aes%1 m0, [r0+0x00] | |
| 62 | + aes%1 m0, [r0-0x10] | |
| 63 | + aes%1 m0, [r0-0x20] | |
| 64 | + aes%1 m0, [r0-0x30] | |
| 65 | + aes%1 m0, [r0-0x40] | |
| 66 | + aes%1 m0, [r0-0x50] | |
| 67 | + aes%1last m0, [r0-0x60] | |
| 68 | + test r4, r4 | |
| 69 | + je .noiv | |
| 70 | +%ifidn %1, enc | |
| 71 | + mova m1, m0 | |
| 72 | +%else | |
| 73 | + pxor m0, m1 | |
| 74 | + movu m1, [r2+r3] | |
| 75 | +%endif | |
| 76 | +.noiv: | |
| 77 | + movu [r1+r3], m0 | |
| 78 | + add r3, 16 | |
| 79 | + jl .block | |
| 80 | + test r4, r4 | |
| 81 | + je .ret | |
| 82 | +%ifidn %1, dec | |
| 83 | + movu [r4], m1 | |
| 84 | +%else | |
| 85 | + movu [r4], m0 | |
| 86 | +%endif | |
| 87 | +.ret: | |
| 88 | + REP_RET | |
| 89 | +%endmacro | |
| 90 | + | |
| 91 | +%if HAVE_AESNI_EXTERNAL | |
| 92 | +INIT_XMM aesni | |
| 93 | +AES_CRYPT enc | |
| 94 | +AES_CRYPT dec | |
| 95 | +%endif | |
| @@ -0,0 +1,36 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2015 Rodger Combs <rodger.combs@gmail.com> | |
| 3 | + * | |
| 4 | + * This file is part of FFmpeg. | |
| 5 | + * | |
| 6 | + * FFmpeg is free software; you can redistribute it and/or | |
| 7 | + * modify it under the terms of the GNU Lesser General Public | |
| 8 | + * License as published by the Free Software Foundation; either | |
| 9 | + * version 2.1 of the License, or (at your option) any later version. | |
| 10 | + * | |
| 11 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | + * Lesser General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public | |
| 17 | + * License along with FFmpeg; if not, write to the Free Software | |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 19 | + */ | |
| 20 | + | |
| 21 | +#include <stddef.h> | |
| 22 | +#include "libavutil/aes_internal.h" | |
| 23 | +#include "libavutil/x86/cpu.h" | |
| 24 | + | |
| 25 | +void ff_aes_decrypt_aesni(AVAES *a, uint8_t *dst, const uint8_t *src, | |
| 26 | + int count, uint8_t *iv, int rounds); | |
| 27 | +void ff_aes_encrypt_aesni(AVAES *a, uint8_t *dst, const uint8_t *src, | |
| 28 | + int count, uint8_t *iv, int rounds); | |
| 29 | + | |
| 30 | +void ff_init_aes_x86(AVAES *a, int decrypt) | |
| 31 | +{ | |
| 32 | + int cpu_flags = av_get_cpu_flags(); | |
| 33 | + | |
| 34 | + if (EXTERNAL_AESNI(cpu_flags)) | |
| 35 | + a->crypt = decrypt ? ff_aes_decrypt_aesni : ff_aes_encrypt_aesni; | |
| 36 | +} | |