[FFmpeg-devel] libavutil: Added twofish block cipher

supraja reddy supraja0493 at gmail.com
Tue Jan 20 20:56:18 CET 2015


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 have updated the patch with other changes suggested. Please let me know
if there is anything else to be changed.

Thanks,
Supraja

On Tue, Jan 20, 2015 at 8:45 PM, Michael Niedermayer <michaelni at gmx.at>
wrote:

> On Thu, Jan 15, 2015 at 10:21:22PM +0530, supraja reddy wrote:
> > Hello,
> >
> > I have attached the patch for twofish implementation. Please let me know
> if
> > there are any changes to be made.
> >
> > Thank you,
> >
> > Supraja
>
> [...]
>
> > +av_cold int av_twofish_init(AVTWOFISH *cs, const uint8_t *Key, int
> key_bits)
> > +{
> > +    uint32_t key[8], Ke[4], Ko[4], rh, A, B;
> > +    uint8_t keypad[32];
> > +    int i, j, k;
> > +    k = cs->ksize = ((key_bits <=128) ? 128 : ((key_bits <=192) ? 192 :
> 256)) >> 6;
> > +    memset(keypad, 0, sizeof(keypad));
> > +    memcpy(keypad, Key, key_bits >> 3);
>
> key_bits should be checked to be a supported value otherwise
> the memcpy could write out of the array
>
>
> [...]
> > +#ifdef TEST
> > +#include<stdio.h>
> > +#include<stdlib.h>
> > +#include"log.h"
> > +
> > +int main(int argc, char *argv[])
> > +{
> > +    uint8_t Key[32] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
> 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33,
> 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
> > +    };
> > +    const uint8_t rct[6][16] = {
> > +        {0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, 0xb6, 0xbf,
> 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a},
> > +        {0xcf, 0xd1, 0xd2, 0xe5, 0xa9, 0xbe, 0x9c, 0xdf, 0x50, 0x1f,
> 0x13, 0xb8, 0x92, 0xbd, 0x22, 0x48},
> > +        {0x37, 0x52, 0x7b, 0xe0, 0x05, 0x23, 0x34, 0xb8, 0x9f, 0x0c,
> 0xfc, 0xca, 0xe8, 0x7c, 0xfa, 0x20},
> > +        {0x5d, 0x9d, 0x4e, 0xef, 0xfa, 0x91, 0x51, 0x57, 0x55, 0x24,
> 0xf1, 0x15, 0x81, 0x5a, 0x12, 0xe0},
> > +        {0xe7, 0x54, 0x49, 0x21, 0x2b, 0xee, 0xf9, 0xf4, 0xa3, 0x90,
> 0xbd, 0x86, 0x0a, 0x64, 0x09, 0x41},
> > +        {0x37, 0xfe, 0x26, 0xff, 0x1c, 0xf6, 0x61, 0x75, 0xf5, 0xdd,
> 0xf4, 0xc3, 0x3b, 0x97, 0xa2, 0x05}
> > +    };
> > +    uint8_t temp[32], iv[16], rpt[32];
> > +    const int kbits[3] = {128, 192, 256};
> > +    int i, j, err = 0;
> > +    AVTWOFISH *cs;
> > +    cs = av_twofish_alloc();
> > +    if (!cs)
> > +        return 1;
>
> > +    memset(rpt, 0, sizeof(rpt));
>
> could be avoided with:
> uint8_t rpt[32] = {0};
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> There will always be a question for which you do not know the correct
> answer.
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tf2.patch
Type: text/x-patch
Size: 22345 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150121/2c6ef51a/attachment.bin>


More information about the ffmpeg-devel mailing list