@@ -0,0 +1,2565 @@
+import java.math.BigInteger;%0Aimport org.bouncycastle.crypto.CryptoException;%0Aimport org.bouncycastle.crypto.agreement.srp.SRP6Client;%0A%0A/** Custom extension of the BouncyCastle's default org.bouncycastle.crypto.agreement.srp.SRP6Client%0A * M1, M2, Key calculation methods added.%0A * @author Daniele Grasso%0A */%0Apublic class SRP6ClientCustom extends SRP6Client %7B%0A%09protected BigInteger M1;%0A%09protected BigInteger M2;%0A%09protected BigInteger Key;%0A%09public SRP6ClientCustom()%7B%0A%09%09super();%0A%09%7D%0A%09%0A%09/**%0A%09 * Computes the client evidence message M1 using the previously received values.%0A%09 * To be called after calculating the secret S.%0A%09 * @return M1: the client side generated evidence message%0A%09 * @throws CryptoException%0A%09 */%0A%09public BigInteger calculateClientEvidenceMessage() throws CryptoException%7B%0A%09%09// verify pre-requirements%0A%09%09if ((this.A==null)%7C%7C(this.B==null)%7C%7C(this.S==null))%7B%0A%09%09%09throw new CryptoException(%22Impossible to compute M2: some data are missing from the previous operations (A,M1,S)%22);%0A%09%09%7D%0A%09%09// compute the client evidence message 'M1'%0A%09%09this.M1 = SRP6UtilCustom.calculateM1(digest, A, M1, S);  %0A%09%09return M1;%0A%09%7D%0A%09%0A%09/** Authenticates the server evidence message M2 received and saves it only if correct.%0A%09 * @param M2: the server side generated evidence message%0A%09 * @return A boolean indicating if the server message M2 was the expected one.%0A%09 * @throws CryptoException%0A%09 */%0A%09public boolean verifyServerEvidenceMessage(BigInteger serverM2) throws CryptoException%7B%0A%09%09//verify pre-requirements%0A%09%09if ((this.A==null)%7C%7C(this.M1==null)%7C%7C(this.S==null))%7B%0A%09%09%09throw new CryptoException(%22Impossible to compute and verify M2: some data are missing from the previous operations (A,M1,S)%22);%0A%09%09%7D%0A%09%09// Compute the own server evidence message 'M2'%0A%09%09BigInteger computedM2 = SRP6UtilCustom.calculateM2(digest, A, M1, S);%0A%09%09if (computedM2.equals(serverM2))%7B%0A%09%09%09this.M2 = serverM2;%0A%09%09%09return true;%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A%09%0A%09/**%0A%09 * Computes the final session key as a result of the SRP successful mutual authentication%0A%09 * To be called after verifying the server evidence message M2.%0A%09 * @return Key: the mutually authenticated symmetric session key%0A%09 * @throws CryptoException%0A%09 */%0A%09public BigInteger calculateSessionKey() throws CryptoException%7B%0A%09%09//verify pre-requirements (here we enforce a previous calculation of M1 and M2)%0A%09%09if ((this.S==null)%7C%7C(this.M1==null)%7C%7C(this.M2==null))%7B%0A%09%09%09throw new CryptoException(%22Impossible to compute Key: some data are missing from the previous operations (S,M1,M2)%22);%0A%09%09%7D%0A%09%09this.Key = SRP6UtilCustom.calculateKey(digest,S);%0A%09%09return Key;%0A%09%7D%0A%7D%0A

Create SRP6ClientCustom.java