aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2023-03-30 10:35:00 +0200
committerJ08nY2023-03-30 12:05:06 +0200
commit0eb176e35702a87470f642bc4cc1158c61c66961 (patch)
tree3a5fffbaa80a81c5b7a0ce9033d0758d636b1e75
parent68a4698448f0d5c6b8d8af022c870b47dab8f1af (diff)
downloadpyecsca-codegen-0eb176e35702a87470f642bc4cc1158c61c66961.tar.gz
pyecsca-codegen-0eb176e35702a87470f642bc4cc1158c61c66961.tar.zst
pyecsca-codegen-0eb176e35702a87470f642bc4cc1158c61c66961.zip
Add github actions.
-rw-r--r--.coveragerc1
-rw-r--r--.github/workflows/test.yml54
-rw-r--r--.travis.yml37
-rw-r--r--README.md6
-rw-r--r--docs/INSTALL.md16
-rw-r--r--docs/install.rst16
-rw-r--r--pyecsca/codegen/render.py16
7 files changed, 83 insertions, 63 deletions
diff --git a/.coveragerc b/.coveragerc
index 33d3f05..52944ef 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -5,6 +5,7 @@ omit =
setup.py
pyecsca/codegen/templates/*
ext/pyecsca/*
+ pyecsca-upstream/*
[report]
exclude_lines =
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..82ccd60
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,54 @@
+name: Test
+
+on: [push, pull_request]
+
+env:
+ LLVM_CONFIG: /usr/bin/llvm-config-10
+ 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", "3.10"]
+ env:
+ PYTHON: ${{ matrix.python-version }}
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ submodules: true
+ - uses: actions/cache@v3
+ 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@v3
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Install system dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y $OTHER_PACKAGES
+ - name: Build libtommath
+ run: |
+ cd ext && make host && cd ..
+ - name: Install dependencies
+ run: |
+ pip install -U pip setuptools wheel
+ - name: Install pyecsca
+ run: |
+ git clone https://github.com/J08nY/pyecsca pyecsca-upstream && cd pyecsca-upstream && git submodule update --init && pip install -e ".[chipwhisperer, test, dev]" && cd ..
+ - name: Install pyecsca-codegen
+ run: |
+ pip install -e ".[test, dev]"
+ - name: Test
+ run: |
+ make test
+ - name: Code coverage
+ uses: codecov/codecov-action@v3
+ if: ${{ matrix.python-version == 3.9 }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index b6f64c8..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,37 +0,0 @@
-os: linux
-language: python
-dist: focal
-python:
- - "3.8"
- - "3.9"
-
-addons:
- apt:
- packages:
- - swig
- - gcc
- - llvm-10
- - libllvm10
- - llvm-10-dev
-
-env:
- - LLVM_CONFIG=/usr/bin/llvm-config-10
-
-install:
- - pip install codecov
- - cd ext/
- - make host
- - git clone https://github.com/J08nY/pyecsca
- - cd pyecsca/
- - git submodule update --init --recursive
- - pip install -e ".[chipwhisperer]"
- - cd ../..
- - pip install -e ".[test, dev]"
-
-script:
- - make -i typecheck
- - make -i codestyle
- - make test
-
-after_success:
- - codecov
diff --git a/README.md b/README.md
index eca3e80..c029975 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,18 @@
# pyecsca-codegen
-[![Build Status](https://travis-ci.com/J08nY/pyecsca-codegen.svg?branch=master)](https://travis-ci.com/J08nY/pyecsca-codegen) ![License: MIT](https://img.shields.io/github/license/J08nY/pyecsca.svg) [![codecov](https://codecov.io/gh/J08nY/pyecsca-codegen/branch/master/graph/badge.svg)](https://codecov.io/gh/J08nY/pyecsca-codegen)
+[![Test](https://github.com/J08nY/pyecsca-codegen/actions/workflows/test.yml/badge.svg)](https://github.com/J08nY/pyecsca-codegen/actions/workflows/test.yml) ![License: MIT](https://img.shields.io/github/license/J08nY/pyecsca.svg) [![codecov](https://codecov.io/gh/J08nY/pyecsca-codegen/branch/master/graph/badge.svg)](https://codecov.io/gh/J08nY/pyecsca-codegen)
**Py**thon **E**lliptic **C**urve cryptography **S**ide-**C**hannel **A**nalysis toolkit.
Codegen package. See the [main repo](https://github.com/J08nY/pyecsca) for more information.
-See [INSTALL](docs/INSTALL.md) for installation instructions.
+See [INSTALL](docs/install.rst) for installation instructions.
## License
MIT License
- Copyright (c) 2018-2020 Jan Jancar
+ Copyright (c) 2018-2023 Jan Jancar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/docs/INSTALL.md b/docs/INSTALL.md
deleted file mode 100644
index 7533529..0000000
--- a/docs/INSTALL.md
+++ /dev/null
@@ -1,16 +0,0 @@
-# Installation
-
-This assumes that both *pyecsca* and the *pyecsca-codegen*
-packages are installed as editable.
-
-1. Checkout the ext/libtommath submodule:
-`git submodule update --init`
-2. Build the libtommath library to prepare it for the future
-build processes steps.
-```
-cd ext
-make host stm32f0 stm32f3
-```
-
-Now the package should be ready with the necessary versions of
-libtommath built for the host and the STM32F0 and F3 targets.
diff --git a/docs/install.rst b/docs/install.rst
new file mode 100644
index 0000000..dbff34f
--- /dev/null
+++ b/docs/install.rst
@@ -0,0 +1,16 @@
+============
+Installation
+============
+
+This assumes that both **pyecsca** and the **pyecsca-codegen**
+packages are installed as editable.
+
+1. Checkout the ext/libtommath submodule: :code:`git submodule update --init`
+2. Build the libtommath library to prepare it for the future build processes steps.
+
+.. code-block:: shell
+ cd ext
+ make host stm32f0 stm32f3
+
+Now the package should be ready with the necessary versions of
+libtommath built for the host and the STM32F0 and F3 targets.
diff --git a/pyecsca/codegen/render.py b/pyecsca/codegen/render.py
index 984a25c..19d395f 100644
--- a/pyecsca/codegen/render.py
+++ b/pyecsca/codegen/render.py
@@ -86,7 +86,7 @@ def transform_ops(ops: List[CodeOp], parameters: List[str], outputs: Set[str],
that will be used by the ops template macros to render the ops.
This tracks allocations and frees, also creates a mapping of constants
- to variable names
+ to variable names.
"""
def rename(name: str):
if renames is not None and name not in outputs:
@@ -98,6 +98,11 @@ def transform_ops(ops: List[CodeOp], parameters: List[str], outputs: Set[str],
const_mapping = {}
operations = []
frees = []
+ # Go over the ops, track allocations needed for intermediates and constants.
+ # There are two kinds of constants, encoded and not-encoded. The encoded
+ # ones are default, the non-encoded ones are only in the exponents, where
+ # you don't want to encode using the reduction object (i.e. Montgomery form).
+ # Also constructs a mapping from raw constants to their variable names.
for op in ops:
if op.result not in allocations:
allocations.append(op.result)
@@ -119,6 +124,8 @@ def transform_ops(ops: List[CodeOp], parameters: List[str], outputs: Set[str],
frees.append(name)
operations.append((op.operator, op.result, rename(op.left), rename(op.right)))
mapped = []
+ # Go over the operations and map constants to their variable names,
+ # make sure the encoded/non-encoded version is used where appropriate.
for op in operations:
o2 = op[2]
if (o2, True) in const_mapping:
@@ -129,6 +136,7 @@ def transform_ops(ops: List[CodeOp], parameters: List[str], outputs: Set[str],
o3 = const_mapping[(o3, o3_enc)]
mapped.append((op[0], op[1], o2, o3))
returns = {}
+ # Handle renames in the returns.
if renames:
for r_from, r_to in renames.items():
if r_from in outputs:
@@ -140,12 +148,6 @@ def transform_ops(ops: List[CodeOp], parameters: List[str], outputs: Set[str],
frees=frees, returns=returns)
-def render_ops(ops: List[CodeOp], parameters: List[str], outputs: Set[str],
- renames: Mapping[str, str] = None) -> str:
- namespace = transform_ops(ops, parameters, outputs, renames)
- return env.get_template("ops.c").render(namespace)
-
-
def render_coords_impl(coords: CoordinateModel) -> str:
ops = []
for s in coords.satisfying: