Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ else if (params instanceof ParametersWithIV)
throw new IllegalArgumentException("invalid parameters passed to KCCM");
}

// TODO Nonce length validation. Should it always be engineBlockSize?
if (newNonce.length < engine.getBlockSize())
{
byte[] tmp = new byte[engine.getBlockSize()];
System.arraycopy(newNonce, 0, tmp, 0, newNonce.length);
newNonce = tmp;
}

// RFC 5116 sec. 2.1 requires a distinct nonce per AEAD encryption under a given key; the
// DSTU 7624 CCM construction inherits this CCM rule (cf. NIST SP 800-38C), and reuse is
// catastrophic (CTR keystream reuse plus a forgeable CBC-MAC). That obligation is the
Expand Down Expand Up @@ -216,11 +224,6 @@ private void processAssociatedText()

boolean hasAssocText = aadLen > 0;

if (hasAssocText && aadLen % engine.getBlockSize() != 0)
{
throw new IllegalArgumentException("padding not supported");
}

// The G1 block binds the nonce, data length and MAC-size flag into the MAC and must be
// processed unconditionally. DSTU 7624 carries the associated-data-present indicator as a flag
// bit inside G1, so it is not a gate on computing G1: skipping G1 when no AAD is present leaves
Expand Down Expand Up @@ -271,9 +274,9 @@ private void processAssociatedText()

int assocOff = 0;
int authLen = aadLen;
while (authLen != 0)
while (authLen > 0)
{
for (int byteIndex = 0; byteIndex < engine.getBlockSize(); byteIndex++)
for (int byteIndex = 0; byteIndex < engine.getBlockSize() && byteIndex < authLen - assocOff; byteIndex++)
{
macBlock[byteIndex] ^= aad[byteIndex + assocOff];
}
Expand Down