Skip to content

Commit b530e83

Browse files
author
gefeili
committed
Minor change in ISAPEngine
1 parent 26ac00b commit b530e83

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

core/src/main/java/org/bouncycastle/crypto/engines/ISAPEngine.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ public void isap_mac(byte[] ad, int adlen, byte[] c, int clen, byte[] tag)
409409
// Absorb C
410410
ABSORB_MAC(SX, c, clen, E, C);
411411
// Derive K*
412-
shortToByte(SX, tag, 0);
412+
shortToByte(SX, tag);
413413
isap_rk(ISAP_IV2_16, tag, KEY_SIZE, SX, KEY_SIZE, C);
414414
// Squeeze tag
415415
PermuteRoundsHX(SX, E, C);
416-
shortToByte(SX, tag, 0);
416+
shortToByte(SX, tag);
417417
}
418418

419419
public void isap_enc(byte[] m, int mOff, int mlen, byte[] c, int cOff, int clen)
@@ -459,11 +459,11 @@ private void byteToShort(byte[] input, short[] output, int outLen)
459459
}
460460
}
461461

462-
private void shortToByte(short[] input, byte[] output, int outOff)
462+
private void shortToByte(short[] input, byte[] output)
463463
{
464464
for (int i = 0; i < 8; ++i)
465465
{
466-
Pack.shortToLittleEndian(input[i], output, outOff + (i << 1));
466+
Pack.shortToLittleEndian(input[i], output, (i << 1));
467467
}
468468
}
469469

@@ -847,7 +847,7 @@ public int doFinal(byte[] output, int outOff)
847847
}
848848
int len;
849849
byte[] c;
850-
byte[] ad;
850+
byte[] ad = aadData.toByteArray();
851851
if (forEncryption)
852852
{
853853
byte[] enc_input = message.toByteArray();
@@ -859,7 +859,6 @@ public int doFinal(byte[] output, int outOff)
859859
ISAPAEAD.isap_enc(enc_input, 0, len, output, outOff, output.length);
860860
outputStream.write(output, outOff, len);
861861
outOff += len;
862-
ad = aadData.toByteArray();
863862
c = outputStream.toByteArray();
864863
mac = new byte[MAC_SIZE];
865864
ISAPAEAD.isap_mac(ad, ad.length, c, c.length, mac);
@@ -868,7 +867,6 @@ public int doFinal(byte[] output, int outOff)
868867
}
869868
else
870869
{
871-
ad = aadData.toByteArray();
872870
c = message.toByteArray();
873871
mac = new byte[MAC_SIZE];
874872
len = c.length - mac.length;
@@ -887,21 +885,20 @@ public int doFinal(byte[] output, int outOff)
887885
}
888886
ISAPAEAD.isap_enc(c, 0, len, output, outOff, output.length);
889887
}
890-
// reset(false);
891888
return len;
892889
}
893890

894891
@Override
895892
public int getUpdateOutputSize(int len)
896893
{
897-
int total = Math.max(0, len + message.size() + (forEncryption ? 0 : -16));
894+
int total = Math.max(0, len + message.size() + (forEncryption ? 0 : -MAC_SIZE));
898895
return total - total % ISAP_rH_SZ;
899896
}
900897

901898
@Override
902899
public int getOutputSize(int len)
903900
{
904-
return Math.max(0, len + message.size() + (forEncryption ? 16 : -16));
901+
return Math.max(0, len + message.size() + (forEncryption ? MAC_SIZE : -MAC_SIZE));
905902
}
906903

907904
protected void reset(boolean clearMac)

0 commit comments

Comments
 (0)