aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2020-02-13 17:52:12 +0100
committerJ08nY2020-02-13 18:29:24 +0100
commiteef8b99dad6f43d97d9194a1a6f16bc5e2ef66b0 (patch)
tree8748dc624cc8047b9f1410b65ac0e6acf7df08eb
parentac0f153698adc4dfde4c8066d6052b916878f14a (diff)
downloadpyecsca-eef8b99dad6f43d97d9194a1a6f16bc5e2ef66b0.tar.gz
pyecsca-eef8b99dad6f43d97d9194a1a6f16bc5e2ef66b0.tar.bz2
pyecsca-eef8b99dad6f43d97d9194a1a6f16bc5e2ef66b0.zip
Add notebooks, fix Travis.
-rw-r--r--README.md5
-rw-r--r--docs/conf.py11
-rw-r--r--docs/index.rst15
m---------notebook0
-rw-r--r--pyecsca/ec/configuration.py26
-rw-r--r--pyecsca/ec/coordinates.py1
-rw-r--r--pyecsca/ec/model.py1
-rw-r--r--test/ec/test_configuration.py41
-rw-r--r--test/ec/utils.py3
-rw-r--r--test/sca/test_align.py2
10 files changed, 80 insertions, 25 deletions
diff --git a/README.md b/README.md
index 20abe8d..a93bb41 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,11 @@
# ![](docs/_static/logo_black_small.png) pyecsca [pɪɛtska]
-[![Build Status](https://travis-ci.org/J08nY/pyecsca.svg?branch=master)](https://travis-ci.org/J08nY/pyecsca) [![docs](https://img.shields.io/badge/docs-neuromancer.sk-brightgreen.svg)](https://neuromancer.sk/pyecsca/) ![License: MIT](https://img.shields.io/github/license/J08nY/pyecsca.svg) [![codecov](https://codecov.io/gh/J08nY/pyecsca/branch/master/graph/badge.svg)](https://codecov.io/gh/J08nY/pyecsca)
+[![Build Status](https://travis-ci.com/J08nY/pyecsca.svg?branch=master)](https://travis-ci.com/J08nY/pyecsca) [![docs](https://img.shields.io/badge/docs-neuromancer.sk-brightgreen.svg)](https://neuromancer.sk/pyecsca/) ![License: MIT](https://img.shields.io/github/license/J08nY/pyecsca.svg) [![codecov](https://codecov.io/gh/J08nY/pyecsca/branch/master/graph/badge.svg)](https://codecov.io/gh/J08nY/pyecsca)
**Py**thon **E**lliptic **C**urve cryptography **S**ide-**C**hannel **A**nalysis toolkit.
+For more info, see the [![docs](https://img.shields.io/badge/docs-neuromancer.sk-brightgreen.svg)](https://neuromancer.sk/pyecsca/).
+
## Functionality
*pyecsca* aims to fill a gap in SCA tooling for Elliptic Curve Cryptography, it focuses on
@@ -42,6 +44,7 @@ It also supports working with [Riscure](https://www.riscure.com) Inspector trace
- [sphinx](https://www.sphinx-doc.org/)
- [sphinx-autodoc-typehints](https://pypi.org/project/sphinx-autodoc-typehints/)
+ - [nbsphinx](https://nbsphinx.readthedocs.io/)
## License
diff --git a/docs/conf.py b/docs/conf.py
index 2b1ee9c..f84364b 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -12,15 +12,15 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
-# import os
-# import sys
-# sys.path.insert(0, os.path.abspath('.'))
+import os
+import sys
+sys.path.insert(0, os.path.abspath('../notebook/'))
# -- Project information -----------------------------------------------------
project = 'pyecsca'
-copyright = '2018-2019, Jan Jancar'
+copyright = '2018-2020, Jan Jancar'
author = 'Jan Jancar'
import sys; import os; sys.path.append(os.path.abspath('..'))
@@ -46,6 +46,7 @@ extensions = [
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
+ 'nbsphinx'
]
# Add any paths that contain templates here, relative to this directory.
@@ -70,7 +71,7 @@ language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
-exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '**.ipynb_checkpoints']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "trac"
diff --git a/docs/index.rst b/docs/index.rst
index 49bab42..d2e96f4 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -5,7 +5,7 @@ pyecsca [pɪɛtska]
.. image:: https://img.shields.io/badge/-Github-brightgreen?style=flat&logo=github
:target: https://github.com/J08nY/pyecsca
.. image:: https://img.shields.io/travis/J08nY/pyecsca
- :target: https://travis-ci.org/J08nY/pyecsca
+ :target: https://travis-ci.com/J08nY/pyecsca
.. image:: https://img.shields.io/github/license/J08nY/pyecsca.svg
:target: https://github.com/J08nY/pyecsca/blob/master/LICENSE
.. image:: https://codecov.io/gh/J08nY/pyecsca/branch/master/graph/badge.svg
@@ -29,6 +29,15 @@ API
api/modules
+Notebooks
+=========
+
+.. toctree::
+ :titlesonly:
+ :maxdepth: 3
+
+ notebook/configuration_space
+
Requirements
============
@@ -56,7 +65,7 @@ Testing
- nose2_
- green_
- mypy_
- - flake8
+ - flake8_
- coverage_
Docs
@@ -64,6 +73,7 @@ Docs
- sphinx_
- sphinx-autodoc-typehints_
+ - nbsphinx_
License
=======
@@ -109,5 +119,6 @@ this support is very appreciated.
.. _coverage: https://coverage.readthedocs.io/
.. _sphinx: https://www.sphinx-doc.org/
.. _sphinx-autodoc-typehints: https://pypi.org/project/sphinx-autodoc-typehints/
+.. _nbsphinx: https://nbsphinx.readthedocs.io/
.. _Explicit-Formulas Database: https://www.hyperelliptic.org/EFD/index.html
.. _Riscure: https://www.riscure.com/
diff --git a/notebook b/notebook
-Subproject 7118e5c28ba9ac5375bb0043684fae786d9c56e
+Subproject ddbc1b6d5cc5d5275b623b7f7315828ddf340c8
diff --git a/pyecsca/ec/configuration.py b/pyecsca/ec/configuration.py
index 25bd4f9..0fd6976 100644
--- a/pyecsca/ec/configuration.py
+++ b/pyecsca/ec/configuration.py
@@ -23,6 +23,10 @@ class EnumDefine(Enum):
def names(cls):
return list(e.name for e in cls)
+ @classmethod
+ def values(cls):
+ return list(e.value for e in cls)
+
@public
class Multiplication(EnumDefine):
@@ -71,7 +75,7 @@ class RandomMod(EnumDefine):
@public
@dataclass(frozen=True)
class Configuration(object):
- """An ECC implementation."""
+ """An ECC implementation configuration."""
model: CurveModel
coords: CoordinateModel
formulas: Set[Formula]
@@ -85,6 +89,24 @@ class Configuration(object):
@public
def all_configurations(**kwargs) -> Generator[Configuration, Configuration, None]:
+ """
+ Get all implementation configurations that match the given `kwargs`.
+ The keys in `kwargs` should be some of the attributes in the :py:class:`Configuration`,
+ and the values limit the returned configurations to configuration matching them.
+
+ .. note::
+ The `formulas` attribute is unsupported and formulas should be provided using the `scalarmult`
+ attribute, which is either a subclass of the :py:class:`ScalarMultiplier` class or an instance
+ of it or a dictionary giving arguments to a constructor of some :py:class:`ScalarMultiplier`
+ subclass.
+
+ .. warning::
+ The returned number of configurations might be quite large and take up significant
+ memory space.
+
+ :param kwargs: The configuration parameters to match.
+ :return: A generator of the configurations
+ """
def is_optional(arg_type):
return get_origin(arg_type) == Union and len(get_args(arg_type)) == 2 and \
get_args(arg_type)[1] == type(None)
@@ -163,6 +185,8 @@ def all_configurations(**kwargs) -> Generator[Configuration, Configuration, None
if "scalarmult" in kwargs:
if isinstance(kwargs["scalarmult"], ScalarMultiplier):
mults = [kwargs["scalarmult"]]
+ if not set(kwargs["scalarmult"].formulas.values()).issubset(coords_formulas):
+ continue
elif isinstance(kwargs["scalarmult"], type) and issubclass(kwargs["scalarmult"],
ScalarMultiplier):
mult_classes = list(
diff --git a/pyecsca/ec/coordinates.py b/pyecsca/ec/coordinates.py
index 922cbcb..9043e76 100644
--- a/pyecsca/ec/coordinates.py
+++ b/pyecsca/ec/coordinates.py
@@ -13,6 +13,7 @@ from .formula import (Formula, EFDFormula, AdditionEFDFormula, DoublingEFDFormul
@public
class CoordinateModel(object):
+ """A coordinate system for a particular model(form) of an elliptic curve."""
name: str
full_name: str
curve_model: Any
diff --git a/pyecsca/ec/model.py b/pyecsca/ec/model.py
index dba083e..08ba70e 100644
--- a/pyecsca/ec/model.py
+++ b/pyecsca/ec/model.py
@@ -8,6 +8,7 @@ from .coordinates import EFDCoordinateModel, CoordinateModel
class CurveModel(object):
+ """A model(form) of an elliptic curve."""
name: str
coordinates: MutableMapping[str, CoordinateModel]
parameter_names: List[str]
diff --git a/test/ec/test_configuration.py b/test/ec/test_configuration.py
index 560074b..e184ca3 100644
--- a/test/ec/test_configuration.py
+++ b/test/ec/test_configuration.py
@@ -4,11 +4,20 @@ from pyecsca.ec.configuration import (all_configurations, HashType, RandomMod, M
Squaring, Reduction)
from pyecsca.ec.model import ShortWeierstrassModel
from pyecsca.ec.mult import LTRMultiplier
-from test.sca.utils import slow
+from .utils import slow
class ConfigurationTests(TestCase):
+ def base_independents(self):
+ return {
+ "hash_type": HashType.SHA1,
+ "mod_rand": RandomMod.SAMPLE,
+ "mult": Multiplication.BASE,
+ "sqr": Squaring.BASE,
+ "red": Reduction.BASE
+ }
+
@slow
def test_all(self):
j = 0
@@ -16,18 +25,18 @@ class ConfigurationTests(TestCase):
j += 1
print(j)
+ def test_weierstrass_projective(self):
+ model = ShortWeierstrassModel()
+ coords = model.coordinates["projective"]
+ configs = list(all_configurations(model=model, coords=coords, **self.base_independents()))
+ self.assertEqual(len(configs), 1344)
+
def test_mult_class(self):
model = ShortWeierstrassModel()
coords = model.coordinates["projective"]
scalarmult = LTRMultiplier
- hash_type = HashType.SHA1
- mod_rand = RandomMod.SAMPLE
- mult = Multiplication.BASE
- sqr = Squaring.BASE
- red = Reduction.BASE
configs = list(all_configurations(model=model, coords=coords, scalarmult=scalarmult,
- hash_type=hash_type, mod_rand=mod_rand, mult=mult,
- sqr=sqr, red=red))
+ **self.base_independents()))
self.assertEqual(len(configs), 384)
def test_one(self):
@@ -42,12 +51,14 @@ class ConfigurationTests(TestCase):
"complete": False,
"short_circuit": True
}
- hash_type = HashType.SHA1
- mod_rand = RandomMod.SAMPLE
- mult = Multiplication.BASE
- sqr = Squaring.BASE
- red = Reduction.BASE
configs = list(all_configurations(model=model, coords=coords, scalarmult=scalarmult,
- hash_type=hash_type, mod_rand=mod_rand, mult=mult,
- sqr=sqr, red=red))
+ **self.base_independents()))
+ self.assertEqual(len(configs), 1)
+ scalarmult = LTRMultiplier(coords.formulas["add-1998-cmo"], coords.formulas["dbl-1998-cmo"],
+ None, True, False, True)
+ configs = list(all_configurations(model=model, coords=coords, scalarmult=scalarmult,
+ **self.base_independents()))
+ self.assertEqual(len(configs), 1)
+ configs = list(all_configurations(model=model, scalarmult=scalarmult,
+ **self.base_independents()))
self.assertEqual(len(configs), 1)
diff --git a/test/ec/utils.py b/test/ec/utils.py
new file mode 100644
index 0000000..bedfed2
--- /dev/null
+++ b/test/ec/utils.py
@@ -0,0 +1,3 @@
+def slow(func):
+ func.slow = 1
+ return func
diff --git a/test/sca/test_align.py b/test/sca/test_align.py
index 3e64334..57f7119 100644
--- a/test/sca/test_align.py
+++ b/test/sca/test_align.py
@@ -3,7 +3,7 @@ from unittest import TestCase
import numpy as np
from pyecsca.sca import align_correlation, align_peaks, align_sad, align_dtw_scale,\
align_dtw, Trace, InspectorTraceSet
-from .utils import slow, plot
+from .utils import plot, slow
class AlignTests(TestCase):