void SetSrpStrength(SrpStrength strength) { m_strength = strength; m_srpByteLength = ((int)strength) >> 3; m_param = SrpConstants.Lookup(m_strength); m_client = new Srp6Client(m_param); }
/// <summary> /// Creates a user credential from the provided data. /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="strength"></param> /// <param name="saltSize"></param> /// <param name="iterations"></param> /// <returns></returns> public SrpUserCredential(string username, string password, SrpStrength strength = SrpStrength.Bits1024, int saltSize = 32, int iterations = 4000) { username = username.Normalize(NormalizationForm.FormKC); password = password.Normalize(NormalizationForm.FormKC); UsernameBytes = Encoding.UTF8.GetBytes(username); var constants = SrpConstants.Lookup(strength); BigInteger N = constants.N; BigInteger g = constants.g; byte[] s = SaltGenerator.Create(saltSize); byte[] hashPassword = PBKDF2.ComputeSaltedPassword(HMACMethod.SHA512, Encoding.UTF8.GetBytes(password), s, iterations, 64); Sha512Digest hash = new Sha512Digest(); byte[] output = new byte[hash.GetDigestSize()]; hash.BlockUpdate(UsernameBytes, 0, UsernameBytes.Length); hash.Update((byte)':'); hash.BlockUpdate(hashPassword, 0, hashPassword.Length); hash.DoFinal(output, 0); hash.BlockUpdate(s, 0, s.Length); hash.BlockUpdate(output, 0, output.Length); hash.DoFinal(output, 0); BigInteger x = new BigInteger(1, output).Mod(N); BigInteger v = g.ModPow(x, N); UserName = username; Salt = s; Verification = v.ToByteArray(); Iterations = iterations; SrpStrength = strength; VerificationInteger = new BigInteger(1, Verification); }
/// <summary> /// Adds the specified user to the credential database. /// </summary> /// <param name="username"></param> /// <param name="verifier"></param> /// <param name="passwordSalt"></param> /// <param name="iterations"></param> /// <param name="strength"></param> public void AddUser(string username, byte[] verifier, byte[] passwordSalt, int iterations, SrpStrength strength) { var user = new SrpUserCredential(username, passwordSalt, verifier, iterations, strength); lock (m_users) { m_users.Add(username, user); } }
/// <summary> /// Adds the specified user to the credentials database. /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="strength"></param> /// <param name="saltSize"></param> /// <param name="iterations"></param> public void AddUser(string username, string password, SrpStrength strength = SrpStrength.Bits1024, int saltSize = 32, int iterations = 4000) { var user = new SrpUserCredential(username, password, strength, saltSize, iterations); lock (m_users) { m_users.Add(username, user); } }
/// <summary> /// Adds the specified user to the credentials database. /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="strength"></param> /// <param name="saltSize"></param> /// <param name="iterations"></param> public void AddUser(string username, string password, SrpStrength strength = SrpStrength.Bits1024, int saltSize = 32, int iterations = 4000) { SrpUserCredential user = new SrpUserCredential(username, password, strength, saltSize, iterations); lock (m_users) { m_users.Add(username, user); } }
/// <summary> /// Creates user credentials /// </summary> /// <param name="username"></param> /// <param name="salt"></param> /// <param name="verification"></param> /// <param name="iterations"></param> /// <param name="srpStrength"></param> public SrpUserCredential(string username, byte[] verification, byte[] salt, int iterations, SrpStrength srpStrength) { UserName = username; UsernameBytes = Encoding.UTF8.GetBytes(username); Salt = salt; Verification = verification; Iterations = iterations; SrpStrength = srpStrength; VerificationInteger = new BigInteger(1, verification); }
/// <summary> /// Looks up the valid precomputed constants for SRP given the specified bit strength. /// </summary> /// <param name="strength">the bit strength to lookup.</param> /// <returns></returns> public static SrpConstants Lookup(SrpStrength strength) { int bits = (int)strength; if (!s_groupParameters.TryGetValue(bits, out SrpConstants value)) { throw new InvalidEnumArgumentException("strength"); } return(value); }
/// <summary> /// Looks up the valid precomputed constants for SRP given the specified bit strength. /// </summary> /// <param name="strength">the bit strength to lookup.</param> /// <returns></returns> public static SrpConstants Lookup(SrpStrength strength) { int bits = (int)strength; SrpConstants value; if (!s_groupParameters.TryGetValue(bits, out value)) throw new InvalidEnumArgumentException("strength"); return value; }
/// <summary> /// Adds the specified user to the credential database. /// </summary> /// <param name="username"></param> /// <param name="verifier"></param> /// <param name="passwordSalt"></param> /// <param name="iterations"></param> /// <param name="strength"></param> public void AddUser(string username, byte[] verifier, byte[] passwordSalt, int iterations, SrpStrength strength) { SrpUserCredential user = new SrpUserCredential(username, passwordSalt, verifier, iterations, strength); lock (m_users) { m_users.Add(username, user); } }