| 581 | } |
| 582 | |
| 583 | static void rs_init(uint8_t degree, uint8_t *coeff) { |
| 584 | memset(coeff, 0, degree); |
| 585 | coeff[degree - 1] = 1; |
| 586 | |
| 587 | // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), |
| 588 | // drop the highest term, and store the rest of the coefficients in order of descending powers. |
| 589 | // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D). |
| 590 | uint16_t root = 1; |
| 591 | for (uint8_t i = 0; i < degree; i++) { |
| 592 | // Multiply the current product by (x - r^i) |
| 593 | for (uint8_t j = 0; j < degree; j++) { |
| 594 | coeff[j] = rs_multiply(coeff[j], root); |
| 595 | if (j + 1 < degree) { |
| 596 | coeff[j] ^= coeff[j + 1]; |
| 597 | } |
| 598 | } |
| 599 | root = (root << 1) ^ ((root >> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D) |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | static void rs_getRemainder(uint8_t degree, uint8_t *coeff, uint8_t *data, uint8_t length, uint8_t *result, uint8_t stride) { |
| 604 | // Compute the remainder by performing polynomial division |
no test coverage detected