| OLD | NEW |
| 1 /* | 1 /* |
| 2 * ASF decryption | 2 * ASF decryption |
| 3 * Copyright (c) 2007 Reimar Doeffinger | 3 * Copyright (c) 2007 Reimar Doeffinger |
| 4 * This is a rewrite of code contained in freeme/freeme2 | 4 * This is a rewrite of code contained in freeme/freeme2 |
| 5 * | 5 * |
| 6 * This file is part of FFmpeg. | 6 * This file is part of FFmpeg. |
| 7 * | 7 * |
| 8 * FFmpeg is free software; you can redistribute it and/or | 8 * FFmpeg is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 b -= tmp; | 132 b -= tmp; |
| 133 a = multiswap_inv_step(keys , tmp); | 133 a = multiswap_inv_step(keys , tmp); |
| 134 a -= key; | 134 a -= key; |
| 135 return ((uint64_t)b << 32) | a; | 135 return ((uint64_t)b << 32) | a; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) { | 138 void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) { |
| 139 struct AVDES des; | 139 struct AVDES des; |
| 140 struct AVRC4 rc4; | 140 struct AVRC4 rc4; |
| 141 int num_qwords = len >> 3; | 141 int num_qwords = len >> 3; |
| 142 uint64_t *qwords = (uint64_t *)data; | 142 uint8_t *qwords = data; |
| 143 uint64_t rc4buff[8]; | 143 uint64_t rc4buff[8]; |
| 144 uint64_t packetkey; | 144 uint64_t packetkey; |
| 145 uint32_t ms_keys[12]; | 145 uint32_t ms_keys[12]; |
| 146 uint64_t ms_state; | 146 uint64_t ms_state; |
| 147 int i; | 147 int i; |
| 148 if (len < 16) { | 148 if (len < 16) { |
| 149 for (i = 0; i < len; i++) | 149 for (i = 0; i < len; i++) |
| 150 data[i] ^= key[i]; | 150 data[i] ^= key[i]; |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 memset(rc4buff, 0, sizeof(rc4buff)); | 154 memset(rc4buff, 0, sizeof(rc4buff)); |
| 155 av_rc4_init(&rc4, key, 12 * 8, 1); | 155 av_rc4_init(&rc4, key, 12 * 8, 1); |
| 156 av_rc4_crypt(&rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1); | 156 av_rc4_crypt(&rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1); |
| 157 multiswap_init((uint8_t *)rc4buff, ms_keys); | 157 multiswap_init((uint8_t *)rc4buff, ms_keys); |
| 158 | 158 |
| 159 packetkey = qwords[num_qwords - 1]; | 159 packetkey = AV_RN64(&qwords[num_qwords*8 - 8]); |
| 160 packetkey ^= rc4buff[7]; | 160 packetkey ^= rc4buff[7]; |
| 161 av_des_init(&des, key + 12, 64, 1); | 161 av_des_init(&des, key + 12, 64, 1); |
| 162 av_des_crypt(&des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1)
; | 162 av_des_crypt(&des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1)
; |
| 163 packetkey ^= rc4buff[6]; | 163 packetkey ^= rc4buff[6]; |
| 164 | 164 |
| 165 av_rc4_init(&rc4, (uint8_t *)&packetkey, 64, 1); | 165 av_rc4_init(&rc4, (uint8_t *)&packetkey, 64, 1); |
| 166 av_rc4_crypt(&rc4, data, data, len, NULL, 1); | 166 av_rc4_crypt(&rc4, data, data, len, NULL, 1); |
| 167 | 167 |
| 168 ms_state = 0; | 168 ms_state = 0; |
| 169 for (i = 0; i < num_qwords - 1; i++, qwords++) | 169 for (i = 0; i < num_qwords - 1; i++, qwords += 8) |
| 170 ms_state = multiswap_enc(ms_keys, ms_state, AV_RL64(qwords)); | 170 ms_state = multiswap_enc(ms_keys, ms_state, AV_RL64(qwords)); |
| 171 multiswap_invert_keys(ms_keys); | 171 multiswap_invert_keys(ms_keys); |
| 172 packetkey = (packetkey << 32) | (packetkey >> 32); | 172 packetkey = (packetkey << 32) | (packetkey >> 32); |
| 173 packetkey = av_le2ne64(packetkey); | 173 packetkey = av_le2ne64(packetkey); |
| 174 packetkey = multiswap_dec(ms_keys, ms_state, packetkey); | 174 packetkey = multiswap_dec(ms_keys, ms_state, packetkey); |
| 175 AV_WL64(qwords, packetkey); | 175 AV_WL64(qwords, packetkey); |
| 176 } | 176 } |
| OLD | NEW |