Compute y + y^2 + y^4 + ... + y^(2^(field_size-1)) mod poly, where y = param*x.
(poly, param, gf)
| 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.""" |
| 240 | out = [0, param] |
| 241 | for _ in range(gf.field_size - 1): |
| 242 | # In each loop iteration i, we start with out = y + y^2 + ... + y^(2^i). By squaring that we |
| 243 | # transform it into out = y^2 + y^4 + ... + y^(2^(i+1)). |
| 244 | out = poly_sqr(out, gf) |
| 245 | # Thus, we just need to add y again to it to get out = y + ... + y^(2^(i+1)). |
| 246 | while len(out) < 2: |
| 247 | out.append(0) |
| 248 | out[1] = param |
| 249 | # Finally take a modulus to keep the intermediary polynomials small. |
| 250 | _, out = poly_divmod(out, poly, gf) |
| 251 | return out |
| 252 | |
| 253 | def poly_frobeniusmod(poly, gf): |
| 254 | """Compute x^(2^field_size) mod poly.""" |
no test coverage detected