public static byte[] decryptCCM(final byte[] data, final byte[] key, final byte[] nonce, final int micSize) throws InvalidCipherTextException { final byte[] ccm = new byte[data.length - micSize]; final CCMBlockCipher ccmBlockCipher = new CCMBlockCipher(new AESEngine()); final AEADParameters aeadParameters = new AEADParameters(new KeyParameter(key), micSize * 8, nonce); ccmBlockCipher.init(false, aeadParameters); ccmBlockCipher.processBytes(data, 0, data.length, ccm, 0); ccmBlockCipher.doFinal(ccm, 0); return ccm; }
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException { byte[] text = data.toByteArray(); byte[] enc = processPacket(text, 0, text.length); System.arraycopy(enc, 0, out, outOff, enc.length); reset(); return enc.length; }
protected AEADBlockCipher createAEADBlockCipher_AES_CCM() { return new CCMBlockCipher(createAESEngine()); }
public void reset() { ccm.reset(); } }
if (hasAssociatedText()) if (hasAssociatedText()) int textLength = getAssociatedTextLength(); if (textLength < ((1 << 16) - (1 << 8)))
calculateMac(in, inOff, inLen, macBlock); calculateMac(out, 0, out.length, calculatedMacBlock);
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()); } }
/** * 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; }
protected AEADBlockCipher createAEADBlockCipher_AES_CCM() { return new CCMBlockCipher(createAESEngine()); }
calculateMac(in, inOff, inLen, macBlock); calculateMac(output, outOff, outputLen, calculatedMacBlock);
public static byte[] encryptCCM(final byte[] data, final byte[] key, final byte[] nonce) { final byte[] ccm = new byte[25 + 8]; final ByteBuffer buffer = ByteBuffer.allocate(ccm.length + 8); CCMBlockCipher ccmBlockCipher = new CCMBlockCipher(new AESEngine()); AEADParameters aeadParameters = new AEADParameters(new KeyParameter(key), 64, nonce); ccmBlockCipher.init(true, aeadParameters); ccmBlockCipher.processBytes(data, 0, data.length, ccm, data.length); try { ccmBlockCipher.doFinal(ccm, 0); } catch (InvalidCipherTextException e) { e.printStackTrace(); } return ccm; }
public CCM() { super(new CCMBlockCipher(new AESEngine()), false, 16); } }
public int doFinal(byte[] out, int outOff) throws IllegalStateException, InvalidCipherTextException { int len = processPacket(data.getBuffer(), 0, data.size(), out, outOff); reset(); return len; }
public static byte[] encryptCCM(final byte[] data, final byte[] key, final byte[] nonce, final int micSize) { final byte[] ccm = new byte[data.length + micSize]; final CCMBlockCipher ccmBlockCipher = new CCMBlockCipher(new AESEngine()); final AEADParameters aeadParameters = new AEADParameters(new KeyParameter(key), micSize * 8, nonce); ccmBlockCipher.init(true, aeadParameters); ccmBlockCipher.processBytes(data, 0, data.length, ccm, data.length); try { ccmBlockCipher.doFinal(ccm, 0); return ccm; } catch (InvalidCipherTextException e) { Log.e(TAG, "Error wile encrypting: " + e.getMessage()); return null; } }
cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));