Class AlgorithmResolutionTest
- java.lang.Object
-
- com.microej.crypto.test.AlgorithmResolutionTest
-
public class AlgorithmResolutionTest extends java.lang.ObjectThis test class can be used to validate that the algorithm lookup of a low-level cryptographic implementation allocates nothing.Every LLAPI that resolves an algorithm name returns an algorithm id. That id is a constant of the low-level implementation, and Managed Code never closes it. An implementation that allocates a native resource on each lookup therefore drains the native memory of an application that calls
getInstance()repeatedly.Managed Code cannot read the native memory, so each test drives the public API in a loop instead. It captures a reference result on the first resolution, forces a garbage collection at regular intervals so that everything the implementation may legitimately reclaim is reclaimed, and checks that the reference result still holds. An implementation that leaks runs out of native memory during the loop.
The default loop is short, because this test class shares the testsuite budget with every other test. Raise the
com.microej.crypto.test.algorithmresolution.iterationsproperty to hunt a slow leak.
-
-
Constructor Summary
Constructors Constructor Description AlgorithmResolutionTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidtestCipherResolution()Checks the cipher lookup.voidtestKeyFactoryResolution()Checks the key factory lookup.voidtestKeyGeneratorResolution()Checks the key generator lookup.voidtestKeyPairGeneratorResolution()Checks the key pair generator lookup, which is the one lookup this class cannot follow with an operation.voidtestMacResolution()Checks the MAC lookup.voidtestMessageDigestResolution()Checks the message digest lookup.voidtestSecretKeyFactoryResolution()Checks the secret key factory lookup.voidtestSignatureResolution()Checks the signature lookup.
-
-
-
Method Detail
-
testMessageDigestResolution
public void testMessageDigestResolution() throws java.lang.ExceptionChecks the message digest lookup. It resolvesSHA-256andSHA-512in turn, so a lookup that returns the id of the other algorithm also fails.- Throws:
java.lang.Exception- if a resolution or a digest fails
-
testMacResolution
public void testMacResolution() throws java.lang.ExceptionChecks the MAC lookup. It resolvesHmacSHA1andHmacSHA256in turn, so a lookup that returns the id of the other algorithm also fails.- Throws:
java.lang.Exception- if a resolution or a MAC computation fails
-
testCipherResolution
public void testCipherResolution() throws java.lang.ExceptionChecks the cipher lookup. It resolvesAES/CBC/NoPaddingandAES/ECB/NoPaddingin turn, so a lookup that returns the id of the other transformation also fails.- Throws:
java.lang.Exception- if a resolution or an encryption fails
-
testSecretKeyFactoryResolution
public void testSecretKeyFactoryResolution() throws java.lang.ExceptionChecks the secret key factory lookup. It resolvesPBKDF2WithHmacSHA1andPBKDF2WithHmacSHA256in turn, so a lookup that returns the id of the other algorithm also fails.- Throws:
java.lang.Exception- if a resolution or a key derivation fails
-
testKeyFactoryResolution
public void testKeyFactoryResolution() throws java.lang.ExceptionChecks the key factory lookup. It decodes the sameECpublic key at each resolution, so the encoding it returns must never change.- Throws:
java.lang.Exception- if a resolution or a key decoding fails
-
testKeyGeneratorResolution
public void testKeyGeneratorResolution() throws java.lang.ExceptionChecks the key generator lookup. It generates anAESkey at each resolution, and the key material is random, so only the algorithm and the length of the key can be compared.- Throws:
java.lang.Exception- if a resolution or a key generation fails
-
testSignatureResolution
public void testSignatureResolution() throws java.lang.ExceptionChecks the signature lookup. Like the key pair generator, the loop only resolves the algorithm: a verification needs a certificate and a pre-computed signature, andSignatureTestalready checks that each algorithm id maps to the right algorithm.- Throws:
java.lang.Exception- if a resolution fails
-
testKeyPairGeneratorResolution
public void testKeyPairGeneratorResolution() throws java.lang.ExceptionChecks the key pair generator lookup, which is the one lookup this class cannot follow with an operation. A key generation costs far too much to run in a loop, so the loop only resolves the algorithm. That is enough for the contract under test: an implementation that allocates on each lookup runs out of native memory here.- Throws:
java.lang.Exception- if a resolution fails
-
-