CryptoBook
  • CryptoBook
  • Book Plan
  • Style Guide
    • Sample Page
  • Contributors
  • Fundamentals
    • Mathematical Notation
    • Division and Greatest common divisor
      • Euclidean Algorithm
    • Modular Arithmetic
      • Theorems of Wilson, Euler, and Fermat
        • Fermat's Little Theorem in Detail
        • Euler's Theorem in Detail
      • Quadratic Residues
    • Continued Fractions
  • Number Theory
  • Ideals
  • Polynomials With Shared Roots
  • Integer Factorization
    • Pollard rho
    • Sieves
  • Abstract algebra
    • Groups
      • Another take on groups
      • Discrete Log Problem
    • Rings
    • Fields
    • Polynomials
  • Elliptic Curves
    • Untitled
  • Lattices
    • Introduction
    • LLL reduction
      • Gram-Schmidt Orthogonalization
      • Lagrange's algorithm
      • LLL reduction
    • Lattice reduction
      • Minkowski reduced
      • HKZ reduced
      • LLL reduced
    • Applications
      • Coppersmith algorithm
      • Extensions of Coppersmith algorithm
    • Hard lattice problems
    • Lattices of interest
    • Cryptographic lattice problems
      • Short integer solutions (SIS)
      • Learning with errors (LWE)
      • Ring-LWE
      • NTRU
    • Interactive fun
    • Resources and notations
  • Asymmetric Cryptography
  • RSA
    • Proof of correctness
    • RSA application
    • Low Private Component Attacks
      • Wiener's Attack
      • Boneh-Durfee Attack
    • Common Modulus Attack
    • Recovering the Modulus
  • Diffie-Hellman
    • MITM
  • Elliptic Curve Cryptography
  • Symmetric Cryptography
    • Encryption
    • The One Time Pad
    • AES
      • Rijndael Finite Field
      • Round Transformations
  • Hashes
    • Introduction / overview
    • The Birthday paradox / attack
  • Isogeny Based Cryptography
    • Introduction to Isogeny Cryptography
    • Isogenies
    • Isogeny and Ramanujan Graphs
  • Appendices
    • Sets and Functions
    • Probability Theory
Powered by GitBook
On this page
  • Overview
  • Optimality proof
  • Exercises

Was this helpful?

Export as PDF
  1. Lattices
  2. LLL reduction

Lagrange's algorithm

PreviousGram-Schmidt OrthogonalizationNextLLL reduction

Last updated 4 years ago

Was this helpful?

Overview

Lagrange's algorithm, often incorrectly called Gaussian reduction, is the 2D analouge to the Euclidean algorithm and is used for lattice reduction. Intuitively, lattice reduction is the idea of finding a new basis that consists of shorter vectors. Before going into Lagrange's algorithm, we first recap the Euclidean algorithm:

def euclid(m,n):
    while n!=0:
        q = round(m/n)
        m -= q*n
        if abs(n) > abs(m):
            m, n = n, m
    return abs(m)

The algorithm primarily consists of two steps, a reduction step where the size of mmmis brought down by a multiple of nnnand a swapping step that ensures mmmis always the largest number. We can adapt this idea for lattices:

def lagrange(b1,b2):
    mu = 1
    while mu != 0:
        mu = round((b1*b2) / (b1*b1))
        b2 -= mu*b1
        if b1*b1 > b2*b2:
            b1, b2 = b2, b1
    return b1, b2

Here μ\muμis actually the Gram-Schmidt coefficient μ2,1\mu_{2,1}μ2,1​and it turns out that this algorithm will always find the shortest possible basis! Using the basis

the Lagrange reduction looks like

and here we see it clearly gives the shortest vectors.

Optimality proof

Hence proving Lagrange's algorithm indeed gives us the shortest basis vectors.

Exercises

1) Show that the output of Lagrange's algorithm generate the same lattice as the input.

b1=(−1.8,1.2)b2=(−3.6,2.3)\begin{matrix} b_1&=&(-1.8,1.2)\\ b_2&=&(-3.6,2.3) \end{matrix}b1​b2​​==​(−1.8,1.2)(−3.6,2.3)​

Let LLLbe a lattice. The basis b1,b2b_1,b_2b1​,b2​is defined to be the shortest for any other basis b1′,b2′,∥b1′∥≤∥b2′∥b_1',b_2',\left\lVert b_1'\right\rVert\leq\left\lVert b_2'\right\rVertb1′​,b2′​,∥b1′​∥≤∥b2′​∥, we have ∥b1∥≤∥b1′∥\left\lVert b_1\right\rVert\leq\left\lVert b_1'\right\rVert∥b1​∥≤∥b1′​∥and ∥b2∥≤∥b2′∥\left\lVert b_2\right\rVert\leq\left\lVert b_2'\right\rVert∥b2​∥≤∥b2′​∥. Note that this generally cannot be generalized to other dimensions, however in dimension 2, this is possible and is given by Lagrange's algorithm. The proof is a somewhat messy sequence of inequalities that eventually lead to the conclusion we want.

