Mercurial > libavformat.hg
comparison asfcrypt.c @ 6401:4c2f01a5f69f libavformat
asfcrypt: fix unaligned accesses with armcc
Compilers may assume a pointer has natural alignment, even if it was
assigned from a pointer type with weaker alignment requirements. It
is thus not safe to assign a possibly unaligned value to a pointer,
regardless of how it is subsequently dereferenced.
author | mru |
---|---|
date | Tue, 24 Aug 2010 13:42:28 +0000 |
parents | 6928d93146e6 |
children |
comparison
equal
deleted
inserted
replaced
6400:6928d93146e6 | 6401:4c2f01a5f69f |
---|---|
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; |
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 = AV_RN64(&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); |