Remove building with NOCRYPTO option
[minix.git] / external / public-domain / xz / dist / src / liblzma / check / check.c
blob428ddaeb77981d648f9bb8119a00609f6f4374f0
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file check.c
4 /// \brief Single API to access different integrity checks
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.
11 ///////////////////////////////////////////////////////////////////////////////
13 #include "check.h"
16 extern LZMA_API(lzma_bool)
17 lzma_check_is_supported(lzma_check type)
19 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
20 return false;
22 static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
23 true, // LZMA_CHECK_NONE
25 #ifdef HAVE_CHECK_CRC32
26 true,
27 #else
28 false,
29 #endif
31 false, // Reserved
32 false, // Reserved
34 #ifdef HAVE_CHECK_CRC64
35 true,
36 #else
37 false,
38 #endif
40 false, // Reserved
41 false, // Reserved
42 false, // Reserved
43 false, // Reserved
44 false, // Reserved
46 #ifdef HAVE_CHECK_SHA256
47 true,
48 #else
49 false,
50 #endif
52 false, // Reserved
53 false, // Reserved
54 false, // Reserved
55 false, // Reserved
56 false, // Reserved
59 return available_checks[(unsigned int)(type)];
63 extern LZMA_API(uint32_t)
64 lzma_check_size(lzma_check type)
66 if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
67 return UINT32_MAX;
69 // See file-format.txt section 2.1.1.2.
70 static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
72 4, 4, 4,
73 8, 8, 8,
74 16, 16, 16,
75 32, 32, 32,
76 64, 64, 64
79 return check_sizes[(unsigned int)(type)];
83 extern void
84 lzma_check_init(lzma_check_state *check, lzma_check type)
86 switch (type) {
87 case LZMA_CHECK_NONE:
88 break;
90 #ifdef HAVE_CHECK_CRC32
91 case LZMA_CHECK_CRC32:
92 check->state.crc32 = 0;
93 break;
94 #endif
96 #ifdef HAVE_CHECK_CRC64
97 case LZMA_CHECK_CRC64:
98 check->state.crc64 = 0;
99 break;
100 #endif
102 #ifdef HAVE_CHECK_SHA256
103 case LZMA_CHECK_SHA256:
104 lzma_sha256_init(check);
105 break;
106 #endif
108 default:
109 break;
112 return;
116 extern void
117 lzma_check_update(lzma_check_state *check, lzma_check type,
118 const uint8_t *buf, size_t size)
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
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
133 #ifdef HAVE_CHECK_SHA256
134 case LZMA_CHECK_SHA256:
135 lzma_sha256_update(buf, size, check);
136 break;
137 #endif
139 default:
140 break;
143 return;
147 extern void
148 lzma_check_finish(lzma_check_state *check, lzma_check type)
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
157 #ifdef HAVE_CHECK_CRC64
158 case LZMA_CHECK_CRC64:
159 check->buffer.u64[0] = conv64le(check->state.crc64);
160 break;
161 #endif
163 #ifdef HAVE_CHECK_SHA256
164 case LZMA_CHECK_SHA256:
165 lzma_sha256_finish(check);
166 break;
167 #endif
169 default:
170 break;
173 return;