Diffie-Hellman Key Exchange

This article focuses about the famous Diffie-Hellman Key Exchange

In the case of symmetric keys in cryptography, you need a key exchange to encrypt or decrypt stuff by its definition. One of the famous key exchange algorithms is the Diffie-Hellman Key Exchange. Let's start.

Algorithm:

So, here there are three areas, for this blog let's say there are two users A and B want to exchange some information. So, there are three areas, A has its own area, which is private to A only, public area and B can't see or sneak into what A is doing. B has its own area, which is private to B only, a public area, and A can't see or sneak into what B is doing. And, public area, which is public to all, attackers and to both A and B.

Step 1: Both A and B are now ready to share information. They will use symmetric keys to encrypt and decrypt the messages. Remember, here they use the "shared secrets" not the key. First, they choose a generator, g, and a really large prime number(2048 bits) p, notice I wrote 2048 bits, which is equal to

$$No. of digits= \lfloor(log_{10}p) + 1\rfloor$$

So, here p is in the range

$$2^{2048} - 1$$

So, no. of digits is approx 617

$$No. of digits = \lfloor1 + 2048 * log10(2)\rfloor \approx 617$$

The reason why the prime number is chosen is cause it can't be decomposed into its factors like 100 can be decomposed into 50 or even small numbers. Think of the p-like marks on a clock where if you find the remainder of any number by the p it will be one of the marks in that clock. So, here remainder means "mod". Now, why is it not bigger than 2048? because it will lose its efficiency.

Step 2: Now both A and B access those values that they have agreed together ( g and n). Now A chooses a key called "a" which is private, and visible to no one. B chooses a key called "b" which is private, visible to no one. Then, they perform an operation like this,
For A,

$$X=g^a mod p$$

For B,

$$Y=g^b modp$$

Step 3: Now, both X and Y are shared publicly and A gives Y to B, and B gives X to A or they are being publicly accessed. Now they raise the shared value to the power of a (in the case of A) and b (in the case of B),

In the case of A, it is equal to,

$$X^amodp$$

In the case of B, it is equal to,

$$Y^bmodp$$

Now both give,

$$g^{ab}modp$$

And now, this is the shared secret.
It's more secure and can't be derived down even if you multiply two values X and Y you will get the g raised to the power (a+b) which is not equal to a*b.

So, this is about the Diffie-Hellman Key Exchange.

Sources used: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange

N.B.: If you find anything wrong/typos, please comment below, I will edit ASAP.

Thank you.

Did you find this article valuable?

Support Tausiq's Blogs by becoming a sponsor. Any amount is appreciated!