Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
e6bd5e8a
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
1 年多 前同步成功
通知
10
Star
18
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e6bd5e8a
编写于
5月 31, 2002
作者:
R
Richard Levitte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make it possible to give vectors only for decryption or encryption.
上级
94f1b50c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
62 deletion
+79
-62
crypto/evp/evp_test.c
crypto/evp/evp_test.c
+79
-62
未找到文件。
crypto/evp/evp_test.c
浏览文件 @
e6bd5e8a
...
...
@@ -123,13 +123,15 @@ static unsigned char *ustrsep(char **p,const char *sep)
static
void
test1
(
const
EVP_CIPHER
*
c
,
const
unsigned
char
*
key
,
int
kn
,
const
unsigned
char
*
iv
,
int
in
,
const
unsigned
char
*
plaintext
,
int
pn
,
const
unsigned
char
*
ciphertext
,
int
cn
)
const
unsigned
char
*
ciphertext
,
int
cn
,
int
encdec
)
{
EVP_CIPHER_CTX
ctx
;
unsigned
char
out
[
4096
];
int
outl
,
outl2
;
printf
(
"Testing cipher %s
\n
"
,
EVP_CIPHER_name
(
c
));
printf
(
"Testing cipher %s%s
\n
"
,
EVP_CIPHER_name
(
c
),
(
encdec
==
1
?
"(encrypt)"
:
(
encdec
==
0
?
"(decrypt)"
:
"(encrypt/decrypt)"
)));
hexdump
(
stdout
,
"Key"
,
key
,
kn
);
if
(
in
)
hexdump
(
stdout
,
"IV"
,
iv
,
in
);
...
...
@@ -143,70 +145,76 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
exit
(
5
);
}
EVP_CIPHER_CTX_init
(
&
ctx
);
if
(
!
EVP_EncryptInit_ex
(
&
ctx
,
c
,
NULL
,
key
,
iv
))
{
fprintf
(
stderr
,
"EncryptInit failed
\n
"
);
exit
(
10
);
}
EVP_CIPHER_CTX_set_padding
(
&
ctx
,
0
);
if
(
encdec
!=
0
)
{
if
(
!
EVP_EncryptInit_ex
(
&
ctx
,
c
,
NULL
,
key
,
iv
))
{
fprintf
(
stderr
,
"EncryptInit failed
\n
"
);
exit
(
10
);
}
EVP_CIPHER_CTX_set_padding
(
&
ctx
,
0
);
if
(
!
EVP_EncryptUpdate
(
&
ctx
,
out
,
&
outl
,
plaintext
,
pn
))
{
fprintf
(
stderr
,
"Encrypt failed
\n
"
);
exit
(
6
);
}
if
(
!
EVP_EncryptFinal_ex
(
&
ctx
,
out
+
outl
,
&
outl2
))
{
fprintf
(
stderr
,
"EncryptFinal failed
\n
"
);
exit
(
7
);
}
if
(
!
EVP_EncryptUpdate
(
&
ctx
,
out
,
&
outl
,
plaintext
,
pn
))
{
fprintf
(
stderr
,
"Encrypt failed
\n
"
);
exit
(
6
);
}
if
(
!
EVP_EncryptFinal_ex
(
&
ctx
,
out
+
outl
,
&
outl2
))
{
fprintf
(
stderr
,
"EncryptFinal failed
\n
"
);
exit
(
7
);
}
if
(
outl
+
outl2
!=
cn
)
{
fprintf
(
stderr
,
"Ciphertext length mismatch got %d expected %d
\n
"
,
outl
+
outl2
,
cn
);
exit
(
8
);
}
if
(
outl
+
outl2
!=
cn
)
{
fprintf
(
stderr
,
"Ciphertext length mismatch got %d expected %d
\n
"
,
outl
+
outl2
,
cn
);
exit
(
8
);
}
if
(
memcmp
(
out
,
ciphertext
,
cn
))
{
fprintf
(
stderr
,
"Ciphertext mismatch
\n
"
);
hexdump
(
stderr
,
"Got"
,
out
,
cn
);
hexdump
(
stderr
,
"Expected"
,
ciphertext
,
cn
);
exit
(
9
);
if
(
memcmp
(
out
,
ciphertext
,
cn
))
{
fprintf
(
stderr
,
"Ciphertext mismatch
\n
"
);
hexdump
(
stderr
,
"Got"
,
out
,
cn
);
hexdump
(
stderr
,
"Expected"
,
ciphertext
,
cn
);
exit
(
9
);
}
}
if
(
!
EVP_DecryptInit_ex
(
&
ctx
,
c
,
NULL
,
key
,
iv
))
{
fprintf
(
stderr
,
"DecryptInit failed
\n
"
);
exit
(
11
);
}
EVP_CIPHER_CTX_set_padding
(
&
ctx
,
0
);
if
(
encdec
<=
0
)
{
if
(
!
EVP_DecryptInit_ex
(
&
ctx
,
c
,
NULL
,
key
,
iv
))
{
fprintf
(
stderr
,
"DecryptInit failed
\n
"
);
exit
(
11
);
}
EVP_CIPHER_CTX_set_padding
(
&
ctx
,
0
);
if
(
!
EVP_DecryptUpdate
(
&
ctx
,
out
,
&
outl
,
ciphertext
,
p
n
))
{
fprintf
(
stderr
,
"Decrypt failed
\n
"
);
exit
(
6
);
}
if
(
!
EVP_DecryptFinal_ex
(
&
ctx
,
out
+
outl
,
&
outl2
))
{
fprintf
(
stderr
,
"DecryptFinal failed
\n
"
);
exit
(
7
);
}
if
(
!
EVP_DecryptUpdate
(
&
ctx
,
out
,
&
outl
,
ciphertext
,
c
n
))
{
fprintf
(
stderr
,
"Decrypt failed
\n
"
);
exit
(
6
);
}
if
(
!
EVP_DecryptFinal_ex
(
&
ctx
,
out
+
outl
,
&
outl2
))
{
fprintf
(
stderr
,
"DecryptFinal failed
\n
"
);
exit
(
7
);
}
if
(
outl
+
outl2
!=
cn
)
{
fprintf
(
stderr
,
"Plaintext length mismatch got %d expected %d
\n
"
,
outl
+
outl2
,
cn
);
exit
(
8
);
}
if
(
outl
+
outl2
!=
cn
)
{
fprintf
(
stderr
,
"Plaintext length mismatch got %d expected %d
\n
"
,
outl
+
outl2
,
cn
);
exit
(
8
);
}
if
(
memcmp
(
out
,
plaintext
,
cn
))
{
fprintf
(
stderr
,
"Plaintext mismatch
\n
"
);
hexdump
(
stderr
,
"Got"
,
out
,
cn
);
hexdump
(
stderr
,
"Expected"
,
plaintext
,
cn
);
exit
(
9
);
if
(
memcmp
(
out
,
plaintext
,
cn
))
{
fprintf
(
stderr
,
"Plaintext mismatch
\n
"
);
hexdump
(
stderr
,
"Got"
,
out
,
cn
);
hexdump
(
stderr
,
"Expected"
,
plaintext
,
cn
);
exit
(
9
);
}
}
EVP_CIPHER_CTX_cleanup
(
&
ctx
);
...
...
@@ -217,7 +225,8 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
static
int
test_cipher
(
const
char
*
cipher
,
const
unsigned
char
*
key
,
int
kn
,
const
unsigned
char
*
iv
,
int
in
,
const
unsigned
char
*
plaintext
,
int
pn
,
const
unsigned
char
*
ciphertext
,
int
cn
)
const
unsigned
char
*
ciphertext
,
int
cn
,
int
encdec
)
{
const
EVP_CIPHER
*
c
;
...
...
@@ -225,7 +234,7 @@ static int test_cipher(const char *cipher,const unsigned char *key,int kn,
if
(
!
c
)
return
0
;
test1
(
c
,
key
,
kn
,
iv
,
in
,
plaintext
,
pn
,
ciphertext
,
cn
);
test1
(
c
,
key
,
kn
,
iv
,
in
,
plaintext
,
pn
,
ciphertext
,
cn
,
encdec
);
return
1
;
}
...
...
@@ -332,6 +341,7 @@ int main(int argc,char **argv)
char
*
p
;
char
*
cipher
;
unsigned
char
*
iv
,
*
key
,
*
plaintext
,
*
ciphertext
;
int
encdec
;
int
kn
,
in
,
pn
,
cn
;
if
(
!
fgets
((
char
*
)
line
,
sizeof
line
,
f
))
...
...
@@ -343,14 +353,21 @@ int main(int argc,char **argv)
key
=
ustrsep
(
&
p
,
":"
);
iv
=
ustrsep
(
&
p
,
":"
);
plaintext
=
ustrsep
(
&
p
,
":"
);
ciphertext
=
ustrsep
(
&
p
,
"
\n
"
);
ciphertext
=
ustrsep
(
&
p
,
":"
);
if
(
p
[
-
1
]
==
'\n'
)
{
p
[
-
1
]
=
'\0'
;
encdec
=
-
1
;
}
else
{
encdec
=
atoi
(
ustrsep
(
&
p
,
"
\n
"
));
}
kn
=
convert
(
key
);
in
=
convert
(
iv
);
pn
=
convert
(
plaintext
);
cn
=
convert
(
ciphertext
);
if
(
!
test_cipher
(
cipher
,
key
,
kn
,
iv
,
in
,
plaintext
,
pn
,
ciphertext
,
cn
)
if
(
!
test_cipher
(
cipher
,
key
,
kn
,
iv
,
in
,
plaintext
,
pn
,
ciphertext
,
cn
,
encdec
)
&&
!
test_digest
(
cipher
,
plaintext
,
pn
,
ciphertext
,
cn
))
{
fprintf
(
stderr
,
"Can't find %s
\n
"
,
cipher
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录