aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2021-01-22 17:02:25 +0100
committerJ08nY2021-01-23 01:15:27 +0100
commit28546dad01a25ce101d6b49924f521c2ef5ffa98 (patch)
treef8eea4a4cc079ba830a27a2ce239aef451ed6597
parent31d72722ad94d4fbcf7c484137730f54bd6a4138 (diff)
downloadpyecsca-28546dad01a25ce101d6b49924f521c2ef5ffa98.tar.gz
pyecsca-28546dad01a25ce101d6b49924f521c2ef5ffa98.tar.zst
pyecsca-28546dad01a25ce101d6b49924f521c2ef5ffa98.zip
Add Test and Lint GitHub action.
-rw-r--r--.github/workflows/lint.yml52
-rw-r--r--.github/workflows/test.yml63
-rw-r--r--Makefile2
-rw-r--r--README.md2
-rw-r--r--docs/index.rst6
-rw-r--r--pyecsca/sca/scope/picoscope_sdk.py4
-rw-r--r--pyecsca/sca/trace/process.py8
-rw-r--r--pyecsca/sca/trace/sampling.py8
8 files changed, 133 insertions, 12 deletions
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
new file mode 100644
index 0000000..ae3693e
--- /dev/null
+++ b/.github/workflows/lint.yml
@@ -0,0 +1,52 @@
+name: Lint
+
+on: [push, pull_request]
+
+env:
+ LLVM_CONFIG: /usr/bin/llvm-config-10
+ PS_PACKAGES: libps4000 libps5000 libps6000
+ GMP_PACKAGES: libgmp-dev libmpfr-dev libmpc-dev
+ OTHER_PACKAGES: swig gcc libpcsclite-dev llvm-10 libllvm10 llvm-10-dev
+
+jobs:
+ lint:
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: true
+ - uses: actions/cache@v2
+ with:
+ path: ~/.cache/pip
+ key: pip-${{ runner.os }}-${{ hashFiles('setup.py') }}
+ restore-keys: |
+ pip-${{ runner.os }}-
+ - name: Setup Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.9
+ - name: Add picoscope repository
+ run: |
+ curl "https://labs.picotech.com/debian/dists/picoscope/Release.gpg.key" | sudo apt-key add
+ sudo echo "deb https://labs.picotech.com/debian/ picoscope main" | sudo tee /etc/apt/sources.list.d/picoscope.list
+ sudo apt-get update
+ - name: Install system dependencies
+ run: |
+ sudo apt-get install -y $PS_PACKAGES $OTHER_PACKAGES $GMP_PACKAGES
+ - name: Install picoscope bindings
+ run: |
+ git clone https://github.com/colinoflynn/pico-python && cd pico-python && python setup.py install && cd ..
+ git clone https://github.com/picotech/picosdk-python-wrappers && cd picosdk-python-wrappers && python setup.py install && cd ..
+ - name: Install dependencies
+ run: |
+ python -m pip install -U pip setuptools wheel
+ pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, gmp, test, dev]"
+ - name: Typecheck
+ run: |
+ make typecheck-all
+ - name: Codestyle
+ run: |
+ make codestyle-all
+ - name: Documentation coverage
+ run: |
+ make doc-coverage \ No newline at end of file
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..5a799d0
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,63 @@
+name: Test
+
+on: [push, pull_request]
+
+env:
+ LLVM_CONFIG: /usr/bin/llvm-config-10
+ PS_PACKAGES: libps4000 libps5000 libps6000
+ GMP_PACKAGES: libgmp-dev libmpfr-dev libmpc-dev
+ OTHER_PACKAGES: swig gcc libpcsclite-dev llvm-10 libllvm10 llvm-10-dev
+
+jobs:
+ test:
+ runs-on: ubuntu-20.04
+ strategy:
+ matrix:
+ python-version: [3.8, 3.9]
+ gmp: [0, 1]
+ env:
+ PYTHON: ${{ matrix.python-version }}
+ USE_GMP: ${{ matrix.gmp }}
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: true
+ - uses: actions/cache@v2
+ with:
+ path: ~/.cache/pip
+ key: pip-${{ runner.os }}-${{ matrix.gmp }}-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
+ restore-keys: |
+ pip-${{ runner.os }}-${{ matrix.gmp }}-${{ matrix.python-version }}-
+ pip-${{ runner.os }}-${{ matrix.gmp }}-
+ pip-${{ runner.os }}-
+ - name: Setup Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v2
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Add picoscope repository
+ run: |
+ curl "https://labs.picotech.com/debian/dists/picoscope/Release.gpg.key" | sudo apt-key add
+ sudo echo "deb https://labs.picotech.com/debian/ picoscope main" | sudo tee /etc/apt/sources.list.d/picoscope.list
+ sudo apt-get update
+ - name: Install system dependencies
+ run: |
+ sudo apt-get install -y $PS_PACKAGES $OTHER_PACKAGES
+ if [ $USE_GMP == 1 ]; then sudo apt-get install -y $GMP_PACKAGES; fi
+ - name: Install picoscope bindings
+ run: |
+ git clone https://github.com/colinoflynn/pico-python && cd pico-python && python setup.py install && cd ..
+ git clone https://github.com/picotech/picosdk-python-wrappers && cd picosdk-python-wrappers && python setup.py install && cd ..
+ - name: Install dependencies
+ run: |
+ python -m pip install -U pip setuptools wheel
+ 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
+ - name: Test
+ run: |
+ make test
+ - name: Code coverage
+ uses: codecov/codecov-action@v1
+ if: ${{ matrix.python-version == 3.9 }}
+ with:
+ env_vars: PYTHON,USE_GMP
+ functionalities: gcov \ No newline at end of file
diff --git a/Makefile b/Makefile
index ff67a45..c22cf87 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ codestyle-all:
flake8 --ignore=E501,F405,F403,F401,E126 pyecsca test
doc-coverage:
- interrogate -vv -nmps -e pyecsca/ec/std/.github/ pyecsca
+ interrogate -vv -nmps -e pyecsca/ec/std/.github/ -f 55 pyecsca
docs:
$(MAKE) -C docs apidoc
diff --git a/README.md b/README.md
index 4179742..429e28d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# ![](docs/_static/logo_black_full.png)
-[![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?color=brightgreen)](https://github.com/J08nY/pyecsca/blob/master/LICENSE) [![Build Status](https://travis-ci.com/J08nY/pyecsca.svg?branch=master)](https://travis-ci.com/J08nY/pyecsca) [![Codecov](https://img.shields.io/codecov/c/gh/J08nY/pyecsca?color=brightgreen&logo=codecov)](https://codecov.io/gh/J08nY/pyecsca) ![](https://img.shields.io/static/v1?label=mypy&message=No%20issues&color=brightgreen)
+[![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?color=brightgreen)](https://github.com/J08nY/pyecsca/blob/master/LICENSE) ![Test](https://github.com/J08nY/pyecsca/workflows/Test/badge.svg) ![Lint](https://github.com/J08nY/pyecsca/workflows/Lint/badge.svg) [![Codecov](https://img.shields.io/codecov/c/gh/J08nY/pyecsca?color=brightgreen&logo=codecov)](https://codecov.io/gh/J08nY/pyecsca) ![](https://img.shields.io/static/v1?label=mypy&message=No%20issues&color=brightgreen)
**Py**thon **E**lliptic **C**urve cryptography **S**ide-**C**hannel **A**nalysis toolkit.
diff --git a/docs/index.rst b/docs/index.rst
index 1ae054f..76c201d 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -6,8 +6,10 @@ pyecsca [pɪɛtska]
:target: https://github.com/J08nY/pyecsca
.. image:: https://img.shields.io/github/license/J08nY/pyecsca?color=brightgreen
:target: https://github.com/J08nY/pyecsca/blob/master/LICENSE
-.. image:: https://img.shields.io/travis/J08nY/pyecsca
- :target: https://travis-ci.com/J08nY/pyecsca
+.. image:: https://github.com/J08nY/pyecsca/workflows/Test/badge.svg
+ :target: https://github.com/J08nY/pyecsca/actions?query=workflow%3ATest
+.. image:: https://github.com/J08nY/pyecsca/workflows/Lint/badge.svg
+ :target: https://github.com/J08nY/pyecsca/actions?query=workflow%3ALint
.. image:: https://img.shields.io/codecov/c/gh/J08nY/pyecsca?color=brightgreen&logo=codecov
:target: https://codecov.io/gh/J08nY/pyecsca
.. image:: https://img.shields.io/static/v1?label=mypy&message=No%20issues&color=brightgreen
diff --git a/pyecsca/sca/scope/picoscope_sdk.py b/pyecsca/sca/scope/picoscope_sdk.py
index 1a7979c..8101f94 100644
--- a/pyecsca/sca/scope/picoscope_sdk.py
+++ b/pyecsca/sca/scope/picoscope_sdk.py
@@ -5,7 +5,7 @@ the official `picosdk-python-wrappers <https://github.com/picotech/picosdk-pytho
import ctypes
from math import log2, floor
from time import time_ns, sleep
-from typing import Mapping, Optional, MutableMapping, Union, Tuple
+from typing import cast, Mapping, Optional, MutableMapping, Union, Tuple
import numpy as np
from picosdk.errors import CannotFindPicoSDKError
@@ -226,7 +226,7 @@ class PicoScopeSdk(Scope): # pragma: no cover
if type == SampleType.Raw:
data = arr
else:
- data = adc2volt(arr, self.ranges[channel], self.MAX_ADC_VALUE, dtype=dtype)
+ data = cast(np.ndarray, adc2volt(arr, self.ranges[channel], self.MAX_ADC_VALUE, dtype=dtype))
return Trace(data, {"sampling_frequency": self.frequency, "channel": channel, "sample_type": type})
def stop(self):
diff --git a/pyecsca/sca/trace/process.py b/pyecsca/sca/trace/process.py
index 5b31ee8..87b00ee 100644
--- a/pyecsca/sca/trace/process.py
+++ b/pyecsca/sca/trace/process.py
@@ -1,6 +1,8 @@
"""
This module provides functions for sample-wise processing of single traces.
"""
+from typing import cast
+
import numpy as np
from public import public
@@ -47,7 +49,7 @@ def threshold(trace: Trace, value) -> Trace:
def _rolling_window(samples: np.ndarray, window: int) -> np.ndarray:
shape = samples.shape[:-1] + (samples.shape[-1] - window + 1, window)
strides = samples.strides + (samples.strides[-1],)
- return np.lib.stride_tricks.as_strided(samples, shape=shape, strides=strides)
+ return np.lib.stride_tricks.as_strided(samples, shape=shape, strides=strides) # type: ignore[attr-defined]
@public
@@ -59,8 +61,8 @@ def rolling_mean(trace: Trace, window: int) -> Trace:
:param window:
:return:
"""
- return trace.with_samples(np.mean(_rolling_window(trace.samples, window), -1).astype(
- dtype=trace.samples.dtype, copy=False))
+ return trace.with_samples(cast(np.ndarray, np.mean(_rolling_window(trace.samples, window), -1).astype(
+ dtype=trace.samples.dtype, copy=False)))
@public
diff --git a/pyecsca/sca/trace/sampling.py b/pyecsca/sca/trace/sampling.py
index 9dc6bf5..b263adc 100644
--- a/pyecsca/sca/trace/sampling.py
+++ b/pyecsca/sca/trace/sampling.py
@@ -1,6 +1,8 @@
"""
This module provides downsampling functions for traces.
"""
+from typing import cast
+
import numpy as np
from public import public
from scipy.signal import decimate
@@ -19,7 +21,7 @@ def downsample_average(trace: Trace, factor: int = 2) -> Trace:
:return:
"""
resized = np.resize(trace.samples, len(trace.samples) - (len(trace.samples) % factor))
- result_samples = resized.reshape(-1, factor).mean(axis=1).astype(trace.samples.dtype, copy=False)
+ result_samples = cast(np.ndarray, resized.reshape(-1, factor).mean(axis=1).astype(trace.samples.dtype, copy=False))
return trace.with_samples(result_samples)
@@ -48,7 +50,7 @@ def downsample_max(trace: Trace, factor: int = 2) -> Trace:
:return:
"""
resized = np.resize(trace.samples, len(trace.samples) - (len(trace.samples) % factor))
- result_samples = resized.reshape(-1, factor).max(axis=1).astype(trace.samples.dtype, copy=False)
+ result_samples = cast(np.ndarray, resized.reshape(-1, factor).max(axis=1).astype(trace.samples.dtype, copy=False))
return trace.with_samples(result_samples)
@@ -63,7 +65,7 @@ def downsample_min(trace: Trace, factor: int = 2) -> Trace:
:return:
"""
resized = np.resize(trace.samples, len(trace.samples) - (len(trace.samples) % factor))
- result_samples = resized.reshape(-1, factor).min(axis=1).astype(trace.samples.dtype, copy=False)
+ result_samples = cast(np.ndarray, resized.reshape(-1, factor).min(axis=1).astype(trace.samples.dtype, copy=False))
return trace.with_samples(result_samples)