blob: 05f99413182ab44a1a9a4e8f8fd9fa6cc4011b1e [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* sha.h
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Redistribution and use in source and binary forms, with or without
6** modification, are permitted provided that the following conditions are met:
7** * Redistributions of source code must retain the above copyright
8** notice, this list of conditions and the following disclaimer.
9** * Redistributions in binary form must reproduce the above copyright
10** notice, this list of conditions and the following disclaimer in the
11** documentation and/or other materials provided with the distribution.
12** * Neither the name of Google Inc. nor the names of its contributors may
13** be used to endorse or promote products derived from this software
14** without specific prior written permission.
15**
16** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
17** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef _EMBEDDED_SHA_H_
29#define _EMBEDDED_SHA_H_
30
31#include <inttypes.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37typedef struct SHA_CTX {
38 uint64_t count;
39 uint32_t state[5];
40#if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
41 union {
42 uint8_t b[64];
43 uint32_t w[16];
44 } buf;
45#else
46 uint8_t buf[64];
47#endif
48} SHA_CTX;
49
50void SHA_init(SHA_CTX* ctx);
51void SHA_update(SHA_CTX* ctx, const void* data, int len);
52const uint8_t* SHA_final(SHA_CTX* ctx);
53
54/* Convenience method. Returns digest parameter value. */
55const uint8_t* SHA(const void* data, int len, uint8_t* digest);
56
57#define SHA_DIGEST_SIZE 20
58
59typedef enum check_status_t{
60 ERROR_SHA = -3, // sha1输入参数错误
61 PATCH_ERR = -2, // 检测hash既不等于source_hash也不等于target_hash, 一般错误情况
62 NOT_EXIST_FILE = -1, // 检测文件不存在
63 SOURCE_SUCC = 0, // 检测hash等于目标source_hash, 一般正常情况
64 PATCH_SUCC = 1, // 检测hash等于目标target_hash, up to data
65}Check_status;
66
67int ParseSha1(const char* str, uint8_t* digest);
68
69const uint8_t* ROCK_SHA(const char *file_name, uint8_t *digest);
70
71#ifdef __cplusplus
72}
73#endif
74
75#endif