Decoding Cryptographic Security: GCD, AGCD, and Lattice Attacks

Tejaaswini Narendra
7 min readJun 17, 2024

--

Part 1: Exploring the Foundations: GCD, AGCD, and their Cryptographic Significance

The Greatest Common Divisor (GCD) is a fundamental concept in cryptography, ensuring the security and integrity of algorithms like RSA (Rivest, Shamir, Adleman). It aids in key generation and ensures the co-primality of numbers. The Approximate Greatest Common Divisor (AGCD) extends this concept to scenarios involving noisy data. It also plays a crucial role in fully homomorphic encryption (FHE) by enabling operations on encrypted data without decryption. This maintains data privacy as well as security.

This article series explores the foundational concepts of GCD and AGCD and their critical roles in cryptography, followed by an in-depth analysis of lattice attacks. It aims to provide a comprehensive understanding of how these mathematical principles underpin cryptographic security and how lattice reduction techniques can be employed to compromise certain cryptographic schemes, highlighting both the theoretical and practical aspects.

Basics of GCD

The textbook definition of GCD is that,
Let a, b be integers, not both zero. The largest integer that divides
both a and b is called the greatest common divisor
of a and b.

Notation: gcd(a, b).

What does that mean!? GCD is the largest number that divides two numbers without leaving a remainder. Using the Euclidean algorithm, we repeatedly take remainders until one number becomes zero. Simple isn’t it?

Let’s see an example of finding GCD using the Euclidean Algorithm which says that

The GCD of a and b can be computed using the Euclidean algorithm, which is based on the principle that

gcd(a,b)=gcd(b ,a%b) , where mod (%) denotes the remainder of the division of a by b.

The algorithm works as follows:
gcd(a,b)=gcd(b,r) , where where r=a%b. Repeat the process until r=0

example of a simple GCD function
Function Definition:
The function gcd(a, b) takes two numbers, a and b, as input.

Base Case:
The function first checks if b is 0.
If b is 0, the function returns the absolute value of a.
This is because the GCD of any number and 0 is the number itself.

Recursive Case:
If b is not 0, the function calls itself with b and the
remainder of a divided by b (a % b). This step repeats until b becomes 0.

Example:
Given a = 60 and b = 48, the function gcd(a, b) is called.
The function calculates the GCD of 60 and 48, which is 12.


Step-by-Step Calculation
For a = 60 and b = 48:

First Call:
gcd(60, 48)
Since b is not 0, we calculate gcd(48, 60 % 48),
which is gcd(48, 12).
Second Call:
gcd(48, 12)
Again, b is not 0, so we calculate gcd(12, 48 % 12),
which is gcd(12, 0).
Third Call:
gcd(12, 0)
This time, b is 0, so we return the absolute value of a, which is 12.

So what makes GCD fascinating? It is the ability to solve complex problems into simpler parts that makes GCD captivating. It is crucial in many real-life applications such as solving certain mathematical puzzles and in cryptography where it helps in securing information by ensuring numbers work well with complex algorithms. We shall discuss how GCD works with RSA in the upcoming sections.

Too theoretical? Thinking where exactly it is used in real life? Its applications range from key generation in RSA to ensuring the security of ECC and the Diffie-Hellman key exchange. Understanding and utilizing the GCD is essential for designing robust cryptographic protocols. Let’s explore how it is used in these examples.

  1. Key Generation in RSA
    - used to ensure that the public exponent ‘e’ is in coprime with
    Φ(n) = (p-1)*(q-1).
    - to ensure gcd(e,Φ(n))=1 is vital for security of RSA as it guarantees the existence of the modular inverse of e, which is used to compute the private key d.
  2. Simplifying Modular Inverses
    GCD is used to compute the modular inverse of a number, which is an essential operation in many cryptographic protocols.
  3. Parameter Selection in Diffie-Hellman Key Exchange
    -
    GCD ensures the security of the Diffie-Hellman key exchange protocol by ensuring that the chosen base g and the modulus p are appropriately related to prevent small subgroup attacks.
    - this requires selecting a prime number p and base g such that the order of g%p is a large prime factor of p-1.
    - as discussed earlier, to improvise randomness we introduce small perturbations (errors), called noise, to the multiples of the common divisor. This makes it difficult to identify the common divisor, thereby adding complexity to cryptographic schemes. The addition of moise to GCD makes it an AGCD problem.
  4. Point Multiplication in Elliptic Curve Cryptography (ECC)
    In ECC, point multiplication involves repeated addition of a point on an elliptic curve and GCD ensures that the chosen parameters does not lead to cases where the curve operations fail.

