Skip to content

aameen951/diffie-hellman-experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

An experiment with Elliptic Curve Diffie-Hellman (ECDH) Key Exchange as a simple way for implementing end-to-end encryption.

How to Use

  1. Initialize the server:
node main init-server
  1. Create users that will communicate with each other:
node main init-user alice
node main init-user bob
  1. Send a message from alice to bob:
node main send alice bob "Hello"
  1. View the mailbox for bob:
node main send alice bob "Hello"

How does it works?

The init-server command will create server.json file. This file contains the public keys and the mailbox for all the users. This file represents the database that will be used if this was a real server.

The init-user command will create a separate <user>.json file per user that will contains the private key and public key for that user. This file represents the data stored in the user device that doesn't need/mustn't be shared with the server.

The send command will take the sender, the receiver, and the message and will do the following:

  1. read the private key of the sender from <sender>.json as Senderprivate.

    Note: the send command can read <sender>.json but not <receiver>.json because in reality, the encryption process happen on the sender device.

  2. Get the public key of the receiver from server.json as Receiverpublic.

  3. Compute the shared secret:

    SS = ECDH(Senderprivate, Receiverpublic)

  4. Derive a key from the shared secret using HKDF (HMAC Key Derivation Function):

    K = HKDF(SS)

  5. Generate random IV using a secure random byte generator IV.

  6. Encrypt the message using AES-256-GCM with the resulting key:

    C = ENCRYPT(K, IV, M)

  7. Mail the encrypted message C, IV, and receiver to the server.

  8. The server will store the received message in the mailbox for the receiver.

The mailbox command will do the following:

  1. Get all the encrypted messages for the user from the mailbox.

  2. Read the private key for the user from the file <user>.json as Receiverprivate.

  3. For each message in the mailbox do the following steps:

    1. Get the public key for the sender from the server as Senderpublic

    2. Compute the shared secret:

      SS = ECDH(Receiverprivate, Senderpublic)

    3. Derive a key from the shared secret using HKDF (HMAC Key Derivation Function):

      K = HKDF(SS)

    4. Decrypt the message using the resulting key:

      M = DECRYPT(K, IV, C)

Resources

Command List

 Usage:

   node main init-server
        Initialize the server.

   node main init-user <user-name>
        Create a new user.

   node main send <from> <to> <message>
        Send an encrypted message.

   node main mailbox <for-user>
        Get and decrypt all messages for specified user.

   node main clear-mailbox <for-user>
        Delete all messages for specified user.

About

An experiment with Elliptic Curve Diffie-Hellman (ECDH) Key Exchange as a simple way for implementing end-to-end encryption.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors