• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 struct HcfCipher HcfCipher;
40 /**
41  * @brief his class provides cipher algorithms for cryptographic operations,
42  * mainly including encrypt and decrypt.
43  *
44  * @since 9
45  * @version 1.0
46  */
47 struct HcfCipher {
48     HcfObjectBase base;
49 
50     HcfResult (*init)(HcfCipher *self, enum HcfCryptoMode opMode,
51         HcfKey *key, HcfParamsSpec *params);
52 
53     HcfResult (*update)(HcfCipher *self, HcfBlob *input, HcfBlob *output);
54 
55     HcfResult (*doFinal)(HcfCipher *self, HcfBlob *input, HcfBlob *output);
56 
57     const char *(*getAlgorithm)(HcfCipher *self);
58 };
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /**
65  * @brief Generate a corresponding cryptographic operation cipher object according to the algorithm name.
66  *
67  * @param transformation Specifies the type of generated cipher object.
68  * @param returnObj The address of the pointer to the generated cipher object.
69  * @return Returns the status code of the execution.
70  * @since 9
71  * @version 1.0
72  */
73 HcfResult HcfCipherCreate(const char *transformation, HcfCipher **returnObj);
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif
80