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 #ifndef HKS_TEST_AES_C_H 17 #define HKS_TEST_AES_C_H 18 19 #include "hks_test_aes.h" 20 #include "hks_api.h" 21 #include "hks_param.h" 22 #include "hks_test_common.h" 23 #include "hks_test_log.h" 24 25 #define TEST_PLAIN_TEST "This is a plain text! Hello world and thanks for watching AES^^" 26 #define TEST_AES_12 12 27 #define TEST_AES_16 16 28 #define TEST_AES_128 128 29 #define TEST_AES_256 256 30 31 static uint8_t g_buffer[TEST_AES_256]; 32 static uint32_t g_bufferSize = TEST_AES_256; 33 34 static uint8_t g_nonce[TEST_AES_12] = "hahahahahah"; 35 static uint8_t g_aad[TEST_AES_16] = "bababababababab"; 36 static uint8_t g_iv[TEST_AES_16] = "aabaabaabaabaab"; 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 int32_t ConstructParamSetEncryptDecryptAesPre(uint32_t mode, uint32_t padding, bool isEncrypt, 42 struct HksParamSet **paramSet); 43 44 int32_t ConstructParamSetEncryptDecryptAesPost(uint32_t mode, struct HksParamSet **paramSet); 45 46 int32_t ConstructParamSetEncryptDecryptAes(uint32_t mode, uint32_t padding, bool isEncrypt, 47 struct HksParamSet **paramSet); 48 49 void GenerateBaseKey(const struct HksBlob *alias); 50 51 void PlainPubKey(const struct HksBlob *baseKey, const struct HksBlob *peerPubKey, 52 struct HksParamSet *paramSet); 53 54 void SetKeyAliasTrue(const struct HksBlob *baseKey, const struct HksBlob *peerPubKey, 55 struct HksParamSet *paramSet); 56 57 void SetKeyAliasWrong(const struct HksBlob *baseKey, const struct HksBlob *peerPubKey, 58 struct HksParamSet *paramSet); 59 60 void GenerateAesAgreeKey(const struct HksBlob *alias, const struct HksBlob *baseKey, 61 const struct HksBlob *peerPubKey, bool isPlainPubKey, bool isSetKeyAliasTrue); 62 63 void ExportPubKey(const struct HksBlob *alias, struct HksBlob *pubKey); 64 65 void ImportPubKey(const struct HksBlob *alias, const struct HksBlob *pubKey); 66 67 int32_t TestAes256ByAgree(); 68 69 int32_t TestAes256ByAgree1(); 70 71 int32_t TestAes256ByAgree2(); 72 #ifdef __cplusplus 73 } 74 #endif 75 #endif