Exemple #1
0
        public SRPVerifier(HashAlgorithm hashAlgorithm, SRPParameter parameter,
                           VerificationKey verification, byte[] A)
            : base(hashAlgorithm, parameter)
        {
            _hashAlgorithm = hashAlgorithm;
            _parameter     = parameter;

            _s        = verification.Salt.StringToByteArray().ToBigInteger();
            _v        = verification.Verifier.StringToByteArray().ToBigInteger();
            _username = verification.Username;

            _A = A.ToBigInteger();

            if ((_A % _parameter.PrimeNumber) == BigInteger.Zero)
            {
                throw new Exception("Safety check failed");
            }

            _b = BigInteger.Parse("6120781328594294848119626246127827602386035851539447828004723105537643674485");

            _k = Compute_k().ToBigInteger();

            _B = (_k * _v + BigInteger.ModPow(
                      _parameter.Generator, _b, _parameter.PrimeNumber)
                  ) % _parameter.PrimeNumber;

            // _B = Compute_B(_v, _k, _b);
            _u               = Compute_u(_A.ToBytes(), _B.ToBytes()).ToBigInteger();
            _S               = Compute_S(_A, _v, _u, _b);
            _K               = Compute_K(_S.ToBytes());
            _M               = Compute_M(_username, _s.ToBytes(), _A.ToBytes(), _B.ToBytes(), _K);
            _HMAK            = Compute_HAMK(_A.ToBytes(), _M, _K);
            _verificationKey = verification;

#if DEBUG
            Console.WriteLine("=================== Verifier ====================");
            Console.WriteLine("_s = {0}", _s);
            Console.WriteLine("_v = {0}", _v);
            Console.WriteLine("_username = {0}", _username);
            Console.WriteLine("_A = {0}", _A);
            Console.WriteLine("_b = {0}", _b);
            Console.WriteLine("_k = {0}", _k);
            Console.WriteLine("_B = {0}", _B);
            Console.WriteLine("_u = {0}", _u);
            Console.WriteLine("_S = {0}", _S);
            Console.WriteLine("_K = {0}", _K.ToBigInteger());
            Console.WriteLine("_M = {0}", _M.ToBigInteger());
            Console.WriteLine("=============================================");
#endif
        }
Exemple #2
0
        public SRPVerifier(HashAlgorithm hashAlgorithm, SRPParameter parameter,
                           VerificationKey verification, byte[] A, byte[] b = null)
            : base(hashAlgorithm, parameter)
        {
            _hashAlgorithm = hashAlgorithm;
            _parameter     = parameter;

            _s        = verification.Salt.StringToBytes().ToBigInteger();
            _v        = verification.Verifier.StringToBytes().ToBigInteger();
            _username = verification.Username;

            _A = A.ToBigInteger();

            if ((_A % _parameter.PrimeNumber) == BigInteger.Zero)
            {
                throw new Exception("Safety check failed");
            }

            _b = b != null?b.ToBigInteger() : GetRandomNumber().ToBytes().ToBigInteger();

            _k = Compute_k().ToBigInteger();

            _B = (_k * _v + BigInteger.ModPow(
                      _parameter.Generator, _b, _parameter.PrimeNumber)
                  ) % _parameter.PrimeNumber;

            _u               = Compute_u(_A.ToBytes(), _B.ToBytes()).ToBigInteger();
            _S               = Compute_S(_A, _v, _u, _b);
            _K               = Compute_K(_S.ToBytes());
            _M               = Compute_M(_username, _s.ToBytes(), _A.ToBytes(), _B.ToBytes(), _K);
            _HMAK            = Compute_HAMK(_A.ToBytes(), _M, _K);
            _verificationKey = verification;

#if DEBUG
            Console.WriteLine("=================== Verifier ====================");
            Console.WriteLine("_s = {0}", _s);
            Console.WriteLine("_v = {0}", _v);
            Console.WriteLine("_username = {0}", _username);
            Console.WriteLine("_A = {0}", _A);
            Console.WriteLine("_b = {0}", _b);
            Console.WriteLine("_k = {0}", _k);
            Console.WriteLine("_B = {0}", _B);
            Console.WriteLine("_u = {0}", _u);
            Console.WriteLine("_S = {0}", _S);
            Console.WriteLine("_K = {0}", _K.ToBigInteger());
            Console.WriteLine("_M = {0}", _M.ToBigInteger());
            Console.WriteLine("=============================================");
#endif
        }
Exemple #3
0
        public SRPUser(string username, string password, HashAlgorithm hashAlgorithm,
                       SRPParameter parameter, byte [] a = null) : base(hashAlgorithm, parameter)
        {
            _hashAlgorithm = hashAlgorithm;
            _parameter     = parameter;
            _k             = Compute_k().ToBigInteger();
            _username      = username;
            _password      = password;
            _a             = a != null?a.ToBigInteger() : GetRandomNumber().ToBytes().ToBigInteger();

            _A = Compute_A(_a);

#if DEBUG
            Console.WriteLine("=================== User ====================");
            Console.WriteLine("_k = {0}", _k);
            Console.WriteLine("_a = {0}", _a);
            Console.WriteLine("_A = {0}", _A.ToBigInteger());
            Console.WriteLine("=============================================");
#endif
        }
Exemple #4
0
        public SRPUser(string username, string password, HashAlgorithm hashAlgorithm,
                       SRPParameter parameter) : base(hashAlgorithm, parameter)
        {
            _hashAlgorithm = hashAlgorithm;
            _parameter     = parameter;
            _k             = Compute_k().ToBigInteger();
            _username      = username;
            _password      = password;
            //if (a == null)
            //{
            //  a = GetRandomNumber().ToBytes();
            //}
            //_a = GetRandomNumber();
            _a = BigInteger.Parse("74236667825352264527273219564547312472100561501249972990525296015972193477642");
            _A = Compute_A(_a);

#if DEBUG
            Console.WriteLine("=================== User ====================");
            Console.WriteLine("_k = {0}", _k);
            Console.WriteLine("_a = {0}", _a);
            Console.WriteLine("_A = {0}", _A.ToBigInteger());
            Console.WriteLine("=============================================");
#endif
        }
 public SecureRemoteProtocol(HashAlgorithm hashAlgorithm, SRPParameter parameter)
 {
     _hashAlgorithm = hashAlgorithm;
     _parameter     = parameter;
 }