diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2011-01-28 17:22:04 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2011-01-28 17:22:04 +0000 |
commit | 58ebbe700d922af33b79886f715ee302fb62c523 (patch) | |
tree | 04ef6bd750c0f1a316a300eab11773b42cc3eceb /smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java | |
parent | 6fd90ed8c0ef12aedf8f4121611f35bcec89a06b (diff) | |
download | mocca-58ebbe700d922af33b79886f715ee302fb62c523.tar.gz mocca-58ebbe700d922af33b79886f715ee302fb62c523.tar.bz2 mocca-58ebbe700d922af33b79886f715ee302fb62c523.zip |
Read PuK_QS (secure messaging case1b/2)
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@896 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java')
-rw-r--r-- | smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java b/smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java index f8cedc0e..c614e57f 100644 --- a/smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java +++ b/smccTest/src/main/java/at/gv/egiz/smcc/activation/RetailCBCMac.java @@ -13,6 +13,10 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class RetailCBCMac { + + public enum PADDING { + NoPadding, ISO9797_2 + }; /** * Calculates a Retail CBC Mac from the given message. @@ -53,7 +57,8 @@ public class RetailCBCMac { * @throws InvalidKeyException if the key cannot be used with the Ciphers * @throws GeneralSecurityException if the Cipher operation(s) fails */ - static byte[] retailMac(byte[] msg, + static byte[] retailMac(byte[] msg, + PADDING msgPadding, String cbcCipherAlg, String cipherAlg, SecretKey csk, @@ -84,17 +89,20 @@ public class RetailCBCMac { System.arraycopy(rawCsk, 0, rawCbcCipherKey, 0, blockSize); cbcCipherKey = new SecretKeySpec(rawCbcCipherKey, cbcCipherAlg); } - // if necessary pad message with zeros - byte[] paddedMsg = pad(msg, blockSize); - + + if (msgPadding == PADDING.ISO9797_2) { + // if necessary pad message with zeros + msg = pad(msg, blockSize); + } + // calculate CBC Mac for the first n-1 blocks - int n = paddedMsg.length; + int n = msg.length; int n_1 = n - blockSize; - byte[] cbcMac = cbcMac(paddedMsg, 0, n_1, cbcCipherKey, cbcCipherAlg, blockSize); + byte[] cbcMac = cbcMac(msg, 0, n_1, cbcCipherKey, cbcCipherAlg, blockSize); // calculate retail mac byte[] xor = new byte[blockSize]; - CryptoUtils.xorBlock(paddedMsg, n_1, cbcMac, 0, xor, 0, blockSize); + CryptoUtils.xorBlock(msg, n_1, cbcMac, 0, xor, 0, blockSize); Cipher cipher = Cipher.getInstance(cipherAlg+"/ECB/NoPadding", "IAIK"); cipher.init(Cipher.ENCRYPT_MODE, csk); byte[] retailMac = cipher.doFinal(xor); |