fix oneShotAES

This commit is contained in:
Michele Balistreri 2019-09-06 15:43:08 +03:00
parent c53b0cd811
commit b9fa61282e
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 4 additions and 3 deletions

View File

@ -62,7 +62,7 @@ public class Crypto {
public short oneShotAES(byte mode, byte[] src, short sOff, short sLen, byte[] dst, short dOff, byte[] key, short keyOff) { public short oneShotAES(byte mode, byte[] src, short sOff, short sLen, byte[] dst, short dOff, byte[] key, short keyOff) {
tmpAES256.setKey(key, keyOff); tmpAES256.setKey(key, keyOff);
aesCbcIso9797m2.init(tmpAES256, mode, src, sOff, AES_BLOCK_SIZE); aesCbcIso9797m2.init(tmpAES256, mode, src, sOff, AES_BLOCK_SIZE);
return aesCbcIso9797m2.doFinal(src, (short) (sOff + AES_BLOCK_SIZE), sLen, dst, dOff); return aesCbcIso9797m2.doFinal(src, (short) (sOff + AES_BLOCK_SIZE), (short) (sLen - AES_BLOCK_SIZE), dst, dOff);
} }
boolean bip32IsHardened(byte[] i, short iOff) { boolean bip32IsHardened(byte[] i, short iOff) {

View File

@ -1180,7 +1180,8 @@ public class KeycardApplet extends Applet {
private short exportDuplicate(byte[] apduBuffer) { private short exportDuplicate(byte[] apduBuffer) {
finalizeDuplicationKey(); finalizeDuplicationKey();
crypto.random.generateData(apduBuffer, SecureChannel.SC_OUT_OFFSET, Crypto.AES_BLOCK_SIZE); crypto.random.generateData(apduBuffer, SecureChannel.SC_OUT_OFFSET, Crypto.AES_BLOCK_SIZE);
short off = (short) (SecureChannel.SC_OUT_OFFSET + Crypto.AES_BLOCK_SIZE); short sOff = (short) (SecureChannel.SC_OUT_OFFSET + Crypto.AES_BLOCK_SIZE);
short off = sOff;
Util.arrayCopyNonAtomic(apduBuffer, SecureChannel.SC_OUT_OFFSET, apduBuffer, off, Crypto.AES_BLOCK_SIZE); Util.arrayCopyNonAtomic(apduBuffer, SecureChannel.SC_OUT_OFFSET, apduBuffer, off, Crypto.AES_BLOCK_SIZE);
off += Crypto.AES_BLOCK_SIZE; off += Crypto.AES_BLOCK_SIZE;
@ -1200,7 +1201,7 @@ public class KeycardApplet extends Applet {
off += CHAIN_CODE_SIZE; off += CHAIN_CODE_SIZE;
} }
return (short) (Crypto.AES_BLOCK_SIZE + crypto.oneShotAES(Cipher.MODE_ENCRYPT, apduBuffer, (short) (SecureChannel.SC_OUT_OFFSET + Crypto.AES_BLOCK_SIZE), off, apduBuffer, (short) (SecureChannel.SC_OUT_OFFSET + Crypto.AES_BLOCK_SIZE), duplicationEncKey, (short) 0)); return (short) (Crypto.AES_BLOCK_SIZE + crypto.oneShotAES(Cipher.MODE_ENCRYPT, apduBuffer, sOff, (short)(off - sOff), apduBuffer, sOff, duplicationEncKey, (short) 0));
} }
private void importDuplicate(byte[] apduBuffer) { private void importDuplicate(byte[] apduBuffer) {