]> code.delx.au - refind/blob - refind/crc32.h
Fixed uninitialized-pointer bug that manifested as a crash with
[refind] / refind / crc32.h
1 /*-
2 * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
3 * code or tables extracted from it, as desired without restriction.
4 *
5 * First, the polynomial itself and its table of feedback terms. The
6 * polynomial is
7 * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
8 *
9 * Note that we take it "backwards" and put the highest-order term in
10 * the lowest-order bit. The X^32 term is "implied"; the LSB is the
11 * X^31 term, etc. The X^0 term (usually shown as "+1") results in
12 * the MSB being 1
13 *
14 * Note that the usual hardware shift register implementation, which
15 * is what we're using (we're merely optimizing it by doing eight-bit
16 * chunks at a time) shifts bits into the lowest-order term. In our
17 * implementation, that means shifting towards the right. Why do we
18 * do it this way? Because the calculated CRC must be transmitted in
19 * order from highest-order term to lowest-order term. UARTs transmit
20 * characters in order from LSB to MSB. By storing the CRC this way
21 * we hand it to the UART in the order low-byte to high-byte; the UART
22 * sends each low-bit to hight-bit; and the result is transmission bit
23 * by bit from highest- to lowest-order term without requiring any bit
24 * shuffling on our part. Reception works similarly
25 *
26 * The feedback terms table consists of 256, 32-bit entries. Notes
27 *
28 * The table can be generated at runtime if desired; code to do so
29 * is shown later. It might not be obvious, but the feedback
30 * terms simply represent the results of eight shift/xor opera
31 * tions for all combinations of data and CRC register values
32 *
33 * The values must be right-shifted by eight bits by the "updcrc
34 * logic; the shift must be unsigned (bring in zeroes). On some
35 * hardware you could probably optimize the shift in assembler by
36 * using byte-swap instructions
37 * polynomial $edb88320
38 *
39 *
40 * CRC32 code derived from work by Gary S. Brown.
41 */
42 /*
43 * Modified slightly for use on EFI by Rod Smith
44 */
45
46 #ifndef __CRC32_H_
47 #define __CRC32_H_
48
49 #ifdef __MAKEWITH_GNUEFI
50 #include "efi.h"
51 #include "efilib.h"
52 #else
53 #include "../include/tiano_includes.h"
54 #endif
55
56 UINT32 crc32(UINT32 crc, const VOID *buf, UINTN size);
57
58 #endif