SDRAngel
4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
sdrbase
util
CRC64.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
3
// //
4
// This program is free software; you can redistribute it and/or modify //
5
// it under the terms of the GNU General Public License as published by //
6
// the Free Software Foundation as version 3 of the License, or //
7
// (at your option) any later version. //
8
// //
9
// This program is distributed in the hope that it will be useful, //
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12
// GNU General Public License V3 for more details. //
13
// //
14
// You should have received a copy of the GNU General Public License //
15
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
17
18
#include "
util/CRC64.h
"
19
38
const
uint64_t
CRC64::m_poly
= 0xC96C5795D7870F42ull;
39
40
CRC64::CRC64
()
41
{
42
build_crc_table
();
43
}
44
45
CRC64::~CRC64
()
46
{}
47
59
void
CRC64::build_crc_table
()
60
{
61
for
(
int
i
= 0;
i
< 256; ++
i
)
62
{
63
uint64_t
crc =
i
;
64
65
for
(
unsigned
int
j = 0; j < 8; ++j)
66
{
67
if
(crc & 1)
// is current coefficient set?
68
{
69
crc >>= 1;
// yes, then assume it gets zero'd (by implied x^64 coefficient of dividend)
70
crc ^=
m_poly
;
// and add rest of the divisor
71
}
72
else
// no? then move to next coefficient
73
{
74
crc >>= 1;
75
}
76
}
77
78
m_crcTable
[
i
] = crc;
79
}
80
}
81
144
uint64_t
CRC64::calculate_crc
(
uint8_t
*stream,
int
length)
145
{
146
uint64_t
crc = 0;
147
148
for
(
int
i
= 0 ;
i
< length; ++
i
)
149
{
150
uint8_t
index = stream[
i
] ^ crc;
151
uint64_t
lookup =
m_crcTable
[index];
152
153
crc >>= 8;
154
crc ^= lookup;
155
}
156
157
return
crc;
158
}
159
160
CRC64::m_poly
static const uint64_t m_poly
Definition:
CRC64.h:36
CRC64::m_crcTable
uint64_t m_crcTable[256]
Definition:
CRC64.h:35
CRC64::CRC64
CRC64()
Definition:
CRC64.cpp:40
uint8_t
unsigned char uint8_t
Definition:
rtptypes_win.h:42
i
int32_t i
Definition:
decimators.h:244
CRC64::calculate_crc
uint64_t calculate_crc(uint8_t *stream, int length)
Definition:
CRC64.cpp:144
CRC64::~CRC64
~CRC64()
Definition:
CRC64.cpp:45
CRC64.h
CRC64::build_crc_table
void build_crc_table()
Definition:
CRC64.cpp:59
uint64_t
unsigned __int64 uint64_t
Definition:
rtptypes_win.h:48
Generated on Fri Aug 2 2019 17:56:33 for SDRAngel by
1.8.13