Notes - MCS
Applied Cryptography
Notes - MCS
Applied Cryptography
  • Applied Cryptography
  • Classical (Symmetric) Cryptography
    • Terminology
    • The Players
    • Use Cases
    • Information-Theoretic Security
    • Computational Security
    • Cryptanalysis
    • Practical Approaches
    • Cryptographic Robustness
    • Ciphers
      • Mono-Alphabetic
      • Polylphabetic
    • Rotor Machines
    • Stream Ciphers
  • Modern Symmetric Cryptography
    • Types
    • Symmetric Ciphers
    • Symmetric Block Ciphers
    • Feistel Networks
    • DES (Data Encryption Standard)
    • AES (Advanced Encryption Standard)
    • Stream Ciphers
    • Uniform Random Access
    • Linear Feedback Shift Register (LFSR)
  • Cipher Modes
    • Deployment of (Symmetric) Block Ciphers
    • Stream Cipher Modes
    • Security Reinforcement
  • Cryptographic Hashing
    • Digest functions
    • Rainbow Tables
    • Message Authentication Codes (MAC)
    • Authenticated Encryption
    • Encryption + Authentication
  • RSA & Related Subjects
    • Modular Arithmetic
    • Fast Modular Multiplication
    • The Extended Euclid's Algorithm
    • Linear Maps
    • Fermat's Little Theorem
    • Chinese Remainder Theorem
    • Fermat's Little Theorem
    • Modular Exponentiation
    • Multiplicative Order
    • The Discrete Logarithm Problem
    • Primality tests
    • The Diffie-Hellman Key Exchange Protocol
    • ElGamal Public Key Cryptosystem
    • The Rivest-Shamir-Adleman Cryptosystem
    • Finite Fields
    • Elliptic Curves
    • Diffie-Hellman using elliptic curves
    • Can we do RSA-like things with elliptic curves?
    • The discrete logarithm problem for elliptic curves
    • Secret sharing
    • Quadratic Residues
    • Zero-Knowledge proofs
      • One of two oblivious transfer
      • Coin flipping
      • Zero-knowledge proofs of identity
    • Homomorphic encryption
  • Asymmetric Key Management
    • Design Principles
    • Exploitation of private keys
    • Distribution of public keys
    • Public key (digital) certificates
    • Key pair usage
    • Certification Authorities (CA)
    • Certification Hierarchies
    • Refreshing of asymmetric key pairs
    • Certificate revocation lists (CRL)
    • Validity of signatures
    • Distribution of public key certificates
    • Time Stamping Authority (TSA)
    • PKI (Public Key Infrastructure)
  • Digital Signatures
    • Fundamental Approach
    • Signature Schemes
    • Key Elements
    • The document to sign
    • The signature date
    • The identity of the signatory
    • Optional elements of a digital signature
    • Algorithms
    • RSA signatures
    • ASN.1 digest algorithm prefixes
    • Digital Signature Standard (DSS)
    • Blind Signatures
    • Chaum Blind Signatures
    • Qualified electronic signature
      • Signature devices
    • PKCS #11
    • Microsoft Cryptographic API (CAPI)
    • Long-Term Validation (LTV)
    • LTV Advanced Electronic Signatures (AdES)
Powered by GitBook
On this page
  1. RSA & Related Subjects

Primality tests

Last updated 1 year ago

One way to prove that a given number mmm is prime is to find one of its primitive roots.

Choose a random aaa between 222 and m−2m-2m−2.

If gcd(a.m)≠1gcd(a.m) \ne 1gcd(a.m)=1, then mmm is not prime. Better yet, the greatest common divisor allows us to partially factor mmm.

By Fermat's little theorem, we know that am−1≡1modma^{m-1} \equiv 1 mod mam−1≡1modm. If this is not so, then definitely mmm is not prime.

Furthermore, when mmm is an odd number, we must have either a(m−1)/2≡1modma^{(m-1)/2} \equiv 1 mod ma(m−1)/2≡1modm or a(m−1)/2≡−1modma^{(m-1)/2} \equiv -1modma(m−1)/2≡−1modm.

Now, it can be shown that aaa is a primitive root modulo mmm if, for every prime divisor ddd of m−1m-1m−1, we have a(m−1)/dmodm≠1a^{(m-1)/d} mod m \ne 1a(m−1)/dmodm=1. If aaa satisfies these conditions then the order of aaa modulo mmm must be m−1m-1m−1, and thus mmm must be prime.

If not, try another aaa.

These exist composite numbers, called Carmichael numbers, for which am−1modm=1a^{m-1}mod m = 1am−1modm=1 for all aaa which are relatively prime to mmm. For these numbes, λ(m)∣(m−1)\lambda(m) \mid (m-1)λ(m)∣(m−1).

The Miller-Rabin primality test

Goal: to test if the odd number nnn, with n>3n \gt 3n>3, is a prime number or not.

Result of the test: either nnn is not prime or it may be prime (a probable primer number); in the second case, the probability that the test fails to identify a composite number is at most 0.25.

How it is done (to increase confidence on the result, do steps 2 to 6 several times):

  1. Let n−1n-1n−1 be written as n−1=2rdn-1 = 2^rdn−1=2rd, with ddd an odd number (so rrr is as large as possible).

  2. Select at random an integer aaa uniformly distributed in the interval 2≤a≤n−22\le a \le n-22≤a≤n−2.

  3. If gcd(a,n)≠1gcd(a,n) \ne 1gcd(a,n)=1, then nnn is definitely a composite number.

  4. Compute x0=admodnx_0 = a^d mod nx0​=admodn. If x0=1x_0 = 1x0​=1 or x0=n−1x_0 = n -1x0​=n−1 then nnn is a probale prime.

  5. Otherwise, for k=1,2,...,d−1k = 1, 2, ..., d-1k=1,2,...,d−1, compute xk=xk−12modnx_k = x²_{k-1} mod nxk​=xk−12​modn. If xk=n−1x_k = n - 1xk​=n−1 then nnn is a probable prime.

  6. Finally, if we get here, say that nnn is definitely a composite number (because Fermat's little theorem failed because a(m−1)/2≡±1modma^{(m-1)/2} \equiv \pm 1 modma(m−1)/2≡±1modm).

The composite numbers that pass this test (meaning that the algorithm above says that they are probable primes) for a given aaa are called base-aaa strong pseudo-primes.