Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
check.h
Go to the documentation of this file.
1// SPDX-License-Identifier: 0BSD
2
4//
7//
8// Author: Lasse Collin
9//
11
12#ifndef LZMA_CHECK_H
13#define LZMA_CHECK_H
14
15#include "common.h"
16
17// If the function for external SHA-256 is missing, use the internal SHA-256
18// code. Due to how configure works, these defines can only get defined when
19// both a usable header and a type have already been found.
20#if !(defined(HAVE_CC_SHA256_INIT) \
21 || defined(HAVE_SHA256_INIT) \
22 || defined(HAVE_SHA256INIT))
23# define HAVE_INTERNAL_SHA256 1
24#endif
25
26#if defined(HAVE_INTERNAL_SHA256)
27// Nothing
28#elif defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
29# include <CommonCrypto/CommonDigest.h>
30#elif defined(HAVE_SHA256_H)
31# include <sys/types.h>
32# include <sha256.h>
33#elif defined(HAVE_SHA2_H)
34# include <sys/types.h>
35# include <sha2.h>
36#endif
37
38#if defined(HAVE_INTERNAL_SHA256)
40typedef struct {
42 uint32_t state[8];
43
45 uint64_t size;
47#elif defined(HAVE_CC_SHA256_CTX)
48typedef CC_SHA256_CTX lzma_sha256_state;
49#elif defined(HAVE_SHA256_CTX)
51#elif defined(HAVE_SHA2_CTX)
52typedef SHA2_CTX lzma_sha256_state;
53#endif
54
55#if defined(HAVE_INTERNAL_SHA256)
56// Nothing
57#elif defined(HAVE_CC_SHA256_INIT)
58# define LZMA_SHA256FUNC(x) CC_SHA256_ ## x
59#elif defined(HAVE_SHA256_INIT)
60# define LZMA_SHA256FUNC(x) SHA256_ ## x
61#elif defined(HAVE_SHA256INIT)
62# define LZMA_SHA256FUNC(x) SHA256 ## x
63#endif
64
65// Index hashing needs the best possible hash function (preferably
66// a cryptographic hash) for maximum reliability.
67#if defined(HAVE_CHECK_SHA256)
68# define LZMA_CHECK_BEST LZMA_CHECK_SHA256
69#elif defined(HAVE_CHECK_CRC64)
70# define LZMA_CHECK_BEST LZMA_CHECK_CRC64
71#else
72# define LZMA_CHECK_BEST LZMA_CHECK_CRC32
73#endif
74
75
80typedef struct {
82 union {
83 uint8_t u8[64];
84 uint32_t u32[16];
85 uint64_t u64[8];
86 } buffer;
87
89 union {
90 uint32_t crc32;
91 uint64_t crc64;
92 lzma_sha256_state sha256;
93 } state;
94
96
97
100#ifdef HAVE_SMALL
102extern uint32_t lzma_crc32_table[1][256];
103
104extern void lzma_crc32_init(void);
105
106#else
107
109extern const uint32_t lzma_crc32_table[8][256];
110
112extern const uint64_t lzma_crc64_table[4][256];
113#endif
114
115
118
121 const uint8_t *buf, size_t size);
122
125
126
127#ifndef LZMA_SHA256FUNC
128
131
133extern void lzma_sha256_update(
134 const uint8_t *buf, size_t size, lzma_check_state *check);
135
138
139
140#else
141
142static inline void
144{
145 LZMA_SHA256FUNC(Init)(&check->state.sha256);
146}
147
148
149static inline void
150lzma_sha256_update(const uint8_t *buf, size_t size, lzma_check_state *check)
151{
152#if defined(HAVE_CC_SHA256_INIT) && SIZE_MAX > UINT32_MAX
153 // Darwin's CC_SHA256_Update takes uint32_t as the buffer size,
154 // so use a loop to support size_t.
155 while (size > UINT32_MAX) {
156 LZMA_SHA256FUNC(Update)(&check->state.sha256, buf, UINT32_MAX);
157 buf += UINT32_MAX;
158 size -= UINT32_MAX;
159 }
160#endif
161
162 LZMA_SHA256FUNC(Update)(&check->state.sha256, buf, size);
163}
164
165
166static inline void
168{
169 LZMA_SHA256FUNC(Final)(check->buffer.u8, &check->state.sha256);
170}
171
172#endif
173
174#endif
char buf[N_BUF]
Definition spewG.c:36
Definition sha.h:62
Structure to hold internal state of the check being calculated.
Definition check.h:81
State for the internal SHA-256 implementation.
Definition check.h:41
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition crc32.c:237
#define lzma_attr_visibility_hidden
Definition common.h:40
lzma_check
Type of the integrity check (Check ID)
Definition check.h:27
size_t size
Definition check.h:120
lzma_check check
Definition container.h:292
#define UINT32_MAX
Definition lzma.h:158
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
const uint64_t lzma_crc64_table[4][256]
Definition crc64_table_be.h:3
void lzma_sha256_init(lzma_check_state *check)
Prepare SHA-256 state for new input.
Definition sha256.c:127
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
const uint32_t lzma_crc32_table[8][256]
Definition crc32_small.c:16
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
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
void lzma_crc32_init(void)
Definition crc32_small.c:45
unsigned char u8
Definition harness.c:16
uint64_t u64
Definition zstd_decompress.c:63
uint32_t u32
Definition zstd_decompress.c:62