ecdh test

This commit is contained in:
2025-02-19 16:01:20 +01:00
parent 7732504136
commit 2fe9b83876
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,15 @@
// X25519 aka ECDH on Curve25519 from [RFC7748](https://www.rfc-editor.org/rfc/rfc7748)
import { x25519 } from '@noble/curves/ed25519';
export function genKeys() {
const priv = x25519.utils.randomPrivateKey();
const pub = x25519.getPublicKey(priv);
return {
privkey: priv,
pubkey: pub
};
}
export function sharedKey(priv, pub) {
return x25519.getSharedSecret(priv, pub);
}