scalarMult static method

List<int> scalarMult(
  1. List<int> scalar,
  2. List<int> uBytes
)

Perform scalar multiplication with an arbitrary public key (u-coordinate). Returns the shared secret.

Implementation

static List<int> scalarMult(List<int> scalar, List<int> uBytes) {
  if (scalar.length != Ed25519KeysConst.privKeyByteLen) {
    throw ArgumentException.invalidOperationArguments(
      "scalarMultBase",
      name: "scalar",
      reason: 'Incorrect scalar bytes length.',
    );
  }
  if (uBytes.length != Ed25519KeysConst.pubKeyByteLen) {
    throw ArgumentException.invalidOperationArguments(
      "scalarMultBase",
      name: "uBytes",
      reason: 'Incorrect public key bytes length.',
    );
  }
  final clamped = _clampScalar(scalar);
  final u = BigintUtils.fromBytes(uBytes, byteOrder: Endian.little);
  if (u >= X25519KeyConst.p) {
    throw CryptoException.failed("scalarMult", reason: "Invalid public key.");
  }
  return _montgomeryLadder(clamped, u);
}