diff --git a/docker/ubuntu24.04/.dockerignore b/docker/ubuntu24.04/.dockerignore new file mode 100644 index 00000000..75bbe544 --- /dev/null +++ b/docker/ubuntu24.04/.dockerignore @@ -0,0 +1,8 @@ +.git +**/__pycache__/ +*.pyc +venv/ +target/ +dist/ +build/ +docs/_build \ No newline at end of file diff --git a/docker/ubuntu24.04/Dockerfile b/docker/ubuntu24.04/Dockerfile new file mode 100644 index 00000000..219fb9e0 --- /dev/null +++ b/docker/ubuntu24.04/Dockerfile @@ -0,0 +1,54 @@ +FROM ubuntu:24.04 + +# Disabling installing extra packages with apt-get install +RUN echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/00-docker +RUN echo 'APT::Install-Recommends "0";' >> /etc/apt/apt.conf.d/00-docker + +RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + apt-get install -y \ + make \ + wget \ + python3 \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# download conda +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ + bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda + +# Add conda to PATH +ENV PATH=/opt/conda/bin:$PATH + +# Run conda init +RUN conda init + +# Restart shell +RUN bash -l + +# Install sage +# add conda-forge channel +RUN conda config --add channels conda-forge +RUN conda config --set channel_priority strict + +# accept terms of service +RUN conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \ + conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r + +# create conda environment with sage and python +RUN conda create -y -n lattice_estimator sage python=3.12.5 +RUN conda run -n lattice_estimator pip install sphinxcontrib-jupyter + +# copy lattice-estimator repo to container +WORKDIR /opt/lattice_estimator +COPY . . + +# ensure interactive shells auto-activate the env, activate the conda env, and install the sagemath kernel +RUN echo "source /opt/conda/etc/profile.d/conda.sh" >> /root/.bashrc && \ + echo "conda activate lattice_estimator" >> /root/.bashrc && \ + /opt/conda/envs/lattice_estimator/bin/sage -python -m ipykernel install --name sagemath --display-name "SageMath" --sys-prefix + +# Install pytest dependencies +RUN conda install -n lattice_estimator -c conda-forge numpy nbmake pytest traitlets +# dependency not available in conda-forge hence use pip +RUN pip install --upgrade sphinxcontrib-jupyter +RUN make jupyter diff --git a/docker/ubuntu24.04/README.md b/docker/ubuntu24.04/README.md new file mode 100644 index 00000000..61a18c05 --- /dev/null +++ b/docker/ubuntu24.04/README.md @@ -0,0 +1,70 @@ +# Running lattice estimator in a Ubuntu 24.04 container + +This docker build will run the lattice-estimator using a Ubuntu24.04 LTS base image with the latest stable SageMath installed on Conda. + +## Dependencies + +- [Docker](https://docs.docker.com/engine/install/) + +## Build and Run + +```bash +docker build . -t lattice-estimator -f docker/ubuntu24.04/Dockerfile +docker run -it lattice-estimator:latest +``` + +Enter the Python interactive shell to get started running the lattice-estimator: + +```console +(lattice_estimator) root@9af6e51a3e65:/opt/lattice_estimator# python +Python 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:36:51) [GCC 12.4.0] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> from sage.all import * +>>> from estimator import * +>>> schemes.Kyber512 +LWEParameters(n=512, q=3329, Xs=D(σ=1.22), Xe=D(σ=1.22), m=512, tag='Kyber 512') +``` + +## Run pytests + +```console +>>> exit() # exit python interactive shell + +(lattice_estimator) root@dd916359f4c6:/opt/lattice_estimator# PYTHONIOENCODING=UTF-8 PYTHONPATH=`pwd` python -m pytest + +/opt/conda/envs/lattice_estimator/lib/python3.12/site-packages/nbmake/pytest_plugin.py:6: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. + import pkg_resources +==================================================================== test session starts ==================================================================== +platform linux -- Python 3.12.5, pytest-8.4.1, pluggy-1.6.0 +rootdir: /opt/lattice_estimator +configfile: pyproject.toml +plugins: anyio-4.10.0, nbmake-1.3.4 +collected 85 items + +README.rst . [ 1%] +docs/schemes/hes.rst . [ 2%] +docs/schemes/nist-pqc-round-3.rst . [ 3%] +estimator/cost.py .... [ 8%] +estimator/gb.py .. [ 10%] +estimator/lwe.py .. [ 12%] +estimator/lwe_bkw.py . [ 14%] +estimator/lwe_dual.py . [ 15%] +estimator/lwe_guess.py .... [ 20%] +estimator/lwe_parameters.py .... [ 24%] +estimator/lwe_primal.py .. [ 27%] +estimator/nd.py ......................... [ 56%] +estimator/ntru.py .. [ 58%] +estimator/ntru_parameters.py .. [ 61%] +estimator/ntru_primal.py ... [ 64%] +estimator/prob.py . [ 65%] +estimator/reduction.py .................... [ 89%] +estimator/simulator.py . [ 90%] +estimator/sis.py .. [ 92%] +estimator/sis_lattice.py . [ 94%] +estimator/sis_parameters.py . [ 95%] +estimator/util.py .. [ 97%] +param_sweep.py .. [100%] + +============================================================== 85 passed in 438.12s (0:07:18) =============================================================== +``` +