diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 8eb0244..223bbde 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -12,7 +12,8 @@ env: jobs: lint: - runs-on: ubuntu-latest + # Keep older supported Python versions available on the runner. + runs-on: ubuntu-22.04 strategy: matrix: python-version: [ 3.9, "3.10", 3.11, 3.12 ] diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 95c698f..6ff9768 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -12,7 +12,8 @@ env: jobs: docs: name: Build and deploy documentation - runs-on: ubuntu-latest + # Keep older supported Python versions available on the runner. + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 with: diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 646168c..ea42f5e 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -3,6 +3,15 @@ on: push: branches: - 'build-wheel' + pull_request: + paths: + - 'setup.cfg' + - '.github/workflows/wheels.yml' + workflow_dispatch: + +permissions: + contents: read + jobs: build_linux_wheels: name: build linux wheels @@ -10,10 +19,12 @@ jobs: env: PY_VERS: cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + with: + persist-credentials: false - name: set up container run: | - docker create --name linux_build -i -v /:/host quay.io/pypa/manylinux2014_x86_64:latest /bin/bash + docker create --name linux_build -i quay.io/pypa/manylinux2014_x86_64:latest /bin/bash docker cp . linux_build:/cryptomite/ - name: run build run: | @@ -25,38 +36,42 @@ jobs: with: name: linux_wheels path: wheelhouse/ + if-no-files-found: error build_macos_wheels: name: build macos wheels - runs-on: macos-13 + runs-on: macos-15-intel + env: + MACOSX_DEPLOYMENT_TARGET: '13.0' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + with: + persist-credentials: false - name: set up python 3.9 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.9' - name: build wheel (3.9) run: .github/workflows/macosbuildwheel - name: set up python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.10' - name: build wheel (3.10) run: .github/workflows/macosbuildwheel - name: set up python 3.11 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.11' - name: build wheel (3.11) run: .github/workflows/macosbuildwheel - name: set up python 3.12 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.12' - name: build wheel (3.12) run: .github/workflows/macosbuildwheel - - uses: actions/checkout@v2 - - name: set up python '3.13' - uses: actions/setup-python@v2 + - name: set up python 3.13 + uses: actions/setup-python@v6 with: python-version: '3.13' - name: build wheel (3.13) @@ -65,31 +80,36 @@ jobs: with: name: macos_wheels path: wheelhouse/ + if-no-files-found: error build_macos_m1_wheels: name: build macos M1 wheels - runs-on: macos-latest-xlarge + runs-on: macos-15 + env: + MACOSX_DEPLOYMENT_TARGET: '14.0' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + with: + persist-credentials: false - name: set up python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.10' - name: build wheel (3.10) run: .github/workflows/macosbuildwheel - name: set up python 3.11 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.11' - name: build wheel (3.11) run: .github/workflows/macosbuildwheel - name: set up python 3.12 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.12' - name: build wheel (3.12) run: .github/workflows/macosbuildwheel - name: set up python 3.13 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.13' - name: build wheel (3.13) @@ -98,13 +118,16 @@ jobs: with: name: macos_m1_wheels path: wheelhouse/ + if-no-files-found: error build_windows_wheels: name: build windows wheels - runs-on: windows-2019 + runs-on: windows-2022 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + with: + persist-credentials: false - name: set up python 3.8 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.8' - name: build wheel (3.8) @@ -112,7 +135,7 @@ jobs: python -m pip install -U pip wheel scikit-build python setup.py bdist_wheel -d "${{ github.workspace }}/wheelhouse" - name: set up python 3.9 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.9' - name: build wheel (3.9) @@ -120,7 +143,7 @@ jobs: python -m pip install -U pip wheel scikit-build python setup.py bdist_wheel -d "${{ github.workspace }}/wheelhouse" - name: set up python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.10' - name: build wheel (3.10) @@ -128,7 +151,7 @@ jobs: python -m pip install -U pip wheel scikit-build python setup.py bdist_wheel -d "${{ github.workspace }}/wheelhouse" - name: set up python 3.11 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.11' - name: build wheel (3.11) @@ -136,7 +159,7 @@ jobs: python -m pip install -U pip wheel scikit-build python setup.py bdist_wheel -d "${{ github.workspace }}/wheelhouse" - name: set up python 3.12 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.12' - name: build wheel (3.12) @@ -144,7 +167,7 @@ jobs: python -m pip install -U pip wheel scikit-build python setup.py bdist_wheel -d "${{ github.workspace }}/wheelhouse" - name: set up python 3.13 - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: '3.13' - name: build wheel (3.13) @@ -155,3 +178,4 @@ jobs: with: name: windows_wheels path: wheelhouse/ + if-no-files-found: error diff --git a/cryptomite/raz.py b/cryptomite/raz.py index 9af51e0..214df76 100644 --- a/cryptomite/raz.py +++ b/cryptomite/raz.py @@ -125,7 +125,7 @@ def extract(self, input1: BitsT, input2: BitsT) -> BitsT: assert 0 < len(input2) <= self.n x1, x2 = input1[0:self.n], input1[self.n:] - y = input2 + [0] * (len(input2) - self.n) + y = input2 + [0] * (self.n - len(input2)) pad_amount = self.pad_amount x1 = x1 + [0]*pad_amount diff --git a/setup.cfg b/setup.cfg index 9da22b0..41809eb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ name = cryptomite description = An awesome extractor library long_description = file: README.md long_description_content_type = text/markdown -version = 0.3.0 +version = 0.3.1 author = Cambridge Quantum author_email = qcrypto@cambridgequantum.com license_files = file: LICENSE diff --git a/test/test_raz.py b/test/test_raz.py new file mode 100644 index 0000000..0c2916e --- /dev/null +++ b/test/test_raz.py @@ -0,0 +1,25 @@ +from cryptomite.raz import Raz + +import pytest + + +@pytest.mark.parametrize('n', [3, 7, 15]) +@pytest.mark.parametrize('input_length', ['one', 'short', 'full']) +def test_raz_zero_extension(n, input_length, monkeypatch): + extractor = Raz(2 * n, n) + length = {'one': 1, 'short': n - 1, 'full': n}[input_length] + input1 = [i % 2 for i in range(2 * n)] + input2 = [(i + 1) % 2 for i in range(length)] + original_input2 = input2.copy() + multiply = extractor.gf_mul + + def checked_multiply(x, y): + # Reject undersized buffers before the native NTT reads past them. + assert len(x) == len(y) == 1 << extractor.logp + return multiply(x, y) + + monkeypatch.setattr(extractor, 'gf_mul', checked_multiply) + expected = extractor.extract(input1, input2 + [0] * (n - length)) + + assert extractor.extract(input1, input2) == expected + assert input2 == original_input2