blob: 264833b4dbce09b865d9f9669048a5f136e6442f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
using System;
using Org.BouncyCastle.Math;
namespace Org.BouncyCastle.Crypto.Agreement.Srp
{
/**
* Generates new SRP verifier for user
*/
public class Srp6VerifierGenerator
{
protected BigInteger N;
protected BigInteger g;
protected IDigest digest;
public Srp6VerifierGenerator()
{
}
/**
* Initialises generator to create new verifiers
* @param N The safe prime to use (see DHParametersGenerator)
* @param g The group parameter to use (see DHParametersGenerator)
* @param digest The digest to use. The same digest type will need to be used later for the actual authentication
* attempt. Also note that the final session key size is dependent on the chosen digest.
*/
public virtual void Init(BigInteger N, BigInteger g, IDigest digest)
{
this.N = N;
this.g = g;
this.digest = digest;
}
/**
* Creates a new SRP verifier
* @param salt The salt to use, generally should be large and random
* @param identity The user's identifying information (eg. username)
* @param password The user's password
* @return A new verifier for use in future SRP authentication
*/
public virtual BigInteger GenerateVerifier(byte[] salt, byte[] identity, byte[] password)
{
BigInteger x = Srp6Utilities.CalculateX(digest, N, salt, identity, password);
return g.ModPow(x, N);
}
}
}
|