1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// automatically generated by rust-bindgen 0.71.1
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::asym_key::OH_CryptoKeyPair;
use crate::common::{CryptoResult, Crypto_CipherMode, Crypto_DataBlob};
/// Defines the asymmetric cipher structure.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
#[repr(C)]
pub struct OH_CryptoAsymCipher {
_unused: [u8; 0],
}
/// Defines the SM2 ciphertext spec structure.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
#[repr(C)]
pub struct OH_CryptoSm2CiphertextSpec {
_unused: [u8; 0],
}
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
impl CryptoSm2CiphertextSpec_item {
/// Public key x, also known as C1x.
pub const CRYPTO_SM2_CIPHERTEXT_C1_X: CryptoSm2CiphertextSpec_item =
CryptoSm2CiphertextSpec_item(0);
/// Public key y, also known as C1y.
pub const CRYPTO_SM2_CIPHERTEXT_C1_Y: CryptoSm2CiphertextSpec_item =
CryptoSm2CiphertextSpec_item(1);
/// Hash, also known as C2.
pub const CRYPTO_SM2_CIPHERTEXT_C2: CryptoSm2CiphertextSpec_item =
CryptoSm2CiphertextSpec_item(2);
/// Ciphertext data, also known as C3.
pub const CRYPTO_SM2_CIPHERTEXT_C3: CryptoSm2CiphertextSpec_item =
CryptoSm2CiphertextSpec_item(3);
}
#[repr(transparent)]
/// Defines the SM2 ciphertext spec item type.
///
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct CryptoSm2CiphertextSpec_item(pub ::core::ffi::c_uint);
extern "C" {
/// Creates an asymmetric cipher context according to the given algorithm name.
///
/// # Arguments
///
/// * `algoName` - Indicates the algorithm name used to generate the asymmetric cipher context. e.g. "RSA|PKCS1",
/// "RSA|PKCS1_OAEP|SHA384|MGF1_SHA384", "SM2|SM3".
///
/// * `ctx` - Indicates the pointer to the asymmetric cipher context.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoAsymCipher_Create(
algoName: *const ::core::ffi::c_char,
ctx: *mut *mut OH_CryptoAsymCipher,
) -> CryptoResult;
/// Initializes the asymmetric cipher context with the given crypto mode, key and parameters.
///
/// # Arguments
///
/// * `ctx` - Indicates the asymmetric cipher context.
///
/// * `mode` - Indicates the crypto mode is encryption or decryption.
///
/// * `key` - Indicates the asymmetric key.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
/// [`OH_CryptoAsymCipher_Final`]
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoAsymCipher_Init(
ctx: *mut OH_CryptoAsymCipher,
mode: Crypto_CipherMode,
key: *mut OH_CryptoKeyPair,
) -> CryptoResult;
/// Finalizes the encryption or decryption operation.
///
/// # Arguments
///
/// * `ctx` - Indicates the asymmetric cipher context.
///
/// * `in` - Indicates the input data to be encrypted or decrypted.
///
/// * `out` - Indicates the result of encryption or decryption.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
/// [`OH_CryptoAsymCipher_Init`]
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoAsymCipher_Final(
ctx: *mut OH_CryptoAsymCipher,
in_: *const Crypto_DataBlob,
out: *mut Crypto_DataBlob,
) -> CryptoResult;
/// Destroys the asymmetric cipher context.
///
/// # Arguments
///
/// * `ctx` - Indicates the asymmetric cipher context.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoAsymCipher_Destroy(ctx: *mut OH_CryptoAsymCipher);
/// Creates a SM2 ciphertext spec.
///
/// # Arguments
///
/// * `sm2Ciphertext` - Indicates the SM2 ciphertext in DER format, if sm2Ciphertext param is NULL,
/// an empty SM2 ciphertext spec will be created.
///
/// * `spec` - Indicates the output SM2 ciphertext spec.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoSm2CiphertextSpec_Create(
sm2Ciphertext: *mut Crypto_DataBlob,
spec: *mut *mut OH_CryptoSm2CiphertextSpec,
) -> CryptoResult;
/// Gets the specified item of the SM2 ciphertext.
///
/// # Arguments
///
/// * `spec` - Indicates the SM2 ciphertext spec.
///
/// * `item` - Indicates the SM2 ciphertext spec item.
///
/// * `out` - Indicates the output data.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoSm2CiphertextSpec_GetItem(
spec: *mut OH_CryptoSm2CiphertextSpec,
item: CryptoSm2CiphertextSpec_item,
out: *mut Crypto_DataBlob,
) -> CryptoResult;
/// Sets the specified item to the SM2 ciphertext spec.
///
/// # Arguments
///
/// * `spec` - Indicates the SM2 ciphertext spec.
///
/// * `item` - Indicates the SM2 ciphertext spec item.
///
/// * `in` - Indicates the input data.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoSm2CiphertextSpec_SetItem(
spec: *mut OH_CryptoSm2CiphertextSpec,
item: CryptoSm2CiphertextSpec_item,
in_: *mut Crypto_DataBlob,
) -> CryptoResult;
/// Encodes the SM2 ciphertext spec to ciphertext in DER format.
///
/// # Arguments
///
/// * `spec` - Indicates the SM2 ciphertext spec.
///
/// * `out` - Indicates the output data.
///
/// # Returns
///
/// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
/// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
/// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
/// [`OH_Crypto_ErrCode#CRYPTO_PARAMETER_CHECK_FAILED`] 17620003 - If parameter check failed.
/// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto operation failed.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoSm2CiphertextSpec_Encode(
spec: *mut OH_CryptoSm2CiphertextSpec,
out: *mut Crypto_DataBlob,
) -> CryptoResult;
/// Destroys the SM2 ciphertext spec.
///
/// # Arguments
///
/// * `spec` - Indicates the SM2 ciphertext spec.
///
/// Available since API-level: 20
#[cfg(feature = "api-20")]
#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
pub fn OH_CryptoSm2CiphertextSpec_Destroy(spec: *mut OH_CryptoSm2CiphertextSpec);
}