In the post-quantum era, most of the cryptographic algorithms that are in widespread use today will be rendered obsolete. Polynomial-time quantum algorithms such as Shor's Algorithm have already been discovered, and threaten the security of cryptosystems relying on integer factorization, the Discrete Logarithm Problem (DLP), and Elliptic Curve Discrete Logarithm Problem (ECDLP). For example, the ECDLP with 256-bit modulus (corresponding to a 128-bit security level) will become feasible to solve once a quantum computer with ≈2330 qubits and ≈126 billion Toffoli gates is created, assuming it doesn't succumb to quantum noise [Roetteler et al. 2017].
Emerging from this chaos, lattice-based cryptosystems have moved to the forefront of post-quantum cryptography, bringing forth new "hard" problems like the Shortest Vector Problem (SVP) and the Closest Vector Problem (CVP). One of the earliest lattice-based cryptosystems to be devised is NTRU. As of the time this document is written, no polynomial-time quantum algorithm has been discovered that can break the NTRU cryptosystem, even after 30 years of its existence.
This writeup will provide a brief overview of the NTRU cryptosystem, including the necessary background in convolution polynomial rings and the core encryption and decryption algorithms.
Notice.
This code is not intended for use in security-critical systems. It was conceived as an interpretable (and therefore unoptimized) implementation of the legacy NTRUEncrypt cryptosystem. For production applications, use modern key encapsulation mechanisms such as Streamlined NTRU Prime (sntrup761) or ML-KEM (FIPS 203).
Note.
I revised the implementation of this project in 2026. The following expository writeup was originally submitted in 2023 for my MATH 1580 (Cryptography) final project at Brown University. In 2024, Alex Khosrowshahi and I implemented this cryptosystem for use in our CSCI 1680 (Computer Networks) final project.
InstallationCopy link to heading
The crate requires only the Rust toolchain. Add it to an existing Rust project as a Git dependency.
We assume the reader is familiar with the basics of ring theory and a little bit of algebraic number theory, and proceed accordingly. For a more thorough introduction to these topics, a reader is encouraged to reference [Gallian 2010] and [Hoffstein et al. 2008].
Definition 4.1 (Ring of Convolution Polynomials)Copy link to heading
Choose a positive integer N. We define the ring of convolution polynomials of rank N as the quotient ring
R=⟨xN−1⟩Z[x].
Likewise, we define the ring of convolution polynomials modulo q as the quotient ring
Rq=⟨xN−1⟩(Z/qZ)[x].
Next, we show that in both R and Rq, quotient ring elements of the form a(x)+⟨xN−1⟩ can be uniquely expressed by coset representatives r(x) with deg(r(x))<N. We prove the following proposition with R, but some slight modifications allow similar results to be proven for Rq.
Proposition 4.2 (Unique Coset Representatives)Copy link to heading
Every congruence class a(x) of R (or Rq) can be uniquely represented as some polynomial,
r(x)=a0+a1x+⋯+aN−1xN−1,
of degree less than N with coefficients in Z (or Z/qZ). Additionally, a(x)≡r(x)(modxN−1).
Let a(x)+⟨xN−1⟩∈R. We can use high-school polynomial long division to write
k(x))xN−1)a(x))−⋮(r(x).)
Here, k(x)∈Z[x] is the quotient, and r(x)∈Z[x] is the remainder satisfying deg(r(x))<N, which exist because the polynomial xN−1 is monic. Thus,
a(x)=k(x)⋅(xN−1)+r(x).
If r(x)=0, then a(x)∈⟨xN−1⟩ so that a(x)=0. Otherwise, we can take both sides modulo xN−1 to get a(x)≡r(x)(modxN−1). This proves the existence of a coset representative r(x) for a(x) with degree less than N. To show uniqueness, suppose that r(x) and r′(x) are two such representatives. Then,
r(x)−r′(x)≡a(x)−a(x)≡0(modxN−1),
so that r(x)−r′(x)∈⟨xN−1⟩. But since deg(r(x)−r′(x))<N, we must have r(x)−r′(x)=0, which implies that r(x)=r′(x) as desired.
Proposition 4.2 reveals that we only need to consider polynomials of degree less than N when working in R and Rq. This is because the two rings are formed by taking a quotient with the ideal ⟨xN−1⟩, which effectively sets xN−1 to zero. Equivalently, you can think of this quotient as replacing any occurrence of xN with the multiplicative identity 1, so that we may reduce exponents modulo N.
A direct consequence is that polynomials in R or Rq can be efficiently represented as vectors based on their coefficients in Z or Z/qZ, thanks to the existence of the bijection
r0+r1x+⋯+rN−1xN−1∈R or Rq⟷bij(r0,…,rN−1)∈ZN or (Z/qZ)N.
Hence, from this point forward we will view polynomials in R as lattice elements in ZN. Now, we are ready to define addition and multiplication in R and Rq.
Definition 4.3 (Addition of Convolution Polynomials)Copy link to heading
Let a(x),b(x)∈R or Rq. We define the sum of a(x) and b(x) as:
a(x)+b(x)⟷(a0+b0,a1+b1,…,aN−1+bN−1).
Definition 4.4 (Multiplication of Convolution Polynomials)Copy link to heading
Let a(x),b(x)∈R or Rq. We define the product of a(x) and b(x) as:
a(x)⋆b(x)⟷(c0,c1,…,cN−1),
where
ck=i=0∑N−1aib(k−i)modN.
This definition for multiplication can be obtained by taking the product of both polynomials in the standard sense and substituting xN=1 as mentioned earlier. We note that this "⋆" operator can also be used between two vectors in ZN or (Z/qZ)N, and the resulting vector simply has entries matching the coefficients of the product of the corresponding polynomials.
There is a natural ring homomorphism from R→Rq that reduces the coefficients of a polynomial a(x)∈R modulo q. The map for the reverse direction from Rq→R is sufficiently complicated to warrant a separate definition.
Definition 4.5 (Center Lift from Rq to R)Copy link to heading
Let a(x)∈Rq. The center lift of a(x) is the unique polynomial a∗(x)∈R that satisfies
a∗(x)≡a(x)(modq),
where the coefficients of a∗(x) are in the range (−21q,21q].
Finally, for polynomials lifted out of the ring R3 (ternary polynomials), we use the following notation.
Notation (Ternary Polynomial Sets)Copy link to heading
Let d1 and d2 be positive integers. Define
T(d1,d2)=⎩⎨⎧a(x)∈R:a(x) has d1 coefficients equal to 1,a(x) has d2 coefficients equal to −1,a(x) has all other coefficients equal to 0⎭⎬⎫.
The NTRU CryptosystemCopy link to heading
At last, we are ready to cover the NTRU cryptosystem itself. This cryptosystem is best explained using convolution polynomials, but it is actually closely tied to lattices and the SVP and CVP mentioned in the introduction. To get started, suppose Alice wants to receive a secret message from Bob. Alice (or some other trusted third party) chooses the following public parameters:
Definition 5.1 (NTRU Parameters)Copy link to heading
(N,p,q,d) with N and p prime, and gcd(N,q)=gcd(p,q)=1. Additionally, q>(6d+1)p and 2d+1≤N (so that T(d+1,d) is nonempty).
For simplicity, we assume q is prime, so that Z/qZ is a field and inverses in Rq can be computed by the Extended Euclidean Algorithm. Hoffstein et al. [2008] do not explicitly require this (standard parameter sets take q=2k and obtain inverses via Hensel's Lifting Lemma). The exact reasoning for why the parameters are chosen as such will become apparent in the proof of Proposition 6.1. Using these public parameters, we can define the structures within which NTRUEncrypt operates. Given choices of N and two moduli p and q, the NTRU cryptosystem utilizes three different convolution polynomial rings.
Alice can then generate a private key composed of two randomly chosen ternary polynomials.
Definition 5.3 (NTRU Private Key)Copy link to heading
f(x)∈T(d+1,d)andg(x)∈T(d,d)
Here, it's important to note that f(x) must have a multiplicative inverse in both Rp and Rq. If this is not the case, then Alice must choose a new f(x) and try again until she finds . Assuming Alice has gone through this process, let
Fp(x)=f(x)−1∈RpandFq(x)=f(x)−1∈Rq.
Existence of polynomial multiplicative inverse
A polynomial f(x)∈Rq is a unit ⟺gcd(f(x),xN−1)=1 in (Z/qZ)[x]. This is because Bézout's Identity ensures that there exist polynomials s(x),t(x)∈(Z/qZ)[x] such that s(x)f(x)+t(x)(xN−1)=1. Reducing both sides modulo xN−1 reveals that s(x)⋆f(x)=1, so s(x)=f(x)−1 in Rq.
At this point, Alice can compute her public key.
Definition 5.4 (NTRU Public Key)Copy link to heading
h(x)=Fq(x)⋆g(x) in Rq
Now, we are almost ready to encrypt a message that Bob would like to send to Alice, but first, we must define what constitutes valid plaintext in the NTRU cryptosystem.
Definition 5.5 (NTRU Plaintext)Copy link to heading
A plaintext m(x)∈R is a polynomial with coefficients mi in the range (−21p,21p].
Notice that we've constructed plaintext as the center lift of a polynomial in Rp (equivalently, we could have defined plaintext as a polynomial in Rp to begin with). Concretely, m(x) can be constructed by representing each byte of a message in base-p and shifting the digits from [0,p) to (−21p,21p] to obtain the polynomial's coefficients.
Figure 5.1 (Message Encoding)Copy link to heading
LChar→76Byte→002211Base 3→00-1-111Center lift
m(x)Coefficients
For p=3, each UTF-8 byte becomes six coefficients in {−1,0,1}.
And now, we turn to the much-anticipated encryption algorithm.
Definition 5.6 (NTRU Encryption Algorithm)Copy link to heading
Let r(x)∈T(d,d) be random. The ciphertext e(x)∈Rq is given by
e(x)≡ph(x)⋆r(x)+m(x)(modq).
To decrypt this ciphertext, Alice must go through the two steps outlined below.
Definition 5.7 (NTRU Decryption Algorithm)Copy link to heading
First, compute
a(x)≡f(x)⋆e(x)(modq).
Take the center lift of this value to obtain a∗(x). The plaintext can be recovered by taking
m(x)≡Fp(x)⋆a∗(x)(modp).
The following diagram encrypts the message “Les sanglots longs des violons de l'automne”. Select values of p and N to update d,q, and the resulting ciphertext.
Figure 5.2 (Encryption and Decryption)Copy link to heading
p
N
d=147q=2657
m(x)m(x)282 center-lifted base-3 coefficients
Plaintext and ciphertext coefficients for the selected parameters.
CorrectnessCopy link to heading
We quickly verify that this approach to encryption and decryption is indeed correct.
Proposition 6.1 (Decryption Correctness)Copy link to heading
If the NTRU encryption parameters (N,p,q,d) are chosen to satisfy the criteria in Definition 5.1, then the encryption/decryption algorithm is correct and yields the plaintext m(x).
For a moment, consider the last line, pg(x)⋆r(x)+f(x)⋆m(x), as a convolution polynomial in R rather than Rq. Recall that we have chosen g(x) and r(x) to be ternary polynomials in T(d,d). Hence, even if all of their 1 or −1 values line up, the maximum coefficient in g(x)⋆r(x) is 2d. Additionally, recall that f(x) is in T(d+1,d) and the coefficients of m(x) are in the range −21p<mi≤21p. Hence, the largest possible coefficient in f(x)⋆m(x) is (2d+1)21p. Thus, the sum of these two convolution polynomials (with p multiplied onto the left convolution) will have coefficients no larger than
2dp+(2d+1)21p=2dp+dp+21p=(3d+21)p.
So, we were correct in choosing q>(6d+1)p in Definition 5.1, as this ensures that the coefficients of pg(x)⋆r(x)+f(x)⋆m(x) are constrained to the range −21q<ai≤21q. Therefore, when a(x)∈Rq is lifted to a∗(x)∈R, we get an equality rather than a congruence:
To reiterate, NTRUEncrypt is a public-key cryptosystem (which means two parties can securely send messages to each other while only revealing their public keys). The following diagram shows how a full exchange between Alice and Bob proceeds, including which mathematical data is sent over a public channel.
Figure 6.1 (Secret Exchange)Copy link to heading
Alice
f∈T(d+1,d),g∈T(d,d)
h=Fq⋆g(modq)
m= blessent mon coeur d'une langueur monotone
Fp⋆f⋆e
hePublic channel
Bob
m= blessent mon coeur d'une langueur monotone
e≡ph⋆r+m(modq)
r ephemeral
A complete NTRUEncrypt exchange from key generation through decryption.
ReferencesCopy link to heading
Martin Roetteler, Michael Naehrig, Krysta M. Svore, and Kristin Lauter. 2017. Quantum resource estimates for computing elliptic curve discrete logarithms. arxiv.org
Joseph A. Gallian. 2010. Contemporary Abstract Algebra. Brooks/Cole, Cengage Learning. books.google.com
Jeffrey Hoffstein, Jill Pipher, and Joseph H. Silverman. 2008. An Introduction to Mathematical Cryptography. Springer. doi:10.1007/978-0-387-77993-5