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 #ifndef SECURITY_APP_VERIFY_HAP_H
17 #define SECURITY_APP_VERIFY_HAP_H
18 
19 #include <stdint.h>
20 
21 #include "app_centraldirectory.h"
22 #include "app_common.h"
23 #include "app_file.h"
24 #include "app_verify.h"
25 #include "app_verify_pub.h"
26 #include "mbedtls/pk.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33 
34 #define ALGORITHM_MASK 0x000f
35 #define ALGORITHM_SHA256 0x01
36 #define ALGORITHM_SHA384 0x02
37 #define ALGORITHM_SHA512 0x03
38 #define ALGORITHM_PKCS1_SHA256 0x04
39 #define ALGORITHM_PKCS1_SHA384 0x05
40 #define ALGORITHM_PKCS1_SHA512 0x06
41 
42 #define HAP_DIGEST_PRIFIX_LEN 5
43 #define MAX_OID_LENGTH 128
44 #define HASH_BLOB_LEN (1024 * 1024)
45 #define ONCE_READ_LEN (1024 * 64)
46 #define HASH_ALG_SHA256     MBEDTLS_MD_SHA256 /* sha256 */
47 #define HASH_ALG_SHA384     MBEDTLS_MD_SHA384 /* sha384 */
48 #define HASH_ALG_SHA512     MBEDTLS_MD_SHA512 /* sha512 */
49 
50 bool VerifyIntegrityChunk(
51     int32_t digestAlgorithm, int32_t fp, const SignatureInfo *signInfo, const HapBuf *actualDigest);
52 int32_t GetDigestAlgorithmId(uint32_t signAlgorithm);
53 
54 #ifdef __cplusplus
55 #if __cplusplus
56 }
57 #endif
58 #endif
59 
60 #endif
61