]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/asfcrypt.c
add FF_API_ALLOC_FORMAT_CONTEXT define to disable the deprecated
[ffmpeg] / libavformat / asfcrypt.c
index 74a3dcc431910bcbf6ab30783201e85e164f3d98..59986e0a2c3be2f9b3b648acdc9097d0e5e1f733 100644 (file)
@@ -136,8 +136,10 @@ static uint64_t multiswap_dec(const uint32_t keys[12], uint64_t key, uint64_t da
 }
 
 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;
+    uint8_t *qwords = data;
     uint64_t rc4buff[8];
     uint64_t packetkey;
     uint32_t ms_keys[12];
@@ -150,24 +152,25 @@ void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
     }
 
     memset(rc4buff, 0, sizeof(rc4buff));
-    ff_rc4_enc(key, 12, (uint8_t *)rc4buff, sizeof(rc4buff));
+    av_rc4_init(&rc4, key, 12 * 8, 1);
+    av_rc4_crypt(&rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1);
     multiswap_init((uint8_t *)rc4buff, ms_keys);
 
-    packetkey = qwords[num_qwords - 1];
+    packetkey = AV_RN64(&qwords[num_qwords*8 - 8]);
     packetkey ^= rc4buff[7];
-    packetkey = be2me_64(packetkey);
-    packetkey = ff_des_encdec(packetkey, AV_RB64(key + 12), 1);
-    packetkey = be2me_64(packetkey);
+    av_des_init(&des, key + 12, 64, 1);
+    av_des_crypt(&des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1);
     packetkey ^= rc4buff[6];
 
-    ff_rc4_enc((uint8_t *)&packetkey, 8, data, len);
+    av_rc4_init(&rc4, (uint8_t *)&packetkey, 64, 1);
+    av_rc4_crypt(&rc4, data, data, len, NULL, 1);
 
     ms_state = 0;
-    for (i = 0; i < num_qwords - 1; i++, qwords++)
+    for (i = 0; i < num_qwords - 1; i++, qwords += 8)
         ms_state = multiswap_enc(ms_keys, ms_state, AV_RL64(qwords));
     multiswap_invert_keys(ms_keys);
     packetkey = (packetkey << 32) | (packetkey >> 32);
-    packetkey = le2me_64(packetkey);
+    packetkey = av_le2ne64(packetkey);
     packetkey = multiswap_dec(ms_keys, ms_state, packetkey);
     AV_WL64(qwords, packetkey);
 }