Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

lattice-algebra

pypi python codecov main-tests

This library is a fundamental infrastructure package for building lattice-based cryptography.

Introduction

The mathematical objects and calculations handled by this package are foundational for lattice algebra, with a variety of applications ranging from signature aggregation to zero-knowledge proofs. The module highly prioritizes developer experience for researchers and engineers, by allowing them to work with a few high level objects (e.g. polynomials, polynomial vectors) that contain built-in methods to abstractly handle the ways that they interact with each other. The goal is to lower the barrier for creating lattice cryptography primitives and applications by allowing the developers to focus on securely building the higher-level constructs without having to worry about implementing the underlying algebra as well.

The module is specifically deesigned for building cryptographic schemes in the Ring/Module/Ideal Short Integer Solution setting with with secrets uniformly distributed with respect to the infinity-norm and one-norm; it can also be used to implement schemes in the Ring/Module/Ideal Learning With Errors setting. The library’s lead author Brandon Goodell explained how the high level objects are efficiently implemented under the hood, “to manipulate equations of polynomials, we carry out the computations with vectors and matrices, with highly optimized algebraic operations.”

Features for cryptography developers

The library is designed to make it easy for developers to write clean code that securely implements lattice-based cryptography for protocols and applications. The package is optimized to use the Number Theoretic Transform (NTT) to multiply polynomials in time O(2dlog(2d)), and uses constant-time modular arithmetic to avoid timing attacks. For convenience, we included tools for both hashing to and sampling from these "suitably small" polynomials and vectors. Both the hashing and sampling are carried out such that the bias of the resulting distribution is negligibly different from uniform.

One way that the lattice_algebra toolkit helps developers write succinct code is by leveraging python's magic methods for arithmetic with elements from R and R^l. For example, suppose we have two polynomials f and g. Simple expressions such as f + g, f - g, and f * g carry out constant-time polynomial arithmetic such as addition, subtraction, and multiplication (respectively). Likewise if we have two vectors of polynomials x and y, several vector arithmetic methods are at our disposal: we can add them like x + y, or calculate the dot product as x * y. Additionally, x ** f scales a vector x by the polynomial f, which is useful for constructing digital signatures.

Contributors

Brandon Goodell (lead author), Mitchell "Isthmus" Krawiec-Thayer, Rob Cannon.

Built by Geometry Labs with funding from The QRL Foundation.

Running Tests

Use pytest test_lattices.py. Basic tests cover almost every function, are generally short, and are all correct tests. However, test robustness can be greatly improved. For example, we implement the Number Theoretic transform function ntt that calls (or uses data from) bit_rev and make_zeta_and_invs, among other functions, so we test all three of these with test_ntt, test_bit_rev, and test_make_zeta_and_invs... but in all three of these tests, we only test a single example with small parameters.

Our tests do not have full coverage; we have not mocked any hash functions to test hash2bddpoly and hash2bddpolyvec. Interestingly, one can look at our tests as a Rosetta stone for our encoding and decoding of polynomials from binary strings, which is used in our hash functions. A keen-eyed reader can compare decode2coef in main with test_decode2coef in test_lattices.py, for example, to see where the test comes from and how the decoding scheme works. See also test_decode2indices and test_decode2polycoefs.

Building Docs

Docs are built with mkdocs. Run the following and navigate to http://127.0.0.1:8000/rsis/ which should update automatically as you write the docs.

pip install -r docs/requirements.txt
mkdocs serve

License

This library is released as free and open-source software under the MIT License, see LICENSE file for details.

Metadata

Release files for lattice-algebra 0.1.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lattice-algebra 0.1.0a1
File Size Uploaded Provenance Actions
lattice_algebra-0.1.0a1.tar.gz 17.0 kB Without provenance Details for lattice_algebra-0.1.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lattice-algebra 0.1.0a1
File Interpreter ABI Platform Actions
lattice_algebra-0.1.0a1-py3-none-any.whl Python 3 none any Details for lattice_algebra-0.1.0a1-py3-none-any.whl

Total release size: 31.6 kB

Release files / lattice_algebra-0.1.0a1.tar.gz

Download URL lattice_algebra-0.1.0a1.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ae29629d8cc22a081c613e29b93918b9e485633d33d9bb1aafc517eddf2053d3
BLAKE2b-256 checksum
How to use checksums
35a25c974603d5ff543135c2875b7c2cfc7b12c04cc7fb2b8771aab2be1dfbb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

Release files / lattice_algebra-0.1.0a1-py3-none-any.whl

Download URL lattice_algebra-0.1.0a1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01e9d81558976d39fe016b011698e6a181ede7934373f2da2983791f3c088f57
BLAKE2b-256 checksum
How to use checksums
95c34535e4262878c5755c08069ea9bfd345bcd9d09b8daa6fdeb4ad02032e11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

Security for lattice-algebra 0.1.0a1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page