• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-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 HCF_CIPHER_H
17 #define HCF_CIPHER_H
18 
19 #include "blob.h"
20 #include "key.h"
21 #include "algorithm_parameter.h"
22 
23 enum HcfCryptoMode {
24     /**
25      * The value of aes and 3des encrypt operation
26      * @syscap SystemCapability.Security.CryptoFramework
27      * @since 9
28      */
29     ENCRYPT_MODE = 0,
30 
31     /**
32      * The value of aes and 3des decrypt operation
33      * @syscap SystemCapability.Security.CryptoFramework
34      * @since 9
35      */
36     DECRYPT_MODE = 1,
37 };
38 
39 typedef enum {
40     OAEP_MD_NAME_STR = 100,
41     OAEP_MGF_NAME_STR = 101,
42     OAEP_MGF1_MD_STR = 102,
43     OAEP_MGF1_PSRC_UINT8ARR = 103,
44     SM2_MD_NAME_STR = 104
45 } CipherSpecItem;
46 
47 typedef struct HcfCipher HcfCipher;
48 /**
49  * @brief this class provides cipher algorithms for cryptographic operations,
50  * mainly including encrypt and decrypt.
51  *
52  * @since 9
53  * @version 1.0
54  */
55 struct HcfCipher {
56     HcfObjectBase base;
57 
58     HcfResult (*init)(HcfCipher *self, enum HcfCryptoMode opMode,
59         HcfKey *key, HcfParamsSpec *params);
60 
61     HcfResult (*update)(HcfCipher *self, HcfBlob *input, HcfBlob *output);
62 
63     HcfResult (*doFinal)(HcfCipher *self, HcfBlob *input, HcfBlob *output);
64 
65     const char *(*getAlgorithm)(HcfCipher *self);
66 
67     HcfResult (*setCipherSpecUint8Array)(HcfCipher *self, CipherSpecItem item, HcfBlob blob);
68 
69     HcfResult (*getCipherSpecString)(HcfCipher *self, CipherSpecItem item, char **returnString);
70 
71     HcfResult (*getCipherSpecUint8Array)(HcfCipher *self, CipherSpecItem item, HcfBlob *returnUint8Array);
72 };
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 /**
79  * @brief Generate a corresponding cryptographic operation cipher object according to the algorithm name.
80  *
81  * @param transformation Specifies the type of generated cipher object.
82  * @param returnObj The address of the pointer to the generated cipher object.
83  * @return Returns the status code of the execution.
84  * @since 9
85  * @version 1.0
86  */
87 HcfResult HcfCipherCreate(const char *transformation, HcfCipher **returnObj);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif
94