Class MacReuseTest
- java.lang.Object
-
- com.microej.crypto.test.MacReuseTest
-
public class MacReuseTest extends java.lang.ObjectChecks that aMacis usable again afterdoFinal()without being re-initialized.javax.crypto.Macspecifies thatdoFinal()leaves the object reset and ready for another message with the same key. Nothing exercised that: every MAC in the rest of the suite is computed by a freshly initialized object, so the reset the backend performs between messages has its effect discarded every time and a reset that keeps the buffered bytes, or leaves the context unusable, is not caught.The expected values are the published RFC 2202 and RFC 4231 vectors, so a wrong result is wrong against the standard rather than against a previous run.
Mac.reset()is deliberately never called here. Reuse afterdoFinal()is the path the specification promises and the one an application takes; callingreset()explicitly would suggest the backend reset is being driven directly, which it is not.
-
-
Constructor Summary
Constructors Constructor Description MacReuseTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidtestDifferentSecondMessageWithoutReinit()A different second message through the same object gives that message's MAC.voidtestReusedMacFedInTwoParts()Feeding the reused object throughupdate()beforedoFinal()gives the same MAC as one call.voidtestSameMessageTwiceWithoutReinit()The same message twice through one object gives the same MAC twice.
-
-
-
Method Detail
-
testSameMessageTwiceWithoutReinit
public void testSameMessageTwiceWithoutReinit() throws java.lang.ExceptionThe same message twice through one object gives the same MAC twice.A reset that leaves the previous message buffered gives a different second value.
- Throws:
java.lang.Exception
-
testDifferentSecondMessageWithoutReinit
public void testDifferentSecondMessageWithoutReinit() throws java.lang.ExceptionA different second message through the same object gives that message's MAC.Repeating one message cannot tell a correct reset from one that reproduces the previous state; a second message can. The key is longer than the block size, so the object also has to keep the hashed key across
doFinal().- Throws:
java.lang.Exception
-
testReusedMacFedInTwoParts
public void testReusedMacFedInTwoParts() throws java.lang.ExceptionFeeding the reused object throughupdate()beforedoFinal()gives the same MAC as one call.This is the ordering that fails when the reset happens on the first
update()afterdoFinal()rather than atdoFinal()itself: the first fragment is discarded and the MAC covers only the rest.- Throws:
java.lang.Exception
-
-