Class AESCipherTest
- java.lang.Object
-
- com.microej.crypto.test.AESCipherTest
-
public class AESCipherTest extends java.lang.ObjectTests for AES cipher operations including CBC, CTR, and authenticated cipher modes (e.g. GCM, CCM).Authenticated cipher tests are configuration-driven. All properties are prefixed with
com.microej.crypto.test.and hex-encoded unless stated otherwise.cipher.auth.transformations- comma-separated list of transformations to test (default:AES/GCM/NoPadding).<i>in the following properties refers to the 0-based index in this list.cipher.auth.<i>.keySizes- comma-separated key sizes in bits (default:128)cipher.auth.<i>.plaintext- plaintext (default:000102030405060708090a0b0c0d0e0f)cipher.auth.<i>.nonce- nonce (default:0123456789abcdef01234567, 12 bytes)cipher.auth.<i>.aad- additional authenticated data (default:0123456789abcdef0123456789abcdef)cipher.auth.<i>.key.<keySize>- raw key for the given key size (default:0123456789abcdef0123456789abcdef)cipher.auth.<i>.cipherTextAndTag.<keySize>- expected ciphertext+tag without AADcipher.auth.<i>.cipherTextAndTag.<keySize>.withAad- expected ciphertext+tag with AAD
-
-
Constructor Summary
Constructors Constructor Description AESCipherTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidtestAES128_16bytes()Test encryption of 16 data bytes using a 128-bit AES key, and verify the output against a precomputed ciphertext.voidtestAES128_80bytes()Test encryption of 80 data bytes using a 128-bit AES key, and verify the output against a precomputed ciphertext.voidtestAES256_16bytes()Test encryption of 16 data bytes using a 256-bit AES key, and verify the output against a precomputed ciphertext.voidtestAES256_80bytes()Test encryption of 80 data bytes using a 256-bit AES key, and verify the output against a precomputed ciphertext.voidtestAuthenticatedCipherDecrypt()voidtestAuthenticatedCipherDecryptWithAad()voidtestAuthenticatedCipherEncrypt()voidtestAuthenticatedCipherEncryptWithAad()voidtestAuthenticatedCipherRoundTripAtEveryTagLength()Encrypting and decrypting at every tag length the standard allows gives the plaintext back, and the tag is as long as it was asked to be.voidtestCipherAtNonZeroOffsets()Encrypting from a sub-range into an offset produces the ciphertext of the same operation at offset zero, decrypting it back from a sub-range into an offset gives the plaintext, and neither operation touches the bytes around its result, on a block mode and a stream mode.voidtestGetIvReturnsNullForEcb()ECB has no initialization vector, sogetIV()reports none.voidtestGetIvRoundTripsOnCbcCtrAndGcm()A cipher initialized without parameters generates an initialization vector, returns it fromgetIV()with the length the transformation implies, and decrypting with it gives the plaintext back, under a 128-bit and a 256-bit key.voidtestMultiPartCipherAndResetOnDoFinalNoPadding()voidtestMultiPartCipherAtNonZeroOffsets()A multi-part operation whoseupdateanddoFinalboth read from a sub-range and write at an offset produces, end to end, the ciphertext of the single-part operation at offset zero.voidtestParallelCipherEncryption()Test parallel Cipher initialization and encryptionvoidtestReinitWithDifferentKeyAndIv()Initializing an already initialized cipher with another key and another initialization vector gives a cipher that encrypts as a freshly created one does, on a block mode and a stream mode.
-
-
-
Method Detail
-
testAES128_16bytes
public void testAES128_16bytes() throws java.lang.ExceptionTest encryption of 16 data bytes using a 128-bit AES key, and verify the output against a precomputed ciphertext.- Throws:
java.lang.Exception
-
testAES128_80bytes
public void testAES128_80bytes() throws java.lang.ExceptionTest encryption of 80 data bytes using a 128-bit AES key, and verify the output against a precomputed ciphertext.- Throws:
java.lang.Exception
-
testAES256_16bytes
public void testAES256_16bytes() throws java.lang.ExceptionTest encryption of 16 data bytes using a 256-bit AES key, and verify the output against a precomputed ciphertext.- Throws:
java.lang.Exception
-
testAES256_80bytes
public void testAES256_80bytes() throws java.lang.ExceptionTest encryption of 80 data bytes using a 256-bit AES key, and verify the output against a precomputed ciphertext.- Throws:
java.lang.Exception
-
testParallelCipherEncryption
public void testParallelCipherEncryption() throws java.lang.ThrowableTest parallel Cipher initialization and encryption- Throws:
java.lang.Throwable
-
testMultiPartCipherAndResetOnDoFinalNoPadding
public void testMultiPartCipherAndResetOnDoFinalNoPadding() throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
testAuthenticatedCipherEncrypt
public void testAuthenticatedCipherEncrypt() throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
testAuthenticatedCipherEncryptWithAad
public void testAuthenticatedCipherEncryptWithAad() throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
testAuthenticatedCipherDecrypt
public void testAuthenticatedCipherDecrypt() throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
testAuthenticatedCipherDecryptWithAad
public void testAuthenticatedCipherDecryptWithAad() throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
testGetIvRoundTripsOnCbcCtrAndGcm
public void testGetIvRoundTripsOnCbcCtrAndGcm() throws java.lang.ExceptionA cipher initialized without parameters generates an initialization vector, returns it fromgetIV()with the length the transformation implies, and decrypting with it gives the plaintext back, under a 128-bit and a 256-bit key.CBC, CTR and GCM reach the same backend entry point by different routes, so each one is checked on its own. The round trip is what shows the value returned is the value actually used.
- Throws:
java.lang.Exception
-
testReinitWithDifferentKeyAndIv
public void testReinitWithDifferentKeyAndIv() throws java.lang.ExceptionInitializing an already initialized cipher with another key and another initialization vector gives a cipher that encrypts as a freshly created one does, on a block mode and a stream mode.A second initialization is how an application reaches the backend's cipher-close path: the first context has to be released before the second one is allocated.
- Throws:
java.lang.Exception
-
testGetIvReturnsNullForEcb
public void testGetIvReturnsNullForEcb() throws java.lang.ExceptionECB has no initialization vector, sogetIV()reports none.A backend that returns an empty array or a block of zeros here instead of nothing is telling an application it has an IV to carry.
- Throws:
java.lang.Exception
-
testCipherAtNonZeroOffsets
public void testCipherAtNonZeroOffsets() throws java.lang.ExceptionEncrypting from a sub-range into an offset produces the ciphertext of the same operation at offset zero, decrypting it back from a sub-range into an offset gives the plaintext, and neither operation touches the bytes around its result, on a block mode and a stream mode.Comparing against the offset-zero result rather than a written-out ciphertext keeps the case independent of the mode, so both transformations are checked the same way.
- Throws:
java.lang.Exception
-
testMultiPartCipherAtNonZeroOffsets
public void testMultiPartCipherAtNonZeroOffsets() throws java.lang.ExceptionA multi-part operation whoseupdateanddoFinalboth read from a sub-range and write at an offset produces, end to end, the ciphertext of the single-part operation at offset zero.- Throws:
java.lang.Exception
-
testAuthenticatedCipherRoundTripAtEveryTagLength
public void testAuthenticatedCipherRoundTripAtEveryTagLength() throws java.security.GeneralSecurityExceptionEncrypting and decrypting at every tag length the standard allows gives the plaintext back, and the tag is as long as it was asked to be.The expected ciphertext is not written out here: it differs per tag length, and the round trip plus the length check already fail on a backend that ignores the requested length and produces a 16-byte tag, which is the defect this covers.
- Throws:
java.security.GeneralSecurityException
-
-