Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
9a2d2fb3
O
openssl
项目概览
btwise
/
openssl
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9a2d2fb3
编写于
4月 23, 2016
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test/evp_test.c: exercise different combinations of data misalignment.
Reviewed-by:
N
Emilia Käsper
<
emilia@openssl.org
>
上级
c0aa8c27
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
24 deletion
+55
-24
test/evp_test.c
test/evp_test.c
+55
-24
未找到文件。
test/evp_test.c
浏览文件 @
9a2d2fb3
...
...
@@ -251,7 +251,7 @@ struct evp_test {
/* start line of current test */
unsigned
int
start_line
;
/* Error string for test */
const
char
*
err
;
const
char
*
err
,
*
aux_err
;
/* Expected error value of test */
char
*
expected_err
;
/* Number of tests */
...
...
@@ -364,8 +364,13 @@ static int check_test_error(struct evp_test *t)
if
(
!
t
->
err
&&
!
t
->
expected_err
)
return
1
;
if
(
t
->
err
&&
!
t
->
expected_err
)
{
fprintf
(
stderr
,
"Test line %d: unexpected error %s
\n
"
,
t
->
start_line
,
t
->
err
);
if
(
t
->
aux_err
!=
NULL
)
{
fprintf
(
stderr
,
"Test line %d(%s): unexpected error %s
\n
"
,
t
->
start_line
,
t
->
aux_err
,
t
->
err
);
}
else
{
fprintf
(
stderr
,
"Test line %d: unexpected error %s
\n
"
,
t
->
start_line
,
t
->
err
);
}
print_expected
(
t
);
return
0
;
}
...
...
@@ -830,7 +835,8 @@ static int cipher_test_parse(struct evp_test *t, const char *keyword,
return
0
;
}
static
int
cipher_test_enc
(
struct
evp_test
*
t
,
int
enc
)
static
int
cipher_test_enc
(
struct
evp_test
*
t
,
int
enc
,
size_t
out_misalign
,
size_t
inp_misalign
)
{
struct
cipher_data
*
cdat
=
t
->
data
;
unsigned
char
*
in
,
*
out
,
*
tmp
=
NULL
;
...
...
@@ -854,9 +860,21 @@ static int cipher_test_enc(struct evp_test *t, int enc)
out
=
cdat
->
plaintext
;
out_len
=
cdat
->
plaintext_len
;
}
tmp
=
OPENSSL_malloc
(
in_len
+
2
*
EVP_MAX_BLOCK_LENGTH
);
inp_misalign
+=
16
-
((
out_misalign
+
in_len
)
&
15
);
/*
* 'tmp' will store both output and copy of input. We make the copy
* of input to specifically aligned part of 'tmp'. So we just
* figured out how much padding would ensure the required alignment,
* now we allocate extended buffer and finally copy the input just
* past inp_misalign in expression below. Output will be written
* past out_misalign...
*/
tmp
=
OPENSSL_malloc
(
out_misalign
+
in_len
+
2
*
EVP_MAX_BLOCK_LENGTH
+
inp_misalign
+
in_len
);
if
(
!
tmp
)
goto
err
;
in
=
memcpy
(
tmp
+
out_misalign
+
in_len
+
2
*
EVP_MAX_BLOCK_LENGTH
+
inp_misalign
,
in
,
in_len
);
err
=
"CIPHERINIT_ERROR"
;
if
(
!
EVP_CipherInit_ex
(
ctx
,
cdat
->
cipher
,
NULL
,
NULL
,
NULL
,
enc
))
goto
err
;
...
...
@@ -918,20 +936,20 @@ static int cipher_test_enc(struct evp_test *t, int enc)
}
EVP_CIPHER_CTX_set_padding
(
ctx
,
0
);
err
=
"CIPHERUPDATE_ERROR"
;
if
(
!
EVP_CipherUpdate
(
ctx
,
tmp
,
&
tmplen
,
in
,
in_len
))
if
(
!
EVP_CipherUpdate
(
ctx
,
tmp
+
out_misalign
,
&
tmplen
,
in
,
in_len
))
goto
err
;
if
(
cdat
->
aead
==
EVP_CIPH_CCM_MODE
)
tmpflen
=
0
;
else
{
err
=
"CIPHERFINAL_ERROR"
;
if
(
!
EVP_CipherFinal_ex
(
ctx
,
tmp
+
tmplen
,
&
tmpflen
))
if
(
!
EVP_CipherFinal_ex
(
ctx
,
tmp
+
out_misalign
+
tmplen
,
&
tmpflen
))
goto
err
;
}
err
=
"LENGTH_MISMATCH"
;
if
(
out_len
!=
(
size_t
)(
tmplen
+
tmpflen
))
goto
err
;
err
=
"VALUE_MISMATCH"
;
if
(
check_output
(
t
,
out
,
tmp
,
out_len
))
if
(
check_output
(
t
,
out
,
tmp
+
out_misalign
,
out_len
))
goto
err
;
if
(
enc
&&
cdat
->
aead
)
{
unsigned
char
rtag
[
16
];
...
...
@@ -961,6 +979,8 @@ static int cipher_test_run(struct evp_test *t)
{
struct
cipher_data
*
cdat
=
t
->
data
;
int
rv
;
size_t
out_misalign
,
inp_misalign
;
if
(
!
cdat
->
key
)
{
t
->
err
=
"NO_KEY"
;
return
0
;
...
...
@@ -976,24 +996,35 @@ static int cipher_test_run(struct evp_test *t)
t
->
err
=
"NO_TAG"
;
return
0
;
}
if
(
cdat
->
enc
)
{
rv
=
cipher_test_enc
(
t
,
1
);
/* Not fatal errors: return */
if
(
rv
!=
1
)
{
if
(
rv
<
0
)
return
0
;
return
1
;
}
}
if
(
cdat
->
enc
!=
1
)
{
rv
=
cipher_test_enc
(
t
,
0
);
/* Not fatal errors: return */
if
(
rv
!=
1
)
{
if
(
rv
<
0
)
return
0
;
return
1
;
for
(
out_misalign
=
0
;
out_misalign
<=
1
;
out_misalign
++
)
{
static
char
aux_err
[
64
];
t
->
aux_err
=
aux_err
;
for
(
inp_misalign
=
0
;
inp_misalign
<=
1
;
inp_misalign
++
)
{
BIO_snprintf
(
aux_err
,
sizeof
(
aux_err
),
"%s output and %s input"
,
out_misalign
?
"misaligned"
:
"aligned"
,
inp_misalign
?
"misaligned"
:
"aligned"
);
if
(
cdat
->
enc
)
{
rv
=
cipher_test_enc
(
t
,
1
,
out_misalign
,
inp_misalign
);
/* Not fatal errors: return */
if
(
rv
!=
1
)
{
if
(
rv
<
0
)
return
0
;
return
1
;
}
}
if
(
cdat
->
enc
!=
1
)
{
rv
=
cipher_test_enc
(
t
,
0
,
out_misalign
,
inp_misalign
);
/* Not fatal errors: return */
if
(
rv
!=
1
)
{
if
(
rv
<
0
)
return
0
;
return
1
;
}
}
}
}
t
->
aux_err
=
NULL
;
return
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录