summaryrefslogtreecommitdiff
path: root/libavutil/aes.c
diff options
context:
space:
mode:
authorDiego Biurrun <diego@biurrun.de>2016-03-21 15:19:30 +0100
committerDiego Biurrun <diego@biurrun.de>2016-03-24 21:45:07 +0100
commit3b08d9d932eef09403074d5af31e10d8011e840b (patch)
tree45f65ef8ab29ab8d979bfd5dff4bd726f62ae97b /libavutil/aes.c
parent439929859ae0eb9542d3bb8a0c856bd5a1d1ec48 (diff)
testprogs: K&R formatting cosmetics
Diffstat (limited to 'libavutil/aes.c')
-rw-r--r--libavutil/aes.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/libavutil/aes.c b/libavutil/aes.c
index 02a9281b77..d534bc78a7 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -21,9 +21,9 @@
*/
#include "common.h"
-#include "aes.h"
#include "intreadwrite.h"
#include "timer.h"
+#include "aes.h"
typedef union {
uint64_t u64[2];
@@ -46,7 +46,7 @@ struct AVAES *av_aes_alloc(void)
}
static const uint8_t rcon[10] = {
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
};
static uint8_t sbox[256];
@@ -109,7 +109,8 @@ static void subshift(av_aes_block s0[2], int s, const uint8_t *box)
s3[0].u8[ 5] = box[s3[1].u8[ 1]];
}
-static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
+static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d)
+{
#if CONFIG_SMALL
return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
#else
@@ -117,12 +118,13 @@ static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
#endif
}
-static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3){
+static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3)
+{
uint8_t (*src)[4] = state[1].u8x4;
- state[0].u32[0] = mix_core(multbl, src[0][0], src[s1 ][1], src[2][2], src[s3 ][3]);
- state[0].u32[1] = mix_core(multbl, src[1][0], src[s3-1][1], src[3][2], src[s1-1][3]);
- state[0].u32[2] = mix_core(multbl, src[2][0], src[s3 ][1], src[0][2], src[s1 ][3]);
- state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]);
+ state[0].u32[0] = mix_core(multbl, src[0][0], src[s1 ][1], src[2][2], src[s3 ][3]);
+ state[0].u32[1] = mix_core(multbl, src[1][0], src[s3 - 1][1], src[3][2], src[s1 - 1][3]);
+ state[0].u32[2] = mix_core(multbl, src[2][0], src[s3 ][1], src[0][2], src[s1 ][3]);
+ state[0].u32[3] = mix_core(multbl, src[3][0], src[s1 - 1][1], src[1][2], src[s3 - 1][3]);
}
static inline void crypt(AVAES *a, int s, const uint8_t *sbox,
@@ -178,7 +180,7 @@ static void init_multbl2(uint32_t tbl[][256], const int c[4],
l = alog8[x + log8[c[1]]];
m = alog8[x + log8[c[2]]];
n = alog8[x + log8[c[3]]];
- tbl[0][i] = AV_NE(MKBETAG(k,l,m,n), MKTAG(k,l,m,n));
+ tbl[0][i] = AV_NE(MKBETAG(k, l, m, n), MKTAG(k, l, m, n));
#if !CONFIG_SMALL
tbl[1][i] = ROT(tbl[0][i], 8);
tbl[2][i] = ROT(tbl[0][i], 16);
@@ -198,7 +200,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
uint8_t log8[256];
uint8_t alog8[512];
- if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl)-1][FF_ARRAY_ELEMS(enc_multbl[0])-1]) {
+ if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) {
j = 1;
for (i = 0; i < 255; i++) {
alog8[i] = alog8[i + 255] = j;
@@ -212,7 +214,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
j ^= (j << 1) ^ (j << 2) ^ (j << 3) ^ (j << 4);
j = (j ^ (j >> 8) ^ 99) & 255;
inv_sbox[j] = i;
- sbox[i] = j;
+ sbox[i] = j;
}
init_multbl2(dec_multbl, (const int[4]) { 0xe, 0x9, 0xd, 0xb },
log8, alog8, inv_sbox);
@@ -254,9 +256,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
a->round_key[i] = tmp[0];
}
} else {
- for (i = 0; i < (rounds + 1) >> 1; i++) {
- FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds-i]);
- }
+ for (i = 0; i < (rounds + 1) >> 1; i++)
+ FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds - i]);
}
return 0;
@@ -264,6 +265,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
#ifdef TEST
#include <string.h>
+
#include "lfg.h"
#include "log.h"
@@ -276,12 +278,12 @@ int main(int argc, char **argv)
{ 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
};
- uint8_t pt[16], rpt[2][16]= {
+ uint8_t pt[16], rpt[2][16] = {
{ 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
{ 0 }
};
- uint8_t rct[2][16]= {
+ uint8_t rct[2][16] = {
{ 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
{ 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
@@ -313,9 +315,8 @@ int main(int argc, char **argv)
av_lfg_init(&prng, 1);
for (i = 0; i < 10000; i++) {
- for (j = 0; j < 16; j++) {
+ for (j = 0; j < 16; j++)
pt[j] = av_lfg_get(&prng);
- }
{
START_TIMER;
av_aes_crypt(&ae, temp, pt, 1, NULL, 0);