KeyPairGenerator cPairGen = KeyPairGenerator.getInstance(algName, "BC");
cPairGen.initialize(spec);
KeyPair cPair = cPairGen.generateKeyPair();
KeyAgreement aKeyAgree = KeyAgreement.getInstance(algName, "BC");
aKeyAgree.init(aPair.getPrivate());
KeyAgreement bKeyAgree = KeyAgreement.getInstance(algName, "BC");
bKeyAgree.init(bPair.getPrivate());
KeyAgreement cKeyAgree = KeyAgreement.getInstance(algName, "BC");
cKeyAgree.init(cPair.getPrivate());
Key ac = aKeyAgree.doPhase(cPair.getPublic(), false);
Key ba = bKeyAgree.doPhase(aPair.getPublic(), false);
Key cb = cKeyAgree.doPhase(bPair.getPublic(), false);
aKeyAgree.doPhase(cb, true);
bKeyAgree.doPhase(ac, true);
cKeyAgree.doPhase(ba, true);
BigInteger aShared = new BigInteger(aKeyAgree.generateSecret());
BigInteger bShared = new BigInteger(bKeyAgree.generateSecret());
BigInteger cShared = new BigInteger(cKeyAgree.generateSecret());
if (!aShared.equals(bShared))
{
fail(size + " bit 3-way test failed (a and b differ)");
}