1 /*
2 * Copyright (c) 2020-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 #include "hks_mbedtls_engine.h"
17
18 #ifdef HKS_CONFIG_FILE
19 #include HKS_CONFIG_FILE
20 #else
21 #include "hks_config.h"
22 #endif
23
24 #include "hks_ability.h"
25 #include "hks_crypto_hal.h"
26 #include "hks_log.h"
27 #include "hks_template.h"
28
EncryptCheckParam(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,const struct HksBlob * message,struct HksBlob * cipherText)29 static int32_t EncryptCheckParam(const struct HksBlob *key, const struct HksUsageSpec *usageSpec,
30 const struct HksBlob *message, struct HksBlob *cipherText)
31 {
32 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(key), HKS_ERROR_INVALID_ARGUMENT, "Invalid param key!")
33 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(message), HKS_ERROR_INVALID_ARGUMENT, "Invalid param message!")
34 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(cipherText), HKS_ERROR_INVALID_ARGUMENT, "Invalid param cipherText!")
35
36 HKS_IF_NULL_LOGE_RETURN(usageSpec, HKS_ERROR_INVALID_ARGUMENT, "Invalid param usageSpec!")
37 return HKS_SUCCESS;
38 }
39
HksCryptoHalHmac(const struct HksBlob * key,uint32_t digestAlg,const struct HksBlob * msg,struct HksBlob * mac)40 int32_t HksCryptoHalHmac(const struct HksBlob *key, uint32_t digestAlg, const struct HksBlob *msg,
41 struct HksBlob *mac)
42 {
43 if (CheckBlob(key) != HKS_SUCCESS || CheckBlob(msg) != HKS_SUCCESS || CheckBlob(mac) != HKS_SUCCESS) {
44 HKS_LOG_E("Crypt Hal Hmac invalid param");
45 return HKS_ERROR_INVALID_ARGUMENT;
46 }
47 Hmac func = (Hmac)GetAbility(HKS_CRYPTO_ABILITY_HMAC);
48 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
49 return func(key, digestAlg, msg, mac);
50 }
51
HksCryptoHalHmacInit(const struct HksBlob * key,uint32_t digestAlg,void ** ctx)52 int32_t HksCryptoHalHmacInit(const struct HksBlob *key, uint32_t digestAlg, void **ctx)
53 {
54 if (CheckBlob(key) != HKS_SUCCESS || ctx == NULL) {
55 HKS_LOG_E("Crypt Hal Hmac init msg is NULL");
56 return HKS_ERROR_INVALID_ARGUMENT;
57 }
58
59 HmacInit func = (HmacInit)GetAbility(HKS_CRYPTO_ABILITY_HMAC_INIT);
60 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
61
62 return func(ctx, key, digestAlg);
63 }
64
HksCryptoHalHmacUpdate(const struct HksBlob * chunk,void * ctx)65 int32_t HksCryptoHalHmacUpdate(const struct HksBlob *chunk, void *ctx)
66 {
67 if (CheckBlob(chunk) != HKS_SUCCESS || ctx == NULL) {
68 HKS_LOG_E("Crypt Hal Hmac update chunk is invalid param");
69 return HKS_ERROR_INVALID_ARGUMENT;
70 }
71
72 HmacUpdate func = (HmacUpdate)GetAbility(HKS_CRYPTO_ABILITY_HMAC_UPDATE);
73 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
74
75 return func(ctx, chunk);
76 }
77
HksCryptoHalHmacFinal(const struct HksBlob * msg,void ** ctx,struct HksBlob * mac)78 int32_t HksCryptoHalHmacFinal(const struct HksBlob *msg, void **ctx, struct HksBlob *mac)
79 {
80 if (msg == NULL || ctx == NULL || *ctx == NULL || CheckBlob(mac) != HKS_SUCCESS) {
81 HKS_LOG_E("Crypt Hal Hmac final msg or mac is NULL");
82 return HKS_ERROR_INVALID_ARGUMENT;
83 }
84
85 HmacFinal func = (HmacFinal)GetAbility(HKS_CRYPTO_ABILITY_HMAC_FINAL);
86 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
87
88 return func(ctx, msg, mac);
89 }
90
HksCryptoHalHmacFreeCtx(void ** ctx)91 void HksCryptoHalHmacFreeCtx(void **ctx)
92 {
93 FreeCtx func = (FreeCtx)GetAbility(HKS_CRYPTO_ABILITY_HMAC_FREE_CTX);
94 if (func == NULL) {
95 HKS_LOG_E("CryptoHalHmacFreeCtx func is null");
96 return;
97 }
98
99 func(ctx);
100 }
101
102 #ifndef _CUT_AUTHENTICATE_
HksCryptoHalHash(uint32_t alg,const struct HksBlob * msg,struct HksBlob * hash)103 int32_t HksCryptoHalHash(uint32_t alg, const struct HksBlob *msg, struct HksBlob *hash)
104 {
105 Hash func = (Hash)GetAbility(HKS_CRYPTO_ABILITY_HASH);
106 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls Hash func is null!")
107 return func(alg, msg, hash);
108 }
109
HksCryptoHalHashInit(uint32_t alg,void ** ctx)110 int32_t HksCryptoHalHashInit(uint32_t alg, void **ctx)
111 {
112 HashInit func = (HashInit)GetAbility(HKS_CRYPTO_ABILITY_HASH_INIT);
113 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls Hash init func is null!")
114
115 return func(ctx, alg);
116 }
117
HksCryptoHalHashUpdate(const struct HksBlob * msg,void * ctx)118 int32_t HksCryptoHalHashUpdate(const struct HksBlob *msg, void *ctx)
119 {
120 if (CheckBlob(msg) != HKS_SUCCESS || ctx == NULL) {
121 HKS_LOG_E("Crypt Hal Hash msg or ctx is NULL");
122 return HKS_ERROR_INVALID_ARGUMENT;
123 }
124
125 HashUpdate func = (HashUpdate)GetAbility(HKS_CRYPTO_ABILITY_HASH_UPDATE);
126 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls Hash update func is null!")
127
128 return func(ctx, msg);
129 }
130
HksCryptoHalHashFinal(const struct HksBlob * msg,void ** ctx,struct HksBlob * hash)131 int32_t HksCryptoHalHashFinal(const struct HksBlob *msg, void **ctx, struct HksBlob *hash)
132 {
133 if (msg == NULL || CheckBlob(hash) != HKS_SUCCESS || ctx == NULL || *ctx == NULL) {
134 HKS_LOG_E("Crypt Hal Hash final msg or hash or ctx is NULL");
135 return HKS_ERROR_INVALID_ARGUMENT;
136 }
137
138 HashFinal func = (HashFinal)GetAbility(HKS_CRYPTO_ABILITY_HASH_FINAL);
139 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls Hash final func is null!")
140
141 return func(ctx, msg, hash);
142 }
143
HksCryptoHalHashFreeCtx(void ** ctx)144 void HksCryptoHalHashFreeCtx(void **ctx)
145 {
146 FreeCtx func = (FreeCtx)GetAbility(HKS_CRYPTO_ABILITY_HASH_FREE_CTX);
147 if (func == NULL) {
148 HKS_LOG_E("CryptoHalHashFreeCtx func is null");
149 return;
150 }
151
152 func(ctx);
153 }
154
155 #endif /* _CUT_AUTHENTICATE_ */
156
HksCryptoHalBnExpMod(struct HksBlob * x,const struct HksBlob * a,const struct HksBlob * e,const struct HksBlob * n)157 int32_t HksCryptoHalBnExpMod(struct HksBlob *x, const struct HksBlob *a,
158 const struct HksBlob *e, const struct HksBlob *n)
159 {
160 BnExpMod func = (BnExpMod)GetAbility(HKS_CRYPTO_ABILITY_BN_EXP_MOD);
161 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
162 return func(x, a, e, n);
163 }
164
165 #ifndef _CUT_AUTHENTICATE_
HksCryptoHalGenerateKey(const struct HksKeySpec * spec,struct HksBlob * key)166 int32_t HksCryptoHalGenerateKey(const struct HksKeySpec *spec, struct HksBlob *key)
167 {
168 if (spec == NULL || key == NULL) {
169 HKS_LOG_E("Crypt Hal GenerateKey msg or hash or ctx is NULL");
170 return HKS_ERROR_INVALID_ARGUMENT;
171 }
172
173 GenerateKey func = (GenerateKey)GetAbility(HKS_CRYPTO_ABILITY_GENERATE_KEY(spec->algType));
174 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls GenerateKey func is null!")
175 return func(spec, key);
176 }
177
HksCryptoHalGetMainKey(const struct HksBlob * message,struct HksBlob * mainKey)178 int32_t HksCryptoHalGetMainKey(const struct HksBlob *message, struct HksBlob *mainKey)
179 {
180 GetMainKey func = (GetMainKey)GetAbility(HKS_CRYPTO_ABILITY_GET_MAIN_KEY);
181 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
182 return func(message, mainKey);
183 }
184
HksCryptoHalGetPubKey(const struct HksBlob * keyIn,struct HksBlob * keyOut)185 int32_t HksCryptoHalGetPubKey(const struct HksBlob *keyIn, struct HksBlob *keyOut)
186 {
187 if (CheckBlob(keyIn) != HKS_SUCCESS || CheckBlob(keyOut) != HKS_SUCCESS) {
188 HKS_LOG_E("Invalid params!");
189 return HKS_ERROR_INVALID_ARGUMENT;
190 }
191
192 /* KeyMaterialRsa, KeyMaterialEcc, KeyMaterial25519's size are same */
193 if (keyIn->size < sizeof(struct KeyMaterialRsa)) {
194 HKS_LOG_E("Crypt Hal getPubKey keyIn size is more smaller. size[%" LOG_PUBLIC "d]", keyIn->size);
195 return HKS_ERROR_INVALID_KEY_SIZE;
196 }
197
198 struct KeyMaterialRsa *key = (struct KeyMaterialRsa *)(keyIn->data);
199 PubKey func = (PubKey)GetAbility(HKS_CRYPTO_ABILITY_GET_PUBLIC_KEY(key->keyAlg));
200 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
201 return func(keyIn, keyOut);
202 }
203 #endif /* _CUT_AUTHENTICATE_ */
204
HksCryptoHalDeriveKey(const struct HksBlob * mainKey,const struct HksKeySpec * derivationSpec,struct HksBlob * derivedKey)205 int32_t HksCryptoHalDeriveKey(const struct HksBlob *mainKey,
206 const struct HksKeySpec *derivationSpec, struct HksBlob *derivedKey)
207 {
208 DeriveKey func = (DeriveKey)GetAbility(HKS_CRYPTO_ABILITY_DERIVE_KEY(derivationSpec->algType));
209 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls DeriveKey func is null!")
210 return func(mainKey, derivationSpec, derivedKey);
211 }
212
213 #ifndef _CUT_AUTHENTICATE_
HksCryptoHalAgreeKey(const struct HksBlob * nativeKey,const struct HksBlob * pubKey,const struct HksKeySpec * spec,struct HksBlob * sharedKey)214 int32_t HksCryptoHalAgreeKey(const struct HksBlob *nativeKey, const struct HksBlob *pubKey,
215 const struct HksKeySpec *spec, struct HksBlob *sharedKey)
216 {
217 if (CheckBlob(nativeKey) != HKS_SUCCESS || CheckBlob(pubKey) != HKS_SUCCESS || spec == NULL ||
218 CheckBlob(sharedKey) != HKS_SUCCESS) {
219 HKS_LOG_E("Crypt Hal AgreeKey param error");
220 return HKS_ERROR_INVALID_ARGUMENT;
221 }
222
223 AgreeKey func = (AgreeKey)GetAbility(HKS_CRYPTO_ABILITY_AGREE_KEY(spec->algType));
224 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "Mbedtls AgreeKey func is null!")
225 return func(nativeKey, pubKey, spec, sharedKey);
226 }
227
HksCryptoHalSign(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,const struct HksBlob * message,struct HksBlob * signature)228 int32_t HksCryptoHalSign(const struct HksBlob *key, const struct HksUsageSpec *usageSpec,
229 const struct HksBlob *message, struct HksBlob *signature)
230 {
231 if (CheckBlob(key) != HKS_SUCCESS || usageSpec == NULL || CheckBlob(message) != HKS_SUCCESS ||
232 CheckBlob(signature) != HKS_SUCCESS) {
233 HKS_LOG_E("Crypt Hal Sign param error");
234 return HKS_ERROR_INVALID_ARGUMENT;
235 }
236
237 Sign func = (Sign)GetAbility(HKS_CRYPTO_ABILITY_SIGN(usageSpec->algType));
238 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
239 return func(key, usageSpec, message, signature);
240 }
241
HksCryptoHalVerify(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,const struct HksBlob * message,const struct HksBlob * signature)242 int32_t HksCryptoHalVerify(const struct HksBlob *key, const struct HksUsageSpec *usageSpec,
243 const struct HksBlob *message, const struct HksBlob *signature)
244 {
245 if (CheckBlob(key) != HKS_SUCCESS || usageSpec == NULL || CheckBlob(message) != HKS_SUCCESS ||
246 CheckBlob(signature) != HKS_SUCCESS) {
247 HKS_LOG_E("Crypt Hal Verify param error");
248 return HKS_ERROR_INVALID_ARGUMENT;
249 }
250
251 Verify func = (Verify)GetAbility(HKS_CRYPTO_ABILITY_VERIFY(usageSpec->algType));
252 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
253 return func(key, usageSpec, message, signature);
254 }
255 #endif /* _CUT_AUTHENTICATE_ */
256
HksCryptoHalFillRandom(struct HksBlob * randomData)257 int32_t HksCryptoHalFillRandom(struct HksBlob *randomData)
258 {
259 FillRandom func = (FillRandom)GetAbility(HKS_CRYPTO_ABILITY_FILL_RANDOM);
260 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
261 return func(randomData);
262 }
263
HksCryptoHalFillPrivRandom(struct HksBlob * randomData)264 int32_t HksCryptoHalFillPrivRandom(struct HksBlob *randomData)
265 {
266 return HksCryptoHalFillRandom(randomData);
267 }
268
HksCryptoHalEncrypt(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,const struct HksBlob * message,struct HksBlob * cipherText,struct HksBlob * tagAead)269 int32_t HksCryptoHalEncrypt(const struct HksBlob *key, const struct HksUsageSpec *usageSpec,
270 const struct HksBlob *message, struct HksBlob *cipherText, struct HksBlob *tagAead)
271 {
272 int32_t ret = EncryptCheckParam(key, usageSpec, message, cipherText);
273 HKS_IF_NOT_SUCC_LOGE_RETURN(ret, HKS_ERROR_INVALID_ARGUMENT, "Invalid params!")
274
275 Encrypt func = (Encrypt)GetAbility(HKS_CRYPTO_ABILITY_ENCRYPT(usageSpec->algType));
276 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "EncryptAes func is null!")
277 return func(key, usageSpec, message, cipherText, tagAead);
278 }
279
HksCryptoHalEncryptInit(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,void ** ctx)280 int32_t HksCryptoHalEncryptInit(const struct HksBlob *key, const struct HksUsageSpec *usageSpec, void **ctx)
281 {
282 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(key), HKS_ERROR_INVALID_ARGUMENT, "Invalid param key!")
283 HKS_IF_NULL_LOGE_RETURN(usageSpec, HKS_ERROR_INVALID_ARGUMENT, "Invalid param usageSpec!")
284
285 EncryptInit func = (EncryptInit)GetAbility(HKS_CRYPTO_ABILITY_ENCRYPT_INIT(usageSpec->algType));
286 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
287
288 return func(ctx, key, usageSpec, true);
289 }
290
HksCryptoHalEncryptUpdate(const struct HksBlob * message,void * ctx,struct HksBlob * out,const uint32_t algtype)291 int32_t HksCryptoHalEncryptUpdate(const struct HksBlob *message, void *ctx, struct HksBlob *out, const uint32_t algtype)
292 {
293 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(message), HKS_ERROR_INVALID_ARGUMENT, "Invalid param message!")
294 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(out), HKS_ERROR_INVALID_ARGUMENT, "Invalid param out!")
295
296 HKS_IF_NULL_LOGE_RETURN(ctx, HKS_ERROR_INVALID_ARGUMENT, "Invalid param ctx or out !")
297
298 EncryptUpdate func = (EncryptUpdate)GetAbility(HKS_CRYPTO_ABILITY_ENCRYPT_UPDATE(algtype));
299 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
300
301 return func(ctx, message, out, true);
302 }
303
HksCryptoHalEncryptFinal(const struct HksBlob * message,void ** ctx,struct HksBlob * cipherText,struct HksBlob * tagAead,const uint32_t algtype)304 int32_t HksCryptoHalEncryptFinal(const struct HksBlob *message, void **ctx, struct HksBlob *cipherText,
305 struct HksBlob *tagAead, const uint32_t algtype)
306 {
307 HKS_IF_NULL_LOGE_RETURN(message, HKS_ERROR_INVALID_ARGUMENT, "Invalid param message!")
308
309 if (ctx == NULL || *ctx == NULL) {
310 HKS_LOG_E("Invalid param ctx!");
311 return HKS_ERROR_INVALID_ARGUMENT;
312 }
313
314 EncryptFinal func = (EncryptFinal)GetAbility(HKS_CRYPTO_ABILITY_ENCRYPT_FINAL(algtype));
315 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
316
317 return func(ctx, message, cipherText, tagAead, true);
318 }
319
HksCryptoHalEncryptFreeCtx(void ** ctx,const uint32_t algtype)320 void HksCryptoHalEncryptFreeCtx(void **ctx, const uint32_t algtype)
321 {
322 FreeCtx func = (FreeCtx)GetAbility(HKS_CRYPTO_ABILITY_ENCRYPT_FREE_CTX(algtype));
323 if (func == NULL) {
324 HKS_LOG_E("CryptoHalEncryptFreeCtx func is null");
325 return;
326 }
327
328 func(ctx);
329 }
330
HksCryptoHalDecrypt(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,const struct HksBlob * message,struct HksBlob * cipherText)331 int32_t HksCryptoHalDecrypt(const struct HksBlob *key, const struct HksUsageSpec *usageSpec,
332 const struct HksBlob *message, struct HksBlob *cipherText)
333 {
334 int32_t ret = EncryptCheckParam(key, usageSpec, message, cipherText);
335 HKS_IF_NOT_SUCC_LOGE_RETURN(ret, HKS_ERROR_INVALID_ARGUMENT, "Invalid params!")
336
337 Decrypt func = (Decrypt)GetAbility(HKS_CRYPTO_ABILITY_DECRYPT(usageSpec->algType));
338 HKS_IF_NULL_LOGE_RETURN(func, HKS_ERROR_INVALID_ARGUMENT, "DecryptAes func is null!")
339 return func(key, usageSpec, message, cipherText);
340 }
341
HksCryptoHalDecryptInit(const struct HksBlob * key,const struct HksUsageSpec * usageSpec,void ** ctx)342 int32_t HksCryptoHalDecryptInit(const struct HksBlob *key, const struct HksUsageSpec *usageSpec, void **ctx)
343 {
344 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(key), HKS_ERROR_INVALID_ARGUMENT, "Invalid param key!")
345 HKS_IF_NULL_LOGE_RETURN(usageSpec, HKS_ERROR_INVALID_ARGUMENT, "Invalid param key!")
346
347 DecryptInit func = (DecryptInit)GetAbility(HKS_CRYPTO_ABILITY_DECRYPT_INIT(usageSpec->algType));
348 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
349
350 return func(ctx, key, usageSpec, false);
351 }
352
HksCryptoHalDecryptUpdate(const struct HksBlob * message,void * ctx,struct HksBlob * out,const uint32_t algtype)353 int32_t HksCryptoHalDecryptUpdate(const struct HksBlob *message, void *ctx, struct HksBlob *out, const uint32_t algtype)
354 {
355 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(message), HKS_ERROR_INVALID_ARGUMENT, "Invalid param message!")
356 HKS_IF_NOT_SUCC_LOGE_RETURN(CheckBlob(out), HKS_ERROR_INVALID_ARGUMENT, "Invalid param out!")
357 HKS_IF_NULL_LOGE_RETURN(ctx, HKS_ERROR_INVALID_ARGUMENT, "Invalid param ctx or out !")
358
359 DecryptUpdate func = (DecryptUpdate)GetAbility(HKS_CRYPTO_ABILITY_DECRYPT_UPDATE(algtype));
360 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
361
362 return func(ctx, message, out, false);
363 }
364
HksCryptoHalDecryptFinal(const struct HksBlob * message,void ** ctx,struct HksBlob * cipherText,struct HksBlob * tagAead,const uint32_t algtype)365 int32_t HksCryptoHalDecryptFinal(const struct HksBlob *message, void **ctx, struct HksBlob *cipherText,
366 struct HksBlob *tagAead, const uint32_t algtype)
367 {
368 HKS_IF_NULL_LOGE_RETURN(message, HKS_ERROR_INVALID_ARGUMENT, "Invalid param message!")
369
370 if (ctx == NULL || *ctx == NULL) {
371 HKS_LOG_E("Invalid param ctx!");
372 return HKS_ERROR_INVALID_ARGUMENT;
373 }
374
375 DecryptFinal func = (DecryptFinal)GetAbility(HKS_CRYPTO_ABILITY_DECRYPT_FINAL(algtype));
376 HKS_IF_NULL_RETURN(func, HKS_ERROR_INVALID_ARGUMENT)
377
378 return func(ctx, message, cipherText, tagAead, false);
379 }
380
HksCryptoHalDecryptFreeCtx(void ** ctx,const uint32_t algtype)381 void HksCryptoHalDecryptFreeCtx(void **ctx, const uint32_t algtype)
382 {
383 FreeCtx func = (FreeCtx)GetAbility(HKS_CRYPTO_ABILITY_DECRYPT_FREE_CTX(algtype));
384 if (func == NULL) {
385 HKS_LOG_E("CryptoHalDecryptFreeCtx func is null");
386 return;
387 }
388
389 func(ctx);
390 }
391