Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
3b08d9d9
Commit
3b08d9d9
authored
Mar 21, 2016
by
Diego Biurrun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testprogs: K&R formatting cosmetics
parent
43992985
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
493 additions
and
417 deletions
+493
-417
iirfilter.c
libavcodec/iirfilter.c
+62
-60
rangecoder.c
libavcodec/rangecoder.c
+1
-1
aes.c
libavutil/aes.c
+19
-18
crc.c
libavutil/crc.c
+9
-7
des.c
libavutil/des.c
+131
-137
lls.c
libavutil/lls.c
+1
-1
md5.c
libavutil/md5.c
+36
-21
opt.c
libavutil/opt.c
+234
-172
No files found.
libavcodec/iirfilter.c
View file @
3b08d9d9
...
...
@@ -24,27 +24,29 @@
* different IIR filters implementation
*/
#include "iirfilter.h"
#include <math.h>
#include "libavutil/attributes.h"
#include "libavutil/common.h"
#include "iirfilter.h"
/**
* IIR filter global parameters
*/
typedef
struct
FFIIRFilterCoeffs
{
typedef
struct
FFIIRFilterCoeffs
{
int
order
;
float
gain
;
int
*
cx
;
float
*
cy
;
}
FFIIRFilterCoeffs
;
}
FFIIRFilterCoeffs
;
/**
* IIR filter state
*/
typedef
struct
FFIIRFilterState
{
typedef
struct
FFIIRFilterState
{
float
x
[
1
];
}
FFIIRFilterState
;
}
FFIIRFilterState
;
/// maximum supported filter order
#define MAXORDER 30
...
...
@@ -61,51 +63,50 @@ static av_cold int butterworth_init_coeffs(void *avc,
if
(
filt_mode
!=
FF_FILTER_MODE_LOWPASS
)
{
av_log
(
avc
,
AV_LOG_ERROR
,
"Butterworth filter currently only supports "
"low-pass filter mode
\n
"
);
"low-pass filter mode
\n
"
);
return
-
1
;
}
if
(
order
&
1
)
{
av_log
(
avc
,
AV_LOG_ERROR
,
"Butterworth filter currently only supports "
"even filter orders
\n
"
);
"even filter orders
\n
"
);
return
-
1
;
}
wa
=
2
*
tan
(
M_PI
*
0
.
5
*
cutoff_ratio
);
c
->
cx
[
0
]
=
1
;
for
(
i
=
1
;
i
<
(
order
>>
1
)
+
1
;
i
++
)
for
(
i
=
1
;
i
<
(
order
>>
1
)
+
1
;
i
++
)
c
->
cx
[
i
]
=
c
->
cx
[
i
-
1
]
*
(
order
-
i
+
1LL
)
/
i
;
p
[
0
][
0
]
=
1
.
0
;
p
[
0
][
1
]
=
0
.
0
;
for
(
i
=
1
;
i
<=
order
;
i
++
)
for
(
i
=
1
;
i
<=
order
;
i
++
)
p
[
i
][
0
]
=
p
[
i
][
1
]
=
0
.
0
;
for
(
i
=
0
;
i
<
order
;
i
++
)
{
for
(
i
=
0
;
i
<
order
;
i
++
)
{
double
zp
[
2
];
double
th
=
(
i
+
(
order
>>
1
)
+
0
.
5
)
*
M_PI
/
order
;
double
a_re
,
a_im
,
c_re
,
c_im
;
zp
[
0
]
=
cos
(
th
)
*
wa
;
zp
[
1
]
=
sin
(
th
)
*
wa
;
a_re
=
zp
[
0
]
+
2
.
0
;
c_re
=
zp
[
0
]
-
2
.
0
;
a_im
=
c_im
=
zp
[
1
];
a_re
=
zp
[
0
]
+
2
.
0
;
c_re
=
zp
[
0
]
-
2
.
0
;
a_im
=
c_im
=
zp
[
1
];
zp
[
0
]
=
(
a_re
*
c_re
+
a_im
*
c_im
)
/
(
c_re
*
c_re
+
c_im
*
c_im
);
zp
[
1
]
=
(
a_im
*
c_re
-
a_re
*
c_im
)
/
(
c_re
*
c_re
+
c_im
*
c_im
);
for
(
j
=
order
;
j
>=
1
;
j
--
)
{
a_re
=
p
[
j
][
0
];
a_im
=
p
[
j
][
1
];
p
[
j
][
0
]
=
a_re
*
zp
[
0
]
-
a_im
*
zp
[
1
]
+
p
[
j
-
1
][
0
];
p
[
j
][
1
]
=
a_re
*
zp
[
1
]
+
a_im
*
zp
[
0
]
+
p
[
j
-
1
][
1
];
for
(
j
=
order
;
j
>=
1
;
j
--
)
{
a_re
=
p
[
j
][
0
];
a_im
=
p
[
j
][
1
];
p
[
j
][
0
]
=
a_re
*
zp
[
0
]
-
a_im
*
zp
[
1
]
+
p
[
j
-
1
][
0
];
p
[
j
][
1
]
=
a_re
*
zp
[
1
]
+
a_im
*
zp
[
0
]
+
p
[
j
-
1
][
1
];
}
a_re
=
p
[
0
][
0
]
*
zp
[
0
]
-
p
[
0
][
1
]
*
zp
[
1
];
p
[
0
][
1
]
=
p
[
0
][
0
]
*
zp
[
1
]
+
p
[
0
][
1
]
*
zp
[
0
];
a_re
=
p
[
0
][
0
]
*
zp
[
0
]
-
p
[
0
][
1
]
*
zp
[
1
];
p
[
0
][
1
]
=
p
[
0
][
0
]
*
zp
[
1
]
+
p
[
0
][
1
]
*
zp
[
0
];
p
[
0
][
0
]
=
a_re
;
}
c
->
gain
=
p
[
order
][
0
];
for
(
i
=
0
;
i
<
order
;
i
++
)
{
for
(
i
=
0
;
i
<
order
;
i
++
)
{
c
->
gain
+=
p
[
i
][
0
];
c
->
cy
[
i
]
=
(
-
p
[
i
][
0
]
*
p
[
order
][
0
]
+
-
p
[
i
][
1
]
*
p
[
order
][
1
])
/
(
p
[
order
][
0
]
*
p
[
order
][
0
]
+
p
[
order
][
1
]
*
p
[
order
][
1
]);
...
...
@@ -125,7 +126,7 @@ static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
if
(
filt_mode
!=
FF_FILTER_MODE_HIGHPASS
&&
filt_mode
!=
FF_FILTER_MODE_LOWPASS
)
{
av_log
(
avc
,
AV_LOG_ERROR
,
"Biquad filter currently only supports "
"high-pass and low-pass filter modes
\n
"
);
"high-pass and low-pass filter modes
\n
"
);
return
-
1
;
}
if
(
order
!=
2
)
{
...
...
@@ -158,11 +159,11 @@ static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
return
0
;
}
av_cold
struct
FFIIRFilterCoeffs
*
ff_iir_filter_init_coeffs
(
void
*
avc
,
enum
IIRFilterType
filt_type
,
enum
IIRFilterMode
filt_mode
,
int
order
,
float
cutoff_ratio
,
float
stopband
,
float
ripple
)
av_cold
struct
FFIIRFilterCoeffs
*
ff_iir_filter_init_coeffs
(
void
*
avc
,
enum
IIRFilterType
filt_type
,
enum
IIRFilterMode
filt_mode
,
int
order
,
float
cutoff_ratio
,
float
stopband
,
float
ripple
)
{
FFIIRFilterCoeffs
*
c
;
int
ret
=
0
;
...
...
@@ -170,12 +171,12 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
if
(
order
<=
0
||
order
>
MAXORDER
||
cutoff_ratio
>=
1
.
0
)
return
NULL
;
FF_ALLOCZ_OR_GOTO
(
avc
,
c
,
sizeof
(
FFIIRFilterCoeffs
),
init_fail
);
FF_ALLOC_OR_GOTO
(
avc
,
c
->
cx
,
sizeof
(
c
->
cx
[
0
])
*
((
order
>>
1
)
+
1
),
init_fail
);
FF_ALLOC_OR_GOTO
(
avc
,
c
->
cy
,
sizeof
(
c
->
cy
[
0
])
*
order
,
FF_ALLOCZ_OR_GOTO
(
avc
,
c
,
sizeof
(
FFIIRFilterCoeffs
),
init_fail
);
FF_ALLOC_OR_GOTO
(
avc
,
c
->
cx
,
sizeof
(
c
->
cx
[
0
])
*
((
order
>>
1
)
+
1
),
init_fail
);
FF_ALLOC_OR_GOTO
(
avc
,
c
->
cy
,
sizeof
(
c
->
cy
[
0
])
*
order
,
init_fail
);
c
->
order
=
order
;
switch
(
filt_type
)
{
...
...
@@ -200,9 +201,9 @@ init_fail:
return
NULL
;
}
av_cold
struct
FFIIRFilterState
*
ff_iir_filter_init_state
(
int
order
)
av_cold
struct
FFIIRFilterState
*
ff_iir_filter_init_state
(
int
order
)
{
FFIIRFilterState
*
s
=
av_mallocz
(
sizeof
(
FFIIRFilterState
)
+
sizeof
(
s
->
x
[
0
])
*
(
order
-
1
));
FFIIRFilterState
*
s
=
av_mallocz
(
sizeof
(
FFIIRFilterState
)
+
sizeof
(
s
->
x
[
0
])
*
(
order
-
1
));
return
s
;
}
...
...
@@ -210,17 +211,19 @@ av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
#define CONV_FLT(dest, source) dest = source;
#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt) \
in = *src0 * c->gain \
+ c->cy[0]*s->x[i0] + c->cy[1]*s->x[i1] \
+ c->cy[2]*s->x[i2] + c->cy[3]*s->x[i3]; \
res = (s->x[i0] + in )*1 \
+ (s->x[i1] + s->x[i3])*4 \
+ s->x[i2] *6; \
CONV_##fmt(*dst0, res) \
s->x[i0] = in; \
src0 += sstep; \
dst0 += dstep;
#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt) \
in = *src0 * c->gain + \
c->cy[0] * s->x[i0] + \
c->cy[1] * s->x[i1] + \
c->cy[2] * s->x[i2] + \
c->cy[3] * s->x[i3]; \
res = (s->x[i0] + in) * 1 + \
(s->x[i1] + s->x[i3]) * 4 + \
s->x[i2] * 6; \
CONV_ ## fmt(*dst0, res) \
s->x[i0] = in; \
src0 += sstep; \
dst0 += dstep;
#define FILTER_BW_O4(type, fmt) { \
int i; \
...
...
@@ -243,17 +246,17 @@ av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
int j; \
float in, res; \
in = *src0 * c->gain; \
for
(j = 0; j < c->order; j++)
\
for
(j = 0; j < c->order; j++)
\
in += c->cy[j] * s->x[j]; \
res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1]; \
for
(j = 1; j < c->order >> 1; j++)
\
for
(j = 1; j < c->order >> 1; j++)
\
res += (s->x[j] + s->x[c->order - j]) * c->cx[j]; \
for
(j = 0; j < c->order - 1; j++)
\
for
(j = 0; j < c->order - 1; j++)
\
s->x[j] = s->x[j + 1]; \
CONV_
##fmt(*dst0, res)
\
CONV_
## fmt(*dst0, res)
\
s->x[c->order - 1] = in; \
src0
+= sstep;
\
dst0
+= dstep;
\
src0
+= sstep;
\
dst0
+= dstep;
\
} \
}
...
...
@@ -265,11 +268,11 @@ av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
float in = *src0 * c->gain + \
s->x[0] * c->cy[0] + \
s->x[1] * c->cy[1]; \
CONV_
##fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1])
\
CONV_
## fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1])
\
s->x[0] = s->x[1]; \
s->x[1] = in; \
src0
+= sstep;
\
dst0
+= dstep;
\
src0
+= sstep;
\
dst0
+= dstep;
\
} \
}
...
...
@@ -306,7 +309,7 @@ av_cold void ff_iir_filter_free_state(struct FFIIRFilterState *state)
av_cold
void
ff_iir_filter_free_coeffs
(
struct
FFIIRFilterCoeffs
*
coeffs
)
{
if
(
coeffs
)
{
if
(
coeffs
)
{
av_free
(
coeffs
->
cx
);
av_free
(
coeffs
->
cy
);
}
...
...
@@ -331,9 +334,8 @@ int main(void)
cutoff_coeff
,
0
.
0
,
0
.
0
);
fstate
=
ff_iir_filter_init_state
(
FILT_ORDER
);
for
(
i
=
0
;
i
<
SIZE
;
i
++
)
{
x
[
i
]
=
lrint
(
0
.
75
*
INT16_MAX
*
sin
(
0
.
5
*
M_PI
*
i
*
i
/
SIZE
));
}
for
(
i
=
0
;
i
<
SIZE
;
i
++
)
x
[
i
]
=
lrint
(
0
.
75
*
INT16_MAX
*
sin
(
0
.
5
*
M_PI
*
i
*
i
/
SIZE
));
ff_iir_filter
(
fcoeffs
,
fstate
,
SIZE
,
x
,
1
,
y
,
1
);
...
...
libavcodec/rangecoder.c
View file @
3b08d9d9
...
...
@@ -55,7 +55,7 @@ av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf,
/* cast to avoid compiler warning */
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
;
}
...
...
libavutil/aes.c
View file @
3b08d9d9
...
...
@@ -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
);
...
...
libavutil/crc.c
View file @
3b08d9d9
...
...
@@ -19,8 +19,9 @@
*/
#include "config.h"
#include "common.h"
#include "bswap.h"
#include "common.h"
#include "crc.h"
#if CONFIG_HARDCODED_TABLES
...
...
@@ -287,7 +288,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
if
(
ctx_size
>=
sizeof
(
AVCRC
)
*
1024
)
for
(
i
=
0
;
i
<
256
;
i
++
)
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
];
#endif
...
...
@@ -338,11 +339,12 @@ int main(void)
{
uint8_t
buf
[
1999
];
int
i
;
int
p
[
5
][
3
]
=
{
{
AV_CRC_32_IEEE_LE
,
0xEDB88320
,
0x3D5CDD04
},
{
AV_CRC_32_IEEE
,
0x04C11DB7
,
0xC0F5BAE0
},
{
AV_CRC_16_ANSI_LE
,
0xA001
,
0xBFD8
},
{
AV_CRC_16_ANSI
,
0x8005
,
0x1FBB
},
{
AV_CRC_8_ATM
,
0x07
,
0xE3
}
int
p
[
5
][
3
]
=
{
{
AV_CRC_32_IEEE_LE
,
0xEDB88320
,
0x3D5CDD04
},
{
AV_CRC_32_IEEE
,
0x04C11DB7
,
0xC0F5BAE0
},
{
AV_CRC_16_ANSI_LE
,
0xA001
,
0xBFD8
},
{
AV_CRC_16_ANSI
,
0x8005
,
0x1FBB
},
{
AV_CRC_8_ATM
,
0x07
,
0xE3
}
};
const
AVCRC
*
ctx
;
...
...
libavutil/des.c
View file @
3b08d9d9
...
...
@@ -34,7 +34,7 @@ struct AVDES {
};
#endif
#define T(a, b, c, d, e, f, g, h) 64
-a,64-b,64-c,64-d,64-e,64-f,64-g,64-
h
#define T(a, b, c, d, e, f, g, h) 64
- a, 64 - b, 64 - c, 64 - d, 64 - e, 64 - f, 64 - g, 64 -
h
static
const
uint8_t
IP_shuffle
[]
=
{
T
(
58
,
50
,
42
,
34
,
26
,
18
,
10
,
2
),
T
(
60
,
52
,
44
,
36
,
28
,
20
,
12
,
4
),
...
...
@@ -48,7 +48,7 @@ static const uint8_t IP_shuffle[] = {
#undef T
#if CONFIG_SMALL || defined(GENTABLES)
#define T(a, b, c, d) 32
-a,32-b,32-c,32-
d
#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
),
T
(
29
,
12
,
28
,
17
),
...
...
@@ -62,7 +62,7 @@ static const uint8_t P_shuffle[] = {
#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
#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
[]
=
{
T
(
57
,
49
,
41
,
33
,
25
,
17
,
9
),
T
(
1
,
58
,
50
,
42
,
34
,
26
,
18
),
...
...
@@ -75,7 +75,7 @@ static const uint8_t PC1_shuffle[] = {
};
#undef T
#define T(a, b, c, d, e, f) 56
-a,56-b,56-c,56-d,56-e,56-
f
#define T(a, b, c, d, e, f) 56
- a, 56 - b, 56 - c, 56 - d, 56 - e, 56 -
f
static
const
uint8_t
PC2_shuffle
[]
=
{
T
(
14
,
17
,
11
,
24
,
1
,
5
),
T
(
3
,
28
,
15
,
6
,
21
,
10
),
...
...
@@ -90,30 +90,22 @@ static const uint8_t PC2_shuffle[] = {
#if CONFIG_SMALL
static
const
uint8_t
S_boxes
[
8
][
32
]
=
{
{
0x0e
,
0xf4
,
0x7d
,
0x41
,
0xe2
,
0x2f
,
0xdb
,
0x18
,
0xa3
,
0x6a
,
0xc6
,
0xbc
,
0x95
,
0x59
,
0x30
,
0x87
,
0xf4
,
0xc1
,
0x8e
,
0x28
,
0x4d
,
0x96
,
0x12
,
0x7b
,
0x5f
,
0xbc
,
0x39
,
0xe7
,
0xa3
,
0x0a
,
0x65
,
0xd0
,
},
{
0x3f
,
0xd1
,
0x48
,
0x7e
,
0xf6
,
0x2b
,
0x83
,
0xe4
,
0xc9
,
0x07
,
0x12
,
0xad
,
0x6c
,
0x90
,
0xb5
,
0x5a
,
0xd0
,
0x8e
,
0xa7
,
0x1b
,
0x3a
,
0xf4
,
0x4d
,
0x21
,
0xb5
,
0x68
,
0x7c
,
0xc6
,
0x09
,
0x53
,
0xe2
,
0x9f
,
},
{
0xda
,
0x70
,
0x09
,
0x9e
,
0x36
,
0x43
,
0x6f
,
0xa5
,
0x21
,
0x8d
,
0x5c
,
0xe7
,
0xcb
,
0xb4
,
0xf2
,
0x18
,
0x1d
,
0xa6
,
0xd4
,
0x09
,
0x68
,
0x9f
,
0x83
,
0x70
,
0x4b
,
0xf1
,
0xe2
,
0x3c
,
0xb5
,
0x5a
,
0x2e
,
0xc7
,
},
{
0xd7
,
0x8d
,
0xbe
,
0x53
,
0x60
,
0xf6
,
0x09
,
0x3a
,
0x41
,
0x72
,
0x28
,
0xc5
,
0x1b
,
0xac
,
0xe4
,
0x9f
,
0x3a
,
0xf6
,
0x09
,
0x60
,
0xac
,
0x1b
,
0xd7
,
0x8d
,
0x9f
,
0x41
,
0x53
,
0xbe
,
0xc5
,
0x72
,
0x28
,
0xe4
,
},
{
0xe2
,
0xbc
,
0x24
,
0xc1
,
0x47
,
0x7a
,
0xdb
,
0x16
,
0x58
,
0x05
,
0xf3
,
0xaf
,
0x3d
,
0x90
,
0x8e
,
0x69
,
0xb4
,
0x82
,
0xc1
,
0x7b
,
0x1a
,
0xed
,
0x27
,
0xd8
,
0x6f
,
0xf9
,
0x0c
,
0x95
,
0xa6
,
0x43
,
0x50
,
0x3e
,
},
{
0xac
,
0xf1
,
0x4a
,
0x2f
,
0x79
,
0xc2
,
0x96
,
0x58
,
0x60
,
0x1d
,
0xd3
,
0xe4
,
0x0e
,
0xb7
,
0x35
,
0x8b
,
0x49
,
0x3e
,
0x2f
,
0xc5
,
0x92
,
0x58
,
0xfc
,
0xa3
,
0xb7
,
0xe0
,
0x14
,
0x7a
,
0x61
,
0x0d
,
0x8b
,
0xd6
,
},
{
0xd4
,
0x0b
,
0xb2
,
0x7e
,
0x4f
,
0x90
,
0x18
,
0xad
,
0xe3
,
0x3c
,
0x59
,
0xc7
,
0x25
,
0xfa
,
0x86
,
0x61
,
0x61
,
0xb4
,
0xdb
,
0x8d
,
0x1c
,
0x43
,
0xa7
,
0x7e
,
0x9a
,
0x5f
,
0x06
,
0xf8
,
0xe0
,
0x25
,
0x39
,
0xc2
,
},
{
0x1d
,
0xf2
,
0xd8
,
0x84
,
0xa6
,
0x3f
,
0x7b
,
0x41
,
0xca
,
0x59
,
0x63
,
0xbe
,
0x05
,
0xe0
,
0x9c
,
0x27
,
0x27
,
0x1b
,
0xe4
,
0x71
,
0x49
,
0xac
,
0x8e
,
0xd2
,
0xf0
,
0xc6
,
0x9a
,
0x0d
,
0x3f
,
0x53
,
0x65
,
0xb8
,
{
0x0e
,
0xf4
,
0x7d
,
0x41
,
0xe2
,
0x2f
,
0xdb
,
0x18
,
0xa3
,
0x6a
,
0xc6
,
0xbc
,
0x95
,
0x59
,
0x30
,
0x87
,
0xf4
,
0xc1
,
0x8e
,
0x28
,
0x4d
,
0x96
,
0x12
,
0x7b
,
0x5f
,
0xbc
,
0x39
,
0xe7
,
0xa3
,
0x0a
,
0x65
,
0xd0
,
},
{
0x3f
,
0xd1
,
0x48
,
0x7e
,
0xf6
,
0x2b
,
0x83
,
0xe4
,
0xc9
,
0x07
,
0x12
,
0xad
,
0x6c
,
0x90
,
0xb5
,
0x5a
,
0xd0
,
0x8e
,
0xa7
,
0x1b
,
0x3a
,
0xf4
,
0x4d
,
0x21
,
0xb5
,
0x68
,
0x7c
,
0xc6
,
0x09
,
0x53
,
0xe2
,
0x9f
,
},
{
0xda
,
0x70
,
0x09
,
0x9e
,
0x36
,
0x43
,
0x6f
,
0xa5
,
0x21
,
0x8d
,
0x5c
,
0xe7
,
0xcb
,
0xb4
,
0xf2
,
0x18
,
0x1d
,
0xa6
,
0xd4
,
0x09
,
0x68
,
0x9f
,
0x83
,
0x70
,
0x4b
,
0xf1
,
0xe2
,
0x3c
,
0xb5
,
0x5a
,
0x2e
,
0xc7
,
},
{
0xd7
,
0x8d
,
0xbe
,
0x53
,
0x60
,
0xf6
,
0x09
,
0x3a
,
0x41
,
0x72
,
0x28
,
0xc5
,
0x1b
,
0xac
,
0xe4
,
0x9f
,
0x3a
,
0xf6
,
0x09
,
0x60
,
0xac
,
0x1b
,
0xd7
,
0x8d
,
0x9f
,
0x41
,
0x53
,
0xbe
,
0xc5
,
0x72
,
0x28
,
0xe4
,
},
{
0xe2
,
0xbc
,
0x24
,
0xc1
,
0x47
,
0x7a
,
0xdb
,
0x16
,
0x58
,
0x05
,
0xf3
,
0xaf
,
0x3d
,
0x90
,
0x8e
,
0x69
,
0xb4
,
0x82
,
0xc1
,
0x7b
,
0x1a
,
0xed
,
0x27
,
0xd8
,
0x6f
,
0xf9
,
0x0c
,
0x95
,
0xa6
,
0x43
,
0x50
,
0x3e
,
},
{
0xac
,
0xf1
,
0x4a
,
0x2f
,
0x79
,
0xc2
,
0x96
,
0x58
,
0x60
,
0x1d
,
0xd3
,
0xe4
,
0x0e
,
0xb7
,
0x35
,
0x8b
,
0x49
,
0x3e
,
0x2f
,
0xc5
,
0x92
,
0x58
,
0xfc
,
0xa3
,
0xb7
,
0xe0
,
0x14
,
0x7a
,
0x61
,
0x0d
,
0x8b
,
0xd6
,
},
{
0xd4
,
0x0b
,
0xb2
,
0x7e
,
0x4f
,
0x90
,
0x18
,
0xad
,
0xe3
,
0x3c
,
0x59
,
0xc7
,
0x25
,
0xfa
,
0x86
,
0x61
,
0x61
,
0xb4
,
0xdb
,
0x8d
,
0x1c
,
0x43
,
0xa7
,
0x7e
,
0x9a
,
0x5f
,
0x06
,
0xf8
,
0xe0
,
0x25
,
0x39
,
0xc2
,
},
{
0x1d
,
0xf2
,
0xd8
,
0x84
,
0xa6
,
0x3f
,
0x7b
,
0x41
,
0xca
,
0x59
,
0x63
,
0xbe
,
0x05
,
0xe0
,
0x9c
,
0x27
,
0x27
,
0x1b
,
0xe4
,
0x71
,
0x49
,
0xac
,
0x8e
,
0xd2
,
0xf0
,
0xc6
,
0x9a
,
0x0d
,
0x3f
,
0x53
,
0x65
,
0xb8
,
}
};
#else
...
...
@@ -122,90 +114,75 @@ static const uint8_t S_boxes[8][32] = {
* It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES
*/
static
const
uint32_t
S_boxes_P_shuffle
[
8
][
64
]
=
{
{
0x00808200
,
0x00000000
,
0x00008000
,
0x00808202
,
0x00808002
,
0x00008202
,
0x00000002
,
0x00008000
,
0x00000200
,
0x00808200
,
0x00808202
,
0x00000200
,
0x00800202
,
0x00808002
,
0x00800000
,
0x00000002
,
0x00000202
,
0x00800200
,
0x00800200
,
0x00008200
,
0x00008200
,
0x00808000
,
0x00808000
,
0x00800202
,
0x00008002
,
0x00800002
,
0x00800002
,
0x00008002
,
0x00000000
,
0x00000202
,
0x00008202
,
0x00800000
,
0x00008000
,
0x00808202
,
0x00000002
,
0x00808000
,
0x00808200
,
0x00800000
,
0x00800000
,
0x00000200
,
0x00808002
,
0x00008000
,
0x00008200
,
0x00800002
,
0x00000200
,
0x00000002
,
0x00800202
,
0x00008202
,
0x00808202
,
0x00008002
,
0x00808000
,
0x00800202
,
0x00800002
,
0x00000202
,
0x00008202
,
0x00808200
,
0x00000202
,
0x00800200
,
0x00800200
,
0x00000000
,
0x00008002
,
0x00008200
,
0x00000000
,
0x00808002
,
},
{
0x40084010
,
0x40004000
,
0x00004000
,
0x00084010
,
0x00080000
,
0x00000010
,
0x40080010
,
0x40004010
,
0x40000010
,
0x40084010
,
0x40084000
,
0x40000000
,
0x40004000
,
0x00080000
,
0x00000010
,
0x40080010
,
0x00084000
,
0x00080010
,
0x40004010
,
0x00000000
,
0x40000000
,
0x00004000
,
0x00084010
,
0x40080000
,
0x00080010
,
0x40000010
,
0x00000000
,
0x00084000
,
0x00004010
,
0x40084000
,
0x40080000
,
0x00004010
,
0x00000000
,
0x00084010
,
0x40080010
,
0x00080000
,
0x40004010
,
0x40080000
,
0x40084000
,
0x00004000
,
0x40080000
,
0x40004000
,
0x00000010
,
0x40084010
,
0x00084010
,
0x00000010
,
0x00004000
,
0x40000000
,
0x00004010
,
0x40084000
,
0x00080000
,
0x40000010
,
0x00080010
,
0x40004010
,
0x40000010
,
0x00080010
,
0x00084000
,
0x00000000
,
0x40004000
,
0x00004010
,
0x40000000
,
0x40080010
,
0x40084010
,
0x00084000
,
},
{
0x00000104
,
0x04010100
,
0x00000000
,
0x04010004
,
0x04000100
,
0x00000000
,
0x00010104
,
0x04000100
,
0x00010004
,
0x04000004
,
0x04000004
,
0x00010000
,
0x04010104
,
0x00010004
,
0x04010000
,
0x00000104
,
0x04000000
,
0x00000004
,
0x04010100
,
0x00000100
,
0x00010100
,
0x04010000
,
0x04010004
,
0x00010104
,
0x04000104
,
0x00010100
,
0x00010000
,
0x04000104
,
0x00000004
,
0x04010104
,
0x00000100
,
0x04000000
,
0x04010100
,
0x04000000
,
0x00010004
,
0x00000104
,
0x00010000
,
0x04010100
,
0x04000100
,
0x00000000
,
0x00000100
,
0x00010004
,
0x04010104
,
0x04000100
,
0x04000004
,
0x00000100
,
0x00000000
,
0x04010004
,
0x04000104
,
0x00010000
,
0x04000000
,
0x04010104
,
0x00000004
,
0x00010104
,
0x00010100
,
0x04000004
,
0x04010000
,
0x04000104
,
0x00000104
,
0x04010000
,
0x00010104
,
0x00000004
,
0x04010004
,
0x00010100
,
},
{
0x80401000
,
0x80001040
,
0x80001040
,
0x00000040
,
0x00401040
,
0x80400040
,
0x80400000
,
0x80001000
,
0x00000000
,
0x00401000
,
0x00401000
,
0x80401040
,
0x80000040
,
0x00000000
,
0x00400040
,
0x80400000
,
0x80000000
,
0x00001000
,
0x00400000
,
0x80401000
,
0x00000040
,
0x00400000
,
0x80001000
,
0x00001040
,
0x80400040
,
0x80000000
,
0x00001040
,
0x00400040
,
0x00001000
,
0x00401040
,
0x80401040
,
0x80000040
,
0x00400040
,
0x80400000
,
0x00401000
,
0x80401040
,
0x80000040
,
0x00000000
,
0x00000000
,
0x00401000
,
0x00001040
,
0x00400040
,
0x80400040
,
0x80000000
,
0x80401000
,
0x80001040
,
0x80001040
,
0x00000040
,
0x80401040
,
0x80000040
,
0x80000000
,
0x00001000
,
0x80400000
,
0x80001000
,
0x00401040
,
0x80400040
,
0x80001000
,
0x00001040
,
0x00400000
,
0x80401000
,
0x00000040
,
0x00400000
,
0x00001000
,
0x00401040
,
},
{
0x00000080
,
0x01040080
,
0x01040000
,
0x21000080
,
0x00040000
,
0x00000080
,
0x20000000
,
0x01040000
,
0x20040080
,
0x00040000
,
0x01000080
,
0x20040080
,
0x21000080
,
0x21040000
,
0x00040080
,
0x20000000
,
0x01000000
,
0x20040000
,
0x20040000
,
0x00000000
,
0x20000080
,
0x21040080
,
0x21040080
,
0x01000080
,
0x21040000
,
0x20000080
,
0x00000000
,
0x21000000
,
0x01040080
,
0x01000000
,
0x21000000
,
0x00040080
,
0x00040000
,
0x21000080
,
0x00000080
,
0x01000000
,
0x20000000
,
0x01040000
,
0x21000080
,
0x20040080
,
0x01000080
,
0x20000000
,
0x21040000
,
0x01040080
,
0x20040080
,
0x00000080
,
0x01000000
,
0x21040000
,
0x21040080
,
0x00040080
,
0x21000000
,
0x21040080
,
0x01040000
,
0x00000000
,
0x20040000
,
0x21000000
,
0x00040080
,
0x01000080
,
0x20000080
,
0x00040000
,
0x00000000
,
0x20040000
,
0x01040080
,
0x20000080
,
},
{
0x10000008
,
0x10200000
,
0x00002000
,
0x10202008
,
0x10200000
,
0x00000008
,
0x10202008
,
0x00200000
,
0x10002000
,
0x00202008
,
0x00200000
,
0x10000008
,
0x00200008
,
0x10002000
,
0x10000000
,
0x00002008
,
0x00000000
,
0x00200008
,
0x10002008
,
0x00002000
,
0x00202000
,
0x10002008
,
0x00000008
,
0x10200008
,
0x10200008
,
0x00000000
,
0x00202008
,
0x10202000
,
0x00002008
,
0x00202000
,
0x10202000
,
0x10000000
,
0x10002000
,
0x00000008
,
0x10200008
,
0x00202000
,
0x10202008
,
0x00200000
,
0x00002008
,
0x10000008
,
0x00200000
,
0x10002000
,
0x10000000
,
0x00002008
,
0x10000008
,
0x10202008
,
0x00202000
,
0x10200000
,
0x00202008
,
0x10202000
,
0x00000000
,
0x10200008
,
0x00000008
,
0x00002000
,
0x10200000
,
0x00202008
,
0x00002000
,
0x00200008
,
0x10002008
,
0x00000000
,
0x10202000
,
0x10000000
,
0x00200008
,
0x10002008
,
},
{
0x00100000
,
0x02100001
,
0x02000401
,
0x00000000
,
0x00000400
,
0x02000401
,
0x00100401
,
0x02100400
,
0x02100401
,
0x00100000
,
0x00000000
,
0x02000001
,
0x00000001
,
0x02000000
,
0x02100001
,
0x00000401
,
0x02000400
,
0x00100401
,
0x00100001
,
0x02000400
,
0x02000001
,
0x02100000
,
0x02100400
,
0x00100001
,
0x02100000
,
0x00000400
,
0x00000401
,
0x02100401
,
0x00100400
,
0x00000001
,
0x02000000
,
0x00100400
,
0x02000000
,
0x00100400
,
0x00100000
,
0x02000401
,
0x02000401
,
0x02100001
,
0x02100001
,
0x00000001
,
0x00100001
,
0x02000000
,
0x02000400
,
0x00100000
,
0x02100400
,
0x00000401
,
0x00100401
,
0x02100400
,
0x00000401
,
0x02000001
,
0x02100401
,
0x02100000
,
0x00100400
,
0x00000000
,
0x00000001
,
0x02100401
,
0x00000000
,
0x00100401
,
0x02100000
,
0x00000400
,
0x02000001
,
0x02000400
,
0x00000400
,
0x00100001
,
},
{
0x08000820
,
0x00000800
,
0x00020000
,
0x08020820
,
0x08000000
,
0x08000820
,
0x00000020
,
0x08000000
,
0x00020020
,
0x08020000
,
0x08020820
,
0x00020800
,
0x08020800
,
0x00020820
,
0x00000800
,
0x00000020
,
0x08020000
,
0x08000020
,
0x08000800
,
0x00000820
,
0x00020800
,
0x00020020
,
0x08020020
,
0x08020800
,
0x00000820
,
0x00000000
,
0x00000000
,
0x08020020
,
0x08000020
,
0x08000800
,
0x00020820
,
0x00020000
,
0x00020820
,
0x00020000
,
0x08020800
,
0x00000800
,
0x00000020
,
0x08020020
,
0x00000800
,
0x00020820
,
0x08000800
,
0x00000020
,
0x08000020
,
0x08020000
,
0x08020020
,
0x08000000
,
0x00020000
,
0x08000820
,
0x00000000
,
0x08020820
,
0x00020020
,
0x08000020
,
0x08020000
,
0x08000800
,
0x08000820
,
0x00000000
,
0x08020820
,
0x00020800
,
0x00020800
,
0x00000820
,
0x00000820
,
0x00020020
,
0x08000000
,
0x08020800
,
},
{
0x00808200
,
0x00000000
,
0x00008000
,
0x00808202
,
0x00808002
,
0x00008202
,
0x00000002
,
0x00008000
,
0x00000200
,
0x00808200
,
0x00808202
,
0x00000200
,
0x00800202
,
0x00808002
,
0x00800000
,
0x00000002
,
0x00000202
,
0x00800200
,
0x00800200
,
0x00008200
,
0x00008200
,
0x00808000
,
0x00808000
,
0x00800202
,
0x00008002
,
0x00800002
,
0x00800002
,
0x00008002
,
0x00000000
,
0x00000202
,
0x00008202
,
0x00800000
,
0x00008000
,
0x00808202
,
0x00000002
,
0x00808000
,
0x00808200
,
0x00800000
,
0x00800000
,
0x00000200
,
0x00808002
,
0x00008000
,
0x00008200
,
0x00800002
,
0x00000200
,
0x00000002
,
0x00800202
,
0x00008202
,
0x00808202
,
0x00008002
,
0x00808000
,
0x00800202
,
0x00800002
,
0x00000202
,
0x00008202
,
0x00808200
,
0x00000202
,
0x00800200
,
0x00800200
,
0x00000000
,
0x00008002
,
0x00008200
,
0x00000000
,
0x00808002
,
},
{
0x40084010
,
0x40004000
,
0x00004000
,
0x00084010
,
0x00080000
,
0x00000010
,
0x40080010
,
0x40004010
,
0x40000010
,
0x40084010
,
0x40084000
,
0x40000000
,
0x40004000
,
0x00080000
,
0x00000010
,
0x40080010
,
0x00084000
,
0x00080010
,
0x40004010
,
0x00000000
,
0x40000000
,
0x00004000
,
0x00084010
,
0x40080000
,
0x00080010
,
0x40000010
,
0x00000000
,
0x00084000
,
0x00004010
,
0x40084000
,
0x40080000
,
0x00004010
,
0x00000000
,
0x00084010
,
0x40080010
,
0x00080000
,
0x40004010
,
0x40080000
,
0x40084000
,
0x00004000
,
0x40080000
,
0x40004000
,
0x00000010
,
0x40084010
,
0x00084010
,
0x00000010
,
0x00004000
,
0x40000000
,
0x00004010
,
0x40084000
,
0x00080000
,
0x40000010
,
0x00080010
,
0x40004010
,
0x40000010
,
0x00080010
,
0x00084000
,
0x00000000
,
0x40004000
,
0x00004010
,
0x40000000
,
0x40080010
,
0x40084010
,
0x00084000
,
},
{
0x00000104
,
0x04010100
,
0x00000000
,
0x04010004
,
0x04000100
,
0x00000000
,
0x00010104
,
0x04000100
,
0x00010004
,
0x04000004
,
0x04000004
,
0x00010000
,
0x04010104
,
0x00010004
,
0x04010000
,
0x00000104
,
0x04000000
,
0x00000004
,
0x04010100
,
0x00000100
,
0x00010100
,
0x04010000
,
0x04010004
,
0x00010104
,
0x04000104
,
0x00010100
,
0x00010000
,
0x04000104
,
0x00000004
,
0x04010104
,
0x00000100
,
0x04000000
,
0x04010100
,
0x04000000
,
0x00010004
,
0x00000104
,
0x00010000
,
0x04010100
,
0x04000100
,
0x00000000
,
0x00000100
,
0x00010004
,
0x04010104
,
0x04000100
,
0x04000004
,
0x00000100
,
0x00000000
,
0x04010004
,
0x04000104
,
0x00010000
,
0x04000000
,
0x04010104
,
0x00000004
,
0x00010104
,
0x00010100
,
0x04000004
,
0x04010000
,
0x04000104
,
0x00000104
,
0x04010000
,
0x00010104
,
0x00000004
,
0x04010004
,
0x00010100
,
},
{
0x80401000
,
0x80001040
,
0x80001040
,
0x00000040
,
0x00401040
,
0x80400040
,
0x80400000
,
0x80001000
,
0x00000000
,
0x00401000
,
0x00401000
,
0x80401040
,
0x80000040
,
0x00000000
,
0x00400040
,
0x80400000
,
0x80000000
,
0x00001000
,
0x00400000
,
0x80401000
,
0x00000040
,
0x00400000
,
0x80001000
,
0x00001040
,
0x80400040
,
0x80000000
,
0x00001040
,
0x00400040
,
0x00001000
,
0x00401040
,
0x80401040
,
0x80000040
,
0x00400040
,
0x80400000
,
0x00401000
,
0x80401040
,
0x80000040
,
0x00000000
,
0x00000000
,
0x00401000
,
0x00001040
,
0x00400040
,
0x80400040
,
0x80000000
,
0x80401000
,
0x80001040
,
0x80001040
,
0x00000040
,
0x80401040
,
0x80000040
,
0x80000000
,
0x00001000
,
0x80400000
,
0x80001000
,
0x00401040
,
0x80400040
,
0x80001000
,
0x00001040
,
0x00400000
,
0x80401000
,
0x00000040
,
0x00400000
,
0x00001000
,
0x00401040
,
},
{
0x00000080
,
0x01040080
,
0x01040000
,
0x21000080
,
0x00040000
,
0x00000080
,
0x20000000
,
0x01040000
,
0x20040080
,
0x00040000
,
0x01000080
,
0x20040080
,
0x21000080
,
0x21040000
,
0x00040080
,
0x20000000
,
0x01000000
,
0x20040000
,
0x20040000
,
0x00000000
,
0x20000080
,
0x21040080
,
0x21040080
,
0x01000080
,
0x21040000
,
0x20000080
,
0x00000000
,
0x21000000
,
0x01040080
,
0x01000000
,
0x21000000
,
0x00040080
,
0x00040000
,
0x21000080
,
0x00000080
,
0x01000000
,
0x20000000
,
0x01040000
,
0x21000080
,
0x20040080
,
0x01000080
,
0x20000000
,
0x21040000
,
0x01040080
,
0x20040080
,
0x00000080
,
0x01000000
,
0x21040000
,
0x21040080
,
0x00040080
,
0x21000000
,
0x21040080
,
0x01040000
,
0x00000000
,
0x20040000
,
0x21000000
,
0x00040080
,
0x01000080
,
0x20000080
,
0x00040000
,
0x00000000
,
0x20040000
,
0x01040080
,
0x20000080
,
},
{
0x10000008
,
0x10200000
,
0x00002000
,
0x10202008
,
0x10200000
,
0x00000008
,
0x10202008
,
0x00200000
,
0x10002000
,
0x00202008
,
0x00200000
,
0x10000008
,
0x00200008
,
0x10002000
,
0x10000000
,
0x00002008
,
0x00000000
,
0x00200008
,
0x10002008
,
0x00002000
,
0x00202000
,
0x10002008
,
0x00000008
,
0x10200008
,
0x10200008
,
0x00000000
,
0x00202008
,
0x10202000
,
0x00002008
,
0x00202000
,
0x10202000
,
0x10000000
,
0x10002000
,
0x00000008
,
0x10200008
,
0x00202000
,
0x10202008
,
0x00200000
,
0x00002008
,
0x10000008
,
0x00200000
,
0x10002000
,
0x10000000
,
0x00002008
,
0x10000008
,
0x10202008
,
0x00202000
,
0x10200000
,
0x00202008
,
0x10202000
,
0x00000000
,
0x10200008
,
0x00000008
,
0x00002000
,
0x10200000
,
0x00202008
,
0x00002000
,
0x00200008
,
0x10002008
,
0x00000000
,
0x10202000
,
0x10000000
,
0x00200008
,
0x10002008
,
},
{
0x00100000
,
0x02100001
,
0x02000401
,
0x00000000
,
0x00000400
,
0x02000401
,
0x00100401
,
0x02100400
,
0x02100401
,
0x00100000
,
0x00000000
,
0x02000001
,
0x00000001
,
0x02000000
,
0x02100001
,
0x00000401
,
0x02000400
,
0x00100401
,
0x00100001
,
0x02000400
,
0x02000001
,
0x02100000
,
0x02100400
,
0x00100001
,
0x02100000
,
0x00000400
,
0x00000401
,
0x02100401
,
0x00100400
,
0x00000001
,
0x02000000
,
0x00100400
,
0x02000000
,
0x00100400
,
0x00100000
,
0x02000401
,
0x02000401
,
0x02100001
,
0x02100001
,
0x00000001
,
0x00100001
,
0x02000000
,
0x02000400
,
0x00100000
,
0x02100400
,
0x00000401
,
0x00100401
,
0x02100400
,
0x00000401
,
0x02000001
,
0x02100401
,
0x02100000
,
0x00100400
,
0x00000000
,
0x00000001
,
0x02100401
,
0x00000000
,
0x00100401
,
0x02100000
,
0x00000400
,
0x02000001
,
0x02000400
,
0x00000400
,
0x00100001
,
},
{
0x08000820
,
0x00000800
,
0x00020000
,
0x08020820
,
0x08000000
,
0x08000820
,
0x00000020
,
0x08000000
,
0x00020020
,
0x08020000
,
0x08020820
,
0x00020800
,
0x08020800
,
0x00020820
,
0x00000800
,
0x00000020
,
0x08020000
,
0x08000020
,
0x08000800
,
0x00000820
,
0x00020800
,
0x00020020
,
0x08020020
,
0x08020800
,
0x00000820
,
0x00000000
,
0x00000000
,
0x08020020
,
0x08000020
,
0x08000800
,
0x00020820
,
0x00020000
,
0x00020820
,
0x00020000
,
0x08020800
,
0x00000800
,
0x00000020
,
0x08020020
,
0x00000800
,
0x00020820
,
0x08000800
,
0x00000020
,
0x08000020
,
0x08020000
,
0x08020020
,
0x08000000
,
0x00020000
,
0x08000820
,
0x00000000
,
0x08020820
,
0x00020020
,
0x08000020
,
0x08020000
,
0x08000800
,
0x08000820
,
0x00000000
,
0x08020820
,
0x00020800
,
0x00020800
,
0x00000820
,
0x00000820
,
0x00020020
,
0x08000000
,
0x08020800
,
},
};
#endif
static
uint64_t
shuffle
(
uint64_t
in
,
const
uint8_t
*
shuffle
,
int
shuffle_len
)
{
static
uint64_t
shuffle
(
uint64_t
in
,
const
uint8_t
*
shuffle
,
int
shuffle_len
)
{
int
i
;
uint64_t
res
=
0
;
for
(
i
=
0
;
i
<
shuffle_len
;
i
++
)
...
...
@@ -213,7 +190,8 @@ static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len) {
return
res
;
}
static
uint64_t
shuffle_inv
(
uint64_t
in
,
const
uint8_t
*
shuffle
,
int
shuffle_len
)
{
static
uint64_t
shuffle_inv
(
uint64_t
in
,
const
uint8_t
*
shuffle
,
int
shuffle_len
)
{
int
i
;
uint64_t
res
=
0
;
shuffle
+=
shuffle_len
-
1
;
...
...
@@ -224,7 +202,8 @@ static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len
return
res
;
}
static
uint32_t
f_func
(
uint32_t
r
,
uint64_t
k
)
{
static
uint32_t
f_func
(
uint32_t
r
,
uint64_t
k
)
{
int
i
;
uint32_t
out
=
0
;
// rotate to get first part of E-shuffle in the lowest 6 bits
...
...
@@ -234,13 +213,14 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
uint8_t
tmp
=
(
r
^
k
)
&
0x3f
;
#if CONFIG_SMALL
uint8_t
v
=
S_boxes
[
i
][
tmp
>>
1
];
if
(
tmp
&
1
)
v
>>=
4
;
if
(
tmp
&
1
)
v
>>=
4
;
out
=
(
out
>>
4
)
|
(
v
<<
28
);
#else
out
|=
S_boxes_P_shuffle
[
i
][
tmp
];
#endif
// get next 6 bits of E-shuffle and round key k into the lowest bits
r
=
(
r
>>
4
)
|
(
r
<<
28
);
r
=
(
r
>>
4
)
|
(
r
<<
28
);
k
>>=
6
;
}
#if CONFIG_SMALL
...
...
@@ -255,15 +235,17 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
* Note: the specification calls this "shift", so I kept it although
* it is confusing.
*/
static
uint64_t
key_shift_left
(
uint64_t
CDn
)
{
static
uint64_t
key_shift_left
(
uint64_t
CDn
)
{
uint64_t
carries
=
(
CDn
>>
27
)
&
0x10000001
;
CDn
<<=
1
;
CDn
&=
~
0x10000001
;
CDn
|=
carries
;
CDn
&=
~
0x10000001
;
CDn
|=
carries
;
return
CDn
;
}
static
void
gen_roundkeys
(
uint64_t
K
[
16
],
uint64_t
key
)
{
static
void
gen_roundkeys
(
uint64_t
K
[
16
],
uint64_t
key
)
{
int
i
;
// discard parity bits from key and shuffle it into C and D parts
uint64_t
CDn
=
shuffle
(
key
,
PC1_shuffle
,
sizeof
(
PC1_shuffle
));
...
...
@@ -276,7 +258,8 @@ static void gen_roundkeys(uint64_t K[16], uint64_t key) {
}
}
static
uint64_t
des_encdec
(
uint64_t
in
,
uint64_t
K
[
16
],
int
decrypt
)
{
static
uint64_t
des_encdec
(
uint64_t
in
,
uint64_t
K
[
16
],
int
decrypt
)
{
int
i
;
// used to apply round keys in reverse order for decryption
decrypt
=
decrypt
?
15
:
0
;
...
...
@@ -285,8 +268,8 @@ static uint64_t des_encdec(uint64_t in, uint64_t K[16], int decrypt) {
for
(
i
=
0
;
i
<
16
;
i
++
)
{
uint32_t
f_res
;
f_res
=
f_func
(
in
,
K
[
decrypt
^
i
]);
in
=
(
in
<<
32
)
|
(
in
>>
32
);
in
^=
f_res
;
in
=
(
in
<<
32
)
|
(
in
>>
32
);
in
^=
f_res
;
}
in
=
(
in
<<
32
)
|
(
in
>>
32
);
// reverse shuffle used to ease hardware implementations
...
...
@@ -299,7 +282,8 @@ AVDES *av_des_alloc(void)
return
av_mallocz
(
sizeof
(
struct
AVDES
));
}
int
av_des_init
(
AVDES
*
d
,
const
uint8_t
*
key
,
int
key_bits
,
int
decrypt
)
{
int
av_des_init
(
AVDES
*
d
,
const
uint8_t
*
key
,
int
key_bits
,
int
decrypt
)
{
if
(
key_bits
!=
64
&&
key_bits
!=
192
)
return
-
1
;
d
->
triple_des
=
key_bits
>
64
;
...
...
@@ -311,7 +295,9 @@ int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) {
return
0
;
}
static
void
av_des_crypt_mac
(
AVDES
*
d
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
,
int
mac
)
{
static
void
av_des_crypt_mac
(
AVDES
*
d
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
,
int
mac
)
{
uint64_t
iv_val
=
iv
?
AV_RB64
(
iv
)
:
0
;
while
(
count
--
>
0
)
{
uint64_t
dst_val
;
...
...
@@ -323,7 +309,7 @@ static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int cou
src_val
=
des_encdec
(
src_val
,
d
->
round_keys
[
1
],
0
);
}
dst_val
=
des_encdec
(
src_val
,
d
->
round_keys
[
0
],
1
)
^
iv_val
;
iv_val
=
iv
?
tmp
:
0
;
iv_val
=
iv
?
tmp
:
0
;
}
else
{
dst_val
=
des_encdec
(
src_val
^
iv_val
,
d
->
round_keys
[
0
],
0
);
if
(
d
->
triple_des
)
{
...
...
@@ -341,12 +327,15 @@ static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int cou
AV_WB64
(
iv
,
iv_val
);
}
void
av_des_crypt
(
AVDES
*
d
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
)
{
void
av_des_crypt
(
AVDES
*
d
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
)
{
av_des_crypt_mac
(
d
,
dst
,
src
,
count
,
iv
,
decrypt
,
0
);
}
void
av_des_mac
(
AVDES
*
d
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
)
{
av_des_crypt_mac
(
d
,
dst
,
src
,
count
,
(
uint8_t
[
8
]){
0
},
0
,
1
);
void
av_des_mac
(
AVDES
*
d
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
)
{
av_des_crypt_mac
(
d
,
dst
,
src
,
count
,
(
uint8_t
[
8
])
{
0
},
0
,
1
);
}
#ifdef TEST
...
...
@@ -355,15 +344,16 @@ void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) {
#include "time.h"
static
uint64_t
rand64
(
void
)
{
static
uint64_t
rand64
(
void
)
{
uint64_t
r
=
rand
();
r
=
(
r
<<
32
)
|
rand
();
return
r
;
}
static
const
uint8_t
test_key
[]
=
{
0x12
,
0x34
,
0x56
,
0x78
,
0x9a
,
0xbc
,
0xde
,
0xf0
};
static
const
DECLARE_ALIGNED
(
8
,
uint8_t
,
plain
)[]
=
{
0xfe
,
0xdc
,
0xba
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
};
static
const
DECLARE_ALIGNED
(
8
,
uint8_t
,
crypt
)[]
=
{
0x4a
,
0xb6
,
0x5b
,
0x3d
,
0x4b
,
0x06
,
0x15
,
0x18
};
static
const
uint8_t
test_key
[]
=
{
0x12
,
0x34
,
0x56
,
0x78
,
0x9a
,
0xbc
,
0xde
,
0xf0
};
static
const
DECLARE_ALIGNED
(
8
,
uint8_t
,
plain
)[]
=
{
0xfe
,
0xdc
,
0xba
,
0x98
,
0x76
,
0x54
,
0x32
,
0x10
};
static
const
DECLARE_ALIGNED
(
8
,
uint8_t
,
crypt
)[]
=
{
0x4a
,
0xb6
,
0x5b
,
0x3d
,
0x4b
,
0x06
,
0x15
,
0x18
};
static
DECLARE_ALIGNED
(
8
,
uint8_t
,
tmp
)[
8
];
static
DECLARE_ALIGNED
(
8
,
uint8_t
,
large_buffer
)[
10002
][
8
];
static
const
uint8_t
cbc_key
[]
=
{
...
...
@@ -372,7 +362,8 @@ static const uint8_t cbc_key[] = {
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
};
static
int
run_test
(
int
cbc
,
int
decrypt
)
{
static
int
run_test
(
int
cbc
,
int
decrypt
)
{
AVDES
d
;
int
delay
=
cbc
&&
!
decrypt
?
2
:
1
;
uint64_t
res
;
...
...
@@ -395,7 +386,8 @@ static int run_test(int cbc, int decrypt) {
}
}
int
main
(
void
)
{
int
main
(
void
)
{
AVDES
d
;
int
i
;
uint64_t
key
[
3
];
...
...
@@ -404,7 +396,7 @@ int main(void) {
uint64_t
roundkeys
[
16
];
srand
(
av_gettime
());
key
[
0
]
=
AV_RB64
(
test_key
);
data
=
AV_RB64
(
plain
);
data
=
AV_RB64
(
plain
);
gen_roundkeys
(
roundkeys
,
key
[
0
]);
if
(
des_encdec
(
data
,
roundkeys
,
0
)
!=
AV_RB64
(
crypt
))
{
printf
(
"Test 1 failed
\n
"
);
...
...
@@ -421,8 +413,10 @@ int main(void) {
return
1
;
}
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
key
[
0
]
=
rand64
();
key
[
1
]
=
rand64
();
key
[
2
]
=
rand64
();
data
=
rand64
();
key
[
0
]
=
rand64
();
key
[
1
]
=
rand64
();
key
[
2
]
=
rand64
();
data
=
rand64
();
av_des_init
(
&
d
,
key
,
192
,
0
);
av_des_crypt
(
&
d
,
&
ct
,
&
data
,
1
,
NULL
,
0
);
av_des_init
(
&
d
,
key
,
192
,
1
);
...
...
@@ -439,9 +433,9 @@ int main(void) {
printf
(
" {"
);
for
(
j
=
0
;
j
<
64
;
j
++
)
{
uint32_t
v
=
S_boxes
[
i
][
j
>>
1
];
v
=
j
&
1
?
v
>>
4
:
v
&
0xf
;
v
=
j
&
1
?
v
>>
4
:
v
&
0xf
;
v
<<=
28
-
4
*
i
;
v
=
shuffle
(
v
,
P_shuffle
,
sizeof
(
P_shuffle
));
v
=
shuffle
(
v
,
P_shuffle
,
sizeof
(
P_shuffle
));
printf
((
j
&
7
)
==
0
?
"
\n
"
:
" "
);
printf
(
"0x%08X,"
,
v
);
}
...
...
libavutil/lls.c
View file @
3b08d9d9
...
...
@@ -141,7 +141,7 @@ int main(void)
LOCAL_ALIGNED
(
32
,
double
,
var
,
[
4
]);
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
[
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
;
...
...
libavutil/md5.c
View file @
3b08d9d9
...
...
@@ -31,12 +31,13 @@
*/
#include <stdint.h>
#include "bswap.h"
#include "intreadwrite.h"
#include "md5.h"
#include "mem.h"
#include "md5.h"
typedef
struct
AVMD5
{
typedef
struct
AVMD5
{
uint64_t
len
;
uint8_t
block
[
64
];
uint32_t
ABCD
[
4
];
...
...
@@ -76,16 +77,21 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32)
0xf7537e82
,
0xbd3af235
,
0x2ad7d2bb
,
0xeb86d391
,
};
#define CORE(i, a, b, c, d) do { \
t = S[i >> 4][i & 3]; \
#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]; \
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]; \
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)
...
...
@@ -115,10 +121,13 @@ static void body(uint32_t ABCD[4], uint32_t X[16])
}
#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
);
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
;
...
...
@@ -141,7 +150,7 @@ 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
++
)
{
...
...
@@ -162,10 +171,10 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst)
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
++
)
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
)
...
...
@@ -188,20 +197,26 @@ static void print_md5(uint8_t *md5)
printf
(
"
\n
"
);
}
int
main
(
void
){
int
main
(
void
)
{
uint8_t
md5val
[
16
];
int
i
;
uint8_t
in
[
1000
];
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
);
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
);
av_md5_sum
(
md5val
,
in
,
999
);
print_md5
(
md5val
);
return
0
;
}
...
...
libavutil/opt.c
View file @
3b08d9d9
...
...
@@ -25,18 +25,18 @@
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "avutil.h"
#include "avstring.h"
#include "avutil.h"
#include "common.h"
#include "opt.h"
#include "eval.h"
#include "dict.h"
#include "eval.h"
#include "log.h"
#include "mathematics.h"
#include "opt.h"
const
AVOption
*
av_opt_next
(
const
void
*
obj
,
const
AVOption
*
last
)
{
AVClass
*
class
=
*
(
AVClass
**
)
obj
;
AVClass
*
class
=
*
(
AVClass
**
)
obj
;
if
(
!
last
&&
class
->
option
&&
class
->
option
[
0
].
name
)
return
class
->
option
;
if
(
last
&&
last
[
1
].
name
)
...
...
@@ -47,14 +47,25 @@ const AVOption *av_opt_next(const void *obj, const AVOption *last)
static
int
read_number
(
const
AVOption
*
o
,
const
void
*
dst
,
double
*
num
,
int
*
den
,
int64_t
*
intnum
)
{
switch
(
o
->
type
)
{
case
AV_OPT_TYPE_FLAGS
:
*
intnum
=
*
(
unsigned
int
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_INT
:
*
intnum
=
*
(
int
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_INT64
:
*
intnum
=
*
(
int64_t
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_FLOAT
:
*
num
=
*
(
float
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_DOUBLE
:
*
num
=
*
(
double
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_RATIONAL
:
*
intnum
=
((
AVRational
*
)
dst
)
->
num
;
*
den
=
((
AVRational
*
)
dst
)
->
den
;
return
0
;
case
AV_OPT_TYPE_FLAGS
:
*
intnum
=
*
(
unsigned
int
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_INT
:
*
intnum
=
*
(
int
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_INT64
:
*
intnum
=
*
(
int64_t
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_FLOAT
:
*
num
=
*
(
float
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_DOUBLE
:
*
num
=
*
(
double
*
)
dst
;
return
0
;
case
AV_OPT_TYPE_RATIONAL
:
*
intnum
=
((
AVRational
*
)
dst
)
->
num
;
*
den
=
((
AVRational
*
)
dst
)
->
den
;
return
0
;
}
return
AVERROR
(
EINVAL
);
}
...
...
@@ -64,19 +75,29 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
if
(
o
->
type
!=
AV_OPT_TYPE_FLAGS
&&
(
o
->
max
*
den
<
num
*
intnum
||
o
->
min
*
den
>
num
*
intnum
))
{
av_log
(
obj
,
AV_LOG_ERROR
,
"Value %f for parameter '%s' out of range
\n
"
,
num
*
intnum
/
den
,
o
->
name
);
num
*
intnum
/
den
,
o
->
name
);
return
AVERROR
(
ERANGE
);
}
switch
(
o
->
type
)
{
case
AV_OPT_TYPE_FLAGS
:
case
AV_OPT_TYPE_INT
:
*
(
int
*
)
dst
=
llrint
(
num
/
den
)
*
intnum
;
break
;
case
AV_OPT_TYPE_INT64
:
*
(
int64_t
*
)
dst
=
llrint
(
num
/
den
)
*
intnum
;
break
;
case
AV_OPT_TYPE_FLOAT
:
*
(
float
*
)
dst
=
num
*
intnum
/
den
;
break
;
case
AV_OPT_TYPE_DOUBLE
:
*
(
double
*
)
dst
=
num
*
intnum
/
den
;
break
;
case
AV_OPT_TYPE_INT
:
*
(
int
*
)
dst
=
llrint
(
num
/
den
)
*
intnum
;
break
;
case
AV_OPT_TYPE_INT64
:
*
(
int64_t
*
)
dst
=
llrint
(
num
/
den
)
*
intnum
;
break
;
case
AV_OPT_TYPE_FLOAT
:
*
(
float
*
)
dst
=
num
*
intnum
/
den
;
break
;
case
AV_OPT_TYPE_DOUBLE
:
*
(
double
*
)
dst
=
num
*
intnum
/
den
;
break
;
case
AV_OPT_TYPE_RATIONAL
:
if
((
int
)
num
==
num
)
*
(
AVRational
*
)
dst
=
(
AVRational
){
num
*
intnum
,
den
};
else
*
(
AVRational
*
)
dst
=
av_d2q
(
num
*
intnum
/
den
,
1
<<
24
);
if
((
int
)
num
==
num
)
*
(
AVRational
*
)
dst
=
(
AVRational
)
{
num
*
intnum
,
den
};
else
*
(
AVRational
*
)
dst
=
av_d2q
(
num
*
intnum
/
den
,
1
<<
24
);
break
;
default:
return
AVERROR
(
EINVAL
);
...
...
@@ -91,17 +112,21 @@ static const double const_values[] = {
0
};
static
const
char
*
const
const_names
[]
=
{
static
const
char
*
const
const_names
[]
=
{
"PI"
,
"E"
,
"QP2LAMBDA"
,
0
};
static
int
hexchar2int
(
char
c
)
{
if
(
c
>=
'0'
&&
c
<=
'9'
)
return
c
-
'0'
;
if
(
c
>=
'a'
&&
c
<=
'f'
)
return
c
-
'a'
+
10
;
if
(
c
>=
'A'
&&
c
<=
'F'
)
return
c
-
'A'
+
10
;
static
int
hexchar2int
(
char
c
)
{
if
(
c
>=
'0'
&&
c
<=
'9'
)
return
c
-
'0'
;
if
(
c
>=
'a'
&&
c
<=
'f'
)
return
c
-
'a'
+
10
;
if
(
c
>=
'A'
&&
c
<=
'F'
)
return
c
-
'A'
+
10
;
return
-
1
;
}
...
...
@@ -130,7 +155,7 @@ static int set_string_binary(void *obj, const AVOption *o, const char *val, uint
}
*
ptr
++
=
(
a
<<
4
)
|
b
;
}
*
dst
=
bin
;
*
dst
=
bin
;
*
lendst
=
len
;
return
0
;
...
...
@@ -146,8 +171,9 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d
#define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
opt->type == AV_OPT_TYPE_CONST || \
opt->type == AV_OPT_TYPE_FLAGS || \
opt->type == AV_OPT_TYPE_INT) ? \
opt->default_val.i64 : opt->default_val.dbl)
opt->type == AV_OPT_TYPE_INT) \
? opt->default_val.i64 \
: opt->default_val.dbl)
static
int
set_string_number
(
void
*
obj
,
void
*
target_obj
,
const
AVOption
*
o
,
const
char
*
val
,
void
*
dst
)
{
...
...
@@ -175,11 +201,16 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con
const
AVOption
*
o_named
=
av_opt_find
(
target_obj
,
buf
,
o
->
unit
,
0
,
0
);
if
(
o_named
&&
o_named
->
type
==
AV_OPT_TYPE_CONST
)
d
=
DEFAULT_NUMVAL
(
o_named
);
else
if
(
!
strcmp
(
buf
,
"default"
))
d
=
DEFAULT_NUMVAL
(
o
);
else
if
(
!
strcmp
(
buf
,
"max"
))
d
=
o
->
max
;
else
if
(
!
strcmp
(
buf
,
"min"
))
d
=
o
->
min
;
else
if
(
!
strcmp
(
buf
,
"none"
))
d
=
0
;
else
if
(
!
strcmp
(
buf
,
"all"
))
d
=
~
0
;
else
if
(
!
strcmp
(
buf
,
"default"
))
d
=
DEFAULT_NUMVAL
(
o
);
else
if
(
!
strcmp
(
buf
,
"max"
))
d
=
o
->
max
;
else
if
(
!
strcmp
(
buf
,
"min"
))
d
=
o
->
min
;
else
if
(
!
strcmp
(
buf
,
"none"
))
d
=
0
;
else
if
(
!
strcmp
(
buf
,
"all"
))
d
=
~
0
;
else
{
int
res
=
av_expr_parse_and_eval
(
&
d
,
buf
,
const_names
,
const_values
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
0
,
obj
);
if
(
res
<
0
)
{
...
...
@@ -190,12 +221,16 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con
}
if
(
o
->
type
==
AV_OPT_TYPE_FLAGS
)
{
read_number
(
o
,
dst
,
NULL
,
NULL
,
&
intnum
);
if
(
cmd
==
'+'
)
d
=
intnum
|
(
int64_t
)
d
;
else
if
(
cmd
==
'-'
)
d
=
intnum
&~
(
int64_t
)
d
;
if
(
cmd
==
'+'
)
d
=
intnum
|
(
int64_t
)
d
;
else
if
(
cmd
==
'-'
)
d
=
intnum
&
~
(
int64_t
)
d
;
}
else
{
read_number
(
o
,
dst
,
&
num
,
&
den
,
&
intnum
);
if
(
cmd
==
'+'
)
d
=
notfirst
*
num
*
intnum
/
den
+
d
;
else
if
(
cmd
==
'-'
)
d
=
notfirst
*
num
*
intnum
/
den
-
d
;
if
(
cmd
==
'+'
)
d
=
notfirst
*
num
*
intnum
/
den
+
d
;
else
if
(
cmd
==
'-'
)
d
=
notfirst
*
num
*
intnum
/
den
-
d
;
}
if
((
ret
=
write_number
(
obj
,
o
,
dst
,
d
,
1
,
1
))
<
0
)
...
...
@@ -218,29 +253,33 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
if
(
!
val
||
o
->
flags
&
AV_OPT_FLAG_READONLY
)
return
AVERROR
(
EINVAL
);
dst
=
((
uint8_t
*
)
target_obj
)
+
o
->
offset
;
dst
=
((
uint8_t
*
)
target_obj
)
+
o
->
offset
;
switch
(
o
->
type
)
{
case
AV_OPT_TYPE_STRING
:
return
set_string
(
obj
,
o
,
val
,
dst
);
case
AV_OPT_TYPE_BINARY
:
return
set_string_binary
(
obj
,
o
,
val
,
dst
);
case
AV_OPT_TYPE_STRING
:
return
set_string
(
obj
,
o
,
val
,
dst
);
case
AV_OPT_TYPE_BINARY
:
return
set_string_binary
(
obj
,
o
,
val
,
dst
);
case
AV_OPT_TYPE_FLAGS
:
case
AV_OPT_TYPE_INT
:
case
AV_OPT_TYPE_INT64
:
case
AV_OPT_TYPE_FLOAT
:
case
AV_OPT_TYPE_DOUBLE
:
case
AV_OPT_TYPE_RATIONAL
:
return
set_string_number
(
obj
,
target_obj
,
o
,
val
,
dst
);
case
AV_OPT_TYPE_RATIONAL
:
return
set_string_number
(
obj
,
target_obj
,
o
,
val
,
dst
);
}
av_log
(
obj
,
AV_LOG_ERROR
,
"Invalid option type.
\n
"
);
return
AVERROR
(
EINVAL
);
}
#define OPT_EVAL_NUMBER(name, opttype, vartype)\
int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
{\
if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
return AVERROR(EINVAL);\
return set_string_number(obj, obj, o, val, name ## _out);\
}
#define OPT_EVAL_NUMBER(name, opttype, vartype) \
int av_opt_eval_ ## name(void *obj, const AVOption *o, \
const char *val, vartype *name ## _out) \
{ \
if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
return AVERROR(EINVAL); \
return set_string_number(obj, obj, o, val, name ## _out); \
}
OPT_EVAL_NUMBER
(
flags
,
AV_OPT_TYPE_FLAGS
,
int
)
OPT_EVAL_NUMBER
(
int
,
AV_OPT_TYPE_INT
,
int
)
...
...
@@ -250,7 +289,7 @@ OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
OPT_EVAL_NUMBER
(
q
,
AV_OPT_TYPE_RATIONAL
,
AVRational
)
static
int
set_number
(
void
*
obj
,
const
char
*
name
,
double
num
,
int
den
,
int64_t
intnum
,
int
search_flags
)
int
search_flags
)
{
void
*
dst
,
*
target_obj
;
const
AVOption
*
o
=
av_opt_find2
(
obj
,
name
,
NULL
,
0
,
search_flags
,
&
target_obj
);
...
...
@@ -261,7 +300,7 @@ static int set_number(void *obj, const char *name, double num, int den, int64_t
if
(
o
->
flags
&
AV_OPT_FLAG_READONLY
)
return
AVERROR
(
EINVAL
);
dst
=
((
uint8_t
*
)
target_obj
)
+
o
->
offset
;
dst
=
((
uint8_t
*
)
target_obj
)
+
o
->
offset
;
return
write_number
(
obj
,
o
,
dst
,
num
,
den
,
intnum
);
}
...
...
@@ -298,18 +337,19 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
if
(
!
ptr
)
return
AVERROR
(
ENOMEM
);
dst
=
(
uint8_t
**
)(((
uint8_t
*
)
target_obj
)
+
o
->
offset
);
dst
=
(
uint8_t
**
)(((
uint8_t
*
)
target_obj
)
+
o
->
offset
);
lendst
=
(
int
*
)(
dst
+
1
);
av_free
(
*
dst
);
*
dst
=
ptr
;
*
dst
=
ptr
;
*
lendst
=
len
;
memcpy
(
ptr
,
val
,
len
);
return
0
;
}
int
av_opt_set_dict_val
(
void
*
obj
,
const
char
*
name
,
const
AVDictionary
*
val
,
int
search_flags
)
int
av_opt_set_dict_val
(
void
*
obj
,
const
char
*
name
,
const
AVDictionary
*
val
,
int
search_flags
)
{
void
*
target_obj
;
AVDictionary
**
dst
;
...
...
@@ -337,31 +377,44 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
if
(
!
o
||
!
target_obj
)
return
AVERROR_OPTION_NOT_FOUND
;
dst
=
(
uint8_t
*
)
target_obj
+
o
->
offset
;
dst
=
(
uint8_t
*
)
target_obj
+
o
->
offset
;
buf
[
0
]
=
0
;
switch
(
o
->
type
)
{
case
AV_OPT_TYPE_FLAGS
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"0x%08X"
,
*
(
int
*
)
dst
);
break
;
case
AV_OPT_TYPE_INT
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%d"
,
*
(
int
*
)
dst
);
break
;
case
AV_OPT_TYPE_INT64
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRId64
,
*
(
int64_t
*
)
dst
);
break
;
case
AV_OPT_TYPE_FLOAT
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%f"
,
*
(
float
*
)
dst
);
break
;
case
AV_OPT_TYPE_DOUBLE
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%f"
,
*
(
double
*
)
dst
);
break
;
case
AV_OPT_TYPE_RATIONAL
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%d/%d"
,
((
AVRational
*
)
dst
)
->
num
,
((
AVRational
*
)
dst
)
->
den
);
break
;
case
AV_OPT_TYPE_FLAGS
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"0x%08X"
,
*
(
int
*
)
dst
);
break
;
case
AV_OPT_TYPE_INT
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%d"
,
*
(
int
*
)
dst
);
break
;
case
AV_OPT_TYPE_INT64
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRId64
,
*
(
int64_t
*
)
dst
);
break
;
case
AV_OPT_TYPE_FLOAT
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%f"
,
*
(
float
*
)
dst
);
break
;
case
AV_OPT_TYPE_DOUBLE
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%f"
,
*
(
double
*
)
dst
);
break
;
case
AV_OPT_TYPE_RATIONAL
:
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%d/%d"
,
((
AVRational
*
)
dst
)
->
num
,
((
AVRational
*
)
dst
)
->
den
);
break
;
case
AV_OPT_TYPE_STRING
:
if
(
*
(
uint8_t
**
)
dst
)
*
out_val
=
av_strdup
(
*
(
uint8_t
**
)
dst
);
if
(
*
(
uint8_t
**
)
dst
)
*
out_val
=
av_strdup
(
*
(
uint8_t
**
)
dst
);
else
*
out_val
=
av_strdup
(
""
);
return
*
out_val
?
0
:
AVERROR
(
ENOMEM
);
case
AV_OPT_TYPE_BINARY
:
len
=
*
(
int
*
)(((
uint8_t
*
)
dst
)
+
sizeof
(
uint8_t
*
));
if
((
uint64_t
)
len
*
2
+
1
>
INT_MAX
)
len
=
*
(
int
*
)(((
uint8_t
*
)
dst
)
+
sizeof
(
uint8_t
*
));
if
((
uint64_t
)
len
*
2
+
1
>
INT_MAX
)
return
AVERROR
(
EINVAL
);
if
(
!
(
*
out_val
=
av_malloc
(
len
*
2
+
1
)))
if
(
!
(
*
out_val
=
av_malloc
(
len
*
2
+
1
)))
return
AVERROR
(
ENOMEM
);
bin
=
*
(
uint8_t
**
)
dst
;
bin
=
*
(
uint8_t
**
)
dst
;
for
(
i
=
0
;
i
<
len
;
i
++
)
snprintf
(
*
out_val
+
i
*
2
,
3
,
"%02X"
,
bin
[
i
]);
snprintf
(
*
out_val
+
i
*
2
,
3
,
"%02X"
,
bin
[
i
]);
return
0
;
default
:
return
AVERROR
(
EINVAL
);
...
...
@@ -381,52 +434,53 @@ static int get_number(void *obj, const char *name, double *num, int *den, int64_
if
(
!
o
||
!
target_obj
)
goto
error
;
dst
=
((
uint8_t
*
)
target_obj
)
+
o
->
offset
;
dst
=
((
uint8_t
*
)
target_obj
)
+
o
->
offset
;
return
read_number
(
o
,
dst
,
num
,
den
,
intnum
);
error
:
*
den
=*
intnum
=
0
;
*
den
=
*
intnum
=
0
;
return
-
1
;
}
int
av_opt_get_int
(
void
*
obj
,
const
char
*
name
,
int
search_flags
,
int64_t
*
out_val
)
{
int64_t
intnum
=
1
;
double
num
=
1
;
int
ret
,
den
=
1
;
double
num
=
1
;
int
ret
,
den
=
1
;
if
((
ret
=
get_number
(
obj
,
name
,
&
num
,
&
den
,
&
intnum
,
search_flags
))
<
0
)
return
ret
;
*
out_val
=
num
*
intnum
/
den
;
*
out_val
=
num
*
intnum
/
den
;
return
0
;
}
int
av_opt_get_double
(
void
*
obj
,
const
char
*
name
,
int
search_flags
,
double
*
out_val
)
{
int64_t
intnum
=
1
;
double
num
=
1
;
int
ret
,
den
=
1
;
double
num
=
1
;
int
ret
,
den
=
1
;
if
((
ret
=
get_number
(
obj
,
name
,
&
num
,
&
den
,
&
intnum
,
search_flags
))
<
0
)
return
ret
;
*
out_val
=
num
*
intnum
/
den
;
*
out_val
=
num
*
intnum
/
den
;
return
0
;
}
int
av_opt_get_q
(
void
*
obj
,
const
char
*
name
,
int
search_flags
,
AVRational
*
out_val
)
{
int64_t
intnum
=
1
;
double
num
=
1
;
int
ret
,
den
=
1
;
double
num
=
1
;
int
ret
,
den
=
1
;
if
((
ret
=
get_number
(
obj
,
name
,
&
num
,
&
den
,
&
intnum
,
search_flags
))
<
0
)
return
ret
;
if
(
num
==
1
.
0
&&
(
int
)
intnum
==
intnum
)
*
out_val
=
(
AVRational
)
{
intnum
,
den
};
*
out_val
=
(
AVRational
)
{
intnum
,
den
};
else
*
out_val
=
av_d2q
(
num
*
intnum
/
den
,
1
<<
24
);
*
out_val
=
av_d2q
(
num
*
intnum
/
den
,
1
<<
24
);
return
0
;
}
...
...
@@ -463,7 +517,7 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
static
void
opt_list
(
void
*
obj
,
void
*
av_log_obj
,
const
char
*
unit
,
int
req_flags
,
int
rej_flags
)
{
const
AVOption
*
opt
=
NULL
;
const
AVOption
*
opt
=
NULL
;
while
((
opt
=
av_opt_next
(
obj
,
opt
)))
{
if
(
!
(
opt
->
flags
&
req_flags
)
||
(
opt
->
flags
&
rej_flags
))
...
...
@@ -473,11 +527,11 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
* Don't print anything but CONST's on level two.
* Only print items from the requested unit.
*/
if
(
!
unit
&&
opt
->
type
==
AV_OPT_TYPE_CONST
)
if
(
!
unit
&&
opt
->
type
==
AV_OPT_TYPE_CONST
)
continue
;
else
if
(
unit
&&
opt
->
type
!=
AV_OPT_TYPE_CONST
)
else
if
(
unit
&&
opt
->
type
!=
AV_OPT_TYPE_CONST
)
continue
;
else
if
(
unit
&&
opt
->
type
==
AV_OPT_TYPE_CONST
&&
strcmp
(
unit
,
opt
->
unit
))
else
if
(
unit
&&
opt
->
type
==
AV_OPT_TYPE_CONST
&&
strcmp
(
unit
,
opt
->
unit
))
continue
;
else
if
(
unit
&&
opt
->
type
==
AV_OPT_TYPE_CONST
)
av_log
(
av_log_obj
,
AV_LOG_INFO
,
" %-15s "
,
opt
->
name
);
...
...
@@ -485,39 +539,39 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"-%-17s "
,
opt
->
name
);
switch
(
opt
->
type
)
{
case
AV_OPT_TYPE_FLAGS
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<flags>"
);
break
;
case
AV_OPT_TYPE_INT
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<int>"
);
break
;
case
AV_OPT_TYPE_INT64
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<int64>"
);
break
;
case
AV_OPT_TYPE_DOUBLE
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<double>"
);
break
;
case
AV_OPT_TYPE_FLOAT
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<float>"
);
break
;
case
AV_OPT_TYPE_STRING
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<string>"
);
break
;
case
AV_OPT_TYPE_RATIONAL
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<rational>"
);
break
;
case
AV_OPT_TYPE_BINARY
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<binary>"
);
break
;
case
AV_OPT_TYPE_CONST
:
default
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
""
);
break
;
case
AV_OPT_TYPE_FLAGS
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<flags>"
);
break
;
case
AV_OPT_TYPE_INT
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<int>"
);
break
;
case
AV_OPT_TYPE_INT64
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<int64>"
);
break
;
case
AV_OPT_TYPE_DOUBLE
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<double>"
);
break
;
case
AV_OPT_TYPE_FLOAT
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<float>"
);
break
;
case
AV_OPT_TYPE_STRING
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<string>"
);
break
;
case
AV_OPT_TYPE_RATIONAL
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<rational>"
);
break
;
case
AV_OPT_TYPE_BINARY
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
"<binary>"
);
break
;
case
AV_OPT_TYPE_CONST
:
default
:
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%-7s "
,
""
);
break
;
}
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_ENCODING_PARAM
)
?
'E'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_DECODING_PARAM
)
?
'D'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_VIDEO_PARAM
)
?
'V'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_AUDIO_PARAM
)
?
'A'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_VIDEO_PARAM
)
?
'V'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_AUDIO_PARAM
)
?
'A'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_SUBTITLE_PARAM
)
?
'S'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_EXPORT
)
?
'X'
:
'.'
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%c"
,
(
opt
->
flags
&
AV_OPT_FLAG_READONLY
)
?
'R'
:
'.'
);
...
...
@@ -525,9 +579,8 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
if
(
opt
->
help
)
av_log
(
av_log_obj
,
AV_LOG_INFO
,
" %s"
,
opt
->
help
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"
\n
"
);
if
(
opt
->
unit
&&
opt
->
type
!=
AV_OPT_TYPE_CONST
)
{
if
(
opt
->
unit
&&
opt
->
type
!=
AV_OPT_TYPE_CONST
)
opt_list
(
obj
,
av_log_obj
,
opt
->
unit
,
req_flags
,
rej_flags
);
}
}
}
...
...
@@ -536,7 +589,7 @@ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
if
(
!
obj
)
return
-
1
;
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%s AVOptions:
\n
"
,
(
*
(
AVClass
**
)
obj
)
->
class_name
);
av_log
(
av_log_obj
,
AV_LOG_INFO
,
"%s AVOptions:
\n
"
,
(
*
(
AVClass
**
)
obj
)
->
class_name
);
opt_list
(
obj
,
av_log_obj
,
NULL
,
req_flags
,
rej_flags
);
...
...
@@ -551,36 +604,39 @@ void av_opt_set_defaults(void *s)
continue
;
switch
(
opt
->
type
)
{
case
AV_OPT_TYPE_CONST
:
/* Nothing to be done here */
break
;
case
AV_OPT_TYPE_FLAGS
:
case
AV_OPT_TYPE_INT
:
case
AV_OPT_TYPE_INT64
:
av_opt_set_int
(
s
,
opt
->
name
,
opt
->
default_val
.
i64
,
0
);
case
AV_OPT_TYPE_CONST
:
/* Nothing to be done here */
break
;
case
AV_OPT_TYPE_DOUBLE
:
case
AV_OPT_TYPE_FLOAT
:
{
double
val
;
val
=
opt
->
default_val
.
dbl
;
av_opt_set_double
(
s
,
opt
->
name
,
val
,
0
);
}
case
AV_OPT_TYPE_FLAGS
:
case
AV_OPT_TYPE_INT
:
case
AV_OPT_TYPE_INT64
:
av_opt_set_int
(
s
,
opt
->
name
,
opt
->
default_val
.
i64
,
0
);
break
;
case
AV_OPT_TYPE_RATIONAL
:
{
AVRational
val
;
val
=
av_d2q
(
opt
->
default_val
.
dbl
,
INT_MAX
);
av_opt_set_q
(
s
,
opt
->
name
,
val
,
0
);
}
case
AV_OPT_TYPE_DOUBLE
:
case
AV_OPT_TYPE_FLOAT
:
{
double
val
;
val
=
opt
->
default_val
.
dbl
;
av_opt_set_double
(
s
,
opt
->
name
,
val
,
0
);
}
break
;
case
AV_OPT_TYPE_RATIONAL
:
{
AVRational
val
;
val
=
av_d2q
(
opt
->
default_val
.
dbl
,
INT_MAX
);
av_opt_set_q
(
s
,
opt
->
name
,
val
,
0
);
}
break
;
case
AV_OPT_TYPE_STRING
:
av_opt_set
(
s
,
opt
->
name
,
opt
->
default_val
.
str
,
0
);
break
;
case
AV_OPT_TYPE_STRING
:
av_opt_set
(
s
,
opt
->
name
,
opt
->
default_val
.
str
,
0
);
break
;
case
AV_OPT_TYPE_BINARY
:
case
AV_OPT_TYPE_DICT
:
/* Cannot set defaults for these types */
case
AV_OPT_TYPE_BINARY
:
case
AV_OPT_TYPE_DICT
:
/* Cannot set defaults for these types */
break
;
default
:
av_log
(
s
,
AV_LOG_DEBUG
,
"AVOption type %d of option %s not implemented yet
\n
"
,
opt
->
type
,
opt
->
name
);
default
:
av_log
(
s
,
AV_LOG_DEBUG
,
"AVOption type %d of option %s not implemented yet
\n
"
,
opt
->
type
,
opt
->
name
);
}
}
}
...
...
@@ -706,7 +762,7 @@ const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
const
AVOption
*
av_opt_find2
(
void
*
obj
,
const
char
*
name
,
const
char
*
unit
,
int
opt_flags
,
int
search_flags
,
void
**
target_obj
)
{
const
AVClass
*
c
=
*
(
AVClass
**
)
obj
;
const
AVClass
*
c
=
*
(
AVClass
**
)
obj
;
const
AVOption
*
o
=
NULL
;
if
(
!
c
)
...
...
@@ -729,7 +785,7 @@ const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
while
(
o
=
av_opt_next
(
obj
,
o
))
{
if
(
!
strcmp
(
o
->
name
,
name
)
&&
(
o
->
flags
&
opt_flags
)
==
opt_flags
&&
((
!
unit
&&
o
->
type
!=
AV_OPT_TYPE_CONST
)
||
(
unit
&&
o
->
unit
&&
!
strcmp
(
o
->
unit
,
unit
))))
{
(
unit
&&
o
->
unit
&&
!
strcmp
(
o
->
unit
,
unit
))))
{
if
(
target_obj
)
{
if
(
!
(
search_flags
&
AV_OPT_SEARCH_FAKE_OBJ
))
*
target_obj
=
obj
;
...
...
@@ -744,7 +800,7 @@ const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
void
*
av_opt_child_next
(
void
*
obj
,
void
*
prev
)
{
const
AVClass
*
c
=
*
(
AVClass
**
)
obj
;
const
AVClass
*
c
=
*
(
AVClass
**
)
obj
;
if
(
c
->
child_next
)
return
c
->
child_next
(
obj
,
prev
);
return
NULL
;
...
...
@@ -759,15 +815,22 @@ const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *pre
static
int
opt_size
(
enum
AVOptionType
type
)
{
switch
(
type
)
{
switch
(
type
)
{
case
AV_OPT_TYPE_INT
:
case
AV_OPT_TYPE_FLAGS
:
return
sizeof
(
int
);
case
AV_OPT_TYPE_INT64
:
return
sizeof
(
int64_t
);
case
AV_OPT_TYPE_DOUBLE
:
return
sizeof
(
double
);
case
AV_OPT_TYPE_FLOAT
:
return
sizeof
(
float
);
case
AV_OPT_TYPE_STRING
:
return
sizeof
(
uint8_t
*
);
case
AV_OPT_TYPE_RATIONAL
:
return
sizeof
(
AVRational
);
case
AV_OPT_TYPE_BINARY
:
return
sizeof
(
uint8_t
*
)
+
sizeof
(
int
);
case
AV_OPT_TYPE_FLAGS
:
return
sizeof
(
int
);
case
AV_OPT_TYPE_INT64
:
return
sizeof
(
int64_t
);
case
AV_OPT_TYPE_DOUBLE
:
return
sizeof
(
double
);
case
AV_OPT_TYPE_FLOAT
:
return
sizeof
(
float
);
case
AV_OPT_TYPE_STRING
:
return
sizeof
(
uint8_t
*
);
case
AV_OPT_TYPE_RATIONAL
:
return
sizeof
(
AVRational
);
case
AV_OPT_TYPE_BINARY
:
return
sizeof
(
uint8_t
*
)
+
sizeof
(
int
);
}
return
AVERROR
(
EINVAL
);
}
...
...
@@ -781,22 +844,22 @@ int av_opt_copy(void *dst, const void *src)
if
(
!
src
)
return
AVERROR
(
EINVAL
);
c
=
*
(
AVClass
**
)
src
;
if
(
!
c
||
c
!=
*
(
AVClass
**
)
dst
)
c
=
*
(
AVClass
**
)
src
;
if
(
!
c
||
c
!=
*
(
AVClass
**
)
dst
)
return
AVERROR
(
EINVAL
);
while
((
o
=
av_opt_next
(
src
,
o
)))
{
void
*
field_dst
=
(
(
uint8_t
*
)
dst
)
+
o
->
offset
;
void
*
field_src
=
(
(
uint8_t
*
)
src
)
+
o
->
offset
;
uint8_t
**
field_dst8
=
(
uint8_t
**
)
field_dst
;
uint8_t
**
field_src8
=
(
uint8_t
**
)
field_src
;
void
*
field_dst
=
(
uint8_t
*
)
dst
+
o
->
offset
;
void
*
field_src
=
(
uint8_t
*
)
src
+
o
->
offset
;
uint8_t
**
field_dst8
=
(
uint8_t
**
)
field_dst
;
uint8_t
**
field_src8
=
(
uint8_t
**
)
field_src
;
if
(
o
->
type
==
AV_OPT_TYPE_STRING
)
{
set_string
(
dst
,
o
,
*
field_src8
,
field_dst8
);
if
(
*
field_src8
&&
!*
field_dst8
)
ret
=
AVERROR
(
ENOMEM
);
}
else
if
(
o
->
type
==
AV_OPT_TYPE_BINARY
)
{
int
len
=
*
(
int
*
)(
field_src8
+
1
);
int
len
=
*
(
int
*
)(
field_src8
+
1
);
if
(
*
field_dst8
!=
*
field_src8
)
av_freep
(
field_dst8
);
if
(
len
)
{
...
...
@@ -809,7 +872,7 @@ int av_opt_copy(void *dst, const void *src)
}
else
{
*
field_dst8
=
NULL
;
}
*
(
int
*
)(
field_dst8
+
1
)
=
len
;
*
(
int
*
)(
field_dst8
+
1
)
=
len
;
}
else
if
(
o
->
type
==
AV_OPT_TYPE_CONST
)
{
// do nothing
}
else
{
...
...
@@ -825,8 +888,7 @@ int av_opt_copy(void *dst, const void *src)
#ifdef TEST
typedef
struct
TestContext
{
typedef
struct
TestContext
{
const
AVClass
*
class
;
int
num
;
int
toggle
;
...
...
@@ -841,16 +903,16 @@ typedef struct TestContext
#define TEST_FLAG_LAME 02
#define TEST_FLAG_MU 04
static
const
AVOption
test_options
[]
=
{
{
"num"
,
"set num"
,
OFFSET
(
num
),
AV_OPT_TYPE_INT
,
{.
i64
=
0
},
0
,
100
},
{
"toggle"
,
"set toggle"
,
OFFSET
(
toggle
),
AV_OPT_TYPE_INT
,
{.
i64
=
0
},
0
,
1
},
{
"rational"
,
"set rational"
,
OFFSET
(
rational
),
AV_OPT_TYPE_RATIONAL
,
{.
dbl
=
0
},
0
,
10
},
{
"string"
,
"set string"
,
OFFSET
(
string
),
AV_OPT_TYPE_STRING
,
{
0
},
CHAR_MIN
,
CHAR_MAX
},
{
"flags"
,
"set flags"
,
OFFSET
(
flags
),
AV_OPT_TYPE_FLAGS
,
{.
i64
=
0
},
0
,
INT_MAX
,
0
,
"flags"
},
{
"cool"
,
"set cool flag "
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
TEST_FLAG_COOL
},
INT_MIN
,
INT_MAX
,
0
,
"flags"
},
{
"lame"
,
"set lame flag "
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
TEST_FLAG_LAME
},
INT_MIN
,
INT_MAX
,
0
,
"flags"
},
{
"mu"
,
"set mu flag "
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
TEST_FLAG_MU
},
INT_MIN
,
INT_MAX
,
0
,
"flags"
},
{
NULL
},
static
const
AVOption
test_options
[]
=
{
{
"num"
,
"set num"
,
OFFSET
(
num
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
100
},
{
"toggle"
,
"set toggle"
,
OFFSET
(
toggle
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
1
},
{
"rational"
,
"set rational"
,
OFFSET
(
rational
),
AV_OPT_TYPE_RATIONAL
,
{
.
dbl
=
0
},
0
,
10
},
{
"string"
,
"set string"
,
OFFSET
(
string
),
AV_OPT_TYPE_STRING
,
{
0
},
CHAR_MIN
,
CHAR_MAX
},
{
"flags"
,
"set flags"
,
OFFSET
(
flags
),
AV_OPT_TYPE_FLAGS
,
{
.
i64
=
0
},
0
,
INT_MAX
,
0
,
"flags"
},
{
"cool"
,
"set cool flag "
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
TEST_FLAG_COOL
},
INT_MIN
,
INT_MAX
,
0
,
"flags"
},
{
"lame"
,
"set lame flag "
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
TEST_FLAG_LAME
},
INT_MIN
,
INT_MAX
,
0
,
"flags"
},
{
"mu"
,
"set mu flag "
,
0
,
AV_OPT_TYPE_CONST
,
{
.
i64
=
TEST_FLAG_MU
},
INT_MIN
,
INT_MAX
,
0
,
"flags"
},
{
NULL
},
};
static
const
char
*
test_get_name
(
void
*
ctx
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment