initializeDiffieHellman method

void initializeDiffieHellman(
  1. int kexMethod,
  2. Random random
)

Implementation

void initializeDiffieHellman(int kexMethod, Random random) {
  if (KEX.x25519DiffieHellman(kexMethod)) {
    kexHash = SHA256Digest();
    x25519dh.generatePair(random);
  } else if (KEX.ellipticCurveDiffieHellman(kexMethod)) {
    kexHash = KEX.ellipticCurveHash(kexMethod);
    ecdh = EllipticCurveDiffieHellman(
        KEX.ellipticCurve(kexMethod), KEX.ellipticCurveSecretBits(kexMethod));
    ecdh.generatePair(random);
  } else if (KEX.diffieHellmanGroupExchange(kexMethod)) {
    if (kexMethod == KEX.DHGEX_SHA1) {
      kexHash = SHA1Digest();
    } else if (kexMethod == KEX.DHGEX_SHA256) {
      kexHash = SHA256Digest();
    }
  } else if (KEX.diffieHellman(kexMethod)) {
    if (kexMethod == KEX.DH14_SHA1) {
      dh = DiffieHellman.group14();
    } else if (kexMethod == KEX.DH1_SHA1) {
      dh = DiffieHellman.group1();
    }
    kexHash = SHA1Digest();
    dh.generatePair(random);
  } else {
    throw FormatException('unknown kex method: $kexMethod');
  }
}