Skip to content

Commit cb38f25

Browse files
author
gefeili
committed
Merge remote-tracking branch 'tonywasher/nistAEADoutputLength' into 1924-lightweight-aead-output-size
2 parents 4580acc + 36e78a4 commit cb38f25

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ public int doFinal(byte[] output, int outOff)
404404
throw new OutputLengthException("output buffer is too short");
405405
}
406406
int mlen = len + messageLen - (forEncryption ? 0 : CRYPTO_ABYTES);
407+
int rv = mlen - messageLen;
407408
int adlen = processAADBytes();
408409
int nblocks_c = 1 + mlen / BLOCK_SIZE;
409410
int nblocks_m = (mlen % BLOCK_SIZE) != 0 ? nblocks_c : nblocks_c - 1;
@@ -418,7 +419,7 @@ public int doFinal(byte[] output, int outOff)
418419
{
419420
System.arraycopy(tag_buffer, 0, tag, 0, CRYPTO_ABYTES);
420421
System.arraycopy(tag, 0, output, outOff, tag.length);
421-
mlen += CRYPTO_ABYTES;
422+
rv += CRYPTO_ABYTES;
422423
}
423424
else
424425
{
@@ -432,7 +433,7 @@ public int doFinal(byte[] output, int outOff)
432433
}
433434
}
434435
reset(false);
435-
return mlen;
436+
return rv;
436437
}
437438

438439
@Override
@@ -455,6 +456,8 @@ public int getUpdateOutputSize(int len)
455456
case EncData:
456457
case EncInit:
457458
return inputOff + len + CRYPTO_ABYTES;
459+
case DecData:
460+
return inputOff + len;
458461
}
459462
return Math.max(0, len + inputOff - CRYPTO_ABYTES);
460463
}
@@ -472,9 +475,9 @@ public int getOutputSize(int len)
472475
case EncAad:
473476
case EncData:
474477
case EncInit:
475-
return len + CRYPTO_ABYTES;
478+
return len + inputOff + CRYPTO_ABYTES;
476479
}
477-
return Math.max(0, len - CRYPTO_ABYTES);
480+
return Math.max(0, len + inputOff - CRYPTO_ABYTES);
478481
}
479482

480483
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ public void init(boolean forEncryption, CipherParameters params)
806806
if (iv == null || iv.length != 16)
807807
{
808808
throw new IllegalArgumentException(
809-
"ISAP AEAD requires exactly 12 bytes of IV");
809+
"ISAP AEAD requires exactly 16 bytes of IV");
810810
}
811811

812812
if (!(ivParams.getParameters() instanceof KeyParameter))
@@ -961,13 +961,13 @@ public byte[] getMac()
961961
@Override
962962
public int getUpdateOutputSize(int len)
963963
{
964-
return len;
964+
return len + message.size();
965965
}
966966

967967
@Override
968968
public int getOutputSize(int len)
969969
{
970-
return len + 16;
970+
return Math.max(0, len + message.size() + (forEncryption ? 16 : -16));
971971
}
972972

973973
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ public byte[] getMac()
270270
@Override
271271
public int getUpdateOutputSize(int len)
272272
{
273-
return len;
273+
return len + message.size();
274274
}
275275

276276
@Override
277277
public int getOutputSize(int len)
278278
{
279-
return len + TAG_INBYTES;
279+
return Math.max(0, len + message.size() + (forEncryption ? TAG_INBYTES : -TAG_INBYTES));
280280
}
281281

282282
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ public byte[] getMac()
262262
@Override
263263
public int getUpdateOutputSize(int len)
264264
{
265-
return len;
265+
return len + message.size();
266266
}
267267

268268
@Override
269269
public int getOutputSize(int len)
270270
{
271-
return len + TAGLEN;
271+
return Math.max(0, len + message.size() + (forEncryption ? TAGLEN : -TAGLEN));
272272
}
273273

274274
@Override

0 commit comments

Comments
 (0)