GetNandG() public static method

Returns N and g as an out parameter based on given keySize.
public static GetNandG ( Int32 keySize, NetBigInteger &g ) : NetBigInteger
keySize System.Int32
g NetBigInteger
return NetBigInteger
        /// <summary>
        /// Generates Salt and Verifier for username and password
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="keysize"></param>
        /// <param name="salt"></param>
        /// <returns></returns>
        public static NetBigInteger PasswordVerifier(String username, String password, Int32 keysize, out Byte[] salt)
        {
            salt = NetSRP.GenerateSalt();
            NetBigInteger g, N = NetSRP.GetNandG(keysize, out g);

            return(NetSRP.PasswordVerifier(username, password, salt, N, g));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new Handshake
        /// </summary>
        /// <param name="active">Is active party</param>
        /// <param name="keySize">keysize</param>
        /// <param name="logonManager">logonManager (only needed if passive)</param>
        internal Handshake(Boolean active, Int32 keySize, ILogonManager logonManager)
        {
            // Local Data setup
            _cache        = new NetSRP.State();
            _keySize      = keySize;
            _logonManager = logonManager ?? _defaultLogonManager;

            if (!active && _defaultLogonManager == null)
            {
                _defaultLogonManager = logonManager;
            }

            // We calculate N and G for this insance. I choose to do so, so you can
            // have different keysizes throughout your program and are not stuck with one
            N = NetSRP.GetNandG(_keySize, out g);
            k = NetSRP.Calck(N, g);

            // Set as NotInitialized
            this.HandshakeState = Handshake.State.NotInitialized;

            if (!active && _logonManager == null)
            {
                throw new InvalidOperationException("Receiving handshakes need a logonManager");
            }

            if (keySize == 0 || N == null || g == null || k == null)
            {
                throw new InvalidOperationException("Handshake not intialized");
            }

            // NOTE: this is caused by the length of the hailmessage - larger then 4096 goes over the MTU
            if (keySize < 1024 || keySize > 4096)
            {
                throw new NetException("SRP6Keysize is not supported by Lidgren.Network",
                                       new ArgumentOutOfRangeException("keySize"));
            }
        }