/// <summary> /// Calculates k. /// </summary> /// <param name="N"></param> /// <param name="g"></param> /// <returns></returns> public static NetBigInteger Calck(NetBigInteger N, NetBigInteger g) { // k = SHA1(N | PAD(g)) SRP-6a Byte[] gBytes = g.ToByteArray(); Byte[] NBytes = N.ToByteArray(); Byte[] both = NetUtility.JoinArrays(NBytes, gBytes); Byte[] hash = hashAlgo.ComputeHash(both); return(new NetBigInteger(hash)); }
/// <summary> /// Calculates u. /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public static NetBigInteger Calcu(NetBigInteger A, NetBigInteger B) { // Both: u = SHA1(PAD(A) | PAD(B)) Byte[] aBytes = A.ToByteArray(); Byte[] bBytes = B.ToByteArray(); Byte[] both = NetUtility.JoinArrays(aBytes, bBytes); Byte[] hash = hashAlgo.ComputeHash(both); return(new NetBigInteger(hash)); }
/// <summary> /// Calculates x. /// </summary> /// <param name="salt"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public static NetBigInteger Calcx(Byte[] salt, String userName, String password) { // x = SHA(s + SHA(userName + ":" + password)) Byte[] saltBytes = salt; Byte[] innerBytes = Encoding.UTF8.GetBytes(userName + ":" + password); Byte[] bytes = NetUtility.JoinArrays(saltBytes, innerBytes); Byte[] hash = hashAlgo.ComputeHash(bytes); NetBigInteger x = new NetBigInteger(hash); return(x); }
/// <summary> /// M2 is Server's proof of K. /// </summary> /// <returns></returns> public static Byte[] CalcM2(NetBigInteger A, Byte[] M, Byte[] K) { // Host -> User: H(A, M, K) Byte[] ABytes = A.ToByteArray(); ArrayList al = new ArrayList(); al.Add(ABytes); al.Add(M); al.Add(K); Byte[] all = NetUtility.JoinArrays(al); return(hashAlgo.ComputeHash(all)); }
/// <summary> /// M is client's proof of K. /// </summary> /// <returns></returns> public static Byte[] CalcM(NetBigInteger N, NetBigInteger g, String userName, Byte[] salt, NetBigInteger A, NetBigInteger B, Byte[] K) { // User -> Host: M = H(H(N) xor H(g), H(I), s, A, B, K) Byte[] gBytes = g.ToByteArray(); Byte[] NBytes = N.ToByteArray(); Byte[] hg = hashAlgo.ComputeHash(gBytes); Byte[] hN = hashAlgo.ComputeHash(NBytes); Byte[] gNXorBytes = XorArrays(hN, hg); Byte[] userNameBytes = Encoding.UTF8.GetBytes(userName); Byte[] hUserNameBytes = hashAlgo.ComputeHash(userNameBytes); Byte[] ABytes = A.ToByteArray(); Byte[] BBytes = B.ToByteArray(); ArrayList al = new ArrayList(); al.Add(gNXorBytes); al.Add(hUserNameBytes); al.Add(salt); al.Add(ABytes); al.Add(BBytes); al.Add(K); Byte[] all = NetUtility.JoinArrays(al); return(hashAlgo.ComputeHash(all)); }