liblzma: Fix a typo in a comment
[xz/debian.git] / src / liblzma / check / check.c
blob7734ace1856edce8c7b4936995189294ed13066b
1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file check.c
6 /// \brief Single API to access different integrity checks
7 //
8 // Author: Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "check.h"
15 extern LZMA_API(lzma_bool)
16 lzma_check_is_supported(lzma_check type)
18 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
19 return false;
21 static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
22 true, // LZMA_CHECK_NONE
24 #ifdef HAVE_CHECK_CRC32
25 true,
26 #else
27 false,
28 #endif
30 false, // Reserved
31 false, // Reserved
33 #ifdef HAVE_CHECK_CRC64
34 true,
35 #else
36 false,
37 #endif
39 false, // Reserved
40 false, // Reserved
41 false, // Reserved
42 false, // Reserved
43 false, // Reserved
45 #ifdef HAVE_CHECK_SHA256
46 true,
47 #else
48 false,
49 #endif
51 false, // Reserved
52 false, // Reserved
53 false, // Reserved
54 false, // Reserved
55 false, // Reserved
58 return available_checks[(unsigned int)(type)];
62 extern LZMA_API(uint32_t)
63 lzma_check_size(lzma_check type)
65 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
66 return UINT32_MAX;
68 // See file-format.txt section 2.1.1.2.
69 static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
71 4, 4, 4,
72 8, 8, 8,
73 16, 16, 16,
74 32, 32, 32,
75 64, 64, 64
78 return check_sizes[(unsigned int)(type)];
82 extern void
83 lzma_check_init(lzma_check_state *check, lzma_check type)
85 switch (type) {
86 case LZMA_CHECK_NONE:
87 break;
89 #ifdef HAVE_CHECK_CRC32
90 case LZMA_CHECK_CRC32:
91 check->state.crc32 = 0;
92 break;
93 #endif
95 #ifdef HAVE_CHECK_CRC64
96 case LZMA_CHECK_CRC64:
97 check->state.crc64 = 0;
98 break;
99 #endif
101 #ifdef HAVE_CHECK_SHA256
102 case LZMA_CHECK_SHA256:
103 lzma_sha256_init(check);
104 break;
105 #endif
107 default:
108 break;
111 return;
115 extern void
116 lzma_check_update(lzma_check_state *check, lzma_check type,
117 const uint8_t *buf, size_t size)
119 switch (type) {
120 #ifdef HAVE_CHECK_CRC32
121 case LZMA_CHECK_CRC32:
122 check->state.crc32 = lzma_crc32(buf, size, check->state.crc32);
123 break;
124 #endif
126 #ifdef HAVE_CHECK_CRC64
127 case LZMA_CHECK_CRC64:
128 check->state.crc64 = lzma_crc64(buf, size, check->state.crc64);
129 break;
130 #endif
132 #ifdef HAVE_CHECK_SHA256
133 case LZMA_CHECK_SHA256:
134 lzma_sha256_update(buf, size, check);
135 break;
136 #endif
138 default:
139 break;
142 return;
146 extern void
147 lzma_check_finish(lzma_check_state *check, lzma_check type)
149 switch (type) {
150 #ifdef HAVE_CHECK_CRC32
151 case LZMA_CHECK_CRC32:
152 check->buffer.u32[0] = conv32le(check->state.crc32);
153 break;
154 #endif
156 #ifdef HAVE_CHECK_CRC64
157 case LZMA_CHECK_CRC64:
158 check->buffer.u64[0] = conv64le(check->state.crc64);
159 break;
160 #endif
162 #ifdef HAVE_CHECK_SHA256
163 case LZMA_CHECK_SHA256:
164 lzma_sha256_finish(check);
165 break;
166 #endif
168 default:
169 break;
172 return;