The Concept of Approximate Greatest Common Divisor (AGCD)

Now that we’ve a general idea of GCD, it is important to know that GCD can break RSA with poor randomness. In order to avoid this we introduce what is called ‘noise’. Noise refers to adding a small random perturbations or errors to the multiples of the common divisor. So why is noise important? Because it adds complexity to the cryptographic schemes by making it difficult to identify the common divisor. This adding of noise to GCD makes it an AGCD problem. This makes the problem hard against any attack.

It is a problem of finding a common divisor of several integers that have been perturbed by a small random error.

Mathematically is can be defined as,

AGCD is considered as IND-CPA secure (IND-CPA — Ciphertext indistinguishability under Chosen Plaintext Attack), meaning that an attacker who can choose plaintexts and obtain their corresponding ciphertexts cannot distinguish between the ciphertexts of two chosen plaintexts. This security is achieved due to the hardness of the AGCD problem, where the added noise makes it computationally infeasible for an attacker to determine the underlying common divisor or decrypt the ciphertexts without the secret key. The noise effectively obfuscates the relationship between the plaintext and ciphertext even under chosen plaintext attacks.

Let’s looks at the difference between GCD and AGCD

Applications of AGCD in Cryptography — Fully Homomorphic Encryption aka FHE

Homomorphic Encryption (HE) it is a form of encryption that allows computations to be performed on encrypted data without needing to decrypt it first. This property enables secure data processing and analysis in applications where data privacy is crucial.

FHE is a type of Homomorphic Encryption that allows arbitrary computations on encrypted data, producing an encrypted result that, when decrypted, matches the outcome of operations performed on the plaintext. FHE supports both addition and multiplication operations on ciphertexts, enabling complex, secure data processing without exposing sensitive information. This is ideally useful for cloud computing and privacy-preserving applications.

FHE relies in the hardness of the AGCD problem. There are various FHE schemes (for example DGHV — Dijk, Gentry, Halevi, Vaikuntanathan) where the cipher texts are formed by adding a small noise to multiples of a secret key. Thus making it difficult to determine the secret key without having any knowledge of the noise value.

It is mathematically represented as,

Solving the AGCD Problem

AGCD can be solved in two ways — Exhaustive Search Approach or Time-Memory Trade-Off.

Below is a small snippet to solve the AGCD problem using a simple approach. This example demonstrates how you might use the Euclidean algorithm to guess and check possible noise values.

example of solving the AGCD problem

In simple terms:

  • gcd Function: Implements the Euclidean algorithm to compute the greatest common divisor of two integers.
  • solveAGCD Function: Tries to solve the AGCD problem by exhaustively searching through possible noise values (r0, r1) within the range determined by the noise level λ.
  • For each pair of noise values, it computes the GCD of the adjusted integers.
  • If a common GCD is found across all integers, it returns this value as the approximate GCD.
  • If no solution is found, it returns -1.
  • main Function: Provides an example usage of the solveAGCD function with noisy integers and a noise level λ.

Conclusion

In this article, we explored the concepts of GCD and AGCD, highlighting their significance in cryptography. The GCD, or Greatest Common Divisor, is essential for many cryptographic algorithms, but its limitations are addressed by introducing noise, leading to the AGCD, or Approximate Greatest Common Divisor, problem. AGCD adds complexity and enhances security by making it harder to find the common divisor, even with quantum computers. We also discussed applications of AGCD in cryptographic schemes like Fully Homomorphic Encryption (FHE) and provided a practical approach to solving the AGCD problem using C++. Understanding the mathematical foundations of GCD and AGCD is crucial for developing and analyzing secure cryptographic schemes.

What’s in Part 2?

In the next part of this series, we will delve into the fascinating world of lattice attacks, a powerful cryptanalytic tool used to break various cryptographic schemes. We’ll explore how lattice-based methods can solve complex problems like the AGCD, revealing vulnerabilities in encryption systems that rely on their supposed hardness. From understanding the mathematical structure of lattices to examining specific algorithms like the LLL (Lenstra–Lenstra–Lovász) algorithm, Part 2 will equip you with insights into the mechanisms and implications of lattice attacks in modern cryptography.

Stay tuned to uncover how these techniques challenge the security of cryptographic schemes and learn about the strategies used to defend against them.

--

--

Tejaaswini Narendra
Tejaaswini Narendra

Written by Tejaaswini Narendra

Where’s the fun without some challenge?

No responses yet