Cryptography

Cards (12)

  • Diffie-Hellman Key Exchange
    • The Diffie-Hellman key exchange, named after its inventors Whitfield Diffie and Martin Hellman, is a crucial concept in modern cryptography.
    • It allows two parties to establish a shared secret key over an insecure communication channel without ever exchanging the key itself.
    • This is accomplished by leveraging the properties of modular arithmetic and the computational complexity of discrete logarithm problems.
  • DHKE: Common Base Potion
    • To begin the exchange, Alice and Bob must agree on an arbitrary starting (shared) potion that does not need to be kept secret. 
    • They each start by brewing a special base potion in their cauldrons, which are publicly known and form the foundation for their magical key exchange.
    • The ingredients in this base mixture refer to the selection of the prime modulus (p), typically a very large prime number, and the base (g), which are part of the Diffie-Hellman parameters. It's essential that they are known to both parties to generate the foundational criteria of the exchange.
  • DHKE: Common Base Potion: Generating DH Params
    • In this case, we've chosen a key size (prime modulus length) of 2048 bits; a longer key size generally offers greater security but requires more computational resources.
    • This step is typically performed by a certificate authority, but for the sake of this example, let's assume Alice and Bob are generating their parameters. Parameter generation is CPU expensive and is, therefore, generally done in advance.
  • DHKE: Secret Potions
    • In the next step of the exchange, Alice and Bob each create their secret potions using their own secret ingredients. These secret (private) potions are kept confidential and are never exchanged.
    • The secret potions in this step correspond to the private keys for Alice (a) and Bob (b). These private keys are made up of large random numbers, which are always kept secret.
    • These commands generate the alice_private.pem and bob_private.pem key pairs using the dhparams.pem parameters generated previously.
  • Public Potions
    • Finally, Alice and Bob combine their secret potion together with the common base potion. This process is like that of a one-way function. Combining two potions to create a mixed brew is trivial.
    • However, given a mixed potion, it is difficult (and very time-consuming) to determine which potions (or ingredients) went into the mixture. As a result, the obtained mixed potions are safe for public exchange and are treated as public keys.
  • Public Potions
    In this step, Alice and Bob's public potions are calculated using modular exponentiation.
    • Alice calculates Alice's public key (A) using the following formula:
    • A = (ga) % p
    • Bob calculates Bob's public key (B) using the same formula:
    • B = (gb) % p
    In the above calculations, Alice and Bob take the chosen base (g) and raise it to the power of their private key a or b. Alice and Bob then take the result of that operation and calculate its remainder when divided by the prime number (p). The modulo operation (%) ensures the result is above 0 and below p.
  • Public Potions
    • Given the nature of modular arithmetic, it is, as a result, very difficult to reverse the calculation and determine what a or b are, respectively.
    • The above commands take the user's private key and generate the corresponding public key, which can now be exchanged via insecure means (like the Internet) without concern.
    • Next, Alice and Bob will exchange their public keys to complete the final calculation to derive the same shared secret.
  • Shared Secret Potions
    • After the exchange, Alice and Bob combine the other person's public potions and their own private potions to compute the shared secret potion. The shared secret potion (key) in this step is calculated using modular exponentiation, deriving the same result for Alice and Bob.
    • Alice calculates the shared secret key (s) by taking Bob's public key (B), raising it to the power of her private key (a), and then taking the result modulo p: s = (Ba) % p
    • and vice versa
  • Shared Secret Potions
    • As a result, Alice and Bob have arrived at the same answer despite the fact that neither of them knew each other's private key.
  • Eve (Eavesdropper)
    • Eve can see the prime modulus (p), the base (g), and even the exchanged public potions (A and B). However, she cannot peek into the cauldrons to know the private potions (Alice's secret and Bob's secret), which are the most critical ingredients for creating the shared secret.
    • Without these private potions, it's impossible for Eve to recreate the shared secret potion.
    • Mathematically, this is because calculating the shared secret requires calculating a discrete logarithm problem. G
  • Encryption and Decryption Operations
    • It is important to note that Diffie-Hellman is simply a key exchange protocol, not an encryption algorithm. On its own, Diffie-Hellman doesn't provide encryption or decryption capabilities, but it is often used in conjunction with other cryptographic algorithms, such as AES (Advanced Encryption Standard), to secure data transmission.
    • penSSL not only supports the implementation of Diffie-Hellman key exchange but also offers the ability to encrypt and decrypt data using symmetric keys.
  • Encryption and Decryption Operations
    • In The Witch's Cauldron, Alice and Bob use their shared secret potion to keep their recipe safe from Eve. First, Bob "encrypts" the recipe by dipping it into the cauldron containing the shared secret mixture. This results in a potion that looks like a jumbled mess, nothing like the original recipe. After which, Bob can safely share this with Alice, even with Eve watching.
    • Next, Alice, the recipient, can privately "decrypt" and uncover the original recipe since she has the same shared secret potion.