public static byte[] calculateDHBasicAgreement(DHPublicKeyParameters publicKey, DHPrivateKeyParameters privateKey) { DHBasicAgreement basicAgreement = new DHBasicAgreement(); basicAgreement.init(privateKey); BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey); /* * RFC 5246 8.1.2. Leading bytes of Z that contain all zero bits are stripped before it is * used as the pre_master_secret. */ return BigIntegers.asUnsignedByteArray(agreementValue); }
public IESwithDESede() { super(new IESEngine(new DHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()), new PaddedBufferedBlockCipher(new DESedeEngine()))); }
public IESwithAES() { super(new IESEngine(new DHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()), new PaddedBufferedBlockCipher(new AESEngine()))); }
public IES() { super(new IESEngine( new DHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()))); }
private void testSimpleWithRandom( DHBasicKeyPairGenerator kpGen) { // // generate first pair // AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); // // generate second pair // pair = kpGen.generateKeyPair(); DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); // // two way // DHBasicAgreement e1 = new DHBasicAgreement(); DHBasicAgreement e2 = new DHBasicAgreement(); e1.init(new ParametersWithRandom(pv1, new SecureRandom())); e2.init(new ParametersWithRandom(pv2, new SecureRandom())); BigInteger k1 = e1.calculateAgreement(pu2); BigInteger k2 = e2.calculateAgreement(pu1); if (!k1.equals(k2)) { fail("basic with random 2-way test failed"); } }
public OldIESwithCipher(BlockCipher baseCipher) { super(new OldIESEngine(new DHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()), new PaddedBufferedBlockCipher(baseCipher))); }
public byte[] generatePremasterSecret() throws IOException { /* * Diffie-Hellman basic key agreement */ DHBasicAgreement dhAgree = new DHBasicAgreement(); dhAgree.init(dhAgreeClientKeyPair.getPrivate()); BigInteger agreement = dhAgree.calculateAgreement(dhAgreeServerPublicKey); return BigIntegers.asUnsignedByteArray(agreement); }
public IES() { super(new IESEngine(new DHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()))); }
private void testDHBasic( int size, int privateValueSize, BigInteger g, BigInteger p) { DHBasicKeyPairGenerator kpGen = getDHBasicKeyPairGenerator(g, p, privateValueSize); // // generate first pair // AsymmetricCipherKeyPair pair = kpGen.generateKeyPair(); DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic(); DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate(); checkKeySize(privateValueSize, pv1); // // generate second pair // pair = kpGen.generateKeyPair(); DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic(); DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate(); checkKeySize(privateValueSize, pv2); // // two way // DHBasicAgreement e1 = new DHBasicAgreement(); DHBasicAgreement e2 = new DHBasicAgreement(); e1.init(pv1); e2.init(pv2); BigInteger k1 = e1.calculateAgreement(pu2); BigInteger k2 = e2.calculateAgreement(pu1); if (!k1.equals(k2)) { fail("basic " + size + " bit 2-way test failed"); } }
public OldIES() { super(new OldIESEngine(new DHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()))); }