Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
M
mbedtls
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
Wiki
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
esp-mirror
Mbed-TLS
mbedtls
提交
87be9db6
提交
87be9db6
编辑于
9 months ago
作者:
Valerio Setti
浏览文件
操作
下载
补丁
差异文件
psasim: add AUT for key derivation
Signed-off-by:
Valerio Setti
<
valerio.setti@nordicsemi.no
>
上级
a06b22d7
No related branches found
分支 包含提交
No related tags found
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
tests/psa-client-server/psasim/src/aut_main.c
+2
-0
2 个添加, 0 个删除
tests/psa-client-server/psasim/src/aut_main.c
tests/psa-client-server/psasim/src/aut_psa_hkdf.c
+121
-0
121 个添加, 0 个删除
tests/psa-client-server/psasim/src/aut_psa_hkdf.c
有
123 个添加
和
0 个删除
tests/psa-client-server/psasim/src/aut_main.c
+
2
−
0
浏览文件 @
87be9db6
...
...
@@ -27,6 +27,7 @@ int psa_random_main(void);
int
psa_mac_main
(
void
);
int
psa_key_agreement_main
(
void
);
int
psa_sign_verify_main
(
void
);
int
psa_hkdf_main
(
void
);
#define TEST_MODULE(main_func) \
do { \
...
...
@@ -59,6 +60,7 @@ int main()
TEST_MODULE
(
psa_key_agreement_main
());
TEST_MODULE
(
psa_sign_verify_main
());
TEST_MODULE
(
psa_aead_encrypt_decrypt_main
());
TEST_MODULE
(
psa_hkdf_main
());
exit:
return
(
ret
!=
0
)
?
1
:
0
;
...
...
此差异已折叠。
点击以展开。
tests/psa-client-server/psasim/src/aut_psa_hkdf.c
0 → 100644
+
121
−
0
浏览文件 @
87be9db6
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/
#include
"psa/crypto.h"
#include
<string.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
"mbedtls/build_info.h"
int
psa_hkdf_main
(
void
)
{
psa_status_t
status
;
psa_key_attributes_t
attributes
=
PSA_KEY_ATTRIBUTES_INIT
;
psa_key_id_t
key_id
=
0
;
psa_key_derivation_operation_t
operation
=
PSA_KEY_DERIVATION_OPERATION_INIT
;
/* Example test vector from RFC 5869 */
/* Input keying material (IKM) */
unsigned
char
ikm
[]
=
{
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
};
unsigned
char
salt
[]
=
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0c
};
/* Context and application specific information, which can be of zero length */
unsigned
char
info
[]
=
{
0xf0
,
0xf1
,
0xf2
,
0xf3
,
0xf4
,
0xf5
,
0xf6
,
0xf7
,
0xf8
,
0xf9
};
/* Expected OKM based on the RFC 5869-provided test vector */
unsigned
char
expected_okm
[]
=
{
0x3c
,
0xb2
,
0x5f
,
0x25
,
0xfa
,
0xac
,
0xd5
,
0x7a
,
0x90
,
0x43
,
0x4f
,
0x64
,
0xd0
,
0x36
,
0x2f
,
0x2a
,
0x2d
,
0x2d
,
0x0a
,
0x90
,
0xcf
,
0x1a
,
0x5a
,
0x4c
,
0x5d
,
0xb0
,
0x2d
,
0x56
,
0xec
,
0xc4
,
0xc5
,
0xbf
,
0x34
,
0x00
,
0x72
,
0x08
,
0xd5
,
0xb8
,
0x87
,
0x18
,
0x58
,
0x65
};
/* The output size of the HKDF function depends on the hash function used.
* In our case we use SHA-256, which produces a 32 byte fingerprint.
* Therefore, we allocate a buffer of 32 bytes to hold the output keying
* material (OKM).
*/
unsigned
char
output
[
32
];
psa_algorithm_t
alg
=
PSA_ALG_HKDF
(
PSA_ALG_SHA_256
);
printf
(
"PSA Crypto API: HKDF SHA-256 example
\n\n
"
);
status
=
psa_crypto_init
();
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_crypto_init failed
\n
"
);
return
EXIT_FAILURE
;
}
psa_set_key_usage_flags
(
&
attributes
,
PSA_KEY_USAGE_DERIVE
);
psa_set_key_algorithm
(
&
attributes
,
PSA_ALG_HKDF
(
PSA_ALG_SHA_256
));
psa_set_key_type
(
&
attributes
,
PSA_KEY_TYPE_DERIVE
);
status
=
psa_import_key
(
&
attributes
,
ikm
,
sizeof
(
ikm
),
&
key_id
);
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_import_key failed
\n
"
);
return
EXIT_FAILURE
;
}
status
=
psa_key_derivation_setup
(
&
operation
,
alg
);
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_key_derivation_setup failed"
);
return
EXIT_FAILURE
;
}
status
=
psa_key_derivation_input_bytes
(
&
operation
,
PSA_KEY_DERIVATION_INPUT_SALT
,
salt
,
sizeof
(
salt
));
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_key_derivation_input_bytes (salt) failed"
);
return
EXIT_FAILURE
;
}
status
=
psa_key_derivation_input_key
(
&
operation
,
PSA_KEY_DERIVATION_INPUT_SECRET
,
key_id
);
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_key_derivation_input_key failed"
);
return
EXIT_FAILURE
;
}
status
=
psa_key_derivation_input_bytes
(
&
operation
,
PSA_KEY_DERIVATION_INPUT_INFO
,
info
,
sizeof
(
info
));
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_key_derivation_input_bytes (info) failed"
);
return
EXIT_FAILURE
;
}
status
=
psa_key_derivation_output_bytes
(
&
operation
,
output
,
sizeof
(
output
));
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_key_derivation_output_bytes failed"
);
return
EXIT_FAILURE
;
}
status
=
psa_key_derivation_abort
(
&
operation
);
if
(
status
!=
PSA_SUCCESS
)
{
printf
(
"psa_key_derivation_abort failed"
);
return
EXIT_FAILURE
;
}
printf
(
"OKM:
\n
"
);
for
(
size_t
j
=
0
;
j
<
sizeof
(
output
);
j
++
)
{
if
(
output
[
j
]
!=
expected_okm
[
j
])
{
printf
(
"
\n
--- Unexpected outcome!
\n
"
);
return
EXIT_FAILURE
;
}
if
(
j
%
8
==
0
)
{
printf
(
"
\n
"
);
}
printf
(
"%02x "
,
output
[
j
]);
}
printf
(
"
\n
"
);
mbedtls_psa_crypto_free
();
return
EXIT_SUCCESS
;
}
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录