C# Class Lidgren.Network.Authentication.NetSRP

Library of SRP Functions used in SRP protocol. Refs: http://srp.stanford.edu/design.html http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-09.txt Required Credit to Tom Wu for the SRP algo: "This product uses the 'Secure Remote Password' cryptographic authentication system developed by Tom Wu ([email protected])." Note: Method naming follows the SRP6 naming of variables which may be a single upper case or lower case character. This allows a reader to more easily follow the protocol at the expense of non-standard method naming convension.
Exibir arquivo Open project: SleeplessByte/lidgren-srp6a Class Usage Examples

Public Properties

Property Type Description
N1024Bit NetBigInteger
N1536Bit NetBigInteger
N2048Bit NetBigInteger
N3072Bit NetBigInteger
N4096Bit NetBigInteger
N6144Bit NetBigInteger
N8192Bit NetBigInteger
g1024Bit NetBigInteger
g1536Bit NetBigInteger
g2048Bit NetBigInteger
g3072Bit NetBigInteger
g4096Bit NetBigInteger
g6144Bit NetBigInteger
g8192Bit NetBigInteger

Public Methods

Method Description
CalcA ( NetBigInteger N, NetBigInteger g, NetBigInteger a ) : NetBigInteger

Returns A.

CalcB ( NetBigInteger N, NetBigInteger g, NetBigInteger b, NetBigInteger v ) : NetBigInteger

Calculates B.

CalcK ( NetBigInteger S ) : Byte[]

Returns 32 byte array using SHA256 one-way hash of value S. RijndaelManaged, for example can use max key of 32 bytes directly, so this is convienent. If you need more or less entropy, add or subtract bytes as required. Naturally, both sides need to be able to generate the same key bytes. It is recommended to just use the 32 bytes as returned from this method.

CalcM ( NetBigInteger N, NetBigInteger g, String userName, Byte salt, NetBigInteger A, NetBigInteger B, Byte K ) : Byte[]

M is client's proof of K.

CalcM2 ( NetBigInteger A, Byte M, Byte K ) : Byte[]

M2 is Server's proof of K.

CalcSClient ( NetBigInteger N, NetBigInteger g, NetBigInteger B, NetBigInteger k, NetBigInteger x, NetBigInteger a, NetBigInteger u ) : NetBigInteger

Calculates client's S.

CalcSServer ( NetBigInteger N, NetBigInteger A, NetBigInteger v, NetBigInteger u, NetBigInteger b ) : NetBigInteger

Calculates server's S.

CalcV ( NetBigInteger N, NetBigInteger g, NetBigInteger x ) : NetBigInteger

Calculates V. The password verifier.

Calck ( NetBigInteger N, NetBigInteger g ) : NetBigInteger

Calculates k.

Calcu ( NetBigInteger A, NetBigInteger B ) : NetBigInteger

Calculates u.

Calcx ( Byte salt, String userName, String password ) : NetBigInteger

Calculates x.

CreateEncryption ( Byte sessionValue ) : NetXtea

Create XTEA symmetrical encryption object from sessionValue

GenerateSalt ( ) : Byte[]

Returns cryptographically random salt bytes.

GetNandG ( Int32 keySize, NetBigInteger &g ) : NetBigInteger

Returns N and g as an out parameter based on given keySize.

Geta ( ) : NetBigInteger

Returns a - a random private value.

Getb ( ) : NetBigInteger

Returns b - a random private value.

PasswordVerifier ( String userName, String password, Byte salt, NetBigInteger N, NetBigInteger g ) : NetBigInteger

Host stores v (password verifier) in database.

Private Methods

Method Description
XorArrays ( Byte array1, Byte array2 ) : Byte[]

XOR two byte arrays together and returns result. Both arrays must be same length and neither can be null. Resulting array will be same size as array1.

Method Details

CalcA() public static method

Returns A.
public static CalcA ( NetBigInteger N, NetBigInteger g, NetBigInteger a ) : NetBigInteger
N NetBigInteger
g NetBigInteger
a NetBigInteger
return NetBigInteger

CalcB() public static method

Calculates B.
public static CalcB ( NetBigInteger N, NetBigInteger g, NetBigInteger b, NetBigInteger v ) : NetBigInteger
N NetBigInteger
g NetBigInteger
b NetBigInteger
v NetBigInteger
return NetBigInteger

CalcK() public static method

Returns 32 byte array using SHA256 one-way hash of value S. RijndaelManaged, for example can use max key of 32 bytes directly, so this is convienent. If you need more or less entropy, add or subtract bytes as required. Naturally, both sides need to be able to generate the same key bytes. It is recommended to just use the 32 bytes as returned from this method.
public static CalcK ( NetBigInteger S ) : Byte[]
S NetBigInteger
return Byte[]

CalcM() public static method

M is client's proof of K.
public static CalcM ( NetBigInteger N, NetBigInteger g, String userName, Byte salt, NetBigInteger A, NetBigInteger B, Byte K ) : Byte[]
N NetBigInteger
g NetBigInteger
userName String
salt Byte
A NetBigInteger
B NetBigInteger
K Byte
return Byte[]

