Rizin
unix-like reverse engineering framework and cli tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Macros Modules Pages
check.c File Reference

Single API to access different integrity checks. More...

#include "check.h"

Go to the source code of this file.

Functions

 LZMA_API (lzma_bool)
 
 LZMA_API (uint32_t)
 
void lzma_check_init (lzma_check_state *check, lzma_check type)
 Initialize *check depending on type. More...
 
void lzma_check_update (lzma_check_state *check, lzma_check type, const uint8_t *buf, size_t size)
 Update the check state. More...
 
void lzma_check_finish (lzma_check_state *check, lzma_check type)
 Finish the check calculation and store the result to check->buffer.u8. More...
 

Detailed Description

Single API to access different integrity checks.

Definition in file check.c.

Function Documentation

◆ LZMA_API() [1/2]

LZMA_API ( lzma_bool  )

Definition at line 16 of file check.c.

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 }
#define LZMA_CHECK_ID_MAX
Maximum valid Check ID.
Definition: check.h:68
int type
Definition: mipsasm.c:17
static int
Definition: sfsocketcall.h:114
unsigned char lzma_bool
Boolean.
Definition: base.h:29

References int, LZMA_CHECK_ID_MAX, and type.

◆ LZMA_API() [2/2]

LZMA_API ( uint32_t  )

Definition at line 63 of file check.c.

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 }
unsigned char uint8_t
Definition: sftypes.h:31
#define UINT32_MAX

References int, LZMA_CHECK_ID_MAX, type, and UINT32_MAX.

◆ lzma_check_finish()

void lzma_check_finish ( lzma_check_state check,
lzma_check  type 
)

Finish the check calculation and store the result to check->buffer.u8.

Definition at line 148 of file check.c.

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_CRC32
Definition: check.h:35
@ LZMA_CHECK_CRC64
Definition: check.h:42
@ LZMA_CHECK_SHA256
Definition: check.h:49
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_check check
Definition: container.h:292
#define conv64le(num)
#define conv32le(num)

References check, conv32le, conv64le, LZMA_CHECK_CRC32, LZMA_CHECK_CRC64, LZMA_CHECK_SHA256, lzma_sha256_finish(), and type.

Referenced by block_buffer_encode(), block_decode(), and block_encode().

◆ lzma_check_init()

void lzma_check_init ( lzma_check_state check,
lzma_check  type 
)

Initialize *check depending on type.

Returns
LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not supported by the current version or build of liblzma. LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.

Definition at line 84 of file check.c.

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 }
@ LZMA_CHECK_NONE
Definition: check.h:28
void lzma_sha256_init(lzma_check_state *check)
Prepare SHA-256 state for new input.
Definition: sha256.c:127

References check, LZMA_CHECK_CRC32, LZMA_CHECK_CRC64, LZMA_CHECK_NONE, LZMA_CHECK_SHA256, lzma_sha256_init(), and type.

Referenced by block_buffer_encode(), LZMA_API(), lzma_block_decoder_init(), and lzma_block_encoder_init().

◆ lzma_check_update()

void lzma_check_update ( lzma_check_state check,
lzma_check  type,
const uint8_t buf,
size_t  size 
)

Update the check state.

Definition at line 117 of file check.c.

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 }
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
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138

References check, LZMA_CHECK_CRC32, LZMA_CHECK_CRC64, LZMA_CHECK_SHA256, lzma_sha256_update(), and type.

Referenced by block_buffer_encode(), block_decode(), block_encode(), and hash_append().