Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
92d107a1
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92d107a1
编写于
11月 11, 2015
作者:
M
Martin Storsjö
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
xtea: Add functions for little endian mode
Signed-off-by:
N
Martin Storsjö
<
martin@martin.st
>
上级
1fc94724
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
14 deletion
+108
-14
doc/APIchanges
doc/APIchanges
+3
-0
libavutil/version.h
libavutil/version.h
+1
-1
libavutil/xtea.c
libavutil/xtea.c
+81
-13
libavutil/xtea.h
libavutil/xtea.h
+23
-0
未找到文件。
doc/APIchanges
浏览文件 @
92d107a1
...
...
@@ -12,6 +12,9 @@ libavutil: 2015-08-28
API changes, most recent first:
2015-11-xx - xxxxxxx - lavu 55.3.0 - xtea.h
Add av_xtea_le_init and av_xtea_le_crypt
2015-11-xx - xxxxxxx - lavfi 6.1.0 - avfilter.h
Add a frame_rate field to AVFilterLink
...
...
libavutil/version.h
浏览文件 @
92d107a1
...
...
@@ -54,7 +54,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 55
#define LIBAVUTIL_VERSION_MINOR
2
#define LIBAVUTIL_VERSION_MINOR
3
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
...
...
libavutil/xtea.c
浏览文件 @
92d107a1
...
...
@@ -53,6 +53,14 @@ void av_xtea_init(AVXTEA *ctx, const uint8_t key[16])
ctx
->
key
[
i
]
=
AV_RB32
(
key
+
(
i
<<
2
));
}
void
av_xtea_le_init
(
AVXTEA
*
ctx
,
const
uint8_t
key
[
16
])
{
int
i
;
for
(
i
=
0
;
i
<
4
;
i
++
)
ctx
->
key
[
i
]
=
AV_RL32
(
key
+
(
i
<<
2
));
}
static
void
xtea_crypt_ecb
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
decrypt
,
uint8_t
*
iv
)
{
...
...
@@ -89,14 +97,51 @@ static void xtea_crypt_ecb(AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
AV_WB32
(
dst
+
4
,
v1
);
}
void
av_xtea_crypt
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
)
static
void
xtea_le_crypt_ecb
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
decrypt
,
uint8_t
*
iv
)
{
uint32_t
v0
,
v1
;
int
i
;
v0
=
AV_RL32
(
src
);
v1
=
AV_RL32
(
src
+
4
);
if
(
decrypt
)
{
uint32_t
delta
=
0x9E3779B9
,
sum
=
delta
*
32
;
for
(
i
=
0
;
i
<
32
;
i
++
)
{
v1
-=
(((
v0
<<
4
)
^
(
v0
>>
5
))
+
v0
)
^
(
sum
+
ctx
->
key
[(
sum
>>
11
)
&
3
]);
sum
-=
delta
;
v0
-=
(((
v1
<<
4
)
^
(
v1
>>
5
))
+
v1
)
^
(
sum
+
ctx
->
key
[
sum
&
3
]);
}
if
(
iv
)
{
v0
^=
AV_RL32
(
iv
);
v1
^=
AV_RL32
(
iv
+
4
);
memcpy
(
iv
,
src
,
8
);
}
}
else
{
uint32_t
sum
=
0
,
delta
=
0x9E3779B9
;
for
(
i
=
0
;
i
<
32
;
i
++
)
{
v0
+=
(((
v1
<<
4
)
^
(
v1
>>
5
))
+
v1
)
^
(
sum
+
ctx
->
key
[
sum
&
3
]);
sum
+=
delta
;
v1
+=
(((
v0
<<
4
)
^
(
v0
>>
5
))
+
v0
)
^
(
sum
+
ctx
->
key
[(
sum
>>
11
)
&
3
]);
}
}
AV_WL32
(
dst
,
v0
);
AV_WL32
(
dst
+
4
,
v1
);
}
static
void
xtea_crypt
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
,
void
(
*
crypt
)(
AVXTEA
*
,
uint8_t
*
,
const
uint8_t
*
,
int
,
uint8_t
*
))
{
int
i
;
if
(
decrypt
)
{
while
(
count
--
)
{
xtea_crypt_ecb
(
ctx
,
dst
,
src
,
decrypt
,
iv
);
crypt
(
ctx
,
dst
,
src
,
decrypt
,
iv
);
src
+=
8
;
dst
+=
8
;
...
...
@@ -106,10 +151,10 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
if
(
iv
)
{
for
(
i
=
0
;
i
<
8
;
i
++
)
dst
[
i
]
=
src
[
i
]
^
iv
[
i
];
xtea_crypt_ecb
(
ctx
,
dst
,
dst
,
decrypt
,
NULL
);
crypt
(
ctx
,
dst
,
dst
,
decrypt
,
NULL
);
memcpy
(
iv
,
dst
,
8
);
}
else
{
xtea_crypt_ecb
(
ctx
,
dst
,
src
,
decrypt
,
NULL
);
crypt
(
ctx
,
dst
,
src
,
decrypt
,
NULL
);
}
src
+=
8
;
dst
+=
8
;
...
...
@@ -117,6 +162,18 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
}
}
void
av_xtea_crypt
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
)
{
xtea_crypt
(
ctx
,
dst
,
src
,
count
,
iv
,
decrypt
,
xtea_crypt_ecb
);
}
void
av_xtea_le_crypt
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
)
{
xtea_crypt
(
ctx
,
dst
,
src
,
count
,
iv
,
decrypt
,
xtea_le_crypt_ecb
);
}
#ifdef TEST
#include <stdio.h>
...
...
@@ -157,9 +214,10 @@ static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = {
static
void
test_xtea
(
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
const
uint8_t
*
ref
,
int
len
,
uint8_t
*
iv
,
int
dir
,
const
char
*
test
)
const
char
*
test
,
void
(
*
crypt
)(
AVXTEA
*
,
uint8_t
*
,
const
uint8_t
*
,
int
,
uint8_t
*
,
int
))
{
av_xtea_
crypt
(
ctx
,
dst
,
src
,
len
,
iv
,
dir
);
crypt
(
ctx
,
dst
,
src
,
len
,
iv
,
dir
);
if
(
memcmp
(
dst
,
ref
,
8
*
len
))
{
int
i
;
printf
(
"%s failed
\n
got "
,
test
);
...
...
@@ -176,8 +234,8 @@ static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
int
main
(
void
)
{
AVXTEA
ctx
;
uint8_t
buf
[
8
],
iv
[
8
];
int
i
;
uint8_t
buf
[
16
],
iv
[
8
];
int
i
,
j
;
const
uint8_t
src
[
32
]
=
"HelloWorldHelloWorldHelloWorld"
;
uint8_t
ct
[
32
];
uint8_t
pl
[
32
];
...
...
@@ -185,8 +243,18 @@ int main(void)
for
(
i
=
0
;
i
<
XTEA_NUM_TESTS
;
i
++
)
{
av_xtea_init
(
&
ctx
,
xtea_test_key
[
i
]);
test_xtea
(
&
ctx
,
buf
,
xtea_test_pt
[
i
],
xtea_test_ct
[
i
],
1
,
NULL
,
0
,
"encryption"
);
test_xtea
(
&
ctx
,
buf
,
xtea_test_ct
[
i
],
xtea_test_pt
[
i
],
1
,
NULL
,
1
,
"decryption"
);
test_xtea
(
&
ctx
,
buf
,
xtea_test_pt
[
i
],
xtea_test_ct
[
i
],
1
,
NULL
,
0
,
"encryption"
,
av_xtea_crypt
);
test_xtea
(
&
ctx
,
buf
,
xtea_test_ct
[
i
],
xtea_test_pt
[
i
],
1
,
NULL
,
1
,
"decryption"
,
av_xtea_crypt
);
for
(
j
=
0
;
j
<
4
;
j
++
)
AV_WL32
(
&
buf
[
4
*
j
],
AV_RB32
(
&
xtea_test_key
[
i
][
4
*
j
]));
av_xtea_le_init
(
&
ctx
,
buf
);
for
(
j
=
0
;
j
<
2
;
j
++
)
{
AV_WL32
(
&
ct
[
4
*
j
],
AV_RB32
(
&
xtea_test_ct
[
i
][
4
*
j
]));
AV_WL32
(
&
pl
[
4
*
j
],
AV_RB32
(
&
xtea_test_pt
[
i
][
4
*
j
]));
}
test_xtea
(
&
ctx
,
buf
,
pl
,
ct
,
1
,
NULL
,
0
,
"encryption"
,
av_xtea_le_crypt
);
test_xtea
(
&
ctx
,
buf
,
ct
,
pl
,
1
,
NULL
,
1
,
"decryption"
,
av_xtea_le_crypt
);
/* encrypt */
memcpy
(
iv
,
"HALLO123"
,
8
);
...
...
@@ -194,10 +262,10 @@ int main(void)
/* decrypt into pl */
memcpy
(
iv
,
"HALLO123"
,
8
);
test_xtea
(
&
ctx
,
pl
,
ct
,
src
,
4
,
iv
,
1
,
"CBC decryption"
);
test_xtea
(
&
ctx
,
pl
,
ct
,
src
,
4
,
iv
,
1
,
"CBC decryption"
,
av_xtea_crypt
);
memcpy
(
iv
,
"HALLO123"
,
8
);
test_xtea
(
&
ctx
,
ct
,
ct
,
src
,
4
,
iv
,
1
,
"CBC inplace decryption"
);
test_xtea
(
&
ctx
,
ct
,
ct
,
src
,
4
,
iv
,
1
,
"CBC inplace decryption"
,
av_xtea_crypt
);
}
printf
(
"Test encryption/decryption success.
\n
"
);
...
...
libavutil/xtea.h
浏览文件 @
92d107a1
...
...
@@ -54,6 +54,15 @@ AVXTEA *av_xtea_alloc(void);
*/
void
av_xtea_init
(
struct
AVXTEA
*
ctx
,
const
uint8_t
key
[
16
]);
/**
* Initialize an AVXTEA context.
*
* @param ctx an AVXTEA context
* @param key a key of 16 bytes used for encryption/decryption,
* interpreted as little endian 32 bit numbers
*/
void
av_xtea_le_init
(
struct
AVXTEA
*
ctx
,
const
uint8_t
key
[
16
]);
/**
* Encrypt or decrypt a buffer using a previously initialized context,
* in big endian format.
...
...
@@ -68,6 +77,20 @@ void av_xtea_init(struct AVXTEA *ctx, const uint8_t key[16]);
void
av_xtea_crypt
(
struct
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
);
/**
* Encrypt or decrypt a buffer using a previously initialized context,
* in little endian format.
*
* @param ctx an AVXTEA context
* @param dst destination array, can be equal to src
* @param src source array, can be equal to dst
* @param count number of 8 byte blocks
* @param iv initialization vector for CBC mode, if NULL then ECB will be used
* @param decrypt 0 for encryption, 1 for decryption
*/
void
av_xtea_le_crypt
(
struct
AVXTEA
*
ctx
,
uint8_t
*
dst
,
const
uint8_t
*
src
,
int
count
,
uint8_t
*
iv
,
int
decrypt
);
/**
* @}
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录