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

Function calcReedSolomonGenerator

modules/data/qrcode/qrcodegen.c:266–285  ·  view source on GitHub ↗

Calculates the Reed-Solomon generator polynomial of the given degree, storing in result[0 : degree].

Source from the content-addressed store, hash-verified

264
265// Calculates the Reed-Solomon generator polynomial of the given degree, storing in result[0 : degree].
266testable void calcReedSolomonGenerator(int degree, uint8_t result[]) {
267 // Start with the monomial x^0
268 assert(1 <= degree && degree <= 30);
269 memset(result, 0, degree * sizeof(result[0]));
270 result[degree - 1] = 1;
271
272 // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
273 // drop the highest term, and store the rest of the coefficients in order of descending powers.
274 // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
275 uint8_t root = 1;
276 for (int i = 0; i < degree; i++) {
277 // Multiply the current product by (x - r^i)
278 for (int j = 0; j < degree; j++) {
279 result[j] = finiteFieldMultiply(result[j], root);
280 if (j + 1 < degree)
281 result[j] ^= result[j + 1];
282 }
283 root = finiteFieldMultiply(root, 0x02);
284 }
285}
286
287
288// Calculates the remainder of the polynomial data[0 : dataLen] when divided by the generator[0 : degree], where all

Callers 1

appendErrorCorrectionFunction · 0.85

Calls 2

finiteFieldMultiplyFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected