protected AEADBlockCipher createAEADBlockCipher_AES_CCM() { return new CCMBlockCipher(createAESEngine()); }
private boolean hasAssociatedText() { return getAssociatedTextLength() > 0; }
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException { int len = processPacket(data.getBuffer(), 0, data.size(), out, outOff); reset(); return len; }
if (hasAssociatedText()) if (hasAssociatedText()) int textLength = getAssociatedTextLength(); if (textLength < ((1 << 16) - (1 << 8)))
public void reset() { ccm.reset(); } }
/** * Process a packet of data for either CCM decryption or encryption. * * @param in data for processing. * @param inOff offset at which data starts in the input array. * @param inLen length of the data in the input array. * @return a byte array containing the processed input.. * @throws IllegalStateException if the cipher is not appropriately set up. * @throws InvalidCipherTextException if the input data is truncated or the mac check fails. */ public byte[] processPacket(byte[] in, int inOff, int inLen) throws IllegalStateException, InvalidCipherTextException { byte[] output; if (forEncryption) { output = new byte[inLen + macSize]; } else { if (inLen < macSize) { throw new InvalidCipherTextException("data too short"); } output = new byte[inLen - macSize]; } processPacket(in, inOff, inLen, output, 0); return output; }
calculateMac(in, inOff, inLen, macBlock); calculateMac(output, outOff, outputLen, calculatedMacBlock);
public String getAlgorithmName() { return ccm.getAlgorithmName() + "Mac"; }
public int doFinal(byte[] out, int outOff) throws DataLengthException, IllegalStateException { try { return ccm.doFinal(out, 0); } catch (InvalidCipherTextException e) { throw new IllegalStateException("exception on doFinal(): " + e.toString()); } }
if (hasAssociatedText()) if (hasAssociatedText()) int textLength = getAssociatedTextLength(); if (textLength < ((1 << 16) - (1 << 8)))
/** * Process a packet of data for either CCM decryption or encryption. * * @param in data for processing. * @param inOff offset at which data starts in the input array. * @param inLen length of the data in the input array. * @return a byte array containing the processed input.. * @throws IllegalStateException if the cipher is not appropriately set up. * @throws InvalidCipherTextException if the input data is truncated or the mac check fails. */ public byte[] processPacket(byte[] in, int inOff, int inLen) throws IllegalStateException, InvalidCipherTextException { byte[] output; if (forEncryption) { output = new byte[inLen + macSize]; } else { if (inLen < macSize) { throw new InvalidCipherTextException("data too short"); } output = new byte[inLen - macSize]; } processPacket(in, inOff, inLen, output, 0); return output; }
calculateMac(in, inOff, inLen, macBlock); calculateMac(output, outOff, outputLen, calculatedMacBlock);
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException { int len = processPacket(data.getBuffer(), 0, data.size(), out, outOff); reset(); return len; }
protected AEADBlockCipher createAEADBlockCipher_AES_CCM() { return new CCMBlockCipher(createAESEngine()); }
private boolean hasAssociatedText() { return getAssociatedTextLength() > 0; }
public CCM() { super(new CCMBlockCipher(new AESEngine()), false, 16); } }
/** * Creates a new AEAD block cipher from the specification in this instance. * * @return New AEAD block cipher instance. */ @Override public AEADBlockCipher newInstance() { final BlockCipher blockCipher = new BlockCipherSpec(algorithm).newInstance(); final AEADBlockCipher aeadBlockCipher; switch (mode) { case "GCM": aeadBlockCipher = new GCMBlockCipher(blockCipher); break; case "CCM": aeadBlockCipher = new CCMBlockCipher(blockCipher); break; case "OCB": aeadBlockCipher = new OCBBlockCipher(blockCipher, new BlockCipherSpec(algorithm).newInstance()); break; case "EAX": aeadBlockCipher = new EAXBlockCipher(blockCipher); break; default: throw new IllegalStateException("Unsupported mode " + mode); } return aeadBlockCipher; }