mhostetter / galois

A performant NumPy extension for Galois fields and their applications
https://mhostetter.github.io/galois/
MIT License
295 stars 27 forks source link

Binary operations can move values outside of valid bounds #509

Open mhostetter opened 9 months ago

mhostetter commented 9 months ago
import numpy as np

import galois

x = galois.GF2([1, 0, 1])
print(x)

x = np.left_shift(x, 1)
print(x)
$ python3 test_left_shift.py 
[1 0 1]
[2 0 2]  # Should error
mhostetter commented 9 months ago
import numpy as np

import galois

x = galois.GF2([1, 0, 1])
print(x)

x = np.bitwise_or(x, 0b10)
print(x)
$ python3 test_bitwise_or.py
[1 0 1]
[3 2 3]  # Should error
mhostetter commented 9 months ago

Maybe use _view() instead of _view_without_verification() for operations that could expand the bit depth.