iPXE
crypto
crc32.c
Go to the documentation of this file.
1
/*
2
* Little-endian CRC32 implementation.
3
*
4
* Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation; either version 2 of the
9
* License, or any later version.
10
*
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
* 02110-1301, USA.
20
*/
21
22
FILE_LICENCE
( GPL2_OR_LATER );
23
FILE_SECBOOT
( PERMITTED );
24
25
#include <
ipxe/crc32.h
>
26
27
#define CRCPOLY 0xedb88320
28
29
/**
30
* Calculate 32-bit little-endian CRC checksum
31
*
32
* @v seed Initial value
33
* @v data Data to checksum
34
* @v len Length of data
35
*
36
* Usually @a seed is initially zero or all one bits, depending on the
37
* protocol. To continue a CRC checksum over multiple calls, pass the
38
* return value from one call as the @a seed parameter to the next.
39
*/
40
u32
crc32_le
(
u32
seed,
const
void
*
data
,
size_t
len
)
41
{
42
u32
crc = seed;
43
const
u8
*
src
=
data
;
44
u32
mult;
45
int
i;
46
47
while
(
len
-- ) {
48
crc ^= *
src
++;
49
for
( i = 0; i < 8; i++ ) {
50
mult = ( crc & 1 ) ?
CRCPOLY
: 0;
51
crc = ( crc >> 1 ) ^ mult;
52
}
53
}
54
55
return
crc;
56
}
FILE_LICENCE
FILE_LICENCE(GPL2_OR_LATER)
crc32.h
crc32_le
u32 crc32_le(u32 seed, const void *data, size_t len)
Calculate 32-bit little-endian CRC checksum.
Definition:
crc32.c:40
src
static const void * src
Definition:
string.h:48
len
ring len
Length.
Definition:
dwmac.h:231
FILE_SECBOOT
FILE_SECBOOT(PERMITTED)
CRCPOLY
#define CRCPOLY
Definition:
crc32.c:27
data
uint8_t data[48]
Additional event data.
Definition:
ena.h:22
u8
uint8_t u8
Definition:
stdint.h:20
u32
uint32_t u32
Definition:
stdint.h:24
Generated by
1.8.15