Exemple #1
0
            /// <summary>
            /// Respond to the server's challenge with a proof of password.
            /// </summary>
            /// <returns>The to challenge.</returns>
            /// <param name="password">Password.</param>
            /// <param name="identity">Identity.</param>
            /// <param name="salt">Salt.</param>
            /// <param name="Bhex">Bhex.</param>
            public static Meteor.ChallengeResponse RespondToChallenge(string password, string identity, string salt, string Bhex)
            {
                BigInteger B = new BigInteger (Bhex, 16);
                BigInteger u = new BigInteger (Hash (Ahex + Bhex), 16);
                BigInteger x = new BigInteger (Hash (salt + Hash (identity + ":" + password)),16);

                BigInteger kgx = k * (g.modPow (x, N));
                BigInteger aux = a + (u * x);
                S = (B - kgx).modPow (aux, N);
                string Shex = S.ToString(16).ToLowerInvariant().TrimStart('0');
                string M = Hash (Ahex + Bhex + Shex);
                HAMK = Hash (Ahex + M + Shex);

                return new Meteor.ChallengeResponse () {
                    M = M.ToLowerInvariant().TrimStart('0')
                };
            }
Exemple #2
0
            /// <summary>
            /// Generate a new SRP verifier. Password is the plaintext password.
            /// </summary>
            /// <returns>The verifier.</returns>
            /// <param name="password">Password.</param>
            //original: (didn't work with 3.5 .Net compiler and was annoying to keep switching to 4.0
            //public static Meteor.Verifier GenerateVerifier(string password, string identity = null, string salt = null)
            public static Meteor.Verifier GenerateVerifier(string password, string identity, string salt)
            {
                if (identity == null)
                {
                    BigInteger i = new BigInteger ();
                    i.genRandomBits (36);
                    identity = i.ToString(16).ToLowerInvariant().TrimStart('0');
                }

                if (salt == null)
                {
                    BigInteger s = new BigInteger ();
                    s.genRandomBits (36);
                    salt = s.ToString(16).ToLowerInvariant().TrimStart('0');
                }

                string x = Hash (salt + Hash (identity + ":" + password));

                BigInteger xi = new BigInteger (x, 16);
                BigInteger v = g.modPow (xi, N);

                return new Meteor.Verifier () {
                    identity = identity,
                    salt = salt,
                    verifier = v.ToString(16).ToLowerInvariant().TrimStart('0')
                };
            }