diffieHellman static method

Uint8List diffieHellman(
  1. List<int> secretKey,
  2. List<int> publicKey
)

Computes X25519(secretKey, publicKey).

Throws TspDecryptionException when the result is all zero, which happens exactly when publicKey is a small-order point (RFC 7748 §6.1, RFC 9180 §7.1.4).

Implementation

static Uint8List diffieHellman(List<int> secretKey, List<int> publicKey) {
  _checkLength(secretKey, 'secret key');
  _checkLength(publicKey, 'public key');
  final out = TweetNaCl.crypto_scalarmult(
    Uint8List(keyLength),
    Uint8List.fromList(secretKey),
    Uint8List.fromList(publicKey),
  );
  checkContributory(out);
  return out;
}