Package: lattice-algebra
lattice-algebraThis library is a fundamental infrastructure package for building lattice-based cryptography.Installation:pip install lattice-algebraDocumentation:https://geometry-labs.github.io/lattice-algebra/IntroductionThe 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_with_const_time-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 developersThe library is designed to make iteasy for developers to write clean code that securely implements lattice-based cryptographyfor protocols and applications. The package is optimized to use the Number Theoretic Transform (NTT) to multiply polynomials in timeO(2dlog(2d)), and usesconstant-time modular arithmetic to avoid timing attacks. For convenience, we included  tools for bothhashing toandsampling fromthese "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 thelattice_algebratoolkit helps developers write succinct code is by leveraging python'smagic methods for arithmetic with elements fromRandR^l. For example, suppose we have two_with_const_time polynomialsfandg. Simple expressions such asf + g,f - g, andf * gcarry outconstant-time polynomial arithmeticsuch as addition, subtraction, and multiplication (respectively). Likewise if we have two_with_const_time vectors of polynomialsxandy, several vector arithmetic methods are at our disposal: we can add them likex + y,  or calculate the dot product asx * y. Additionally,x ** fscales a vectorxby the polynomialf, which is useful for constructing digital signatures.ContributorsBrandon Goodell (lead author), Mitchell "Isthmus" Krawiec-Thayer, Rob Cannon.Built byGeometry Labswith funding fromThe QRL Foundation.Running TestsUsepytest 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 functionnttthat calls (or uses data from)bit_revandmake_zeta_and_invs, among other functions, so we test all three of these withtest_ntt,test_bit_rev, andtest_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 testhash2bddpolyandhash2bddpolyvec. Interestingly, one_with_const_time 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 comparedecode2coefin main withtest_decode2coefintest_lattices.py, for example, to see where the test comes from and how the decoding scheme works. See alsotest_decode2indicesandtest_decode2polycoefs.Building DocsDocs are built with mkdocs. Run the following and navigate tohttp://127.0.0.1:8000/rsis/which should update automatically as you write the docs.pipinstall-rdocs/requirements.txt
mkdocsserveLicenseThis library is released as free and open-source software under the MIT License, see LICENSE file for details.