[FFmpeg-devel] [RFC] Public API for RC4 and DES
Michael Niedermayer
michaelni
Fri Jan 30 00:10:06 CET 2009
On Wed, Jan 28, 2009 at 03:17:27PM +0100, Reimar D?ffinger wrote:
> Hello,
> attached patch makes them use an API similar to AES.
> Differences:
> - src is const
> - alignment requirements of src and dst documented
> - src == NULL is allowed for easier use as PRNG
> - RC4 does not implement CBC (what would be the IV length for RC4?
> Would a one-byte IV even be useful?)
> - block size, relative to which count is given, is 16 bytes for AES,
> 8 bytes for DES and 1 byte for RC4
>
> The disadvantage for the only user asfcrypt is that it adds two
> malloc/frees per ASF block, at least with the current design.
>
> Greetings,
> Reimar D?ffinger
> Index: libavformat/asfcrypt.c
> ===================================================================
> --- libavformat/asfcrypt.c (revision 16844)
> +++ libavformat/asfcrypt.c (working copy)
> @@ -136,6 +136,8 @@
> }
>
> void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
> + struct AVDES *des;
> + struct AVRC4 *rc4;
> int num_qwords = len >> 3;
> uint64_t *qwords = (uint64_t *)data;
> uint64_t rc4buff[8];
> @@ -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;
[...]
> @@ -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
> +
> +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
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090130/81c3a525/attachment.pgp>
More information about the ffmpeg-devel
mailing list