| 146 | } |
| 147 | |
| 148 | void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) |
| 149 | { |
| 150 | struct AVDES *des; |
| 151 | struct AVRC4 *rc4; |
| 152 | int num_qwords = len >> 3; |
| 153 | uint8_t *qwords = data; |
| 154 | uint64_t rc4buff[8] = { 0 }; |
| 155 | uint64_t packetkey; |
| 156 | uint32_t ms_keys[12]; |
| 157 | uint64_t ms_state; |
| 158 | int i; |
| 159 | if (len < 16) { |
| 160 | for (i = 0; i < len; i++) |
| 161 | data[i] ^= key[i]; |
| 162 | return; |
| 163 | } |
| 164 | des = av_des_alloc(); |
| 165 | rc4 = av_rc4_alloc(); |
| 166 | if (!des || !rc4) { |
| 167 | av_freep(&des); |
| 168 | av_freep(&rc4); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | av_rc4_init(rc4, key, 12 * 8, 1); |
| 173 | av_rc4_crypt(rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1); |
| 174 | multiswap_init((uint8_t *)rc4buff, ms_keys); |
| 175 | |
| 176 | packetkey = AV_RN64(&qwords[num_qwords * 8 - 8]); |
| 177 | packetkey ^= rc4buff[7]; |
| 178 | av_des_init(des, key + 12, 64, 1); |
| 179 | av_des_crypt(des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1); |
| 180 | packetkey ^= rc4buff[6]; |
| 181 | |
| 182 | av_rc4_init(rc4, (uint8_t *)&packetkey, 64, 1); |
| 183 | av_rc4_crypt(rc4, data, data, len, NULL, 1); |
| 184 | |
| 185 | ms_state = 0; |
| 186 | for (i = 0; i < num_qwords - 1; i++, qwords += 8) |
| 187 | ms_state = multiswap_enc(ms_keys, ms_state, AV_RL64(qwords)); |
| 188 | multiswap_invert_keys(ms_keys); |
| 189 | packetkey = (packetkey << 32) | (packetkey >> 32); |
| 190 | packetkey = av_le2ne64(packetkey); |
| 191 | packetkey = multiswap_dec(ms_keys, ms_state, packetkey); |
| 192 | AV_WL64(qwords, packetkey); |
| 193 | |
| 194 | av_free(rc4); |
| 195 | av_free(des); |
| 196 | } |
no test coverage detected