• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hks_modify_key_test.h"
17 
18 #include "hks_api.h"
19 #include "hks_param.h"
20 #include "hks_test_api_performance.h"
21 #include "hks_test_cipher.h"
22 #include "hks_test_common.h"
23 #include "hks_test_file_operator.h"
24 #include "hks_test_log.h"
25 #include "hks_test_mem.h"
26 
27 #define G_TEST_CIPHER_PARAMS \
28 { 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE }, \
29     { \
30         true, /* genKey params */ \
31         true, HKS_ALG_AES, \
32         true, HKS_AES_KEY_SIZE_256, \
33         true, HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT, \
34         false, 0, \
35         true, HKS_PADDING_NONE, \
36         true, HKS_MODE_GCM, \
37         false, 0 \
38     }, \
39     { false, 0 }, \
40     { \
41         HKS_TEST_CIPHER_TYPE_AES,  true, /* encrypt params */ \
42         true, HKS_ALG_AES, \
43         true, HKS_KEY_PURPOSE_ENCRYPT, \
44         false, 0, \
45         true, HKS_PADDING_NONE, \
46         true, HKS_MODE_GCM, \
47         false, 0, \
48         true, AES_DEFAULT_GCM_NONCE_LENGTH, \
49         true, AES_DEFAULT_AAD_LEN \
50     }, \
51     { \
52         HKS_TEST_CIPHER_TYPE_AES,  true, /* decrypt params */ \
53         true, HKS_ALG_AES, \
54         true, HKS_KEY_PURPOSE_DECRYPT, \
55         false, 0, \
56         true, HKS_PADDING_NONE, \
57         true, HKS_MODE_GCM, \
58         false, 0, \
59         true, AES_DEFAULT_GCM_NONCE_LENGTH, \
60         true, AES_DEFAULT_AAD_LEN \
61     }, \
62     { true, DEFAULT_AES_CIPHER_PLAIN_SIZE, true, DEFAULT_AES_CIPHER_PLAIN_SIZE }, \
63     { true, DEFAULT_AES_CIPHER_PLAIN_SIZE + 16, true, DEFAULT_AES_CIPHER_PLAIN_SIZE + 16 }, \
64     { true, DEFAULT_AES_CIPHER_PLAIN_SIZE, true, DEFAULT_AES_CIPHER_PLAIN_SIZE }, \
65     { false, 0, false, 0 } \
66 },
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 int32_t ConstructDataToBlob(struct HksBlob **inData, struct HksBlob **outData,
72     const struct HksTestBlobParams *inTextParams, const struct HksTestBlobParams *outTextParams);
73 
74 int32_t Encrypt(struct CipherEncryptStructure *encryptStruct);
75 
76 int32_t DecryptCipher(struct CipherDecryptStructure *decryptStruct);
77 
78 int32_t GenerateKeyTwo(struct HksBlob *keyAlias, const struct HksTestBlobParams *keyAliasParams,
79     const struct HksTestGenKeyParamsParamSet *genKeyParamSetParams,
80     const struct HksTestGenKeyParamsParamSetOut *genKeyParamSetParamsOut);
81 #ifdef __cplusplus
82 }
83 #endif