1 /*
2  * Copyright (C) 2024 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 SM4_COMMON_H
17 #define SM4_COMMON_H
18 
19 #include "algorithm_parameter.h"
20 #include "blob.h"
21 #include "cipher.h"
22 #include "sym_key.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 HcfResult GenerateSm4SymKey(HcfSymKey **key);
29 int32_t GenerateSymKeyForSm4(const char *algoName, HcfSymKey **key);
30 
31 // use ECB, test abnormal input
32 int32_t Sm4EncryptWithInput(HcfCipher *cipher, HcfSymKey *key, HcfBlob *input,
33     uint8_t *cipherText, int *cipherTextLen);
34 
35 // test encrypt and decrypt with null plain text
36 int32_t Sm4DecryptEmptyMsg(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params,
37     uint8_t *cipherText, int cipherTextLen);
38 int32_t Sm4Encrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params,
39     uint8_t *cipherText, int *cipherTextLen);
40 int32_t Sm4Decrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params,
41     uint8_t *cipherText, int cipherTextLen);
42 int32_t Sm4NoUpdateEncrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params,
43     uint8_t *cipherText, int *cipherTextLen);
44 int32_t Sm4NoUpdateDecrypt(HcfCipher *cipher, HcfSymKey *key, HcfParamsSpec *params,
45     uint8_t *cipherText, int cipherTextLen);
46 const char *GetMockClass(void);
47 
48 #ifdef __cplusplus
49 }
50 #endif
51 #endif
52