public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException { this.forEncryption = forEncryption; CipherParameters cipherParameters; if (params instanceof AEADParameters) { AEADParameters param = (AEADParameters) params; nonce = param.getNonce(); initialAssociatedText = param.getAssociatedText(); macSize = param.getMacSize() / 8; cipherParameters = param.getKey(); } else if (params instanceof ParametersWithIV) { ParametersWithIV param = (ParametersWithIV) params; nonce = param.getIV(); initialAssociatedText = null; macSize = macBlock.length / 2; cipherParameters = param.getParameters(); } else { throw new IllegalArgumentException("invalid parameters passed to CCM"); } // NOTE: Very basic support for key re-use, but no performance gain from it if (cipherParameters != null) { keyParam = cipherParameters; } if (nonce == null || nonce.length < 7 || nonce.length > 13) { throw new IllegalArgumentException("nonce must have length from 7 to 13 octets"); } reset(); }
protected byte[] engineGetIV() { return (ivParam != null) ? ivParam.getIV() : null; }