-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tn3w
authored and
tn3w
committed
Aug 24, 2024
1 parent
dadc2a2
commit eb0877c
Showing
7 changed files
with
531 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Build Wheels | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8, 3.9, 3.10] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install maturin cibuildwheel | ||
- name: Build wheels | ||
run: | | ||
if [ ${{ matrix.os }} == 'ubuntu-latest' ]; then | ||
cibuildwheel --output-dir wheelhouse | ||
fi | ||
env: | ||
CIBW_BUILD: "cp36-abi3-* cp37-abi3-* cp38-abi3-* cp39-abi3-* cp310-abi3-*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "py_ntru" | ||
version = "1.0.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
rand = "0.8" | ||
aes-gcm = "0.9" | ||
ntrust-native = { version = "1.0", features = ["ntruhrss701"] } | ||
pyo3 = { version = "0.15", features = ["extension-module"] } | ||
|
||
[lib] | ||
crate-type = ["cdylib"] # Required for creating a Python extension module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM python:3.11-slim | ||
|
||
# Install Rust and Cargo | ||
RUN apt-get update && apt-get install -y \ | ||
curl \ | ||
build-essential \ | ||
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ | ||
&& export PATH="$PATH:/root/.cargo/bin" | ||
|
||
# Install maturin and cibuildwheel | ||
RUN pip install maturin cibuildwheel | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy the project files into the container | ||
COPY . . | ||
|
||
# Run cibuildwheel to build wheels | ||
CMD ["cibuildwheel", "--output-dir", "/wheelhouse"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,159 @@ | ||
# py_ntru | ||
This is an implementation of the Rust NTRU library through a Python wrapper to improve the availability and speed of post quantum algorithms for Python. | ||
|
||
Welcome to the `py_ntru` documentation! This library provides a Python wrapper around the Rust NTRU library, enabling the use of post-quantum cryptographic algorithms with enhanced performance and availability. The following comprehensive guide will walk you through the installation, building, and usage processes. | ||
|
||
## 🚀 Installation | ||
|
||
### Prerequisites | ||
|
||
Before you begin, ensure you have the following installed on your system: | ||
- **Python 3.7+**: The latest version of Python 3 is recommended. You can download it from the [official Python website](https://www.python.org/downloads/). | ||
- **Rust**: Required for compiling the Rust code. You can install it via [rustup](https://rustup.rs/). | ||
|
||
### Virtualenv Setup | ||
|
||
Using a virtual environment helps manage dependencies and avoid conflicts. Follow these steps to set it up: | ||
|
||
1. **Create a Virtual Environment** | ||
|
||
Run the following command to create a virtual environment in the current directory: | ||
|
||
```bash | ||
python -m venv .venv | ||
``` | ||
|
||
2. **Activate the Virtual Environment** | ||
|
||
- On **Linux/macOS**, activate the virtual environment with: | ||
|
||
```bash | ||
source .venv/bin/activate | ||
``` | ||
|
||
- On **Windows**, use: | ||
|
||
```bash | ||
.venv\Scripts\activate | ||
``` | ||
|
||
### Installing Dependencies | ||
|
||
1. **Install Maturin** | ||
|
||
Maturin is a tool for building and publishing Rust-based Python packages. Install it using pip: | ||
|
||
```bash | ||
pip install maturin | ||
``` | ||
|
||
2. **Clone the Repository** | ||
|
||
Clone the `py_ntru` repository from GitHub to your local machine: | ||
|
||
```bash | ||
git clone https://github.com/tn3w/py_ntru.git | ||
``` | ||
|
||
3. **Navigate to the Repository Directory** | ||
|
||
Change your working directory to the `py_ntru` directory: | ||
|
||
```bash | ||
cd py_ntru | ||
``` | ||
|
||
4. **Build the Python Package** | ||
|
||
Use Maturin to compile the Rust code and create a Python extension wheel. The `--release` flag ensures that the code is optimized for performance: | ||
|
||
```bash | ||
maturin build --release | ||
``` | ||
|
||
5. **Locate the Wheel File** | ||
|
||
After building, navigate to the directory where the wheel file is located: | ||
|
||
```bash | ||
cd target/wheels | ||
``` | ||
|
||
6. **Install the Wheel File** | ||
|
||
Install the wheel file using pip. Replace `<version>` and `<build>` with the actual version and build number from the wheel file: | ||
|
||
```bash | ||
pip install py_ntru-<version>-<build>.whl | ||
``` | ||
|
||
## 🛞 Building Wheels Using Docker | ||
|
||
If you prefer to build the package in a Docker container, follow these steps: | ||
|
||
1. **Build the Docker Image** | ||
|
||
Use the provided Dockerfile to build the Docker image. This image contains all the necessary dependencies for building `py_ntru`: | ||
|
||
```bash | ||
sudo docker build -t py_ntru_builder . | ||
``` | ||
|
||
2. **Run the Docker Container** | ||
|
||
Start a container from the image and mount your local repository directory: | ||
|
||
```bash | ||
sudo docker run --rm -it -v $(pwd):/workspace py_ntru_builder | ||
``` | ||
|
||
Inside the Docker container, navigate to the `/workspace` directory and build the package as described in the [Building the Python Package](#build-the-python-package) section. | ||
|
||
## 📝 Usage | ||
|
||
Once `py_ntru` is installed, you can use it in your Python scripts. Here is a basic example of how to use the library: | ||
|
||
```python | ||
import py_ntru | ||
# Generate a private key | ||
private_key = py_ntru.generate_private_key() | ||
print(f"Private Key: {private_key}") | ||
# Generate a public key based on the private key | ||
public_key = py_ntru.generate_public_key_based_on_private_key(private_key) | ||
print(f"Public Key: {public_key}") | ||
# Message to encrypt | ||
message = b"Hello!" | ||
print(f"Original Message: {message}") | ||
# Encrypt the message using the public key | ||
ciphertext = py_ntru.encrypt(public_key, message) | ||
print(f"Ciphertext: {ciphertext}") | ||
# Decrypt the ciphertext using the private key | ||
decrypted_message = py_ntru.decrypt(private_key, ciphertext) | ||
print(f"Decrypted Message: {decrypted_message}") | ||
``` | ||
|
||
## 🛠 Troubleshooting | ||
|
||
If you encounter any issues during installation or usage, consider the following: | ||
|
||
- **Ensure Compatibility**: Check that your versions of Python, Rust, and Maturin are compatible with `py_ntru`. | ||
- **Check Dependencies**: Verify that all necessary dependencies are installed and up-to-date. | ||
- **Consult Logs**: Review error messages and logs for clues on what might be going wrong. | ||
|
||
For additional support, you can open an issue on the [GitHub repository](https://github.com/tn3w/py_ntru/issues) or consult the community forums. | ||
|
||
## 📚 Contributing | ||
|
||
Contributions to `py_ntru` are welcome! If you'd like to contribute, please follow these guidelines: | ||
1. **Fork the Repository**: Create a personal fork of the `py_ntru` repository. | ||
2. **Create a Branch**: Make a new branch for your changes. | ||
3. **Make Changes**: Implement your changes and ensure they adhere to the project's coding standards. | ||
4. **Submit a Pull Request**: Push your branch to your fork and submit a pull request to the main repository. | ||
|
||
Thank you for using `py_ntru` and contributing to the advancement of post-quantum cryptography! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[build-system] | ||
requires = ["maturin"] | ||
build-backend = "maturin" | ||
|
||
[tool.maturin] | ||
name = "py_ntru" |
Oops, something went wrong.