Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Jan 16, 2025
1 parent a436189 commit 98fafea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/docs/supreme.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ signer.keyAgreement(publicKey) {
}
```

!!! tip inline end
If you have an EC private key and know the curve, you already know the public key!
Hence, requiring the public keys of both parties for an ECDH key agreement is, in fact, a non-issue.

Even though key agreement uses the private key of one party and the public key of another, the `keyAgreement` function
is only implemented for `CryptoPrivateKey.WithPublicKey<CryptoPublicKey.EC>`. I.e., both public keys need to be known.
This is necessary to assure that both keys lie on the same curve and are indeed compatible.<br>



## Digest Calculation
The Supreme KMP crypto provider introduces a `digest()` extension function on the `Digest` class.
For a list of supported algorithms, check out the [feature matrix](features.md#supported-algorithms).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ suspend fun CryptoPublicKey.EC.keyAgreement(
/**
* Elliptic-curve Diffie-Hellman key agreement.
* Curves of public key and signer need to match!
* This only works if both public keys are known, because otherwise, it is impossible
* to assure that both keys lie on the same curve.
*/
suspend fun CryptoPrivateKey.WithPublicKey<CryptoPublicKey.EC>.keyAgreement(publicKey: CryptoPublicKey.EC) =
(SignatureAlgorithm.ECDSA(this.publicKey.curve.nativeDigest, this.publicKey.curve)
Expand All @@ -52,6 +54,8 @@ suspend fun CryptoPrivateKey.WithPublicKey<CryptoPublicKey.EC>.keyAgreement(publ
/**
* Elliptic-curve Diffie-Hellman key agreement.
* Curves of public key and signer need to match!
* This only works if both public keys are known, because otherwise, it is impossible
* to assure that both keys lie on the same curve.
*/
suspend fun CryptoPublicKey.EC.keyAgreement(privateKey: CryptoPrivateKey.WithPublicKey<CryptoPublicKey.EC>) =
privateKey.keyAgreement(this)
Expand Down

0 comments on commit 98fafea

Please sign in to comment.