[FFmpeg-devel] [PATCH] support encrypted asf

Reimar Döffinger Reimar.Doeffinger
Sat Oct 13 12:53:34 CEST 2007


Hello,
On Tue, Oct 09, 2007 at 07:53:04PM +0200, Reimar D?ffinger wrote:
> except for the missing license headers attached is the "final" (pending
> comments/objections) version.
> Please comment.

I completely lack time ATM, so this will be delayed a bit.
Either way there are two obvious optimization possibilities you could
comment on whether you like them or even find them sufficient:

> +static uint32_t f_func(uint32_t r, uint64_t k) {
> +    int i;
> +    uint32_t out = 0;
> +    // expand 32 bit data to 8 * 6 bit blocks
> +    uint64_t tmp = shuffle(r, E_shuffle, sizeof(E_shuffle));
> +    tmp ^= k;
> +    // apply S-boxes, those compress the data again from 8 * 6 to 8 * 4 bits
> +    for (i = 0; i < 8; i++) {
> +        uint32_t v = S_boxes[i][(tmp >> 43) & 0x1f];
> +        if (tmp & ((uint64_t)1 << 42)) v >>= 4;
> +        else v &= 0x0f;
> +        tmp <<= 6;
> +        out = (out << 4) | v;
> +    }
> +    out = shuffle(out, P_shuffle, sizeof(P_shuffle));

The inner part of the for loop can be simplified to
> out |= expanded_S_boxes[i][(tmp >> 43) & 0x1f];
> tmp <<= 6;
and the final shuffle can be removed by expanding the S boxes to include the
other operations.
This would increase the table size from 256 to 2048 bytes though (would
using CONFIG_SMALL and having both implementations be good?).

[...]
> +    for (i = 0; i < 16; i++) {
> +        uint64_t Kn;
> +        uint32_t f_res;
> +        if (!decrypt) {
> +            CDn = key_shift_left(CDn);
> +            if (i > 1 && i != 8 && i != 15)
> +                CDn = key_shift_left(CDn);
> +        }

The round keys can be generated in a separate function, which
means these steps would not be necessary for each decryption, but it
needs an extra state and slightly complicates the API. Probably is also
a bit slower if the key is used only once (which may be unlikely
though).

I applied the RC4 part since Michael ok'd it and nobody objected.

Greetings,
Reimar D?ffinger




More information about the ffmpeg-devel mailing list