Ecka Key Agreement
marekbilek.cz - 9.4.2021You can only use EVP_PKEY types that support key agreements (currently only DH and ECDH). In the example of code above the common secret, it must be clearly „liberated“ with OPENSSL_free as soon as it is no longer needed. We use an example of the key ECDH protocol. The first step is to start it with our private key. Then we hand over the public key of the other part on the doPhase method (). We present the second argument that this is the last phase of the agreement (this is the only phase of the ECDH). Diffie-Hellman calculates a common secret based on our private key and the other party`s public key, so that`s all we need in this case. The magic of DH is that each party calculates the same value, although they have different sets of keys at their disposal. No one who listens to the exchange can calculate the common secret, unless they have access to one of the private keys (which are never disclosed). The Elliptic-Curve Diffie-Hellman (ECDH) is an important Memorandum of Understanding that allows two parties, each with a pair of public-private keys with an elliptical curve, to create a common secret on an uncertain channel. [1] [2] [3] This common secret key can be directly used as a key or derive another key. The key or derived key can then be used to encrypt subsequent communication with a chiphiffre key.
It is a variant of the Diffie-Hellman protocol with elliptical cryptography. The most important agreement is the process of a common secret agreement between two peers. For example, if Alice and Bob want to communicate, Alice can calculate the common secret using her private key and Bob`s public key with a key chord function, such as Diffie-Hellman (DH) or Elliptic Curve Diffie-Hellman (ECDH). Similarly, Bob can calculate the same common secret with his own private key and Alice`s public key. This common secret key can then serve as the basis for a key for a symmetrical encryption algorithm. The key ECDH agreement is simple once we have exchanged public keys. We take the approach described in the libnatrium documentation, which is to deflect a key by hating the common secret and the two public keys, but using SHA-256 instead of BLAKE2. This choice of algorithms and curves is simple because it is readily available on JVM without third-party libraries (z.B. Bouncy Castle).
The only trick is to make sure that we inject the public keys into the hash in the same order on either side of the MOU.