public int doFinal(byte[] out, int outOff) throws DataLengthException, IllegalStateException { try { return cipher.doFinal(out, outOff); } catch (InvalidCipherTextException e) { // Impossible in encrypt mode throw new IllegalStateException(e.toString()); } }
public String getAlgorithmName() { return cipher.getUnderlyingCipher().getAlgorithmName() + "-KGMAC"; }
public void update(byte in) throws IllegalStateException { cipher.processAADByte(in); }
processAAD(associatedText.getBuffer(), 0, associatedText.size()); resultLen += ctrEngine.doFinal(out, outOff + resultLen); calculateMac(out, outOff, len); calculateMac(data.getBuffer(), 0, len - macSize); reset(); reset();
public GMAC() { super(new KGMac(new KGCMBlockCipher(new DSTU7624Engine(128)), 128)); } }
private void calculateMac(byte[] input, int inOff, int len) { macBlock = new byte[engine.getBlockSize()]; int totalLength = len; int inOff_ = inOff; while (totalLength > 0) { for (int byteIndex = 0; byteIndex < engine.getBlockSize(); byteIndex++) { b[byteIndex] ^= input[byteIndex + inOff_]; } multiplyOverField(engine.getBlockSize() * BITS_IN_BYTE, b, H, temp); temp = Arrays.reverse(temp); System.arraycopy(temp, 0, b, 0, engine.getBlockSize()); totalLength -= engine.getBlockSize(); inOff_ += engine.getBlockSize(); } Arrays.fill(temp, (byte)0); intToBytes(lambda_o, temp, 0); intToBytes(lambda_c, temp, engine.getBlockSize() / 2); for (int byteIndex = 0; byteIndex < engine.getBlockSize(); byteIndex++) { b[byteIndex] ^= temp[byteIndex]; } engine.processBlock(b, 0, macBlock, 0); }
public void update(byte[] in, int inOff, int len) throws DataLengthException, IllegalStateException { cipher.processAADBytes(in, inOff, len); }
/** * Initialises the GMAC - requires a {@link ParametersWithIV} providing a {@link KeyParameter} * and a nonce. */ public void init(final CipherParameters params) throws IllegalArgumentException { if (params instanceof ParametersWithIV) { final ParametersWithIV param = (ParametersWithIV)params; final byte[] iv = param.getIV(); final KeyParameter keyParam = (KeyParameter)param.getParameters(); // GCM is always operated in encrypt mode to calculate MAC cipher.init(true, new AEADParameters(keyParam, macSizeBits, iv)); } else { throw new IllegalArgumentException("KGMAC requires ParametersWithIV"); } }
private void processAAD(byte[] authText, int authOff, int len) { lambda_o = len * BITS_IN_BYTE; engine.processBlock(H, 0, H, 0); int totalLength = len; int inOff_ = authOff; while (totalLength > 0) { for (int byteIndex = 0; byteIndex < engine.getBlockSize(); byteIndex++) { b[byteIndex] ^= authText[inOff_ + byteIndex]; } multiplyOverField(engine.getBlockSize() * BITS_IN_BYTE, b, H, temp); temp = Arrays.reverse(temp); System.arraycopy(temp, 0, b, 0, engine.getBlockSize()); totalLength -= engine.getBlockSize(); inOff_ += engine.getBlockSize(); } }
public GMAC256() { super(new KGMac(new KGCMBlockCipher(new DSTU7624Engine(256)), 256)); } }
public void reset() { this.H = new byte[engine.getBlockSize()]; this.b = new byte[engine.getBlockSize()]; this.temp = new byte[engine.getBlockSize()]; this.lambda_c = 0; this.lambda_o = 0; engine.reset(); data.reset(); associatedText.reset(); if (initialAssociatedText != null) { processAADBytes(initialAssociatedText, 0, initialAssociatedText.length); } }
public GMAC512() { super(new KGMac(new KGCMBlockCipher(new DSTU7624Engine(512)), 512)); } }
processAADBytes(initialAssociatedText, 0, initialAssociatedText.length);
/** * Creates a KGMAC based on the operation of a block cipher in GCM mode. * <p> * This will produce an authentication code the length of the block size of the cipher. * * @param cipher * the cipher to be used in GCM mode to generate the MAC. */ public KGMac(final KGCMBlockCipher cipher) { // use of this confused flow analyser in some earlier JDKs this.cipher = cipher; this.macSizeBits = cipher.getUnderlyingCipher().getBlockSize() * 8; }
public GCM128() { // TODO: key size is also meant to be fixed super(new KGCMBlockCipher(new DSTU7624Engine(128))); } }
public GCM256() { super(new KGCMBlockCipher(new DSTU7624Engine(256))); } }
public GCM512() { super(new KGCMBlockCipher(new DSTU7624Engine(512))); } }
public GMAC128() { super(new KGMac(new KGCMBlockCipher(new DSTU7624Engine(128)), 128)); } }
if (baseEngine instanceof DSTU7624Engine) cipher = new AEADGenericBlockCipher(new KGCMBlockCipher(baseEngine));