macAlg3 static method
Function returns CMAC result according to ISO9797-1 Algorithm 3 scheme using DES encryption algorithm.
The size of key should be 16 or 24 bytes.
The msg if padMsg is set to false should be padded to the nearest multiple of 8.
When padMsg is true, the msg is padded according to the ISO/IEC 9797-1, padding method 2.
Implementation
static macAlg3(Uint8List key, Uint8List msg, {bool padMsg = true}) {
if (key.length != macAlg3_Key1Len && key.length != macAlg3_Key2Len) {
throw ArgumentError.value(key, "key length must be 16 or 24");
}
final ka = key.sublist(0, 8);
final kb = key.sublist(8, 16);
final kc = key.length == macAlg3_Key1Len ? ka : key.sublist(16, 24);
final cipher = DESCipher(key: ka, iv: Uint8List(DESCipher.blockSize));
var mac = cipher.encrypt(msg, padData: padMsg);
mac = mac.sublist(mac.length - DESCipher.blockSize);
cipher.key = kb;
mac = cipher.decryptBlock(mac);
cipher.key = kc;
mac = cipher.encryptBlock(mac);
return mac;
}