internal static BigInteger ComputeX(ClientInfo clientInfo, Session session) { var method = session.SrpMethod; var iterations = session.Iterations; if (iterations == 0) { throw ExceptionFactory.MakeUnsupported("SRP: 0 iterations is not supported"); } // TODO: Add constants for 1024, 6144 and 8192 if (method != "SRPg-4096") { throw ExceptionFactory.MakeUnsupported( string.Format("SRP: method '{0}' is not supported", method)); } var k1 = Crypto.Hkdf(method: method, ikm: session.Salt, salt: clientInfo.Username.ToBytes()); var k2 = Crypto.Pbes2(method: session.KeyMethod, password: clientInfo.Password, salt: k1, iterations: iterations); var x = clientInfo.AccountKey.CombineWith(k2); return(x.ToBigInt()); }
public static byte[] Pbes2(string method, string password, byte[] salt, int iterations) { switch (method) { case "PBES2-HS256": case "PBES2g-HS256": return(Pbkdf2.GenerateSha256(password.ToBytes(), salt, iterations, 32)); case "PBES2-HS512": case "PBES2g-HS512": return(Pbkdf2.GenerateSha512(password.ToBytes(), salt, iterations, 32)); } throw ExceptionFactory.MakeUnsupported( string.Format("PBES2: method '{0}' is not supported", method)); }