[FFmpeg-devel] [PATCH 03/12] lavu/aes: add runtime dispatch for crypt function
Michael Niedermayer
michael at niedermayer.cc
Tue Oct 27 14:28:02 CET 2015
On Mon, Oct 26, 2015 at 03:25:45AM -0500, Rodger Combs wrote:
> ---
> libavutil/aes.c | 47 +++++++++++++++++++++++++++++++----------------
> libavutil/aes_internal.h | 1 +
> 2 files changed, 32 insertions(+), 16 deletions(-)
>
> diff --git a/libavutil/aes.c b/libavutil/aes.c
> index 61e9dd1..4fa01ea 100644
> --- a/libavutil/aes.c
> +++ b/libavutil/aes.c
> @@ -126,31 +126,44 @@ static inline void aes_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)
> +static void aes_encrypt(AVAES *a, uint8_t *dst, const uint8_t *src,
> + int count, uint8_t *iv, int rounds)
> {
> while (count--) {
> addkey_s(&a->state[1], src, &a->round_key[a->rounds]);
> - if (decrypt) {
> - aes_crypt(a, 0, inv_sbox, dec_multbl);
> - if (iv) {
> - addkey_s(&a->state[0], iv, &a->state[0]);
> - memcpy(iv, src, 16);
> - }
> - addkey_d(dst, &a->state[0], &a->round_key[0]);
> - } else {
> - if (iv)
> - addkey_s(&a->state[1], iv, &a->state[1]);
> - aes_crypt(a, 2, sbox, enc_multbl);
> - addkey_d(dst, &a->state[0], &a->round_key[0]);
> - if (iv)
> - memcpy(iv, dst, 16);
> + if (iv)
> + addkey_s(&a->state[1], iv, &a->state[1]);
> + aes_crypt(a, 2, sbox, enc_multbl);
> + addkey_d(dst, &a->state[0], &a->round_key[0]);
> + if (iv)
> + memcpy(iv, dst, 16);
> + src += 16;
> + dst += 16;
> + }
> +}
> +
> +static void aes_decrypt(AVAES *a, uint8_t *dst, const uint8_t *src,
> + int count, uint8_t *iv, int rounds)
> +{
> + while (count--) {
> + addkey_s(&a->state[1], src, &a->round_key[a->rounds]);
could be simplified by using the funtction argument "rounds"
patch ok either way
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151027/42177532/attachment.sig>
More information about the ffmpeg-devel
mailing list