[FFmpeg-devel] [RFC] support encrypted asf

Reimar Döffinger Reimar.Doeffinger
Sun Oct 7 22:30:54 CEST 2007

attached is a hack that allows to play
http://samples.mplayerhq.hu/asf-wmv/drm/industrial.wmv (and breaks all
other files).
The tar file should be extracted into the main ffmpeg dir.
It has been tested on x86 32 bit and Power G5.
The final version would check if AVFormatContext key and keylen are set
correctly and only then call the decryption code with the given key.
Due to Michaels (and admittedly my own) dislike of openssl and similarly
bloated libs (and because I wanted to do it anyway), this also contains
implementations of RC4 and DES.
Some technical information about the encryption is here:
http://www.spinnaker.com/crypt/drm/freeme/Technical but beware, there
are several inaccuracies or just plain wrong things.
Please note that no optimization for speed was done at all, the code is
as close to the specifications or as small/understandable as I could
make it. And IMHO this is not (yet) a case where clarity should be expended to
gain speed.
Also understand that this in no way circumvents the DRM or similar
stuff, it only does the decryption if you have the key.
I used code from freeme2 to help in the development of asfcrypt.c, but I
think that none of that code remains so LGPL should be okay (the
maintainer of freeme2 also told me he would be okay with putting it
under LGPL).

Reimar D?ffinger
-------------- next part --------------
Index: libavformat/asf.c
--- libavformat/asf.c	(revision 10676)
+++ libavformat/asf.c	(working copy)
@@ -23,6 +23,7 @@
 #include "mpegaudio.h"
 #include "asf.h"
 #include "common.h"
+#include "asfcrypt.h"
 #undef NDEBUG
 #include <assert.h>
@@ -707,6 +708,12 @@
     return 0;
+static uint8_t hexkey[20] = {
+  0x13, 0x73, 0x81, 0x53, 0x8c, 0x84, 0xc0, 0x68,
+  0x11, 0x19, 0x02, 0xa5, 0x9c, 0x5c, 0xf6, 0xc3,
+  0x40, 0x24, 0x7c, 0x39
 static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
     ASFContext *asf = s->priv_data;
@@ -823,6 +830,7 @@
         get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
+        asfcrypt_dec(hexkey, asf_st->pkt.data + asf->packet_frag_offset, asf->packet_frag_size);
         asf_st->frag_offset += asf->packet_frag_size;
         /* test if whole packet is read */
         if (asf_st->frag_offset == asf_st->pkt.size) {
Index: libavformat/Makefile
--- libavformat/Makefile	(revision 10676)
+++ libavformat/Makefile	(working copy)
@@ -21,7 +21,7 @@
 OBJS-$(CONFIG_AMR_MUXER)                 += amr.o
 OBJS-$(CONFIG_APC_DEMUXER)               += apc.o
 OBJS-$(CONFIG_APE_DEMUXER)               += ape.o
-OBJS-$(CONFIG_ASF_DEMUXER)               += asf.o riff.o
+OBJS-$(CONFIG_ASF_DEMUXER)               += asf.o riff.o asfcrypt.o des.o rc4.o
 OBJS-$(CONFIG_ASF_MUXER)                 += asf-enc.o riff.o
 OBJS-$(CONFIG_ASF_STREAM_MUXER)          += asf-enc.o riff.o
 OBJS-$(CONFIG_AU_DEMUXER)                += au.o raw.o
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asfcrypt.tar.gz
Type: application/octet-stream
Size: 3921 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071007/b92494fe/attachment.obj>

More information about the ffmpeg-devel mailing list