Return the square of polynomial poly.
(poly, gf)
| 226 | return a |
| 227 | |
| 228 | def poly_sqr(poly, gf): |
| 229 | """Return the square of polynomial poly.""" |
| 230 | if len(poly) == 0: |
| 231 | return [] |
| 232 | # In characteristic-2 fields, thanks to Frobenius' endomorphism ((a + b)^2 = a^2 + b^2), |
| 233 | # squaring a polynomial is easy: square all the coefficients and interleave with zeroes. |
| 234 | # E.g., (3 + 5*x + 17*x^2)^2 = 3^2 + (5*x)^2 + (17*x^2)^2. |
| 235 | # See https://en.wikipedia.org/wiki/Frobenius_endomorphism. |
| 236 | return [0 if i & 1 else gf.sqr(poly[i // 2]) for i in range(2 * len(poly) - 1)] |
| 237 | |
| 238 | def poly_tracemod(poly, param, gf): |
| 239 | """Compute y + y^2 + y^4 + ... + y^(2^(field_size-1)) mod poly, where y = param*x.""" |
no test coverage detected