summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-07-04 00:34:44 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-07-04 00:45:21 +0200
commit976a8b217986fecdbe1fdcaa3e14ce9c3c92eb25 (patch)
treed31a42173318b29419733ec4634c1f6f07cdce6c /libavutil
parent2a375bb400febf8c1a2dfa87c29fd4185663454c (diff)
parent556f8a066cb33241bf29e85d7e24c9acf7ea9043 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (40 commits) H.264: template left MB handling H.264: faster fill_decode_caches H.264: faster write_back_* H.264: faster fill_filter_caches H.264: make filter_mb_fast support the case of unavailable top mb Do not include log.h in avutil.h Do not include pixfmt.h in avutil.h Do not include rational.h in avutil.h Do not include mathematics.h in avutil.h Do not include intfloat_readwrite.h in avutil.h Remove return statements following infinite loops without break RTSP: Doxygen comment cleanup doxygen: Escape '\' in Doxygen documentation. md5: cosmetics md5: use AV_WL32 to write result md5: add fate test md5: include correct headers md5: fix test program doxygen: Drop array size declarations from Doxygen parameter names. doxygen: Fix parameter names to match the function prototypes. ... Conflicts: libavcodec/x86/dsputil_mmx.c libavformat/flvenc.c libavformat/oggenc.c libavformat/wtv.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/aes.c51
-rw-r--r--libavutil/avutil.h4
-rw-r--r--libavutil/des.c4
-rw-r--r--libavutil/eval.c1
-rw-r--r--libavutil/file.c1
-rw-r--r--libavutil/imgutils.c1
-rw-r--r--libavutil/imgutils.h6
-rw-r--r--libavutil/lfg.h2
-rw-r--r--libavutil/md5.c136
-rw-r--r--libavutil/opt.c2
-rw-r--r--libavutil/parseutils.c2
11 files changed, 122 insertions, 88 deletions
diff --git a/libavutil/aes.c b/libavutil/aes.c
index 83c07696fd..7c92a2757f 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -54,6 +54,12 @@ static uint32_t enc_multbl[4][256];
static uint32_t dec_multbl[4][256];
#endif
+#if HAVE_BIGENDIAN
+# define ROT(x, s) ((x >> s) | (x << (32-s)))
+#else
+# define ROT(x, s) ((x << s) | (x >> (32-s)))
+#endif
+
static inline void addkey(av_aes_block *dst, const av_aes_block *src,
const av_aes_block *round_key)
{
@@ -86,7 +92,6 @@ static void subshift(av_aes_block s0[2], int s, const uint8_t *box)
static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
#if CONFIG_SMALL
-#define ROT(x,s) ((x<<s)|(x>>(32-s)))
return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
#else
return multbl[0][a] ^ multbl[1][b] ^ multbl[2][c] ^ multbl[3][d];
@@ -127,7 +132,7 @@ void av_aes_crypt(AVAES *a, uint8_t *dst_, const uint8_t *src_,
crypt(a, 0, inv_sbox, dec_multbl);
if (iv) {
addkey(&a->state[0], &a->state[0], iv);
- memcpy(iv, src, 16);
+ *iv = *src;
}
addkey(dst, &a->state[0], &a->round_key[0]);
} else {
@@ -136,29 +141,36 @@ void av_aes_crypt(AVAES *a, uint8_t *dst_, const uint8_t *src_,
crypt(a, 2, sbox, enc_multbl);
addkey(dst, &a->state[0], &a->round_key[0]);
if (iv)
- memcpy(iv, dst, 16);
+ *iv = *dst;
}
src++;
dst++;
}
}
-static void init_multbl2(uint8_t tbl[1024], const int c[4],
+static void init_multbl2(uint32_t tbl[][256], const int c[4],
const uint8_t *log8, const uint8_t *alog8,
const uint8_t *sbox)
{
- int i, j;
-
- for (i = 0; i < 1024; i++) {
- int x = sbox[i >> 2];
- if (x)
- tbl[i] = alog8[log8[x] + log8[c[i & 3]]];
- }
+ int i;
+
+ for (i = 0; i < 256; i++) {
+ int x = sbox[i];
+ if (x) {
+ int k, l, m, n;
+ x = log8[x];
+ k = alog8[x + log8[c[0]]];
+ 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));
#if !CONFIG_SMALL
- for (j = 256; j < 1024; j++)
- for (i = 0; i < 4; i++)
- tbl[4*j + i] = tbl[4*j + ((i - 1) & 3) - 1024];
+ tbl[1][i] = ROT(tbl[0][i], 8);
+ tbl[2][i] = ROT(tbl[0][i], 16);
+ tbl[3][i] = ROT(tbl[0][i], 24);
#endif
+ }
+ }
}
// this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
@@ -187,9 +199,9 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
inv_sbox[j] = i;
sbox[i] = j;
}
- init_multbl2(dec_multbl[0], (const int[4]) { 0xe, 0x9, 0xd, 0xb },
+ init_multbl2(dec_multbl, (const int[4]) { 0xe, 0x9, 0xd, 0xb },
log8, alog8, inv_sbox);
- init_multbl2(enc_multbl[0], (const int[4]) { 0x2, 0x1, 0x1, 0x3 },
+ init_multbl2(enc_multbl, (const int[4]) { 0x2, 0x1, 0x1, 0x3 },
log8, alog8, sbox);
}
@@ -221,15 +233,14 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
if (decrypt) {
for (i = 1; i < rounds; i++) {
av_aes_block tmp[3];
- memcpy(&tmp[2], &a->round_key[i], 16);
+ tmp[2] = a->round_key[i];
subshift(&tmp[1], 0, sbox);
mix(tmp, dec_multbl, 1, 3);
- memcpy(&a->round_key[i], &tmp[0], 16);
+ a->round_key[i] = tmp[0];
}
} else {
for (i = 0; i < (rounds + 1) >> 1; i++) {
- for (j = 0; j < 16; j++)
- FFSWAP(int, a->round_key[i].u8[j], a->round_key[rounds-i].u8[j]);
+ FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds-i]);
}
}
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 568f66b989..d0d5d8d3dc 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -126,9 +126,5 @@ char av_get_picture_type_char(enum AVPictureType pict_type);
#include "common.h"
#include "error.h"
#include "mathematics.h"
-#include "rational.h"
-#include "intfloat_readwrite.h"
-#include "log.h"
-#include "pixfmt.h"
#endif /* AVUTIL_AVUTIL_H */
diff --git a/libavutil/des.c b/libavutil/des.c
index f3482aebd6..15ae503466 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -39,6 +39,7 @@ static const uint8_t IP_shuffle[] = {
};
#undef T
+#if defined(CONFIG_SMALL) || defined(GENTABLES)
#define T(a, b, c, d) 32-a,32-b,32-c,32-d
static const uint8_t P_shuffle[] = {
T(16, 7, 20, 21),
@@ -51,6 +52,7 @@ static const uint8_t P_shuffle[] = {
T(22, 11, 4, 25)
};
#undef T
+#endif
#define T(a, b, c, d, e, f, g) 64-a,64-b,64-c,64-d,64-e,64-f,64-g
static const uint8_t PC1_shuffle[] = {
@@ -402,7 +404,7 @@ int main(void) {
printf("Partial Monte-Carlo test failed\n");
return 1;
}
- for (i = 0; i < 1000000; i++) {
+ for (i = 0; i < 1000; i++) {
key[0] = rand64(); key[1] = rand64(); key[2] = rand64();
data = rand64();
av_des_init(&d, key, 192, 0);
diff --git a/libavutil/eval.c b/libavutil/eval.c
index fa2999b84c..faa74a05fd 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -28,6 +28,7 @@
#include "avutil.h"
#include "eval.h"
+#include "log.h"
typedef struct Parser {
const AVClass *class;
diff --git a/libavutil/file.c b/libavutil/file.c
index ed6fa38b9c..31a3b7564f 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -17,6 +17,7 @@
*/
#include "file.h"
+#include "log.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index e04c307f62..9447779c36 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -23,6 +23,7 @@
#include "imgutils.h"
#include "internal.h"
+#include "log.h"
#include "pixdesc.h"
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index f34cb2d921..f976d210b9 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -69,7 +69,7 @@ int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int widt
*
* @param data pointers array to be filled with the pointer for each image plane
* @param ptr the pointer to a buffer which will contain the image
- * @param linesizes[4] the array containing the linesize for each
+ * @param linesizes the array containing the linesize for each
* plane, should be filled by av_image_fill_linesizes()
* @return the size in bytes required for the image buffer, a negative
* error code in case of failure
@@ -106,8 +106,8 @@ void av_image_copy_plane(uint8_t *dst, int dst_linesize,
/**
* Copy image in src_data to dst_data.
*
- * @param dst_linesize linesizes for the image in dst_data
- * @param src_linesize linesizes for the image in src_data
+ * @param dst_linesizes linesizes for the image in dst_data
+ * @param src_linesizes linesizes for the image in src_data
*/
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
const uint8_t *src_data[4], const int src_linesizes[4],
diff --git a/libavutil/lfg.h b/libavutil/lfg.h
index 0e89ea308d..854ffce737 100644
--- a/libavutil/lfg.h
+++ b/libavutil/lfg.h
@@ -55,7 +55,7 @@ static inline unsigned int av_mlfg_get(AVLFG *c){
* Get the next two numbers generated by a Box-Muller Gaussian
* generator using the random numbers issued by lfg.
*
- * @param out[2] array where the two generated numbers are placed
+ * @param out array where the two generated numbers are placed
*/
void av_bmg_get(AVLFG *lfg, double out[2]);
diff --git a/libavutil/md5.c b/libavutil/md5.c
index 173ed0623b..471a510a73 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -30,8 +30,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <string.h>
+#include <stdint.h>
#include "bswap.h"
+#include "intreadwrite.h"
#include "md5.h"
typedef struct AVMD5{
@@ -40,7 +41,7 @@ typedef struct AVMD5{
uint32_t ABCD[4];
} AVMD5;
-const int av_md5_size= sizeof(AVMD5);
+const int av_md5_size = sizeof(AVMD5);
static const uint8_t S[4][4] = {
{ 7, 12, 17, 22 }, /* round 1 */
@@ -71,42 +72,49 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
};
-#define CORE(i, a, b, c, d) \
- t = S[i>>4][i&3];\
- a += T[i];\
-\
- if(i<32){\
- if(i<16) a += (d ^ (b&(c^d))) + X[ i &15 ];\
- else a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ];\
- }else{\
- if(i<48) 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) ));
-
-static void body(uint32_t ABCD[4], uint32_t X[16]){
-
+#define CORE(i, a, b, c, d) do { \
+ t = S[i >> 4][i & 3]; \
+ a += T[i]; \
+ \
+ if (i < 32) { \
+ if (i < 16) a += (d ^ (b & (c ^ d))) + X[ i & 15]; \
+ else a += (c ^ (d & (c ^ b))) + X[(1 + 5*i) & 15]; \
+ } else { \
+ if (i < 48) 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)); \
+ } while (0)
+
+static void body(uint32_t ABCD[4], uint32_t X[16])
+{
int t;
int i av_unused;
- unsigned int a= ABCD[3];
- unsigned int b= ABCD[2];
- unsigned int c= ABCD[1];
- unsigned int d= ABCD[0];
+ unsigned int a = ABCD[3];
+ unsigned int b = ABCD[2];
+ unsigned int c = ABCD[1];
+ unsigned int d = ABCD[0];
#if HAVE_BIGENDIAN
- for(i=0; i<16; i++)
- X[i]= av_bswap32(X[i]);
+ for (i = 0; i < 16; i++)
+ X[i] = av_bswap32(X[i]);
#endif
#if CONFIG_SMALL
- for( i = 0; i < 64; i++ ){
- CORE(i,a,b,c,d)
- t=d; d=c; c=b; b=a; a=t;
+ for (i = 0; i < 64; i++) {
+ CORE(i, a, b, c, d);
+ t = d;
+ d = c;
+ c = b;
+ b = a;
+ a = t;
}
#else
-#define CORE2(i) 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)
-#define CORE4(i) CORE2(i) CORE2((i+4)) CORE2((i+8)) CORE2((i+12))
-CORE4(0) CORE4(16) CORE4(32) CORE4(48)
+#define CORE2(i) \
+ 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)
+#define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12))
+ CORE4(0); CORE4(16); CORE4(32); CORE4(48);
#endif
ABCD[0] += d;
@@ -115,8 +123,9 @@ CORE4(0) CORE4(16) CORE4(32) CORE4(48)
ABCD[3] += a;
}
-void av_md5_init(AVMD5 *ctx){
- ctx->len = 0;
+void av_md5_init(AVMD5 *ctx)
+{
+ ctx->len = 0;
ctx->ABCD[0] = 0x10325476;
ctx->ABCD[1] = 0x98badcfe;
@@ -124,59 +133,72 @@ void av_md5_init(AVMD5 *ctx){
ctx->ABCD[3] = 0x67452301;
}
-void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len){
+void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len)
+{
int i, j;
- j= ctx->len & 63;
+ j = ctx->len & 63;
ctx->len += len;
- for( i = 0; i < len; i++ ){
+ for (i = 0; i < len; i++) {
ctx->block[j++] = src[i];
- if( 64 == j ){
- body(ctx->ABCD, (uint32_t*) ctx->block);
+ if (j == 64) {
+ body(ctx->ABCD, (uint32_t *) ctx->block);
j = 0;
}
}
}
-void av_md5_final(AVMD5 *ctx, uint8_t *dst){
+void av_md5_final(AVMD5 *ctx, uint8_t *dst)
+{
int i;
- uint64_t finalcount= av_le2ne64(ctx->len<<3);
+ uint64_t finalcount = av_le2ne64(ctx->len << 3);
av_md5_update(ctx, "\200", 1);
- while((ctx->len & 63)!=56)
+ while ((ctx->len & 63) != 56)
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++)
- ((uint32_t*)dst)[i]= av_le2ne32(ctx->ABCD[3-i]);
+ for (i = 0; i < 4; i++)
+ AV_WL32(dst + 4*i, ctx->ABCD[3 - i]);
}
-void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){
- AVMD5 ctx[1];
+void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
+{
+ AVMD5 ctx;
- av_md5_init(ctx);
- av_md5_update(ctx, src, len);
- av_md5_final(ctx, dst);
+ av_md5_init(&ctx);
+ av_md5_update(&ctx, src, len);
+ av_md5_final(&ctx, dst);
}
#ifdef TEST
-#include <stdio.h>
-#include <inttypes.h>
#undef printf
+#include <stdio.h>
+
+static void print_md5(uint8_t *md5)
+{
+ int i;
+ for (i = 0; i < 16; i++)
+ printf("%02x", md5[i]);
+ printf("\n");
+}
+
int main(void){
- uint64_t md5val;
+ uint8_t md5val[16];
int i;
uint8_t in[1000];
- for(i=0; i<1000; i++) in[i]= i*i;
- av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val);
- av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%"PRId64"\n", md5val);
- av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%"PRId64"\n", md5val);
- av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val);
- for(i=0; i<1000; i++) in[i]= i % 127;
- av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val);
+ for (i = 0; i < 1000; i++)
+ in[i] = i * i;
+ av_md5_sum(md5val, in, 1000); print_md5(md5val);
+ av_md5_sum(md5val, in, 63); 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++)
+ in[i] = i % 127;
+ av_md5_sum(md5val, in, 999); print_md5(md5val);
return 0;
}
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 5215e4bc22..60fc307c0e 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -30,6 +30,7 @@
#include "opt.h"
#include "eval.h"
#include "dict.h"
+#include "log.h"
#if FF_API_FIND_OPT
//FIXME order them and do a bin search
@@ -195,7 +196,6 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
return 0;
notfirst=1;
}
- return AVERROR(EINVAL);
}
if (alloc) {
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index b2404b5c0f..69917d32e5 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -28,6 +28,7 @@
#include "avstring.h"
#include "avutil.h"
#include "eval.h"
+#include "log.h"
#include "random_seed.h"
#include "parseutils.h"
@@ -462,7 +463,6 @@ const char *small_strptime(const char *p, const char *fmt,
p++;
}
}
- return p;
}
static time_t mktimegm(struct tm *tm)