public static byte[] scp03_mac(byte[] keybytes, byte[] msg, int lengthBits) { // Use BouncyCastle light interface. BlockCipher cipher = new AESEngine(); CMac cmac = new CMac(cipher); cmac.init(new KeyParameter(keybytes)); cmac.update(msg, 0, msg.length); byte[] out = new byte[cmac.getMacSize()]; cmac.doFinal(out, 0); return Arrays.copyOf(out, lengthBits / 8); }
private static byte[] doubleLu(byte[] in) { byte[] ret = new byte[in.length]; int carry = shiftLeft(in, ret); int xor = 0xff & (in.length == 16 ? CONSTANT_128 : CONSTANT_64); /* * NOTE: This construction is an attempt at a constant-time implementation. */ ret[in.length - 1] ^= (xor >>> ((1 - carry) << 3)); return ret; }
public CMAC_256() { super(new CMac(new ThreefishEngine(256))); } }
public int doFinal(byte[] out, int outOff) { int blockSize = cipher.getBlockSize(); byte[] lu; if (bufOff == blockSize) { lu = Lu; } else { new ISO7816d4Padding().addPadding(buf, bufOff); lu = Lu2; } for (int i = 0; i < mac.length; i++) { buf[i] ^= lu[i]; } cipher.processBlock(buf, 0, mac, 0); System.arraycopy(mac, 0, out, outOff, macSize); reset(); return macSize; }
public CMAC_512() { super(new CMac(new ThreefishEngine(512))); } }
public int doFinal(byte[] out, int outOff) { int blockSize = cipher.getBlockSize(); byte[] lu; if (bufOff == blockSize) { lu = Lu; } else { new ISO7816d4Padding().addPadding(buf, bufOff); lu = Lu2; } for (int i = 0; i < mac.length; i++) { buf[i] ^= lu[i]; } cipher.processBlock(buf, 0, mac, 0); System.arraycopy(mac, 0, out, outOff, macSize); reset(); return macSize; }
public CMAC() { super(new CMac(new DESEngine())); } }
public static byte[] generateCmac(byte[] key, String msg) throws UnsupportedEncodingException { CMac cmac = new CMac(new AESFastEngine()); byte[] data = msg.getBytes("UTF-8"); byte[] output = new byte[cmac.getMacSize()]; cmac.init(new KeyParameter(key)); cmac.reset(); cmac.update(data, 0, data.length); cmac.doFinal(output, 0); return output; }
private byte[] doubleLu(byte[] in) { byte[] ret = new byte[in.length]; int carry = shiftLeft(in, ret); /* * NOTE: This construction is an attempt at a constant-time implementation. */ int mask = (-carry) & 0xff; ret[in.length - 3] ^= poly[1] & mask; ret[in.length - 2] ^= poly[2] & mask; ret[in.length - 1] ^= poly[3] & mask; return ret; }
public Mac() { super(new CMac(new GOST3412_2015Engine())); } }
public CMAC() { super(new CMac(new DESedeEngine())); } }
public CMAC() { super(new CMac(new SEEDEngine())); } }
public AESCMAC() { super(new CMac(new AESEngine())); } }
public CMAC_1024() { super(new CMac(new ThreefishEngine(1024))); } }
public CMAC() { super(new CMac(new SM4Engine())); } }
public CMAC() { super(new CMac(new Shacal2Engine())); } }
public CMAC() { super(new CMac(new BlowfishEngine())); } }
/** * Constructor that accepts an instance of a block cipher engine. * * @param cipher the engine to use */ public EAXBlockCipher(BlockCipher cipher) { blockSize = cipher.getBlockSize(); mac = new CMac(cipher); macBlock = new byte[blockSize]; associatedTextMac = new byte[mac.getMacSize()]; nonceMac = new byte[mac.getMacSize()]; this.cipher = new SICBlockCipher(cipher); }