1 /*
2  * Copyright (C) 2022 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 HCF_AES_OPENSSL_COMMON_H
17 #define HCF_AES_OPENSSL_COMMON_H
18 
19 #include <stdbool.h>
20 #include <openssl/evp.h>
21 #include "aes_openssl.h"
22 #include "detailed_iv_params.h"
23 #include "detailed_ccm_params.h"
24 #include "detailed_gcm_params.h"
25 
26 typedef struct {
27     EVP_CIPHER_CTX *ctx;
28     enum HcfCryptoMode enc;
29     /* EVP_CIPH_GCM_MODE, EVP_CIPH_CCM_MODE need AEAD */
30     bool aead;
31     uint32_t updateLen;
32     unsigned char *iv;
33     uint32_t ivLen;
34     /* GCM, CCM only */
35     unsigned char *aad;
36     uint32_t aadLen;
37     unsigned char *tag;
38     uint32_t tagLen;
39 } CipherData;
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 const unsigned char *GetIv(HcfParamsSpec *params);
45 
46 size_t GetIvLen(HcfParamsSpec *params);
47 
48 int32_t GetCcmTagLen(HcfParamsSpec *params);
49 
50 void *GetCcmTag(HcfParamsSpec *params);
51 
52 void FreeCipherData(CipherData **data);
53 
54 void FreeRedundantOutput(HcfBlob *blob);
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #endif
61