Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
0d4e2b02
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0d4e2b02
编写于
1月 22, 2022
作者:
O
openharmony_ci
提交者:
Gitee
1月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1626 设备认证依赖算法测试用例
Merge pull request !1626 from code4lala/deviceauth_alg_xts_test_case
上级
44b25e27
a927a6d4
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
884 addition
and
94 deletion
+884
-94
security_lite/deviceauth_basic_deps/BUILD.gn
security_lite/deviceauth_basic_deps/BUILD.gn
+42
-11
security_lite/deviceauth_basic_deps/README.md
security_lite/deviceauth_basic_deps/README.md
+8
-0
security_lite/deviceauth_basic_deps/deviceauth.gni
security_lite/deviceauth_basic_deps/deviceauth.gni
+24
-0
security_lite/deviceauth_basic_deps/hc_alg_test.c
security_lite/deviceauth_basic_deps/hc_alg_test.c
+716
-78
security_lite/deviceauth_basic_deps/hc_alg_test_case.h
security_lite/deviceauth_basic_deps/hc_alg_test_case.h
+94
-5
未找到文件。
security_lite/deviceauth_basic_deps/BUILD.gn
浏览文件 @
0d4e2b02
...
@@ -50,16 +50,8 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
...
@@ -50,16 +50,8 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
"UTILS_FILE_IMPLEMENTED=1",
"UTILS_FILE_IMPLEMENTED=1",
"TEST_PTHREAD_CREATE_DETACHED=0",
"TEST_PTHREAD_CREATE_DETACHED=0",
"TEST_HC_FILE_OPEN_SERIES=1",
"TEST_HC_FILE_OPEN_SERIES=1",
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=1",
"TEST_IMPORT_ASYMMETRIC_KEY=1",
"TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE=1",
"TEST_HASH_TO_POINT=1",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET=1",
"TEST_BIG_NUM_EXP_MOD=1",
]
]
defines += DEVICEAUTH_BASIC_DEPS_ALGORITHM_DEFINES
if (defined(ohos_lite)) {
if (defined(ohos_lite)) {
include_dirs += [
include_dirs += [
...
@@ -76,11 +68,42 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
...
@@ -76,11 +68,42 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
defines -= [
defines -= [
"FLASH_START_ADDRESS_HICHAIN=0",
"FLASH_START_ADDRESS_HICHAIN=0",
"TEST_HC_FILE_OPEN_SERIES=1",
"TEST_HC_FILE_OPEN_SERIES=1",
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=1",
"TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE=1",
"TEST_HASH_TO_POINT=1",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET=1",
"TEST_GENERATE_KEY_PAIR=1",
"TEST_EXPORT_PUBLIC_KEY=1",
"TEST_ALGORITHM_SIGN=1",
"TEST_ALGORITHM_VERIFY=1",
"TEST_IMPORT_PUBLIC_KEY=1",
"TEST_CHECK_KEY_EXIST=1",
"TEST_DELETE_KEY=1",
"TEST_AES_GCM_ENCRYPT=1",
"TEST_AES_GCM_DECRYPT=1",
]
]
defines += [
defines += [
"FLASH_START_ADDRESS_HICHAIN=0x1F6000",
"FLASH_START_ADDRESS_HICHAIN=0x1F6000",
"TEST_HC_FILE_OPEN_SERIES=0",
"TEST_HC_FILE_OPEN_SERIES=0",
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=0",
"TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE=0",
"TEST_HASH_TO_POINT=0",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=0",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=0",
"TEST_AGREE_SHARED_SECRET=0",
"TEST_GENERATE_KEY_PAIR=0",
"TEST_EXPORT_PUBLIC_KEY=0",
"TEST_ALGORITHM_SIGN=0",
"TEST_ALGORITHM_VERIFY=0",
"TEST_IMPORT_PUBLIC_KEY=0",
"TEST_CHECK_KEY_EXIST=0",
"TEST_DELETE_KEY=0",
"TEST_AES_GCM_ENCRYPT=0",
"TEST_AES_GCM_DECRYPT=0",
]
]
defines += [ "DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY=1" ]
}
}
if (board_name == "hispark_pegasus") {
if (board_name == "hispark_pegasus") {
# 3861
# 3861
...
@@ -90,7 +113,11 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
...
@@ -90,7 +113,11 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=1",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET=1",
"TEST_AGREE_SHARED_SECRET=1",
"TEST_BIG_NUM_EXP_MOD=1",
"TEST_GENERATE_KEY_PAIR=1",
"TEST_EXPORT_PUBLIC_KEY=1",
"TEST_ALGORITHM_SIGN=1",
"TEST_ALGORITHM_VERIFY=1",
"TEST_IMPORT_PUBLIC_KEY=1",
]
]
defines += [
defines += [
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=0",
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=0",
...
@@ -98,7 +125,11 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
...
@@ -98,7 +125,11 @@ hctest_suite("ActsSecurityHichainBasicDeps") {
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=0",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=0",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=0",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=0",
"TEST_AGREE_SHARED_SECRET=0",
"TEST_AGREE_SHARED_SECRET=0",
"TEST_BIG_NUM_EXP_MOD=0",
"TEST_GENERATE_KEY_PAIR=0",
"TEST_EXPORT_PUBLIC_KEY=0",
"TEST_ALGORITHM_SIGN=0",
"TEST_ALGORITHM_VERIFY=0",
"TEST_IMPORT_PUBLIC_KEY=0",
]
]
}
}
} else {
} else {
...
...
security_lite/deviceauth_basic_deps/README.md
0 → 100644
浏览文件 @
0d4e2b02
## wifiiot_hispark_pegasus
1.
compile command:
```
bash
cd test
/xts/tools/lite
./build.sh
product
=
wifiiot
xts
=
acts
target
=
//test/xts/acts/security_lite/deviceauth_basic_deps:ActsSecurityHichainBasicDeps
```
security_lite/deviceauth_basic_deps/deviceauth.gni
浏览文件 @
0d4e2b02
...
@@ -40,3 +40,27 @@ DEVICEAUTH_BASIC_DEPS_INC = [
...
@@ -40,3 +40,27 @@ DEVICEAUTH_BASIC_DEPS_INC = [
"//base/security/deviceauth/common_lib/interfaces",
"//base/security/deviceauth/common_lib/interfaces",
"//base/security/deviceauth/interfaces/innerkits",
"//base/security/deviceauth/interfaces/innerkits",
]
]
DEVICEAUTH_BASIC_DEPS_ALGORITHM_DEFINES = [
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=1",
"TEST_IMPORT_SYMMETRIC_KEY=1",
"TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE=1",
"TEST_HASH_TO_POINT=1",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET=1",
"TEST_BIG_NUM_EXP_MOD=1",
"TEST_EXPORT_IMPORT_SIGN_VERIFY_ED25519=1",
"TEST_EXPORT_IMPORT_SIGN_VERIFY_P256=1",
"TEST_BIG_NUM_COMPARE=1",
"TEST_GENERATE_KEY_PAIR=1",
"TEST_EXPORT_PUBLIC_KEY=1",
"TEST_ALGORITHM_SIGN=1",
"TEST_ALGORITHM_VERIFY=1",
"TEST_IMPORT_PUBLIC_KEY=1",
"TEST_CHECK_DL_PUBLIC_KEY=1",
"TEST_CHECK_KEY_EXIST=1",
"TEST_DELETE_KEY=1",
"TEST_AES_GCM_ENCRYPT=1",
"TEST_AES_GCM_DECRYPT=1",
]
security_lite/deviceauth_basic_deps/hc_alg_test.c
浏览文件 @
0d4e2b02
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include <hal_error.h>
#include <hal_error.h>
#include <hctest.h>
#include <hctest.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string_util.h>
#include <unistd.h>
#include <unistd.h>
#include "hc_alg_test_case.h"
#include "hc_alg_test_case.h"
...
@@ -45,19 +46,25 @@ static uint32_t CountZero(const uint8_t *buffer, uint32_t length)
...
@@ -45,19 +46,25 @@ static uint32_t CountZero(const uint8_t *buffer, uint32_t length)
static
void
FillRandom
(
uint8_t
*
msg
,
uint32_t
setZeroLength
,
uint32_t
randomLength
)
static
void
FillRandom
(
uint8_t
*
msg
,
uint32_t
setZeroLength
,
uint32_t
randomLength
)
{
{
if
(
randomLength
<
1
)
{
return
;
}
int
res
;
int
res
;
res
=
memset_s
(
msg
,
setZeroLength
,
0
,
setZeroLength
);
res
=
memset_s
(
msg
,
setZeroLength
,
0
,
setZeroLength
);
TEST_ASSERT_EQUAL
(
EOK
,
res
);
TEST_ASSERT_EQUAL
(
EOK
,
res
);
// generate random message
if
(
randomLength
==
1
)
{
msg
[
0
]
=
rand
()
%
(
UINT8_MAX
-
1
)
+
1
;
msg
[
0
]
=
rand
()
%
(
UINT8_MAX
-
1
)
+
1
;
}
else
{
for
(
uint32_t
i
=
1
;
i
<
randomLength
;
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
randomLength
;
++
i
)
{
msg
[
i
]
=
rand
()
%
UINT8_MAX
;
msg
[
i
]
=
rand
()
%
UINT8_MAX
;
}
}
enum
{
// ignore rand correctness if the random length is equal or less than 3
RANDOM_CONSECUTIVE_ZERO_LENGTH_LIMIT
=
3
,
};
if
(
randomLength
<=
RANDOM_CONSECUTIVE_ZERO_LENGTH_LIMIT
+
1
)
{
return
;
}
}
TEST_ASSERT_NOT_EQUAL
(
randomLength
,
CountZero
(
msg
,
randomLength
));
TEST_ASSERT_NOT_EQUAL
(
randomLength
-
1
,
CountZero
(
msg
+
1
,
randomLength
-
1
));
}
}
// Note: sha256 and sha256Compare will be set to all zero
// Note: sha256 and sha256Compare will be set to all zero
...
@@ -244,10 +251,9 @@ static void TestComputeHmacWithIsAliasTrue(const AlgLoader *loader,
...
@@ -244,10 +251,9 @@ static void TestComputeHmacWithIsAliasTrue(const AlgLoader *loader,
Uint8Buff
*
msg
,
Uint8Buff
*
hmacKeyBuff
,
Uint8Buff
*
outHmacBuff
)
Uint8Buff
*
msg
,
Uint8Buff
*
hmacKeyBuff
,
Uint8Buff
*
outHmacBuff
)
#if TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE
#if TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE
{
{
TEST_ASSERT_NOT_NULL
(
loader
->
importAsymmetricKey
);
TEST_ASSERT_NOT_NULL
(
loader
->
importSymmetricKey
);
TEST_ASSERT_NOT_NULL
(
loader
->
deleteKey
);
if
(
!
loader
->
importSymmetricKey
)
{
if
(
loader
->
importAsymmetricKey
==
NULL
||
loader
->
deleteKey
==
NULL
)
{
LOGE
(
"importSymmetricKey is NULL, can not test computeHmac with isAlias true"
);
LOGE
(
"importAsymmetricKey or deleteKey is NULL, can not test computeHmac with isAlias true"
);
return
;
return
;
}
}
LOGI
(
"test hmac for isAlias true"
);
LOGI
(
"test hmac for isAlias true"
);
...
@@ -260,19 +266,24 @@ static void TestComputeHmacWithIsAliasTrue(const AlgLoader *loader,
...
@@ -260,19 +266,24 @@ static void TestComputeHmacWithIsAliasTrue(const AlgLoader *loader,
.
userType
=
DEVICE_TYPE_ACCESSORY
,
.
userType
=
DEVICE_TYPE_ACCESSORY
,
.
pairType
=
PAIR_TYPE_BIND
,
.
pairType
=
PAIR_TYPE_BIND
,
};
};
int
res
=
loader
->
import
AsymmetricKey
(
hmacKeyBuff
,
hmacKeyBuff
,
&
info
);
int
res
=
loader
->
import
SymmetricKey
(
hmacKeyBuff
,
hmacKeyBuff
,
KEY_PURPOSE_MAC
,
&
info
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TestComputeHmacInner
(
loader
,
hmacKeyBuff
,
msg
,
outHmacBuff
,
true
);
TestComputeHmacInner
(
loader
,
hmacKeyBuff
,
msg
,
outHmacBuff
,
true
);
// delete key after the test
// delete key after the test
if
(
loader
->
deleteKey
)
{
LOGD
(
"test deleteKey"
);
res
=
loader
->
deleteKey
(
hmacKeyBuff
);
res
=
loader
->
deleteKey
(
hmacKeyBuff
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
}
}
}
#else // TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE
#else // TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE
{
{
LOGE
(
"no TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE, do not test computeHmac with isAlias true"
);
LOGE
(
"no TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE, do not test computeHmac with isAlias true"
);
TEST_ASSERT_TRUE
(
loader
->
importAsymmetricKey
==
NULL
||
loader
->
deleteKey
==
NULL
);
#if (defined(DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY) && DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY)
LOG_ERROR_IF_POINTER_NULL
(
loader
->
importAsymmetricKey
);
(
void
)(
loader
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
deleteKey
);
#else // DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY
TEST_ASSERT_NULL
(
loader
->
importSymmetricKey
);
#endif // DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY
(
void
)(
msg
);
(
void
)(
msg
);
(
void
)(
hmacKeyBuff
);
(
void
)(
hmacKeyBuff
);
(
void
)(
outHmacBuff
);
(
void
)(
outHmacBuff
);
...
@@ -423,9 +434,8 @@ static void TestComputeHkdfWithKeyAliasTrue(
...
@@ -423,9 +434,8 @@ static void TestComputeHkdfWithKeyAliasTrue(
LOGI
(
"pake psk derive secret keyAlias true"
);
LOGI
(
"pake psk derive secret keyAlias true"
);
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
agreeSharedSecretWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
agreeSharedSecretWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
deleteKey
);
if
(
!
loader
->
generateKeyPairWithStorage
||
!
loader
->
agreeSharedSecretWithStorage
)
{
if
(
!
loader
->
generateKeyPairWithStorage
||
!
loader
->
agreeSharedSecretWithStorage
||
!
loader
->
deleteKey
)
{
LOGE
(
"generateKeyPairWithStorage or agreeSharedSecretWithStorage pointer is NULL! "
LOGE
(
"generateKeyPairWithStorage or agreeSharedSecretWithStorage or deleteKey pointer is NULL! "
"can not test hkdf with alias true!"
);
"can not test hkdf with alias true!"
);
return
;
return
;
}
}
...
@@ -452,9 +462,12 @@ static void TestComputeHkdfWithKeyAliasTrue(
...
@@ -452,9 +462,12 @@ static void TestComputeHkdfWithKeyAliasTrue(
loader
,
&
privKeyPairAlias
,
&
pubKeyPairAlias
,
&
extraInfo
,
&
sharedKeyAlias
);
loader
,
&
privKeyPairAlias
,
&
pubKeyPairAlias
,
&
extraInfo
,
&
sharedKeyAlias
);
TestComputeHkdfWithKeyAliasTrueThirdStep
(
TestComputeHkdfWithKeyAliasTrueThirdStep
(
loader
,
argument
,
&
sharedKeyAlias
);
loader
,
argument
,
&
sharedKeyAlias
);
if
(
loader
->
deleteKey
)
{
LOGD
(
"test deleteKey"
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
privKeyPairAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
privKeyPairAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
pubKeyPairAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
pubKeyPairAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
sharedKeyAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
sharedKeyAlias
));
}
LOGD
(
"At last, free all memories allocated"
);
LOGD
(
"At last, free all memories allocated"
);
free
(
privKeyPairAlias
.
val
);
free
(
privKeyPairAlias
.
val
);
...
@@ -472,11 +485,9 @@ static void TestComputeHkdfWithKeyAliasTrue(
...
@@ -472,11 +485,9 @@ static void TestComputeHkdfWithKeyAliasTrue(
struct
HkdfArgument
*
argument
)
struct
HkdfArgument
*
argument
)
{
{
LOGE
(
"no TEST_HKDF_WITH_KEY_ALIAS_TRUE, do not test hkdf with key alias true"
);
LOGE
(
"no TEST_HKDF_WITH_KEY_ALIAS_TRUE, do not test hkdf with key alias true"
);
TEST_ASSERT_TRUE
(
loader
->
generateKeyPairWithStorage
==
NULL
||
loader
->
agreeSharedSecretWithStorage
==
NULL
||
TEST_ASSERT_TRUE
(
loader
->
generateKeyPairWithStorage
==
NULL
||
loader
->
agreeSharedSecretWithStorage
==
NULL
);
loader
->
deleteKey
==
NULL
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
generateKeyPairWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
generateKeyPairWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
agreeSharedSecretWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
agreeSharedSecretWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
deleteKey
);
(
void
)(
argument
);
(
void
)(
argument
);
}
}
#endif // TEST_HKDF_WITH_KEY_ALIAS_TRUE // }
#endif // TEST_HKDF_WITH_KEY_ALIAS_TRUE // }
...
@@ -543,30 +554,30 @@ static void TestComputeHkdf(const AlgLoader *loader)
...
@@ -543,30 +554,30 @@ static void TestComputeHkdf(const AlgLoader *loader)
TestComputeHkdfCorrectness
(
loader
,
&
argument
);
TestComputeHkdfCorrectness
(
loader
,
&
argument
);
}
}
#if TEST_IMPORT_
A
SYMMETRIC_KEY // {
#if TEST_IMPORT_SYMMETRIC_KEY // {
enum
{
enum
{
WAIT_FOR_WATCH_DOG
=
1
,
WAIT_FOR_WATCH_DOG
=
1
,
};
};
static
void
TestImport
As
ymmetricKey
(
const
AlgLoader
*
loader
)
static
void
TestImport
S
ymmetricKey
(
const
AlgLoader
*
loader
)
{
{
TEST_ASSERT_NOT_NULL
(
loader
->
import
As
ymmetricKey
);
TEST_ASSERT_NOT_NULL
(
loader
->
import
S
ymmetricKey
);
if
(
loader
->
import
As
ymmetricKey
==
NULL
)
{
if
(
loader
->
import
S
ymmetricKey
==
NULL
)
{
LOGE
(
"import
As
ymmetricKey pointer is NULL! will not test!"
);
LOGE
(
"import
S
ymmetricKey pointer is NULL! will not test!"
);
return
;
return
;
}
}
int
res
;
int
res
;
const
uint32_t
authIdLenArray
[]
=
{
TEST_IMPORT_
A
SYMMETRIC_KEY_AUTH_ID_LENGTH_32
,
const
uint32_t
authIdLenArray
[]
=
{
TEST_IMPORT_SYMMETRIC_KEY_AUTH_ID_LENGTH_32
,
TEST_IMPORT_
A
SYMMETRIC_KEY_AUTH_ID_LENGTH_64
};
TEST_IMPORT_SYMMETRIC_KEY_AUTH_ID_LENGTH_64
};
for
(
uint32_t
i
=
0
;
i
<
ARRAY_SIZE
(
authIdLenArray
);
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
ARRAY_SIZE
(
authIdLenArray
);
++
i
)
{
for
(
for
(
uint32_t
j
=
IMPORT_
A
SYMMETRIC_KEY_KEYALIAS_LEN_MIN
;
uint32_t
j
=
IMPORT_SYMMETRIC_KEY_KEYALIAS_LEN_MIN
;
j
<=
IMPORT_
A
SYMMETRIC_KEY_KEYALIAS_LEN_MAX
;
j
<=
IMPORT_SYMMETRIC_KEY_KEYALIAS_LEN_MAX
;
++
j
)
{
++
j
)
{
LOGD
(
"auth id length = %
d, msg length = %d
"
,
authIdLenArray
[
i
],
j
);
LOGD
(
"auth id length = %
u, msg length = %u
"
,
authIdLenArray
[
i
],
j
);
Uint8Buff
keyAlias
=
{
(
uint8_t
*
)
malloc
(
j
),
j
};
Uint8Buff
keyAlias
=
{
(
uint8_t
*
)
malloc
(
j
),
j
};
Uint8Buff
authToken
=
{
(
uint8_t
*
)
malloc
(
IMPORT_
A
SYMMETRIC_KEY_AUTHTOKEN_LEN
),
Uint8Buff
authToken
=
{
(
uint8_t
*
)
malloc
(
IMPORT_SYMMETRIC_KEY_AUTHTOKEN_LEN
),
IMPORT_
A
SYMMETRIC_KEY_AUTHTOKEN_LEN
};
IMPORT_SYMMETRIC_KEY_AUTHTOKEN_LEN
};
ExtraInfo
extraInfo
=
{
{
(
uint8_t
*
)
malloc
(
authIdLenArray
[
i
]),
authIdLenArray
[
i
]
},
ExtraInfo
extraInfo
=
{
{
(
uint8_t
*
)
malloc
(
authIdLenArray
[
i
]),
authIdLenArray
[
i
]
},
DEVICE_TYPE_ACCESSORY
,
PAIR_TYPE_BIND
};
DEVICE_TYPE_ACCESSORY
,
PAIR_TYPE_BIND
};
TEST_ASSERT_NOT_NULL
(
keyAlias
.
val
);
TEST_ASSERT_NOT_NULL
(
keyAlias
.
val
);
...
@@ -575,14 +586,19 @@ static void TestImportAsymmetricKey(const AlgLoader *loader)
...
@@ -575,14 +586,19 @@ static void TestImportAsymmetricKey(const AlgLoader *loader)
FillRandom
(
keyAlias
.
val
,
keyAlias
.
length
,
keyAlias
.
length
);
FillRandom
(
keyAlias
.
val
,
keyAlias
.
length
,
keyAlias
.
length
);
FillRandom
(
authToken
.
val
,
authToken
.
length
,
authToken
.
length
);
FillRandom
(
authToken
.
val
,
authToken
.
length
,
authToken
.
length
);
FillRandom
(
extraInfo
.
authId
.
val
,
extraInfo
.
authId
.
length
,
extraInfo
.
authId
.
length
);
FillRandom
(
extraInfo
.
authId
.
val
,
extraInfo
.
authId
.
length
,
extraInfo
.
authId
.
length
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
importAsymmetricKey
(
&
keyAlias
,
&
authToken
,
&
extraInfo
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
importSymmetricKey
(
&
keyAlias
,
&
authToken
,
KEY_PURPOSE_MAC
,
&
extraInfo
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
LOGD
(
"test exist"
);
if
(
loader
->
checkKeyExist
)
{
LOGD
(
"test checkKeyExist"
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkKeyExist
(
&
keyAlias
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkKeyExist
(
&
keyAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
}
if
(
loader
->
deleteKey
)
{
LOGD
(
"test delete"
);
LOGD
(
"test delete"
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
deleteKey
(
&
keyAlias
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
deleteKey
(
&
keyAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
}
free
(
keyAlias
.
val
);
free
(
keyAlias
.
val
);
keyAlias
.
val
=
(
uint8_t
*
)
NULL
;
keyAlias
.
val
=
(
uint8_t
*
)
NULL
;
free
(
authToken
.
val
);
free
(
authToken
.
val
);
...
@@ -594,16 +610,16 @@ static void TestImportAsymmetricKey(const AlgLoader *loader)
...
@@ -594,16 +610,16 @@ static void TestImportAsymmetricKey(const AlgLoader *loader)
sleep
(
WAIT_FOR_WATCH_DOG
);
sleep
(
WAIT_FOR_WATCH_DOG
);
}
}
}
}
#else // TEST_IMPORT_
A
SYMMETRIC_KEY // } {
#else // TEST_IMPORT_SYMMETRIC_KEY // } {
static
void
TestImport
As
ymmetricKey
(
const
AlgLoader
*
loader
)
static
void
TestImport
S
ymmetricKey
(
const
AlgLoader
*
loader
)
{
{
LOGE
(
"no TEST_IMPORT_ASYMMETRIC_KEY, do not test importAsymmetricKey"
);
LOGE
(
"no TEST_IMPORT_SYMMETRIC_KEY, do not test importSymmetricKey"
);
TEST_ASSERT_NULL
(
loader
->
importAsymmetricKey
);
TEST_ASSERT_NULL
(
loader
->
importSymmetricKey
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
importAsymmetricKey
);
}
}
#endif // TEST_IMPORT_
A
SYMMETRIC_KEY // }
#endif // TEST_IMPORT_SYMMETRIC_KEY // }
static
void
TestCheckKeyExist
(
const
AlgLoader
*
loader
)
static
void
TestCheckKeyExist
(
const
AlgLoader
*
loader
)
#if TEST_CHECK_KEY_EXIST
{
{
TEST_ASSERT_NOT_NULL
(
loader
->
checkKeyExist
);
TEST_ASSERT_NOT_NULL
(
loader
->
checkKeyExist
);
if
(
loader
->
checkKeyExist
==
NULL
)
{
if
(
loader
->
checkKeyExist
==
NULL
)
{
...
@@ -620,8 +636,15 @@ static void TestCheckKeyExist(const AlgLoader *loader)
...
@@ -620,8 +636,15 @@ static void TestCheckKeyExist(const AlgLoader *loader)
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkKeyExist
(
&
keyAlias
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkKeyExist
(
&
keyAlias
));
TEST_ASSERT_NOT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_NOT_EQUAL
(
HAL_SUCCESS
,
res
);
}
}
#else // TEST_CHECK_KEY_EXIST
{
LOGE
(
"no TEST_CHECK_KEY_EXIST, do not test checkKeyExist"
);
TEST_ASSERT_NULL
(
loader
->
checkKeyExist
);
}
#endif // TEST_CHECK_KEY_EXIST
static
void
TestDeleteKey
(
const
AlgLoader
*
loader
)
static
void
TestDeleteKey
(
const
AlgLoader
*
loader
)
#if TEST_DELETE_KEY
{
{
TEST_ASSERT_NOT_NULL
(
loader
->
deleteKey
);
TEST_ASSERT_NOT_NULL
(
loader
->
deleteKey
);
if
(
loader
->
deleteKey
==
NULL
)
{
if
(
loader
->
deleteKey
==
NULL
)
{
...
@@ -638,8 +661,15 @@ static void TestDeleteKey(const AlgLoader *loader)
...
@@ -638,8 +661,15 @@ static void TestDeleteKey(const AlgLoader *loader)
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
deleteKey
(
&
keyAlias
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
deleteKey
(
&
keyAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
}
}
#else // TEST_DELETE_KEY
{
LOGE
(
"no TEST_DELETE_KEY, do not test deleteKey"
);
TEST_ASSERT_NULL
(
loader
->
deleteKey
);
}
#endif // TEST_DELETE_KEY
static
void
TestAesGcmEncrypt
(
const
AlgLoader
*
loader
)
static
void
TestAesGcmEncrypt
(
const
AlgLoader
*
loader
)
#if TEST_AES_GCM_ENCRYPT
{
{
LOGI
(
"begin to test the AES-GCM algorithm encryption"
);
LOGI
(
"begin to test the AES-GCM algorithm encryption"
);
TEST_ASSERT_NOT_NULL
(
loader
->
aesGcmEncrypt
);
TEST_ASSERT_NOT_NULL
(
loader
->
aesGcmEncrypt
);
...
@@ -674,8 +704,15 @@ static void TestAesGcmEncrypt(const AlgLoader *loader)
...
@@ -674,8 +704,15 @@ static void TestAesGcmEncrypt(const AlgLoader *loader)
free
(
nonce
);
free
(
nonce
);
free
(
cipher
);
free
(
cipher
);
}
}
#else // TEST_AES_GCM_ENCRYPT
{
LOGE
(
"no TEST_AES_GCM_ENCRYPT, do not test aesGcmEncrypt"
);
TEST_ASSERT_NULL
(
loader
->
aesGcmEncrypt
);
}
#endif // TEST_AES_GCM_ENCRYPT
static
void
TestAesGcmDecrypt
(
const
AlgLoader
*
loader
)
static
void
TestAesGcmDecrypt
(
const
AlgLoader
*
loader
)
#if TEST_AES_GCM_DECRYPT
{
{
LOGI
(
"begin to test the AES-GCM algorithm decryption"
);
LOGI
(
"begin to test the AES-GCM algorithm decryption"
);
TEST_ASSERT_NOT_NULL
(
loader
->
aesGcmDecrypt
);
TEST_ASSERT_NOT_NULL
(
loader
->
aesGcmDecrypt
);
...
@@ -710,6 +747,12 @@ static void TestAesGcmDecrypt(const AlgLoader *loader)
...
@@ -710,6 +747,12 @@ static void TestAesGcmDecrypt(const AlgLoader *loader)
free
(
nonce
);
free
(
nonce
);
free
(
plain
);
free
(
plain
);
}
}
#else // TEST_AES_GCM_DECRYPT
{
LOGE
(
"no TEST_AES_GCM_DECRYPT, do not test aesGcmDecrypt"
);
TEST_ASSERT_NULL
(
loader
->
aesGcmDecrypt
);
}
#endif // TEST_AES_GCM_DECRYPT
static
void
TestHashToPoint
(
const
AlgLoader
*
loader
)
static
void
TestHashToPoint
(
const
AlgLoader
*
loader
)
#if TEST_HASH_TO_POINT
#if TEST_HASH_TO_POINT
...
@@ -737,7 +780,6 @@ static void TestHashToPoint(const AlgLoader *loader)
...
@@ -737,7 +780,6 @@ static void TestHashToPoint(const AlgLoader *loader)
{
{
LOGE
(
"no TEST_HASH_TO_POINT, do not test loader->hashToPoint!"
);
LOGE
(
"no TEST_HASH_TO_POINT, do not test loader->hashToPoint!"
);
TEST_ASSERT_NULL
(
loader
->
hashToPoint
);
TEST_ASSERT_NULL
(
loader
->
hashToPoint
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
hashToPoint
);
}
}
#endif // TEST_HASH_TO_POINT
#endif // TEST_HASH_TO_POINT
...
@@ -785,9 +827,8 @@ static void TestAgreeSharedSecretWithStorage(const AlgLoader *loader)
...
@@ -785,9 +827,8 @@ static void TestAgreeSharedSecretWithStorage(const AlgLoader *loader)
TEST_ASSERT_NOT_NULL
(
loader
->
agreeSharedSecretWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
agreeSharedSecretWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
computeHkdf
);
TEST_ASSERT_NOT_NULL
(
loader
->
computeHkdf
);
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
deleteKey
);
if
(
!
loader
->
agreeSharedSecretWithStorage
||
!
loader
->
computeHkdf
if
(
!
loader
->
agreeSharedSecretWithStorage
||
!
loader
->
computeHkdf
||
!
loader
->
generateKeyPairWithStorage
||
!
loader
->
deleteKey
)
{
||
!
loader
->
generateKeyPairWithStorage
)
{
LOGE
(
"one of required function pointer is NULL! will not test!"
);
LOGE
(
"one of required function pointer is NULL! will not test!"
);
return
;
return
;
}
}
...
@@ -825,10 +866,13 @@ static void TestAgreeSharedSecretWithStorage(const AlgLoader *loader)
...
@@ -825,10 +866,13 @@ static void TestAgreeSharedSecretWithStorage(const AlgLoader *loader)
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
ret
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
ret
);
VerifyAgreeSharedSecretWithStorage
(
loader
,
&
sharedKeyAlias1
,
&
sharedKeyAlias2
);
VerifyAgreeSharedSecretWithStorage
(
loader
,
&
sharedKeyAlias1
,
&
sharedKeyAlias2
);
if
(
loader
->
deleteKey
)
{
LOGD
(
"test deleteKey"
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
sharedKeyAlias1
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
sharedKeyAlias1
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
sharedKeyAlias2
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
sharedKeyAlias2
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
keyAliasA
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
keyAliasA
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
keyAliasB
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
keyAliasB
));
}
}
}
#else // TEST_AGREE_SHARED_SECRET_WITH_STORAGE
#else // TEST_AGREE_SHARED_SECRET_WITH_STORAGE
static
void
TestAgreeSharedSecretWithStorage
(
const
AlgLoader
*
loader
)
static
void
TestAgreeSharedSecretWithStorage
(
const
AlgLoader
*
loader
)
...
@@ -836,12 +880,10 @@ static void TestAgreeSharedSecretWithStorage(const AlgLoader *loader)
...
@@ -836,12 +880,10 @@ static void TestAgreeSharedSecretWithStorage(const AlgLoader *loader)
LOGE
(
"no TEST_AGREE_SHARED_SECRET_WITH_STORAGE, do not test loader->agreeSharedSecretWithStorage!"
);
LOGE
(
"no TEST_AGREE_SHARED_SECRET_WITH_STORAGE, do not test loader->agreeSharedSecretWithStorage!"
);
TEST_ASSERT_TRUE
(
loader
->
agreeSharedSecretWithStorage
==
NULL
||
TEST_ASSERT_TRUE
(
loader
->
agreeSharedSecretWithStorage
==
NULL
||
loader
->
computeHkdf
==
NULL
||
loader
->
computeHkdf
==
NULL
||
loader
->
generateKeyPairWithStorage
==
NULL
||
loader
->
generateKeyPairWithStorage
==
NULL
);
loader
->
deleteKey
==
NULL
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
agreeSharedSecretWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
agreeSharedSecretWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
computeHkdf
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
computeHkdf
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
generateKeyPairWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
generateKeyPairWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
deleteKey
);
}
}
#endif // TEST_AGREE_SHARED_SECRET_WITH_STORAGE
#endif // TEST_AGREE_SHARED_SECRET_WITH_STORAGE
...
@@ -887,7 +929,6 @@ static void TestAgreeSharedSecret(const AlgLoader *loader)
...
@@ -887,7 +929,6 @@ static void TestAgreeSharedSecret(const AlgLoader *loader)
{
{
LOGE
(
"no TEST_AGREE_SHARED_SECRET, do not test loader->agreeSharedSecret"
);
LOGE
(
"no TEST_AGREE_SHARED_SECRET, do not test loader->agreeSharedSecret"
);
TEST_ASSERT_NULL
(
loader
->
agreeSharedSecret
);
TEST_ASSERT_NULL
(
loader
->
agreeSharedSecret
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
agreeSharedSecret
);
}
}
#endif // TEST_AGREE_SHARED_SECRET
#endif // TEST_AGREE_SHARED_SECRET
...
@@ -895,10 +936,8 @@ static void TestGenerateKeyPairWithStorage(const AlgLoader *loader)
...
@@ -895,10 +936,8 @@ static void TestGenerateKeyPairWithStorage(const AlgLoader *loader)
#if TEST_GENERATE_KEY_PAIR_WITH_STORAGE
#if TEST_GENERATE_KEY_PAIR_WITH_STORAGE
{
{
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
TEST_ASSERT_NOT_NULL
(
loader
->
checkKeyExist
);
if
(
!
loader
->
generateKeyPairWithStorage
)
{
TEST_ASSERT_NOT_NULL
(
loader
->
deleteKey
);
LOGE
(
"generateKeyPairWithStorage pointer is NULL! will not test!"
);
if
(
!
loader
->
generateKeyPairWithStorage
||
!
loader
->
checkKeyExist
||
!
loader
->
deleteKey
)
{
LOGE
(
"one of required function pointer is NULL! will not test!"
);
return
;
return
;
}
}
...
@@ -918,20 +957,21 @@ static void TestGenerateKeyPairWithStorage(const AlgLoader *loader)
...
@@ -918,20 +957,21 @@ static void TestGenerateKeyPairWithStorage(const AlgLoader *loader)
RUN_AND_PRINT_ELAPSED_TIME
(
ret
,
RUN_AND_PRINT_ELAPSED_TIME
(
ret
,
loader
->
generateKeyPairWithStorage
(
&
keyAlias
,
ED25519_KEY_BYTE_LEN
,
ED25519
,
&
extraInfo
));
loader
->
generateKeyPairWithStorage
(
&
keyAlias
,
ED25519_KEY_BYTE_LEN
,
ED25519
,
&
extraInfo
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
ret
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
ret
);
if
(
loader
->
checkKeyExist
)
{
LOGD
(
"test checkKeyExist"
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
checkKeyExist
(
&
keyAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
checkKeyExist
(
&
keyAlias
));
}
if
(
loader
->
deleteKey
)
{
LOGD
(
"test deleteKey"
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
keyAlias
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
keyAlias
));
}
free
(
extraInfo
.
authId
.
val
);
free
(
extraInfo
.
authId
.
val
);
}
}
#else // TEST_GENERATE_KEY_PAIR_WITH_STORAGE
#else // TEST_GENERATE_KEY_PAIR_WITH_STORAGE
{
{
LOGE
(
"no TEST_GENERATE_KEY_PAIR_WITH_STORAGE, do not test loader->generateKeyPairWithStorage!"
);
LOGE
(
"no TEST_GENERATE_KEY_PAIR_WITH_STORAGE, do not test loader->generateKeyPairWithStorage!"
);
TEST_ASSERT_TRUE
(
loader
->
generateKeyPairWithStorage
==
NULL
||
TEST_ASSERT_NULL
(
loader
->
generateKeyPairWithStorage
);
loader
->
checkKeyExist
==
NULL
||
loader
->
deleteKey
==
NULL
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
generateKeyPairWithStorage
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
checkKeyExist
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
deleteKey
);
}
}
#endif // TEST_GENERATE_KEY_PAIR_WITH_STORAGE
#endif // TEST_GENERATE_KEY_PAIR_WITH_STORAGE
...
@@ -956,7 +996,7 @@ static void TestBigNumExpMod(const AlgLoader *loader)
...
@@ -956,7 +996,7 @@ static void TestBigNumExpMod(const AlgLoader *loader)
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
modResult
.
val
,
primeLength
,
0
,
primeLength
));
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
modResult
.
val
,
primeLength
,
0
,
primeLength
));
int
ret
;
int
ret
;
LOGI
(
"test the big num case: base = %
d, exp = %d, prime = %d
"
,
baseLength
,
expLength
,
primeLength
);
LOGI
(
"test the big num case: base = %
u, exp = %u, prime = %u
"
,
baseLength
,
expLength
,
primeLength
);
RUN_AND_PRINT_ELAPSED_TIME
(
ret
,
loader
->
bigNumExpMod
(
&
base
,
&
exp
,
BIG_NUM_TEST_CASES
[
i
].
prime
,
&
modResult
));
RUN_AND_PRINT_ELAPSED_TIME
(
ret
,
loader
->
bigNumExpMod
(
&
base
,
&
exp
,
BIG_NUM_TEST_CASES
[
i
].
prime
,
&
modResult
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
ret
);
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
ret
);
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
BIG_NUM_TEST_CASES
[
i
].
result
,
modResult
.
val
,
primeLength
);
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
BIG_NUM_TEST_CASES
[
i
].
result
,
modResult
.
val
,
primeLength
);
...
@@ -968,10 +1008,588 @@ static void TestBigNumExpMod(const AlgLoader *loader)
...
@@ -968,10 +1008,588 @@ static void TestBigNumExpMod(const AlgLoader *loader)
{
{
LOGE
(
"no TEST_BIG_NUM_EXP_MOD, do not test loader->bigNumExpMod!"
);
LOGE
(
"no TEST_BIG_NUM_EXP_MOD, do not test loader->bigNumExpMod!"
);
TEST_ASSERT_NULL
(
loader
->
bigNumExpMod
);
TEST_ASSERT_NULL
(
loader
->
bigNumExpMod
);
LOG_ERROR_IF_POINTER_NULL
(
loader
->
bigNumExpMod
);
}
}
#endif // TEST_BIG_NUM_EXP_MOD
#endif // TEST_BIG_NUM_EXP_MOD
static
void
TestGenerateKeyPair
(
const
AlgLoader
*
loader
)
#if TEST_GENERATE_KEY_PAIR
{
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPair
);
LOGE
(
"nobody use generateKeyPair, do not test"
);
}
#else // TEST_GENERATE_KEY_PAIR
{
TEST_ASSERT_NULL
(
loader
->
generateKeyPair
);
LOGE
(
"no TEST_GENERATE_KEY_PAIR, do not test generateKeyPair"
);
}
#endif // TEST_GENERATE_KEY_PAIR
#if (TEST_EXPORT_PUBLIC_KEY || TEST_IMPORT_PUBLIC_KEY || TEST_ALGORITHM_SIGN || TEST_ALGORITHM_VERIFY)
struct
TestExportImportSignVerifyParam
{
ExtraInfo
extInfo
;
Uint8Buff
keyAlias
;
Uint8Buff
outPubKey
;
Uint8Buff
anotherKeyAlias
;
Uint8Buff
messages
[
ARRAY_SIZE
(
TEST_SIGN_MSG_LENGTHES
)];
Uint8Buff
signatures
[
ARRAY_SIZE
(
TEST_SIGN_MSG_LENGTHES
)];
Uint8Buff
anotherOutPk
;
};
static
void
TestExportImportSignVerifyPrepareResources
(
struct
TestExportImportSignVerifyParam
*
param
)
{
param
->
extInfo
.
authId
.
length
=
TEST_EX_IM_SN_VF_EXTRA_INFO_AUTH_ID_LENGTH
;
param
->
extInfo
.
authId
.
val
=
(
uint8_t
*
)
malloc
(
param
->
extInfo
.
authId
.
length
);
param
->
extInfo
.
userType
=
DEVICE_TYPE_ACCESSORY
;
param
->
extInfo
.
pairType
=
PAIR_TYPE_BIND
;
TEST_ASSERT_NOT_NULL
(
param
->
extInfo
.
authId
.
val
);
FillRandom
(
param
->
extInfo
.
authId
.
val
,
param
->
extInfo
.
authId
.
length
,
param
->
extInfo
.
authId
.
length
);
param
->
keyAlias
.
length
=
TEST_EX_IM_SN_VF_KEY_ALIAS_LENGTH
;
param
->
keyAlias
.
val
=
(
uint8_t
*
)
malloc
(
param
->
keyAlias
.
length
);
TEST_ASSERT_NOT_NULL
(
param
->
keyAlias
.
val
);
FillRandom
(
param
->
keyAlias
.
val
,
param
->
keyAlias
.
length
,
param
->
keyAlias
.
length
);
param
->
outPubKey
.
length
=
TEST_EX_IM_SN_VF_OUT_PUB_KEY_LENGTH
;
param
->
outPubKey
.
val
=
(
uint8_t
*
)
malloc
(
param
->
outPubKey
.
length
);
TEST_ASSERT_NOT_NULL
(
param
->
outPubKey
.
val
);
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
param
->
outPubKey
.
val
,
param
->
outPubKey
.
length
,
0
,
param
->
outPubKey
.
length
));
param
->
anotherKeyAlias
.
length
=
TEST_EX_IM_SN_VF_KEY_ALIAS_LENGTH
;
param
->
anotherKeyAlias
.
val
=
(
uint8_t
*
)
malloc
(
param
->
anotherKeyAlias
.
length
);
TEST_ASSERT_NOT_NULL
(
param
->
anotherKeyAlias
.
val
);
do
{
FillRandom
(
param
->
anotherKeyAlias
.
val
,
param
->
anotherKeyAlias
.
length
,
param
->
anotherKeyAlias
.
length
);
}
while
(
memcmp
(
param
->
keyAlias
.
val
,
param
->
anotherKeyAlias
.
val
,
TEST_EX_IM_SN_VF_KEY_ALIAS_LENGTH
)
==
0
);
for
(
uint32_t
i
=
0
;
i
<
ARRAY_SIZE
(
TEST_SIGN_MSG_LENGTHES
);
++
i
)
{
param
->
messages
[
i
].
length
=
TEST_SIGN_MSG_LENGTHES
[
i
];
param
->
messages
[
i
].
val
=
(
uint8_t
*
)
malloc
(
param
->
messages
[
i
].
length
);
TEST_ASSERT_NOT_NULL
(
param
->
messages
[
i
].
val
);
FillRandom
(
param
->
messages
[
i
].
val
,
param
->
messages
[
i
].
length
,
param
->
messages
[
i
].
length
);
param
->
signatures
[
i
].
length
=
TEST_SIGN_SIGNATURE_LENGTH
;
param
->
signatures
[
i
].
val
=
(
uint8_t
*
)
malloc
(
param
->
signatures
[
i
].
length
);
TEST_ASSERT_NOT_NULL
(
param
->
signatures
[
i
].
val
);
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
param
->
signatures
[
i
].
val
,
param
->
signatures
[
i
].
length
,
0
,
param
->
signatures
[
i
].
length
));
}
param
->
anotherOutPk
.
length
=
TEST_EX_IM_SN_VF_OUT_PUB_KEY_LENGTH
;
param
->
anotherOutPk
.
val
=
(
uint8_t
*
)
malloc
(
param
->
anotherOutPk
.
length
);
TEST_ASSERT_NOT_NULL
(
param
->
anotherOutPk
.
val
);
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
param
->
anotherOutPk
.
val
,
param
->
anotherOutPk
.
length
,
0
,
param
->
anotherOutPk
.
length
));
}
static
void
TestExportImportSignVerifyInnerVerfiyNormalAndAbnormalCases
(
const
AlgLoader
*
loader
,
const
Algorithm
alg
,
struct
TestExportImportSignVerifyParam
*
param
)
{
int
res
;
for
(
uint32_t
i
=
0
;
i
<
ARRAY_SIZE
(
TEST_SIGN_MSG_LENGTHES
);
++
i
)
{
// test normal case
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
verify
(
&
param
->
anotherOutPk
,
&
param
->
messages
[
i
],
alg
,
&
param
->
signatures
[
i
],
false
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
// test tamper message
uint8_t
originMsg
=
param
->
messages
[
i
].
val
[
0
];
param
->
messages
[
i
].
val
[
0
]
=
((
originMsg
==
UINT8_MAX
)
?
0
:
(
originMsg
+
1
));
TEST_ASSERT_NOT_EQUAL
(
originMsg
,
param
->
messages
[
i
].
val
[
0
]);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
verify
(
&
param
->
anotherOutPk
,
&
param
->
messages
[
i
],
alg
,
&
param
->
signatures
[
i
],
false
));
TEST_ASSERT_NOT_EQUAL
(
HAL_SUCCESS
,
res
);
param
->
messages
[
i
].
val
[
0
]
=
originMsg
;
// test normal case
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
verify
(
&
param
->
anotherOutPk
,
&
param
->
messages
[
i
],
alg
,
&
param
->
signatures
[
i
],
false
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
// test tamper signature
uint8_t
originSig
=
param
->
signatures
[
i
].
val
[
0
];
param
->
signatures
[
i
].
val
[
0
]
=
((
originSig
==
UINT8_MAX
)
?
0
:
(
originSig
+
1
));
TEST_ASSERT_NOT_EQUAL
(
originSig
,
param
->
signatures
[
i
].
val
[
0
]);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
verify
(
&
param
->
anotherOutPk
,
&
param
->
messages
[
i
],
alg
,
&
param
->
signatures
[
i
],
false
));
TEST_ASSERT_NOT_EQUAL
(
HAL_SUCCESS
,
res
);
param
->
signatures
[
i
].
val
[
0
]
=
originSig
;
// test normal case
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
verify
(
&
param
->
anotherOutPk
,
&
param
->
messages
[
i
],
alg
,
&
param
->
signatures
[
i
],
false
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
}
}
static
void
TestExportImportSignVerifyInner
(
const
AlgLoader
*
loader
,
const
Algorithm
alg
,
struct
TestExportImportSignVerifyParam
*
param
)
{
int
res
;
// 1. generate one public private key pair
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
generateKeyPairWithStorage
(
&
param
->
keyAlias
,
TEST_EX_IM_SN_VF_KEY_LENGTH
,
alg
,
&
param
->
extInfo
));
// 2. export the public key which is generated in the first step
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
exportPublicKey
(
&
param
->
keyAlias
,
&
param
->
outPubKey
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
// 3. import the public key which is exported in the second step with a different name
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
importPublicKey
(
&
param
->
anotherKeyAlias
,
&
param
->
outPubKey
,
alg
,
&
param
->
extInfo
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
// 4. sign with the public key which is generated in the first step
for
(
uint32_t
i
=
0
;
i
<
ARRAY_SIZE
(
TEST_SIGN_MSG_LENGTHES
);
++
i
)
{
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
sign
(
&
param
->
keyAlias
,
&
param
->
messages
[
i
],
alg
,
&
param
->
signatures
[
i
],
true
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
TEST_ASSERT_GREATER_THAN
(
0u
,
param
->
signatures
[
i
].
length
);
TEST_ASSERT_LESS_OR_EQUAL
(
TEST_SIGN_SIGNATURE_LENGTH
,
param
->
signatures
[
i
].
length
);
TEST_ASSERT_NOT_EQUAL
(
param
->
signatures
[
i
].
length
,
CountZero
(
param
->
signatures
[
i
].
val
,
param
->
signatures
[
i
].
length
));
}
// 5. export the public key which is imported in the third step
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
exportPublicKey
(
&
param
->
anotherKeyAlias
,
&
param
->
anotherOutPk
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
res
);
// 6. verify the signature that is signed in the fourth step with the public key that is imported in the fifth step
TestExportImportSignVerifyInnerVerfiyNormalAndAbnormalCases
(
loader
,
alg
,
param
);
// 7. compare the public keys which are exported in the second and fifth step
PrintBuffer
(
"exported public key"
,
param
->
outPubKey
.
val
,
param
->
outPubKey
.
length
);
TEST_ASSERT_GREATER_THAN
(
0u
,
param
->
outPubKey
.
length
);
TEST_ASSERT_LESS_OR_EQUAL
(
TEST_EX_IM_SN_VF_OUT_PUB_KEY_LENGTH
,
param
->
outPubKey
.
length
);
TEST_ASSERT_NOT_EQUAL
(
param
->
outPubKey
.
length
,
CountZero
(
param
->
outPubKey
.
val
,
param
->
outPubKey
.
length
));
TEST_ASSERT_EQUAL_MESSAGE
(
param
->
outPubKey
.
length
,
param
->
anotherOutPk
.
length
,
TEST_EXPORT_DIFFERENT_ERROR_MESSAGE
);
TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE
(
param
->
outPubKey
.
val
,
param
->
anotherOutPk
.
val
,
param
->
outPubKey
.
length
,
TEST_EXPORT_DIFFERENT_ERROR_MESSAGE
);
if
(
loader
->
deleteKey
)
{
LOGD
(
"test deleteKey"
);
// 8. delete the key pair which is generated in the first step
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
param
->
keyAlias
));
// 9. delete the public key which is imported in the third step
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
loader
->
deleteKey
(
&
param
->
anotherKeyAlias
));
}
}
static
void
TestExportImportSignVerifyReleaseResources
(
struct
TestExportImportSignVerifyParam
*
param
)
{
free
(
param
->
extInfo
.
authId
.
val
);
param
->
extInfo
.
authId
.
val
=
NULL
;
free
(
param
->
keyAlias
.
val
);
param
->
keyAlias
.
val
=
NULL
;
free
(
param
->
outPubKey
.
val
);
param
->
outPubKey
.
val
=
NULL
;
free
(
param
->
anotherKeyAlias
.
val
);
param
->
anotherKeyAlias
.
val
=
NULL
;
for
(
uint32_t
i
=
0
;
i
<
ARRAY_SIZE
(
TEST_SIGN_MSG_LENGTHES
);
++
i
)
{
free
(
param
->
messages
[
i
].
val
);
param
->
messages
[
i
].
val
=
NULL
;
free
(
param
->
signatures
[
i
].
val
);
param
->
signatures
[
i
].
val
=
NULL
;
}
free
(
param
->
anotherOutPk
.
val
);
param
->
anotherOutPk
.
val
=
NULL
;
}
static
void
TestExportImportSignVerify
(
const
AlgLoader
*
loader
,
const
Algorithm
alg
)
{
TEST_ASSERT_NOT_NULL
(
loader
->
generateKeyPairWithStorage
);
// only two test cases for exportPublicKey, P256 and ED25519, outKey length is 32
TEST_ASSERT_NOT_NULL
(
loader
->
exportPublicKey
);
TEST_ASSERT_NOT_NULL
(
loader
->
importPublicKey
);
// sign message length varies from min 1 to max 1024
TEST_ASSERT_NOT_NULL
(
loader
->
sign
);
TEST_ASSERT_NOT_NULL
(
loader
->
verify
);
TEST_ASSERT_TRUE
((
alg
==
ED25519
)
||
(
alg
==
P256
));
if
(((
alg
!=
ED25519
)
&&
(
alg
!=
P256
))
||
!
loader
->
generateKeyPairWithStorage
||
!
loader
->
exportPublicKey
||
!
loader
->
importPublicKey
||
!
loader
->
sign
||
!
loader
->
verify
)
{
LOGE
(
"one of requested pointer is NULL or alg is invalid, can not test!"
);
return
;
}
struct
TestExportImportSignVerifyParam
param
;
TestExportImportSignVerifyPrepareResources
(
&
param
);
TestExportImportSignVerifyInner
(
loader
,
alg
,
&
param
);
TestExportImportSignVerifyReleaseResources
(
&
param
);
}
static
void
TestExportImportSignVerifyP256AndEd25519
(
const
AlgLoader
*
loader
)
{
#if TEST_EXPORT_IMPORT_SIGN_VERIFY_ED25519
LOGI
(
"test export import sign verify ED25519"
);
TestExportImportSignVerify
(
loader
,
ED25519
);
#else // TEST_EXPORT_IMPORT_SIGN_VERIFY_ED25519
LOGE
(
"no TEST_EXPORT_IMPORT_SIGN_VERIFY_ED25519, do not test ED25519"
);
#endif // TEST_EXPORT_IMPORT_SIGN_VERIFY_ED25519
#if TEST_EXPORT_IMPORT_SIGN_VERIFY_P256
LOGI
(
"test export import sign verify P256"
);
TestExportImportSignVerify
(
loader
,
P256
);
#else // TEST_EXPORT_IMPORT_SIGN_VERIFY_P256
LOGE
(
"no TEST_EXPORT_IMPORT_SIGN_VERIFY_P256, do not test P256"
);
#endif // TEST_EXPORT_IMPORT_SIGN_VERIFY_P256
}
#endif // (TEST_EXPORT_PUBLIC_KEY || TEST_IMPORT_PUBLIC_KEY || TEST_ALGORITHM_SIGN || TEST_ALGORITHM_VERIFY)
static
void
TestExportPublicKey
(
const
AlgLoader
*
loader
)
#if TEST_EXPORT_PUBLIC_KEY
{
TEST_ASSERT_NOT_NULL
(
loader
->
exportPublicKey
);
if
(
!
loader
->
exportPublicKey
)
{
LOGE
(
"exportPublicKey pointer is NULL, can not test!"
);
return
;
}
TestExportImportSignVerifyP256AndEd25519
(
loader
);
}
#else // TEST_EXPORT_PUBLIC_KEY
{
TEST_ASSERT_NULL
(
loader
->
exportPublicKey
);
LOGE
(
"no TEST_EXPORT_PUBLIC_KEY, do not test exportPublicKey"
);
}
#endif // TEST_EXPORT_PUBLIC_KEY
static
void
TestSign
(
const
AlgLoader
*
loader
)
#if TEST_ALGORITHM_SIGN
{
TEST_ASSERT_NOT_NULL
(
loader
->
sign
);
if
(
!
loader
->
sign
)
{
LOGE
(
"sign pointer is NULL, can not test!"
);
return
;
}
TestExportImportSignVerifyP256AndEd25519
(
loader
);
}
#else // TEST_ALGORITHM_SIGN
{
TEST_ASSERT_NULL
(
loader
->
sign
);
LOGE
(
"no TEST_ALGORITHM_SIGN, do not test sign"
);
}
#endif // TEST_ALGORITHM_SIGN
static
void
TestVerify
(
const
AlgLoader
*
loader
)
#if TEST_ALGORITHM_VERIFY
{
TEST_ASSERT_NOT_NULL
(
loader
->
verify
);
if
(
!
loader
->
verify
)
{
LOGE
(
"verify pointer is NULL, can not test!"
);
return
;
}
TestExportImportSignVerifyP256AndEd25519
(
loader
);
}
#else // TEST_ALGORITHM_VERIFY
{
TEST_ASSERT_NULL
(
loader
->
verify
);
LOGE
(
"no TEST_ALGORITHM_VERIFY, do not test verify"
);
}
#endif // TEST_ALGORITHM_VERIFY
static
void
TestImportPublicKey
(
const
AlgLoader
*
loader
)
#if TEST_IMPORT_PUBLIC_KEY
{
TEST_ASSERT_NOT_NULL
(
loader
->
importPublicKey
);
if
(
!
loader
->
importPublicKey
)
{
LOGE
(
"importPublicKey pointer is NULL, can not test!"
);
return
;
}
TestExportImportSignVerifyP256AndEd25519
(
loader
);
}
#else // TEST_IMPORT_PUBLIC_KEY
{
TEST_ASSERT_NULL
(
loader
->
importPublicKey
);
LOGE
(
"no TEST_IMPORT_PUBLIC_KEY, do not test importPublicKey"
);
}
#endif // TEST_IMPORT_PUBLIC_KEY
#if TEST_CHECK_DL_PUBLIC_KEY // {
static
void
TestCheckDlPublicKeyInner
(
const
AlgLoader
*
loader
,
Uint8Buff
*
key
,
const
char
*
primeHex
)
{
bool
res
;
int
randIndex
;
// 1. all zero
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
false
,
res
);
// 2. value is 1
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
key
->
val
[
key
->
length
-
1
]
=
TEST_CHECK_DL_VALUE_ONE
;
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
false
,
res
);
// 3. value is 2
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
key
->
val
[
key
->
length
-
1
]
=
TEST_CHECK_DL_VALUE_TWO
;
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
true
,
res
);
// 4. value is between 2 and primeHex - 2
// first, init value with 2
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
key
->
val
[
key
->
length
-
1
]
=
TEST_CHECK_DL_VALUE_TWO
;
// then add 1 on rand byte
randIndex
=
rand
()
%
key
->
length
;
key
->
val
[
randIndex
]
+=
TEST_CHECK_DL_VALUE_ONE
;
PrintBuffer
(
"rand key"
,
key
->
val
,
key
->
length
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
true
,
res
);
// first, init value with primeHex - 2
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
HexStringToByte
(
primeHex
,
key
->
val
,
key
->
length
));
TEST_ASSERT_GREATER_OR_EQUAL
(
TEST_CHECK_DL_VALUE_TWO
,
key
->
val
[
key
->
length
-
1
]);
key
->
val
[
key
->
length
-
1
]
-=
TEST_CHECK_DL_VALUE_TWO
;
// then sub 1 on rand byte
do
{
randIndex
=
rand
()
%
key
->
length
;
}
while
(
key
->
val
[
randIndex
]
<
TEST_CHECK_DL_VALUE_ONE
);
key
->
val
[
randIndex
]
-=
TEST_CHECK_DL_VALUE_ONE
;
PrintBuffer
(
"rand key"
,
key
->
val
,
key
->
length
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
true
,
res
);
// 5. value is primeHex - 2
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
HexStringToByte
(
primeHex
,
key
->
val
,
key
->
length
));
TEST_ASSERT_GREATER_OR_EQUAL
(
TEST_CHECK_DL_VALUE_TWO
,
key
->
val
[
key
->
length
-
1
]);
key
->
val
[
key
->
length
-
1
]
-=
TEST_CHECK_DL_VALUE_TWO
;
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
true
,
res
);
// 6. value is primeHex - 1
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
HexStringToByte
(
primeHex
,
key
->
val
,
key
->
length
));
TEST_ASSERT_GREATER_OR_EQUAL
(
TEST_CHECK_DL_VALUE_ONE
,
key
->
val
[
key
->
length
-
1
]);
key
->
val
[
key
->
length
-
1
]
-=
TEST_CHECK_DL_VALUE_ONE
;
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
false
,
res
);
// 7. value is primeHex
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
key
->
val
,
key
->
length
,
0
,
key
->
length
));
TEST_ASSERT_EQUAL
(
HAL_SUCCESS
,
HexStringToByte
(
primeHex
,
key
->
val
,
key
->
length
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
checkDlPublicKey
(
key
,
primeHex
));
TEST_ASSERT_EQUAL
(
false
,
res
);
}
static
void
TestCheckDlPublicKey
(
const
AlgLoader
*
loader
)
{
TEST_ASSERT_NOT_NULL
(
loader
->
checkDlPublicKey
);
if
(
!
loader
->
checkDlPublicKey
)
{
LOGE
(
"checkDlPublicKey pointer is NULL, can not test!"
);
return
;
}
Uint8Buff
key
;
key
.
length
=
PAKE_DL_PRIME_LEN_256
;
key
.
val
=
(
uint8_t
*
)
malloc
(
key
.
length
);
TEST_ASSERT_NOT_NULL
(
key
.
val
);
TestCheckDlPublicKeyInner
(
loader
,
&
key
,
LARGE_PRIME_NUM_HEX_256
);
free
(
key
.
val
);
key
.
length
=
PAKE_DL_PRIME_LEN_384
;
key
.
val
=
(
uint8_t
*
)
malloc
(
key
.
length
);
TEST_ASSERT_NOT_NULL
(
key
.
val
);
TestCheckDlPublicKeyInner
(
loader
,
&
key
,
LARGE_PRIME_NUM_HEX_384
);
free
(
key
.
val
);
}
#else // TEST_CHECK_DL_PUBLIC_KEY // } {
static
void
TestCheckDlPublicKey
(
const
AlgLoader
*
loader
)
{
TEST_ASSERT_NULL
(
loader
->
checkDlPublicKey
);
LOGE
(
"no TEST_CHECK_DL_PUBLIC_KEY, do not test checkDlPublicKey"
);
}
#endif // TEST_CHECK_DL_PUBLIC_KEY // }
static
void
TestCheckEcPublicKey
(
const
AlgLoader
*
loader
)
{
TEST_ASSERT_NULL
(
loader
->
checkEcPublicKey
);
LOGE
(
"loader->checkEcPublicKey is NULL, and nobody use it, do not test!"
);
}
#if TEST_BIG_NUM_COMPARE // {
static
void
TestBigNumCompareInnerMinMax
(
const
AlgLoader
*
loader
,
Uint8Buff
*
x
,
Uint8Buff
*
y
)
{
// 0. 0xFFFFFF > 0x000000
int
res
;
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
x
->
val
,
x
->
length
,
UINT8_MAX
,
x
->
length
));
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
y
->
val
,
y
->
length
,
0
,
y
->
length
));
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
1
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
-
1
,
res
);
}
static
void
TestBigNumCompareInnerFull
(
const
AlgLoader
*
loader
,
Uint8Buff
*
x
,
Uint8Buff
*
y
)
{
int
previous
,
res
;
// 1. 0x123456 > 0x123455
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
,
x
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
);
previous
=
y
->
val
[
y
->
length
-
1
];
y
->
val
[
y
->
length
-
1
]
-=
1
;
TEST_ASSERT_LESS_THAN
(
previous
,
y
->
val
[
y
->
length
-
1
]);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
1
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
-
1
,
res
);
// 2. 0x123456 = 0x123456
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
,
x
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
0
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
0
,
res
);
// 3. 0x123456 < 0x123457
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
,
x
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
);
previous
=
y
->
val
[
y
->
length
-
1
];
y
->
val
[
y
->
length
-
1
]
+=
1
;
TEST_ASSERT_GREATER_THAN
(
previous
,
y
->
val
[
y
->
length
-
1
]);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
-
1
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
1
,
res
);
}
static
void
TestBigNumCompareInnerHalf
(
const
AlgLoader
*
loader
,
Uint8Buff
*
x
,
Uint8Buff
*
y
)
{
int
previous
,
res
;
// 4. 0x003456 > 0x3455
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
x
->
val
,
x
->
length
,
0
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
x
->
length
-
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
);
previous
=
y
->
val
[
y
->
length
-
1
];
y
->
val
[
y
->
length
-
1
]
-=
1
;
TEST_ASSERT_LESS_THAN
(
previous
,
y
->
val
[
y
->
length
-
1
]);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
1
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
-
1
,
res
);
// 5. 0x003456 = 0x3456
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
x
->
val
,
x
->
length
,
0
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
x
->
length
-
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
0
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
0
,
res
);
// 6. 0x003456 < 0x3457
TEST_ASSERT_EQUAL
(
EOK
,
memset_s
(
x
->
val
,
x
->
length
,
0
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
x
->
length
-
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
);
previous
=
y
->
val
[
y
->
length
-
1
];
y
->
val
[
y
->
length
-
1
]
+=
1
;
TEST_ASSERT_GREATER_THAN
(
previous
,
y
->
val
[
y
->
length
-
1
]);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
-
1
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
1
,
res
);
}
static
void
TestBigNumCompareInnerCompareFullAgainstHalf
(
const
AlgLoader
*
loader
,
Uint8Buff
*
x
,
Uint8Buff
*
y
)
{
int
res
;
// 7. 0x123456 > 0x3456
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
,
x
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
x
->
length
-
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL
(
EOK
,
memcpy_s
(
y
->
val
,
y
->
length
,
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
,
sizeof
(
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
)));
TEST_ASSERT_EQUAL_HEX8_ARRAY
(
x
->
val
+
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
,
y
->
val
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
x
,
y
));
TEST_ASSERT_EQUAL
(
1
,
res
);
RUN_AND_PRINT_ELAPSED_TIME
(
res
,
loader
->
bigNumCompare
(
y
,
x
));
TEST_ASSERT_EQUAL
(
-
1
,
res
);
}
static
void
TestBigNumCompare
(
const
AlgLoader
*
loader
)
{
TEST_ASSERT_NOT_NULL
(
loader
->
bigNumCompare
);
if
(
!
loader
->
bigNumCompare
)
{
LOGE
(
"bigNumCompare pointer is NULL, can not test!"
);
return
;
}
Uint8Buff
x
=
{
(
uint8_t
*
)
malloc
(
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
),
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
};
TEST_ASSERT_NOT_NULL
(
x
.
val
);
Uint8Buff
y
=
{
(
uint8_t
*
)
malloc
(
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
),
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
};
TEST_ASSERT_NOT_NULL
(
y
.
val
);
TestBigNumCompareInnerMinMax
(
loader
,
&
x
,
&
y
);
TestBigNumCompareInnerFull
(
loader
,
&
x
,
&
y
);
free
(
y
.
val
);
y
.
length
=
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
;
y
.
val
=
(
uint8_t
*
)
malloc
(
y
.
length
);
TEST_ASSERT_NOT_NULL
(
y
.
val
);
TestBigNumCompareInnerHalf
(
loader
,
&
x
,
&
y
);
TestBigNumCompareInnerCompareFullAgainstHalf
(
loader
,
&
x
,
&
y
);
free
(
x
.
val
);
free
(
y
.
val
);
}
#else // TEST_BIG_NUM_COMPARE // } {
static
void
TestBigNumCompare
(
const
AlgLoader
*
loader
)
{
TEST_ASSERT_NULL
(
loader
->
bigNumCompare
);
LOGE
(
"no TEST_BIG_NUM_COMPARE, do not test loader->bigNumCompare"
);
}
#endif // TEST_BIG_NUM_COMPARE // {
void
TestHcAlg
(
void
)
void
TestHcAlg
(
void
)
{
{
const
AlgLoader
*
loader
=
GetLoaderInstance
();
const
AlgLoader
*
loader
=
GetLoaderInstance
();
...
@@ -993,7 +1611,11 @@ void TestHcAlg(void)
...
@@ -993,7 +1611,11 @@ void TestHcAlg(void)
TestComputeHkdf
(
loader
);
TestComputeHkdf
(
loader
);
TestImportAsymmetricKey
(
loader
);
#if (defined(DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY) && DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY)
(
void
)(
TestImportSymmetricKey
);
#else // DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY
TestImportSymmetricKey
(
loader
);
#endif // DO_NOT_TEST_DEPRECATED_IMPORT_SYMMETRIC_KEY
TestCheckKeyExist
(
loader
);
TestCheckKeyExist
(
loader
);
...
@@ -1012,6 +1634,22 @@ void TestHcAlg(void)
...
@@ -1012,6 +1634,22 @@ void TestHcAlg(void)
TestAgreeSharedSecret
(
loader
);
TestAgreeSharedSecret
(
loader
);
TestBigNumExpMod
(
loader
);
TestBigNumExpMod
(
loader
);
TestGenerateKeyPair
(
loader
);
TestExportPublicKey
(
loader
);
TestSign
(
loader
);
TestVerify
(
loader
);
TestImportPublicKey
(
loader
);
TestCheckDlPublicKey
(
loader
);
TestCheckEcPublicKey
(
loader
);
TestBigNumCompare
(
loader
);
}
}
#ifdef __cplusplus
#ifdef __cplusplus
...
...
security_lite/deviceauth_basic_deps/hc_alg_test_case.h
浏览文件 @
0d4e2b02
...
@@ -372,9 +372,9 @@ enum {
...
@@ -372,9 +372,9 @@ enum {
HKDF_PAKE_SHAREDSECRET_DERIVE_UNIONKEY_SALT_LEN
=
16
,
HKDF_PAKE_SHAREDSECRET_DERIVE_UNIONKEY_SALT_LEN
=
16
,
HKDF_PAKE_SHAREDSECRET_DERIVE_UNIONKEY_OUTKEY_LEN
=
48
,
HKDF_PAKE_SHAREDSECRET_DERIVE_UNIONKEY_OUTKEY_LEN
=
48
,
IMPORT_
A
SYMMETRIC_KEY_KEYALIAS_LEN_MAX
=
32
,
IMPORT_SYMMETRIC_KEY_KEYALIAS_LEN_MAX
=
32
,
IMPORT_
A
SYMMETRIC_KEY_KEYALIAS_LEN_MIN
=
1
,
IMPORT_SYMMETRIC_KEY_KEYALIAS_LEN_MIN
=
1
,
IMPORT_
A
SYMMETRIC_KEY_AUTHTOKEN_LEN
=
32
,
IMPORT_SYMMETRIC_KEY_AUTHTOKEN_LEN
=
32
,
};
};
enum
{
enum
{
...
@@ -623,14 +623,103 @@ enum {
...
@@ -623,14 +623,103 @@ enum {
};
};
enum
{
enum
{
TEST_IMPORT_
A
SYMMETRIC_KEY_AUTH_ID_LENGTH_32
=
32
,
TEST_IMPORT_SYMMETRIC_KEY_AUTH_ID_LENGTH_32
=
32
,
TEST_IMPORT_
A
SYMMETRIC_KEY_AUTH_ID_LENGTH_64
=
64
,
TEST_IMPORT_SYMMETRIC_KEY_AUTH_ID_LENGTH_64
=
64
,
};
};
enum
{
enum
{
TEST_GENERATE_KEY_PAIR_WITH_STORAGE_AUTH_ID_LENGTH
=
32
,
TEST_GENERATE_KEY_PAIR_WITH_STORAGE_AUTH_ID_LENGTH
=
32
,
};
};
// TestExportImportSignVerify
enum
{
TEST_EX_IM_SN_VF_EXTRA_INFO_AUTH_ID_LENGTH
=
32
,
TEST_EX_IM_SN_VF_KEY_ALIAS_LENGTH
=
64
,
TEST_EX_IM_SN_VF_KEY_LENGTH
=
32
,
TEST_EX_IM_SN_VF_OUT_PUB_KEY_LENGTH
=
32
,
TEST_SIGN_MESSAGE_LENGTH_1
=
1
,
TEST_SIGN_MESSAGE_LENGTH_2
=
2
,
TEST_SIGN_MESSAGE_LENGTH_4
=
4
,
TEST_SIGN_MESSAGE_LENGTH_8
=
8
,
TEST_SIGN_MESSAGE_LENGTH_16
=
16
,
TEST_SIGN_MESSAGE_LENGTH_32
=
32
,
TEST_SIGN_MESSAGE_LENGTH_64
=
64
,
TEST_SIGN_MESSAGE_LENGTH_128
=
128
,
TEST_SIGN_MESSAGE_LENGTH_256
=
256
,
TEST_SIGN_MESSAGE_LENGTH_512
=
512
,
TEST_SIGN_MESSAGE_LENGTH_1024
=
1024
,
TEST_SIGN_SIGNATURE_LENGTH
=
64
,
};
static
const
uint32_t
TEST_SIGN_MSG_LENGTHES
[]
=
{
TEST_SIGN_MESSAGE_LENGTH_1
,
TEST_SIGN_MESSAGE_LENGTH_2
,
TEST_SIGN_MESSAGE_LENGTH_4
,
TEST_SIGN_MESSAGE_LENGTH_8
,
TEST_SIGN_MESSAGE_LENGTH_16
,
TEST_SIGN_MESSAGE_LENGTH_32
,
TEST_SIGN_MESSAGE_LENGTH_64
,
TEST_SIGN_MESSAGE_LENGTH_128
,
TEST_SIGN_MESSAGE_LENGTH_256
,
TEST_SIGN_MESSAGE_LENGTH_512
,
TEST_SIGN_MESSAGE_LENGTH_1024
,
};
static
const
char
TEST_EXPORT_DIFFERENT_ERROR_MESSAGE
[]
=
"two different public keys are exported"
;
// g_largePrimeNumberHex384 and g_largePrimeNumberHex256 are from
// base/security/deviceauth/services/protocol/src/pake_protocol/pake_protocol_dl_common/pake_protocol_dl_common.c
static
const
char
LARGE_PRIME_NUM_HEX_384
[]
=
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74"
"020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437"
"4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05"
"98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB"
"9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718"
"3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33"
"A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864"
"D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E2"
"08E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF"
;
static
const
char
LARGE_PRIME_NUM_HEX_256
[]
=
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74"
"020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437"
"4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF05"
"98DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB"
"9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718"
"3995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF"
;
enum
{
PAKE_DL_PRIME_LEN_256
=
256
,
PAKE_DL_PRIME_LEN_384
=
384
,
};
enum
{
TEST_CHECK_DL_VALUE_ONE
=
1
,
TEST_CHECK_DL_VALUE_TWO
=
2
,
};
enum
{
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
=
32
,
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
=
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
/
2
,
// 16
};
static
const
uint8_t
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_FULL
[
TEST_BIG_NUM_COMPARE_NUM_LENGTH_FULL
]
=
{
/* */
/* */
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
};
static
const
uint8_t
TEST_BIG_NUM_COMPARE_NUM_EXAMPLE_HALF
[
TEST_BIG_NUM_COMPARE_NUM_LENGTH_HALF
]
=
{
/* */
/* */
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
0xab
,
0xcd
,
0xef
,
0x01
,
0x23
,
0x45
,
0x67
,
0x89
,
};
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录