Skip to content

Commit 802cce1

Browse files
committed
Preserve mac after doFinal
1 parent 06a406b commit 802cce1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,17 @@ public int processBytes(byte[] input, int inOff, int len, byte[] output,
322322
}
323323

324324
public void reset()
325+
{
326+
reset(true);
327+
}
328+
329+
private void reset(boolean clearMac)
325330
{
326331
this.isEven = true;
327-
this.mac = null;
332+
if (clearMac)
333+
{
334+
this.mac = null;
335+
}
328336
this.aadData.reset();
329337
this.aadFinished = false;
330338
setKey(workingKey, workingIV);
@@ -487,14 +495,9 @@ public int doFinal(byte[] out, int outOff)
487495

488496
System.arraycopy(mac, 0, out, outOff, mac.length);
489497

490-
try
491-
{
492-
return mac.length;
493-
}
494-
finally
495-
{
496-
reset();
497-
}
498+
reset(false);
499+
500+
return mac.length;
498501
}
499502

500503
public byte[] getMac()

0 commit comments

Comments
 (0)