MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / calcReedSolomonRemainder

Function calcReedSolomonRemainder

modules/data/qrcode/qrcodegen.c:290–303  ·  view source on GitHub ↗

Calculates the remainder of the polynomial data[0 : dataLen] when divided by the generator[0 : degree], where all polynomials are in big endian and the generator has an implicit leading 1 term, storing the result in result[0 : degree].

Source from the content-addressed store, hash-verified

288// Calculates the remainder of the polynomial data[0 : dataLen] when divided by the generator[0 : degree], where all
289// polynomials are in big endian and the generator has an implicit leading 1 term, storing the result in result[0 : degree].
290testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen,
291 const uint8_t generator[], int degree, uint8_t result[]) {
292
293 // Perform polynomial division
294 assert(1 <= degree && degree <= 30);
295 memset(result, 0, degree * sizeof(result[0]));
296 for (int i = 0; i < dataLen; i++) {
297 uint8_t factor = data[i] ^ result[0];
298 c_memmove(&result[0], &result[1], (degree - 1) * sizeof(result[0]));
299 result[degree - 1] = 0;
300 for (int j = 0; j < degree; j++)
301 result[j] ^= finiteFieldMultiply(generator[j], factor);
302 }
303}
304
305
306// Returns the product of the two given field elements modulo GF(2^8/0x11D).

Callers 1

appendErrorCorrectionFunction · 0.85

Calls 2

finiteFieldMultiplyFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected