1 /*
2  * Copyright (c) 2021-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 HKS_COMMON_CHECK_H
17 #define HKS_COMMON_CHECK_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 #include "hks_type.h"
23 #include "hks_crypto_hal.h"
24 
25 #define HKS_DIGEST_MD5_LEN 16
26 #define HKS_DIGEST_SHA1_LEN 20
27 #define HKS_DIGEST_SHA224_LEN 28
28 #define HKS_DIGEST_SHA256_LEN 32
29 #define HKS_DIGEST_SHA384_LEN 48
30 #define HKS_DIGEST_SHA512_LEN 64
31 #define HKS_DIGEST_SM3_LEN 32
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 int32_t HksCheckBlob4(const struct HksBlob *data1, const struct HksBlob *data2,
38     const struct HksBlob *data3, const struct HksBlob *data4);
39 
40 int32_t HksCheckBlob3(const struct HksBlob *data1, const struct HksBlob *data2, const struct HksBlob *data3);
41 
42 int32_t HksCheckBlob2(const struct HksBlob *data1, const struct HksBlob *data2);
43 
44 int32_t HksCheckParamSetValidity(const struct HksParamSet *paramSet);
45 
46 int32_t HksCheckBlob4AndParamSet(const struct HksBlob *data1, const struct HksBlob *data2,
47     const struct HksBlob *data3, const struct HksBlob *data4, const struct HksParamSet *paramSet);
48 
49 int32_t HksCheckBlob3AndParamSet(const struct HksBlob *data1, const struct HksBlob *data2,
50     const struct HksBlob *data3, const struct HksParamSet *paramSet);
51 
52 int32_t HksCheckBlob2AndParamSet(const struct HksBlob *data1, const struct HksBlob *data2,
53     const struct HksParamSet *paramSet);
54 
55 int32_t HksCheckBlobAndParamSet(const struct HksBlob *data, const struct HksParamSet *paramSet);
56 
57 int32_t HksCheckBlobAndParamSet2(const struct HksBlob *data, const struct HksParamSet *paramSet1,
58     const struct HksParamSet *paramSet2);
59 
60 int32_t HksCheckBlob2AndParamSet2(const struct HksBlob *data1, const struct HksBlob *data2,
61     const struct HksParamSet *paramSet1, const struct HksParamSet *paramSet2);
62 
63 int32_t HksGetDigestLen(uint32_t digest, uint32_t *digestLen);
64 
65 int32_t HksCheckAesAeMode(const struct HksParamSet *paramSet, bool *isAes, bool *isAeMode);
66 
67 int32_t HksCheckWrappedDataFormatValidity(const struct HksBlob *wrappedData, uint32_t validTotalBlobs,
68     const uint32_t *validBlobLengths);
69 
70 int32_t HksGetBlobFromWrappedData(const struct HksBlob *wrappedData, uint32_t blobIndex, uint32_t totalBlobs,
71     struct HksBlob *blob);
72 
73 int32_t HksCheckKeyNeedStored(const struct HksParamSet *paramSet, bool *isNeedStorage);
74 
75 int32_t HksCheckKeyBlobParamSetEqualRuntimeParamSet(const struct HksParamSet *keyBlobParamSet,
76     const struct HksParamSet *runtimeParamSet, uint32_t tag);
77 
78 void SetRsaPssSaltLenType(const struct HksParamSet *paramSet, struct HksUsageSpec *usageSpec);
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif /* HKS_COMMON_CHECK_H */
84