[FFmpeg-devel] libavutil: Added twofish block cipher

Michael Niedermayer michaelni at gmx.at
Fri Jan 23 02:27:02 CET 2015


Hi

On Wed, Jan 21, 2015 at 01:26:18AM +0530, supraja reddy wrote:
> Hello,
> 
> Thanks for you reviews.
> 
> I see this is only use during init but if it still matters speedwise
> > and assuming this is a galois field multiplication the it can be
> > written as
> >
> > EXP_GF256[LOG_GF256[a] + LOG_GF256[b]]  (for a!=0 && b!=0)
> >
> > Do you want me to insert tables EXP_GF256 and LOG_GF256 in the code or are
> there any existing tables ?

i think there are no existing tables


> 
> I have updated the patch with other changes suggested. Please let me know
> if there is anything else to be changed.
> 

[...]

> +static uint32_t tf_h(uint32_t X, uint32_t L[4], int k)
> +{
> +    uint8_t y[4], l[4];
> +    AV_WL32(y, X);
> +    if (k == 4) {
> +        AV_WL32(l, L[3]);
> +        y[0] = q1[y[0]] ^ l[0];
> +        y[1] = q0[y[1]] ^ l[1];
> +        y[2] = q0[y[2]] ^ l[2];
> +        y[3] = q1[y[3]] ^ l[3];
> +    }
> +    if (k >= 3) {
> +        AV_WL32(l, L[2]);
> +        y[0] = q1[y[0]] ^ l[0];
> +        y[1] = q1[y[1]] ^ l[1];
> +        y[2] = q0[y[2]] ^ l[2];
> +        y[3] = q0[y[3]] ^ l[3];
> +    }
> +    AV_WL32(l, L[1]);
> +    y[0] = q1[q0[q0[y[0]] ^ l[0]] ^ (L[0] & 0xff)];
> +    y[1] = q0[q0[q1[y[1]] ^ l[1]] ^ ((L[0] >> 8) & 0xff)];
> +    y[2] = q1[q1[q0[y[2]] ^ l[2]] ^ ((L[0] >> 16) & 0xff)];
> +    y[3] = q0[q1[q1[y[3]] ^ l[3]] ^ (L[0] >> 24)];
> +
> +    l[0] = y[0] ^ MD2[y[1]] ^ MD1[y[2]] ^ MD1[y[3]];
> +    l[1] = MD1[y[0]] ^ MD2[y[1]] ^ MD2[y[2]] ^ y[3];
> +    l[2] = MD2[y[0]] ^ MD1[y[1]] ^ y[2] ^ MD2[y[3]];
> +    l[3] = MD2[y[0]] ^ y[1] ^ MD2[y[2]] ^ MD1[y[3]];
> +
> +    return AV_RL32(l);
> +}

I think this can be implemented with a few 8bit->32bit LUTs which are
computed during init


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150123/562000a0/attachment.asc>


More information about the ffmpeg-devel mailing list