11b8d9b87Sopenharmony_ci/* 21b8d9b87Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 31b8d9b87Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41b8d9b87Sopenharmony_ci * you may not use this file except in compliance with the License. 51b8d9b87Sopenharmony_ci * You may obtain a copy of the License at 61b8d9b87Sopenharmony_ci * 71b8d9b87Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81b8d9b87Sopenharmony_ci * 91b8d9b87Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101b8d9b87Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111b8d9b87Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121b8d9b87Sopenharmony_ci * See the License for the specific language governing permissions and 131b8d9b87Sopenharmony_ci * limitations under the License. 141b8d9b87Sopenharmony_ci */ 151b8d9b87Sopenharmony_ci 161b8d9b87Sopenharmony_ci#ifndef AES_COMMON_H 171b8d9b87Sopenharmony_ci#define AES_COMMON_H 181b8d9b87Sopenharmony_ci 191b8d9b87Sopenharmony_ci#include "algorithm_parameter.h" 201b8d9b87Sopenharmony_ci#include "blob.h" 211b8d9b87Sopenharmony_ci#include "cipher.h" 221b8d9b87Sopenharmony_ci#include "sym_key.h" 231b8d9b87Sopenharmony_ci 241b8d9b87Sopenharmony_ci#ifdef __cplusplus 251b8d9b87Sopenharmony_ciextern "C" { 261b8d9b87Sopenharmony_ci#endif 271b8d9b87Sopenharmony_ci 281b8d9b87Sopenharmony_cistatic const int32_t FILE_BLOCK_SIZE = 1024; 291b8d9b87Sopenharmony_cistatic const int32_t RAND_MAX_NUM = 100; 301b8d9b87Sopenharmony_cistatic const bool IS_DEBUG = false; 311b8d9b87Sopenharmony_cistatic constexpr int32_t CIPHER_TEXT_LEN = 128; 321b8d9b87Sopenharmony_cistatic constexpr int32_t KEY_MATERIAL_LEN = 16; 331b8d9b87Sopenharmony_cistatic constexpr int32_t AES_IV_LEN = 16; // iv for CBC|CTR|OFB|CFB mode 341b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_IV_LEN = 12; // GCM 351b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_AAD_LEN = 8; 361b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_TAG_LEN = 16; 371b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_IV_LONG_LEN = 16; 381b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_IV_SHORT_LEN = 9; 391b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_AAD_LONG_LEN = 2049; 401b8d9b87Sopenharmony_cistatic constexpr int32_t GCM_AAD_SHORT_LEN = 1; 411b8d9b87Sopenharmony_cistatic constexpr int32_t CCM_IV_LEN = 7; // CCM 421b8d9b87Sopenharmony_cistatic constexpr int32_t CCM_AAD_LEN = 8; 431b8d9b87Sopenharmony_cistatic constexpr int32_t CCM_TAG_LEN = 12; 441b8d9b87Sopenharmony_cistatic constexpr int32_t PLAINTEXT_LEN = 13; 451b8d9b87Sopenharmony_cistatic constexpr int32_t AES_KEY_SIZE = 128; 461b8d9b87Sopenharmony_ci 471b8d9b87Sopenharmony_civoid PrintfHex(const char *tag, uint8_t *in, int inLen); 481b8d9b87Sopenharmony_ciint32_t GenerateSymKey(const char *algoName, HcfSymKey **key); 491b8d9b87Sopenharmony_ciint32_t ConvertSymKey(const char *algoName, HcfSymKey **key); 501b8d9b87Sopenharmony_ci 511b8d9b87Sopenharmony_ci/* just rand data fill file for test */ 521b8d9b87Sopenharmony_ciint32_t GeneratorFile(const char *fileName, int32_t genFileSize); 531b8d9b87Sopenharmony_ciint32_t CompareFileContent(void); 541b8d9b87Sopenharmony_ciint32_t AesMultiBlockEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params); 551b8d9b87Sopenharmony_ciint32_t AesMultiBlockDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params); 561b8d9b87Sopenharmony_ci 571b8d9b87Sopenharmony_ci// use ECB, test abnormal input 581b8d9b87Sopenharmony_ciint32_t AesEncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, 591b8d9b87Sopenharmony_ci uint8_t *cipherText, int *cipherTextLen); 601b8d9b87Sopenharmony_ciint32_t AesEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, 611b8d9b87Sopenharmony_ci uint8_t *cipherText, int *cipherTextLen); 621b8d9b87Sopenharmony_ciint32_t AesDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, 631b8d9b87Sopenharmony_ci uint8_t *cipherText, int cipherTextLen); 641b8d9b87Sopenharmony_ciint32_t AesNoUpdateEncWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input, 651b8d9b87Sopenharmony_ci uint8_t *cipherText, int *cipherTextLen); 661b8d9b87Sopenharmony_ci 671b8d9b87Sopenharmony_ci// test encrypt and decrypt with null plain text 681b8d9b87Sopenharmony_ciint32_t AesDecryptEmptyMsg(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, 691b8d9b87Sopenharmony_ci uint8_t *cipherText, int cipherTextLen); 701b8d9b87Sopenharmony_ciint32_t AesNoUpdateEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, 711b8d9b87Sopenharmony_ci uint8_t *cipherText, int *cipherTextLen); 721b8d9b87Sopenharmony_ciint32_t AesNoUpdateDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params, 731b8d9b87Sopenharmony_ci uint8_t *cipherText, int cipherTextLen); 741b8d9b87Sopenharmony_ci 751b8d9b87Sopenharmony_ci#ifdef __cplusplus 761b8d9b87Sopenharmony_ci} 771b8d9b87Sopenharmony_ci#endif 781b8d9b87Sopenharmony_ci#endif