Returns the product of the two given field elements modulo GF(2^8/0x11D). All inputs are valid. This could be implemented as a 256*256 lookup table.
| 306 | // Returns the product of the two given field elements modulo GF(2^8/0x11D). |
| 307 | // All inputs are valid. This could be implemented as a 256*256 lookup table. |
| 308 | testable uint8_t finiteFieldMultiply(uint8_t x, uint8_t y) { |
| 309 | // Russian peasant multiplication |
| 310 | uint8_t z = 0; |
| 311 | for (int i = 7; i >= 0; i--) { |
| 312 | z = (z << 1) ^ ((z >> 7) * 0x11D); |
| 313 | z ^= ((y >> i) & 1) * x; |
| 314 | } |
| 315 | return z; |
| 316 | } |
| 317 | |
| 318 | |
| 319 |
no outgoing calls
no test coverage detected