VirtualBox

source: vbox/trunk/src/libs/liblzma-5.4.1/check/crc64_small.c@ 101443

最後變更 在這個檔案從101443是 98730,由 vboxsync 提交於 2 年 前

libs/liblzma-5.4.1: Export to OSE, bugref:10254

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 1.1 KB
 
1///////////////////////////////////////////////////////////////////////////////
2//
3/// \file crc64_small.c
4/// \brief CRC64 calculation (size-optimized)
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.
10//
11///////////////////////////////////////////////////////////////////////////////
12
13#include "check.h"
14
15
16static uint64_t crc64_table[256];
17
18
19#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
20__attribute__((__constructor__))
21#endif
22static void
23crc64_init(void)
24{
25 static const uint64_t poly64 = UINT64_C(0xC96C5795D7870F42);
26
27 for (size_t b = 0; b < 256; ++b) {
28 uint64_t r = b;
29 for (size_t i = 0; i < 8; ++i) {
30 if (r & 1)
31 r = (r >> 1) ^ poly64;
32 else
33 r >>= 1;
34 }
35
36 crc64_table[b] = r;
37 }
38
39 return;
40}
41
42
43extern LZMA_API(uint64_t)
44lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc)
45{
46#ifndef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
47 mythread_once(crc64_init);
48#endif
49
50 crc = ~crc;
51
52 while (size != 0) {
53 crc = crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
54 --size;
55 }
56
57 return ~crc;
58}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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