djiparsetxt
Functions | Variables
scrambleBytes.cpp File Reference
#include "scrambleBytes.hh"
Include dependency graph for scrambleBytes.cpp:

Go to the source code of this file.

Functions

static u_int64_t crc64 (u_int8_t seed, u_int8_t const *buffer, unsigned bufferSize)
 
void getScrambleBytes (u_int8_t recordType, u_int8_t keyByte, u_int8_t *resultScrambleBytes)
 

Variables

static u_int64_t crc64Table [256]
 

Function Documentation

◆ crc64()

static u_int64_t crc64 ( u_int8_t  seed,
u_int8_t const *  buffer,
unsigned  bufferSize 
)
static

Definition at line 116 of file scrambleBytes.cpp.

116  {
117  u_int64_t crc = seed;
118 
119  for (unsigned i = 0; i < bufferSize; ++i) {
120  u_int8_t tabIndex = buffer[i] ^ crc;
121  crc = crc64Table[tabIndex] ^ (crc >> 8);
122  }
123 
124  return crc;
125 }
static u_int64_t crc64Table[256]

References crc64Table.

Referenced by getScrambleBytes().

◆ getScrambleBytes()

void getScrambleBytes ( u_int8_t  recordType,
u_int8_t  keyByte,
u_int8_t *  resultScrambleBytes 
)

Definition at line 127 of file scrambleBytes.cpp.

128  {
129  // Set up the (8-byte) buffer to compute the CRC over:
130  u_int64_t dataForBuffer = 0x123456789ABCDEF0*keyByte;
131  u_int8_t bufferToCRC[8];
132  // Fill in the buffer in little-endian order:
133  for (int i = 0; i < sizeof bufferToCRC; ++i) {
134  bufferToCRC[i] = dataForBuffer; // low 8 bits
135  dataForBuffer >>= 8;
136  }
137 
138  // Compute a CRC over this buffer, using our "recordType" and "keyByte" parameters as salt:
139  u_int64_t crcResult = crc64(recordType + keyByte, bufferToCRC, sizeof bufferToCRC);
140 
141  // Unpack this into "resultScrambleBytes", in little-endian order:
142  for (unsigned i = 0; i < 8; ++i) {
143  resultScrambleBytes[i] = crcResult; // low 8 bits
144  crcResult >>= 8;
145  }
146 }
static u_int64_t crc64(u_int8_t seed, u_int8_t const *buffer, unsigned bufferSize)

References crc64().

Referenced by RecordAndDetailsParser::parseRecord().

Here is the caller graph for this function:

Variable Documentation

◆ crc64Table

u_int64_t crc64Table[256]
static

Definition at line 28 of file scrambleBytes.cpp.

Referenced by crc64().