The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/xz-embedded/linux/lib/xz/xz_crc64.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * CRC64 using the polynomial from ECMA-182
    3  *
    4  * This file is similar to xz_crc32.c. See the comments there.
    5  *
    6  * Authors: Lasse Collin <lasse.collin@tukaani.org>
    7  *          Igor Pavlov <https://7-zip.org/>
    8  *
    9  * This file has been put into the public domain.
   10  * You can do whatever you want with this file.
   11  */
   12 
   13 #include "xz_private.h"
   14 
   15 #ifndef STATIC_RW_DATA
   16 #       define STATIC_RW_DATA static
   17 #endif
   18 
   19 STATIC_RW_DATA uint64_t xz_crc64_table[256];
   20 
   21 XZ_EXTERN void xz_crc64_init(void)
   22 {
   23         /*
   24          * The ULL suffix is needed for -std=gnu89 compatibility
   25          * on 32-bit platforms.
   26          */
   27         const uint64_t poly = 0xC96C5795D7870F42ULL;
   28 
   29         uint32_t i;
   30         uint32_t j;
   31         uint64_t r;
   32 
   33         for (i = 0; i < 256; ++i) {
   34                 r = i;
   35                 for (j = 0; j < 8; ++j)
   36                         r = (r >> 1) ^ (poly & ~((r & 1) - 1));
   37 
   38                 xz_crc64_table[i] = r;
   39         }
   40 
   41         return;
   42 }
   43 
   44 XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
   45 {
   46         crc = ~crc;
   47 
   48         while (size != 0) {
   49                 crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
   50                 --size;
   51         }
   52 
   53         return ~crc;
   54 }

Cache object: 0f985193b1d5c9c4f9bd70aa383208b5


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.