/// <summary> /// Computes the client session value /// </summary> public static byte[] ComputeClientSessionValue(byte[] serverPublicEphemeral, byte[] xdata, byte[] udata, byte[] clientPrivateEphemeral) { // (B - kg^x) ^ (a + ux) (mod N) var B = new NetBigInteger(NetUtility.ToHexString(serverPublicEphemeral), 16); var x = new NetBigInteger(NetUtility.ToHexString(xdata), 16); var u = new NetBigInteger(NetUtility.ToHexString(udata), 16); var a = new NetBigInteger(NetUtility.ToHexString(clientPrivateEphemeral), 16); var bx = g.ModPow(x, N); var btmp = B.Add(N.Multiply(k)).Subtract(bx.Multiply(k)).Mod(N); return btmp.ModPow(x.Multiply(u).Add(a), N).ToByteArrayUnsigned(); }
/// <summary> /// Compute server ephemeral value (B) /// </summary> public static byte[] ComputeServerEphemeral(byte[] serverPrivateEphemeral, byte[] verifier) // b { var b = new NetBigInteger(NetUtility.ToHexString(serverPrivateEphemeral), 16); var v = new NetBigInteger(NetUtility.ToHexString(verifier), 16); // B = kv + g^b (mod N) var bb = g.ModPow(b, N); var kv = v.Multiply(k); var B = (kv.Add(bb)).Mod(N); return B.ToByteArrayUnsigned(); }