diff options
author | Diego Biurrun <diego@biurrun.de> | 2013-02-06 03:44:00 +0400 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2013-02-06 12:48:51 +0400 |
commit | 48a4ffa722c0874b251de9d201babed52cef0bcb (patch) | |
tree | 2648a734acbd1963f3971bf3af77edef5a675377 /libavformat/asfcrypt.c | |
parent | 77bcb89600e79fbf37d4b739480813ef03292c5b (diff) |
asf: K&R formatting cosmetics
Diffstat (limited to 'libavformat/asfcrypt.c')
-rw-r--r-- | libavformat/asfcrypt.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/libavformat/asfcrypt.c b/libavformat/asfcrypt.c index 6c48a1967a..c261475848 100644 --- a/libavformat/asfcrypt.c +++ b/libavformat/asfcrypt.c @@ -20,10 +20,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/common.h" -#include "libavutil/intreadwrite.h" #include "libavutil/bswap.h" +#include "libavutil/common.h" #include "libavutil/des.h" +#include "libavutil/intreadwrite.h" #include "libavutil/rc4.h" #include "asfcrypt.h" @@ -32,7 +32,8 @@ * @param v number to invert, must be odd! * @return number so that result * v = 1 (mod 2^32) */ -static uint32_t inverse(uint32_t v) { +static uint32_t inverse(uint32_t v) +{ // v ^ 3 gives the inverse (mod 16), could also be implemented // as table etc. (only lowest 4 bits matter!) uint32_t inverse = v * v * v; @@ -50,7 +51,8 @@ static uint32_t inverse(uint32_t v) { * @param keys output key array containing the keys for encryption in * native endianness */ -static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) { +static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) +{ int i; for (i = 0; i < 12; i++) keys[i] = AV_RL32(keybuf + (i << 2)) | 1; @@ -61,7 +63,8 @@ static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) { * the other way round. * @param keys key array of ints to invert */ -static void multiswap_invert_keys(uint32_t keys[12]) { +static void multiswap_invert_keys(uint32_t keys[12]) +{ int i; for (i = 0; i < 5; i++) keys[i] = inverse(keys[i]); @@ -69,23 +72,25 @@ static void multiswap_invert_keys(uint32_t keys[12]) { keys[i] = inverse(keys[i]); } -static uint32_t multiswap_step(const uint32_t keys[12], uint32_t v) { +static uint32_t multiswap_step(const uint32_t keys[12], uint32_t v) +{ int i; v *= keys[0]; for (i = 1; i < 5; i++) { - v = (v >> 16) | (v << 16); + v = (v >> 16) | (v << 16); v *= keys[i]; } v += keys[5]; return v; } -static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v) { +static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v) +{ int i; v -= keys[5]; for (i = 4; i > 0; i--) { v *= keys[i]; - v = (v >> 16) | (v << 16); + v = (v >> 16) | (v << 16); } v *= keys[0]; return v; @@ -99,17 +104,19 @@ static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v) { * @param data data to encrypt * @return encrypted data */ -static uint64_t multiswap_enc(const uint32_t keys[12], uint64_t key, uint64_t data) { +static uint64_t multiswap_enc(const uint32_t keys[12], + uint64_t key, uint64_t data) +{ uint32_t a = data; uint32_t b = data >> 32; uint32_t c; uint32_t tmp; - a += key; - tmp = multiswap_step(keys , a); - b += tmp; - c = (key >> 32) + tmp; + a += key; + tmp = multiswap_step(keys, a); + b += tmp; + c = (key >> 32) + tmp; tmp = multiswap_step(keys + 6, b); - c += tmp; + c += tmp; return ((uint64_t)c << 32) | tmp; } @@ -121,25 +128,28 @@ static uint64_t multiswap_enc(const uint32_t keys[12], uint64_t key, uint64_t da * @param data data to decrypt * @return decrypted data */ -static uint64_t multiswap_dec(const uint32_t keys[12], uint64_t key, uint64_t data) { +static uint64_t multiswap_dec(const uint32_t keys[12], + uint64_t key, uint64_t data) +{ uint32_t a; uint32_t b; - uint32_t c = data >> 32; + uint32_t c = data >> 32; uint32_t tmp = data; - c -= tmp; - b = multiswap_inv_step(keys + 6, tmp); + c -= tmp; + b = multiswap_inv_step(keys + 6, tmp); tmp = c - (key >> 32); - b -= tmp; - a = multiswap_inv_step(keys , tmp); - a -= key; + b -= tmp; + a = multiswap_inv_step(keys, tmp); + a -= key; return ((uint64_t)b << 32) | a; } -void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) { +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; - uint8_t *qwords = data; + int num_qwords = len >> 3; + uint8_t *qwords = data; uint64_t rc4buff[8] = { 0 }; uint64_t packetkey; uint32_t ms_keys[12]; @@ -155,7 +165,7 @@ void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) { av_rc4_crypt(&rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1); multiswap_init((uint8_t *)rc4buff, ms_keys); - packetkey = AV_RN64(&qwords[num_qwords*8 - 8]); + packetkey = AV_RN64(&qwords[num_qwords * 8 - 8]); packetkey ^= rc4buff[7]; av_des_init(&des, key + 12, 64, 1); av_des_crypt(&des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1); |