Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.agreement.srp;
  
  
Implements the server side SRP-6a protocol. Note that this class is stateful, and therefore NOT threadsafe. This implementation of SRP is based on the optimized message sequence put forth by Thomas Wu in the paper "SRP-6: Improvements and Refinements to the Secure Remote Password Protocol, 2002"
 
 public class SRP6Server
 {
     protected BigInteger N;
     protected BigInteger g;
     protected BigInteger v;
 
     protected SecureRandom random;
     protected Digest digest;
 
     protected BigInteger A;
 
     protected BigInteger b;
     protected BigInteger B;
 
     protected BigInteger u;
     protected BigInteger S;
     protected BigInteger M1;
 	protected BigInteger M2;
 	protected BigInteger Key;
 	
     public SRP6Server()
     {
     }

    
Initialises the server to accept a new client authentication attempt

Parameters:
N The safe prime associated with the client's verifier
g The group parameter associated with the client's verifier
v The client's verifier
digest The digest algorithm associated with the client's verifier
random For key generation
 
     public void init(BigInteger NBigInteger gBigInteger vDigest digestSecureRandom random)
     {
         this. = N;
         this. = g;
         this. = v;
 
         this. = random;
         this. = digest;
     }
 
     public void init(SRP6GroupParameters groupBigInteger vDigest digestSecureRandom random)
     {
         init(group.getN(), group.getG(), vdigestrandom);
     }

    
Generates the server's credentials that are to be sent to the client.

Returns:
The server's public value to the client
 
     {
         BigInteger k = SRP6Util.calculateK();
         this. = selectPrivateValue();
         this. = k.multiply().mod().add(.modPow()).mod();
 
         return ;
     }

    
Processes the client's credentials. If valid the shared secret is generated and returned.

Parameters:
clientA The client's credentials
Returns:
A shared secret BigInteger
Throws:
org.bouncycastle.crypto.CryptoException If client's credentials are invalid
 
     public BigInteger calculateSecret(BigInteger clientAthrows CryptoException
     {
         this. = SRP6Util.validatePublicValue(clientA);
         this. = SRP6Util.calculateU();
         this. = calculateS();
 
         return ;
     }
 
     protected BigInteger selectPrivateValue()
     {
         return SRP6Util.generatePrivateValue();        
     }
 
     private BigInteger calculateS()
     {
         return .modPow().multiply().mod().modPow();
     }
    
    
Authenticates the received client evidence message M1 and saves it only if correct. To be called after calculating the secret S.

Parameters:
M1: the client side generated evidence message
Returns:
A boolean indicating if the client message M1 was the expected one.
Throws:
org.bouncycastle.crypto.CryptoException
	public boolean verifyClientEvidenceMessage(BigInteger clientM1throws CryptoException{
		//verify pre-requirements
		if ((this.==null)||(this.==null)||(this.==null)){
			throw new CryptoException("Impossible to compute and verify M1: " +
					"some data are missing from the previous operations (A,B,S)");
		}
		// Compute the own client evidence message 'M1'
		BigInteger computedM1 = SRP6Util.calculateM1();
		if (computedM1.equals(clientM1)){
			this. = clientM1;
			return true;
		}
		return false;
	}

Computes the server evidence message M2 using the previously verified values. To be called after successfully verifying the client evidence message M1.

Returns:
M2: the server side generated evidence message
Throws:
org.bouncycastle.crypto.CryptoException
		//verify pre-requirements
		if ((this.==null)||(this.==null)||(this.==null)){
			throw new CryptoException("Impossible to compute M2: " +
					"some data are missing from the previous operations (A,M1,S)");
		}
		// Compute the server evidence message 'M2'
		this. = SRP6Util.calculateM2();  
		return ;
	}

Computes the final session key as a result of the SRP successful mutual authentication To be called after calculating the server evidence message M2.

Returns:
Key: the mutual authenticated symmetric session key
Throws:
org.bouncycastle.crypto.CryptoException
		//verify pre-requirements
		if ((this.==null)||(this.==null)||(this.==null)){
			throw new CryptoException("Impossible to compute Key: " +
					"some data are missing from the previous operations (S,M1,M2)");
		}
		this. = SRP6Util.calculateKey();
		return ;
	}
New to GrepCode? Check out our FAQ X