Java Code Examples for org.bouncycastle.crypto.macs.CMac

The following examples show how to use org.bouncycastle.crypto.macs.CMac. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: protect   Source File: PseudoRandomFunctionAES.java    License: MIT License 5 votes vote down vote up
public PseudoRandomFunctionAES(final PrfKey key)  {
	super(key);

	// Create CMAC instance based on AES
	final BlockCipher cipher = new AESEngine();
    this.cipherMac = new CMac(cipher);
    
    // Initialize with key
    final KeyParameter params = new KeyParameter(key.getKeyBytes());
    cipherMac.init(params);
}
 
Example 2
private 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);
}
 
Example 3
private static byte[] scp03_kdf(byte[] key, byte[] a, byte[] b, int bytes) {
    BlockCipher cipher = new AESEngine();
    CMac cmac = new CMac(cipher);
    KDFCounterBytesGenerator kdf = new KDFCounterBytesGenerator(cmac);
    kdf.init(new KDFCounterParameters(key, a, b, 8));
    byte[] cgram = new byte[bytes];
    kdf.generateBytes(cgram, 0, cgram.length);
    return cgram;
}
 
Example 4
Source Project: Clusion   Source File: CryptoPrimitives.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 5
public static byte[] scp03_kdf(byte[] key, byte[] a, byte[] b, int bytes) {
    BlockCipher cipher = new AESEngine();
    CMac cmac = new CMac(cipher);
    KDFCounterBytesGenerator kdf = new KDFCounterBytesGenerator(cmac);
    kdf.init(new KDFCounterParameters(key, a, b, 8)); // counter size is in bits
    byte[] cgram = new byte[bytes];
    kdf.generateBytes(cgram, 0, cgram.length);
    return cgram;
}
 
Example 6
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);
}