• 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 } CipherSpecItem;
45 
46 typedef struct HcfCipher HcfCipher;
47 /**
48  * @brief this class provides cipher algorithms for cryptographic operations,
49  * mainly including encrypt and decrypt.
50  *
51  * @since 9
52  * @version 1.0
53  */
54 struct HcfCipher {
55     HcfObjectBase base;
56 
57     HcfResult (*init)(HcfCipher *self, enum HcfCryptoMode opMode,
58         HcfKey *key, HcfParamsSpec *params);
59 
60     HcfResult (*update)(HcfCipher *self, HcfBlob *input, HcfBlob *output);
61 
62     HcfResult (*doFinal)(HcfCipher *self, HcfBlob *input, HcfBlob *output);
63 
64     const char *(*getAlgorithm)(HcfCipher *self);
65 
66     HcfResult (*setCipherSpecUint8Array)(HcfCipher *self, CipherSpecItem item, HcfBlob pSource);
67 
68     HcfResult (*getCipherSpecString)(HcfCipher *self, CipherSpecItem item, char **returnString);
69 
70     HcfResult (*getCipherSpecUint8Array)(HcfCipher *self, CipherSpecItem item, HcfBlob *returnUint8Array);
71 };
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 /**
78  * @brief Generate a corresponding cryptographic operation cipher object according to the algorithm name.
79  *
80  * @param transformation Specifies the type of generated cipher object.
81  * @param returnObj The address of the pointer to the generated cipher object.
82  * @return Returns the status code of the execution.
83  * @since 9
84  * @version 1.0
85  */
86 HcfResult HcfCipherCreate(const char *transformation, HcfCipher **returnObj);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif
93