Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
b3a45e7d
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,发现更多精彩内容 >>
提交
b3a45e7d
编写于
4月 18, 2011
作者:
D
Dr. Stephen Henson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CCM encrypt algorithm test support.
上级
23916810
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
117 addition
and
3 deletion
+117
-3
fips/aes/fips_gcmtest.c
fips/aes/fips_gcmtest.c
+117
-3
未找到文件。
fips/aes/fips_gcmtest.c
浏览文件 @
b3a45e7d
...
@@ -288,7 +288,7 @@ static void xtstest(FILE *in, FILE *out)
...
@@ -288,7 +288,7 @@ static void xtstest(FILE *in, FILE *out)
else
if
(
!
strncmp
(
buf
,
"[DECRYPT]"
,
9
))
else
if
(
!
strncmp
(
buf
,
"[DECRYPT]"
,
9
))
encrypt
=
0
;
encrypt
=
0
;
}
}
if
(
!
parse_line
(
&
keyword
,
&
value
,
lbuf
,
buf
))
if
(
!
parse_line
(
&
keyword
,
&
value
,
lbuf
,
buf
))
continue
;
continue
;
else
if
(
!
strcmp
(
keyword
,
"Key"
))
else
if
(
!
strcmp
(
keyword
,
"Key"
))
{
{
...
@@ -337,10 +337,120 @@ static void xtstest(FILE *in, FILE *out)
...
@@ -337,10 +337,120 @@ static void xtstest(FILE *in, FILE *out)
}
}
}
}
static
void
ccmencrypt
(
FILE
*
in
,
FILE
*
out
)
{
char
buf
[
2048
];
char
lbuf
[
2048
];
char
*
keyword
,
*
value
;
long
l
;
unsigned
char
*
Key
=
NULL
,
*
Nonce
=
NULL
;
unsigned
char
*
Adata
=
NULL
,
*
Payload
=
NULL
;
unsigned
char
*
CT
=
NULL
;
int
Plen
=
-
1
,
Nlen
=
-
1
,
Tlen
=
-
1
,
Alen
=
-
1
;
EVP_CIPHER_CTX
ctx
;
const
EVP_CIPHER
*
ccm
=
NULL
;
FIPS_cipher_ctx_init
(
&
ctx
);
while
(
fgets
(
buf
,
sizeof
buf
,
in
)
!=
NULL
)
{
fputs
(
buf
,
out
);
if
(
!
parse_line
(
&
keyword
,
&
value
,
lbuf
,
buf
))
continue
;
/* If surrounded by square brackets zap them */
if
(
keyword
[
0
]
==
'['
)
{
char
*
p
;
keyword
++
;
p
=
strchr
(
value
,
']'
);
if
(
p
)
*
p
=
0
;
}
if
(
!
strcmp
(
keyword
,
"Plen"
))
Plen
=
atoi
(
value
);
else
if
(
!
strcmp
(
keyword
,
"Nlen"
))
Nlen
=
atoi
(
value
);
else
if
(
!
strcmp
(
keyword
,
"Tlen"
))
Tlen
=
atoi
(
value
);
else
if
(
!
strcmp
(
keyword
,
"Alen"
))
Alen
=
atoi
(
value
);
else
if
(
!
strcmp
(
keyword
,
"Key"
))
{
if
(
Key
)
OPENSSL_free
(
Key
);
Key
=
hex2bin_m
(
value
,
&
l
);
if
(
l
==
16
)
ccm
=
EVP_aes_128_ccm
();
else
if
(
l
==
24
)
ccm
=
EVP_aes_192_ccm
();
else
if
(
l
==
32
)
ccm
=
EVP_aes_256_ccm
();
else
{
fprintf
(
stderr
,
"Inconsistent Key length
\n
"
);
exit
(
1
);
}
}
else
if
(
!
strcmp
(
keyword
,
"Nonce"
))
{
if
(
Nonce
)
OPENSSL_free
(
Nonce
);
Nonce
=
hex2bin_m
(
value
,
&
l
);
if
(
l
!=
Nlen
)
{
fprintf
(
stderr
,
"Inconsistent nonce length
\n
"
);
exit
(
1
);
}
}
else
if
(
!
strcmp
(
keyword
,
"Payload"
))
{
Payload
=
hex2bin_m
(
value
,
&
l
);
if
(
Plen
&&
l
!=
Plen
)
{
fprintf
(
stderr
,
"Inconsistent Payload length
\n
"
);
exit
(
1
);
}
}
else
if
(
!
strcmp
(
keyword
,
"Adata"
))
{
Adata
=
hex2bin_m
(
value
,
&
l
);
if
(
Alen
&&
l
!=
Alen
)
{
fprintf
(
stderr
,
"Inconsistent Payload length
\n
"
);
exit
(
1
);
}
}
if
(
Payload
)
{
FIPS_cipherinit
(
&
ctx
,
ccm
,
NULL
,
NULL
,
1
);
FIPS_cipher_ctx_ctrl
(
&
ctx
,
EVP_CTRL_CCM_SET_IVLEN
,
Nlen
,
0
);
FIPS_cipher_ctx_ctrl
(
&
ctx
,
EVP_CTRL_CCM_SET_TAG
,
Tlen
,
0
);
FIPS_cipherinit
(
&
ctx
,
NULL
,
Key
,
Nonce
,
1
);
FIPS_cipher
(
&
ctx
,
NULL
,
NULL
,
Plen
);
FIPS_cipher
(
&
ctx
,
NULL
,
Adata
,
Alen
);
CT
=
OPENSSL_malloc
(
Plen
+
Tlen
);
FIPS_cipher
(
&
ctx
,
CT
,
Payload
,
Plen
);
FIPS_cipher_ctx_ctrl
(
&
ctx
,
EVP_CTRL_CCM_GET_TAG
,
Tlen
,
CT
+
Plen
);
OutputValue
(
"CT"
,
CT
,
Plen
+
Tlen
,
out
,
0
);
OPENSSL_free
(
CT
);
OPENSSL_free
(
Payload
);
CT
=
Payload
=
NULL
;
}
}
if
(
Key
)
OPENSSL_free
(
Key
);
if
(
Nonce
)
OPENSSL_free
(
Nonce
);
FIPS_cipher_ctx_cleanup
(
&
ctx
);
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
encrypt
;
int
encrypt
;
int
xts
=
0
;
int
xts
=
0
,
ccmenc
=
0
;
FILE
*
in
,
*
out
;
FILE
*
in
,
*
out
;
if
(
argc
==
4
)
if
(
argc
==
4
)
{
{
...
@@ -374,6 +484,8 @@ int main(int argc,char **argv)
...
@@ -374,6 +484,8 @@ int main(int argc,char **argv)
encrypt
=
2
;
encrypt
=
2
;
else
if
(
!
strcmp
(
argv
[
1
],
"-decrypt"
))
else
if
(
!
strcmp
(
argv
[
1
],
"-decrypt"
))
encrypt
=
0
;
encrypt
=
0
;
else
if
(
!
strcmp
(
argv
[
1
],
"-ccmencrypt"
))
ccmenc
=
1
;
else
if
(
!
strcmp
(
argv
[
1
],
"-xts"
))
else
if
(
!
strcmp
(
argv
[
1
],
"-xts"
))
xts
=
1
;
xts
=
1
;
else
else
...
@@ -382,7 +494,9 @@ int main(int argc,char **argv)
...
@@ -382,7 +494,9 @@ int main(int argc,char **argv)
exit
(
1
);
exit
(
1
);
}
}
if
(
xts
)
if
(
ccmenc
)
ccmencrypt
(
in
,
out
);
else
if
(
xts
)
xtstest
(
in
,
out
);
xtstest
(
in
,
out
);
else
else
gcmtest
(
in
,
out
,
encrypt
);
gcmtest
(
in
,
out
,
encrypt
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录