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:
-
GenerateKeypair()-> generates an X25519 public and private key pair -
SharedSecret()-> takes private key and peer public key and performs ECDH using those keys -
ComputePSKProof()-> outputs the HMAC result of a psk and the given data -
DeriveSessionKey()-> the final function which uses HKDF and outputs a session key, which will be used to encrypt/decrypt -
Encrypt()-> encrypts using the given session key, it uses ChaCha20-Poly1305 to encrypt plaintext -
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
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.