# HG changeset patch # User Laman # Date 2020-12-18 12:07:10 # Node ID c6815615a077f82201ca6311f859b4059b8915d8 # Parent 8cbbc92dd17c248d7d3ccc6bc02d7d1cfa6be586 gfmul caching diff --git a/src/shamira/gf256.py b/src/shamira/gf256.py --- a/src/shamira/gf256.py +++ b/src/shamira/gf256.py @@ -2,7 +2,7 @@ """Arithmetic operations on Galois Field 2**8. See https://en.wikipedia.org/wiki/Finite_field_arithmetic""" -from functools import reduce +from functools import reduce, cache import operator @@ -29,6 +29,7 @@ L[1] = 0 INV = [E[255-L[i]] if i!=0 else None for i in range(256)] # multiplicative inverse +@cache def gfmul(a, b): """Fast multiplication. Basic multiplication is expensive. a*b==g**(log(a)+log(b))""" assert 0<=a<=255, 0<=b<=255