/// <summary> /// Compute client public ephemeral value (A) /// </summary> public static byte[] ComputeClientEphemeral(byte[] clientPrivateEphemeral) // a { // A= g^a (mod N) NetBigInteger a = new NetBigInteger(NetUtility.ToHexString(clientPrivateEphemeral), 16); NetBigInteger retval = g.ModPow(a, N); return(retval.ToByteArrayUnsigned()); }
public static byte[] ComputeServerSessionValue(byte[] clientPublicEphemeral, byte[] verifier, byte[] udata, byte[] serverPrivateEphemeral) { // S = (Av^u) ^ b (mod N) var A = new NetBigInteger(NetUtility.ToHexString(clientPublicEphemeral), 16); var v = new NetBigInteger(NetUtility.ToHexString(verifier), 16); var u = new NetBigInteger(NetUtility.ToHexString(udata), 16); var b = new NetBigInteger(NetUtility.ToHexString(serverPrivateEphemeral), 16); NetBigInteger retval = v.ModPow(u, N).Multiply(A).Mod(N).ModPow(b, N).Mod(N); return(retval.ToByteArrayUnsigned()); }
/// <summary> /// Compute multiplier (k) /// </summary> private static NetBigInteger ComputeMultiplier() { string one = NetUtility.ToHexString(N.ToByteArrayUnsigned()); string two = NetUtility.ToHexString(g.ToByteArrayUnsigned()); string ccstr = one + two.PadLeft(one.Length, '0'); var cc = NetUtility.HexToBytes(ccstr, stackalloc byte[ccstr.Length * 2]); var ccHashed = NetUtility.ComputeSHAHash(cc, stackalloc byte[NetUtility.SHAHashSize]); return(new NetBigInteger(NetUtility.ToHexString(ccHashed), 16)); }
/// <summary> /// Compute multiplier (k) /// </summary> private static NetBigInteger ComputeMultiplier() { string one = NetUtility.ToHexString(N.ToByteArrayUnsigned()); string two = NetUtility.ToHexString(g.ToByteArrayUnsigned()); string ccstr = one + two.PadLeft(one.Length, '0'); byte[] cc = NetUtility.ToByteArray(ccstr); var ccHashed = NetUtility.ComputeSHAHash(cc); return(new NetBigInteger(NetUtility.ToHexString(ccHashed), 16)); }