Let b1,b2b_1,b_2b1​,b2​be the output of the Lagrange reduction for some lattice LLL. To prove that Lagrange reduction gives the shortest basis, we first show that ∥b1∥\left\lVert b_1\right\rVert∥b1​∥is the shortest vector in LLL.

We know that ∣⟨b1,b2⟩∣∥b1∥2≤12\frac{\left|\langle b_1,b_2\rangle\right|}{\left\lVert b_1\right\rVert^2}\le\frac12∥b1​∥2∣⟨b1​,b2​⟩∣​≤21​from the algorithm directly. Let v=mb1+nb2∈Lv=mb_1+nb_2\in Lv=mb1​+nb2​∈Lbe any element in LLL. We first show that ∥b1∥≤∥v∥\left\lVert b_1\right\rVert\leq\left\lVert v\right\rVert∥b1​∥≤∥v∥:

∥v∥2=∥mb1+nb2∥2=m2∥b1∥2+2mn⟨b1,b2⟩+n2∥b2∥2≥m2∥b1∥2−∣mn∣∥b1∥2+n2∥b1∥2=(m2−∣mn∣+n2)∥b1∥2\begin{align*} \left\lVert v\right\rVert^2&=\left\lVert mb_1+nb_2\right\rVert^2\\ &=m^2\left\lVert b_1\right\rVert^2+2mn\langle b_1,b_2\rangle+n^2\left\lVert b_2\right\rVert^2\\ &\geq m^2\left\lVert b_1\right\rVert^2-|mn|\left\lVert b_1\right\rVert^2+n^2\left\lVert b_1\right\rVert^2\\ &=\left(m^2-|mn|+n^2\right)\left\lVert b_1\right\rVert^2\\ \end{align*}∥v∥2​=∥mb1​+nb2​∥2=m2∥b1​∥2+2mn⟨b1​,b2​⟩+n2∥b2​∥2≥m2∥b1​∥2−∣mn∣∥b1​∥2+n2∥b1​∥2=(m2−∣mn∣+n2)∥b1​∥2​

Since m2−mn+n2=(m−n2)2+34n2m^2-mn+n^2=\left(m-\frac n2\right)^2+\frac34n^2m2−mn+n2=(m−2n​)2+43​n2, this quantity is only 000when m=n=0m=n=0m=n=0and is a positive integer for all other cases, hence ∥v∥≥∥b1∥\left\lVert v\right\rVert\geq\left\lVert b_1\right\rVert∥v∥≥∥b1​∥and ∥b1∥\left\lVert b_1\right\rVert∥b1​∥is a shortest vector of LLL. Note that we can have multiple vectors with the same norm as b1b_1b1​, for instance −b1-b_1−b1​. So this is not a unique shortest vector.

Suppose there exists some basis b1′,b2′b'_1,b'_2b1′​,b2′​for LLLsuch that ∥b1′∥≤∥b2′∥\left\lVert b_1'\right\rVert\leq\left\lVert b_2'\right\rVert∥b1′​∥≤∥b2′​∥. We show that ∥b2∥≤∥b2′∥\left\lVert b_2\right\rVert\leq\left\lVert b_2'\right\rVert∥b2​∥≤∥b2′​∥. Let b2′=mb1+nb2b_2'=mb_1+nb_2b2′​=mb1​+nb2​.

If n=0n=0n=0, then b2′=±b1b_2'=\pm b_1b2′​=±b1​as b1′,b2′b_1',b_2'b1′​,b2′​must form a basis. This means that ∥b1∥=∥b1′∥=∥b2′∥\left\lVert b_1\right\rVert=\left\lVert b_1'\right\rVert=\left\lVert b_2'\right\rVert∥b1​∥=∥b1′​∥=∥b2′​∥ and by the inequality above, we must have ±b1′=b2\pm b_1'=b_2±b1′​=b2​or ±b1′=b1+b2\pm b_1'=b_1+b_2±b1′​=b1​+b2​. The first case tells us that ∥b1′∥=∥b2∥\left\lVert b'_1\right\rVert=\left\lVert b_2\right\rVert∥b1′​∥=∥b2​∥. By squaring the second case, we get

