diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-07-05 01:46:03 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-07-05 02:26:17 +0200 |
commit | 5d4fd1d1adf1ec17dd19548783f7f2eb0d64225f (patch) | |
tree | 0ed0d9be892e55bea47d777dcd78d7c1cf104adf /libavutil/aes.c | |
parent | 96676e1abfece89e20bc962255b48cb2d9e417bd (diff) | |
parent | 3824ef08e0878aa9f100f33ef22b61daf68058c2 (diff) | |
download | ffmpeg-5d4fd1d1adf1ec17dd19548783f7f2eb0d64225f.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (36 commits)
ARM: allow unaligned buffer in fixed-point NEON FFT4
fate: test more FFT etc sizes
dca: set AVCodecContext frame_size for DTS audio
YASM: Shut up unused variable compiler warning with --disable-yasm.
x86_32: Fix build on x86_32 with --disable-yasm.
iirfilter: add fate test
doxygen: Add qmul docs.
ogg: propagate return values and return more meaningful error values
H.264: fix overreads of qscale_table
Remove unused static tables and static inline functions.
eval: clear Parser instances before using
dct-test: remove 'ref' function pointer from tables
build: Remove deleted 'check' target from .PHONY list.
oggdec: Abort Ogg header parsing when encountering a data packet.
Add LGPL license boilerplate to files lacking it.
mxfenc: small typo fix
doxygen: Fix documentation for some VP8 functions.
sha: use AV_RB32() instead of assuming buffer can be cast to uint32_t*
des: allow unaligned input and output buffers
aes: allow unaligned input and output buffers
...
Conflicts:
libavcodec/dct-test.c
libavcodec/libvpxenc.c
libavcodec/x86/dsputil_mmx.c
libavcodec/x86/h264_qpel_mmx.c
libavfilter/x86/gradfun.c
libavformat/oggdec.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/aes.c')
-rw-r--r-- | libavutil/aes.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/libavutil/aes.c b/libavutil/aes.c index 7c92a2757f..49093efc53 100644 --- a/libavutil/aes.c +++ b/libavutil/aes.c @@ -22,6 +22,7 @@ #include "common.h" #include "aes.h" +#include "intreadwrite.h" typedef union { uint64_t u64[2]; @@ -67,6 +68,20 @@ static inline void addkey(av_aes_block *dst, const av_aes_block *src, dst->u64[1] = src->u64[1] ^ round_key->u64[1]; } +static inline void addkey_s(av_aes_block *dst, const uint8_t *src, + const av_aes_block *round_key) +{ + dst->u64[0] = AV_RN64(src) ^ round_key->u64[0]; + dst->u64[1] = AV_RN64(src + 8) ^ round_key->u64[1]; +} + +static inline void addkey_d(uint8_t *dst, const av_aes_block *src, + const av_aes_block *round_key) +{ + AV_WN64(dst, src->u64[0] ^ round_key->u64[0]); + AV_WN64(dst + 8, src->u64[1] ^ round_key->u64[1]); +} + static void subshift(av_aes_block s0[2], int s, const uint8_t *box) { av_aes_block *s1 = (av_aes_block *) (s0[0].u8 - s); @@ -119,32 +134,28 @@ static inline void crypt(AVAES *a, int s, const uint8_t *sbox, subshift(&a->state[0], s, sbox); } -void av_aes_crypt(AVAES *a, uint8_t *dst_, const uint8_t *src_, - int count, uint8_t *iv_, int decrypt) +void av_aes_crypt(AVAES *a, uint8_t *dst, const uint8_t *src, + int count, uint8_t *iv, int decrypt) { - av_aes_block *dst = (av_aes_block *) dst_; - const av_aes_block *src = (const av_aes_block *) src_; - av_aes_block *iv = (av_aes_block *) iv_; - while (count--) { - addkey(&a->state[1], src, &a->round_key[a->rounds]); + addkey_s(&a->state[1], src, &a->round_key[a->rounds]); if (decrypt) { crypt(a, 0, inv_sbox, dec_multbl); if (iv) { - addkey(&a->state[0], &a->state[0], iv); - *iv = *src; + addkey_s(&a->state[0], iv, &a->state[0]); + memcpy(iv, src, 16); } - addkey(dst, &a->state[0], &a->round_key[0]); + addkey_d(dst, &a->state[0], &a->round_key[0]); } else { if (iv) - addkey(&a->state[1], &a->state[1], iv); + addkey_s(&a->state[1], iv, &a->state[1]); crypt(a, 2, sbox, enc_multbl); - addkey(dst, &a->state[0], &a->round_key[0]); + addkey_d(dst, &a->state[0], &a->round_key[0]); if (iv) - *iv = *dst; + memcpy(iv, dst, 16); } - src++; - dst++; + src += 16; + dst += 16; } } |