Commit 5f587b1d authored by Derek Buitenhuis's avatar Derek Buitenhuis

Merge commit '3b08d9d9'

* commit '3b08d9d9':
  testprogs: K&R formatting cosmetics
Merged-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parents 32c044cb 3b08d9d9
This diff is collapsed.
...@@ -56,7 +56,7 @@ av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, ...@@ -56,7 +56,7 @@ av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf,
/* cast to avoid compiler warning */ /* cast to avoid compiler warning */
ff_init_range_encoder(c, (uint8_t *)buf, buf_size); ff_init_range_encoder(c, (uint8_t *)buf, buf_size);
c->low = AV_RB16(c->bytestream); c->low = AV_RB16(c->bytestream);
c->bytestream += 2; c->bytestream += 2;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "aes_internal.h" #include "aes_internal.h"
#include "intreadwrite.h" #include "intreadwrite.h"
#include "timer.h" #include "timer.h"
#include "aes.h"
const int av_aes_size= sizeof(AVAES); const int av_aes_size= sizeof(AVAES);
...@@ -34,7 +35,7 @@ struct AVAES *av_aes_alloc(void) ...@@ -34,7 +35,7 @@ struct AVAES *av_aes_alloc(void)
} }
static const uint8_t rcon[10] = { 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]; static uint8_t sbox[256];
...@@ -97,7 +98,8 @@ static void subshift(av_aes_block s0[2], int s, const uint8_t *box) ...@@ -97,7 +98,8 @@ static void subshift(av_aes_block s0[2], int s, const uint8_t *box)
s3[0].u8[ 5] = box[s3[1].u8[ 1]]; 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 #if CONFIG_SMALL
return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24); return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
#else #else
...@@ -105,12 +107,13 @@ static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){ ...@@ -105,12 +107,13 @@ static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
#endif #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; 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[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[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[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[3] = mix_core(multbl, src[3][0], src[s1 - 1][1], src[1][2], src[s3 - 1][3]);
} }
static inline void aes_crypt(AVAES *a, int s, const uint8_t *sbox, static inline void aes_crypt(AVAES *a, int s, const uint8_t *sbox,
...@@ -179,7 +182,7 @@ static void init_multbl2(uint32_t tbl[][256], const int c[4], ...@@ -179,7 +182,7 @@ static void init_multbl2(uint32_t tbl[][256], const int c[4],
l = alog8[x + log8[c[1]]]; l = alog8[x + log8[c[1]]];
m = alog8[x + log8[c[2]]]; m = alog8[x + log8[c[2]]];
n = alog8[x + log8[c[3]]]; 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 #if !CONFIG_SMALL
tbl[1][i] = ROT(tbl[0][i], 8); tbl[1][i] = ROT(tbl[0][i], 8);
tbl[2][i] = ROT(tbl[0][i], 16); tbl[2][i] = ROT(tbl[0][i], 16);
...@@ -201,7 +204,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) ...@@ -201,7 +204,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
a->crypt = decrypt ? aes_decrypt : aes_encrypt; a->crypt = decrypt ? aes_decrypt : aes_encrypt;
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; j = 1;
for (i = 0; i < 255; i++) { for (i = 0; i < 255; i++) {
alog8[i] = alog8[i + 255] = j; alog8[i] = alog8[i + 255] = j;
...@@ -215,7 +218,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) ...@@ -215,7 +218,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 << 1) ^ (j << 2) ^ (j << 3) ^ (j << 4);
j = (j ^ (j >> 8) ^ 99) & 255; j = (j ^ (j >> 8) ^ 99) & 255;
inv_sbox[j] = i; inv_sbox[j] = i;
sbox[i] = j; sbox[i] = j;
} }
init_multbl2(dec_multbl, (const int[4]) { 0xe, 0x9, 0xd, 0xb }, init_multbl2(dec_multbl, (const int[4]) { 0xe, 0x9, 0xd, 0xb },
log8, alog8, inv_sbox); log8, alog8, inv_sbox);
...@@ -257,9 +260,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) ...@@ -257,9 +260,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
a->round_key[i] = tmp[0]; a->round_key[i] = tmp[0];
} }
} else { } else {
for (i = 0; i < (rounds + 1) >> 1; i++) { for (i = 0; i < (rounds + 1) >> 1; i++)
FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds-i]); FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds - i]);
}
} }
return 0; return 0;
...@@ -268,6 +270,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) ...@@ -268,6 +270,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
#ifdef TEST #ifdef TEST
// LCOV_EXCL_START // LCOV_EXCL_START
#include <string.h> #include <string.h>
#include "lfg.h" #include "lfg.h"
#include "log.h" #include "log.h"
...@@ -280,12 +283,12 @@ int main(int argc, char **argv) ...@@ -280,12 +283,12 @@ int main(int argc, char **argv)
{ 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 } 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
}; };
uint8_t pt[32], rpt[2][16]= { uint8_t pt[32], rpt[2][16] = {
{ 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 }, 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
{ 0 } { 0 }
}; };
uint8_t rct[2][16]= { uint8_t rct[2][16] = {
{ 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf }, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
{ 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
...@@ -318,12 +321,10 @@ int main(int argc, char **argv) ...@@ -318,12 +321,10 @@ int main(int argc, char **argv)
av_lfg_init(&prng, 1); av_lfg_init(&prng, 1);
for (i = 0; i < 10000; i++) { for (i = 0; i < 10000; i++) {
for (j = 0; j < 32; j++) { for (j = 0; j < 32; j++)
pt[j] = av_lfg_get(&prng); pt[j] = av_lfg_get(&prng);
} for (j = 0; j < 16; j++)
for (j = 0; j < 16; j++) {
iv[0][j] = iv[1][j] = av_lfg_get(&prng); iv[0][j] = iv[1][j] = av_lfg_get(&prng);
}
{ {
START_TIMER; START_TIMER;
av_aes_crypt(&ae, temp, pt, 2, iv[0], 0); av_aes_crypt(&ae, temp, pt, 2, iv[0], 0);
......
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
*/ */
#include "config.h" #include "config.h"
#include "common.h"
#include "bswap.h" #include "bswap.h"
#include "common.h"
#include "crc.h" #include "crc.h"
#if CONFIG_HARDCODED_TABLES #if CONFIG_HARDCODED_TABLES
...@@ -332,7 +333,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size) ...@@ -332,7 +333,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
if (ctx_size >= sizeof(AVCRC) * 1024) if (ctx_size >= sizeof(AVCRC) * 1024)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
ctx[256 *(j + 1) + i] = ctx[256 * (j + 1) + i] =
(ctx[256 * j + i] >> 8) ^ ctx[ctx[256 * j + i] & 0xFF]; (ctx[256 * j + i] >> 8) ^ ctx[ctx[256 * j + i] & 0xFF];
#endif #endif
...@@ -383,13 +384,13 @@ int main(void) ...@@ -383,13 +384,13 @@ int main(void)
{ {
uint8_t buf[1999]; uint8_t buf[1999];
int i; int i;
unsigned unsigned p[6][3] = {
p[6][3] = { { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 }, { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
{ AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0 }, { AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0 },
{ AV_CRC_24_IEEE , 0x864CFB , 0xB704CE }, { AV_CRC_24_IEEE , 0x864CFB , 0xB704CE },
{ AV_CRC_16_ANSI_LE, 0xA001 , 0xBFD8 }, { AV_CRC_16_ANSI_LE, 0xA001 , 0xBFD8 },
{ AV_CRC_16_ANSI , 0x8005 , 0x1FBB }, { AV_CRC_16_ANSI , 0x8005 , 0x1FBB },
{ AV_CRC_8_ATM , 0x07 , 0xE3 } { AV_CRC_8_ATM , 0x07 , 0xE3 }
}; };
const AVCRC *ctx; const AVCRC *ctx;
......
This diff is collapsed.
...@@ -141,7 +141,7 @@ int main(void) ...@@ -141,7 +141,7 @@ int main(void)
LOCAL_ALIGNED(32, double, var, [4]); LOCAL_ALIGNED(32, double, var, [4]);
double eval; double eval;
var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2; var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
......
...@@ -31,12 +31,13 @@ ...@@ -31,12 +31,13 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include "bswap.h" #include "bswap.h"
#include "intreadwrite.h" #include "intreadwrite.h"
#include "md5.h"
#include "mem.h" #include "mem.h"
#include "md5.h"
typedef struct AVMD5{ typedef struct AVMD5 {
uint64_t len; uint64_t len;
uint8_t block[64]; uint8_t block[64];
uint32_t ABCD[4]; uint32_t ABCD[4];
...@@ -78,16 +79,21 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32) ...@@ -78,16 +79,21 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
}; };
#define CORE(i, a, b, c, d) do { \ #define CORE(i, a, b, c, d) \
t = S[i >> 4][i & 3]; \ do { \
t = S[i >> 4][i & 3]; \
a += T[i]; \ a += T[i]; \
\ \
if (i < 32) { \ if (i < 32) { \
if (i < 16) a += (d ^ (b & (c ^ d))) + X[ i & 15]; \ if (i < 16) \
else a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15]; \ a += (d ^ (b & (c ^ d))) + X[ i & 15]; \
else \
a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15]; \
} else { \ } else { \
if (i < 48) a += (b ^ c ^ d) + X[(5 + 3*i) & 15]; \ if (i < 48) \
else a += (c ^ (b | ~d)) + X[( 7*i) & 15]; \ a += (b ^ c ^ d) + X[(5 + 3*i) & 15]; \
else \
a += (c ^ (b | ~d)) + X[( 7*i) & 15]; \
} \ } \
a = b + (a << t | a >> (32 - t)); \ a = b + (a << t | a >> (32 - t)); \
} while (0) } while (0)
...@@ -122,10 +128,13 @@ static void body(uint32_t ABCD[4], uint32_t *src, int nblocks) ...@@ -122,10 +128,13 @@ static void body(uint32_t ABCD[4], uint32_t *src, int nblocks)
} }
#else #else
#define CORE2(i) \ #define CORE2(i) \
CORE( i, a,b,c,d); CORE((i+1),d,a,b,c); \ CORE(i, a, b, c, d); CORE((i + 1), d, a, b, c); \
CORE((i+2),c,d,a,b); CORE((i+3),b,c,d,a) CORE((i + 2), c, d, a, b); CORE((i + 3), b, c, d, a)
#define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12)) #define CORE4(i) CORE2(i); CORE2((i + 4)); CORE2((i + 8)); CORE2((i + 12))
CORE4(0); CORE4(16); CORE4(32); CORE4(48); CORE4(0);
CORE4(16);
CORE4(32);
CORE4(48);
#endif #endif
ABCD[0] += d; ABCD[0] += d;
...@@ -150,7 +159,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len) ...@@ -150,7 +159,7 @@ void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
const uint8_t *end; const uint8_t *end;
int j; int j;
j = ctx->len & 63; j = ctx->len & 63;
ctx->len += len; ctx->len += len;
if (j) { if (j) {
...@@ -189,10 +198,10 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst) ...@@ -189,10 +198,10 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst)
while ((ctx->len & 63) != 56) while ((ctx->len & 63) != 56)
av_md5_update(ctx, "", 1); av_md5_update(ctx, "", 1);
av_md5_update(ctx, (uint8_t *)&finalcount, 8); av_md5_update(ctx, (uint8_t *) &finalcount, 8);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
AV_WL32(dst + 4*i, ctx->ABCD[3 - i]); AV_WL32(dst + 4 * i, ctx->ABCD[3 - i]);
} }
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len) void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
...@@ -215,7 +224,8 @@ static void print_md5(uint8_t *md5) ...@@ -215,7 +224,8 @@ static void print_md5(uint8_t *md5)
printf("\n"); printf("\n");
} }
int main(void){ int main(void)
{
uint8_t md5val[16]; uint8_t md5val[16];
int i; int i;
volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849 volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849
...@@ -223,13 +233,18 @@ int main(void){ ...@@ -223,13 +233,18 @@ int main(void){
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
in[i] = i * i; in[i] = i * i;
av_md5_sum(md5val, in, 1000); print_md5(md5val); av_md5_sum(md5val, in, 1000);
av_md5_sum(md5val, in, 63); print_md5(md5val); print_md5(md5val);
av_md5_sum(md5val, in, 64); print_md5(md5val); av_md5_sum(md5val, in, 63);
av_md5_sum(md5val, in, 65); print_md5(md5val); print_md5(md5val);
av_md5_sum(md5val, in, 64);
print_md5(md5val);
av_md5_sum(md5val, in, 65);
print_md5(md5val);
for (i = 0; i < 1000; i++) for (i = 0; i < 1000; i++)
in[i] = i % 127; in[i] = i % 127;
av_md5_sum(md5val, in, 999); print_md5(md5val); av_md5_sum(md5val, in, 999);
print_md5(md5val);
return 0; return 0;
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment