Class AESNistVectorsTest


  • public class AESNistVectorsTest
    extends java.lang.Object
    Checks AES/ECB and AES/CTR against the example vectors of NIST SP 800-38A.

    The expected values come from the standard rather than from a run of the implementation, so they constrain the backend instead of recording what it happens to produce. ECB uses appendix F.1 and CTR appendix F.5, both over the same four-block plaintext, which is what makes the two directly comparable.

    Key sizes are read from com.microej.crypto.test.cipher.aes.keysizes. A VEE Port whose backend lacks one of them shortens the list.

    • Constructor Detail

      • AESNistVectorsTest

        public AESNistVectorsTest()
    • Method Detail

      • testEcbEncryptMatchesNistVector

        public void testEcbEncryptMatchesNistVector()
                                             throws java.lang.Exception
        Encrypting the appendix F plaintext with AES/ECB gives the ciphertext of appendix F.1.
        Throws:
        java.lang.Exception
      • testEcbDecryptMatchesNistVector

        public void testEcbDecryptMatchesNistVector()
                                             throws java.lang.Exception
        Decrypting the appendix F.1 ciphertext with AES/ECB gives the plaintext back.
        Throws:
        java.lang.Exception
      • testCtrEncryptMatchesNistVector

        public void testCtrEncryptMatchesNistVector()
                                             throws java.lang.Exception
        Encrypting the appendix F plaintext with AES/CTR gives the ciphertext of appendix F.5.
        Throws:
        java.lang.Exception
      • testCtrDecryptMatchesNistVector

        public void testCtrDecryptMatchesNistVector()
                                             throws java.lang.Exception
        Decrypting the appendix F.5 ciphertext with AES/CTR gives the plaintext back.
        Throws:
        java.lang.Exception
      • testMultiBlockUpdateMatchesSinglePass

        public void testMultiBlockUpdateMatchesSinglePass()
                                                   throws java.lang.Exception
        Feeding the input one block at a time through update() gives the same output as one doFinal(), when encrypting and when decrypting.

        A four-block input is what makes this worth testing: an implementation that mishandles its internal buffer, or the counter it keeps between two calls, produces the right answer for a single block and the wrong one here.

        Throws:
        java.lang.Exception