[FFmpeg-devel] [RFC] Public API for RC4 and DES

Reimar Döffinger Reimar.Doeffinger
Fri Jan 30 09:40:28 CET 2009


On Fri, Jan 30, 2009 at 12:10:06AM +0100, Michael Niedermayer wrote:
> On Wed, Jan 28, 2009 at 03:17:27PM +0100, Reimar D?ffinger wrote:
> > @@ -150,17 +152,22 @@
> >      }
> >  
> >      memset(rc4buff, 0, sizeof(rc4buff));
> > -    ff_rc4_enc(key, 12, (uint8_t *)rc4buff, sizeof(rc4buff));
> > +    rc4 = av_malloc(av_rc4_size);
> 
> uint8_t rc4v[av_rc4_size];
> struct AVRC4 *rc4= (void*)rc4v;

I was thinking about that, it just seemed horribly ugly...

> [...]
> > @@ -277,6 +284,33 @@
> >      return in;
> >  }
> >  
> > +int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) {
> > +    if (key_bits != 64)
> > +        return -1;
> > +    d->key = be2me_64(*(const uint64_t *)key);
> > +    return 0;
> > +}
> 
> iam not sure what i should think about this but it feels somehow ugly
> it simply does nothing

That is why I did not implement it at first, but it does allow for a
more thoroughly optimized implementation somewhen later.
I do think that AV_RB64 probably is a better idea here, requiring the
key to be aligned seems a bit like overkill...

> > +
> > +void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
> > +    uint64_t iv_val = iv ? be2me_64(*(uint64_t *)iv) : 0;
> > +    while (count-- > 0) {
> > +        uint64_t dst_val;
> > +        uint64_t src_val = src ? be2me_64(*(const uint64_t *)src) : 0;
> > +        if (decrypt) {
> > +            dst_val = ff_des_encdec(src_val, d->key, 1) ^ iv_val;
> > +            iv_val = iv ? src_val : 0;
> > +        } else {
> > +            dst_val = ff_des_encdec(src_val ^ iv_val, d->key, 0);
> > +            iv_val = iv ? dst_val : 0;
> > +        }
> > +        *(uint64_t *)dst = be2me_64(dst_val);
> > +        src += 8;
> > +        dst += 8;
> > +    }
> > +    if (iv)
> > +        *(uint64_t *)iv = be2me_64(iv_val);
> > +}
> 
> have you done some benchmark with asf?
> I dont want playback of asf to become slower

Nothing thorough, I also have only one sample for encrypted asf.
Keep in mind that there is only 8 bytes encrypted with DES per
asf chunk, all others use rc4.




More information about the ffmpeg-devel mailing list