Rizin
unix-like reverse engineering framework and cli tools
check.c
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #include "check.h"
14 
15 
17 lzma_check_is_supported(lzma_check type)
18 {
19  if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
20  return false;
21 
22  static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
23  true, // LZMA_CHECK_NONE
24 
25 #ifdef HAVE_CHECK_CRC32
26  true,
27 #else
28  false,
29 #endif
30 
31  false, // Reserved
32  false, // Reserved
33 
34 #ifdef HAVE_CHECK_CRC64
35  true,
36 #else
37  false,
38 #endif
39 
40  false, // Reserved
41  false, // Reserved
42  false, // Reserved
43  false, // Reserved
44  false, // Reserved
45 
46 #ifdef HAVE_CHECK_SHA256
47  true,
48 #else
49  false,
50 #endif
51 
52  false, // Reserved
53  false, // Reserved
54  false, // Reserved
55  false, // Reserved
56  false, // Reserved
57  };
58 
59  return available_checks[(unsigned int)(type)];
60 }
61 
62 
64 lzma_check_size(lzma_check type)
65 {
66  if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
67  return UINT32_MAX;
68 
69  // See file-format.txt section 2.1.1.2.
70  static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
71  0,
72  4, 4, 4,
73  8, 8, 8,
74  16, 16, 16,
75  32, 32, 32,
76  64, 64, 64
77  };
78 
79  return check_sizes[(unsigned int)(type)];
80 }
81 
82 
83 extern void
85 {
86  switch (type) {
87  case LZMA_CHECK_NONE:
88  break;
89 
90 #ifdef HAVE_CHECK_CRC32
91  case LZMA_CHECK_CRC32:
92  check->state.crc32 = 0;
93  break;
94 #endif
95 
96 #ifdef HAVE_CHECK_CRC64
97  case LZMA_CHECK_CRC64:
98  check->state.crc64 = 0;
99  break;
100 #endif
101 
102 #ifdef HAVE_CHECK_SHA256
103  case LZMA_CHECK_SHA256:
105  break;
106 #endif
107 
108  default:
109  break;
110  }
111 
112  return;
113 }
114 
115 
116 extern void
118  const uint8_t *buf, size_t size)
119 {
120  switch (type) {
121 #ifdef HAVE_CHECK_CRC32
122  case LZMA_CHECK_CRC32:
123  check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
124  break;
125 #endif
126 
127 #ifdef HAVE_CHECK_CRC64
128  case LZMA_CHECK_CRC64:
129  check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
130  break;
131 #endif
132 
133 #ifdef HAVE_CHECK_SHA256
134  case LZMA_CHECK_SHA256:
136  break;
137 #endif
138 
139  default:
140  break;
141  }
142 
143  return;
144 }
145 
146 
147 extern void
149 {
150  switch (type) {
151 #ifdef HAVE_CHECK_CRC32
152  case LZMA_CHECK_CRC32:
153  check->buffer.u32[0] = conv32le(check->state.crc32);
154  break;
155 #endif
156 
157 #ifdef HAVE_CHECK_CRC64
158  case LZMA_CHECK_CRC64:
159  check->buffer.u64[0] = conv64le(check->state.crc64);
160  break;
161 #endif
162 
163 #ifdef HAVE_CHECK_SHA256
164  case LZMA_CHECK_SHA256:
166  break;
167 #endif
168 
169  default:
170  break;
171  }
172 
173  return;
174 }
lzma_check
Type of the integrity check (Check ID)
Definition: check.h:27
@ LZMA_CHECK_CRC32
Definition: check.h:35
@ LZMA_CHECK_NONE
Definition: check.h:28
@ LZMA_CHECK_CRC64
Definition: check.h:42
@ LZMA_CHECK_SHA256
Definition: check.h:49
#define LZMA_CHECK_ID_MAX
Maximum valid Check ID.
Definition: check.h:68
Internal API to different integrity check functions.
void lzma_sha256_update(const uint8_t *buf, size_t size, lzma_check_state *check)
Update the SHA-256 hash state.
Definition: sha256.c:142
void lzma_sha256_init(lzma_check_state *check)
Prepare SHA-256 state for new input.
Definition: sha256.c:127
void lzma_sha256_finish(lzma_check_state *check)
Finish the SHA-256 calculation and store the result to check->buffer.u8.
Definition: sha256.c:169
LZMA_API(lzma_bool)
Definition: check.c:16
void lzma_check_finish(lzma_check_state *check, lzma_check type)
Finish the check calculation and store the result to check->buffer.u8.
Definition: check.c:148
void lzma_check_update(lzma_check_state *check, lzma_check type, const uint8_t *buf, size_t size)
Update the check state.
Definition: check.c:117
void lzma_check_init(lzma_check_state *check, lzma_check type)
Initialize *check depending on type.
Definition: check.c:84
lzma_check check
Definition: container.h:292
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
int type
Definition: mipsasm.c:17
static int
Definition: sfsocketcall.h:114
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define UINT32_MAX
Structure to hold internal state of the check being calculated.
Definition: check.h:81
#define conv64le(num)
#define conv32le(num)
unsigned char lzma_bool
Boolean.
Definition: base.h:29