∥b1′∥2=∥b1+b2∥2∥b1′∥2=∥b1∥2+2⟨b1,b2⟩+∥b2∥20=2⟨b1,b2⟩+∥b2∥2∥b1∥2≤∥b2∥2\begin{align*} \left\lVert b'_1\right\rVert^2&=\left\lVert b_1+b_2\right\rVert^2\\ \left\lVert b'_1\right\rVert^2&=\left\lVert b_1\right\rVert^2+2\langle b_1,b_2\rangle+\left\lVert b_2\right\rVert^2\\ 0&=2\langle b_1,b_2\rangle+\left\lVert b_2\right\rVert^2\\ \left\lVert b_1\right\rVert^2&\leq\left\lVert b_2\right\rVert^2\\ \end{align*}∥b1′​∥2∥b1′​∥20∥b1​∥2​=∥b1​+b2​∥2=∥b1​∥2+2⟨b1​,b2​⟩+∥b2​∥2=2⟨b1​,b2​⟩+∥b2​∥2≤∥b2​∥2​

but since ∥b1∥\left\lVert b_1\right\rVert∥b1​∥is the shortest vector, ∥b1∥=∥b2∥\left\lVert b_1\right\rVert=\left\lVert b_2\right\rVert∥b1​∥=∥b2​∥.

Otherwise, we have m,n≠0m,n\neq0m,n=0 and m2−mn+n2≥1m^2-mn+n^2\geq1m2−mn+n2≥1, so

∥b2′∥2=m2∥b1∥2+2mn⟨b1,b2⟩+n2∥b2∥2≥m2∥b1∥2−∣mn∣∥b1∥2+n2∥b2∥2=n2(∥b2∥2−∥b1∥2)+(m2−∣mn∣+n2)∥b1∥2≥(n2−1)(∥b2∥2−∥b1∥2)+∥b2∥2≥∥b2∥2\begin{align*} \left\lVert b'_2\right\rVert^2&=m^2\left\lVert b_1\right\rVert^2+2mn\langle b_1,b_2\rangle+n^2\left\lVert b_2\right\rVert^2\\ &\geq m^2\left\lVert b_1\right\rVert^2-|mn|\left\lVert b_1\right\rVert^2+n^2\left\lVert b_2\right\rVert^2\\ &=n^2\left(\left\lVert b_2\right\rVert^2-\left\lVert b_1\right\rVert^2\right)+\left(m^2-|mn|+n^2\right)\left\lVert b_1\right\rVert^2\\ &\geq\left(n^2-1\right)\left(\left\lVert b_2\right\rVert^2-\left\lVert b_1\right\rVert^2\right)+\left\lVert b_2\right\rVert^2\\ &\geq\left\lVert b_2\right\rVert^2 \end{align*}∥b2′​∥2​=m2∥b1​∥2+2mn⟨b1​,b2​⟩+n2∥b2​∥2≥m2∥b1​∥2−∣mn∣∥b1​∥2+n2∥b2​∥2=n2(∥b2​∥2−∥b1​∥2)+(m2−∣mn∣+n2)∥b1​∥2≥(n2−1)(∥b2​∥2−∥b1​∥2)+∥b2​∥2≥∥b2​∥2​

2) Find a case where ∥b1∥=∥b2∥=∥b1+b2∥\left\lVert b_1\right\rVert=\left\lVert b_2\right\rVert=\left\lVert b_1+b_2\right\rVert∥b1​∥=∥b2​∥=∥b1​+b2​∥. Notice that the vectors here is the equality case for the bound given in Exercise 4 of the introduction, this actually tells us that the optimal lattice circle packing in 2D is given by this precise lattice! It turns out that this is actually the optimal circle packing in 2D but the proof is significantly more involved. (See for the details)

3*) Let μ2,1=⌊μ2,1⌉+ε=μ+ϵ\mu_{2,1}=\lfloor\mu_{2,1}\rceil+\varepsilon=\mu+\epsilonμ2,1​=⌊μ2,1​⌉+ε=μ+ϵ, show that

∥b2∥2≥((∣μ∣−12)2−ε2)∥b1∥2+∥b2−μb1∥\left\lVert b_2\right\rVert^2\geq\left(\left(|\mu|-\frac12\right)^2-\varepsilon^2\right)\left\lVert b_1\right\rVert^2+\left\lVert b_2-\mu b_1\right\rVert∥b2​∥2≥((∣μ∣−21​)2−ε2)∥b1​∥2+∥b2​−μb1​∥

and show that ∣μ∣≥2|\mu|\geq2∣μ∣≥2for all steps in the algorithm except the first and last, hence ∥b1∥∥b2∥\left\lVert b_1\right\rVert\left\lVert b_2\right\rVert∥b1​∥∥b2​∥decreases by at least 3\sqrt33​ at each loop and the algorithm runs in polynomial time.

https://arxiv.org/abs/1009.4322