Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect is_primitive_poly attribute of "large" finite fields #188

Closed
mhostetter opened this issue Oct 18, 2021 · 1 comment
Closed

Incorrect is_primitive_poly attribute of "large" finite fields #188

mhostetter opened this issue Oct 18, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@mhostetter
Copy link
Owner

As discovered in #185, the is_primitive_poly attribute of GF(2^256) isn't correct. It says False, however the specified polynomial is primitive (according to a Google search... can't currently test with galois due to #187).

In [1]: import galois                                                                                                                        

In [2]: GF = galois.GF(2**256, irreducible_poly="x^256 + x^241 + x^178 + x^121 + 1", primitive_element="x", verify=False)                    

In [3]: print(GF.properties)                                                                                                                 
GF(2^256):
  characteristic: 2
  degree: 256
  order: 115792089237316195423570985008687907853269984665640564039457584007913129639936
  irreducible_poly: x^256 + x^241 + x^178 + x^121 + 1
  is_primitive_poly: False
  primitive_element: x

In [4]: poly = GF.irreducible_poly; poly                                                                                                     
Out[4]: Poly(x^256 + x^241 + x^178 + x^121 + 1, GF(2))

In [5]: alpha = GF.primitive_element; alpha                                                                                                  
Out[5]: GF(2, order=2^256)

# The polynomial is primitive because poly(alpha) = 0
In [6]: poly(alpha, field=GF)                                                                                                                
Out[6]: GF(0, order=2^256)

The issue is here. Upon manually debugging those lines, the polynomial evaluation was 1 and not 0, which lead the equality to be False. Likely there is an issue/bug in _function_python().

# Determine if the irreducible polynomial is primitive
if cls._is_primitive_poly is None:
# TODO: Clean this up
coeffs = cls.irreducible_poly.coeffs.view(np.ndarray)
x = np.array(cls.primitive_element, dtype=cls.dtypes[-1], ndmin=1)
add = cls._func_python("add")
multiply = cls._func_python("multiply")
cls._is_primitive_poly = cls._function_python("poly_evaluate")(coeffs, x, add, multiply, cls.characteristic, cls.degree, cls._irreducible_poly_int)[0] == 0

@mhostetter mhostetter self-assigned this Oct 18, 2021
@mhostetter mhostetter added the bug Something isn't working label Oct 18, 2021
@mhostetter
Copy link
Owner Author

After #189, the above runs as:

In [1]: import galois                                                                                                                                    

In [2]: GF = galois.GF(2**256, irreducible_poly="x^256 + x^241 + x^178 + x^121 + 1", primitive_element="x", verify=False)                                

In [3]: print(GF.properties)                                                                                                                             
GF(2^256):
  characteristic: 2
  degree: 256
  order: 115792089237316195423570985008687907853269984665640564039457584007913129639936
  irreducible_poly: x^256 + x^241 + x^178 + x^121 + 1
  is_primitive_poly: True
  primitive_element: x

mhostetter added a commit that referenced this issue Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant