diff options
| author | J08nY | 2020-12-10 17:48:51 +0100 |
|---|---|---|
| committer | J08nY | 2020-12-10 18:14:26 +0100 |
| commit | 3e78a690cf7f44293556dd5a5a3ef591390c6b93 (patch) | |
| tree | ff6b1266f02f1220992cf61a9880eeab8f5a7b53 | |
| parent | c952dcb9b0f463c4a407d26a30a07b26779610b2 (diff) | |
| download | pyecsca-3e78a690cf7f44293556dd5a5a3ef591390c6b93.tar.gz pyecsca-3e78a690cf7f44293556dd5a5a3ef591390c6b93.tar.zst pyecsca-3e78a690cf7f44293556dd5a5a3ef591390c6b93.zip | |
Add testing of GMP and non-GMP into Travis.
| -rw-r--r-- | .travis.yml | 26 | ||||
| -rw-r--r-- | test/ec/test_mod.py | 13 | ||||
| -rw-r--r-- | test/sca/test_test.py | 2 |
3 files changed, 33 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml index 8b9e4ad..f57f665 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ os: linux language: python dist: focal -python: - - "3.8" - - "3.9" addons: apt: @@ -24,8 +21,24 @@ addons: - libllvm10 - llvm-10-dev -env: - - LLVM_CONFIG=/usr/bin/llvm-config-10 +jobs: + include: + - env: + - USE_GMP=1 + - LLVM_CONFIG=/usr/bin/llvm-config-10 + python: "3.9" + - env: + - USE_GMP=0 + - LLVM_CONFIG=/usr/bin/llvm-config-10 + python: "3.9" + - env: + - USE_GMP=1 + - LLVM_CONFIG=/usr/bin/llvm-config-10 + python: "3.8" + - env: + - USE_GMP=0 + - LLVM_CONFIG=/usr/bin/llvm-config-10 + python: "3.8" before_install: - git clone https://github.com/colinoflynn/pico-python @@ -39,7 +52,8 @@ before_install: install: - pip install codecov - - pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, test, dev]" + - if [ $USE_GMP == 1 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, gmp, test, dev]"; fi + - if [ $USE_GMP == 0 ]; then pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, test, dev]"; fi script: - make -i typecheck diff --git a/test/ec/test_mod.py b/test/ec/test_mod.py index b653705..3a14c91 100644 --- a/test/ec/test_mod.py +++ b/test/ec/test_mod.py @@ -1,6 +1,6 @@ from unittest import TestCase -from pyecsca.ec.mod import Mod, gcd, extgcd, Undefined, miller_rabin +from pyecsca.ec.mod import Mod, gcd, extgcd, Undefined, miller_rabin, NonResidueError, NonInvertibleError class ModTests(TestCase): @@ -18,6 +18,14 @@ class ModTests(TestCase): self.assertTrue(miller_rabin(0xe807561107ccf8fa82af74fd492543a918ca2e9c13750233a9)) self.assertFalse(miller_rabin(0x6f6889deb08da211927370810f026eb4c17b17755f72ea005)) + def test_inverse(self): + p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff + self.assertEqual(Mod(0x702bdafd3c1c837b23a1cb196ed7f9fadb333c5cfe4a462be32adcd67bfb6ac1, p).inverse(), Mod(0x1cb2e5274bba085c4ca88eede75ae77949e7a410c80368376e97ab22eb590f9d, p)) + with self.assertRaises(NonInvertibleError): + Mod(0, p).inverse() + with self.assertRaises(NonInvertibleError): + Mod(5, 10).inverse() + def test_is_residue(self): self.assertTrue(Mod(4, 11).is_residue()) self.assertFalse(Mod(11, 31).is_residue()) @@ -27,6 +35,9 @@ class ModTests(TestCase): def test_sqrt(self): p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff self.assertIn(Mod(0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc, p).sqrt(), (0x9add512515b70d9ec471151c1dec46625cd18b37bde7ca7fb2c8b31d7033599d, 0x6522aed9ea48f2623b8eeae3e213b99da32e74c9421835804d374ce28fcca662)) + with self.assertRaises(NonResidueError): + Mod(0x702bdafd3c1c837b23a1cb196ed7f9fadb333c5cfe4a462be32adcd67bfb6ac1, p).sqrt() + self.assertEqual(Mod(0, p).sqrt(), Mod(0, p)) q = 0x75d44fee9a71841ae8403c0c251fbad self.assertIn(Mod(0x591e0db18cf1bd81a11b2985a821eb3, q).sqrt(), (0x113b41a1a2b73f636e73be3f9a3716e, 0x64990e4cf7ba44b779cc7dcc8ae8a3f)) diff --git a/test/sca/test_test.py b/test/sca/test_test.py index e2b3969..5a20f70 100644 --- a/test/sca/test_test.py +++ b/test/sca/test_test.py @@ -19,7 +19,7 @@ class TTestTests(TestCase): b = Trace(np.array([28.2, 26.6, 20.1, 23.3, 25.2, 22.1, 17.7, 27.6, 20.6, 13.7])) c = Trace(np.array([20.2, 21.6, 27.1, 13.3, 24.2, 20.1, 11.7, 25.6, 26.6, 21.4])) - result = welch_ttest([a, b], [b, c]) + result = welch_ttest([a, b], [b, c], dof=True, p_value=True) self.assertIsNotNone(result) def test_students_ttest(self): |