CalcM2() public static method

M2 is Server's proof of K.
public static CalcM2 ( NetBigInteger A, Byte M, Byte K ) : Byte[]
A NetBigInteger
M Byte
K Byte
return Byte[]

CalcSClient() public static method

Calculates client's S.
public static CalcSClient ( NetBigInteger N, NetBigInteger g, NetBigInteger B, NetBigInteger k, NetBigInteger x, NetBigInteger a, NetBigInteger u ) : NetBigInteger
N NetBigInteger
g NetBigInteger
B NetBigInteger
k NetBigInteger
x NetBigInteger
a NetBigInteger
u NetBigInteger
return NetBigInteger

CalcSServer() public static method

Calculates server's S.
public static CalcSServer ( NetBigInteger N, NetBigInteger A, NetBigInteger v, NetBigInteger u, NetBigInteger b ) : NetBigInteger
N NetBigInteger
A NetBigInteger
v NetBigInteger
u NetBigInteger
b NetBigInteger
return NetBigInteger

CalcV() public static method

Calculates V. The password verifier.
public static CalcV ( NetBigInteger N, NetBigInteger g, NetBigInteger x ) : NetBigInteger
N NetBigInteger
g NetBigInteger
x NetBigInteger
return NetBigInteger

Calck() public static method

Calculates k.
public static Calck ( NetBigInteger N, NetBigInteger g ) : NetBigInteger
N NetBigInteger
g NetBigInteger
return NetBigInteger

Calcu() public static method

Calculates u.
public static Calcu ( NetBigInteger A, NetBigInteger B ) : NetBigInteger
A NetBigInteger
B NetBigInteger
return NetBigInteger

Calcx() public static method

Calculates x.
public static Calcx ( Byte salt, String userName, String password ) : NetBigInteger
salt Byte
userName String
password String
return NetBigInteger

CreateEncryption() public static method

Create XTEA symmetrical encryption object from sessionValue
public static CreateEncryption ( Byte sessionValue ) : NetXtea
sessionValue Byte
return NetXtea

GenerateSalt() public static method

Returns cryptographically random salt bytes.
public static GenerateSalt ( ) : Byte[]
return Byte[]

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

Geta() public static method

Returns a - a random private value.
public static Geta ( ) : NetBigInteger
return NetBigInteger

Getb() public static method

Returns b - a random private value.
public static Getb ( ) : NetBigInteger
return NetBigInteger

PasswordVerifier() public static method

Host stores v (password verifier) in database.
public static PasswordVerifier ( String userName, String password, Byte salt, NetBigInteger N, NetBigInteger g ) : NetBigInteger
userName String
password String
salt Byte
N NetBigInteger
g NetBigInteger
return NetBigInteger

Property Details

N1024Bit public_oe static_oe property

A large safe 1024 bit prime. All SRP arithmetic is done modulo N. See: http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-09.txt
public static NetBigInteger N1024Bit
return NetBigInteger

N1536Bit public_oe static_oe property

A large safe 1536 bit prime. All SRP arithmetic is done modulo N.
public static NetBigInteger N1536Bit
return NetBigInteger

N2048Bit public_oe static_oe property

A large safe 2048 bit prime. All SRP arithmetic is done modulo N.
public static NetBigInteger N2048Bit
return NetBigInteger

N3072Bit public_oe static_oe property

A large safe 3072 bit prime. All SRP arithmetic is done modulo N.
public static NetBigInteger N3072Bit
return NetBigInteger

N4096Bit public_oe static_oe property

A large safe 4096 bit prime. All SRP arithmetic is done modulo N.
public static NetBigInteger N4096Bit
return NetBigInteger

N6144Bit public_oe static_oe property

A large safe 6144 bit prime. All SRP arithmetic is done modulo N.
public static NetBigInteger N6144Bit
return NetBigInteger

N8192Bit public_oe static_oe property

A large safe 8192 bit prime. All SRP arithmetic is done modulo N.
public static NetBigInteger N8192Bit
return NetBigInteger

g1024Bit public_oe static_oe property

Generator modulo N for 1024 bit N.
public static NetBigInteger g1024Bit
return NetBigInteger

g1536Bit public_oe static_oe property

Generator modulo N for 1536 bit N.
public static NetBigInteger g1536Bit
return NetBigInteger

g2048Bit public_oe static_oe property

Generator modulo N for 2048 bit N.
public static NetBigInteger g2048Bit
return NetBigInteger

g3072Bit public_oe static_oe property

Generator modulo N for 3072 bit N.
public static NetBigInteger g3072Bit
return NetBigInteger

g4096Bit public_oe static_oe property

Generator modulo N for 4096 bit N.
public static NetBigInteger g4096Bit
return NetBigInteger

g6144Bit public_oe static_oe property

Generator modulo N for 6144 bit N.
public static NetBigInteger g6144Bit
return NetBigInteger

g8192Bit public_oe static_oe property

Generator modulo N for 8192 bit N.
public static NetBigInteger g8192Bit
return NetBigInteger