You are browsing as a guest. Sign up (or log in) to start making projects!

2h 53m 38s logged

Crypto Functions

so i wrote all the crypto functions or helpers whatever you want to call it.
i did that because see for me TLS or even this project is just a group of cipher suites and we are using them to perform a handshake, so the cipher suite is the most important part, and ofc my project will only have one cipher suite, so i first implemented those functions


Functions implemented:

  1. GenerateKeypair() -> generates an X25519 public and private key pair
  2. SharedSecret() -> takes private key and peer public key and performs ECDH using those keys
  3. ComputePSKProof() -> outputs the HMAC result of a psk and the given data
  4. DeriveSessionKey() -> the final function which uses HKDF and outputs a session key, which will be used to encrypt/decrypt
  5. Encrypt() -> encrypts using the given session key, it uses ChaCha20-Poly1305 to encrypt plaintext
  6. Decrypt() -> decrypts the ciphertext from given key

and i also wrote tests for them, writing tests for me is an uncommon thing i wont lie lol but this time i am testing these functions from tests is because this is a protocol library, if another project wants to use my protocol to build on they can easily import and thats why i dont wanna test in random cmd and build things like it is intended for my planned project only, so i am treating it as a proper library and writing function and their tests, and so far things are doing really good.
had some problems in ECDH because i was messing up the output parameters order but i fixed it after a while.


ignore the weird ahhh numbers output, thats the nonce counter helper function i made i forgot to remove the debug prints lol

1
11

Comments 0

No comments yet. Be the first!