MCPcopy Create free account
hub / github.com/ElementsProject/elements / poly_sqr

Function poly_sqr

src/minisketch/tests/pyminisketch.py:228–236  ·  view source on GitHub ↗

Return the square of polynomial poly.

(poly, gf)

Source from the content-addressed store, hash-verified

226 return a
227
228def 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
238def poly_tracemod(poly, param, gf):
239 """Compute y + y^2 + y^4 + ... + y^(2^(field_size-1)) mod poly, where y = param*x."""

Callers 2

poly_tracemodFunction · 0.85
poly_frobeniusmodFunction · 0.85

Calls 1

sqrMethod · 0.80

Tested by

no test coverage detected