Package com.microej.crypto.test
Class RSACipherTest
- java.lang.Object
-
- com.microej.crypto.test.RSACipherTest
-
public class RSACipherTest extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description RSACipherTest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidloadKeyPairs()Loads the RSA key pair of every configured key size from the test material, so that the class measures the cipher only and runs on a backend without key pair generation.voidtestCipherAtNonZeroOffsets()Encrypting from a sub-range into an offset and decrypting back from a sub-range into an offset round-trip the message for every configured key size, without touching the bytes around either result.voidtestDecryptRejectsTamperedCiphertext()A ciphertext whose bytes were altered does not decrypt, and the failure is theBadPaddingExceptionthatCipher.doFinal(byte[])declares.voidtestRSA_OAEP_params()Test the "RSA/ECB/OAEPWithdigestAndMGF1Padding" cipher with a single-part operation containing 1 byte of input data and explicit OAEP encryption parameters.voidtestRSA_OAEPWithSHA1AndMGF1Padding_MultiPart_16bytes()Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a multi-part operation containing 16 bytes of input data.voidtestRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_16bytes()Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing 16 bytes of input data.voidtestRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_1byte()Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing 1 byte of input data.voidtestRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_lengthError()Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.voidtestRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_maxBytes()Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing max bytes of input data.voidtestRSA_OAEPWithSHA256AndMGF1Padding_MultiPart_16bytes()Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a multi-part operation containing 16 bytes of input data.voidtestRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_16bytes()Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing 16 bytes of input data.voidtestRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_1byte()Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing 1 byte of input data.voidtestRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_lengthError()Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.voidtestRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_maxBytes()Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing max bytes of input data.voidtestRSA_PKCS1Padding_MultiPart_16bytes()Test the "RSA/ECB/PKCS1Padding" cipher with a multi-part operation containing 16 bytes of input data.voidtestRSA_PKCS1Padding_SinglePart_16bytes()Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing 16 bytes of input data.voidtestRSA_PKCS1Padding_SinglePart_1byte()Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing 1 byte of input data.voidtestRSA_PKCS1Padding_SinglePart_lengthError()Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.voidtestRSA_PKCS1Padding_SinglePart_maxBytes()Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing max bytes of input data.
-
-
-
Method Detail
-
loadKeyPairs
public static void loadKeyPairs() throws java.lang.ExceptionLoads the RSA key pair of every configured key size from the test material, so that the class measures the cipher only and runs on a backend without key pair generation.- Throws:
java.lang.Exception- if a key cannot be loaded
-
testRSA_PKCS1Padding_SinglePart_1byte
public void testRSA_PKCS1Padding_SinglePart_1byte() throws java.lang.ExceptionTest the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing 1 byte of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_PKCS1Padding_SinglePart_16bytes
public void testRSA_PKCS1Padding_SinglePart_16bytes() throws java.lang.ExceptionTest the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing 16 bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_PKCS1Padding_MultiPart_16bytes
public void testRSA_PKCS1Padding_MultiPart_16bytes() throws java.lang.ExceptionTest the "RSA/ECB/PKCS1Padding" cipher with a multi-part operation containing 16 bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_PKCS1Padding_SinglePart_maxBytes
public void testRSA_PKCS1Padding_SinglePart_maxBytes() throws java.lang.ExceptionTest the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing max bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_PKCS1Padding_SinglePart_lengthError
public void testRSA_PKCS1Padding_SinglePart_lengthError() throws java.lang.ExceptionTest the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testCipherAtNonZeroOffsets
public void testCipherAtNonZeroOffsets() throws java.lang.ExceptionEncrypting from a sub-range into an offset and decrypting back from a sub-range into an offset round-trip the message for every configured key size, without touching the bytes around either result.An output short by exactly the offset is refused rather than overrun: an implementation computing its capacity from the array length rather than from the length past the offset finds room that is not there.
Neither offset reaches the backend: the RSA cipher buffers its input and copies its result into place itself, so this case checks the library.
- Throws:
java.lang.Exception
-
testDecryptRejectsTamperedCiphertext
public void testDecryptRejectsTamperedCiphertext() throws java.lang.ExceptionA ciphertext whose bytes were altered does not decrypt, and the failure is theBadPaddingExceptionthatCipher.doFinal(byte[])declares. The library raises it only for the error code the abstraction layer declares for a failed decryption, not for a backend failure.A ciphertext is the part of an exchange an attacker reaches, so a caller has to be able to tell "this message is not for me, or was altered" from "the backend broke", and nothing asserted that distinction before.
- Throws:
java.lang.Exception- if the encryption fails
-
testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_1byte
public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_1byte() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing 1 byte of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_16bytes
public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_16bytes() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing 16 bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA1AndMGF1Padding_MultiPart_16bytes
public void testRSA_OAEPWithSHA1AndMGF1Padding_MultiPart_16bytes() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a multi-part operation containing 16 bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_maxBytes
public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_maxBytes() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing max bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_lengthError
public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_lengthError() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_1byte
public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_1byte() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing 1 byte of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_16bytes
public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_16bytes() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing 16 bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA256AndMGF1Padding_MultiPart_16bytes
public void testRSA_OAEPWithSHA256AndMGF1Padding_MultiPart_16bytes() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a multi-part operation containing 16 bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_maxBytes
public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_maxBytes() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing max bytes of input data.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_lengthError
public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_lengthError() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
testRSA_OAEP_params
public void testRSA_OAEP_params() throws java.lang.ExceptionTest the "RSA/ECB/OAEPWithdigestAndMGF1Padding" cipher with a single-part operation containing 1 byte of input data and explicit OAEP encryption parameters.- Throws:
java.lang.Exception- if the encryption or decryption fails.
-
-