VirtualBox

source: vbox/trunk/src/libs/liblzma-5.6.4/check/crc32_small.c@ 109020

Last change on this file since 109020 was 108905, checked in by vboxsync, 6 weeks ago

liblzma-5.6.4: Applied and adjusted our liblzma changes to 5.6.4. jiraref:VBP-1613

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 1.1 KB
Line 
1// SPDX-License-Identifier: 0BSD
2
3///////////////////////////////////////////////////////////////////////////////
4//
5/// \file crc32_small.c
6/// \brief CRC32 calculation (size-optimized)
7//
8// Author: Lasse Collin
9//
10///////////////////////////////////////////////////////////////////////////////
11
12#include "check.h"
13
14
15uint32_t lzma_crc32_table[1][256];
16
17
18#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
19__attribute__((__constructor__))
20#endif
21static void
22crc32_init(void)
23{
24 static const uint32_t poly32 = UINT32_C(0xEDB88320);
25
26 for (size_t b = 0; b < 256; ++b) {
27 uint32_t r = b;
28 for (size_t i = 0; i < 8; ++i) {
29 if (r & 1)
30 r = (r >> 1) ^ poly32;
31 else
32 r >>= 1;
33 }
34
35 lzma_crc32_table[0][b] = r;
36 }
37
38 return;
39}
40
41
42#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
43extern void
44lzma_crc32_init(void)
45{
46 mythread_once(crc32_init);
47 return;
48}
49#endif
50
51
52extern LZMA_API(uint32_t)
53lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
54{
55#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
56 lzma_crc32_init();
57#endif
58
59 crc = ~crc;
60
61 while (size != 0) {
62 crc = lzma_crc32_table[0][*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
63 --size;
64 }
65
66 return ~crc;
67}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette