List of usage examples for org.bouncycastle.crypto.agreement.jpake JPAKERound1Payload getGx2
public BigInteger getGx2()
From source file:com.distrimind.util.crypto.P2PJPAKESecretMessageExchanger.java
License:Open Source License
@Override protected byte[] getDataToSend(int stepNumber) throws Exception { valid = false;//from w ww . j ava 2 s . c om switch (stepNumber) { case 0: try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { try (DataOutputStream oos = new DataOutputStream(baos)) { JPAKERound1Payload toSerialize = jpake.createRound1PayloadToSend(); byte[] tab = toSerialize.getGx1().toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); tab = toSerialize.getGx2().toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); BigInteger[] b = toSerialize.getKnowledgeProofForX1(); if (b == null) oos.writeInt(0); else oos.writeInt(b.length); if (b == null) throw new IOException(); for (BigInteger bi : b) { tab = bi.toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); } b = toSerialize.getKnowledgeProofForX2(); if (b == null) oos.writeInt(0); else oos.writeInt(b.length); if (b == null) throw new IOException(); for (BigInteger bi : b) { tab = bi.toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); } tab = toSerialize.getParticipantId().getBytes(Charset.forName("utf-8")); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); } valid = true; return baos.toByteArray(); } case 1: try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { try (DataOutputStream oos = new DataOutputStream(baos)) { JPAKERound2Payload toSerialize = jpake.createRound2PayloadToSend(); byte[] tab = toSerialize.getA().toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); BigInteger[] b = toSerialize.getKnowledgeProofForX2s(); if (b == null) oos.writeInt(0); else oos.writeInt(b.length); if (b == null) throw new IOException(); for (BigInteger bi : b) { tab = bi.toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); } tab = toSerialize.getParticipantId().getBytes(Charset.forName("utf-8")); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); } valid = true; return baos.toByteArray(); } case 2: try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { try (DataOutputStream oos = new DataOutputStream(baos)) { keyMaterial = jpake.calculateKeyingMaterial(); JPAKERound3Payload toSerialize = jpake.createRound3PayloadToSend(keyMaterial); byte[] tab = toSerialize.getMacTag().toByteArray(); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); tab = toSerialize.getParticipantId().getBytes(Charset.forName("utf-8")); if (tab.length > Short.MAX_VALUE) throw new IOException(); oos.writeShort(tab.length); oos.write(tab); } valid = true; return baos.toByteArray(); } default: throw new IllegalAccessError(); } }