From 8a27e0843be848d1076a462142c9783faf28a2b2 Mon Sep 17 00:00:00 2001 From: Jason Katonica Date: Wed, 2 Oct 2024 09:56:36 -0400 Subject: [PATCH] Update tests to use Junit 5 Tests have been updated to use Junit5. Changes made include: - Removing the `junit-vintage-engine` dependency. This is no longer in use given all tests now make use of Junit 5. - Tests are sorted by alphabetical in test suites. - Tests no longer need to extend `junit.framework.TestCase`. - Tests are explicitly declared with the `@Test` annotation. - Test constructors have been removed. Arguments to the base tests are now sent using getters and setters. This is typically only used for setting providers, algorithms, or key sizes in tests. - Various `main()` methods of tests were removed as they are no longer in use. Tests can be run using various Junit 5 test execution tools such as IDEs, command line tools, and `mvn` surefire which is already in place in this project. - `BaseTest` was removed as it is no longer in use and represents a Junit 3 test. A new `BaseTestJunit5` test has been created to represent the new base for the test hierarchy. - The concept of warming up a test has been removed from a few locations. Tests are not expected to act as performance tests. - Copyrights were updated. - Various empty comment blocks were removed. - Some tests were not executing using the expected provider since the incorrect `Utils` class was in use. This was corrected to use the correct class. - Tests `TestAESGCM_192`, `TestAESGCM_256`, and `TestRSA_4096` were added to the `OpenJCEPlus` and `OpenJCEPlusFIPS` provider test suites. - Tests `TestECDHInteropBC`, `TestRSATypeCheckEnabled`, `TestAES_192`, and `TestAES_256` were added to the `OpenJCEPlus` provider test suite - Tests `TestAES_192` and `TestAES_256` were removed from the `TestMultithreadFIPS` since these tests take a long period of time to complete. Coverage functionally is still maintained since they are executed as part of the `OpenJCEPlusFIPS` provider tests. - Increased timeouts associated with tests `TestMultithreadFIPS` and `TestMultithread`. Signed-off-by: Jason Katonica --- pom.xml | 6 - src/test/java/ibm/jceplus/junit/TestAll.java | 6 +- .../ibm/jceplus/junit/TestIntegration.java | 7 +- .../ibm/jceplus/junit/TestMemStressAll.java | 5 +- .../ibm/jceplus/junit/TestMultithread.java | 18 +- .../jceplus/junit/TestMultithreadFIPS.java | 18 +- .../base/BaseByteArrayOutputDelayTest.java | 42 +- .../java/ibm/jceplus/junit/base/BaseTest.java | 27 - .../ibm/jceplus/junit/base/BaseTestAES.java | 324 +++++------ .../jceplus/junit/base/BaseTestAESCCM.java | 62 +-- .../jceplus/junit/base/BaseTestAESCCM2.java | 47 +- .../junit/base/BaseTestAESCCMInteropBC.java | 54 +- .../junit/base/BaseTestAESCCMParameters.java | 56 +- .../junit/base/BaseTestAESCopySafe.java | 25 +- .../jceplus/junit/base/BaseTestAESGCM.java | 150 ++--- .../junit/base/BaseTestAESGCMBufferIV.java | 17 +- .../junit/base/BaseTestAESGCMCICOWithGCM.java | 28 +- .../base/BaseTestAESGCMCICOWithGCMAndAAD.java | 23 +- .../junit/base/BaseTestAESGCMLong.java | 45 +- .../base/BaseTestAESGCMNonExpanding.java | 22 +- .../junit/base/BaseTestAESGCMSameBuffer.java | 15 +- .../junit/base/BaseTestAESGCMUpdate.java | 102 ++-- .../base/BaseTestAESGCMUpdateInteropBC.java | 47 +- .../base/BaseTestAESGCMWithByteBuffer.java | 13 +- .../base/BaseTestAESGCMWithKeyAndIvCheck.java | 18 +- .../junit/base/BaseTestAESGCM_ExtIV.java | 99 ++-- .../junit/base/BaseTestAESGCM_IntIV.java | 95 ++-- .../junit/base/BaseTestAESInterop.java | 291 +++------- .../jceplus/junit/base/BaseTestChaCha20.java | 219 ++++---- .../junit/base/BaseTestChaCha20KAT.java | 29 +- .../junit/base/BaseTestChaCha20NoReuse.java | 56 +- .../junit/base/BaseTestChaCha20Poly1305.java | 263 ++++----- .../BaseTestChaCha20Poly1305ByteBuffer.java | 26 +- .../BaseTestChaCha20Poly1305ChunkUpdate.java | 19 +- .../jceplus/junit/base/BaseTestCipher.java | 10 +- .../jceplus/junit/base/BaseTestDESede.java | 292 +++++----- .../ibm/jceplus/junit/base/BaseTestDH.java | 79 +-- .../jceplus/junit/base/BaseTestDHInterop.java | 72 +-- .../junit/base/BaseTestDHKeyFactory.java | 63 +-- .../base/BaseTestDHKeyPairGenerator.java | 333 +++++------ .../junit/base/BaseTestDHMultiParty.java | 38 +- .../jceplus/junit/base/BaseTestDSAKey.java | 36 +- .../junit/base/BaseTestDSASignature.java | 2 +- .../base/BaseTestDSASignatureInterop.java | 77 +-- .../base/BaseTestDSASignatureInterop2.java | 90 +-- .../ibm/jceplus/junit/base/BaseTestECDH.java | 66 ++- .../junit/base/BaseTestECDHInterop.java | 75 +-- .../junit/base/BaseTestECDHMultiParty.java | 33 +- .../junit/base/BaseTestECDSASignature.java | 6 +- .../base/BaseTestECDSASignatureInterop.java | 155 ++---- .../base/BaseTestECDSASignatureInterop2.java | 207 ++----- .../junit/base/BaseTestECKeyImport.java | 37 +- .../base/BaseTestECKeyImportInterop.java | 43 +- .../base/BaseTestECKeyPairGenerator.java | 41 +- .../junit/base/BaseTestEdDSASignature.java | 3 +- .../base/BaseTestEdDSASignatureInterop.java | 15 +- .../ibm/jceplus/junit/base/BaseTestHKDF.java | 103 ++-- .../junit/base/BaseTestHKDFInterop.java | 42 +- .../jceplus/junit/base/BaseTestHmacMD5.java | 85 +-- .../junit/base/BaseTestHmacMD5Interop.java | 138 ++--- .../jceplus/junit/base/BaseTestHmacSHA1.java | 113 +--- .../junit/base/BaseTestHmacSHA1Interop.java | 140 ++--- .../junit/base/BaseTestHmacSHA224.java | 96 +--- .../junit/base/BaseTestHmacSHA224Interop.java | 107 +--- .../junit/base/BaseTestHmacSHA256.java | 132 +---- .../junit/base/BaseTestHmacSHA256Interop.java | 164 ++---- .../junit/base/BaseTestHmacSHA384.java | 96 +--- .../junit/base/BaseTestHmacSHA384Interop.java | 115 +--- .../junit/base/BaseTestHmacSHA3_224.java | 63 +-- .../junit/base/BaseTestHmacSHA3_256.java | 63 +-- .../junit/base/BaseTestHmacSHA3_384.java | 63 +-- .../junit/base/BaseTestHmacSHA3_512.java | 63 +-- .../junit/base/BaseTestHmacSHA512.java | 96 +--- .../junit/base/BaseTestHmacSHA512Interop.java | 114 +--- .../BaseTestImplementationClassesExist.java | 28 +- .../BaseTestImplementationClassesFinal.java | 28 +- .../jceplus/junit/base/BaseTestInterop.java | 29 - .../junit/base/BaseTestInvalidArrayIndex.java | 21 +- .../base/BaseTestIsAssignableFromOrder.java | 25 +- .../jceplus/junit/base/BaseTestJunit5.java | 50 +- .../junit/base/BaseTestJunit5Interop.java | 32 ++ ...ture.java => BaseTestJunit5Signature.java} | 39 +- .../ibm/jceplus/junit/base/BaseTestMD5.java | 64 +-- .../base/BaseTestMessageDigestClone.java | 23 +- .../junit/base/BaseTestMiniRSAPSS2.java | 91 +-- .../BaseTestPublicMethodsToMakeNonPublic.java | 48 +- .../ibm/jceplus/junit/base/BaseTestRSA.java | 396 ++++--------- .../jceplus/junit/base/BaseTestRSAKey.java | 90 +-- .../junit/base/BaseTestRSAKeyInterop.java | 129 ++--- .../junit/base/BaseTestRSAKeyInteropBC.java | 128 ++--- .../jceplus/junit/base/BaseTestRSAPSS.java | 83 ++- .../jceplus/junit/base/BaseTestRSAPSS2.java | 50 +- .../junit/base/BaseTestRSAPSSInterop.java | 110 ++-- .../junit/base/BaseTestRSAPSSInterop2.java | 44 +- .../junit/base/BaseTestRSAPSSInterop3.java | 125 +---- .../junit/base/BaseTestRSAPSSSignature.java | 5 +- .../junit/base/BaseTestRSASignature.java | 8 +- .../base/BaseTestRSASignatureChunkUpdate.java | 2 +- .../base/BaseTestRSASignatureInterop.java | 114 ++-- .../base/BaseTestRSATypeCheckDisabled.java | 40 +- .../base/BaseTestRSATypeCheckEnabled.java | 43 +- .../ibm/jceplus/junit/base/BaseTestSHA1.java | 82 +-- .../jceplus/junit/base/BaseTestSHA224.java | 69 +-- .../jceplus/junit/base/BaseTestSHA256.java | 72 +-- .../base/BaseTestSHA256Clone_SharedMD.java | 22 +- .../jceplus/junit/base/BaseTestSHA384.java | 72 +-- .../junit/base/BaseTestSHA3_224KAT.java | 48 +- .../junit/base/BaseTestSHA3_256KAT.java | 48 +- .../junit/base/BaseTestSHA3_384KAT.java | 48 +- .../junit/base/BaseTestSHA3_512KAT.java | 48 +- .../jceplus/junit/base/BaseTestSHA512.java | 78 +-- .../junit/base/BaseTestSHA512_224.java | 24 +- .../junit/base/BaseTestSHA512_256.java | 22 +- .../junit/base/BaseTestSignatureInterop.java | 33 +- .../junit/base/BaseTestTruncatedDigest.java | 2 +- .../ibm/jceplus/junit/base/BaseTestXDH.java | 53 +- .../junit/base/BaseTestXDHInterop.java | 33 +- .../junit/base/BaseTestXDHKeyImport.java | 26 +- .../base/BaseTestXDHKeyPairGenerator.java | 31 +- .../junit/base/BaseTestXDHMultiParty.java | 36 +- .../ibm/jceplus/junit/base/BaseUtils.java | 28 +- .../java/ibm/jceplus/junit/base/Record.java | 2 +- .../base/memstress/BaseTestMemStressAES.java | 150 +---- .../memstress/BaseTestMemStressAESGCM.java | 72 +-- .../BaseTestMemStressChaCha20Poly1305.java | 39 +- .../base/memstress/BaseTestMemStressDH.java | 48 +- .../BaseTestMemStressDHKeyFactory.java | 39 +- .../memstress/BaseTestMemStressDHKeyPair.java | 40 +- .../BaseTestMemStressDSAKeyFactory.java | 39 +- .../BaseTestMemStressDSAKeyPair.java | 44 +- .../BaseTestMemStressDSASignature.java | 8 +- .../memstress/BaseTestMemStressDigest.java | 41 +- .../BaseTestMemStressECDSASignature.java | 8 +- .../BaseTestMemStressECKeyFactory.java | 39 +- .../memstress/BaseTestMemStressECKeyPair.java | 44 +- .../base/memstress/BaseTestMemStressHKDF.java | 45 +- .../memstress/BaseTestMemStressHmacSHA.java | 87 +-- .../BaseTestMemStressRSAKeyFactory.java | 39 +- .../BaseTestMemStressRSAKeyPair.java | 39 +- .../memstress/BaseTestMemStressRSAPSS2.java | 29 +- .../BaseTestMemStressRSASignature.java | 8 +- .../base/memstress/BaseTestMemStressSHA.java | 52 +- .../memstress/BaseTestMemStressSHAClone.java | 43 +- .../base/memstress/BaseTestMemStressXDH.java | 31 +- .../jceplus/junit/openjceplus/TestAES.java | 50 +- .../junit/openjceplus/TestAES256Interop.java | 58 +- .../jceplus/junit/openjceplus/TestAESCCM.java | 41 +- .../junit/openjceplus/TestAESCCM2.java | 41 +- .../openjceplus/TestAESCCMInteropBC.java | 50 +- .../openjceplus/TestAESCCMParameters.java | 41 +- .../TestAESCipherInputStreamExceptions.java | 1 - .../junit/openjceplus/TestAESCopySafe.java | 41 +- .../jceplus/junit/openjceplus/TestAESGCM.java | 48 +- .../junit/openjceplus/TestAESGCMBufferIV.java | 29 +- .../openjceplus/TestAESGCMCICOWithGCM.java | 41 +- .../TestAESGCMCICOWithGCMAndAAD.java | 42 +- .../junit/openjceplus/TestAESGCMLong.java | 41 +- .../openjceplus/TestAESGCMNonExpanding.java | 41 +- .../openjceplus/TestAESGCMSameBuffer.java | 41 +- .../junit/openjceplus/TestAESGCMUpdate.java | 48 +- .../TestAESGCMUpdateInteropBC.java | 51 +- .../openjceplus/TestAESGCMWithByteBuffer.java | 41 +- .../TestAESGCMWithKeyAndIvCheck.java | 42 +- .../junit/openjceplus/TestAESGCM_128.java | 44 +- .../junit/openjceplus/TestAESGCM_192.java | 44 +- .../junit/openjceplus/TestAESGCM_256.java | 44 +- .../junit/openjceplus/TestAESGCM_ExtIV.java | 41 +- .../junit/openjceplus/TestAESGCM_IntIV.java | 41 +- .../junit/openjceplus/TestAES_128.java | 48 +- .../junit/openjceplus/TestAES_192.java | 48 +- .../junit/openjceplus/TestAES_256.java | 48 +- .../junit/openjceplus/TestAliases.java | 474 ++++++---------- .../jceplus/junit/openjceplus/TestAll.java | 154 ++++-- .../openjceplus/TestByteArrayOutputDelay.java | 42 +- .../junit/openjceplus/TestChaCha20.java | 41 +- .../junit/openjceplus/TestChaCha20KAT.java | 41 +- .../openjceplus/TestChaCha20NoReuse.java | 41 +- .../openjceplus/TestChaCha20Poly1305.java | 41 +- .../TestChaCha20Poly1305ByteBuffer.java | 42 +- .../TestChaCha20Poly1305ChunkUpdate.java | 30 +- .../jceplus/junit/openjceplus/TestDESede.java | 49 +- .../ibm/jceplus/junit/openjceplus/TestDH.java | 41 +- .../openjceplus/TestDHInteropSunJCE.java | 43 +- .../junit/openjceplus/TestDHKeyFactory.java | 42 +- .../openjceplus/TestDHKeyPairGenerator.java | 41 +- .../junit/openjceplus/TestDHMultiParty.java | 41 +- .../jceplus/junit/openjceplus/TestDSAKey.java | 41 +- .../junit/openjceplus/TestDSASignature.java | 1 + .../TestDSASignatureInteropBC.java | 49 +- .../TestDSASignatureInteropSUN.java | 42 +- .../jceplus/junit/openjceplus/TestECDH.java | 41 +- .../junit/openjceplus/TestECDHInteropBC.java | 50 +- .../openjceplus/TestECDHInteropSunEC.java | 42 +- .../junit/openjceplus/TestECDHMultiParty.java | 41 +- .../TestECDSASignatureInteropBC.java | 51 +- .../TestECDSASignatureInteropSunEC.java | 43 +- .../junit/openjceplus/TestECKeyImport.java | 41 +- .../TestECKeyImportInteropSunEC.java | 42 +- .../openjceplus/TestECKeyPairGenerator.java | 41 +- .../junit/openjceplus/TestEdDSASignature.java | 1 + .../jceplus/junit/openjceplus/TestHKDF.java | 41 +- .../junit/openjceplus/TestHKDFInterop.java | 50 +- .../junit/openjceplus/TestHmacMD5.java | 41 +- .../openjceplus/TestHmacMD5InteropSunJCE.java | 42 +- .../junit/openjceplus/TestHmacSHA1.java | 41 +- .../TestHmacSHA1InteropSunJCE.java | 42 +- .../junit/openjceplus/TestHmacSHA224.java | 41 +- .../TestHmacSHA224InteropSunJCE.java | 42 +- .../junit/openjceplus/TestHmacSHA256.java | 41 +- .../TestHmacSHA256InteropSunJCE.java | 42 +- .../junit/openjceplus/TestHmacSHA384.java | 41 +- .../TestHmacSHA384InteropSunJCE.java | 42 +- .../junit/openjceplus/TestHmacSHA3_224.java | 41 +- .../junit/openjceplus/TestHmacSHA3_256.java | 41 +- .../junit/openjceplus/TestHmacSHA3_384.java | 41 +- .../junit/openjceplus/TestHmacSHA3_512.java | 41 +- .../junit/openjceplus/TestHmacSHA512.java | 41 +- .../TestHmacSHA512InteropSunJCE.java | 42 +- .../TestImplementationClassesExist.java | 42 +- .../TestImplementationClassesFinal.java | 42 +- .../openjceplus/TestInvalidArrayIndex.java | 41 +- .../TestIsAssignableFromOrder.java | 40 +- .../jceplus/junit/openjceplus/TestMD5.java | 42 +- .../junit/openjceplus/TestMiniRSAPSS2.java | 41 +- .../TestPublicMethodsToMakeNonPublic.java | 45 +- .../jceplus/junit/openjceplus/TestRSA.java | 49 +- .../jceplus/junit/openjceplus/TestRSAKey.java | 41 +- .../junit/openjceplus/TestRSAKeyInterop.java | 59 +- .../openjceplus/TestRSAKeyInteropBC.java | 63 +-- .../jceplus/junit/openjceplus/TestRSAPSS.java | 41 +- .../junit/openjceplus/TestRSAPSS2.java | 41 +- .../junit/openjceplus/TestRSAPSSInterop.java | 43 +- .../junit/openjceplus/TestRSAPSSInterop2.java | 41 +- .../junit/openjceplus/TestRSAPSSInterop3.java | 41 +- .../TestRSASignatureInteropSunRsaSign.java | 44 +- .../openjceplus/TestRSATypeCheckDefault.java | 43 +- .../openjceplus/TestRSATypeCheckDisabled.java | 54 +- .../openjceplus/TestRSATypeCheckEnabled.java | 54 +- .../junit/openjceplus/TestRSA_1024.java | 47 +- .../junit/openjceplus/TestRSA_2048.java | 47 +- .../junit/openjceplus/TestRSA_4096.java | 47 +- .../junit/openjceplus/TestRSA_512.java | 47 +- .../jceplus/junit/openjceplus/TestSHA1.java | 41 +- .../jceplus/junit/openjceplus/TestSHA224.java | 41 +- .../jceplus/junit/openjceplus/TestSHA256.java | 41 +- .../jceplus/junit/openjceplus/TestSHA384.java | 41 +- .../junit/openjceplus/TestSHA3_224.java | 42 +- .../junit/openjceplus/TestSHA3_256.java | 41 +- .../junit/openjceplus/TestSHA3_384.java | 41 +- .../junit/openjceplus/TestSHA3_512.java | 41 +- .../jceplus/junit/openjceplus/TestSHA512.java | 41 +- .../junit/openjceplus/TestSHA512_224.java | 41 +- .../junit/openjceplus/TestSHA512_256.java | 41 +- .../openjceplus/TestTruncatedDigest.java | 1 + .../jceplus/junit/openjceplus/TestXDH.java | 40 +- .../junit/openjceplus/TestXDHInterop.java | 41 +- .../junit/openjceplus/TestXDHInteropBC.java | 49 +- .../junit/openjceplus/TestXDHKeyImport.java | 40 +- .../openjceplus/TestXDHKeyPairGenerator.java | 53 +- .../junit/openjceplus/TestXDHMultiParty.java | 40 +- .../ibm/jceplus/junit/openjceplus/Utils.java | 10 +- .../memstress/TestMemStressAES256.java | 40 +- .../memstress/TestMemStressAESGCM.java | 40 +- .../memstress/TestMemStressAll.java | 31 +- .../TestMemStressChaChaPoly1305.java | 39 +- .../memstress/TestMemStressDH.java | 40 +- .../memstress/TestMemStressDHKeyFactory.java | 39 +- .../memstress/TestMemStressDHKeyPair.java | 40 +- .../memstress/TestMemStressDSAKeyFactory.java | 40 +- .../memstress/TestMemStressDSAKeyPair.java | 40 +- .../memstress/TestMemStressECKeyFactory.java | 40 +- .../memstress/TestMemStressECKeyPair.java | 40 +- .../memstress/TestMemStressHKDF.java | 41 +- .../memstress/TestMemStressHmacSHA256.java | 39 +- .../memstress/TestMemStressMD5.java | 40 +- .../memstress/TestMemStressRSAKeyFactory.java | 40 +- .../memstress/TestMemStressRSAKeyPair.java | 40 +- .../memstress/TestMemStressRSAPSS2.java | 40 +- .../memstress/TestMemStressSHA256.java | 40 +- .../memstress/TestMemStressXDH_X25519.java | 40 +- .../memstress/TestMemStressXDH_X448.java | 37 +- .../TestAESCipherInputStreamExceptions.java | 1 - .../multithread/TestAESCopySafe.java | 38 +- .../multithread/TestAESGCMCICOWithGCM.java | 38 +- .../TestAESGCMCICOWithGCMAndAAD.java | 42 +- .../multithread/TestAESGCMLong.java | 36 +- .../multithread/TestAESGCMNonExpanding.java | 41 +- .../multithread/TestAESGCMSameBuffer.java | 37 +- .../multithread/TestAESGCMUpdate.java | 38 +- .../multithread/TestAESGCMWithByteBuffer.java | 37 +- .../TestAESGCMWithKeyAndIvCheck.java | 42 +- .../multithread/TestAESGCM_128.java | 44 +- .../multithread/TestAESGCM_192.java | 45 +- .../multithread/TestAESGCM_256.java | 44 +- .../openjceplus/multithread/TestAES_128.java | 55 +- .../openjceplus/multithread/TestAES_192.java | 57 +- .../openjceplus/multithread/TestAES_256.java | 45 +- .../openjceplus/multithread/TestAliases.java | 486 ++++++---------- .../openjceplus/multithread/TestDESede.java | 47 +- .../junit/openjceplus/multithread/TestDH.java | 37 +- .../openjceplus/multithread/TestDSAKey.java | 43 +- .../TestDSASignatureInteropSUN.java | 40 +- .../openjceplus/multithread/TestECDH.java | 63 +-- .../multithread/TestECDHInteropSunEC.java | 38 +- .../openjceplus/multithread/TestHKDF.java | 37 +- .../openjceplus/multithread/TestHmacMD5.java | 36 +- .../multithread/TestHmacMD5InteropSunJCE.java | 37 +- .../multithread/TestHmacSHA256.java | 36 +- .../TestHmacSHA256InteropSunJCE.java | 38 +- .../multithread/TestHmacSHA3_224.java | 38 +- .../multithread/TestHmacSHA3_256.java | 37 +- .../multithread/TestHmacSHA3_384.java | 37 +- .../multithread/TestHmacSHA3_512.java | 37 +- .../multithread/TestMiniRSAPSS2.java | 42 +- .../openjceplus/multithread/TestRSAKey.java | 41 +- .../openjceplus/multithread/TestRSAPSS.java | 41 +- .../openjceplus/multithread/TestRSAPSS2.java | 41 +- .../multithread/TestRSAPSSInterop2.java | 42 +- .../multithread/TestRSAPSSInterop3.java | 42 +- .../TestRSASignatureInteropSunRsaSign.java | 44 +- .../openjceplus/multithread/TestRSA_2048.java | 45 +- .../multithread/TestSHA256Clone_SharedMD.java | 43 +- .../openjceplus/multithread/TestSHA3_224.java | 37 +- .../openjceplus/multithread/TestSHA3_256.java | 38 +- .../openjceplus/multithread/TestSHA3_384.java | 37 +- .../openjceplus/multithread/TestSHA3_512.java | 37 +- .../openjceplus/multithread/TestSHA512.java | 35 +- .../multithread/TestSHA512_224.java | 25 +- .../multithread/TestSHA512_256.java | 50 +- .../openjceplus/multithread/TestXDH.java | 61 +- .../multithread/TestXDHKeyImport.java | 42 +- .../multithread/TestXDHKeyPairGenerator.java | 41 +- .../multithread/TestXDHMultiParty.java | 41 +- .../junit/openjceplusfips/TestAES.java | 50 +- .../openjceplusfips/TestAES256Interop.java | 57 +- .../junit/openjceplusfips/TestAESCCM.java | 41 +- .../junit/openjceplusfips/TestAESCCM2.java | 41 +- .../openjceplusfips/TestAESCCMInteropBC.java | 50 +- .../openjceplusfips/TestAESCCMParameters.java | 41 +- .../TestAESCipherInputStreamExceptions.java | 2 - .../openjceplusfips/TestAESCopySafe.java | 42 +- .../junit/openjceplusfips/TestAESGCM.java | 48 +- .../openjceplusfips/TestAESGCMBufferIV.java | 29 +- .../TestAESGCMCICOWithGCM.java | 41 +- .../TestAESGCMCICOWithGCMAndAAD.java | 42 +- .../junit/openjceplusfips/TestAESGCMLong.java | 41 +- .../TestAESGCMNonExpanding.java | 42 +- .../openjceplusfips/TestAESGCMSameBuffer.java | 41 +- .../openjceplusfips/TestAESGCMUpdate.java | 48 +- .../TestAESGCMWithByteBuffer.java | 41 +- .../TestAESGCMWithKeyAndIvCheck.java | 43 +- .../junit/openjceplusfips/TestAESGCM_128.java | 44 +- .../junit/openjceplusfips/TestAESGCM_192.java | 44 +- .../junit/openjceplusfips/TestAESGCM_256.java | 44 +- .../openjceplusfips/TestAESGCM_ExtIV.java | 41 +- .../openjceplusfips/TestAESGCM_IntIV.java | 41 +- .../junit/openjceplusfips/TestAES_128.java | 48 +- .../junit/openjceplusfips/TestAES_192.java | 48 +- .../junit/openjceplusfips/TestAES_256.java | 48 +- .../junit/openjceplusfips/TestAliases.java | 309 ++++------- .../junit/openjceplusfips/TestAll.java | 112 +++- .../junit/openjceplusfips/TestChaCha20.java | 41 +- .../TestChaCha20Poly1305ChunkUpdate.java | 32 +- .../junit/openjceplusfips/TestDESede.java | 51 +- .../jceplus/junit/openjceplusfips/TestDH.java | 41 +- .../openjceplusfips/TestDHInteropSunJCE.java | 43 +- .../openjceplusfips/TestDHKeyFactory.java | 42 +- .../TestDHKeyPairGenerator.java | 41 +- .../openjceplusfips/TestDHMultiParty.java | 41 +- .../junit/openjceplusfips/TestDSAKey.java | 16 +- .../openjceplusfips/TestDSASignature.java | 1 + .../TestDSASignatureInteropSUN.java | 42 +- .../junit/openjceplusfips/TestECDH.java | 41 +- .../openjceplusfips/TestECDHInteropSunEC.java | 42 +- .../openjceplusfips/TestECDHMultiParty.java | 41 +- .../TestECDSASignatureInteropSunEC.java | 43 +- .../openjceplusfips/TestECKeyImport.java | 41 +- .../TestECKeyImportInteropSunEC.java | 42 +- .../TestECKeyPairGenerator.java | 41 +- .../TestFIPSVerifyOnlyTest.java | 57 +- .../junit/openjceplusfips/TestHKDF.java | 41 +- .../openjceplusfips/TestHKDFInterop.java | 53 +- .../junit/openjceplusfips/TestHmacMD5.java | 41 +- .../TestHmacMD5InteropSunJCE.java | 42 +- .../junit/openjceplusfips/TestHmacSHA1.java | 41 +- .../TestHmacSHA1InteropSunJCE.java | 42 +- .../junit/openjceplusfips/TestHmacSHA224.java | 41 +- .../TestHmacSHA224InteropSunJCE.java | 42 +- .../junit/openjceplusfips/TestHmacSHA256.java | 41 +- .../TestHmacSHA256InteropSunJCE.java | 42 +- .../junit/openjceplusfips/TestHmacSHA384.java | 41 +- .../TestHmacSHA384InteropSunJCE.java | 42 +- .../openjceplusfips/TestHmacSHA3_224.java | 42 +- .../openjceplusfips/TestHmacSHA3_256.java | 42 +- .../openjceplusfips/TestHmacSHA3_384.java | 42 +- .../openjceplusfips/TestHmacSHA3_512.java | 42 +- .../junit/openjceplusfips/TestHmacSHA512.java | 41 +- .../TestHmacSHA512InteropSunJCE.java | 42 +- .../TestImplementationClassesExist.java | 42 +- .../TestImplementationClassesFinal.java | 42 +- .../TestInvalidArrayIndex.java | 41 +- .../junit/openjceplusfips/TestMD5.java | 42 +- .../openjceplusfips/TestMiniRSAPSS2.java | 42 +- .../TestPublicMethodsToMakeNonPublic.java | 45 +- .../junit/openjceplusfips/TestRSA.java | 49 +- .../junit/openjceplusfips/TestRSAKey.java | 41 +- .../openjceplusfips/TestRSAKeyInterop.java | 50 +- .../openjceplusfips/TestRSAKeyInteropBC.java | 63 +-- .../junit/openjceplusfips/TestRSAPSS.java | 41 +- .../junit/openjceplusfips/TestRSAPSS2.java | 41 +- .../openjceplusfips/TestRSAPSSInterop.java | 42 +- .../openjceplusfips/TestRSAPSSInterop2.java | 41 +- .../openjceplusfips/TestRSAPSSInterop3.java | 41 +- .../openjceplusfips/TestRSASignature.java | 1 + .../TestRSASignatureChunkUpdate.java | 4 +- .../TestRSASignatureInteropSunRsaSign.java | 44 +- .../TestRSATypeCheckDefault.java | 43 +- .../TestRSATypeCheckDisabled.java | 59 +- .../TestRSATypeCheckEnabled.java | 59 +- .../junit/openjceplusfips/TestRSA_1024.java | 47 +- .../junit/openjceplusfips/TestRSA_2048.java | 47 +- .../junit/openjceplusfips/TestRSA_4096.java | 47 +- .../junit/openjceplusfips/TestSHA1.java | 41 +- .../junit/openjceplusfips/TestSHA224.java | 41 +- .../junit/openjceplusfips/TestSHA256.java | 41 +- .../junit/openjceplusfips/TestSHA384.java | 41 +- .../junit/openjceplusfips/TestSHA3_224.java | 42 +- .../junit/openjceplusfips/TestSHA3_256.java | 41 +- .../junit/openjceplusfips/TestSHA3_384.java | 41 +- .../junit/openjceplusfips/TestSHA3_512.java | 41 +- .../junit/openjceplusfips/TestSHA512.java | 41 +- .../jceplus/junit/openjceplusfips/Utils.java | 8 +- .../openjceplusfips/integration/TestTLS.java | 1 - .../TestAESCipherInputStreamExceptions.java | 3 +- .../multithread/TestAESCopySafe.java | 38 +- .../multithread/TestAESGCMCICOWithGCM.java | 39 +- .../TestAESGCMCICOWithGCMAndAAD.java | 42 +- .../multithread/TestAESGCMLong.java | 36 +- .../multithread/TestAESGCMNonExpanding.java | 41 +- .../multithread/TestAESGCMSameBuffer.java | 37 +- .../multithread/TestAESGCMUpdate.java | 38 +- .../multithread/TestAESGCMWithByteBuffer.java | 37 +- .../TestAESGCMWithKeyAndIvCheck.java | 42 +- .../multithread/TestAESGCM_128.java | 45 +- .../multithread/TestAESGCM_192.java | 46 +- .../multithread/TestAESGCM_256.java | 45 +- .../multithread/TestAES_128.java | 56 +- .../multithread/TestAES_192.java | 58 +- .../multithread/TestAES_256.java | 46 +- .../multithread/TestAliases.java | 522 ++++++------------ .../multithread/TestDESede.java | 47 +- .../openjceplusfips/multithread/TestDH.java | 21 +- .../multithread/TestDSAKey.java | 12 +- .../TestDSASignatureInteropSUN.java | 41 +- .../openjceplusfips/multithread/TestECDH.java | 62 +-- .../multithread/TestECDHInteropSunEC.java | 38 +- .../openjceplusfips/multithread/TestHKDF.java | 39 +- .../multithread/TestHmacMD5.java | 37 +- .../multithread/TestHmacMD5InteropSunJCE.java | 38 +- .../multithread/TestHmacSHA256.java | 37 +- .../TestHmacSHA256InteropSunJCE.java | 38 +- .../multithread/TestHmacSHA3_224.java | 22 +- .../multithread/TestHmacSHA3_256.java | 22 +- .../multithread/TestHmacSHA3_384.java | 22 +- .../multithread/TestHmacSHA3_512.java | 22 +- .../multithread/TestMiniRSAPSS2.java | 42 +- .../multithread/TestRSAKey.java | 41 +- .../multithread/TestRSAPSS.java | 41 +- .../multithread/TestRSAPSS2.java | 42 +- .../multithread/TestRSAPSSInterop2.java | 42 +- .../multithread/TestRSAPSSInterop3.java | 42 +- .../TestRSASignatureInteropSunRsaSign.java | 44 +- .../multithread/TestRSA_2048.java | 46 +- .../multithread/TestSHA256Clone_SharedMD.java | 43 +- .../multithread/TestSHA3_224.java | 22 +- .../multithread/TestSHA3_256.java | 20 +- .../multithread/TestSHA3_384.java | 24 +- .../multithread/TestSHA3_512.java | 22 +- .../multithread/TestSHA512.java | 50 +- .../multithread/TestSHA512_224.java | 21 +- .../multithread/TestSHA512_256.java | 21 +- 481 files changed, 7073 insertions(+), 17863 deletions(-) delete mode 100644 src/test/java/ibm/jceplus/junit/base/BaseTest.java delete mode 100644 src/test/java/ibm/jceplus/junit/base/BaseTestInterop.java create mode 100644 src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Interop.java rename src/test/java/ibm/jceplus/junit/base/{BaseTestSignature.java => BaseTestJunit5Signature.java} (56%) diff --git a/pom.xml b/pom.xml index 4f100ee5..526eb34b 100644 --- a/pom.xml +++ b/pom.xml @@ -551,12 +551,6 @@ 4.13.2 test - - org.junit.vintage - junit-vintage-engine - 5.11.0 - test - org.junit.platform junit-platform-suite diff --git a/src/test/java/ibm/jceplus/junit/TestAll.java b/src/test/java/ibm/jceplus/junit/TestAll.java index f78cf865..5e5b8aa2 100644 --- a/src/test/java/ibm/jceplus/junit/TestAll.java +++ b/src/test/java/ibm/jceplus/junit/TestAll.java @@ -11,8 +11,10 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; -@SelectClasses({ibm.jceplus.junit.openjceplus.TestAll.class, - ibm.jceplus.junit.openjceplusfips.TestAll.class,}) +@SelectClasses({ + ibm.jceplus.junit.openjceplus.TestAll.class, + ibm.jceplus.junit.openjceplusfips.TestAll.class +}) @Suite public class TestAll { diff --git a/src/test/java/ibm/jceplus/junit/TestIntegration.java b/src/test/java/ibm/jceplus/junit/TestIntegration.java index eb2d639b..d6a984ca 100644 --- a/src/test/java/ibm/jceplus/junit/TestIntegration.java +++ b/src/test/java/ibm/jceplus/junit/TestIntegration.java @@ -10,8 +10,11 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; -@SelectClasses({ibm.jceplus.junit.openjceplus.integration.TestAll.class, - ibm.jceplus.junit.openjceplusfips.integration.TestAll.class}) +@SelectClasses({ + ibm.jceplus.junit.openjceplus.integration.TestAll.class, + ibm.jceplus.junit.openjceplusfips.integration.TestAll.class +}) + @Suite public class TestIntegration { } diff --git a/src/test/java/ibm/jceplus/junit/TestMemStressAll.java b/src/test/java/ibm/jceplus/junit/TestMemStressAll.java index ea04910e..d2750a67 100644 --- a/src/test/java/ibm/jceplus/junit/TestMemStressAll.java +++ b/src/test/java/ibm/jceplus/junit/TestMemStressAll.java @@ -11,7 +11,10 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; -@SelectClasses({ibm.jceplus.junit.openjceplus.memstress.TestMemStressAll.class}) +@SelectClasses({ + ibm.jceplus.junit.openjceplus.memstress.TestMemStressAll.class +}) + @Suite public class TestMemStressAll { } diff --git a/src/test/java/ibm/jceplus/junit/TestMultithread.java b/src/test/java/ibm/jceplus/junit/TestMultithread.java index a585e173..dc6d2426 100644 --- a/src/test/java/ibm/jceplus/junit/TestMultithread.java +++ b/src/test/java/ibm/jceplus/junit/TestMultithread.java @@ -16,18 +16,20 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; import org.junit.platform.launcher.core.LauncherFactory; import org.junit.platform.launcher.listeners.SummaryGeneratingListener; import org.junit.platform.launcher.listeners.TestExecutionSummary; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; -public class TestMultithread extends TestCase { +public class TestMultithread { private final int numThreads = 10; - private final int timeoutSec = 3000; + private final int timeoutSec = 4500; private final String[] testList = { "ibm.jceplus.junit.openjceplus.multithread.TestAES_128", "ibm.jceplus.junit.openjceplus.multithread.TestAES_192", @@ -113,12 +115,13 @@ public void run() { } // wait until all threads are ready assertTrue( - "Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent", - allExecutorThreadsReady.await(numThreads * 50, TimeUnit.MILLISECONDS)); + allExecutorThreadsReady.await(numThreads * 100, TimeUnit.MILLISECONDS), + "Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent"); // start all test runners afterInitBlocker.countDown(); - assertTrue(message + " timeout! More than " + maxTimeoutSeconds + " seconds", - allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS)); + assertTrue( + allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS), + message + " timeout! More than " + maxTimeoutSeconds + " seconds"); } finally { threadPool.shutdownNow(); } @@ -154,6 +157,7 @@ public List call() { }; } + @Test public void testMultithread() { System.out.println("#threads=" + numThreads + " timeout=" + timeoutSec); diff --git a/src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java b/src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java index 153e6ff4..dfd60f2d 100644 --- a/src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java +++ b/src/test/java/ibm/jceplus/junit/TestMultithreadFIPS.java @@ -15,18 +15,20 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; import org.junit.platform.launcher.core.LauncherFactory; import org.junit.platform.launcher.listeners.SummaryGeneratingListener; import org.junit.platform.launcher.listeners.TestExecutionSummary; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; -public class TestMultithreadFIPS extends TestCase { +public class TestMultithreadFIPS { private final int numThreads = 10; - private final int timeoutSec = 3000; + private final int timeoutSec = 4500; private final String[] testList = { "ibm.jceplus.junit.openjceplusfips.multithread.TestAES_128", "ibm.jceplus.junit.openjceplusfips.multithread.TestAES_192", @@ -108,12 +110,13 @@ public void run() { } // wait until all threads are ready assertTrue( - "Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent", - allExecutorThreadsReady.await(numThreads * 50, TimeUnit.MILLISECONDS)); + allExecutorThreadsReady.await(numThreads * 100, TimeUnit.MILLISECONDS), + "Timeout initializing threads! Perform long lasting initializations before passing runnables to assertConcurrent"); // start all test runners afterInitBlocker.countDown(); - assertTrue(message + " timeout! More than " + maxTimeoutSeconds + " seconds", - allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS)); + assertTrue( + allDone.await(maxTimeoutSeconds, TimeUnit.SECONDS), + message + " timeout! More than " + maxTimeoutSeconds + " seconds"); } finally { threadPool.shutdownNow(); } @@ -149,6 +152,7 @@ public List call() { }; } + @Test public void testMultithreadFIPS() { System.out.println("#threads=" + numThreads + " timeout=" + timeoutSec); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseByteArrayOutputDelayTest.java b/src/test/java/ibm/jceplus/junit/base/BaseByteArrayOutputDelayTest.java index cf6c45be..670bdd41 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseByteArrayOutputDelayTest.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseByteArrayOutputDelayTest.java @@ -14,6 +14,7 @@ import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; +import org.junit.jupiter.api.Test; /** * Test class for ByteArrayOutputDelay @@ -21,10 +22,6 @@ */ public class BaseByteArrayOutputDelayTest extends BaseTestPublicMethodsToMakeNonPublic { - public BaseByteArrayOutputDelayTest(String providerName) { - super(providerName); - } - private static byte[] TEST_DATA = new byte[1024]; static { @@ -36,42 +33,35 @@ public BaseByteArrayOutputDelayTest(String providerName) { private static int TEST_COUNT = 0; - public static void main(String[] args) throws IOException { - - testSingleByte(); - testIllegalByteDelay(); - testDifferentDelayWritingByteAtATime(); - testDelayLargerThanInput(); - testDelaySameSizeAsInput(); - testRandom(); - - System.out.println("Number of succesful tests = " + TEST_COUNT); - } - - public static void testInputSizeNotMultipleOfDelay() throws IOException { + @Test + public void testInputSizeNotMultipleOfDelay() throws IOException { testByteArrayOutputDelay(16, 11, TEST_DATA); // test left overs } - public static void testDelaySameSizeAsInput() throws IOException { + @Test + public void testDelaySameSizeAsInput() throws IOException { testByteArrayOutputDelay(1024, 1024, TEST_DATA); // test one shot } - public static void testDelayLargerThanInput() throws IOException { + @Test + public void testDelayLargerThanInput() throws IOException { testByteArrayOutputDelay(4096, 1, TEST_DATA); // test buffer larger than data } - public static void testRandom() throws IOException { + @Test + public void testRandom() throws IOException { testRandom(20); } - public static void testDifferentDelayWritingByteAtATime() throws IOException { + @Test + public void testDifferentDelayWritingByteAtATime() throws IOException { for (int bufferSize = 0; bufferSize < 17; ++bufferSize) { testByteArrayOutputDelay(bufferSize, 1, TEST_DATA); } } - private static void testRandom(int iterations) throws IOException { + private void testRandom(int iterations) throws IOException { System.out.println("Running " + iterations + " random iterations"); Random random = new SecureRandom(); @@ -96,7 +86,8 @@ private static void testRandom(int iterations) throws IOException { * * @throws IOException */ - public static void testSingleByte() throws IOException { + @Test + public void testSingleByte() throws IOException { byte[] oneByte = {(byte) 255}; testByteArrayOutputDelay(0, 1, oneByte); // no buffer testByteArrayOutputDelay(1, 1, oneByte); @@ -109,7 +100,8 @@ public static void testSingleByte() throws IOException { * * @throws IOException */ - public static void testIllegalByteDelay() throws IOException { + @Test + public void testIllegalByteDelay() throws IOException { byte[] oneByte = {(byte) 255}; try { testByteArrayOutputDelay(-1, 1, oneByte); @@ -129,7 +121,7 @@ public static void testIllegalByteDelay() throws IOException { * @param testData - data test with * @throws IOException */ - public static void testByteArrayOutputDelay(int delayByte, int chopSize, byte[] testData) + private void testByteArrayOutputDelay(int delayByte, int chopSize, byte[] testData) throws IOException { System.out.println("Test bufferSize: " + delayByte + " chopSize: " + chopSize + " Total length of input data: " + testData.length); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTest.java b/src/test/java/ibm/jceplus/junit/base/BaseTest.java deleted file mode 100644 index 5e247a82..00000000 --- a/src/test/java/ibm/jceplus/junit/base/BaseTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright IBM Corp. 2023 - * - * Licensed under the Apache License 2.0 (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution. - */ - -package ibm.jceplus.junit.base; - -import junit.framework.TestCase; - -public class BaseTest extends TestCase { - //-------------------------------------------------------------------------- - // - // - protected String providerName; - - - //-------------------------------------------------------------------------- - // - // - public BaseTest(String providerName) { - this.providerName = providerName; - } -} - diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAES.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAES.java index fa498eb7..6b5b5abc 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAES.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAES.java @@ -14,7 +14,6 @@ import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; -import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; @@ -27,44 +26,42 @@ import javax.crypto.spec.RC2ParameterSpec; import javax.crypto.spec.RC5ParameterSpec; import javax.crypto.spec.SecretKeySpec; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class BaseTestAES extends BaseTestCipher { // 14 bytes: PASSED - static final byte[] plainText14 = "12345678123456".getBytes(); + final byte[] plainText14 = "12345678123456".getBytes(); // 16 bytes: PASSED - static final byte[] plainText16 = "1234567812345678".getBytes(); + final byte[] plainText16 = "1234567812345678".getBytes(); // 18 bytes: PASSED - static final byte[] plainText18 = "123456781234567812".getBytes(); + final byte[] plainText18 = "123456781234567812".getBytes(); // 63 bytes: PASSED - static final byte[] plainText63 = "123456781234567812345678123456781234567812345678123456781234567" + final byte[] plainText63 = "123456781234567812345678123456781234567812345678123456781234567" .getBytes(); // 128 bytes: PASSED - static final byte[] plainText128 = "12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678" + final byte[] plainText128 = "12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678" .getBytes(); // 512, 65536, 524288 bytes, payload increment of 32 bytes (up to 16384 bytes) : PASSED - static Random r = new Random(5); - static int iteration = 0; - static final byte[] plainText512 = new byte[512]; - static final byte[] plainText65536 = new byte[65536]; - static final byte[] plainText524288 = new byte[524288]; - static final byte[] plainText1048576 = new byte[1048576]; - static final byte[] plainText16KB = new byte[16384]; - static final byte[] plainText = plainText128; // default value - - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; - protected SecretKey key; + Random r = new Random(5); + int iteration = 0; + final byte[] plainText512 = new byte[512]; + final byte[] plainText65536 = new byte[65536]; + final byte[] plainText524288 = new byte[524288]; + final byte[] plainText1048576 = new byte[1048576]; + final byte[] plainText16KB = new byte[16384]; + final byte[] plainText = plainText128; // default value + + protected SecretKey key, key128, key192, key256; protected AlgorithmParameters params = null; /* @@ -74,220 +71,239 @@ public class BaseTestAES extends BaseTestCipher { */ protected Cipher cp = null; protected boolean success = true; - protected int specifiedKeySize = 0; - - public BaseTestAES(String providerName) { - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - } - } - - public BaseTestAES(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - } - } - - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @BeforeAll + public void setUpBeforeClass() throws Exception { r.nextBytes(plainText512); r.nextBytes(plainText65536); r.nextBytes(plainText524288); r.nextBytes(plainText1048576); r.nextBytes(plainText16KB); + + byte[] encodedKey128 = new byte[16]; + byte[] encodedKey192 = new byte[24]; + byte[] encodedKey256 = new byte[32]; + r.nextBytes(encodedKey128); + r.nextBytes(encodedKey192); + r.nextBytes(encodedKey256); + key128 = new SecretKeySpec(encodedKey128, 0, encodedKey128.length, "AES"); + key192 = new SecretKeySpec(encodedKey192, 0, encodedKey192.length, "AES"); + key256 = new SecretKeySpec(encodedKey256, 0, encodedKey256.length, "AES"); } - @Before + @BeforeEach public void setUp() throws Exception { - byte[] encodedKey = new byte[(specifiedKeySize > 0 ? specifiedKeySize : 128) / 8]; - r.nextBytes(encodedKey); - key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); + + int keySize = getKeySize(); + if (getKeySize() == 128) { + key = key128; + } else if (keySize == 192) { + key = key192; + } else if (keySize == 256) { + key = key256; + } else { + throw new Exception("Illegal key size in BaseTestAES."); + } } + @Test public void testAES() throws Exception { encryptDecrypt("AES"); } + @Test public void testAES_CBC_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/CBC/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/CBC/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testAES_CBC_NoPadding() throws Exception { encryptDecrypt("AES/CBC/NoPadding", true, false); } + @Test public void testAES_CBC_PKCS5Padding() throws Exception { encryptDecrypt("AES/CBC/PKCS5Padding"); } + @Test public void testAES_CFB_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/CFB/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/CFB/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testAES_CFB8_NoPadding() throws Exception { encryptDecrypt("AES/CFB8/NoPadding"); } + @Test public void testAES_CFB_NoPadding() throws Exception { encryptDecrypt("AES/CFB/NoPadding"); } + @Test public void testAES_CFB8_PKCS5Padding() throws Exception { encryptDecrypt("AES/CFB8/PKCS5Padding"); } + @Test public void testAES_CFB_PKCS5Padding() throws Exception { encryptDecrypt("AES/CFB/PKCS5Padding"); } + @Test public void testAES_CFB128_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/CFB128/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/CFB128/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testAES_CFB128_NoPadding() throws Exception { encryptDecrypt("AES/CFB128/NoPadding"); } + @Test public void testAES_CFB128_PKCS5Padding() throws Exception { encryptDecrypt("AES/CFB128/PKCS5Padding"); } + @Test public void testAES_CTR_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/CTR/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/CTR/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testAES_CTR_NoPadding() throws Exception { encryptDecrypt("AES/CTR/NoPadding"); } + @Test public void testAES_CTR_PKCS5Padding() throws Exception { encryptDecrypt("AES/CTR/PKCS5Padding"); } + @Test public void testAES_CTS_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/CTS/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/CTS/ISO10126Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testAES_CTS_NoPadding() throws Exception { try { - cp = Cipher.getInstance("AES/CTS/NoPadding", providerName); + cp = Cipher.getInstance("AES/CTS/NoPadding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testAES_CTS_PKCS5Padding() throws Exception { try { - cp = Cipher.getInstance("AES/CTS/PKCS5Padding", providerName); + cp = Cipher.getInstance("AES/CTS/PKCS5Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testAES_ECB_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/ECB/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/ECB/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testAES_ECB_NoPadding() throws Exception { encryptDecrypt("AES/ECB/NoPadding", true, false); } + @Test public void testAES_ECB_PKCS5Padding() throws Exception { encryptDecrypt("AES/ECB/PKCS5Padding"); } + @Test public void testAES_OFB_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/OFB/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/OFB/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testAES_OFB_NoPadding() throws Exception { encryptDecrypt("AES/OFB/NoPadding"); } + @Test public void testAES_OFB_PKCS5Padding() throws Exception { encryptDecrypt("AES/OFB/PKCS5Padding"); } + @Test public void testAES_PCBC_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("AES/PCBC/ISO10126Padding", providerName); + cp = Cipher.getInstance("AES/PCBC/ISO10126Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testAES_PCBC_NoPadding() throws Exception { try { - cp = Cipher.getInstance("AES/PCBC/NoPadding", providerName); + cp = Cipher.getInstance("AES/PCBC/NoPadding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testAES_PCBC_PKCS5Padding() throws Exception { try { - cp = Cipher.getInstance("AES/PCBC/PKCS5Padding", providerName); + cp = Cipher.getInstance("AES/PCBC/PKCS5Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testAESShortBuffer() throws Exception { try { // Test AES Cipher - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -299,9 +315,10 @@ public void testAESShortBuffer() throws Exception { } } + @Test public void testAESIllegalBlockSizeEncrypt() throws Exception { try { - Cipher cp = Cipher.getInstance("AES/CBC/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/CBC/NoPadding", getProviderName()); int blockSize = cp.getBlockSize(); byte[] message = new byte[blockSize - 1]; @@ -317,9 +334,10 @@ public void testAESIllegalBlockSizeEncrypt() throws Exception { } } + @Test public void testAESIllegalBlockSizeDecrypt() throws Exception { try { - Cipher cp = Cipher.getInstance("AES/CBC/PKCS5Padding", providerName); + Cipher cp = Cipher.getInstance("AES/CBC/PKCS5Padding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -337,10 +355,11 @@ public void testAESIllegalBlockSizeDecrypt() throws Exception { } } + @Test public void testAESBadPaddingDecrypt() throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException { try { - Cipher cp = Cipher.getInstance("AES/CBC/PKCS5Padding", providerName); + Cipher cp = Cipher.getInstance("AES/CBC/PKCS5Padding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -365,17 +384,19 @@ public void testAESBadPaddingDecrypt() throws NoSuchAlgorithmException, NoSuchPr } } + @Test public void testAESNoSuchAlgorithm() throws Exception { try { - cp = Cipher.getInstance("AES/BBC/PKCS5Padding", providerName); + cp = Cipher.getInstance("AES/BBC/PKCS5Padding", getProviderName()); fail("Expected NoSuchAlgorithmException did not occur"); } catch (NoSuchAlgorithmException ex) { assertTrue(true); } } + @Test public void testAESNull() throws Exception { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); SecretKey nullKey = null; try { @@ -392,8 +413,9 @@ public void testAESNull() throws Exception { } } + @Test public void testIllegalParamSpec() throws Exception { - Cipher cp = Cipher.getInstance("AES/CBC/PKCS5Padding", providerName); + Cipher cp = Cipher.getInstance("AES/CBC/PKCS5Padding", getProviderName()); try { byte[] iv = null; @@ -445,16 +467,17 @@ public void testIllegalParamSpec() throws Exception { } } + @Test public void testArguments() throws Exception { try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0]); } catch (Exception e) { @@ -462,21 +485,21 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0)"); @@ -484,7 +507,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1); fail("Should have gotten exception on doFinal(new byte[0], 1)"); @@ -492,7 +515,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[cp.getOutputSize(0)], 1); fail("Expected ShortBufferException"); @@ -500,28 +523,28 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0); } catch (Exception e) { @@ -529,7 +552,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1, 0); fail("Did not get expected exception on doFinal(new byte[0], 1, 0)"); @@ -537,7 +560,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 1); fail("Did not get expected exception on doFinal(new byte[0], 0, 1)"); @@ -545,14 +568,14 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0, null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0]); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0, 9, new byte[0])"); @@ -560,14 +583,14 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0], 0); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0, 0, new byte[0], 0)"); @@ -575,14 +598,14 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0]); } catch (Exception e) { @@ -590,28 +613,28 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 1, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0); } catch (Exception e) { @@ -619,63 +642,63 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 1, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, new byte[0]); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES", providerName); + Cipher cp = Cipher.getInstance("AES", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { @@ -760,7 +783,7 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult AlgorithmParameters algParams, byte[] message) throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -803,7 +826,7 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult // protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message) throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -851,7 +874,7 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti protected void encryptDecryptPartialUpdate(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message) throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -903,7 +926,7 @@ protected void encryptDecryptReuseObject(String algorithm, throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -952,7 +975,7 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm, throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1002,7 +1025,7 @@ protected void encryptDecryptUpdateCopySafe(String algorithm, throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1051,78 +1074,7 @@ protected void encryptDecryptUpdateCopySafe(String algorithm, } } - //-------------------------------------------------------------------------- - // warmup functions for enable fastjni - // - static public void warmup() throws Exception { - java.security.Provider java_provider = null; - int modeInt; - boolean stream = false; - SecretKeySpec skey; - int key_size = 128; - byte[] skey_bytes = new byte[key_size / 8]; - int len = 4096; - byte[] iv; - byte[] data = plainText16; - byte[] out; - Cipher cipher; - Random r; - try { - java_provider = java.security.Security.getProvider("OpenJCEPlus"); - if (java_provider == null) { - java_provider = new com.ibm.crypto.plus.provider.OpenJCEPlus(); - java.security.Security.insertProviderAt(java_provider, 1); - } - - r = new Random(10); - String mode = "encrypt_stream"; - String cipherMode = "AES/CBC/NoPadding"; - - if (mode.contains("encrypt")) - modeInt = 1; - else if (mode.contains("decrypt")) - modeInt = 0; - else - throw new RuntimeException("Unsupported mode"); - - if (mode.contains("block")) - stream = false; - else if (mode.contains("stream")) - stream = true; - else - throw new RuntimeException("block mode or stream mode must be specified"); - - r.nextBytes(skey_bytes); - skey = new SecretKeySpec(skey_bytes, "AES"); - - - for (int i = 0; i < 999999; i++) { - cipher = Cipher.getInstance(cipherMode, java_provider); - out = new byte[len]; - iv = new byte[16]; - r.nextBytes(iv); - AlgorithmParameterSpec iviv = new IvParameterSpec(iv); - - if (modeInt == 0) - cipher.init(Cipher.DECRYPT_MODE, skey, iviv); - else - cipher.init(Cipher.ENCRYPT_MODE, skey, iviv); - if (stream) { - for (long j = 0; j < 9; j++) - cipher.update(data, 0, data.length, out); - } else { - for (long k = 0; k < 9; k++) { - cipher.update(data, 0, data.length, out); - // cipher.doFinal(); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } - + @Test public void testUpdateForAES_CBC_PKCS5Padding() throws Exception { try { @@ -1134,7 +1086,7 @@ public void testUpdateForAES_CBC_PKCS5Padding() throws Exception { Arrays.fill(key, (byte) 1); SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES"); - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", providerName); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", getProviderName()); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] plain = new byte[10000]; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM.java index d848f87e..5ece9b4a 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,10 +19,11 @@ import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import org.junit.Assert; +import org.junit.jupiter.api.Test; // This test case exercises the AES/CCM cipher using a CCMParameterSpec object -public class BaseTestAESCCM extends BaseTest { +public class BaseTestAESCCM extends BaseTestJunit5 { public static int iterationLimit = 100; public static int iterationCounter = 0; @@ -49,23 +50,10 @@ public class BaseTestAESCCM extends BaseTest { private static Object myMutexObject = new Object(); - public static String provider; public static boolean printJunitTrace = false; - - - public BaseTestAESCCM(String providerName) { - super(providerName); - provider = providerName; - printJunitTrace = Boolean - .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - protected void setUp() throws Exception {} - - - public static void testAESCCM() throws Exception { + @Test + public void testAESCCM() throws Exception { while (iterationCounter < iterationLimit) { iterationCounter++; @@ -123,7 +111,7 @@ public static void testAESCCM() throws Exception { } - KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", provider); + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", getProviderName()); if (printJunitTrace) System.out.println("BaseTestAESCCM.java: testAESCCM(): The KeyGenerator is a: " + keyGenerator.getClass().getName()); @@ -282,7 +270,6 @@ public static void testAESCCM() throws Exception { } // end iteration loop - synchronized (myMutexObject) { if (printJunitTrace) System.out.println( @@ -303,9 +290,7 @@ public static void testAESCCM() throws Exception { } // end testAESCCM() - - - private static byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV, int ccmTagLength) + private byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV, int ccmTagLength) throws Exception { synchronized (myMutexObject) { if (printJunitTrace) @@ -320,7 +305,7 @@ private static byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV, int cc } // Get Cipher Instance - Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", provider); + Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", getProviderName()); if (printJunitTrace) System.out.println( "BaseTestAESCCM.java: encrypt(): The encryption cipher is a: " @@ -563,9 +548,7 @@ else if (whichMethod == 4) { return cipherText; } // end encrypt( ) - - - private static String decrypt(byte[] cipherText, SecretKey key, byte[] IV, int ccmTagLength) + private String decrypt(byte[] cipherText, SecretKey key, byte[] IV, int ccmTagLength) throws Exception { synchronized (myMutexObject) { @@ -581,7 +564,7 @@ private static String decrypt(byte[] cipherText, SecretKey key, byte[] IV, int c } // Get Cipher Instance - Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", provider); + Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", getProviderName()); if (printJunitTrace) System.out.println( "BaseTestAESCCM.java: decrypt(): The decryption cipher is a: " @@ -827,11 +810,9 @@ else if (whichMethod == 4) { return new String(decryptedText); } // end decrypt( ) - - // This CCM tag length is specified in bits. Valid values are: 32, 48, 64, 80, 96, 112, 128 // The ccmTagLength will be selected randomly for each iteration. - private static int computeTagLength() { + private int computeTagLength() { int ccmTagLength = 0; // Generate a random tag length of: 32, 48, 64, 80, 96, 112, or 128) @@ -858,7 +839,7 @@ private static int computeTagLength() { // The IV buffer length is specified in bytes. Valid values are 7 thru 13 inclusive. // The ivBufferLength will be selected randomly for each iteration. - private static int computeIVBufferLength() { + private int computeIVBufferLength() { int ivBufferLength = 0; // Generate a random IV buffer length ( 7 bytes thru 13 bytes inclusive ) @@ -882,24 +863,8 @@ private static int computeIVBufferLength() { return ivBufferLength; } - - - // public static void main(String args[]) { - // try { - // BaseTestAESCCM test = new BaseTestAESCCM(); - // test.testAESCCM(); - // } - // catch (Exception ex) - // { - // if (printJunitTrace) System.out.println("main() BaseTestAESCCM.java: The following exception was thrown:"); - // ex.printStackTrace( System.out ); - // } - // } - - - /** * Converts a byte array to hex string */ - private static String toHexString(byte[] block) { + private String toHexString(byte[] block) { StringBuffer buf = new StringBuffer(); char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; @@ -920,5 +885,4 @@ private static String toHexString(byte[] block) { return buf.toString(); } - } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM2.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM2.java index 66e3b816..e4cdcb5f 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM2.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCM2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,10 +20,11 @@ import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import org.junit.Assert; +import org.junit.jupiter.api.Test; // This test case exercises the AES/CCM cipher using a CCMParameters object -public class BaseTestAESCCM2 extends BaseTest { +public class BaseTestAESCCM2 extends BaseTestJunit5 { public int iterationLimit = 100; public int iterationCounter = 0; @@ -50,22 +51,9 @@ public class BaseTestAESCCM2 extends BaseTest { private Object myMutexObject = new Object(); - public String provider; - public boolean printJunitTrace = false; - - public BaseTestAESCCM2(String providerName) { - super(providerName); - provider = providerName; - printJunitTrace = Boolean - .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - protected void setUp() throws Exception {} - - + @Test public void testAESCCM() throws Exception { while (iterationCounter < iterationLimit) { @@ -94,7 +82,6 @@ public void testAESCCM() throws Exception { plainText = plainTextLong; } - // IF USED, THIS DEBUG BLOCK OF CODE WILL ENSURE THAT THE SAME plaintext WILL BE USED FOR EVERY ITERATION // plainText = plainTextShort; @@ -124,7 +111,7 @@ public void testAESCCM() throws Exception { } - KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", provider); + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", getProviderName()); if (printJunitTrace) System.out.println("BaseTestAESCCM2.java: testAESCCM(): The KeyGenerator is a: " + keyGenerator.getClass().getName()); @@ -322,7 +309,7 @@ private byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV, int ccmTagLen } // Get Cipher Instance - Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", provider); + Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", getProviderName()); if (printJunitTrace) System.out.println( "BaseTestAESCCM2.java: encrypt(): The encryption cipher is a: " @@ -349,7 +336,7 @@ private byte[] encrypt(byte[] plaintext, SecretKey key, byte[] IV, int ccmTagLen // Create a CCMParameters object AlgorithmParameters ccmParameters = null; try { - ccmParameters = AlgorithmParameters.getInstance("CCM", provider); + ccmParameters = AlgorithmParameters.getInstance("CCM", getProviderName()); ccmParameters.init(ccmParameterSpec); } catch (Exception ex) { if (printJunitTrace) @@ -596,7 +583,7 @@ private String decrypt(byte[] cipherText, SecretKey key, byte[] IV, int ccmTagLe } // Get Cipher Instance - Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", provider); + Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", getProviderName()); if (printJunitTrace) System.out.println( "BaseTestAESCCM2.java: decrypt(): The decryption cipher is a: " @@ -623,7 +610,7 @@ private String decrypt(byte[] cipherText, SecretKey key, byte[] IV, int ccmTagLe // Create a CCMParameters object AlgorithmParameters ccmParameters = null; try { - ccmParameters = AlgorithmParameters.getInstance("CCM", provider); + ccmParameters = AlgorithmParameters.getInstance("CCM", getProviderName()); ccmParameters.init(ccmParameterSpec); } catch (Exception ex) { if (printJunitTrace) @@ -910,22 +897,6 @@ private static int computeIVBufferLength() { return ivBufferLength; } - - - // public static void main(String args[]) { - // try { - // BaseTestAESCCM2 test = new BaseTestAESCCM2(); - // test.testAESCCM(); - // } - // catch (Exception ex) - // { - // if (printJunitTrace) System.out.println("main() BaseTestAESCCM2.java: The following exception was thrown:"); - // ex.printStackTrace( System.out ); - // } - // } - - - /** * Converts a byte array to hex string */ private static String toHexString(byte[] block) { StringBuffer buf = new StringBuffer(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMInteropBC.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMInteropBC.java index bce61bd4..491c32bc 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMInteropBC.java @@ -17,14 +17,12 @@ import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import org.junit.Assert; +import org.junit.jupiter.api.Test; -// This test case exercises the AES/CCM cipher using a CCMParameterSpec object. - -// This test case was compiled with: -// javac -Xlint:deprecation -cp .;.\hamcrest-core-1.3.jar;.\junit-4.13.jar;.\bcprov-jdk18on-173.jar - - -public class BaseTestAESCCMInteropBC extends BaseTestInterop { +/** + * This test case exercises the AES/CCM cipher using a CCMParameterSpec object. + */ +public class BaseTestAESCCMInteropBC extends BaseTestJunit5Interop { public static int iterationLimit = 100; public static int iterationCounter = 0; @@ -51,27 +49,12 @@ public class BaseTestAESCCMInteropBC extends BaseTestInterop { private static Object myMutexObject = new Object(); - public static String provider = null; - public static String interopProvider = null; - public static String encryptionProvider = null; public static String decryptionProvider = null; public static boolean printJunitTrace = false; - - public BaseTestAESCCMInteropBC(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - provider = providerName; - interopProvider = interopProviderName; - printJunitTrace = Boolean - .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - protected void setUp() throws Exception {} - - - public static void testAESCCM() throws Exception { + @Test + public void testAESCCM() throws Exception { while (iterationCounter < iterationLimit) { iterationCounter++; @@ -92,12 +75,12 @@ public static void testAESCCM() throws Exception { Random randomForEncryptionProviderSelection = new Random(); int whichEncryptionProvider = randomForEncryptionProviderSelection.nextInt(2); // The specified value is excluded if (whichEncryptionProvider == 0) { - encryptionProvider = provider; - decryptionProvider = interopProvider; + encryptionProvider = getProviderName(); + decryptionProvider = getInteropProviderName(); } else // else whichEncryptionProvider == 1 { - encryptionProvider = interopProvider; - decryptionProvider = provider; + encryptionProvider = getInteropProviderName(); + decryptionProvider = getProviderName(); } if (printJunitTrace) @@ -897,21 +880,6 @@ private static int computeIVBufferLength() { return ivBufferLength; } - - // public static void main(String args[]) { - // try { - // BaseTestInteropBC test = new BaseTestInteropBC(); - // test.testAESCCM(); - // } - // catch (Exception ex) - // { - // if (printJunitTrace) System.out.println("main() BaseTestInteropBC.java: The following exception was thrown:"); - // ex.printStackTrace( System.out ); - // } - // } - - - /** * Converts a byte array to hex string */ private static String toHexString(byte[] block) { StringBuffer buf = new StringBuffer(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMParameters.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMParameters.java index b3453c33..892017d7 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMParameters.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCCMParameters.java @@ -15,8 +15,9 @@ import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; +import org.junit.jupiter.api.Test; -public class BaseTestAESCCMParameters extends BaseTest { +public class BaseTestAESCCMParameters extends BaseTestJunit5 { // Valid tagLen values in bits are 32, 48, 64, 80, 96, 112, 128 public static int tagLenMaximum = 128; public static int tagLenMinimum = 32; @@ -36,29 +37,8 @@ public class BaseTestAESCCMParameters extends BaseTest { private static Object myMutexObject = new Object(); - public static String provider; - - - public BaseTestAESCCMParameters(String providerName) { - super(providerName); - provider = providerName; - } - - - protected void setUp() throws Exception {} - - - // public static void main(String[] args) throws Exception - // { - // testAESCCMParameterSpec(); - // testAESCCMParameters(); - // testAESCCMParameterGenerator(); - // - // System.out.println("\n====== END OF SUCCESSFUL TEST ======"); - // } - - - public static void testAESCCMParameterSpec() { + @Test + public void testAESCCMParameterSpec() { synchronized (myMutexObject) { System.out.println( "\n======================================================================"); @@ -241,7 +221,8 @@ public static void testAESCCMParameterSpec() { //========================================================================================== - public static void testAESCCMParameters() { + @Test + public void testAESCCMParameters() { synchronized (myMutexObject) { System.out.println( "\n==================================================================="); @@ -264,7 +245,7 @@ public static void testAESCCMParameters() { AlgorithmParameters ccmParameters1 = null; try { - ccmParameters1 = AlgorithmParameters.getInstance("CCM", provider); // This is an instance of CCMParameters. + ccmParameters1 = AlgorithmParameters.getInstance("CCM", getProviderName()); // This is an instance of CCMParameters. ccmParameters1.init(ccmParameterSpec1); } catch (Exception ex) { System.out.println( @@ -291,7 +272,7 @@ public static void testAESCCMParameters() { } - if (!(ccmParameters1.getProvider().getName().equals(provider))) { + if (!(ccmParameters1.getProvider().getName().equals(getProviderName()))) { System.out.println( "testAESCCMParameters(): ERROR: ccmParameters1.getProvider().getname() did not return the string \"OpenJCEPlus\". "); RuntimeException rtex = new RuntimeException(); @@ -358,7 +339,7 @@ public static void testAESCCMParameters() { byte[] ccmParameters2Encoded = null; try { ccmParameters2Encoded = ccmParameters1Encoded; - ccmParameters2 = AlgorithmParameters.getInstance("CCM", provider); // This is an instance of CCMParameters. + ccmParameters2 = AlgorithmParameters.getInstance("CCM", getProviderName()); // This is an instance of CCMParameters. ccmParameters2.init(ccmParameters2Encoded); } catch (Exception ex) { System.out.println( @@ -376,7 +357,7 @@ public static void testAESCCMParameters() { Assert.fail(); } - if (!(ccmParameters2.getProvider().getName().equals(provider))) { + if (!(ccmParameters2.getProvider().getName().equals(getProviderName()))) { System.out.println( "testAESCCMParameters(): ERROR: ccmParameters2.getProvider() did not return the string \"OpenJCEPlus\". "); RuntimeException rtex = new RuntimeException(); @@ -392,7 +373,7 @@ public static void testAESCCMParameters() { byte[] ccmParameters3Encoded = null; try { ccmParameters3Encoded = ccmParameters2Encoded; - ccmParameters3 = AlgorithmParameters.getInstance("CCM", provider); // This is an instance of CCMParameters. + ccmParameters3 = AlgorithmParameters.getInstance("CCM", getProviderName()); // This is an instance of CCMParameters. ccmParameters3.init(ccmParameters3Encoded, "decodingMethod"); } catch (Exception ex) { System.out.println( @@ -410,7 +391,7 @@ public static void testAESCCMParameters() { Assert.fail(); } - if (!(ccmParameters3.getProvider().getName().equals(provider))) { + if (!(ccmParameters3.getProvider().getName().equals(getProviderName()))) { System.out.println( "testAESCCMParameters(): ERROR: ccmParameters3.getProvider() did not return the string \"OpenJCEPlus\". "); RuntimeException rtex = new RuntimeException(); @@ -450,7 +431,8 @@ public static void testAESCCMParameters() { //========================================================================================== - public static void testAESCCMParameterGenerator() { + @Test + public void testAESCCMParameterGenerator() { synchronized (myMutexObject) { System.out.println( "\n=========================================================================="); @@ -463,7 +445,7 @@ public static void testAESCCMParameterGenerator() { Provider openJCEPlusProvider = null; java.security.Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; ++i) { - if ((providers[i].getName()).equals(provider)) { + if ((providers[i].getName()).equals(getProviderName())) { openJCEPlusProvider = providers[i]; break; } @@ -480,7 +462,7 @@ public static void testAESCCMParameterGenerator() { AlgorithmParameterGenerator ccmParameterGenerator = null; try { - ccmParameterGenerator = AlgorithmParameterGenerator.getInstance("CCM", provider); + ccmParameterGenerator = AlgorithmParameterGenerator.getInstance("CCM", getProviderName()); } catch (Exception ex) { System.out.println( "testAESCCMParameterGenerator(): ERROR: The unexpected exception below was thrown while getting a CCMParameterGenerator object. "); @@ -507,7 +489,7 @@ public static void testAESCCMParameterGenerator() { } - if (!(ccmParameterGenerator.getProvider().getName().equals(provider))) { + if (!(ccmParameterGenerator.getProvider().getName().equals(getProviderName()))) { System.out.println( "testAESCCMParameterGenerator(): ERROR: ccmParameterGenerator.getProvider().getName() did not return the string \"OpenJCEPlus\". "); RuntimeException rtex = new RuntimeException(); @@ -558,7 +540,7 @@ public static void testAESCCMParameterGenerator() { } - if (!(algorithmParameters.getProvider().getName().equals(provider))) { + if (!(algorithmParameters.getProvider().getName().equals(getProviderName()))) { System.out.println( "testAESCCMParameterGenerator(): ERROR: algorithmParameters.getProvider().getName() did not return the string \"OpenJCEPlus\". "); RuntimeException rtex = new RuntimeException(); @@ -662,7 +644,7 @@ public static void testAESCCMParameterGenerator() { Assert.fail(); } - if (!(algorithmParameters.getProvider().getName().equals(provider))) { + if (!(algorithmParameters.getProvider().getName().equals(getProviderName()))) { System.out.println( "testAESCCMParameterGenerator(): ERROR: algorithmParameters.getProvider().getName() did not return the string \"OpenJCEPlus\". "); RuntimeException rtex = new RuntimeException(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCopySafe.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCopySafe.java index 346f1369..781e44b3 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESCopySafe.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESCopySafe.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -18,10 +18,11 @@ import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; -import org.junit.Assume; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestAESCopySafe extends BaseTest { +public class BaseTestAESCopySafe extends BaseTestJunit5 { private static final boolean DEBUG = false; private static final int INPUT_LENGTH = 32; // should be a multiple of block size @@ -32,27 +33,17 @@ public class BaseTestAESCopySafe extends BaseTest { enum MODE { CBC, GCM }; - protected int specifiedKeySize = 0; - - public BaseTestAESCopySafe(String providerName) { - super(providerName); - this.specifiedKeySize = 128; - } - - public BaseTestAESCopySafe(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - } + protected int specifiedKeySize = 128; + @Test public void testOverlappingBuffer() throws Exception { KEY = new SecretKeySpec(new byte[specifiedKeySize / 8], "AES"); for (MODE mode : MODE.values()) { String transformation = "AES/" + mode.toString() + "/NoPadding"; - Cipher c = Cipher.getInstance(transformation, providerName); - System.out.println("Testing " + transformation + " from provider: " + providerName); + Cipher c = Cipher.getInstance(transformation, getProviderName()); + System.out.println("Testing " + transformation + " from provider: " + getProviderName()); for (int inputOffset : OFFSETS) { for (int outputOffset : OFFSETS) { System.out.println("Mode: " + mode + " inputOffset: " + inputOffset + " outputOffset: " + outputOffset); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM.java index c2763749..755bacbc 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM.java @@ -28,9 +28,12 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.RC2ParameterSpec; import javax.crypto.spec.RC5ParameterSpec; -import org.junit.Assume; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestAESGCM extends BaseTest { +public class BaseTestAESGCM extends BaseTestJunit5 { // 14 bytes: PASSED static final byte[] plainText14 = "12345678123456".getBytes(); @@ -96,19 +99,9 @@ public class BaseTestAESGCM extends BaseTest { byte[] ivBytes = "123456".getBytes(); byte[] aadBytes = new byte[16]; - public BaseTestAESGCM(String providerName) { - super(providerName); - } - - public BaseTestAESGCM(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - } - + @BeforeEach public void setUp() throws Exception { - aesKeyGen = KeyGenerator.getInstance("AES", providerName); + aesKeyGen = KeyGenerator.getInstance("AES", getProviderName()); if (specifiedKeySize > 0) { aesKeyGen.init(specifiedKeySize); } @@ -154,9 +147,10 @@ public void setUp() throws Exception { } } + @Test public void testAES_GCM_encrypt_offset() throws Exception { // Test AES GCM - Encrypt Offset by 1 - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); byte[] iv = new byte[16]; byte[] aad = new byte[16]; @@ -190,9 +184,10 @@ public void testAES_GCM_encrypt_offset() throws Exception { byteEqual(plainText, 0, decrypted, 0, plainText.length)); } + @Test public void testAES_GCM_decrypt_offset() throws Exception { // Test AES GCM - Decrypt Offset by 1 - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); byte[] iv = new byte[16]; byte[] aad = new byte[16]; @@ -225,9 +220,10 @@ public void testAES_GCM_decrypt_offset() throws Exception { byteEqual(plainText, 0, decrypted, offset, plainText.length)); } + @Test public void testAES_GCM_encrypt_large_buffer() throws Exception { // Test AES GCM - Encrypting buffer large - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); byte[] iv = new byte[16]; byte[] aad = new byte[16]; @@ -255,9 +251,10 @@ public void testAES_GCM_encrypt_large_buffer() throws Exception { } } + @Test public void testAES_GCM_decrypt_large_buffer() throws Exception { // Test AES GCM - Decrypting buffer large - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); byte[] iv = new byte[16]; byte[] aad = new byte[16]; @@ -294,9 +291,10 @@ public void testAES_GCM_decrypt_large_buffer() throws Exception { } } + @Test public void testAES_GCM() throws Exception { // Test AES GCM Cipher - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -311,9 +309,10 @@ public void testAES_GCM() throws Exception { byteEqual(plainText, 0, newPlainText1, 0, plainText.length)); } + @Test public void testAES_GCM_2() throws Exception { // Test AES GCM Cipher using duplicate calls - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -337,10 +336,11 @@ public void testAES_GCM_2() throws Exception { byteEqual(plainText, 0, newPlainText1, 0, plainText.length)); } + @Test public void testAES_GCM_encrypt_empty_text() throws Exception { try { // Test AES GCM - Encrypt Cipher.doFinal() without text - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -354,10 +354,11 @@ public void testAES_GCM_encrypt_empty_text() throws Exception { assertTrue("Passed - Cipher.doFinal() encrypt empty text", true); } + @Test public void testAES_GCM_decrypt_without_parameters() throws Exception { try { // Test AES GCM - Decrypt Cipher.doFinal() without parameters - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(); @@ -372,10 +373,11 @@ public void testAES_GCM_decrypt_without_parameters() throws Exception { false); } + @Test public void testAES_GCM_decrypt_empty_text() throws Exception { try { // Test AES GCM - Decrypt Cipher.doFinal() without text - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); byte[] iv = new byte[16]; // GCMParameterSpec gps = new GCMParameterSpec(16 * 8, iv); @@ -393,11 +395,12 @@ public void testAES_GCM_decrypt_empty_text() throws Exception { assertTrue("Failed - Cipher.doFinal() decrypt should have thrown exception", false); } + @Test public void testAES_GCM_5() { try { // Test AES GCM Cipher Cipher.doFinal(plainTxt) on decrypt - // incorrect text - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -419,11 +422,12 @@ public void testAES_GCM_5() { assertTrue("Failed - Expected AEADBadTagException", false); } + @Test public void testAES_GCM_Exception() throws Exception { // ProviderException try { // Test AES GCM Cipher - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text //cp.init(Cipher.ENCRYPT_MODE, key); @@ -446,10 +450,11 @@ public void testAES_GCM_Exception() throws Exception { assertTrue("Failed - Expected IllegalStateException", true); } + @Test public void testAESShortBuffer() throws Exception { try { // Test AES Cipher - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -461,9 +466,10 @@ public void testAESShortBuffer() throws Exception { } } + @Test public void testAESIllegalBlockSize() throws Exception { try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -487,8 +493,9 @@ public void testAESIllegalBlockSize() throws Exception { } } + @Test public void testAESNull() throws Exception { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); SecretKey nullKey = null; try { @@ -505,8 +512,9 @@ public void testAESNull() throws Exception { } } + @Test public void testIllegalParamSpec() throws Exception { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); try { byte[] iv = null; @@ -558,16 +566,17 @@ public void testIllegalParamSpec() throws Exception { } } + @Test public void testArguments() throws Exception { try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0]); } catch (Exception e) { @@ -575,21 +584,21 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0)"); @@ -597,7 +606,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1); fail("Should have gotten exception on doFinal(new byte[0], 1)"); @@ -605,7 +614,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[cp.getOutputSize(0)], 1); fail("Expected ShortBufferException"); @@ -613,28 +622,28 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0); } catch (Exception e) { @@ -642,7 +651,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1, 0); fail("Did not get expected exception on doFinal(new byte[0], 1, 0)"); @@ -650,7 +659,7 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 1); fail("Did not get expected exception on doFinal(new byte[0], 0, 1)"); @@ -658,14 +667,14 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0, null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0]); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0, 9, new byte[0])"); @@ -673,14 +682,14 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0], 0); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0, 0, new byte[0], 0)"); @@ -688,14 +697,14 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0]); } catch (Exception e) { @@ -703,28 +712,28 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 1, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0); } catch (Exception e) { @@ -732,63 +741,63 @@ public void testArguments() throws Exception { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 1, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, new byte[0]); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 1); } catch (Exception e) { } try { - Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { @@ -856,7 +865,7 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult AlgorithmParameters algParams, byte[] message) throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -900,7 +909,7 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult // protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message) throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -948,7 +957,7 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti protected void encryptDecryptPartialUpdate(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message) throws Exception { - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -992,10 +1001,11 @@ protected void encryptDecryptPartialUpdate(String algorithm, } } + @Test public void testShortBuffer() throws Exception { Cipher cp = null; try { - cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec parameterSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length cp.init(Cipher.ENCRYPT_MODE, key, parameterSpec); cp.updateAAD(aadBytes); @@ -1009,8 +1019,9 @@ public void testShortBuffer() throws Exception { } } + @Test public void testEncryptAfterShortBufferRetry() throws Exception { - Cipher cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec parameterSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length try { cpl.init(Cipher.ENCRYPT_MODE, key, parameterSpec); @@ -1035,11 +1046,12 @@ public void testEncryptAfterShortBufferRetry() throws Exception { } + @Test public void testDecryptAfterShortBufferRetry() throws Exception { byte[] cipherText = null; Cipher cpl = null; try { - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec gcmParamSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length // Encrypt the plain text @@ -1048,7 +1060,7 @@ public void testDecryptAfterShortBufferRetry() throws Exception { AlgorithmParameters params = cpl.getParameters(); - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cpl.init(Cipher.DECRYPT_MODE, key, params); byte[] sbPlainText = new byte[15]; System.out.println("cipherText.length=" + cipherText.length); @@ -1075,7 +1087,7 @@ public void ktestCipherStates() throws Exception { Cipher cpl = null; try { - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec gcmParamSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length // Encrypt the plain text diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMBufferIV.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMBufferIV.java index d2a61f03..0fcd15bc 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMBufferIV.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMBufferIV.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,23 +13,24 @@ import javax.crypto.ShortBufferException; import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestAESGCMBufferIV extends BaseTest { +public class BaseTestAESGCMBufferIV extends BaseTestJunit5 { private Cipher cipher; private SecretKeySpec keySpec; private byte plaintext[]; - public BaseTestAESGCMBufferIV(String providerName) { - super(providerName); - } - - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { keySpec = new SecretKeySpec(new byte[16], "AES"); - cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); plaintext = new byte[51]; } + @Test public void testAESGCMBufferIV() throws Exception { testBufferIV(45, 16); testBufferIV(46, 12); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCM.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCM.java index 3ba7e808..3460c976 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCM.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,41 +16,35 @@ import javax.crypto.CipherOutputStream; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; -import org.junit.Assume; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestAESGCMCICOWithGCM extends BaseTest { +public class BaseTestAESGCMCICOWithGCM extends BaseTestJunit5 { protected int specifiedKeySize = 128; - public BaseTestAESGCMCICOWithGCM(String providerName) { - super(providerName); - } - - public BaseTestAESGCMCICOWithGCM(String providerName, int keySize) throws Exception { - - super(providerName); - this.specifiedKeySize = keySize; - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - } - + @Test public void testDefault() throws Exception { dotestAESGCMCICOWithGCM(specifiedKeySize); } + @Test public void testAESGCMCICOWithGCM128() throws Exception { dotestAESGCMCICOWithGCM(128); } + @Test public void testAESGCMCICOWithGCM192() throws Exception { dotestAESGCMCICOWithGCM(192); } + @Test public void testAESGCMCICOWithGCM256() throws Exception { dotestAESGCMCICOWithGCM(256); } protected void dotestAESGCMCICOWithGCM(int myKeysize) throws Exception { int LEN = 100; - KeyGenerator kg = KeyGenerator.getInstance("AES", providerName); + KeyGenerator kg = KeyGenerator.getInstance("AES", getProviderName()); kg.init(myKeysize); SecretKey key = kg.generateKey(); @@ -61,10 +55,10 @@ protected void dotestAESGCMCICOWithGCM(int myKeysize) throws Exception { rdm.nextBytes(plainText); //init ciphers - Cipher encCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher encCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); encCipher.init(Cipher.ENCRYPT_MODE, key); - Cipher decCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher decCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); decCipher.init(Cipher.DECRYPT_MODE, key, encCipher.getParameters()); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCMAndAAD.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCMAndAAD.java index c1f33f4a..de8080e0 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCMAndAAD.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMCICOWithGCMAndAAD.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,25 +19,16 @@ import javax.crypto.CipherOutputStream; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; -import org.junit.Assume; +import org.junit.jupiter.api.Test; -public class BaseTestAESGCMCICOWithGCMAndAAD extends BaseTest { +public class BaseTestAESGCMCICOWithGCMAndAAD extends BaseTestJunit5 { protected int specifiedKeySize = 128; - public BaseTestAESGCMCICOWithGCMAndAAD(String providerName) { - super(providerName); - } - - public BaseTestAESGCMCICOWithGCMAndAAD(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - } - + @Test public void testGCMWithAAD() throws Exception { //init Secret Key //KeyGenerator kg = KeyGenerator.getInstance("AES", "SunJCE"); - KeyGenerator kg = KeyGenerator.getInstance("AES", providerName); + KeyGenerator kg = KeyGenerator.getInstance("AES", getProviderName()); kg.init(specifiedKeySize); SecretKey key = kg.generateKey(); @@ -51,10 +42,10 @@ public void testGCMWithAAD() throws Exception { byte[] aad2 = aad.clone(); aad2[50]++; - Cipher encCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher encCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); encCipher.init(Cipher.ENCRYPT_MODE, key); encCipher.updateAAD(aad); - Cipher decCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher decCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); decCipher.init(Cipher.DECRYPT_MODE, key, encCipher.getParameters()); decCipher.updateAAD(aad); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMLong.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMLong.java index 921a54a0..1c343575 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMLong.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMLong.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,8 +15,10 @@ import javax.crypto.SecretKey; import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestAESGCMLong extends BaseTest { +public class BaseTestAESGCMLong extends BaseTestJunit5 { private final static int GCM_IV_LENGTH = 12; private final static int GCM_TAG_LENGTH = 16; private static int ARRAY_OFFSET = 16; @@ -27,41 +29,15 @@ public class BaseTestAESGCMLong extends BaseTest { protected AlgorithmParameters params = null; protected Method methodCipherUpdateAAD = null; - // -------------------------------------------------------------------------- - // - // - public BaseTestAESGCMLong(String providerName) { - super(providerName); - } - - public BaseTestAESGCMLong(String providerName, int keySize) { - super(providerName); - System.out.println("keySize is ignored"); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception { - - } - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - private Cipher createCipher(int mode, SecretKey sKey, GCMParameterSpec ivSpec) throws Exception { - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(mode, sKey, ivSpec); return cipher; } - - + @Test public void testWith128Times8() throws Exception { //Create a 1K string @@ -109,6 +85,7 @@ public void testWith128Times8() throws Exception { } } + @Test public void testWith128Times7() throws Exception { //Create a 1K string @@ -164,13 +141,13 @@ private byte[] doTestWithMultipleDataUpdateEncrypt(int mode, SecretKey sKey, byt for (int j = 0; j < numUpdTimes; j++) { System.arraycopy(dataBytes, 0, largeByteBuffer, j * dataBytes.length, dataBytes.length); } - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputBytes = cipher.doFinal(largeByteBuffer); // new cipher for encrypt operation - Cipher cipher2 = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher2 = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher2.init(mode, sKey, ivSpec); cipher2.updateAAD(AAD); int outputLength = cipher2.getOutputSize(10 * dataBytes.length); @@ -204,13 +181,13 @@ private byte[] doTestWithMultipleDataUpdateDecrypt(int mode, SecretKey sKey, byt byte[] largeByteBuffer, GCMParameterSpec ivSpec, int numUpdTimes, boolean noDataForFinal) throws Exception { - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputBytes = cipher.doFinal(largeByteBuffer); // new cipher for encrypt operation - Cipher cipher2 = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher2 = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher2.init(mode, sKey, ivSpec); cipher2.updateAAD(AAD); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMNonExpanding.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMNonExpanding.java index 0d4b2eef..4e3d4916 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMNonExpanding.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMNonExpanding.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,7 +20,7 @@ import javax.crypto.SecretKey; import javax.crypto.ShortBufferException; import javax.crypto.spec.GCMParameterSpec; -import org.junit.Assume; +import org.junit.jupiter.api.Test; /** * @test @@ -28,24 +28,14 @@ * @summary Test AES encryption with no padding. Expect the original data length * is the same as the encrypted data. */ -public class BaseTestAESGCMNonExpanding extends BaseTest { +public class BaseTestAESGCMNonExpanding extends BaseTestJunit5 { private static final String ALGORITHM = "AES"; private static final String[] MODES = {"GCM"}; private static final String PADDING = "NoPadding"; protected int specifiedKeySize = 128; - public BaseTestAESGCMNonExpanding(String providerName) { - super(providerName); - } - - public BaseTestAESGCMNonExpanding(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - } - - + @Test public void testNonExpanding() throws Exception { for (String mode : MODES) { @@ -63,9 +53,9 @@ public void doTest(String algo, String mo, String pad) throws Exception { byte[] plainText = new byte[128]; rdm.nextBytes(plainText); - ci = Cipher.getInstance(algo + "/" + mo + "/" + pad, providerName); + ci = Cipher.getInstance(algo + "/" + mo + "/" + pad, getProviderName()); - KeyGenerator kg = KeyGenerator.getInstance(algo, providerName); + KeyGenerator kg = KeyGenerator.getInstance(algo, getProviderName()); kg.init(specifiedKeySize); key = kg.generateKey(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMSameBuffer.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMSameBuffer.java index 8ae4ae6f..01e8d1d4 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMSameBuffer.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMSameBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,7 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.GCMParameterSpec; +import org.junit.jupiter.api.Test; /* * @test @@ -21,7 +22,7 @@ * @summary Check if AEAD operations work correctly when buffers used * for storing plain text and cipher text are overlapped or the same */ -public class BaseTestAESGCMSameBuffer extends BaseTest { +public class BaseTestAESGCMSameBuffer extends BaseTestJunit5 { private static final String AES = "AES"; private static final String GCM = "GCM"; @@ -37,11 +38,7 @@ public class BaseTestAESGCMSameBuffer extends BaseTest { private int textLength; private int AADLength; - public BaseTestAESGCMSameBuffer(String pname) { - super(pname); - } - - + @Test public void testAESGCMSameBuffer() throws Exception { for (int keyLength : KEY_LENGTHS) { for (int textLength : TEXT_LENGTHS) { @@ -71,7 +68,7 @@ void do_runTest(String algo, String mode, String padding, int keyLength, int tex } // init a secret key - KeyGenerator kg = KeyGenerator.getInstance(algo, providerName); + KeyGenerator kg = KeyGenerator.getInstance(algo, getProviderName()); kg.init(keyLength); key = kg.generateKey(); @@ -351,7 +348,7 @@ private boolean isEqual(byte[] A, int offsetA, byte[] B, int offsetB, int bytesT * existing Cipher. */ private Cipher createCipher(int mode, AlgorithmParameters params) throws Exception { - Cipher cipher = Cipher.getInstance(transformation, providerName); + Cipher cipher = Cipher.getInstance(transformation, getProviderName()); if (Cipher.ENCRYPT_MODE == mode) { // initiate it with the saved parameters if (params != null) { diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdate.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdate.java index 66a15438..5657fb47 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdate.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -37,14 +37,18 @@ import javax.crypto.ShortBufferException; import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestAESGCMUpdate extends BaseTest { +public class BaseTestAESGCMUpdate extends BaseTestJunit5 { private final static int GCM_IV_LENGTH = 12; private final static int GCM_TAG_LENGTH = 16; private static int ARRAY_OFFSET = 16; private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); - protected KeyGenerator aesKeyGen; protected AlgorithmParameters params = null; protected Method methodCipherUpdateAAD = null; @@ -69,38 +73,15 @@ public class BaseTestAESGCMUpdate extends BaseTest { byte[] ivBytes = "123456".getBytes(); byte[] aadBytes = new byte[16]; - // -------------------------------------------------------------------------- - // - // - public BaseTestAESGCMUpdate(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public BaseTestAESGCMUpdate(String providerName, int keySize) throws Exception { - super(providerName); - System.out.println("Warning: keySize ignored"); - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - aesKeyGen = KeyGenerator.getInstance("AES", providerName); + aesKeyGen = KeyGenerator.getInstance("AES", getProviderName()); if (specifiedKeySize > 0) { aesKeyGen.init(specifiedKeySize); } key = aesKeyGen.generateKey(); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - static String[] plainTextStrArray = {"a", "ab", "abc", "abcd", "abcde", "abcdef", "abcdefg", "abcdefgh", "abcdefghi", "abcdefghi", "abcdefghij", "abcdefghijk", "abcdefghijkl", "abcdefghijklm", "abcdefghijklmn", "abcdefghijklmno", "abcdefghijklmnop", @@ -121,7 +102,7 @@ public void tearDown() throws Exception {} private Cipher createCipher(int mode, SecretKey sKey, GCMParameterSpec ivSpec) throws Exception { - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(mode, sKey, ivSpec); return cipher; } @@ -139,6 +120,7 @@ private static String compressString(String original) { return output.toString();*/ } + @Disabled public void testNoDataUpdate1(String dataStr, SecretKey skey) throws Exception { for (int keysizeloop = 1; keysizeloop < 3; keysizeloop++) { @@ -160,7 +142,7 @@ public void testNoDataUpdate1(String dataStr, SecretKey skey) throws Exception { private String doEncryptNoDataUpdate(String privateString, SecretKey skey) throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * Byte.SIZE, iv); cipher.init(Cipher.ENCRYPT_MODE, skey, ivSpec); cipher.updateAAD("12345678".getBytes()); @@ -180,7 +162,7 @@ private String doDecryptNoDataUpdate(String encrypted, SecretKey skey) throws Ex byte[] iv = Arrays.copyOfRange(decoded, 0, GCM_IV_LENGTH); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * Byte.SIZE, iv); cipher.init(Cipher.DECRYPT_MODE, skey, ivSpec); cipher.updateAAD("12345678".getBytes()); @@ -192,6 +174,7 @@ private String doDecryptNoDataUpdate(String encrypted, SecretKey skey) throws Ex return result; } + @Test public void testCaseWithLongString2() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; @@ -221,6 +204,7 @@ public void testCaseWithLongString2() throws Exception { } } + @Test public void testCaseWithShorString3() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; @@ -260,6 +244,7 @@ private byte[] dotestWithString(int mode, SecretKey sKey, byte[] AAD, byte[] pla return (outputText3); } + @Test public void testCaseShortBufferError4() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -328,6 +313,7 @@ private byte[] dotestCaseShortBuffer(int mode, SecretKey sKey, byte[] AAD, byte[ } } + @Test public void testCaseCallAfterShortBuffer5() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -399,6 +385,7 @@ private byte[] dotestCaseCallAfterShortBuffer(int mode, SecretKey sKey, byte[] A } } + @Test public void testCaseCallUpdateAfterFinal() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -491,6 +478,7 @@ private byte[] doCallUpdateAfterFinal(int mode, SecretKey sKey, byte[] AAD, byte * read the encrypted file and decrypt it and write the decrypted bytes to a decrypted file * read both the plain and decrypted files and verify they are same. */ + @Test public void testReadWriteToAFile6() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; @@ -558,7 +546,7 @@ private void doTestReadWriteToAFile(int fileCount, SecretKey sKey, byte[] AAD, S fosEncrypted = new FileOutputStream(fileNameEncrypted); outStreamEncrypted = new DataOutputStream(new BufferedOutputStream(fosEncrypted)); - Cipher cipherE = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherE = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherE.init(Cipher.ENCRYPT_MODE, sKey, ivSpec); cipherE.updateAAD(AAD); byte[] bufferE = new byte[BUFFER_SIZE_ENCRYPTING]; @@ -574,7 +562,7 @@ private void doTestReadWriteToAFile(int fileCount, SecretKey sKey, byte[] AAD, S inputStreamPlain.close(); - Cipher cipherD = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherD = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherD.init(Cipher.DECRYPT_MODE, sKey, ivSpec); cipherD.updateAAD(AAD); @@ -644,6 +632,7 @@ private void doTestReadWriteToAFile(int fileCount, SecretKey sKey, byte[] AAD, S } + @Test public void testWithOneDataUpdate7() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -669,13 +658,13 @@ private byte[] doTestWithOneDataUpdate(int mode, SecretKey sKey, byte[] AAD, byt //System.out.println ("====== doTestWithOneUpdate Entering " + modeStr + "dataText.length=" + dataText.length); // first, generate the cipher text at an allocated buffer - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputText = cipher.doFinal(dataText); // new cipher for encrypt operation - Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); secondCipher.init(mode, sKey, ivSpec); secondCipher.updateAAD(AAD); byte[] destText = new byte[secondCipher.getOutputSize(dataText.length)]; @@ -702,6 +691,7 @@ private byte[] doTestWithOneDataUpdate(int mode, SecretKey sKey, byte[] AAD, byt return destText; } + @Test public void testWith1UpdateinPlace8() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -769,6 +759,7 @@ public byte[] doTestWith1UpdateinPlace(int mode, SecretKey sKey, byte[] AAD, byt return copyOfOutput; } + @Test public void testWithMultipleDataUpdate9() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -795,6 +786,7 @@ public void testWithMultipleDataUpdate9() throws Exception { } } + @Test public void testWithMultipleDataUpdate10() throws Exception { byte[] myAAD = "12345678".getBytes(); byte[] iv = new byte[GCM_IV_LENGTH]; @@ -823,14 +815,14 @@ private byte[] doTestWithMultipleDataUpdate(int mode, SecretKey sKey, byte[] AAD // first, generate the cipher text at an allocated buffer //System.out.println ("================doTestWithMultipleDataUpdate mode = " + modeStr); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputText = cipher.doFinal(text); //System.out.println ("================doTestWithMultipleDataUpdate outputText.length = " + outputText.length); // new cipher for encrypt operation - Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); secondCipher.init(mode, sKey, ivSpec); secondCipher.updateAAD(AAD); byte[] destText = new byte[outputText.length]; @@ -870,6 +862,7 @@ private byte[] doTestWithMultipleDataUpdate(int mode, SecretKey sKey, byte[] AAD return destText; } + @Test public void testByteBuffer11() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -915,6 +908,7 @@ private byte[] doTestByteBuffer(int mode, SecretKey sKey, byte[] AAD, byte[] pla return (outputText12); } + @Test public void test1Update1Final12() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -966,6 +960,7 @@ private byte[] doTest1Update1Final(int mode, SecretKey sKey, byte[] AAD, byte[] } + @Test public void testCalllAAEDAfterDataUpdate13() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -1031,14 +1026,12 @@ private void doTestCallAAEDAfterDataUpdate(int mode, SecretKey sKey, byte[] AAD, } } - //-------------------------------------------------------------------------- - // - // + @Test public void testWithUpdatesShortBuffer() throws Exception { Cipher cpl = null; try { - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec parameterSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length cpl.init(Cipher.ENCRYPT_MODE, key, parameterSpec); cpl.updateAAD(aadBytes); @@ -1053,11 +1046,9 @@ public void testWithUpdatesShortBuffer() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testWithUdpatesEncryptAfterShortBufferRetry() throws Exception { - Cipher cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec parameterSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length try { cpl.init(Cipher.ENCRYPT_MODE, key, parameterSpec); @@ -1083,13 +1074,14 @@ public void testWithUdpatesEncryptAfterShortBufferRetry() throws Exception { } + @Test public void testWithUpdatesDecryptAfterShortBufferRetry() throws Exception { byte[] cipherText = null; Cipher cpl = null; byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); try { - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec gcmParamSpec = new GCMParameterSpec(128, iv); //128 bit auth tag length // Encrypt the plain text @@ -1098,7 +1090,7 @@ public void testWithUpdatesDecryptAfterShortBufferRetry() throws Exception { AlgorithmParameters params = cpl.getParameters(); - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cpl.init(Cipher.DECRYPT_MODE, key, params); byte[] sbPlainText = new byte[15]; System.out.println("cipherText.length=" + cipherText.length); @@ -1122,11 +1114,12 @@ public void testWithUpdatesDecryptAfterShortBufferRetry() throws Exception { } // Respecify parameters twice and it should fail. + @Test public void testWithUpdatesCipherStates() throws Exception { Cipher cpl = null; try { - cpl = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cpl = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec gcmParamSpec = new GCMParameterSpec(128, ivBytes); //128 bit auth tag length // Encrypt the plain text @@ -1170,6 +1163,7 @@ public void testWithUpdatesCipherStates() throws Exception { } + @Test public void testCallUpdateFailsSameKeyIV() throws Exception { int len = 0; GCMParameterSpec gcmParamSpec = new GCMParameterSpec(128, ivBytes); // 128 bit auth tag length @@ -1202,9 +1196,10 @@ public void testCallUpdateFailsSameKeyIV() throws Exception { } + @Test public void testMultipleUpdateWithoutAllocatingExternalBuffer19() throws Exception { - KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", providerName); + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", getProviderName()); keyGenerator.init(16 * 8); // Generate Key @@ -1239,7 +1234,7 @@ public byte[] doMultipleUpdateWithoutAllocatingExternalBufferEncrypt(SecretKey k // Get Cipher Instance Cipher cipher = null; try { - cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Create SecretKeySpec SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES"); @@ -1287,7 +1282,7 @@ public byte[] doMultipleUpdateWithoutAllocatingExternalBufferEncrypt(SecretKey k public byte[] doMultipleUpdateWithoutAllocatingExternalBufferDecrypt(byte[] cipherText, SecretKey key, byte[] IV) throws Exception { // Get Cipher Instance - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); // Create SecretKeySpec SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES"); @@ -1304,6 +1299,7 @@ public byte[] doMultipleUpdateWithoutAllocatingExternalBufferDecrypt(byte[] ciph return decryptedText; } + @Test public void testNoDataUpdate20() throws Exception { for (int keysizeloop = 1; keysizeloop < 3; keysizeloop++) { @@ -1323,7 +1319,7 @@ public void testNoDataUpdate20() throws Exception { private byte[] doEncryptNoDataUpdate(byte[] plainTextBytes, SecretKey skey) throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * Byte.SIZE, iv); cipher.init(Cipher.ENCRYPT_MODE, skey, ivSpec); cipher.updateAAD("12345678".getBytes()); @@ -1339,7 +1335,7 @@ private byte[] doDecryptNoDataUpdate(byte[] encrypted, SecretKey skey) throws Ex byte[] iv = Arrays.copyOfRange(encrypted, 0, GCM_IV_LENGTH); - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); GCMParameterSpec ivSpec = new GCMParameterSpec(GCM_TAG_LENGTH * Byte.SIZE, iv); cipher.init(Cipher.DECRYPT_MODE, skey, ivSpec); cipher.updateAAD("12345678".getBytes()); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdateInteropBC.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdateInteropBC.java index 12d6ad39..0b65cf94 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdateInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMUpdateInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,8 +16,10 @@ import javax.crypto.SecretKey; import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestAESGCMUpdateInteropBC extends BaseTestInterop { +public class BaseTestAESGCMUpdateInteropBC extends BaseTestJunit5Interop { private final static int GCM_IV_LENGTH = 12; private final static int GCM_TAG_LENGTH = 16; private static int ARRAY_OFFSET = 16; @@ -35,32 +37,6 @@ public class BaseTestAESGCMUpdateInteropBC extends BaseTestInterop { //protected Method methodGCMParameterSpecSetAAD = null; protected int specifiedKeySize = 0; - // -------------------------------------------------------------------------- - // - // - public BaseTestAESGCMUpdateInteropBC(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - public BaseTestAESGCMUpdateInteropBC(String providerName, String interopProviderName, - int keySize) { - super(providerName, interopProviderName); - System.out.println("Warning: Keysize is ignored"); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception { - - } - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - static String[] plainTextStrArray = {"a", "ab", "abc", "abcd", "abcde", "abcdef", "abcdefg", "abcdefgh", "abcdefghi", "abcdefghi", "abcdefghij", "abcdefghijk", "abcdefghijkl", "abcdefghijklm", "abcdefghijklmn", "abcdefghijklmno", "abcdefghijklmnop", @@ -91,6 +67,7 @@ private static String compressString(String original) { return original; } + @Test public void testWithOneDataUpdate() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -114,13 +91,13 @@ private byte[] doTestWithOneDataUpdate(int mode, SecretKey sKey, byte[] AAD, byt // first, generate the cipher text at an allocated buffer - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", interopProviderName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getInteropProviderName()); cipher.init(mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputText = cipher.doFinal(dataText); // new cipher for encrypt operation - Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); secondCipher.init(mode, sKey, ivSpec); secondCipher.updateAAD(AAD); byte[] destText = new byte[secondCipher.getOutputSize(dataText.length)]; @@ -142,6 +119,7 @@ private byte[] doTestWithOneDataUpdate(int mode, SecretKey sKey, byte[] AAD, byt return destText; } + @Test public void testWith1UpdateinPlace2() throws Exception { byte[] iv = new byte[GCM_IV_LENGTH]; (new SecureRandom()).nextBytes(iv); @@ -174,11 +152,11 @@ public byte[] doTestWith1UpdateinPlace(int mode, SecretKey sKey, byte[] AAD, byt System.arraycopy(input, 0, copyOfInput, 0, input.length); // first, generate the cipher text at an allocated buffer - Cipher cipher = createCipher(interopProviderName, mode, sKey, ivSpec); + Cipher cipher = createCipher(getInteropProviderName(), mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputText = cipher.doFinal(copyOfInput, 0, input.length); // new cipher for encrypt operation - Cipher anotherCipher = createCipher(providerName, mode, sKey, ivSpec); + Cipher anotherCipher = createCipher(getProviderName(), mode, sKey, ivSpec); anotherCipher.updateAAD(AAD); // next, generate cipher text again at the same buffer of plain text @@ -203,6 +181,7 @@ public byte[] doTestWith1UpdateinPlace(int mode, SecretKey sKey, byte[] AAD, byt return copyOfOutput; } + @Test public void testWithMultipleDataUpdate() throws Exception { byte[] myAAD = "12345678".getBytes(); byte[] iv = new byte[GCM_IV_LENGTH]; @@ -227,13 +206,13 @@ public void testWithMultipleDataUpdate() throws Exception { private byte[] doTestWithMultipleDataUpdate(int mode, SecretKey sKey, byte[] AAD, byte[] text, GCMParameterSpec ivSpec, int numUpdTimes) throws Exception { - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", interopProviderName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getInteropProviderName()); cipher.init(mode, sKey, ivSpec); cipher.updateAAD(AAD); byte[] outputText = cipher.doFinal(text); // new cipher for encrypt operation - Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher secondCipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); secondCipher.init(mode, sKey, ivSpec); secondCipher.updateAAD(AAD); byte[] destText = new byte[outputText.length]; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithByteBuffer.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithByteBuffer.java index 23ddc59e..468978d5 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,8 +17,10 @@ import javax.crypto.SecretKey; import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestAESGCMWithByteBuffer extends BaseTest { +public class BaseTestAESGCMWithByteBuffer extends BaseTestJunit5 { private static Random random = new SecureRandom(); private static int dataSize = 4096; // see javax.crypto.CipherSpi @@ -26,12 +28,9 @@ public class BaseTestAESGCMWithByteBuffer extends BaseTest { private static String testVariant[] = {"HEAP_HEAP", "HEAP_DIRECT", "DIRECT_HEAP", "DIRECT_DIRECT"}; - public BaseTestAESGCMWithByteBuffer(String providerName) { - super(providerName); - } - + @Test public void testAESGCMWithByteBuffer() throws Exception { - Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); System.out.println("Testing " + cipher.getProvider()); boolean failedOnce = false; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithKeyAndIvCheck.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithKeyAndIvCheck.java index f57e6417..be12d8f1 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithKeyAndIvCheck.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCMWithKeyAndIvCheck.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,22 +16,15 @@ import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestAESGCMWithKeyAndIvCheck extends BaseTest { +public class BaseTestAESGCMWithKeyAndIvCheck extends BaseTestJunit5 { private static final byte[] AAD = new byte[5]; private static final byte[] PT = new byte[18]; protected int specifiedKeySize = 16; - public BaseTestAESGCMWithKeyAndIvCheck(String providerName) { - super(providerName); - } - - public BaseTestAESGCMWithKeyAndIvCheck(String providerName, int keySize) { - super(providerName); - System.out.println("Warning: KeySize is ignored"); - } - private void checkISE(Cipher c) throws Exception { // Subsequent encryptions should fail try { @@ -55,8 +48,9 @@ private void checkISE(Cipher c) throws Exception { } } + @Test public void testKeyAndIv() throws Exception { - Cipher c = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher c = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); SecretKey key = new SecretKeySpec(new byte[specifiedKeySize], "AES"); // First try parameter-less init. diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_ExtIV.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_ExtIV.java index 363eec53..8db72cc0 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_ExtIV.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_ExtIV.java @@ -20,16 +20,17 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.fail; /* * Run subset of KAT (Known-Answer Tests) from http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip */ -public class BaseTestAESGCM_ExtIV extends BaseTest { +public class BaseTestAESGCM_ExtIV extends BaseTestJunit5 { + - // -------------------------------------------------------------------------- - // - // private KeyGenerator aesKeyGen = null; private SecretKey key = null; private AlgorithmParameters params = null; @@ -47,17 +48,8 @@ public class BaseTestAESGCM_ExtIV extends BaseTest { private static Method methCipherGetInstance = null; - // -------------------------------------------------------------------------- - // - // - public BaseTestAESGCM_ExtIV(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { /* * Try constructing a javax.crypto.spec.GCMParameterSpec instance (Java @@ -98,9 +90,7 @@ protected void setUp() throws Exception { rnd.nextBytes(iv); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_ExtIV_Test00() throws Exception { runTestEncrypt(104, // init_tag_length, "66a3c722ccf9709525650973ecc100a9", // str_key_bytes, @@ -111,6 +101,7 @@ public void testAESGCM_ExtIV_Test00() throws Exception { "3fd5c0132acfab97b5fff651c4"); // str_tag } + @Test public void testAESGCM_ExtIV_Test01() throws Exception { runTestEncrypt(104, // init_tag_length, "d9821b713dae03c8f246ff3fd65454d7", // str_key_bytes, @@ -121,6 +112,7 @@ public void testAESGCM_ExtIV_Test01() throws Exception { "e6f91e55ad30c74b9f94577375"); // str_tag } + @Test public void testAESGCM_ExtIV_Test02() throws Exception { runTestEncrypt(128, // init_tag_length, "89850dd398e1f1e28443a33d40162664", // str_key_bytes, @@ -131,6 +123,7 @@ public void testAESGCM_ExtIV_Test02() throws Exception { "d84a8c3eac57d1bb0e890a8f461d1065"); // str_tag } + @Test public void testAESGCM_ExtIV_Test03() throws Exception { runTestEncrypt(64, // init_tag_length, "41d0e604d7be7bc069bcc725e6b9ac1d", // str_key_bytes, @@ -141,6 +134,7 @@ public void testAESGCM_ExtIV_Test03() throws Exception { "81c928129992ba8d"); // str_tag } + @Test public void testAESGCM_ExtIV_Test04() throws Exception { runTestEncrypt(64, // init_tag_length, "7e95066b60093f66175493d141359dbd", // str_key_bytes, @@ -151,6 +145,7 @@ public void testAESGCM_ExtIV_Test04() throws Exception { "4fd94671abde616e"); // str_tag } + @Test public void testAESGCM_ExtIV_Test05() throws Exception { runTestEncrypt(32, // init_tag_length, "62dc8e1a98863c7de64f30b74c01d530", // str_key_bytes, @@ -161,6 +156,7 @@ public void testAESGCM_ExtIV_Test05() throws Exception { "e413041a"); // str_tag } + @Test public void testAESGCM_ExtIV_Test06() throws Exception { runTestEncrypt(128, // init_tag_length, "aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539", // str_key_bytes, @@ -171,6 +167,7 @@ public void testAESGCM_ExtIV_Test06() throws Exception { "f149e2b5f0adaa9842ca5f45b768a8fc"); // str_tag } + @Test public void testAESGCM_ExtIV_Test07() throws Exception { runTestEncrypt(120, // init_tag_length, "d74a0b3c2172b1692c5c22741d0cfb2dc898dc100b584a1b", // str_key_bytes, @@ -181,6 +178,7 @@ public void testAESGCM_ExtIV_Test07() throws Exception { "20ff32821d8532b54c7101858b9b88"); // str_tag } + @Test public void testAESGCM_ExtIV_Test08() throws Exception { runTestEncrypt(128, // init_tag_length, "a23dfb84b5976b46b1830d93bcf61941cae5e409e4f5551dc684bdcef9876480", // str_key_bytes, @@ -191,6 +189,7 @@ public void testAESGCM_ExtIV_Test08() throws Exception { "f28217649230bd7a40a9a4ddabc67c43"); // str_tag } + @Test public void testAESGCM_ExtIV_Test09() throws Exception { runTestEncrypt(112, // init_tag_length, "368b486ee83404c9a839f1829c12f064b84788577ba171ab5bf50a54a67b901e", // str_key_bytes, @@ -201,6 +200,7 @@ public void testAESGCM_ExtIV_Test09() throws Exception { "d6a90ccddf478c250f8b84bcc6a"); // str_tag } + @Test public void testAESGCM_ExtIV_Test10() throws Exception { runTestEncrypt(96, // init_tag_length, "b33b0e4c5b9f7ef77cec1a29ed5844bda3853238bdf7766e7645029931f169f0", // str_key_bytes, @@ -211,6 +211,7 @@ public void testAESGCM_ExtIV_Test10() throws Exception { "93af01abb6a970047a7fc010"); // str_tag } + @Test public void testAESGCM_ExtIV_Test11() throws Exception { runTestDecrypt(128, // init_tag_length, "cf063a34d4a9a76c2c86787d3f96db71", // str_key_bytes, @@ -221,6 +222,7 @@ public void testAESGCM_ExtIV_Test11() throws Exception { "72ac8493e3a5228b5d130a69d2510e42"); // str_tag } + @Test public void testAESGCM_ExtIV_Test12() throws Exception { runTestDecrypt(120, // init_tag_length, "6dfa1a07c14f978020ace450ad663d18", // str_key_bytes, @@ -231,6 +233,7 @@ public void testAESGCM_ExtIV_Test12() throws Exception { "751f3098d59cf4ea1d2fb0853bde1c"); // str_tag } + @Test public void testAESGCM_ExtIV_Test13() throws Exception { runTestDecrypt(112, // init_tag_length, "4ccbed984d83124fbc8646aaaa0cad56", // str_key_bytes, @@ -241,6 +244,7 @@ public void testAESGCM_ExtIV_Test13() throws Exception { "106844f33ac3667d7ca6e0e4f38b"); // str_tag } + @Test public void testAESGCM_ExtIV_Test14() throws Exception { runTestDecrypt(104, // init_tag_length, "e029db25c48151c44a089c31dbb7e8d7", // str_key_bytes, @@ -251,6 +255,7 @@ public void testAESGCM_ExtIV_Test14() throws Exception { "b94ed63b00aa5eeeea9558e135"); // str_tag } + @Test public void testAESGCM_ExtIV_Test15() throws Exception { runTestDecrypt(96, // init_tag_length, "94a16fd10c3f34082d443909d076127b", // str_key_bytes, @@ -261,6 +266,7 @@ public void testAESGCM_ExtIV_Test15() throws Exception { "c723b505654410ad9d5112a8"); // str_tag } + @Test public void testAESGCM_ExtIV_Test16() throws Exception { runTestDecrypt(96, // init_tag_length, "748dd62db5ec077e08aaf77243de11ec1794ee66a8d897e4", // str_key_bytes, @@ -271,6 +277,7 @@ public void testAESGCM_ExtIV_Test16() throws Exception { "984a39fecd9c61ca9a6fdabc"); // str_tag } + @Test public void testAESGCM_ExtIV_Test17() throws Exception { runTestDecrypt(64, // init_tag_length, "8a68f0860f05db6d688e38c3dd931b7e1c476df9ea835fd5", // str_key_bytes, @@ -281,6 +288,7 @@ public void testAESGCM_ExtIV_Test17() throws Exception { "014089a8a0c53bed"); // str_tag } + @Test public void testAESGCM_ExtIV_Test18() throws Exception { runTestDecrypt(32, // init_tag_length, "d0f31becae6c6f526b686b468c14bafcbdab4aaf3f6a7892", // str_key_bytes, @@ -291,6 +299,7 @@ public void testAESGCM_ExtIV_Test18() throws Exception { "3e5f75c9"); // str_tag } + @Test public void testAESGCM_ExtIV_Test19() throws Exception { runTestDecrypt(64, // init_tag_length, "cc71a2842d54ebf3eaac8aeb6ac59cd30f2672b190f18c7ad5bcced5567401b7", // str_key_bytes, @@ -301,6 +310,7 @@ public void testAESGCM_ExtIV_Test19() throws Exception { "e1507520c358afec"); // str_tag } + @Test public void testAESGCM_ExtIV_Test20() throws Exception { runTestDecrypt(64, // init_tag_length, "f7b640b7d59b4938689139e1f14179a9388f84c89852e045c568930da83c7521", // str_key_bytes, @@ -311,6 +321,7 @@ public void testAESGCM_ExtIV_Test20() throws Exception { "45d81bc44c0a8ab4"); // str_tag } + @Test public void testAESGCM_ExtIV_Test21() throws Exception { runTestDecryptFail(128, // init_tag_length, "a49a5e26a2f8cb63d05546c2a62f5343", // str_key_bytes, @@ -321,6 +332,7 @@ public void testAESGCM_ExtIV_Test21() throws Exception { "a2be08210d8c470a8df6e8fbd79ec5cf"); // str_tag } + @Test public void testAESGCM_ExtIV_Test22() throws Exception { runTestDecryptFail(104, // init_tag_length, "4be099b41ca9753a1ee2c390128717f0", // str_key_bytes, @@ -331,6 +343,7 @@ public void testAESGCM_ExtIV_Test22() throws Exception { "d4e80f72dcd5e9c80ca16bf0c4"); // str_tag } + @Test public void testAESGCM_ExtIV_Test23() throws Exception { runTestDecryptFail(120, // init_tag_length, "64d8c86131e97843f5aee06bd6e56f321e779bf8a1c8d4c0", // str_key_bytes, @@ -341,6 +354,7 @@ public void testAESGCM_ExtIV_Test23() throws Exception { "e1e1e01085ffd36c4ca2f8a94593a1"); // str_tag } + @Test public void testAESGCM_ExtIV_Test24() throws Exception { runTestDecryptFail(64, // init_tag_length, "01643b56c34eb12ab7a4f4223636201b954ec56019b4d1f0", // str_key_bytes, @@ -351,6 +365,7 @@ public void testAESGCM_ExtIV_Test24() throws Exception { "266685ebed5dab3d"); // str_tag } + @Test public void testAESGCM_ExtIV_Test25() throws Exception { runTestDecryptFail(32, // init_tag_length, "2bcc18d95b3137479f15dce3a0220adeea720032d64f7686", // str_key_bytes, @@ -361,6 +376,7 @@ public void testAESGCM_ExtIV_Test25() throws Exception { "348a2cfa"); // str_tag } + @Test public void testAESGCM_ExtIV_Test26() throws Exception { runTestDecryptFail(96, // init_tag_length, "55680523b7056ac2c365393b9c7bdff3df75528e73baf67ffa615323b9e84543", // str_key_bytes, @@ -371,6 +387,7 @@ public void testAESGCM_ExtIV_Test26() throws Exception { "8aaa9e6b012f5ca26dd237a1"); // str_tag } + @Test public void testAESGCM_ExtIV_Test27() throws Exception { runTestDecryptFail(112, // init_tag_length, "fb5dcada6ee653f69e2e5946c661141e9e1665b4cd0a1cba", // str_key_bytes, @@ -381,9 +398,7 @@ public void testAESGCM_ExtIV_Test27() throws Exception { "d4893f0edeabc8f16f219ee12cb4"); // str_tag } - // -------------------------------------------------------------------------- - // - // + public void runTestEncrypt(int init_tag_length, String key_bytes, String init_vec, String plain_text, String added_auth_data, String cipher_text, String tag) throws Exception { @@ -392,9 +407,7 @@ public void runTestEncrypt(int init_tag_length, String key_bytes, String init_ve asciiToHex(tag)); } - // -------------------------------------------------------------------------- - // - // + public void runTestEncrypt(int init_tag_length, byte[] key_bytes, byte[] init_vec, byte[] plain_text, byte[] added_auth_data, byte[] cipher_text, byte[] tag) throws Exception { @@ -415,7 +428,7 @@ public void runTestEncrypt(int init_tag_length, byte[] key_bytes, byte[] init_ve SecretKeySpec key = new SecretKeySpec(key_bytes, "AES"); - cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(Cipher.ENCRYPT_MODE, key, gcm_param_spec); /* For Java 7/8 */ @@ -440,9 +453,7 @@ public void runTestEncrypt(int init_tag_length, byte[] key_bytes, byte[] init_ve } } - // -------------------------------------------------------------------------- - // - // + public void runTestDecrypt(int init_tag_length, String key_bytes, String init_vec, String plain_text, String added_auth_data, String cipher_text, String tag) throws Exception { @@ -451,9 +462,7 @@ public void runTestDecrypt(int init_tag_length, String key_bytes, String init_ve asciiToHex(tag)); } - // -------------------------------------------------------------------------- - // - // + public void runTestDecrypt(int init_tag_length, byte[] key_bytes, byte[] init_vec, byte[] plain_text, byte[] added_auth_data, byte[] cipher_text, byte[] tag) throws Exception { @@ -479,7 +488,7 @@ public void runTestDecrypt(int init_tag_length, byte[] key_bytes, byte[] init_ve SecretKeySpec key = new SecretKeySpec(key_bytes, "AES"); - cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(Cipher.DECRYPT_MODE, key, gcm_param_spec); /* For Java 7/8 */ @@ -497,9 +506,7 @@ public void runTestDecrypt(int init_tag_length, byte[] key_bytes, byte[] init_ve } } - // -------------------------------------------------------------------------- - // - // + public void runTestDecryptFail(int init_tag_length, String key_bytes, String init_vec, String plain_text, String added_auth_data, String cipher_text, String tag) throws Exception { @@ -508,9 +515,7 @@ public void runTestDecryptFail(int init_tag_length, String key_bytes, String ini asciiToHex(tag)); } - // -------------------------------------------------------------------------- - // - // + public void runTestDecryptFail(int init_tag_length, byte[] key_bytes, byte[] init_vec, byte[] plain_text, byte[] added_auth_data, byte[] cipher_text, byte[] tag) throws Exception { @@ -537,7 +542,7 @@ public void runTestDecryptFail(int init_tag_length, byte[] key_bytes, byte[] ini SecretKeySpec key = new SecretKeySpec(key_bytes, "AES"); - cipher = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cipher = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipher.init(Cipher.DECRYPT_MODE, key, gcm_param_spec); /* For Java 7/8 */ @@ -559,9 +564,7 @@ public void runTestDecryptFail(int init_tag_length, byte[] key_bytes, byte[] ini } } - // -------------------------------------------------------------------------- - // - // + private boolean byteEqual(byte[] b1, int offset1, byte[] b2, int offset2, int len) { if (((b1.length - offset1) < len) || ((b2.length - offset2) < len)) { return false; @@ -575,9 +578,7 @@ private boolean byteEqual(byte[] b1, int offset1, byte[] b2, int offset2, int le return true; } - // -------------------------------------------------------------------------- - // - // + public static String hexToAscii(byte[] b) { char[] hexDigits = "0123456789abcdef".toCharArray(); if (b == null) { @@ -595,9 +596,7 @@ public static String hexToAscii(byte[] b) { return sb.toString(); } - // -------------------------------------------------------------------------- - // - // + public static byte[] asciiToHex(String s) { try { int n = s.length(); @@ -627,9 +626,7 @@ public static byte[] asciiToHex(String s) { } } - // -------------------------------------------------------------------------- - // - // + public static int nextNibble(StringReader r) throws IOException { while (true) { int ch = r.read(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_IntIV.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_IntIV.java index 98d72777..cb1643d7 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_IntIV.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESGCM_IntIV.java @@ -22,14 +22,16 @@ import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestAESGCM_IntIV extends BaseTest { +public class BaseTestAESGCM_IntIV extends BaseTestJunit5 { private static final int DEFAULT_TAG_LENGTH = 128; - // -------------------------------------------------------------------------- - // - // + private final static String RUN_FULL_TEST_SUITE = System.getProperty("run_full_test_suite", "false"); @@ -38,28 +40,17 @@ public class BaseTestAESGCM_IntIV extends BaseTest { public static final String GENERATED_IV_MAX_INVOCATIONS_PLUS_ONE = "18446744073709551616"; - // -------------------------------------------------------------------------- - // - // + KeyGenerator aesKeyGen; SecretKey key; int tagLength = 16; AlgorithmParameterSpec aParamSpec = null; AlgorithmParameters aParams = null; - // -------------------------------------------------------------------------- - // - // - public BaseTestAESGCM_IntIV(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { - aesKeyGen = KeyGenerator.getInstance("AES", providerName); + aesKeyGen = KeyGenerator.getInstance("AES", getProviderName()); key = aesKeyGen.generateKey(); @@ -68,18 +59,16 @@ protected void setUp() throws Exception { rnd.nextBytes(iv); aParamSpec = new javax.crypto.spec.GCMParameterSpec(DEFAULT_TAG_LENGTH, iv); - aParams = AlgorithmParameters.getInstance("AESGCM", providerName); + aParams = AlgorithmParameters.getInstance("AESGCM", getProviderName()); aParams.init(aParamSpec); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test01() throws Exception { /* Do the encrypt using the internally generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key); @@ -92,7 +81,7 @@ public void testAESGCM_IntIV_Test01() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, ap); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -102,9 +91,7 @@ public void testAESGCM_IntIV_Test01() throws Exception { Arrays.equals(plainTextEncrypt, plainTextDecrypt)); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test02() throws Exception { /* @@ -112,7 +99,7 @@ public void testAESGCM_IntIV_Test02() throws Exception { * generated IVs */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); for (int i = 1; i < 6; i++) { @@ -134,7 +121,7 @@ public void testAESGCM_IntIV_Test02() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, ap); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -145,14 +132,12 @@ public void testAESGCM_IntIV_Test02() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test03() throws Exception { /* Do the encrypt using the internally generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, (AlgorithmParameters) null); @@ -166,7 +151,7 @@ public void testAESGCM_IntIV_Test03() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, ap); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -176,14 +161,12 @@ public void testAESGCM_IntIV_Test03() throws Exception { Arrays.equals(plainTextEncrypt, plainTextDecrypt)); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test04() throws Exception { /* Do the encrypt using the internally generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, (AlgorithmParameterSpec) null); @@ -198,7 +181,7 @@ public void testAESGCM_IntIV_Test04() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, apSpec); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -208,15 +191,13 @@ public void testAESGCM_IntIV_Test04() throws Exception { Arrays.equals(plainTextEncrypt, plainTextDecrypt)); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test05() throws Exception { try { /* Do the encrypt using the internally generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, (AlgorithmParameters) null); @@ -226,7 +207,7 @@ public void testAESGCM_IntIV_Test05() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -240,15 +221,13 @@ public void testAESGCM_IntIV_Test05() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test06() throws Exception { try { /* Do the encrypt using the internally generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, (AlgorithmParameters) null); @@ -258,7 +237,7 @@ public void testAESGCM_IntIV_Test06() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, (AlgorithmParameters) null); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -271,15 +250,13 @@ public void testAESGCM_IntIV_Test06() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test07() throws Exception { try { /* Do the encrypt using the internally generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, (AlgorithmParameterSpec) null); @@ -289,7 +266,7 @@ public void testAESGCM_IntIV_Test07() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, (AlgorithmParameterSpec) null); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; @@ -302,9 +279,7 @@ public void testAESGCM_IntIV_Test07() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESGCM_IntIV_Test08() throws Exception { //Assume.assumeTrue(RUN_FULL_TEST_SUITE.equals("true")); @@ -320,7 +295,7 @@ public void testAESGCM_IntIV_Test08() throws Exception { * generated IV */ - Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherEncrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherEncrypt.init(Cipher.ENCRYPT_MODE, key); @@ -340,7 +315,7 @@ public void testAESGCM_IntIV_Test08() throws Exception { /* Do the decryption using the internally generated IV */ - Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", providerName); + Cipher cipherDecrypt = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); cipherDecrypt.init(Cipher.DECRYPT_MODE, key, ap); byte[] plainTextDecrypt = new byte[plainTextEncrypt.length]; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestAESInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestAESInterop.java index 3f98685d..18bf43a5 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestAESInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestAESInterop.java @@ -13,7 +13,6 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; @@ -24,14 +23,12 @@ import javax.crypto.ShortBufferException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; -import org.junit.Assume; - -public class BaseTestAESInterop extends BaseTestInterop { - - // -------------------------------------------------------------------------- - // - // +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +public class BaseTestAESInterop extends BaseTestJunit5Interop { // 14 bytes: PASSED static final byte[] plainText14 = "12345678123456".getBytes(); @@ -60,10 +57,6 @@ public class BaseTestAESInterop extends BaseTestInterop { static final byte[] plainText16KB = new byte[16384]; static final byte[] plainText = plainText128; // default value - // -------------------------------------------------------------------------- - // - // - static boolean warmup = false; protected SecretKey key; protected AlgorithmParameters params = null; protected Cipher cpA = null; @@ -71,113 +64,7 @@ public class BaseTestAESInterop extends BaseTestInterop { protected boolean success = true; protected int specifiedKeySize = 0; - // -------------------------------------------------------------------------- - // - // - public BaseTestAESInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - } - } - - // -------------------------------------------------------------------------- - // - // - public BaseTestAESInterop(String providerName, String interopProviderName, int keySize) - throws Exception { - super(providerName, interopProviderName); - this.specifiedKeySize = keySize; - - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - } - } - - // -------------------------------------------------------------------------- - // warmup functions for enable fastjni - // - static public void warmup() throws Exception { - java.security.Provider java_provider = null; - int modeInt; - boolean stream = false; - SecretKeySpec skey; - int key_size = 128; - byte[] skey_bytes = new byte[key_size / 8]; - int len = 4096; - byte[] iv; - byte[] data = plainText16; - byte[] out; - Cipher cipher; - Random r; - try { - java_provider = java.security.Security.getProvider("OpenJCEPlus"); - if (java_provider == null) { - java_provider = new com.ibm.crypto.plus.provider.OpenJCEPlus(); - java.security.Security.insertProviderAt(java_provider, 1); - } - - r = new Random(10); - String mode = "encrypt_stream"; - String cipherMode = "AES/CBC/NoPadding"; - - if (mode.contains("encrypt")) - modeInt = 1; - else if (mode.contains("decrypt")) - modeInt = 0; - else - throw new RuntimeException("Unsupported mode"); - - if (mode.contains("block")) - stream = false; - else if (mode.contains("stream")) - stream = true; - else - throw new RuntimeException("block mode or stream mode must be specified"); - - r.nextBytes(skey_bytes); - skey = new SecretKeySpec(skey_bytes, "AES"); - - for (int i = 0; i < 999999; i++) { - cipher = Cipher.getInstance(cipherMode, java_provider); - out = new byte[len]; - iv = new byte[16]; - r.nextBytes(iv); - AlgorithmParameterSpec iviv = new IvParameterSpec(iv); - - if (modeInt == 0) - cipher.init(Cipher.DECRYPT_MODE, skey, iviv); - else - cipher.init(Cipher.ENCRYPT_MODE, skey, iviv); - if (stream) { - for (long j = 0; j < 9; j++) - cipher.update(data, 0, data.length, out); - } else { - for (long k = 0; k < 9; k++) { - cipher.update(data, 0, data.length, out); - // cipher.doFinal(); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { byte[] encodedKey = new byte[(specifiedKeySize > 0 ? specifiedKeySize : 128) / 8]; r.nextBytes(plainText512); @@ -189,65 +76,48 @@ public void setUp() throws Exception { key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // + @Test public void testAES() throws Exception { - encryptDecrypt("AES", providerName, interopProviderName); - encryptDecrypt("AES", interopProviderName, providerName); + encryptDecrypt("AES", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES", getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_CBC_NoPadding() throws Exception { - encryptDecrypt("AES/CBC/NoPadding", true, false, providerName, interopProviderName); - encryptDecrypt("AES/CBC/NoPadding", true, false, interopProviderName, providerName); + encryptDecrypt("AES/CBC/NoPadding", true, false, getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/CBC/NoPadding", true, false, getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_CBC_PKCS5Padding() throws Exception { - encryptDecrypt("AES/CBC/PKCS5Padding", providerName, interopProviderName); - encryptDecrypt("AES/CBC/PKCS5Padding", interopProviderName, providerName); + encryptDecrypt("AES/CBC/PKCS5Padding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/CBC/PKCS5Padding", getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_CFB8_NoPadding() throws Exception { - encryptDecrypt("AES/CFB8/NoPadding", providerName, interopProviderName); - encryptDecrypt("AES/CFB8/NoPadding", interopProviderName, providerName); + encryptDecrypt("AES/CFB8/NoPadding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/CFB8/NoPadding", getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_CFB_NoPadding() throws Exception { - encryptDecrypt("AES/CFB/NoPadding", providerName, interopProviderName); - encryptDecrypt("AES/CFB/NoPadding", interopProviderName, providerName); + encryptDecrypt("AES/CFB/NoPadding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/CFB/NoPadding", getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_CFB128_NoPadding() throws Exception { - encryptDecrypt("AES/CFB128/NoPadding", providerName, interopProviderName); - encryptDecrypt("AES/CFB128/NoPadding", interopProviderName, providerName); + encryptDecrypt("AES/CFB128/NoPadding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/CFB128/NoPadding", getInteropProviderName(), getProviderName()); } // -------------------------------------------------------------------------- // To-Do enable later. // public void testAES_CFB8_PKCS5Padding() throws Exception { - // encryptDecrypt("AES/CFB8/PKCS5Padding", interopProviderName, providerName); - // encryptDecrypt("AES/CFB8/PKCS5Padding", providerName, interopProviderName); + // encryptDecrypt("AES/CFB8/PKCS5Padding", getInteropProviderName(), getProviderName()); + // encryptDecrypt("AES/CFB8/PKCS5Padding", getProviderName(), getInteropProviderName()); // // } @@ -256,8 +126,8 @@ public void testAES_CFB128_NoPadding() throws Exception { // // public void testAES_CFB_PKCS5Padding() throws Exception // { - // encryptDecrypt("AES/CFB/PKCS5Padding", providerName, interopProviderName); - // encryptDecrypt("AES/CFB/PKCS5Padding", interopProviderName, providerName); + // encryptDecrypt("AES/CFB/PKCS5Padding", getProviderName(), getInteropProviderName()); + // encryptDecrypt("AES/CFB/PKCS5Padding", getInteropProviderName(), getProviderName()); // } // // @@ -267,70 +137,51 @@ public void testAES_CFB128_NoPadding() throws Exception { // // public void testAES_CFB128_PKCS5Padding() throws Exception // { - // encryptDecrypt("AES/CFB128/PKCS5Padding", providerName, interopProviderName); - // encryptDecrypt("AES/CFB128/PKCS5Padding", interopProviderName, providerName); + // encryptDecrypt("AES/CFB128/PKCS5Padding", getProviderName(), getInteropProviderName()); + // encryptDecrypt("AES/CFB128/PKCS5Padding", getInteropProviderName(), getProviderName()); // } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_CTR_NoPadding() throws Exception { - encryptDecrypt("AES/CTR/NoPadding", providerName, interopProviderName); - encryptDecrypt("AES/CTR/NoPadding", interopProviderName, providerName); + encryptDecrypt("AES/CTR/NoPadding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/CTR/NoPadding", getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // Investigate - // public void testAES_CTR_PKCS5Padding() throws Exception - // { - // encryptDecrypt("AES/CTR/ISO10126Padding", providerName, interopProviderName); - // encryptDecrypt("AES/CTR/ISO10126Padding", interopProviderName, providerName); - // } - - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_ECB_NoPadding() throws Exception { - encryptDecrypt("AES/ECB/NoPadding", true, false, providerName, interopProviderName); - encryptDecrypt("AES/ECB/NoPadding", true, false, interopProviderName, providerName); + encryptDecrypt("AES/ECB/NoPadding", true, false, getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/ECB/NoPadding", true, false, getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_ECB_PKCS5Padding() throws Exception { - encryptDecrypt("AES/ECB/PKCS5Padding", providerName, interopProviderName); - encryptDecrypt("AES/ECB/PKCS5Padding", interopProviderName, providerName); + encryptDecrypt("AES/ECB/PKCS5Padding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/ECB/PKCS5Padding", getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_OFB_NoPadding() throws Exception { - encryptDecrypt("AES/OFB/NoPadding", providerName, interopProviderName); - encryptDecrypt("AES/OFB/NoPadding", interopProviderName, providerName); + encryptDecrypt("AES/OFB/NoPadding", getProviderName(), getInteropProviderName()); + encryptDecrypt("AES/OFB/NoPadding", getInteropProviderName(), getProviderName()); } // -------------------------------------------------------------------------- // public void testAES_OFB_PKCS5Padding() throws Exception // { - // encryptDecrypt("AES/OFB/PKCS5Padding", providerName, interopProviderName); - // encryptDecrypt("AES/OFB/PKCS5Padding", interopProviderName, providerName); + // encryptDecrypt("AES/OFB/PKCS5Padding", getProviderName(), getInteropProviderName()); + // encryptDecrypt("AES/OFB/PKCS5Padding", getInteropProviderName(), getProviderName()); // } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESShortBuffer() throws Exception { - doTestAESShortBuffer("AES", providerName); - doTestAESShortBuffer("AES", interopProviderName); + doTestAESShortBuffer("AES", getProviderName()); + doTestAESShortBuffer("AES", getInteropProviderName()); } private void doTestAESShortBuffer(String algorithm, String providerA) throws Exception { try { // Test AES Cipher - cpA = Cipher.getInstance(algorithm, providerName); + cpA = Cipher.getInstance(algorithm, getProviderName()); // Encrypt the plain text cpA.init(Cipher.ENCRYPT_MODE, key); @@ -342,12 +193,10 @@ private void doTestAESShortBuffer(String algorithm, String providerA) throws Exc } } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESIllegalBlockSizeEncrypt() throws Exception { - doTestAESIllegalBlockSizeEncrypt("AES/CBC/NoPadding", providerName); - doTestAESIllegalBlockSizeEncrypt("AES/CBC/NoPadding", interopProviderName); + doTestAESIllegalBlockSizeEncrypt("AES/CBC/NoPadding", getProviderName()); + doTestAESIllegalBlockSizeEncrypt("AES/CBC/NoPadding", getInteropProviderName()); } private void doTestAESIllegalBlockSizeEncrypt(String algorithm, String providerA) @@ -370,12 +219,10 @@ private void doTestAESIllegalBlockSizeEncrypt(String algorithm, String providerA } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESIllegalBlockSizeDecrypt() throws Exception { - doTestAESIllegalBlockSizeDecrypt("AES/CBC/PKCS5Padding", providerName); - doTestAESIllegalBlockSizeDecrypt("AES/CBC/PKCS5Padding", interopProviderName); + doTestAESIllegalBlockSizeDecrypt("AES/CBC/PKCS5Padding", getProviderName()); + doTestAESIllegalBlockSizeDecrypt("AES/CBC/PKCS5Padding", getInteropProviderName()); } private void doTestAESIllegalBlockSizeDecrypt(String algorithm, String providerA) @@ -400,13 +247,11 @@ private void doTestAESIllegalBlockSizeDecrypt(String algorithm, String providerA } - // -------------------------------------------------------------------------- - // - // + @Test public void testAESBadPaddingDecrypt() throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException { - doTestAESBadPaddingDecrypt("AES/CBC/PKCS5Padding", providerName, interopProviderName); - doTestAESBadPaddingDecrypt("AES/CBC/PKCS5Padding", interopProviderName, providerName); + doTestAESBadPaddingDecrypt("AES/CBC/PKCS5Padding", getProviderName(), getInteropProviderName()); + doTestAESBadPaddingDecrypt("AES/CBC/PKCS5Padding", getInteropProviderName(), getProviderName()); } private void doTestAESBadPaddingDecrypt(String algorithm, String providerA, String providerB) @@ -441,6 +286,7 @@ private void doTestAESBadPaddingDecrypt(String algorithm, String providerA, Stri } + @Test public void testAESOnlyFinal() throws Exception { byte[] fullBlock = "0123456789ABCDEF".getBytes(); byte[] incompleteBlock = "0123456789ABCDEF012".getBytes(); @@ -509,6 +355,7 @@ private void doTestAESOnlyFinal(String algorithm, byte[] plainText, String provi } + @Test public void testAESWithUpdateForEncryptionButOnlyFinalForDecryption() throws Exception { byte[] fullBlock = "0123456789ABCDEF".getBytes(); byte[] incompleteBlock = "0123456789ABCDEF012".getBytes(); @@ -580,6 +427,7 @@ private void doTestAESWithUpdateForEncryptionButOnlyFinalForDecryption(String al } + @Test public void testAESWithUpdateForEncryptionAndDecryption() throws Exception { byte[] fullBlock = "0123456789ABCDEF".getBytes(); byte[] incompleteBlock = "0123456789ABCDEF012".getBytes(); @@ -693,26 +541,20 @@ private void doTestAESWithUpdateEncryptionAndDecryption(String algorithm, byte[] } - // -------------------------------------------------------------------------- - // - // + protected void encryptDecrypt(String algorithm, String providerA, String providerB) throws Exception { encryptDecrypt(algorithm, false, false, providerA, providerB); } - // -------------------------------------------------------------------------- - // - // + protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlockSize, boolean testFinalizeOnly, String providerA, String providerB) throws Exception { encryptDecrypt(algorithm, requireLengthMultipleBlockSize, null, testFinalizeOnly, providerA, providerB); } - // -------------------------------------------------------------------------- - // - // + protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, boolean testFinalizeOnly, String providerA, String providerB) throws Exception { @@ -742,9 +584,7 @@ protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlo } - // -------------------------------------------------------------------------- - // - // + protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message, boolean testFinalizeOnly, String providerA, String providerB) throws Exception { @@ -1099,6 +939,7 @@ protected void encryptDecryptUpdateCopySafe(String algorithm, } } + @Test public void testUpdateForAES_CBC_PKCS5Padding() throws Exception { try { @@ -1110,7 +951,7 @@ public void testUpdateForAES_CBC_PKCS5Padding() throws Exception { Arrays.fill(key, (byte) 1); SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES"); - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", providerName); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", getProviderName()); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); byte[] plain = new byte[10000]; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20.java b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20.java index eba21009..7c6effcd 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -21,11 +21,14 @@ import javax.crypto.ShortBufferException; import javax.crypto.spec.ChaCha20ParameterSpec; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTestChaCha20 extends BaseTestCipher implements ChaCha20Constants { - //-------------------------------------------------------------------------- - // - // + // 14 bytes: PASSED static final byte[] PLAIN_TEXT_14 = "12345678123456".getBytes(); @@ -66,9 +69,7 @@ public class BaseTestChaCha20 extends BaseTestCipher implements ChaCha20Constant static final ChaCha20ParameterSpec CHACHA20_PARAM_SPEC_COUNTER_MAX = new ChaCha20ParameterSpec( NONCE_12_BYTE, COUNTER_MAX); - //-------------------------------------------------------------------------- - // - // + protected KeyGenerator keyGen = null; protected SecretKey key = null; protected SecretKeyFactory keyFactory = null; @@ -77,48 +78,29 @@ public class BaseTestChaCha20 extends BaseTestCipher implements ChaCha20Constant protected boolean success = true; protected int specifiedKeySize = 0; - - //-------------------------------------------------------------------------- - // - // - public BaseTestChaCha20(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, providerName); + keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, getProviderName()); if (specifiedKeySize > 0) { keyGen.init(specifiedKeySize); } key = keyGen.generateKey(); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20KeyFactory() throws Exception { try { - keyFactory = SecretKeyFactory.getInstance(CHACHA20_ALGORITHM, providerName); + keyFactory = SecretKeyFactory.getInstance(CHACHA20_ALGORITHM, getProviderName()); } catch (Exception e) { fail("Got unexpected exception on ChaCha20KeyFactory.getInstance()..."); } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20IllegalKeyNonceReuse() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); cp.init(Cipher.DECRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); @@ -129,12 +111,10 @@ public void testChaCha20IllegalKeyNonceReuse() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20ShortBuffer() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -146,58 +126,48 @@ public void testChaCha20ShortBuffer() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20GetBlockSizeEncryptDecrypt() throws Exception { chaCha20GetBlockSize(Cipher.ENCRYPT_MODE); chaCha20GetBlockSize(Cipher.DECRYPT_MODE); } - //-------------------------------------------------------------------------- - // - // + public void chaCha20GetBlockSize(int opMode) throws Exception { ChaCha20ParameterSpec chaCha20ParamSpec = new ChaCha20ParameterSpec(NONCE_12_BYTE, 0); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(opMode, key, chaCha20ParamSpec); assertTrue("ChaCha20 Block size must be: " + ChaCha20_BLOCK_SIZE, (cp.getBlockSize() == ChaCha20_BLOCK_SIZE)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20ValidTransformations() throws Exception { String transformation = null; try { transformation = CHACHA20_ALGORITHM; - cp = Cipher.getInstance(transformation, providerName); + cp = Cipher.getInstance(transformation, getProviderName()); transformation = "ChaCha20/None/NoPadding"; - cp = Cipher.getInstance(transformation, providerName); + cp = Cipher.getInstance(transformation, getProviderName()); } catch (NoSuchAlgorithmException ex) { fail("NoSuchAlgorithmException occurred for transform: " + transformation); } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20InvalidTransformation() throws Exception { String transformation = "BogusChaCha20/BogusMode/BogusPadding"; try { - cp = Cipher.getInstance(transformation, providerName); + cp = Cipher.getInstance(transformation, getProviderName()); fail("Expected NoSuchAlgorithmException did not occur"); } catch (NoSuchAlgorithmException ex) { assertTrue(true); } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20NullKey() throws Exception { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); SecretKey nullKey = null; try { @@ -214,15 +184,13 @@ public void testChaCha20NullKey() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20NoParamSpec() throws Exception { try { // For ChaCha20 you need to pass in the nonce/iv because // there is no way to get the iv out from this cipher. - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(PLAIN_TEXT); @@ -231,16 +199,14 @@ public void testChaCha20NoParamSpec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20NullParamSpec() throws Exception { try { // For ChaCha20 you need to pass in the nonce/iv because // there is no way to get the iv out from this cipher. ChaCha20ParameterSpec chaCha20pec = null; - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, chaCha20pec); cp.doFinal(PLAIN_TEXT); } catch (Exception e) { @@ -248,15 +214,13 @@ public void testChaCha20NullParamSpec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20InvalidParamSpec() throws Exception { try { byte[] iv = null; IvParameterSpec ivSpec = new IvParameterSpec(iv); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, ivSpec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -266,7 +230,7 @@ public void testChaCha20InvalidParamSpec() throws Exception { try { byte[] iv = null; IvParameterSpec ivSpec = new IvParameterSpec(iv); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, ivSpec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -275,7 +239,7 @@ public void testChaCha20InvalidParamSpec() throws Exception { try { ChaCha20ParameterSpec chaCha20pec = new ChaCha20ParameterSpec(NONCE_11_BYTE, COUNTER_1); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, chaCha20pec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -284,7 +248,7 @@ public void testChaCha20InvalidParamSpec() throws Exception { try { ChaCha20ParameterSpec chaCha20pec = new ChaCha20ParameterSpec(NONCE_13_BYTE, COUNTER_1); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, chaCha20pec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -292,20 +256,18 @@ public void testChaCha20InvalidParamSpec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.doFinal(new byte[0]); fail("Did not get expected IllegalStateException(Cipher not initialized)"); } catch (Exception e) { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null); fail("Did not get expected IllegalArgumentException on doFinal(null)"); @@ -313,7 +275,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0]); } catch (Exception e) { @@ -321,7 +283,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0); fail("Did not get expected IllegalArgumentException on doFinal(null, 0)"); @@ -329,7 +291,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1); fail("Did not get expected IllegalArgumentException on doFinal(null, 1)"); @@ -337,7 +299,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0); } catch (ShortBufferException e) { @@ -345,7 +307,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 1)"); @@ -353,7 +315,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[cp.getOutputSize(0)], 1); fail("Did not get expected IllegalArgumentException on doFinal(new byte[cp.getOutputSize(0)], 1)"); @@ -361,7 +323,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0); fail("Did not get expected IllegalArgumentException on doFinal(null, 0, 0)"); @@ -369,7 +331,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1, 0); fail("Did not get expected IllegalArgumentException on doFinal(null, 1, 0)"); @@ -377,7 +339,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 1); fail("Did not get expected IllegalArgumentException on doFinal(null, 0, 1)"); @@ -385,7 +347,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0); } catch (Exception e) { @@ -393,7 +355,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1, 0); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 1, 0)"); @@ -401,7 +363,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 1); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 0, 1)"); @@ -409,7 +371,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0, null); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 0, 1)"); @@ -417,7 +379,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { @@ -425,7 +387,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, null, 0); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 0, 0, null, 0)"); @@ -433,7 +395,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { @@ -441,14 +403,14 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.update(new byte[0]); fail("Did not get expected IllegalStateException(Cipher not initialized)"); } catch (Exception e) { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null); fail("Did not get expected IllegalArgumentException on update(null)"); @@ -456,7 +418,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0]); } catch (Exception e) { @@ -464,7 +426,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0); fail("Did not get expected IllegalArgumentException on update(null, 0, 0)"); @@ -472,7 +434,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 1, 0); fail("Did not get expected IllegalArgumentException on update(null, 1, 0)"); @@ -480,7 +442,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 1); fail("Did not get expected IllegalArgumentException on update(null, 0, 1)"); @@ -488,7 +450,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0); } catch (Exception e) { @@ -496,7 +458,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 1, 0); fail("Did not get expected IllegalArgumentException on update(new byte[0], 1, 0)"); @@ -504,7 +466,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 1); fail("Did not get expected IllegalArgumentException on update(new byte[0], 0, 1)"); @@ -512,7 +474,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, null); fail("Did not get expected IllegalArgumentException on update(null, 0, 0, null)"); @@ -520,7 +482,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, new byte[0]); fail("Did not get expected IllegalArgumentException on update(null, 0, 0, new byte[0])"); @@ -528,7 +490,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null); } catch (Exception e) { @@ -536,7 +498,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { @@ -544,7 +506,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 0); } catch (Exception e) { @@ -552,7 +514,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 1); } catch (Exception e) { @@ -560,7 +522,7 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { @@ -571,17 +533,18 @@ public void testChaCha20EncryptUpdateAndDoFinalArguments() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test using MIN/MAX counter values // + @Test public void testChaCha20EncryptDecryptMinMaxCounter() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_MIN); byte[] cipherText = cp.doFinal(PLAIN_TEXT); paramSpec = CHACHA20_PARAM_SPEC_COUNTER_MIN; // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -592,14 +555,14 @@ public void testChaCha20EncryptDecryptMinMaxCounter() throws Exception { } try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_MAX); byte[] cipherText = cp.doFinal(PLAIN_TEXT); paramSpec = CHACHA20_PARAM_SPEC_COUNTER_MAX; // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -613,16 +576,17 @@ public void testChaCha20EncryptDecryptMinMaxCounter() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls // + @Test public void testChaCha20EncryptDecryptDoFinal() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); byte[] cipherText = cp.doFinal(PLAIN_TEXT); paramSpec = CHACHA20_PARAM_SPEC_COUNTER_0; // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -636,9 +600,10 @@ public void testChaCha20EncryptDecryptDoFinal() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just update, empty doFinal calls // + @Test public void testChaCha20EncryptDecryptUpdate() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_1); byte[] cipherText1 = cp.update(PLAIN_TEXT); byte[] cipherText2 = cp.doFinal(); @@ -646,7 +611,7 @@ public void testChaCha20EncryptDecryptUpdate() throws Exception { paramSpec = CHACHA20_PARAM_SPEC_COUNTER_1; // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText1 = (cipherText1 == null) ? new byte[0] : cp.update(cipherText1); byte[] newPlainText2 = cp.doFinal(cipherText2); @@ -669,11 +634,12 @@ public void testChaCha20EncryptDecryptUpdate() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test with partial update // + @Test public void testChaCha20EncryptDecryptPartialUpdate() throws Exception { int partialLen = PLAIN_TEXT.length > 10 ? 10 : 1; try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); byte[] cipherText1 = cp.update(PLAIN_TEXT, 0, partialLen); byte[] cipherText2 = cp.doFinal(PLAIN_TEXT, partialLen, PLAIN_TEXT.length - partialLen); @@ -681,7 +647,7 @@ public void testChaCha20EncryptDecryptPartialUpdate() throws Exception { paramSpec = CHACHA20_PARAM_SPEC_COUNTER_0; // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText1 = (cipherText1 == null) ? new byte[0] : cp.update(cipherText1); byte[] newPlainText2 = cp.doFinal(cipherText2); @@ -704,9 +670,10 @@ public void testChaCha20EncryptDecryptPartialUpdate() throws Exception { //-------------------------------------------------------------------------- // Run encrypt twice using same Cipher instance, same key, but different nonce // + @Test public void testChaCha20ReuseObjectSameKeyDifferentNonce() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); byte[] cipherText1 = cp.doFinal(PLAIN_TEXT); @@ -727,15 +694,16 @@ public void testChaCha20ReuseObjectSameKeyDifferentNonce() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls (copy-safe) // + @Test public void testChaCha20EncryptDecryptDoFinalCopySafe() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); byte[] cipherText0 = cp.doFinal(PLAIN_TEXT); byte[] resultBuffer = Arrays.copyOf(PLAIN_TEXT, cp.getOutputSize(PLAIN_TEXT.length)); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); int resultLen = cp.doFinal(resultBuffer, 0, PLAIN_TEXT.length, resultBuffer); byte[] cipherText = Arrays.copyOf(resultBuffer, resultLen); @@ -746,7 +714,7 @@ public void testChaCha20EncryptDecryptDoFinalCopySafe() throws Exception { assertTrue("Encrypted text does not match expected result", success); // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); resultBuffer = Arrays.copyOf(cipherText, cipherText.length);//cp.getOutputSize(cipherText.length)); resultLen = cp.doFinal(resultBuffer, 0, cipherText.length, resultBuffer); @@ -764,15 +732,16 @@ public void testChaCha20EncryptDecryptDoFinalCopySafe() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just update, empty doFinal calls (copy-safe) // + @Test public void testChaCha20EncryptDecryptUpdateCopySafe() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); byte[] cipherText0 = cp.doFinal(PLAIN_TEXT); byte[] cipherText1 = Arrays.copyOf(PLAIN_TEXT, cp.getOutputSize(PLAIN_TEXT.length)); - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_PARAM_SPEC_COUNTER_0); int cipherText1Len = cp.update(cipherText1, 0, PLAIN_TEXT.length, cipherText1); byte[] cipherText2 = cp.doFinal(); @@ -788,7 +757,7 @@ public void testChaCha20EncryptDecryptUpdateCopySafe() throws Exception { assertTrue("Encrypted text does not match expected result", success); // Verify the text - cp = Cipher.getInstance(CHACHA20_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] plainText1 = Arrays.copyOf(cipherText12, cp.getOutputSize(cipherText12.length)); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20KAT.java b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20KAT.java index e45b7048..a238a023 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20KAT.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20KAT.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,14 +20,9 @@ import javax.crypto.spec.ChaCha20ParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; public class BaseTestChaCha20KAT extends BaseTestCipher { - - public BaseTestChaCha20KAT(String providerName) { - super(providerName); - } - - public class TestData { public TestData(String name, String keyStr, String nonceStr, int ctr, int dir, String inputStr, String aadStr, String outStr) { @@ -163,7 +158,7 @@ public TestData(String name, String keyStr, String nonceStr, int ctr, int dir, } }; - + @Test public void testChaChaKnownAnswer() throws Exception { int testsPassed = 0; int testNumber = 0; @@ -243,7 +238,7 @@ private boolean runSinglePartTest(TestData testData) throws GeneralSecurityExcep byte[] decryptedResult; // Get a Cipher instance and set up the parameters - Cipher mambo = Cipher.getInstance("ChaCha20", providerName); + Cipher mambo = Cipher.getInstance("ChaCha20", getProviderName()); SecretKeySpec mamboKey = new SecretKeySpec(testData.key, "ChaCha20"); /* @@ -269,7 +264,7 @@ private boolean runSinglePartTest(TestData testData) throws GeneralSecurityExcep } // Decrypt the result of the encryption operation - mambo = Cipher.getInstance("ChaCha20", providerName); + mambo = Cipher.getInstance("ChaCha20", getProviderName()); mambo.init(Cipher.DECRYPT_MODE, mamboKey, mamboSpec); decryptedResult = mambo.doFinal(encryptedResult); @@ -290,7 +285,7 @@ private boolean runMultiPartTest(TestData testData) throws GeneralSecurityExcept boolean decRes = false; // Get a cipher instance and initialize it - Cipher mambo = Cipher.getInstance("ChaCha20", providerName); + Cipher mambo = Cipher.getInstance("ChaCha20", getProviderName()); SecretKeySpec mamboKey = new SecretKeySpec(testData.key, "ChaCha20"); ChaCha20ParameterSpec mamboSpec = new ChaCha20ParameterSpec(testData.nonce, testData.counter); @@ -310,7 +305,7 @@ private boolean runMultiPartTest(TestData testData) throws GeneralSecurityExcept } // Decrypt the result of the encryption operation - mambo = Cipher.getInstance("ChaCha20", providerName); + mambo = Cipher.getInstance("ChaCha20", getProviderName()); byte[] decryptedResult = new byte[encryptedResult.length]; mambo.init(Cipher.DECRYPT_MODE, mamboKey, mamboSpec); System.out.print("Decrypt - "); @@ -360,7 +355,7 @@ private boolean runByteBuffer(TestData testData) throws GeneralSecurityException boolean decRes = false; // Get a cipher instance and initialize it - Cipher mambo = Cipher.getInstance("ChaCha20", providerName); + Cipher mambo = Cipher.getInstance("ChaCha20", getProviderName()); SecretKeySpec mamboKey = new SecretKeySpec(testData.key, "ChaCha20"); ChaCha20ParameterSpec mamboSpec = new ChaCha20ParameterSpec(testData.nonce, testData.counter); @@ -384,7 +379,7 @@ private boolean runByteBuffer(TestData testData) throws GeneralSecurityException } // Decrypt the result of the encryption operation - mambo = Cipher.getInstance("ChaCha20", providerName); + mambo = Cipher.getInstance("ChaCha20", getProviderName()); mambo.init(Cipher.DECRYPT_MODE, mamboKey, mamboSpec); System.out.print("Decrypt - "); ByteBuffer bbDecOut = ByteBuffer.allocate(mambo.getOutputSize(bbEncOut.remaining())); @@ -409,7 +404,7 @@ private boolean runAEADTest(TestData testData) throws GeneralSecurityException { System.out.println("\nFeed all data at once into update Test: " + testData.testName); boolean result = false; - Cipher mambo = Cipher.getInstance("ChaCha20-Poly1305", providerName); + Cipher mambo = Cipher.getInstance("ChaCha20-Poly1305", getProviderName()); SecretKeySpec mamboKey = new SecretKeySpec(testData.key, "ChaCha20"); IvParameterSpec mamboSpec = new IvParameterSpec(testData.nonce); @@ -490,7 +485,7 @@ private boolean runAEADChopTest(TestData testData, int chopLength) "\nFeed in " + chopLength + " bytes at time to update Test: " + testData.testName); boolean result = false; - Cipher mambo = Cipher.getInstance("ChaCha20-Poly1305", providerName); + Cipher mambo = Cipher.getInstance("ChaCha20-Poly1305", getProviderName()); SecretKeySpec mamboKey = new SecretKeySpec(testData.key, "ChaCha20"); IvParameterSpec mamboSpec = new IvParameterSpec(testData.nonce); int tagLen = 0; @@ -573,7 +568,7 @@ private boolean runAEADBadTagTest(TestData testData) throws GeneralSecurityExcep boolean result = false; - Cipher mambo = Cipher.getInstance("ChaCha20-Poly1305", providerName); + Cipher mambo = Cipher.getInstance("ChaCha20-Poly1305", getProviderName()); SecretKeySpec mamboKey = new SecretKeySpec(testData.key, "ChaCha20"); IvParameterSpec mamboSpec = new IvParameterSpec(testData.nonce); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20NoReuse.java b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20NoReuse.java index f2873b9e..4ffc8632 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20NoReuse.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20NoReuse.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -21,24 +21,9 @@ import javax.crypto.spec.ChaCha20ParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; public class BaseTestChaCha20NoReuse extends BaseTestCipher implements ChaCha20Constants { - // -------------------------------------------------------------------------- - // - // - public BaseTestChaCha20NoReuse(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} private static final String ALG_CC20 = "ChaCha20"; private static final String ALG_CC20_P1305 = "ChaCha20-Poly1305"; @@ -171,7 +156,7 @@ public TestData(String name, String keyStr, String nonceStr, int ctr, int dir, /** * Make sure we do not use this Cipher object without initializing it at all */ - public static final TestMethod noInitTest = new TestMethod() { + public final TestMethod noInitTest = new TestMethod() { @Override public boolean isValid(String algorithm) { return true; // Valid for all algs @@ -181,7 +166,7 @@ public boolean isValid(String algorithm) { public boolean run(String algorithm, String providerName) { System.out.println("----- No Init Test noInitTest [" + algorithm + "] -----"); try { - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); TestData testData; switch (algorithm) { case ALG_CC20: @@ -223,7 +208,7 @@ public String getName() { /** * Make sure we don't allow a double init using the same parameters */ - public static final TestMethod doubleInitTest = new TestMethod() { + public final TestMethod doubleInitTest = new TestMethod() { @Override public boolean isValid(String algorithm) { return true; // Valid for all algs @@ -234,7 +219,7 @@ public boolean run(String algorithm, String providerName) { System.out.println("----- Double Init Test doubleInitTest [" + algorithm + "] -----"); try { AlgorithmParameterSpec spec; - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); TestData testData; switch (algorithm) { case ALG_CC20: @@ -279,7 +264,7 @@ public String getName() { /** * Attempt to run two full encryption operations without an init in between. */ - public static final TestMethod encTwiceNoInit = new TestMethod() { + public final TestMethod encTwiceNoInit = new TestMethod() { @Override public boolean isValid(String algorithm) { return true; // Valid for all algs @@ -291,7 +276,7 @@ public boolean run(String algorithm, String providerName) { + "] -----"); try { AlgorithmParameterSpec spec; - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); TestData testData; switch (algorithm) { case ALG_CC20: @@ -346,7 +331,7 @@ public String getName() { /** * Attempt to run two full decryption operations without an init in between. */ - public static final TestMethod decTwiceNoInit = new TestMethod() { + public final TestMethod decTwiceNoInit = new TestMethod() { @Override public boolean isValid(String algorithm) { return true; // Valid for all algs @@ -358,7 +343,7 @@ public boolean run(String algorithm, String providerName) { + "] -----"); try { AlgorithmParameterSpec spec; - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); TestData testData; switch (algorithm) { case ALG_CC20: @@ -418,7 +403,7 @@ public String getName() { * Perform an AEAD decryption with corrupted data so the tag does not match. * Then attempt to reuse the cipher without initialization. */ - public static final TestMethod decFailNoInit = new TestMethod() { + public final TestMethod decFailNoInit = new TestMethod() { @Override public boolean isValid(String algorithm) { return algorithm.equals(ALG_CC20_P1305); @@ -434,7 +419,7 @@ public boolean run(String algorithm, String providerName) { byte[] corruptInput = testData.input.clone(); corruptInput[0]++; // Corrupt the ciphertext SecretKey key = new SecretKeySpec(testData.key, ALG_CC20); - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); try { // Initialize and encrypt @@ -473,7 +458,7 @@ public String getName() { /** * Encrypt once successfully, then attempt to init with the same key and nonce. */ - public static final TestMethod encTwiceInitSameParams = new TestMethod() { + public final TestMethod encTwiceInitSameParams = new TestMethod() { @Override public boolean isValid(String algorithm) { return true; // Valid for all algs @@ -485,7 +470,7 @@ public boolean run(String algorithm, String providerName) { .println("----- Encrypt, then init with same params [" + algorithm + "] -----"); try { AlgorithmParameterSpec spec; - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); TestData testData; switch (algorithm) { case ALG_CC20: @@ -541,7 +526,7 @@ public String getName() { /** * Decrypt once successfully, then attempt to init with the same key and nonce. */ - public static final TestMethod decTwiceInitSameParams = new TestMethod() { + public final TestMethod decTwiceInitSameParams = new TestMethod() { @Override public boolean isValid(String algorithm) { return true; // Valid for all algs @@ -553,7 +538,7 @@ public boolean run(String algorithm, String providerName) { + algorithm + "] -----"); try { AlgorithmParameterSpec spec; - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); TestData testData; switch (algorithm) { case ALG_CC20: @@ -607,16 +592,13 @@ public String getName() { public static final List algList = Arrays.asList(ALG_CC20, ALG_CC20_P1305); - public static final List testMethodList = Arrays.asList(noInitTest, doubleInitTest, + public final List testMethodList = Arrays.asList(noInitTest, doubleInitTest, encTwiceNoInit, decTwiceNoInit, decFailNoInit, encTwiceInitSameParams, decTwiceInitSameParams); // public static final List algList = Arrays.asList(ALG_CC20_P1305); //DEBUG ONLY // public static final List testMethodList = Arrays.asList(decFailNoInit); //DEBUG ONLY - - // -------------------------------------------------------------------------- - // - // + @Test public void testChaChaNoReuse() throws Exception { { int testsPassed = 0; @@ -627,7 +609,7 @@ public void testChaChaNoReuse() throws Exception { for (String alg : algList) { if (tm.isValid(alg)) { testNumber++; - boolean result = tm.run(alg, providerName); + boolean result = tm.run(alg, getProviderName()); System.out.println(tm.getName() + "[" + alg + "] Result: " + (result ? "PASS" : "FAIL")); System.out.println( diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305.java b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305.java index 6efb9ef5..a08d1141 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,11 +20,14 @@ import javax.crypto.SecretKey; import javax.crypto.ShortBufferException; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTestChaCha20Poly1305 extends BaseTestCipher implements ChaCha20Constants { - //-------------------------------------------------------------------------- - // - // + // 14 bytes: PASSED static final byte[] PLAIN_TEXT_14 = "12345678123456".getBytes(); @@ -59,9 +62,7 @@ public class BaseTestChaCha20Poly1305 extends BaseTestCipher implements ChaCha20 static final IvParameterSpec CHACHA20_POLY1305_PARAM_SPEC = new IvParameterSpec(NONCE_12_BYTE); - //-------------------------------------------------------------------------- - // - // + protected KeyGenerator keyGen = null; protected SecretKey key = null; protected IvParameterSpec paramSpec = null; @@ -69,37 +70,19 @@ public class BaseTestChaCha20Poly1305 extends BaseTestCipher implements ChaCha20 protected boolean success = true; protected int specifiedKeySize = 0; - - - //-------------------------------------------------------------------------- - // - // - public BaseTestChaCha20Poly1305(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, providerName); + keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, getProviderName()); if (specifiedKeySize > 0) { keyGen.init(specifiedKeySize); } key = keyGen.generateKey(); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305IllegalKeyNonceReuse() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.init(Cipher.DECRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); @@ -111,12 +94,10 @@ public void testChaCha20Poly1305IllegalKeyNonceReuse() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305ShortBuffer() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, key); @@ -128,12 +109,10 @@ public void testChaCha20Poly1305ShortBuffer() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305EncryptAfterShortBufferRetry() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); IvParameterSpec ivParamSpec = new IvParameterSpec(NONCE_12_BYTE); // Encrypt the plain text @@ -157,11 +136,12 @@ public void testChaCha20Poly1305EncryptAfterShortBufferRetry() throws Exception } } + @Test public void testChaCha20Poly1305DecryptAfterShortBufferRetry() throws Exception { byte[] cipherText = null; Cipher cpl = null; try { - cpl = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cpl = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); IvParameterSpec ivParamSpec = new IvParameterSpec(NONCEA_12_BYTE); // Encrypt the plain text @@ -170,7 +150,7 @@ public void testChaCha20Poly1305DecryptAfterShortBufferRetry() throws Exception ivParamSpec = cpl.getParameters().getParameterSpec(IvParameterSpec.class); - cpl = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cpl = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cpl.init(Cipher.DECRYPT_MODE, key, ivParamSpec); byte[] sbPlainText = new byte[15]; System.out.println("cipherText.length=" + cipherText.length); @@ -192,58 +172,48 @@ public void testChaCha20Poly1305DecryptAfterShortBufferRetry() throws Exception } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305GetBlockSizeEncryptDecrypt() throws Exception { chaCha20GetBlockSize(Cipher.ENCRYPT_MODE); chaCha20GetBlockSize(Cipher.DECRYPT_MODE); } - //-------------------------------------------------------------------------- - // - // + public void chaCha20GetBlockSize(int opMode) throws Exception { IvParameterSpec chaCha20ParamSpec = new IvParameterSpec(NONCE_12_BYTE); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(opMode, key, chaCha20ParamSpec); assertTrue("ChaCha20 Block size must be: " + ChaCha20_BLOCK_SIZE, (cp.getBlockSize() == ChaCha20_BLOCK_SIZE)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305ValidTransformations() throws Exception { String transformation = null; try { transformation = CHACHA20_POLY1305_ALGORITHM; - cp = Cipher.getInstance(transformation, providerName); + cp = Cipher.getInstance(transformation, getProviderName()); transformation = "ChaCha20-Poly1305/None/NoPadding"; - cp = Cipher.getInstance(transformation, providerName); + cp = Cipher.getInstance(transformation, getProviderName()); } catch (NoSuchAlgorithmException ex) { fail("NoSuchAlgorithmException occurred for transform: " + transformation); } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305InvalidTransformation() throws Exception { String transformation = "BogusChaCha20-Poly1305/BogusMode/BogusPadding"; try { - cp = Cipher.getInstance(transformation, providerName); + cp = Cipher.getInstance(transformation, getProviderName()); fail("Expected NoSuchAlgorithmException did not occur"); } catch (NoSuchAlgorithmException ex) { assertTrue(true); } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305NullKey() throws Exception { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); SecretKey nullKey = null; try { @@ -259,20 +229,18 @@ public void testChaCha20Poly1305NullKey() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305NoParamSpec() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); byte[] cipherText = cp.doFinal(PLAIN_TEXT); paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -283,21 +251,19 @@ public void testChaCha20Poly1305NoParamSpec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305NullParamSpec() throws Exception { try { IvParameterSpec ivSpec = null; - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, ivSpec); byte[] cipherText = cp.doFinal(PLAIN_TEXT); paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -308,15 +274,13 @@ public void testChaCha20Poly1305NullParamSpec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305InvalidParamSpec() throws Exception { try { byte[] iv = null; IvParameterSpec ivSpec = new IvParameterSpec(iv); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, ivSpec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -326,7 +290,7 @@ public void testChaCha20Poly1305InvalidParamSpec() throws Exception { try { byte[] iv = null; IvParameterSpec ivSpec = new IvParameterSpec(iv); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, ivSpec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -335,8 +299,8 @@ public void testChaCha20Poly1305InvalidParamSpec() throws Exception { try { AlgorithmParameters algParameters = AlgorithmParameters - .getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + .getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, algParameters); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -345,8 +309,8 @@ public void testChaCha20Poly1305InvalidParamSpec() throws Exception { try { AlgorithmParameters algParameters = AlgorithmParameters - .getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + .getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, algParameters); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -355,7 +319,7 @@ public void testChaCha20Poly1305InvalidParamSpec() throws Exception { try { IvParameterSpec ivSpec = new IvParameterSpec(NONCE_11_BYTE); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, ivSpec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -364,7 +328,7 @@ public void testChaCha20Poly1305InvalidParamSpec() throws Exception { try { IvParameterSpec ivSpec = new IvParameterSpec(NONCE_13_BYTE); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, ivSpec); fail("Expected NullPointerException or InvalidAlgorithmParameterException"); } catch (NullPointerException npe) { @@ -372,13 +336,11 @@ public void testChaCha20Poly1305InvalidParamSpec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.update(PLAIN_TEXT); // Update AAD must be done before cipher update, or do final... @@ -388,7 +350,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.doFinal(PLAIN_TEXT); // Update AAD must be done before cipher update, or do final... @@ -399,21 +361,21 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); fail("Did not get expected IllegalStateException(Cipher not initialized)"); } catch (Exception e) { } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.doFinal(new byte[0]); fail("Did not get expected IllegalStateException(Cipher not initialized)"); } catch (Exception e) { } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null); fail("Did not get expected IllegalArgumentException on doFinal(null)"); @@ -421,7 +383,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0]); } catch (Exception e) { @@ -429,7 +391,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0); fail("Did not get expected IllegalArgumentException on doFinal(null, 0)"); @@ -437,7 +399,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1); fail("Did not get expected IllegalArgumentException on doFinal(null, 1)"); @@ -445,7 +407,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0); fail("Did not get expected exception on doFinal(new byte[0], 0)"); @@ -453,7 +415,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 1)"); @@ -461,7 +423,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[cp.getOutputSize(0)], 1); fail("Did not get expected IllegalArgumentException on doFinal(new byte[cp.getOutputSize(0)], 1)"); @@ -469,7 +431,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0); fail("Did not get expected IllegalArgumentException on doFinal(null, 0, 0)"); @@ -477,7 +439,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1, 0); fail("Did not get expected IllegalArgumentException on doFinal(null, 1, 0)"); @@ -485,7 +447,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 1); fail("Did not get expected IllegalArgumentException on doFinal(null, 0, 1)"); @@ -493,7 +455,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0); } catch (Exception e) { @@ -501,7 +463,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1, 0); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 1, 0)"); @@ -509,7 +471,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 1); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 0, 1)"); @@ -517,7 +479,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0, null); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 0, 1)"); @@ -525,7 +487,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0]); fail("Did not get expected exception on doFinal(new byte[0], 0, 0, new byte[0])"); @@ -533,7 +495,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, null, 0); fail("Did not get expected IllegalArgumentException on doFinal(new byte[0], 0, 0, null, 0)"); @@ -541,7 +503,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0], 0); fail("Did not get expected exception on doFinal(new byte[0], 0, 0, new byte[0], 0)"); @@ -549,14 +511,14 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.update(new byte[0]); fail("Did not get expected IllegalStateException(Cipher not initialized)"); } catch (Exception e) { } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null); fail("Did not get expected IllegalArgumentException on update(null)"); @@ -564,7 +526,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0]); } catch (Exception e) { @@ -572,7 +534,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0); fail("Did not get expected IllegalArgumentException on update(null, 0, 0)"); @@ -580,7 +542,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 1, 0); fail("Did not get expected IllegalArgumentException on update(null, 1, 0)"); @@ -588,7 +550,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 1); fail("Did not get expected IllegalArgumentException on update(null, 0, 1)"); @@ -596,7 +558,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0); } catch (Exception e) { @@ -604,7 +566,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 1, 0); fail("Did not get expected IllegalArgumentException on update(new byte[0], 1, 0)"); @@ -612,7 +574,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 1); fail("Did not get expected IllegalArgumentException on update(new byte[0], 0, 1)"); @@ -620,7 +582,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, null); fail("Did not get expected IllegalArgumentException on update(null, 0, 0, null)"); @@ -628,7 +590,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, new byte[0]); fail("Did not get expected IllegalArgumentException on update(null, 0, 0, new byte[0])"); @@ -636,7 +598,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null); } catch (Exception e) { @@ -644,7 +606,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { @@ -652,7 +614,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 0); } catch (Exception e) { @@ -660,7 +622,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 1); } catch (Exception e) { @@ -668,7 +630,7 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { @@ -676,18 +638,16 @@ public void testChaCha20Poly1305EncryptUpdateAndDoFinalArguments() throws Except } } - //-------------------------------------------------------------------------- - // - // + @Test public void testChaCha20Poly1305DecryptUpdateAndDoFinalArguments() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); cp.doFinal(PLAIN_TEXT); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.update(PLAIN_TEXT); // Update AAD must be done before cipher update, or do final... @@ -697,12 +657,12 @@ public void testChaCha20Poly1305DecryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); cp.doFinal(PLAIN_TEXT); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.doFinal(PLAIN_TEXT); // Update AAD must be done before cipher update, or do final... @@ -712,7 +672,7 @@ public void testChaCha20Poly1305DecryptUpdateAndDoFinalArguments() throws Except } try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); fail("Did not get expected IllegalStateException(Cipher not initialized)"); } catch (Exception e) { @@ -723,16 +683,17 @@ public void testChaCha20Poly1305DecryptUpdateAndDoFinalArguments() throws Except //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls // + @Test public void testChaCha20Poly1305EncryptDecryptDoFinalWithoutAAD() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText = cp.doFinal(PLAIN_TEXT); paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -746,9 +707,10 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithoutAAD() throws Excepti //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls // + @Test public void testChaCha20Poly1305EncryptDecryptDoFinalWithAAD() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); byte[] cipherText = cp.doFinal(PLAIN_TEXT); @@ -756,7 +718,7 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithAAD() throws Exception paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); @@ -771,9 +733,10 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithAAD() throws Exception //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls // + @Test public void testChaCha20Poly1305EncryptDecryptDoFinalWithoutAadBadTag() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText = cp.doFinal(PLAIN_TEXT); System.arraycopy(BAD_TAG_16, 0, cipherText, cipherText.length - BAD_TAG_16.length, @@ -782,7 +745,7 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithoutAadBadTag() throws E paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); cp.doFinal(cipherText, 0, cipherText.length); @@ -795,17 +758,18 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithoutAadBadTag() throws E //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls // + @Test public void testChaCha20Poly1305DecryptDoFinalWithAadNoTag() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); cp.doFinal(PLAIN_TEXT); paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); cp.doFinal(); @@ -819,9 +783,10 @@ public void testChaCha20Poly1305DecryptDoFinalWithAadNoTag() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just update, empty doFinal calls // + @Test public void testChaCha20Poly1305EncryptDecryptUpdate() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText1 = cp.update(PLAIN_TEXT); byte[] cipherText2 = cp.doFinal(); @@ -829,7 +794,7 @@ public void testChaCha20Poly1305EncryptDecryptUpdate() throws Exception { paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText1 = (cipherText1 == null) ? new byte[0] : cp.update(cipherText1); byte[] newPlainText2 = cp.doFinal(cipherText2); @@ -852,11 +817,12 @@ public void testChaCha20Poly1305EncryptDecryptUpdate() throws Exception { //-------------------------------------------------------------------------- // Run encrypt/decrypt test with partial update // + @Test public void testChaCha20Poly1305EncryptDecryptPartialUpdate() throws Exception { int partialLen = PLAIN_TEXT.length > 10 ? 10 : 1; try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText1 = cp.update(PLAIN_TEXT, 0, partialLen); byte[] cipherText2 = cp.doFinal(PLAIN_TEXT, partialLen, PLAIN_TEXT.length - partialLen); @@ -864,7 +830,7 @@ public void testChaCha20Poly1305EncryptDecryptPartialUpdate() throws Exception { paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] newPlainText1 = (cipherText1 == null) ? new byte[0] : cp.update(cipherText1); byte[] newPlainText2 = cp.doFinal(cipherText2); @@ -887,9 +853,10 @@ public void testChaCha20Poly1305EncryptDecryptPartialUpdate() throws Exception { //-------------------------------------------------------------------------- // Run encrypt twice using same Cipher instance, same key, but different nonce // + @Test public void testChaCha20Poly1305ReuseObjectSameKeyDifferentNonce() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText1 = cp.doFinal(PLAIN_TEXT); @@ -912,15 +879,16 @@ public void testChaCha20Poly1305ReuseObjectSameKeyDifferentNonce() throws Except //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls (copy-safe) // + @Test public void testChaCha20Poly1305EncryptDecryptDoFinalCopySafe() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText0 = cp.doFinal(PLAIN_TEXT); byte[] resultBuffer = Arrays.copyOf(PLAIN_TEXT, cp.getOutputSize(PLAIN_TEXT.length)); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); int resultLen = cp.doFinal(resultBuffer, 0, PLAIN_TEXT.length, resultBuffer); byte[] cipherText = Arrays.copyOf(resultBuffer, resultLen); @@ -931,7 +899,7 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalCopySafe() throws Exception assertTrue("Encrypted text does not match expected result", success); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); resultBuffer = Arrays.copyOf(cipherText, cipherText.length);//cp.getOutputSize(cipherText.length)); resultLen = cp.doFinal(resultBuffer, 0, cipherText.length, resultBuffer); @@ -949,15 +917,16 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalCopySafe() throws Exception //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just update, empty doFinal calls (copy-safe) // + @Test public void testChaCha20Poly1305EncryptDecryptUpdateCopySafe() throws Exception { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] cipherText0 = cp.doFinal(PLAIN_TEXT); byte[] cipherText1 = Arrays.copyOf(PLAIN_TEXT, cp.getOutputSize(PLAIN_TEXT.length)); - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); int cipherText1Len = cp.update(cipherText1, 0, PLAIN_TEXT.length, cipherText1); byte[] cipherText2 = cp.doFinal(); @@ -972,7 +941,7 @@ public void testChaCha20Poly1305EncryptDecryptUpdateCopySafe() throws Exception assertTrue("Encrypted text does not match expected result", success); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); byte[] plainText1 = Arrays.copyOf(cipherText12, cp.getOutputSize(cipherText12.length)); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ByteBuffer.java b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ByteBuffer.java index 3ddc12b4..a08e133c 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,8 +16,11 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestChaCha20Poly1305ByteBuffer extends BaseTest { +public class BaseTestChaCha20Poly1305ByteBuffer extends BaseTestJunit5 { private static Random random = new SecureRandom(); private static int dataSize = 4096; // see javax.crypto.CipherSpi @@ -36,9 +39,7 @@ public class BaseTestChaCha20Poly1305ByteBuffer extends BaseTest { static final String CHACHA20_ALGORITHM = "ChaCha20"; - //-------------------------------------------------------------------------- - // - // + protected KeyGenerator keyGen = null; protected SecretKey key = null; protected IvParameterSpec paramSpec = null; @@ -46,25 +47,18 @@ public class BaseTestChaCha20Poly1305ByteBuffer extends BaseTest { protected boolean success = true; protected int specifiedKeySize = 0; - - public BaseTestChaCha20Poly1305ByteBuffer(String providerName) { - super(providerName); - } - - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, providerName); + keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, getProviderName()); if (specifiedKeySize > 0) { keyGen.init(specifiedKeySize); } //key = keyGen.generateKey(); } + @Test public void testByteBuffer() throws Exception { - Cipher cipher = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + Cipher cipher = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); System.out.println("Testing " + cipher.getProvider()); boolean failedOnce = false; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ChunkUpdate.java b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ChunkUpdate.java index 1e0b7cfe..7bd8da59 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ChunkUpdate.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestChaCha20Poly1305ChunkUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ import javax.crypto.SecretKey; import javax.crypto.ShortBufferException; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestChaCha20Poly1305ChunkUpdate extends BaseTestCipher implements ChaCha20Constants { @@ -27,20 +30,16 @@ public class BaseTestChaCha20Poly1305ChunkUpdate extends BaseTestCipher protected SecretKey key = null; protected int specifiedKeySize = 0; - public BaseTestChaCha20Poly1305ChunkUpdate(String providerName) { - super(providerName); - } - + @BeforeEach public void setUp() throws Exception { - keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, providerName); + keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, getProviderName()); if (specifiedKeySize > 0) { keyGen.init(specifiedKeySize); } key = keyGen.generateKey(); } - public void tearDown() throws Exception {} - + @Test public void testChunks() throws Exception { testChunkUpdate(0); testChunkUpdate(1); @@ -88,7 +87,7 @@ private void testChunkUpdate(int inputSize) throws Exception { } private byte[] encrypt(byte[] pText) throws Exception { - Cipher cipher = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + Cipher cipher = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cipher.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); byte[] encryptedText = cipher.doFinal(pText); byte[] output = ByteBuffer.allocate(encryptedText.length + ChaCha20_NONCE_SIZE) @@ -104,7 +103,7 @@ private byte[] decrypt(byte[] cText, int size) throws Exception { bb.get(encryptedText); bb.get(nonce); - Cipher cipher = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + Cipher cipher = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); IvParameterSpec iv = new IvParameterSpec(nonce); cipher.init(Cipher.DECRYPT_MODE, key, iv); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestCipher.java b/src/test/java/ibm/jceplus/junit/base/BaseTestCipher.java index 6e4bc06b..8065c83b 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestCipher.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestCipher.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,13 +9,7 @@ import java.util.StringTokenizer; -public class BaseTestCipher extends BaseTest { - //-------------------------------------------------------------------------- - // - // - public BaseTestCipher(String providerName) { - super(providerName); - } +public class BaseTestCipher extends BaseTestJunit5 { // -------------------------------------------------------------------------- // This method is to check whether a transformation is valid for the cipher diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDESede.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDESede.java index d06215ed..9ce8f000 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDESede.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDESede.java @@ -22,6 +22,11 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.RC2ParameterSpec; import javax.crypto.spec.RC5ParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; public class BaseTestDESede extends BaseTestCipher { @@ -44,7 +49,6 @@ public class BaseTestDESede extends BaseTestCipher { static final byte[] plainText = plainText128; // default value - protected boolean supportsEncrypt; protected String encryptProviderName; protected KeyGenerator keyGen; protected SecretKey key; @@ -57,21 +61,13 @@ public class BaseTestDESede extends BaseTestCipher { */ protected Cipher cp = null; - public BaseTestDESede(String providerName) { - this(providerName, true); - } - - public BaseTestDESede(String providerName, boolean supportsEncrypt) { - super(providerName); - this.supportsEncrypt = supportsEncrypt; - this.encryptProviderName = supportsEncrypt ? providerName : "IBMJCE"; - } - + @BeforeEach public void setUp() throws Exception { + this.encryptProviderName = getProviderName(); try { - keyGen = KeyGenerator.getInstance("DESede", providerName); + keyGen = KeyGenerator.getInstance("DESede", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DESede for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -81,11 +77,12 @@ public void setUp() throws Exception { key = keyGen.generateKey(); } + @Test public void testDESede() throws Exception { try { encryptDecrypt("DESede"); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede", nsae.getMessage()); return; } else { @@ -94,12 +91,13 @@ public void testDESede() throws Exception { } } + @Test public void testDESede_CBC_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/CBC/ISO10126Padding", providerName); + cp = Cipher.getInstance("DESede/CBC/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/CBC/ISO10126Padding", nsae.getMessage()); return; } else { @@ -110,11 +108,12 @@ public void testDESede_CBC_ISO10126Padding() throws Exception { } } + @Test public void testDESede_CBC_NoPadding() throws Exception { try { encryptDecrypt("DESede/CBC/NoPadding", true); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/CBC/NoPadding", nsae.getMessage()); return; } else { @@ -123,11 +122,12 @@ public void testDESede_CBC_NoPadding() throws Exception { } } + @Test public void testDESede_CBC_PKCS5Padding() throws Exception { try { encryptDecrypt("DESede/CBC/PKCS5Padding"); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/CBC/PKCS5Padding", nsae.getMessage()); return; } else { @@ -136,6 +136,7 @@ public void testDESede_CBC_PKCS5Padding() throws Exception { } } + @Test public void testDESede_CFB_ISO10126Padding() throws Exception { String algorithm = "DESede/CFB/ISO10126Padding"; @@ -144,21 +145,24 @@ public void testDESede_CFB_ISO10126Padding() throws Exception { } try { - cp = Cipher.getInstance(algorithm, providerName); + cp = Cipher.getInstance(algorithm, getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testDESede_CFB_NoPadding() throws Exception { encryptDecrypt("DESede/CFB/NoPadding"); } + @Test public void testDESede_CFB_PKCS5Padding() throws Exception { encryptDecrypt("DESede/CFB/PKCS5Padding"); } + @Test public void testDESede_CFB64_ISO10126Padding() throws Exception { String algorithm = "DESede/CFB64/ISO10126Padding"; @@ -167,76 +171,85 @@ public void testDESede_CFB64_ISO10126Padding() throws Exception { } try { - cp = Cipher.getInstance(algorithm, providerName); + cp = Cipher.getInstance(algorithm, getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testDESede_CFB64_NoPadding() throws Exception { encryptDecrypt("DESede/CFB64/NoPadding"); } + @Test public void testDESede_CFB64_PKCS5Padding() throws Exception { encryptDecrypt("DESede/CFB64/PKCS5Padding"); } + @Test public void testDESede_CTR_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/CTR/ISO10126Padding", providerName); + cp = Cipher.getInstance("DESede/CTR/ISO10126Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testDESede_CTR_NoPadding() throws Exception { try { - cp = Cipher.getInstance("DESede/CTR/NoPadding", providerName); + cp = Cipher.getInstance("DESede/CTR/NoPadding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testDESede_CTR_PKCS5Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/CTR/PKCS5Padding", providerName); + cp = Cipher.getInstance("DESede/CTR/PKCS5Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testDESede_CTS_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/CTS/ISO10126Padding", providerName); + cp = Cipher.getInstance("DESede/CTS/ISO10126Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testDESede_CTS_NoPadding() throws Exception { try { - cp = Cipher.getInstance("DESede/CTS/NoPadding", providerName); + cp = Cipher.getInstance("DESede/CTS/NoPadding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { } } + @Test public void testDESede_CTS_PKCS5Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/CTS/PKCS5Padding", providerName); + cp = Cipher.getInstance("DESede/CTS/PKCS5Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testDESede_ECB_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/ECB/ISO10126Padding", providerName); + cp = Cipher.getInstance("DESede/ECB/ISO10126Padding", getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/ECB/ISO10126Padding", nsae.getMessage()); return; } else { @@ -247,11 +260,12 @@ public void testDESede_ECB_ISO10126Padding() throws Exception { } } + @Test public void testDESede_ECB_NoPadding() throws Exception { try { encryptDecrypt("DESede/ECB/NoPadding", true); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/ECB/NoPadding", nsae.getMessage()); return; } else { @@ -260,11 +274,12 @@ public void testDESede_ECB_NoPadding() throws Exception { } } + @Test public void testDESede_ECB_PKCS5Padding() throws Exception { try { encryptDecrypt("DESede/ECB/PKCS5Padding"); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/ECB/PKCS5Padding", nsae.getMessage()); return; } else { @@ -273,6 +288,7 @@ public void testDESede_ECB_PKCS5Padding() throws Exception { } } + @Test public void testDESede_OFB_ISO10126Padding() throws Exception { String algorithm = "DESede/OFB/ISO10126Padding"; @@ -280,54 +296,60 @@ public void testDESede_OFB_ISO10126Padding() throws Exception { return; } try { - cp = Cipher.getInstance(algorithm, providerName); + cp = Cipher.getInstance(algorithm, getProviderName()); fail(" NoSuchPaddingException is NOT thrown"); } catch (NoSuchPaddingException e) { assertTrue(true); } } + @Test public void testDESede_OFB_NoPadding() throws Exception { encryptDecrypt("DESede/OFB/NoPadding"); } + @Test public void testDESede_OFB_PKCS5Padding() throws Exception { encryptDecrypt("DESede/OFB/PKCS5Padding"); } + @Test public void testDESede_PCBC_ISO10126Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/PCBC/ISO10126Padding", providerName); + cp = Cipher.getInstance("DESede/PCBC/ISO10126Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testDESede_PCBC_NoPadding() throws Exception { try { - cp = Cipher.getInstance("DESede/PCBC/NoPadding", providerName); + cp = Cipher.getInstance("DESede/PCBC/NoPadding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testDESede_PCBC_PKCS5Padding() throws Exception { try { - cp = Cipher.getInstance("DESede/PCBC/PKCS5Padding", providerName); + cp = Cipher.getInstance("DESede/PCBC/PKCS5Padding", getProviderName()); fail(" NoSuchAlgorithmException is NOT thrown"); } catch (NoSuchAlgorithmException e) { assertTrue(true); } } + @Test public void testDESedeShortBuffer() throws Exception { try { // Test DESede Cipher Cipher cp = null; try { - cp = Cipher.getInstance("DESede", encryptProviderName); + cp = Cipher.getInstance("DESede", getProviderName()); } catch (NoSuchAlgorithmException nsae) { if (encryptProviderName.equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede", nsae.getMessage()); @@ -342,7 +364,7 @@ public void testDESedeShortBuffer() throws Exception { byte[] cipherText = cp.doFinal(plainText); params = cp.getParameters(); - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, params); byte[] newPlainText = new byte[5]; cp.doFinal(cipherText, 0, cipherText.length, newPlainText); @@ -353,17 +375,14 @@ public void testDESedeShortBuffer() throws Exception { } } + @Test public void testDESedeIllegalBlockSizeEncrypt() throws Exception { - if (supportsEncrypt == false) { - return; - } - try { Cipher cp = null; try { - cp = Cipher.getInstance("DESede/CBC/NoPadding", providerName); + cp = Cipher.getInstance("DESede/CBC/NoPadding", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/CBC/NoPadding", nsae.getMessage()); return; } else { @@ -385,11 +404,12 @@ public void testDESedeIllegalBlockSizeEncrypt() throws Exception { } } + @Test public void testDESedeIllegalBlockSizeDecrypt() throws Exception { try { Cipher cp = null; try { - cp = Cipher.getInstance("DESede/CBC/PKCS5Padding", encryptProviderName); + cp = Cipher.getInstance("DESede/CBC/PKCS5Padding", getProviderName()); } catch (NoSuchAlgorithmException nsae) { if (encryptProviderName.equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/CBC/PKCS5Padding", nsae.getMessage()); @@ -405,7 +425,7 @@ public void testDESedeIllegalBlockSizeDecrypt() throws Exception { params = cp.getParameters(); // Verify the text - cp = Cipher.getInstance("DESede/CBC/PKCS5Padding", providerName); + cp = Cipher.getInstance("DESede/CBC/PKCS5Padding", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, params); cp.doFinal(cipherText, 0, cipherText.length - 1); @@ -415,19 +435,21 @@ public void testDESedeIllegalBlockSizeDecrypt() throws Exception { } } + @Test public void testDESedeNoSuchAlgorithm() throws Exception { try { - cp = Cipher.getInstance("DESede/BBC/PKCS5Padding", providerName); + cp = Cipher.getInstance("DESede/BBC/PKCS5Padding", getProviderName()); fail("Expected NoSuchAlgorithmException did not occur"); } catch (NoSuchAlgorithmException ex) { assertTrue(true); } } + @Test public void testDESedeNull() throws Exception { Cipher cp = null; try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); } catch (NoSuchAlgorithmException nsae) { if (encryptProviderName.equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede", nsae.getMessage()); @@ -453,12 +475,13 @@ public void testDESedeNull() throws Exception { } } + @Test public void testIllegalParamSpec() throws Exception { Cipher cp = null; try { - cp = Cipher.getInstance("DESede/CBC/PKCS5Padding", providerName); + cp = Cipher.getInstance("DESede/CBC/PKCS5Padding", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede/CBC/PKCS5Padding", nsae.getMessage()); return; } else { @@ -516,10 +539,11 @@ public void testIllegalParamSpec() throws Exception { } } + @Test public void testArgumentsDecrypt() throws Exception { Cipher cp = null; try { - cp = Cipher.getInstance("DESede", encryptProviderName); + cp = Cipher.getInstance("DESede", getProviderName()); } catch (NoSuchAlgorithmException nsae) { if (encryptProviderName.equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede", nsae.getMessage()); @@ -535,35 +559,35 @@ public void testArgumentsDecrypt() throws Exception { params = cp.getParameters(); try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, params); cp.doFinal(null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, params); cp.doFinal(new byte[0]); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, params); cp.doFinal(null, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, params); cp.doFinal(null, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(cipherText); cp.doFinal(new byte[0], 0); @@ -572,7 +596,7 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(new byte[0], 1); fail("Should have gotten exception on doFinal(new byte[0], 1)"); @@ -580,7 +604,7 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(cipherText); cp.doFinal(new byte[cp.getOutputSize(0)], 1); @@ -589,28 +613,28 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(null, 0, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(null, 1, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(null, 0, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(cipherText); cp.doFinal(new byte[0], 0, 0); @@ -619,7 +643,7 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(new byte[0], 1, 0); fail("Did not get expected exception on doFinal(new byte[0], 1, 0)"); @@ -627,7 +651,7 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(new byte[0], 0, 1); fail("Did not get expected exception on doFinal(new byte[0], 0, 1)"); @@ -635,14 +659,14 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(null, 0, 0, null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(cipherText); cp.doFinal(new byte[0], 0, 0, new byte[0]); @@ -651,14 +675,14 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(cipherText); cp.doFinal(new byte[0], 0, 0, new byte[0], 0); @@ -667,14 +691,14 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0]); } catch (Exception e) { @@ -682,28 +706,28 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(null, 0, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(null, 1, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(null, 0, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 0); } catch (Exception e) { @@ -711,79 +735,77 @@ public void testArgumentsDecrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 1, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(null, 0, 0, null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(null, 0, 0, new byte[0]); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 0, null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.DECRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { } } + @Test public void testArgumentsEncrypt() throws Exception { - if (supportsEncrypt == false) { - return; - } Cipher cp = null; try { try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: DESede", nsae.getMessage()); return; } else { @@ -796,7 +818,7 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0]); } catch (Exception e) { @@ -804,21 +826,21 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0)"); @@ -826,7 +848,7 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1); fail("Should have gotten exception on doFinal(new byte[0], 1)"); @@ -834,7 +856,7 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[cp.getOutputSize(0)], 1); fail("Expected ShortBufferException"); @@ -842,28 +864,28 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 1, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0); } catch (Exception e) { @@ -871,7 +893,7 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 1, 0); fail("Did not get expected exception on doFinal(new byte[0], 1, 0)"); @@ -879,7 +901,7 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 1); fail("Did not get expected exception on doFinal(new byte[0], 0, 1)"); @@ -887,14 +909,14 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(null, 0, 0, null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0]); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0, 9, new byte[0])"); @@ -902,14 +924,14 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.doFinal(new byte[0], 0, 0, new byte[0], 0); fail("Did not get expected ShortBufferException on doFinal(new byte[0], 0, 0, new byte[0], 0)"); @@ -917,14 +939,14 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0]); } catch (Exception e) { @@ -932,28 +954,28 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 1, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0); } catch (Exception e) { @@ -961,63 +983,63 @@ public void testArgumentsEncrypt() throws Exception { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 1, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(null, 0, 0, new byte[0]); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0]); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 0); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, null, 1); } catch (Exception e) { } try { - cp = Cipher.getInstance("DESede", providerName); + cp = Cipher.getInstance("DESede", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key); cp.update(new byte[0], 0, 0, new byte[0], 0); } catch (Exception e) { @@ -1073,7 +1095,7 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult return; } - Cipher cp = Cipher.getInstance(algorithm, encryptProviderName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1092,8 +1114,8 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult } // Verify the text - if (providerName.equals(encryptProviderName) == false) { - cp = Cipher.getInstance(algorithm, providerName); + if (getProviderName().equals(encryptProviderName) == false) { + cp = Cipher.getInstance(algorithm, getProviderName()); } cp.init(Cipher.DECRYPT_MODE, key, params); byte[] newPlainText = cp.doFinal(cipherText); @@ -1123,7 +1145,7 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti if (isTransformationValidButUnsupported(algorithm)) { return; } - Cipher cp = Cipher.getInstance(algorithm, encryptProviderName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1143,8 +1165,8 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti } // Verify the text - if (providerName.equals(encryptProviderName) == false) { - cp = Cipher.getInstance(algorithm, providerName); + if (getProviderName().equals(encryptProviderName) == false) { + cp = Cipher.getInstance(algorithm, getProviderName()); } cp.init(Cipher.DECRYPT_MODE, key, params); byte[] newPlainText1 = (cipherText1 == null) ? new byte[0] : cp.update(cipherText1); @@ -1177,7 +1199,7 @@ protected void encryptDecryptPartialUpdate(String algorithm, if (isTransformationValidButUnsupported(algorithm)) { return; } - Cipher cp = Cipher.getInstance(algorithm, encryptProviderName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1198,8 +1220,8 @@ protected void encryptDecryptPartialUpdate(String algorithm, } // Verify the text - if (providerName.equals(encryptProviderName) == false) { - cp = Cipher.getInstance(algorithm, providerName); + if (getProviderName().equals(encryptProviderName) == false) { + cp = Cipher.getInstance(algorithm, getProviderName()); } cp.init(Cipher.DECRYPT_MODE, key, params); byte[] newPlainText1 = (cipherText1 == null) ? new byte[0] : cp.update(cipherText1); @@ -1236,7 +1258,7 @@ protected void encryptDecryptReuseObject(String algorithm, return; } - Cipher cp = Cipher.getInstance(algorithm, encryptProviderName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1261,8 +1283,8 @@ protected void encryptDecryptReuseObject(String algorithm, assertTrue("Re-encrypted text does not match", success); // Verify the text - if (providerName.equals(encryptProviderName) == false) { - cp = Cipher.getInstance(algorithm, providerName); + if (getProviderName().equals(encryptProviderName) == false) { + cp = Cipher.getInstance(algorithm, getProviderName()); } cp.init(Cipher.DECRYPT_MODE, key, params); byte[] newPlainText = cp.doFinal(cipherText); @@ -1294,7 +1316,7 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm, return; } - Cipher cp = Cipher.getInstance(algorithm, encryptProviderName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1320,8 +1342,8 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm, assertTrue("Encrypted text does not match expected result", success); // Verify the text - if (providerName.equals(encryptProviderName) == false) { - cp = Cipher.getInstance(algorithm, providerName); + if (getProviderName().equals(encryptProviderName) == false) { + cp = Cipher.getInstance(algorithm, getProviderName()); } cp.init(Cipher.DECRYPT_MODE, key, params); resultBuffer = Arrays.copyOf(cipherText, cp.getOutputSize(cipherText.length)); @@ -1351,7 +1373,7 @@ protected void encryptDecryptUpdateCopySafe(String algorithm, return; } - Cipher cp = Cipher.getInstance(algorithm, encryptProviderName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -1381,8 +1403,8 @@ protected void encryptDecryptUpdateCopySafe(String algorithm, assertTrue("Encrypted text does not match expected result", success); // Verify the text - if (providerName.equals(encryptProviderName) == false) { - cp = Cipher.getInstance(algorithm, providerName); + if (getProviderName().equals(encryptProviderName) == false) { + cp = Cipher.getInstance(algorithm, getProviderName()); } cp.init(Cipher.DECRYPT_MODE, key, params); resultBuffer = Arrays.copyOf(cipherText, cp.getOutputSize(cipherText.length)); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDH.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDH.java index 39f2da47..03db992a 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDH.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDH.java @@ -19,27 +19,43 @@ import java.util.Arrays; import javax.crypto.KeyAgreement; import javax.crypto.spec.DHParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestDH extends BaseTest { +public class BaseTestDH extends BaseTestJunit5 { static final byte[] origMsg = "this is the original message to be signed".getBytes(); - static DHParameterSpec algParameterSpec_1024, algParameterSpec_2048, algParameterSpec_3072, + DHParameterSpec algParameterSpec_1024, algParameterSpec_2048, algParameterSpec_3072, algParameterSpec_4096, algParameterSpec_6144, algParameterSpec_8192; - static KeyPairGenerator kpgA = null; - static KeyPairGenerator kpgB = null; + KeyPairGenerator kpgA = null; + KeyPairGenerator kpgB = null; - static KeyPair keyPairA_1024, keyPairA_2048, keyPairA_3072, keyPairA_4096, keyPairA_6144, + KeyPair keyPairA_1024, keyPairA_2048, keyPairA_3072, keyPairA_4096, keyPairA_6144, keyPairA_8192; - static KeyPair keyPairB_1024, keyPairB_2048, keyPairB_3072, keyPairB_4096, keyPairB_6144, + KeyPair keyPairB_1024, keyPairB_2048, keyPairB_3072, keyPairB_4096, keyPairB_6144, keyPairB_8192; - public boolean isMulti = false; - static String myProviderName = null; - static boolean generated = false; + private boolean isMulti = false; - synchronized static void generateParameters(String provider_name) { + @BeforeEach + public void setUp() throws Exception { + generateParameters(getProviderName()); + } + + public boolean isMulti() { + return isMulti; + } + + public void setMulti(boolean isMulti) { + this.isMulti = isMulti; + } + + boolean generated = false; + + synchronized void generateParameters(String provider_name) { if (generated) return; try { @@ -97,34 +113,25 @@ synchronized static void generateParameters(String provider_name) { } } - public BaseTestDH(String providerName) { - super(providerName); - myProviderName = providerName; - generateParameters(providerName); - } - - public void setUp() throws Exception {} - - public void tearDown() throws Exception {} - /** * Basic DH example * * @throws Exception */ - + @Test public void testDHKeyPairGeneratorGetAlgorithm() throws Exception { String algorithms[] = {"DiffieHellman", "DH", "1.2.840.113549.1.3.1", "OID.1.2.840.113549.1.3.1"}; for (int i = 0; i < algorithms.length; i++) { - assertTrue(KeyPairGenerator.getInstance(algorithms[i], providerName).getAlgorithm() + assertTrue(KeyPairGenerator.getInstance(algorithms[i], getProviderName()).getAlgorithm() .equals(algorithms[i])); } } + @Test public void testDH_1024() throws Exception { - if (!providerName.equals("OpenJCEPlusFIPS")) { + if (!getProviderName().equals("OpenJCEPlusFIPS")) { DHParameterSpec dhps = generateDHParameters(1024); compute_dh_key("1024", dhps); @@ -135,6 +142,7 @@ public void testDH_1024() throws Exception { } } + @Test public void testDH_2048() throws Exception { //System.out.println ("Testing DH 2048"); @@ -145,6 +153,7 @@ public void testDH_2048() throws Exception { } + @Test public void testDH_3072() throws Exception { //System.out.println ("Testing DH 3072"); @@ -155,6 +164,7 @@ public void testDH_3072() throws Exception { } + @Test public void testDH_4096() throws Exception { //System.out.println ("Testing DH 4096"); @@ -165,6 +175,7 @@ public void testDH_4096() throws Exception { } + @Test public void testDH_6144() throws Exception { //System.out.println ("Testing DH 6144"); @@ -175,6 +186,7 @@ public void testDH_6144() throws Exception { } + @Test public void testDH_8192() throws Exception { //System.out.println ("Testing DH 8192"); @@ -185,11 +197,12 @@ public void testDH_8192() throws Exception { } + @Test public void testDH_DHSpec() throws Exception { String methodId = "DHParamSpec"; - if (!providerName.equals("OpenJCEPlusFIPS")) { + if (!getProviderName().equals("OpenJCEPlusFIPS")) { DHParameterSpec dhParamSpec = generateDHParameters(1024); compute_dh_key(methodId, dhParamSpec); @@ -206,7 +219,7 @@ void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec) KeyPairGenerator kpgA = null; try { - kpgA = KeyPairGenerator.getInstance("DH", providerName); + kpgA = KeyPairGenerator.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -228,7 +241,7 @@ void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec) // set up KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("DH", providerName); + keyAgreeA = KeyAgreement.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -246,7 +259,7 @@ void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec) KeyPairGenerator kpgB = null; try { - kpgB = KeyPairGenerator.getInstance("DH", providerName); + kpgB = KeyPairGenerator.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -269,7 +282,7 @@ void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec) KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("DH", providerName); + keyAgreeB = KeyAgreement.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -333,7 +346,7 @@ void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec) private DHParameterSpec generateDHParameters(int size) throws Exception { AlgorithmParameterGenerator algParamGen = AlgorithmParameterGenerator.getInstance("DH", - providerName); + getProviderName()); algParamGen.init(size); AlgorithmParameters algParams = algParamGen.generateParameters(); DHParameterSpec dhps = algParams.getParameterSpec(DHParameterSpec.class); @@ -382,7 +395,7 @@ void compute_dh_key_with_global_key(String idString, AlgorithmParameterSpec algP // set up A KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("DH", providerName); + keyAgreeA = KeyAgreement.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -400,7 +413,7 @@ void compute_dh_key_with_global_key(String idString, AlgorithmParameterSpec algP // set up B KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("DH", providerName); + keyAgreeB = KeyAgreement.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -459,9 +472,9 @@ void compute_dh_key_with_global_key(String idString, AlgorithmParameterSpec algP } - static private DHParameterSpec generateDHParameters_static(int size) throws Exception { + private DHParameterSpec generateDHParameters_static(int size) throws Exception { AlgorithmParameterGenerator algParamGen = AlgorithmParameterGenerator.getInstance("DH", - myProviderName); + getProviderName()); algParamGen.init(size); AlgorithmParameters algParams = algParamGen.generateParameters(); DHParameterSpec dhps = algParams.getParameterSpec(DHParameterSpec.class); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDHInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDHInterop.java index 063891c0..3368e109 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDHInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDHInterop.java @@ -19,81 +19,45 @@ import java.util.Arrays; import javax.crypto.KeyAgreement; import javax.crypto.spec.DHParameterSpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +public class BaseTestDHInterop extends BaseTestJunit5Interop { -public class BaseTestDHInterop extends BaseTestInterop { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - private int keySize = 1024; - // -------------------------------------------------------------------------- - // - // - public BaseTestDHInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public BaseTestDHInterop(String providerName, String interopProviderName, int size) { - super(providerName, interopProviderName); - this.keySize = size; - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // /** * Basic ECDH example * * @throws Exception */ - + @Test public void testDH() throws Exception { - String idString = (Integer.valueOf(this.keySize)).toString(); - - DHParameterSpec dhps = generateDHParameters(this.keySize); - - compute_dh_key_interop(idString, dhps, providerName, interopProviderName); - compute_dh_key_interop(idString, dhps, interopProviderName, providerName); - + String idString = (Integer.valueOf(getKeySize())).toString(); + DHParameterSpec dhps = generateDHParameters(getKeySize()); + compute_dh_key_interop(idString, dhps, getProviderName(), getInteropProviderName()); + compute_dh_key_interop(idString, dhps, getInteropProviderName(), getProviderName()); } - - + @Test public void testDH_DHSpec() throws Exception { String methodId = "DHParamSpec"; - DHParameterSpec dhParamSpec = generateDHParameters(this.keySize); - - compute_dh_key_interop(methodId, dhParamSpec, providerName, interopProviderName); - compute_dh_key_interop(methodId, dhParamSpec, interopProviderName, providerName); + DHParameterSpec dhParamSpec = generateDHParameters(getKeySize()); + compute_dh_key_interop(methodId, dhParamSpec, getProviderName(), getInteropProviderName()); + compute_dh_key_interop(methodId, dhParamSpec, getInteropProviderName(), getProviderName()); } void compute_dh_key_interop(String idString, AlgorithmParameterSpec algParameterSpec, String providerA, String providerB) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { compute_dh_key(idString, algParameterSpec, providerA, providerB); - } void compute_dh_key_interop_sameKeyPairGenerator(String idString, @@ -101,7 +65,6 @@ void compute_dh_key_interop_sameKeyPairGenerator(String idString, throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException { compute_dh_key_sameKeyPairGenerator(idString, algParameterSpec, providerA, providerB); - } void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec, String providerA, @@ -239,7 +202,6 @@ void compute_dh_key(String idString, AlgorithmParameterSpec algParameterSpec, St } assertTrue(assertFlag); - } void compute_dh_key_sameKeyPairGenerator(String idString, @@ -353,24 +315,16 @@ void compute_dh_key_sameKeyPairGenerator(String idString, "KeyPairB.privKey=" + BaseUtils.bytesToHex(keyPairB.getPrivate().getEncoded())); System.out.println("KeyPairB.publicKey=" + BaseUtils.bytesToHex(keyPairB.getPublic().getEncoded())); - } assertTrue(assertFlag); - - } - private DHParameterSpec generateDHParameters(int size) throws Exception { - AlgorithmParameterGenerator algParamGen = AlgorithmParameterGenerator.getInstance("DH", - providerName); + getProviderName()); algParamGen.init(size); AlgorithmParameters algParams = algParamGen.generateParameters(); DHParameterSpec dhps = algParams.getParameterSpec(DHParameterSpec.class); return dhps; - } - - } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyFactory.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyFactory.java index b5d531fd..c605056e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -21,73 +21,62 @@ import javax.crypto.interfaces.DHPublicKey; import javax.crypto.spec.DHParameterSpec; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; -public class BaseTestDHKeyFactory extends BaseTestInterop { - - // -------------------------------------------------------------------------- - // - // - public BaseTestDHKeyFactory(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} +public class BaseTestDHKeyFactory extends BaseTestJunit5Interop { + @Test public void testDHKeyFactory() throws Exception { - test_dh_keyFactory(interopProviderName, interopProviderName); - test_dh_keyFactory(providerName, providerName); - if (providerName.equals("OpenJCEPlusFIPS") - || interopProviderName.equals("OpenJCEPlusFIPS")) { + test_dh_keyFactory(getInteropProviderName(), getInteropProviderName()); + test_dh_keyFactory(getProviderName(), getProviderName()); + if (getProviderName().equals("OpenJCEPlusFIPS") + || getInteropProviderName().equals("OpenJCEPlusFIPS")) { // OpenJCEPlusFIPS will not work with the static DHParams from IBMJCE. They are no longer FIPS usable. - if (providerName.equals("OpenJCEPlusFIPS")) { - test_dh_keyFactory(providerName, interopProviderName); + if (getProviderName().equals("OpenJCEPlusFIPS")) { + test_dh_keyFactory(getProviderName(), getInteropProviderName()); } else { - test_dh_keyFactory(interopProviderName, providerName); + test_dh_keyFactory(getInteropProviderName(), getProviderName()); } } else { - test_dh_keyFactory(providerName, interopProviderName); - test_dh_keyFactory(interopProviderName, providerName); + test_dh_keyFactory(getProviderName(), getInteropProviderName()); + test_dh_keyFactory(getInteropProviderName(), getProviderName()); } } + @Test public void testDHShortSecret1() throws Exception { - test_dh_short_secret(providerName, providerName); - test_dh_short_secret(interopProviderName, interopProviderName); - test_dh_short_secret(providerName, interopProviderName); - test_dh_short_secret(interopProviderName, providerName); + test_dh_short_secret(getProviderName(), getProviderName()); + test_dh_short_secret(getInteropProviderName(), getInteropProviderName()); + test_dh_short_secret(getProviderName(), getInteropProviderName()); + test_dh_short_secret(getInteropProviderName(), getProviderName()); } - + @Test public void testDHShortSecret2a() throws Exception { - test_dh_short_secret2ndmethod(providerName, providerName); + test_dh_short_secret2ndmethod(getProviderName(), getProviderName()); } + @Test public void testDHShortSecret2b() throws Exception { - test_dh_short_secret2ndmethod(interopProviderName, interopProviderName); + test_dh_short_secret2ndmethod(getInteropProviderName(), getInteropProviderName()); } + @Test public void testDHShortSecret2c() throws Exception { - test_dh_short_secret2ndmethod(providerName, interopProviderName); + test_dh_short_secret2ndmethod(getProviderName(), getInteropProviderName()); } + @Test public void testDHShortSecret2d() throws Exception { - test_dh_short_secret2ndmethod(interopProviderName, providerName); + test_dh_short_secret2ndmethod(getInteropProviderName(), getProviderName()); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyPairGenerator.java index 8026e59c..597853e2 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,25 +16,114 @@ import javax.crypto.interfaces.DHPrivateKey; import javax.crypto.interfaces.DHPublicKey; import javax.crypto.spec.DHParameterSpec; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import sun.security.util.KeyUtil; - -public class BaseTestDHKeyPairGenerator extends BaseTest { - - private static BigInteger p_1024; - private static BigInteger g_1024; - private static BigInteger p_2048; - private static BigInteger g_2048; - private static BigInteger p_3072; - private static BigInteger g_3072; - private static BigInteger p_4096; - private static BigInteger g_4096; - private static BigInteger p_6144; - private static BigInteger g_6144; - private static BigInteger p_8192; - private static BigInteger g_8192; - +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class BaseTestDHKeyPairGenerator extends BaseTestJunit5 { + + private static final BigInteger p_1024 = new BigInteger( + "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7", + 16); + + private static final BigInteger g_1024 = new BigInteger( + "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a", + 16); + + private static final BigInteger p_2048 = new BigInteger( + "24411209893452987982292764298214666563244502108061332429386640762028613944128160958895651358369340617913723942648980595662900397364654037992477306346975555070731906211991330607572500092846972550669206248817906971178489109618091786420639402573006669894740449806296627656350692199924647254064170619723090086490863047112010159257790253286951285397621794370492477371659895119712649029073020971899481274886979229883486313718228936740160705239157339084673807557507596909526771665732158004755500890957481963807104507454286192846294557895603003106614304345189884618591002156946923803100585097553740787441936978505629483919483"); + + private static BigInteger g_2048 = new BigInteger("2"); + + private static BigInteger p_3072 = new BigInteger( + "3984726680996695938962530783543770621997197473797019619492946402463918417974497449270696748883559745014593242225907774697640386789896248706335921624183539227205861406166856041746789956216934423396757374206025238856202293838352862734099515200718875434405427369719603585129497078302914334772902691929376427249954866774998298703463206134964046896733427732673256972486928489840823651681900010770058336600542645764047577763395592081876921743345250127718495033142581430701445402164649747669576965600224735364308288544169046144177941654736483051957076428125812797541358982286057794581533902184510411947880873120004751553586672451616979739170365048511131190463723874572607671672034164712408726027133496561307635238731744151197657342092428256720849422853680865099763220950179379320414708442398940768246727677052983689792890777633870538229105994448668684028184541713919676808045449847221960856377983311349436917256827988839394245521963"); + + private static BigInteger g_3072 = new BigInteger("2"); + private static BigInteger p_4096 = new BigInteger("00bffcbc796f5f5abc038bd0f5425b" + "434c9c841b61aeada4babb733fed0f" + + "4862c892f9eb0d18f63c6543b0dd90" + "53be2067414803e5f88ff10b2af5ae" + + "7a3a91b888a918f32699af4d5649fb" + "11056954620bd3eac082c975934368" + + "6f51ffebadc5ed6f01bfe3ad17418a" + "a167b8ce539bd8793b8cbce1b552ce" + + "1c19067fd79f3ca6ec43ded82da84f" + "06dc26baac741f74518ca7bde76c5e" + + "9767bbfd2548cf90ca7e928905c8df" + "1a15462d58ba539f1d37050ef77559" + + "5226ddb42aa900481560e4419c0719" + "b73927417d7c1f9db30edb1421a77c" + + "b4e8b46e7d8fb40df64efbb29e7fb0" + "ef163a59cf33b8a9e21979cc383842" + + "2057a46e64679e48edafcd014dd464" + "4abd26350bb6cc35daea22d43e70ef" + + "6564630f2cfd9261bd64c346afb3e0" + "8533b67c5702d9edb14cd695bd490e" + + "f4db1fce0fabaa78b8f0248b44098f" + "f1bf21b4ade769bbe25e8a39eb0ea9" + + "b974e3630af226807efce8dce15353" + "d79bdb30656585dd556778e27cbdc1" + + "d1f60c33560e4c80ff39249c6bcc16" + "675fc6a1c228821e45bbb1b0fcaa98" + + "c8f84b6340bfa9282c03bc66566fa3" + "8e82d8fee481f02ea5b5f5742f8aca" + + "4aa4aad1ade687dbded4ec0dfa6856" + "7bcc4dbe009e4384b7762d38cbcf07" + + "36626dcac6b27470642225c4414966" + "24de3d44edf55ae7dc58c30aded35e" + + "dcc4eff89494948f20946a2f0dddcd" + "c0edf952e63a6c7597b8a2627c7054" + "ae644b", + 16); + private static BigInteger g_4096 = new BigInteger("5", 16); + private static BigInteger p_6144 = new BigInteger("00ee44c7210997bc150de5179bdd70" + "11f9cb032d8c2d6ffda5d45f9e7166" + + "004aa8d30581405454c7cbb84ba39b" + "864513c1c388b89956d3191613036b" + + "825620d5048c53f09374cd00484c07" + "41871961998169d1d7b87f11714d84" + + "222649e1d7f5c1e9a1c98313958dc6" + "9cf3a0197c71369e0193c62b70c526" + + "22e01e6c1d14f054de505910cbe594" + "0d69698dfd08afad4b2c3da06d5e06" + + "8f1d96e29d17f6ada88f5339783648" + "bd43ca19edf33a59d3bfaa47743372" + + "b315c858da5c5c4a4015fbac013b1c" + "f250812a35c80676ac289435659cb3" + + "f8f7e7380e86e634303977c5ac331e" + "390798043e25921890e5b10b9c7a82" + + "020b7b5a29a7105c1640e3f635ed01" + "aed002f6d6d6258ce874dbeaf8129d" + + "dd50086607f54d552e3c9da4a935c6" + "b715776c0b97cc8e249546bcd39110" + + "49877f5521d78cddb177819c96f529" + "61129ed5c6d948f68a14aa68231b11" + + "aaedea491e42f17986f4524273193e" + "d68c03d3c5b7f83ccfc28eb3f0bc88" + + "7df84a02dbb0e847ec52558b72c293" + "27010440859026a6c7de02a309edcb" + + "dfc452c7167c3af97974a59e4e279f" + "bf23e6378eb476d0588c48f69431a9" + + "339b4eba9df0725c7fec44ee0cea71" + "d0143246f982721a4aba325a7da1e9" + + "85f888a43243582c6bc0707c0ff950" + "20a72f177a5207d59d7cc15f430f38" + + "ec45f6ac502d7a81ab016cc6128a3d" + "3c7bc9ad830f60529eb2aee98b58e1" + + "f2a913d63339b818fcb5e325cc90ba" + "fa51cf73e3137a59aaec368dc69bc3" + + "302acac0351ebf39e14d93e97353ac" + "f808a87121a088e2c97f85c4aa5d61" + + "ab6d4e33f7f88ec8b4ea4fbb9158a8" + "48142f105357b72869174e3de18bcb" + + "9dd368ce988a0092ca93821a3bdf87" + "fad0761de3f5f3d2e349a67c6fe85a" + + "89681300c4ee2d8b21f8bf2b426f9c" + "31dde2348c5bcef0a5008fcdb4c234" + + "363e3c91e506e574e5fc35474ae749" + "0ea304020ea96732aa9d2b6c668728" + + "318a836ad53e30426968a0245fdcd8" + "a797ed7a3e48b4976c580c379b1d9e" + + "d7155ed864200877667f3e81c0e3e0" + "97038d27a12d71671e8b04689a4ec7" + + "6eabfe4e8607a2575d1bd3d1cb4fd7" + "7e3d4b8b", 16); + private static BigInteger g_6144 = new BigInteger("5", 16); + private static BigInteger p_8192 = new BigInteger("00c164c46dbb0596c77938a260999a" + "bfec25cc6368e789f1483891784d35" + + "09707426319aa5c5d66361a29f4cb0" + "cf8abaf32c81f08b3edf1d599ca15d" + + "4a11d95cedaa7ec3b9677bc28ef9aa" + "86d6b9a5d7f425d0d5243ba2afb67a" + + "c94a1007729d9e053d41c7ef5e0e4c" + "ec815c1a98a0ed5860f0b99dea9d40" + + "9afb4825f58b54e5865ae17c6e20de" + "5e2d9b45bc916ebaba157a0f5b6ddb" + + "e5aca5e9461f42afc7001bd73d2933" + "cff1e6efed2265ecbe16c5586dc7e4" + + "db9fe5d760047b1bcee97ca7b06e58" + "46ee5f197fa862a53dd05565903fc6" + + "2ea87156a9cefafabbeacc13e017c6" + "a71097379d3ed83e56d45b17221455" + + "a6e11ad3e8e1032d87d572471c93ad" + "504d67ffd55ea4586b966b7389cc8b" + + "16e535e6ca822244fb293cc7100627" + "67bf19607c46dde5926b0100c479fc" + + "5731177a309d84a46d8dabc50d5b8a" + "3c26f1316edb6cbddc28acb2f25560" + + "1f292b5f6bb2dc5e3f4a9b7cc44a93" + "dbd775b4559eea91c89ca232e60590" + + "c5b54c1bcc9037542f38ef0c1109fd" + "c6a684f64cb958b9fba757a1717d03" + + "40dec22dc8b77ee853d2272ddbf7c9" + "dfe11a776d20bf117c7eab2bf0ec7b" + + "f208f1ad359c0eb85658796471f863" + "1584fc3f68f647a1064aa4dafa08f9" + + "754739840bc6ba016544c963fda63d" + "97b8a0b50c30bfccf2180bf18a4cbe" + + "708cae982f2fbcb39341a7f2f90aa0" + "2fceb0c795393a2e9eadb54a206db6" + + "862442627a17897c30ac2e33a6135e" + "6816f2aed8e692ed4b5012d8f4e696" + + "916f2c82c1719190c284146b6c794d" + "a617c52da1a63a303c5dfa8afa93e4" + + "beaadab0b121be4812e5b5ffbae09c" + "1c8ffde32707908aa7b7361cd76d9e" + + "aaf095fb91e5b2300f2e87eaa71c49" + "1ca25d3cfdcd259e60ffceca650aa5" + + "41aec8fac6dc5d05d9c3189ec59e27" + "292e02d4a67aba7e895a110e0fb62e" + + "cfee6492cb5e9bd4fe579abfdcd5a0" + "c5da48d93213e7002579922741ab2b" + + "283b459fd949da212b723392a3e1dd" + "b62ae23d42d9c6a49d7fe84046e3f5" + + "b808a900bb8e52f358823e9eec31fc" + "986ee2ad8b0bdf4234a818e1dbad0b" + + "95d38b0789340b531f403580435659" + "6f1c386c6853b78cbf7f7d745013b9" + + "07e5c24af35b81b69c5cdc674a06e1" + "ac3a728e09b00a9ac9e788ace68b6a" + + "4a556598e410666bc29357188faeb3" + "8be56e5691c17ab72163910fe7f9d0" + + "1f8c8468bdf6ba9845a2873b0339c1" + "855263a59abded562b1f40efd49b81" + + "fac9d7f5054be04e51ca0055ff1360" + "f6dc66b8886b5f9b2389e36b9213aa" + + "01e33cba2ac337592b986a436d0e05" + "58521c1d6e9a173bf66c4742bc8ba5" + + "91390032f5a3e9a0a25b5035c0f0f9" + "94869436b37853bf8400a1f435b61a" + + "ba3be39c3c6b2936aff805a2fe0797" + "16fd71be634f8ff90018a68b5aaeb8" + + "2d6cfe1bb6f0e577e38d3364ea0aa8" + "a1ad165aa95c6de0d4a079eda2898a" + + "9cd76f45e3", 16); + private static BigInteger g_8192 = new BigInteger("5", 16); KeyPairGenerator kpg = null; DHParameterSpec dhParams_1024 = null; @@ -46,144 +135,10 @@ public class BaseTestDHKeyPairGenerator extends BaseTest { public static final String PROVIDER_OPENJCEPlus = "OpenJCEPlus"; public static final String PROVIDER_OPENJCEPlusFIPS = "OpenJCEPlusFIPS"; - //-------------------------------------------------------------------------- - // - // - static { - // p,q,g, 1024 - p_1024 = new BigInteger( - "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7", - 16); - - g_1024 = new BigInteger( - "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a", - 16); - - // p,q,g, 2048 - p_2048 = new BigInteger( - "24411209893452987982292764298214666563244502108061332429386640762028613944128160958895651358369340617913723942648980595662900397364654037992477306346975555070731906211991330607572500092846972550669206248817906971178489109618091786420639402573006669894740449806296627656350692199924647254064170619723090086490863047112010159257790253286951285397621794370492477371659895119712649029073020971899481274886979229883486313718228936740160705239157339084673807557507596909526771665732158004755500890957481963807104507454286192846294557895603003106614304345189884618591002156946923803100585097553740787441936978505629483919483"); - - - g_2048 = new BigInteger("2"); - - // p,g, 3072 - p_3072 = new BigInteger( - "3984726680996695938962530783543770621997197473797019619492946402463918417974497449270696748883559745014593242225907774697640386789896248706335921624183539227205861406166856041746789956216934423396757374206025238856202293838352862734099515200718875434405427369719603585129497078302914334772902691929376427249954866774998298703463206134964046896733427732673256972486928489840823651681900010770058336600542645764047577763395592081876921743345250127718495033142581430701445402164649747669576965600224735364308288544169046144177941654736483051957076428125812797541358982286057794581533902184510411947880873120004751553586672451616979739170365048511131190463723874572607671672034164712408726027133496561307635238731744151197657342092428256720849422853680865099763220950179379320414708442398940768246727677052983689792890777633870538229105994448668684028184541713919676808045449847221960856377983311349436917256827988839394245521963"); - - g_3072 = new BigInteger("2"); - - // p,g, 4096 - - - - p_4096 = new BigInteger("00bffcbc796f5f5abc038bd0f5425b" + "434c9c841b61aeada4babb733fed0f" - + "4862c892f9eb0d18f63c6543b0dd90" + "53be2067414803e5f88ff10b2af5ae" - + "7a3a91b888a918f32699af4d5649fb" + "11056954620bd3eac082c975934368" - + "6f51ffebadc5ed6f01bfe3ad17418a" + "a167b8ce539bd8793b8cbce1b552ce" - + "1c19067fd79f3ca6ec43ded82da84f" + "06dc26baac741f74518ca7bde76c5e" - + "9767bbfd2548cf90ca7e928905c8df" + "1a15462d58ba539f1d37050ef77559" - + "5226ddb42aa900481560e4419c0719" + "b73927417d7c1f9db30edb1421a77c" - + "b4e8b46e7d8fb40df64efbb29e7fb0" + "ef163a59cf33b8a9e21979cc383842" - + "2057a46e64679e48edafcd014dd464" + "4abd26350bb6cc35daea22d43e70ef" - + "6564630f2cfd9261bd64c346afb3e0" + "8533b67c5702d9edb14cd695bd490e" - + "f4db1fce0fabaa78b8f0248b44098f" + "f1bf21b4ade769bbe25e8a39eb0ea9" - + "b974e3630af226807efce8dce15353" + "d79bdb30656585dd556778e27cbdc1" - + "d1f60c33560e4c80ff39249c6bcc16" + "675fc6a1c228821e45bbb1b0fcaa98" - + "c8f84b6340bfa9282c03bc66566fa3" + "8e82d8fee481f02ea5b5f5742f8aca" - + "4aa4aad1ade687dbded4ec0dfa6856" + "7bcc4dbe009e4384b7762d38cbcf07" - + "36626dcac6b27470642225c4414966" + "24de3d44edf55ae7dc58c30aded35e" - + "dcc4eff89494948f20946a2f0dddcd" + "c0edf952e63a6c7597b8a2627c7054" + "ae644b", - 16); - g_4096 = new BigInteger("5", 16); - - - // p,g, 6144 - p_6144 = new BigInteger("00ee44c7210997bc150de5179bdd70" + "11f9cb032d8c2d6ffda5d45f9e7166" - + "004aa8d30581405454c7cbb84ba39b" + "864513c1c388b89956d3191613036b" - + "825620d5048c53f09374cd00484c07" + "41871961998169d1d7b87f11714d84" - + "222649e1d7f5c1e9a1c98313958dc6" + "9cf3a0197c71369e0193c62b70c526" - + "22e01e6c1d14f054de505910cbe594" + "0d69698dfd08afad4b2c3da06d5e06" - + "8f1d96e29d17f6ada88f5339783648" + "bd43ca19edf33a59d3bfaa47743372" - + "b315c858da5c5c4a4015fbac013b1c" + "f250812a35c80676ac289435659cb3" - + "f8f7e7380e86e634303977c5ac331e" + "390798043e25921890e5b10b9c7a82" - + "020b7b5a29a7105c1640e3f635ed01" + "aed002f6d6d6258ce874dbeaf8129d" - + "dd50086607f54d552e3c9da4a935c6" + "b715776c0b97cc8e249546bcd39110" - + "49877f5521d78cddb177819c96f529" + "61129ed5c6d948f68a14aa68231b11" - + "aaedea491e42f17986f4524273193e" + "d68c03d3c5b7f83ccfc28eb3f0bc88" - + "7df84a02dbb0e847ec52558b72c293" + "27010440859026a6c7de02a309edcb" - + "dfc452c7167c3af97974a59e4e279f" + "bf23e6378eb476d0588c48f69431a9" - + "339b4eba9df0725c7fec44ee0cea71" + "d0143246f982721a4aba325a7da1e9" - + "85f888a43243582c6bc0707c0ff950" + "20a72f177a5207d59d7cc15f430f38" - + "ec45f6ac502d7a81ab016cc6128a3d" + "3c7bc9ad830f60529eb2aee98b58e1" - + "f2a913d63339b818fcb5e325cc90ba" + "fa51cf73e3137a59aaec368dc69bc3" - + "302acac0351ebf39e14d93e97353ac" + "f808a87121a088e2c97f85c4aa5d61" - + "ab6d4e33f7f88ec8b4ea4fbb9158a8" + "48142f105357b72869174e3de18bcb" - + "9dd368ce988a0092ca93821a3bdf87" + "fad0761de3f5f3d2e349a67c6fe85a" - + "89681300c4ee2d8b21f8bf2b426f9c" + "31dde2348c5bcef0a5008fcdb4c234" - + "363e3c91e506e574e5fc35474ae749" + "0ea304020ea96732aa9d2b6c668728" - + "318a836ad53e30426968a0245fdcd8" + "a797ed7a3e48b4976c580c379b1d9e" - + "d7155ed864200877667f3e81c0e3e0" + "97038d27a12d71671e8b04689a4ec7" - + "6eabfe4e8607a2575d1bd3d1cb4fd7" + "7e3d4b8b", 16); - - g_6144 = new BigInteger("5", 16); - - - // p,g, 8192 - - - - p_8192 = new BigInteger("00c164c46dbb0596c77938a260999a" + "bfec25cc6368e789f1483891784d35" - + "09707426319aa5c5d66361a29f4cb0" + "cf8abaf32c81f08b3edf1d599ca15d" - + "4a11d95cedaa7ec3b9677bc28ef9aa" + "86d6b9a5d7f425d0d5243ba2afb67a" - + "c94a1007729d9e053d41c7ef5e0e4c" + "ec815c1a98a0ed5860f0b99dea9d40" - + "9afb4825f58b54e5865ae17c6e20de" + "5e2d9b45bc916ebaba157a0f5b6ddb" - + "e5aca5e9461f42afc7001bd73d2933" + "cff1e6efed2265ecbe16c5586dc7e4" - + "db9fe5d760047b1bcee97ca7b06e58" + "46ee5f197fa862a53dd05565903fc6" - + "2ea87156a9cefafabbeacc13e017c6" + "a71097379d3ed83e56d45b17221455" - + "a6e11ad3e8e1032d87d572471c93ad" + "504d67ffd55ea4586b966b7389cc8b" - + "16e535e6ca822244fb293cc7100627" + "67bf19607c46dde5926b0100c479fc" - + "5731177a309d84a46d8dabc50d5b8a" + "3c26f1316edb6cbddc28acb2f25560" - + "1f292b5f6bb2dc5e3f4a9b7cc44a93" + "dbd775b4559eea91c89ca232e60590" - + "c5b54c1bcc9037542f38ef0c1109fd" + "c6a684f64cb958b9fba757a1717d03" - + "40dec22dc8b77ee853d2272ddbf7c9" + "dfe11a776d20bf117c7eab2bf0ec7b" - + "f208f1ad359c0eb85658796471f863" + "1584fc3f68f647a1064aa4dafa08f9" - + "754739840bc6ba016544c963fda63d" + "97b8a0b50c30bfccf2180bf18a4cbe" - + "708cae982f2fbcb39341a7f2f90aa0" + "2fceb0c795393a2e9eadb54a206db6" - + "862442627a17897c30ac2e33a6135e" + "6816f2aed8e692ed4b5012d8f4e696" - + "916f2c82c1719190c284146b6c794d" + "a617c52da1a63a303c5dfa8afa93e4" - + "beaadab0b121be4812e5b5ffbae09c" + "1c8ffde32707908aa7b7361cd76d9e" - + "aaf095fb91e5b2300f2e87eaa71c49" + "1ca25d3cfdcd259e60ffceca650aa5" - + "41aec8fac6dc5d05d9c3189ec59e27" + "292e02d4a67aba7e895a110e0fb62e" - + "cfee6492cb5e9bd4fe579abfdcd5a0" + "c5da48d93213e7002579922741ab2b" - + "283b459fd949da212b723392a3e1dd" + "b62ae23d42d9c6a49d7fe84046e3f5" - + "b808a900bb8e52f358823e9eec31fc" + "986ee2ad8b0bdf4234a818e1dbad0b" - + "95d38b0789340b531f403580435659" + "6f1c386c6853b78cbf7f7d745013b9" - + "07e5c24af35b81b69c5cdc674a06e1" + "ac3a728e09b00a9ac9e788ace68b6a" - + "4a556598e410666bc29357188faeb3" + "8be56e5691c17ab72163910fe7f9d0" - + "1f8c8468bdf6ba9845a2873b0339c1" + "855263a59abded562b1f40efd49b81" - + "fac9d7f5054be04e51ca0055ff1360" + "f6dc66b8886b5f9b2389e36b9213aa" - + "01e33cba2ac337592b986a436d0e05" + "58521c1d6e9a173bf66c4742bc8ba5" - + "91390032f5a3e9a0a25b5035c0f0f9" + "94869436b37853bf8400a1f435b61a" - + "ba3be39c3c6b2936aff805a2fe0797" + "16fd71be634f8ff90018a68b5aaeb8" - + "2d6cfe1bb6f0e577e38d3364ea0aa8" + "a1ad165aa95c6de0d4a079eda2898a" - + "9cd76f45e3", 16); - - g_8192 = new BigInteger("5", 16); - - } - - - - public BaseTestDHKeyPairGenerator(String providerName) { - super(providerName); - } - - @Before - @Override - protected void setUp() throws Exception { - super.setUp(); - kpg = KeyPairGenerator.getInstance("DH", providerName); + @BeforeEach + public void setUp() throws Exception { + kpg = KeyPairGenerator.getInstance("DH", getProviderName()); dhParams_1024 = new DHParameterSpec(p_1024, g_1024); dhParams_2048 = new DHParameterSpec(p_2048, g_2048); dhParams_3072 = new DHParameterSpec(p_3072, g_3072); @@ -192,13 +147,9 @@ protected void setUp() throws Exception { dhParams_8192 = new DHParameterSpec(p_8192, g_8192); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testDHKeyGen_1024_withParams() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 1024 bit keys return; } @@ -207,33 +158,39 @@ public void testDHKeyGen_1024_withParams() throws Exception { } + @Test public void testDHKeyGen_2048_withParams() throws Exception { kpg.initialize(dhParams_2048); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_3072_withParams() throws Exception { kpg.initialize(dhParams_3072); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_4096_withParams() throws Exception { kpg.initialize(dhParams_4096); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_6144_withParams() throws Exception { kpg.initialize(dhParams_6144); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_8192_withParams() throws Exception { kpg.initialize(dhParams_8192); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 1024 bit keys return; } @@ -242,63 +199,41 @@ public void testDHKeyGen_1024() throws Exception { compPrivPubKeyParams(); } + @Test public void testDHKeyGen_2048() throws Exception { kpg.initialize(2048); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_3072() throws Exception { kpg.initialize(3072); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_4096() throws Exception { kpg.initialize(4096); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_6144() throws Exception { kpg.initialize(6144); compPrivPubKeyParams(); } + @Test public void testDHKeyGen_8192() throws Exception { kpg.initialize(8192); compPrivPubKeyParams(); } - - // private void compPrivPubKeyParams () { - // KeyPair kp = kpg.generateKeyPair(); - // - // assert(kp != null); - // - // assert(kp.getPublic() != null); - // assert(kp.getPrivate() != null); - // - // DHPublicKey dhpu = (DHPublicKey) kp.getPublic(); - // DHPrivateKey dhpr = (DHPrivateKey) kp.getPrivate(); - // - // assert(dhpu.getY() != null); - // assert(dhpr.getX() != null); - // - // - // - // assert(dhpu.getParams().getP().compareTo(dhpr.getParams().getP()) == 0); - // assert(dhpu.getParams().getG().compareTo(dhpr.getParams().getG()) == 0); - // assert(dhpu.getParams().getL() == dhpr.getParams().getL()); - // } - - /* - * test case from Oracle Security-in-Depth Fix 8293554: Enhanced DH Key - * Exchanges Bring key sizes more in line with public standards (e.g., NIST SP - * 800-56A) Problem Report 148149 - * - */ + @Test public void testDefaultDHPrivateExpSize() throws Exception { // int[] keypairSizes = { 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192 }; int[] keypairSizes = {2048, 3072, 4096, 6144, 8192}; - System.out.println("Testing provider: " + providerName + " DH private exponenent size"); + System.out.println("Testing provider: " + getProviderName() + " DH private exponenent size"); for (int keypairSize : keypairSizes) { //System.out.println("\n**********Keysize: " + keypairSize); @@ -319,10 +254,10 @@ public void testDefaultDHPrivateExpSize() throws Exception { System.out.print(" Custom parameters good."); } catch (InvalidParameterException invalidParameterException) { - if ((PROVIDER_OPENJCEPlusFIPS.equalsIgnoreCase(providerName) - || PROVIDER_OPENJCEPlus.equalsIgnoreCase(providerName)) + if ((PROVIDER_OPENJCEPlusFIPS.equalsIgnoreCase(getProviderName()) + || PROVIDER_OPENJCEPlus.equalsIgnoreCase(getProviderName())) && (keypairSize == 1536)) { - System.out.print("Keysize 1536 not supported on provider: " + providerName + System.out.print("Keysize 1536 not supported on provider: " + getProviderName() + "<===Expected exception caught"); } else { invalidParameterException.printStackTrace(); @@ -442,12 +377,12 @@ private void compPrivPubKeyParams() { * KeyPairGenerator initialize time. * Similar checks on keypair size may be found in other DH related classes as well. */ - @Test(expected = InvalidParameterException.class) + @Test public void testInvalidDHKeySize() throws Exception { int[] someJCEPlusInvalidKeypairSizes = {1088, 1280, 1536, 1728, 2944, 3008, 3968, 4992, 5952, 6976, 7936}; - System.out.println("Testing invalid keypair sizes with provider: " + providerName); + System.out.println("Testing invalid keypair sizes with provider: " + getProviderName()); int[] keypairSizes = someJCEPlusInvalidKeypairSizes; for (int keypairSize : keypairSizes) { @@ -457,10 +392,10 @@ public void testInvalidDHKeySize() throws Exception { kpg.initialize(keypairSize); fail("Invalid DH keypair size: " + keypairSize + " did not cause with provider: " - + providerName); + + getProviderName()); } catch (InvalidParameterException invalidParameterException) { System.out.print(" Keysize: (" + keypairSize + ") not supported on provider: " - + providerName + "<===Expected InvalidParameterException caught"); + + getProviderName() + "<===Expected InvalidParameterException caught"); } finally { System.out.println(""); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDHMultiParty.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDHMultiParty.java index ff2501f6..f3671163 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -18,44 +18,19 @@ import java.util.Arrays; import javax.crypto.KeyAgreement; import javax.crypto.spec.DHParameterSpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestDHMultiParty extends BaseTest { +public class BaseTestDHMultiParty extends BaseTestJunit5 { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // - - // -------------------------------------------------------------------------- - // - // - public BaseTestDHMultiParty(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // /** * Basic DH example * * @throws Exception */ - + @Test public void testDHMulti() throws Exception { String id = "testDHMulti"; @@ -69,7 +44,7 @@ public void testDHMulti() throws Exception { DHParameterSpec dhParams = new DHParameterSpec(p_2048, g_2048); try { - compute_dh_multiparty(id, dhParams, providerName); + compute_dh_multiparty(id, dhParams, getProviderName()); } catch (IllegalStateException e) { //System.out.println(e.getMessage()); assertTrue(true); @@ -176,4 +151,3 @@ void compute_dh_multiparty(String idString, DHParameterSpec dhParameterSpec, Str } } - diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDSAKey.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDSAKey.java index 0baeb6ba..4f5e4695 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDSAKey.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDSAKey.java @@ -23,8 +23,11 @@ import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import java.util.Base64; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestDSAKey extends BaseTest { +public class BaseTestDSAKey extends BaseTestJunit5 { private static String publicKey1024 = "MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7" + "s5Of2EbdSPO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1" + "Vs14E7gB00b/JmYLdrmVClpJ+f6AR7ECLCT7up1/63xhv4O1fnx" @@ -86,17 +89,14 @@ public class BaseTestDSAKey extends BaseTest { + "qMpislBtDj4EIgIgJGAGjgXTmTeq0L8Oo2jCuSCLmEeFfMM9xjt" +"tGLOCEc8="; - public BaseTestDSAKey(String providerName) { - super(providerName); - } - + @Test public void testDSAKeyGen_1024() throws Exception { try { KeyPair dsaKeyPair = generateKeyPair(1024); dsaKeyPair.getPublic(); dsaKeyPair.getPrivate(); } catch (InvalidParameterException | InvalidKeyException ikex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -104,12 +104,14 @@ public void testDSAKeyGen_1024() throws Exception { } } + @Test public void testDSAKeyGen_2048() throws Exception { KeyPair dsaKeyPair = generateKeyPair(2048); dsaKeyPair.getPublic(); dsaKeyPair.getPrivate(); } + @Test public void testDSAKeyGenFromParams_1024() throws Exception { try { AlgorithmParameters algParams = generateParameters(1024); @@ -119,7 +121,7 @@ public void testDSAKeyGenFromParams_1024() throws Exception { dsaKeyPair.getPublic(); dsaKeyPair.getPrivate(); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -128,12 +130,13 @@ public void testDSAKeyGenFromParams_1024() throws Exception { } + @Test public void testDSAKeyFactoryCreateFromEncoded_1024() throws Exception { try { keyFactoryCreateFromEncoded(1024); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -141,15 +144,17 @@ public void testDSAKeyFactoryCreateFromEncoded_1024() throws Exception { } } + @Test public void testDSAKeyFactoryCreateFromEncoded_2048() throws Exception { keyFactoryCreateFromEncoded(2048); } + @Test public void testDSAKeyFactoryCreateFromKeySpec_1024() throws Exception { try { keyFactoryCreateFromKeySpec(1024); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -158,20 +163,21 @@ public void testDSAKeyFactoryCreateFromKeySpec_1024() throws Exception { } + @Test public void testDSAKeyFactoryCreateFromKeySpec_2048() throws Exception { keyFactoryCreateFromKeySpec(2048); } protected AlgorithmParameters generateParameters(int size) throws Exception { AlgorithmParameterGenerator algParmGen = AlgorithmParameterGenerator.getInstance("DSA", - providerName); + getProviderName()); algParmGen.init(size); AlgorithmParameters algParams = algParmGen.generateParameters(); return algParams; } protected KeyPair generateKeyPair(int size) throws Exception { - KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", providerName); + KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", getProviderName()); dsaKeyPairGen.initialize(size); KeyPair keyPair = dsaKeyPairGen.generateKeyPair(); @@ -195,7 +201,7 @@ protected KeyPair generateKeyPair(int size) throws Exception { } protected KeyPair generateKeyPair(DSAParameterSpec dsaParameterSpec) throws Exception { - KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", providerName); + KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", getProviderName()); dsaKeyPairGen.initialize(dsaParameterSpec); KeyPair keyPair = dsaKeyPairGen.generateKeyPair(); @@ -221,7 +227,7 @@ protected KeyPair generateKeyPair(DSAParameterSpec dsaParameterSpec) throws Exce protected KeyPair keyFactoryCreateFromEncoded(int size) throws Exception { byte[] publicKeyArray = null; byte[] privateKeyArray = null; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { if (size == 1024) { publicKeyArray = Base64.getDecoder().decode(publicKey1024); privateKeyArray = Base64.getDecoder().decode(privateKey1024); @@ -240,7 +246,7 @@ protected KeyPair keyFactoryCreateFromEncoded(int size) throws Exception { X509EncodedKeySpec x509Spec = new X509EncodedKeySpec(publicKeyArray); PKCS8EncodedKeySpec pkcs8Spec = new PKCS8EncodedKeySpec(privateKeyArray); - KeyFactory dsaKeyFactory = KeyFactory.getInstance("DSA", providerName); + KeyFactory dsaKeyFactory = KeyFactory.getInstance("DSA", getProviderName()); DSAPublicKey dsaPub = (DSAPublicKey) dsaKeyFactory.generatePublic(x509Spec); DSAPrivateKey dsaPriv = (DSAPrivateKey) dsaKeyFactory.generatePrivate(pkcs8Spec); @@ -259,7 +265,7 @@ protected void keyFactoryCreateFromKeySpec(int size) throws Exception { KeyPair dsaKeyPair = keyFactoryCreateFromEncoded(size); - KeyFactory dsaKeyFactory = KeyFactory.getInstance("DSA", providerName); + KeyFactory dsaKeyFactory = KeyFactory.getInstance("DSA", getProviderName()); DSAPublicKeySpec dsaPubSpec = dsaKeyFactory .getKeySpec(dsaKeyPair.getPublic(), DSAPublicKeySpec.class); DSAPublicKey dsaPub = (DSAPublicKey) dsaKeyFactory.generatePublic(dsaPubSpec); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignature.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignature.java index bd9463b5..5d9fd091 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignature.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -public class BaseTestDSASignature extends BaseTestSignature { +public class BaseTestDSASignature extends BaseTestJunit5Signature { static final byte[] origMsg = "this is the original message to be signed".getBytes(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop.java index 1cd80e95..1743e56a 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,40 +20,23 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTestDSASignatureInterop extends BaseTestSignatureInterop { - // -------------------------------------------------------------------------- - // - // - static final byte[] origMsg = "this is the original message to be signed".getBytes(); - - // -------------------------------------------------------------------------- - // - // - public BaseTestDSASignatureInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} + static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withDSA_1024() throws Exception { KeyPair keyPair = null; try { keyPair = generateKeyPair(1024); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -63,7 +46,7 @@ public void testSHA1withDSA_1024() throws Exception { try { doSignVerify("SHA1withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -71,15 +54,13 @@ public void testSHA1withDSA_1024() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withDSA_1024() throws Exception { KeyPair keyPair = null; try { keyPair = generateKeyPair(1024); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -89,7 +70,7 @@ public void testSHA224withDSA_1024() throws Exception { try { doSignVerify("SHA224withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -97,15 +78,13 @@ public void testSHA224withDSA_1024() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withDSA_1024() throws Exception { KeyPair keyPair = null; try { keyPair = generateKeyPair(1024); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -115,7 +94,7 @@ public void testSHA256withDSA_1024() throws Exception { try { doSignVerify("SHA256withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -123,15 +102,13 @@ public void testSHA256withDSA_1024() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testNONEwithDSA_2048_hash20() throws Exception { KeyPair keyPair = null; try { keyPair = generateKeyPair(2048); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -142,14 +119,12 @@ public void testNONEwithDSA_2048_hash20() throws Exception { doSignVerify("NONEwithDSA", sslHash, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void test_encoding() throws Exception { - test_dsa_encoded(providerName, providerName); - test_dsa_encoded(interopProviderName, interopProviderName); - test_dsa_encoded(providerName, interopProviderName); - test_dsa_encoded(interopProviderName, providerName); + test_dsa_encoded(getProviderName(), getProviderName()); + test_dsa_encoded(getInteropProviderName(), getInteropProviderName()); + test_dsa_encoded(getProviderName(), getInteropProviderName()); + test_dsa_encoded(getInteropProviderName(), getProviderName()); } void test_dsa_encoded(String providerNameX, String providerNameY) throws Exception { @@ -162,7 +137,7 @@ void test_dsa_encoded(String providerNameX, String providerNameY) throws Excepti try { dsaKeyPairX = generateKeyPair(2048); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -218,11 +193,9 @@ void test_dsa_encoded(String providerNameX, String providerNameY) throws Excepti } - // -------------------------------------------------------------------------- - // - // + protected KeyPair generateKeyPair(int keysize) throws Exception { - KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", providerName); + KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", getProviderName()); dsaKeyPairGen.initialize(keysize); return dsaKeyPairGen.generateKeyPair(); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop2.java b/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop2.java index 9deef20c..64bb4aeb 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop2.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestDSASignatureInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,34 +19,15 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTestDSASignatureInterop2 extends BaseTestSignatureInterop { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // - public BaseTestDSASignatureInterop2(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_2244withDSA_1024() throws Exception { try { KeyPair keyPairFromProvider = generateKeyPair(1024); @@ -57,7 +38,7 @@ public void testSHA3_2244withDSA_1024() throws Exception { doSignVerify("SHA3-224withDSA", origMsg, keyPairFromInteropProvider.getPrivate(), keyPairFromInteropProvider.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -65,15 +46,13 @@ public void testSHA3_2244withDSA_1024() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withDSA_1024() throws Exception { try { KeyPair keyPair = generateKeyPair(1024); doSignVerify("SHA3-256withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -81,15 +60,13 @@ public void testSHA3_256withDSA_1024() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withDSA_1024() throws Exception { try { KeyPair keyPair = generateKeyPair(1024); doSignVerify("SHA3-384withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -97,15 +74,13 @@ public void testSHA3_384withDSA_1024() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withDSA_1024() throws Exception { try { KeyPair keyPair = generateKeyPair(1024); doSignVerify("SHA3-512withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -113,15 +88,13 @@ public void testSHA3_512withDSA_1024() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224withDSA_2048() throws Exception { try { KeyPair keyPair = generateKeyPair(2048); doSignVerify("SHA3-224withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -129,15 +102,13 @@ public void testSHA3_224withDSA_2048() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withDSA_2048() throws Exception { try { KeyPair keyPair = generateKeyPair(2048); doSignVerify("SHA3-256withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -145,15 +116,13 @@ public void testSHA3_256withDSA_2048() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withDSA_2048() throws Exception { try { KeyPair keyPair = generateKeyPair(2048); doSignVerify("SHA3-384withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -161,15 +130,13 @@ public void testSHA3_384withDSA_2048() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withDSA_2048() throws Exception { try { KeyPair keyPair = generateKeyPair(2048); doSignVerify("SHA3-512withDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } catch (InvalidParameterException | InvalidKeyException ipex) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); } else { assertTrue(false); @@ -177,11 +144,12 @@ public void testSHA3_512withDSA_2048() throws Exception { } } + @Test public void test_encoding() throws Exception { - test_dsa_encoded(providerName, providerName); - test_dsa_encoded(interopProviderName, interopProviderName); - test_dsa_encoded(providerName, interopProviderName); - test_dsa_encoded(interopProviderName, providerName); + test_dsa_encoded(getProviderName(), getProviderName()); + test_dsa_encoded(getInteropProviderName(), getInteropProviderName()); + test_dsa_encoded(getProviderName(), getInteropProviderName()); + test_dsa_encoded(getInteropProviderName(), getProviderName()); } void test_dsa_encoded(String providerNameX, String providerNameY) throws Exception { @@ -240,17 +208,15 @@ void test_dsa_encoded(String providerNameX, String providerNameY) throws Excepti } - // -------------------------------------------------------------------------- - // - // + protected KeyPair generateKeyPair(int keysize) throws Exception { - KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", providerName); + KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", getProviderName()); dsaKeyPairGen.initialize(keysize); return dsaKeyPairGen.generateKeyPair(); } protected KeyPair generateKeyPairFromInteropProvider(int keysize) throws Exception { - KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", interopProviderName); + KeyPairGenerator dsaKeyPairGen = KeyPairGenerator.getInstance("DSA", getInteropProviderName()); dsaKeyPairGen.initialize(keysize); return dsaKeyPairGen.generateKeyPair(); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECDH.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECDH.java index 8ccbe881..ba2d123f 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECDH.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -26,12 +26,14 @@ import java.security.spec.InvalidParameterSpecException; import java.util.Arrays; import javax.crypto.KeyAgreement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -public class BaseTestECDH extends ibm.jceplus.junit.base.BaseTest { +public class BaseTestECDH extends BaseTestJunit5 { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); static ECGenParameterSpec algParameterSpec_192k1, algParameterSpec_256r1; @@ -41,9 +43,18 @@ public class BaseTestECDH extends ibm.jceplus.junit.base.BaseTest { static KeyPair keyPairA_192k1, keyPairA_256r1; static KeyPair keyPairB_192k1, keyPairB_256r1; - public boolean isMulti = false; + private boolean isMulti = false; + static boolean generated = false; + public boolean isMulti() { + return isMulti; + } + + public void setMulti(boolean isMulti) { + this.isMulti = isMulti; + } + synchronized static void generateParams(String provider_name) { if (generated) return; @@ -81,33 +92,17 @@ synchronized static void generateParams(String provider_name) { } } - // -------------------------------------------------------------------------- - // - // - public BaseTestECDH(String providerName) { - super(providerName); - generateParams(providerName); + @BeforeEach + public void setUp() { + generateParams(getProviderName()); } - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // /** * Basic ECDH example * * @throws Exception */ - + @Test public void testECDH_secp192k1() throws Exception { String curveName = "secp192k1"; @@ -120,6 +115,7 @@ public void testECDH_secp192k1() throws Exception { } + @Test public void testECDH_secp256r1() throws Exception { String curveName = "secp256r1"; @@ -132,6 +128,7 @@ public void testECDH_secp256r1() throws Exception { } + @Test public void testECDH_ECSpec() throws Exception { String methodId = "ECDHECParamSpec"; @@ -166,7 +163,7 @@ void compute_ecdh_key(String idString, AlgorithmParameterSpec algParameterSpec) KeyPairGenerator kpgA = null; try { - kpgA = KeyPairGenerator.getInstance("EC", providerName); + kpgA = KeyPairGenerator.getInstance("EC", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -189,7 +186,7 @@ void compute_ecdh_key(String idString, AlgorithmParameterSpec algParameterSpec) // set up KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("ECDH", providerName); + keyAgreeA = KeyAgreement.getInstance("ECDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -207,7 +204,7 @@ void compute_ecdh_key(String idString, AlgorithmParameterSpec algParameterSpec) KeyPairGenerator kpgB = null; try { - kpgB = KeyPairGenerator.getInstance("EC", providerName); + kpgB = KeyPairGenerator.getInstance("EC", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -231,7 +228,7 @@ void compute_ecdh_key(String idString, AlgorithmParameterSpec algParameterSpec) KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("ECDH", providerName); + keyAgreeB = KeyAgreement.getInstance("ECDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -280,12 +277,13 @@ void compute_ecdh_key(String idString, AlgorithmParameterSpec algParameterSpec) * unrecognized curve name. * Was throwing an InvalidParameterException from ECNamedCurve constructor taking single String argument */ + @Test public void testEC_engineInit_AlgorithmParameterSpec_paramSpec() throws Exception { String curveName = "UnknownCurveNameShouldGenerateInvalidParameterSpecException"; AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance("EC", - providerName); - assertNotNull("AlgorithmParameters EC not found in provider" + providerName, + getProviderName()); + assertNotNull("AlgorithmParameters EC not found in provider" + getProviderName(), algorithmParameters); AlgorithmParameterSpec algorithmParameterSpec = new ECGenParameterSpec(curveName); @@ -324,7 +322,7 @@ void compute_ecdh_key_with_global_key(String idString, AlgorithmParameterSpec al // set up KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("ECDH", providerName); + keyAgreeA = KeyAgreement.getInstance("ECDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -342,7 +340,7 @@ void compute_ecdh_key_with_global_key(String idString, AlgorithmParameterSpec al KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("ECDH", providerName); + keyAgreeB = KeyAgreement.getInstance("ECDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECDHInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECDHInterop.java index f83946ea..6c3ceab0 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECDHInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECDHInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -32,34 +32,13 @@ import javax.crypto.KeyAgreement; import javax.crypto.spec.SecretKeySpec; import org.junit.Ignore; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestECDHInterop extends BaseTestInterop { +public class BaseTestECDHInterop extends BaseTestJunit5Interop { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // - public BaseTestECDHInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // /** * Basic ECDH example * @@ -72,36 +51,38 @@ public void ignore_testECDH_secp192k1() throws Exception { ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - compute_ecdh_key_interop(curveName, ecgn, providerName, interopProviderName); - compute_ecdh_key_interop(curveName, ecgn, interopProviderName, providerName); + compute_ecdh_key_interop(curveName, ecgn, getProviderName(), getInteropProviderName()); + compute_ecdh_key_interop(curveName, ecgn, getInteropProviderName(), getProviderName()); - compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, providerName, - interopProviderName); - compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, interopProviderName, - providerName); + compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, getProviderName(), + getInteropProviderName()); + compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, getInteropProviderName(), + getProviderName()); } + @Test public void testECDH_encdoing() throws Exception { - test_ecdh_keyFactory(providerName, providerName); - test_ecdh_keyFactory(interopProviderName, interopProviderName); - test_ecdh_keyFactory(providerName, interopProviderName); - test_ecdh_keyFactory(interopProviderName, providerName); + test_ecdh_keyFactory(getProviderName(), getProviderName()); + test_ecdh_keyFactory(getInteropProviderName(), getInteropProviderName()); + test_ecdh_keyFactory(getProviderName(), getInteropProviderName()); + test_ecdh_keyFactory(getInteropProviderName(), getProviderName()); } + @Test public void testECDH_secp256r1() throws Exception { String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - compute_ecdh_key_interop(curveName, ecgn, providerName, interopProviderName); - compute_ecdh_key_interop(curveName, ecgn, interopProviderName, providerName); + compute_ecdh_key_interop(curveName, ecgn, getProviderName(), getInteropProviderName()); + compute_ecdh_key_interop(curveName, ecgn, getInteropProviderName(), getProviderName()); - compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, providerName, - interopProviderName); - compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, interopProviderName, - providerName); + compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, getProviderName(), + getInteropProviderName()); + compute_ecdh_key_interop_sameKeyPairGenerator(curveName, ecgn, getInteropProviderName(), + getProviderName()); } @@ -133,13 +114,13 @@ public void ignore_testECDH_ECSpec() throws Exception { int cofactor = 1; ECParameterSpec ecParamSpec = new ECParameterSpec(curve, g, order, cofactor); - compute_ecdh_key_interop(methodId, ecParamSpec, providerName, interopProviderName); - compute_ecdh_key_interop(methodId, ecParamSpec, interopProviderName, providerName); + compute_ecdh_key_interop(methodId, ecParamSpec, getProviderName(), getInteropProviderName()); + compute_ecdh_key_interop(methodId, ecParamSpec, getInteropProviderName(), getProviderName()); - compute_ecdh_key_interop_sameKeyPairGenerator(methodId, ecParamSpec, providerName, - interopProviderName); - compute_ecdh_key_interop_sameKeyPairGenerator(methodId, ecParamSpec, interopProviderName, - providerName); + compute_ecdh_key_interop_sameKeyPairGenerator(methodId, ecParamSpec, getProviderName(), + getInteropProviderName()); + compute_ecdh_key_interop_sameKeyPairGenerator(methodId, ecParamSpec, getInteropProviderName(), + getProviderName()); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECDHMultiParty.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECDHMultiParty.java index b7539edf..fc0787ac 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,40 +19,19 @@ import java.security.spec.ECGenParameterSpec; import java.util.Arrays; import javax.crypto.KeyAgreement; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestECDHMultiParty extends BaseTest { +public class BaseTestECDHMultiParty extends BaseTestJunit5 { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // - public BaseTestECDHMultiParty(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // /** * Basic ECDH example * * @throws Exception */ - + @Test public void testECDHMulti_secp192k1() throws Exception { String curveName = "secp192k1"; @@ -60,7 +39,7 @@ public void testECDHMulti_secp192k1() throws Exception { ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); try { - compute_ecdh_multiparty_oneprovider(curveName, ecgn, providerName); + compute_ecdh_multiparty_oneprovider(curveName, ecgn, getProviderName()); } catch (IllegalStateException e) { //System.out.println(e.getMessage()); assertTrue(true); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignature.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignature.java index afc238ce..d35f224d 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignature.java @@ -31,7 +31,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestECDSASignature extends BaseTestSignature { +public class BaseTestECDSASignature extends BaseTestJunit5Signature { static final byte[] origMsg = "this is the original message to be signed".getBytes(); @@ -808,9 +808,7 @@ private void doTestPositiveSigBytes(String keyAlg, String sigAlg, String provide } } - // -------------------------------------------------------------------------- - // - // + private KeyPair generateKeyPair(int keysize) throws Exception { KeyPairGenerator ecKeyPairGen = KeyPairGenerator.getInstance("EC", getProviderName()); ecKeyPairGen.initialize(keysize); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop.java index 650630f2..b0ba94a1 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,41 +14,16 @@ import java.security.MessageDigest; import java.security.Signature; import org.junit.Ignore; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestECDSASignatureInterop extends BaseTestSignatureInterop { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // - - // -------------------------------------------------------------------------- - // - // - public BaseTestECDSASignatureInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // @Ignore("Curve secp192r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testSHA1withDSA_192() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA-1 or P-192. So skip test return; } @@ -56,12 +31,10 @@ public void ignore_testSHA1withDSA_192() throws Exception { doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp224r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testSHA1withDSA_224() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA-1. So skip test return; } @@ -69,11 +42,9 @@ public void ignore_testSHA1withDSA_224() throws Exception { doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withDSA_256() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA-1. So skip test return; } @@ -81,11 +52,9 @@ public void testSHA1withDSA_256() throws Exception { doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withECDSA_384() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA-1. So skip test return; } @@ -93,11 +62,9 @@ public void testSHA1withECDSA_384() throws Exception { doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withECDSA_521() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA-1. So skip test return; } @@ -105,12 +72,10 @@ public void testSHA1withECDSA_521() throws Exception { doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp192r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testSHA224withECDSA_192() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support P-192. So skip test return; } @@ -118,9 +83,7 @@ public void ignore_testSHA224withECDSA_192() throws Exception { doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp224r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testSHA224withECDSA_224() throws Exception { @@ -128,37 +91,29 @@ public void ignore_testSHA224withECDSA_224() throws Exception { doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp192r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testSHA256withECDSA_192() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support P-192. So skip test return; } @@ -166,9 +121,7 @@ public void ignore_testSHA256withECDSA_192() throws Exception { doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp224r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testSHA256withECDSA_224() throws Exception { @@ -176,91 +129,75 @@ public void ignore_testSHA256withECDSA_224() throws Exception { doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp192r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testDatawithECDSA_SHA1_192() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support P-192 and SHA-1. So skip test return; } KeyPair keyPair = generateKeyPair(192); - MessageDigest md = MessageDigest.getInstance("SHA-1", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-1", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Ignore("Curve secp224r1 removed via https://bugs.openjdk.org/browse/JDK-8251547 in JDK16") public void ignore_testDatawithECDSA_SHA224_224() throws Exception { KeyPair keyPair = generateKeyPair(224); - MessageDigest md = MessageDigest.getInstance("SHA-224", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-224", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA256_256() throws Exception { KeyPair keyPair = generateKeyPair(256); - MessageDigest md = MessageDigest.getInstance("SHA-256", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-256", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA384_384() throws Exception { KeyPair keyPair = generateKeyPair(384); - MessageDigest md = MessageDigest.getInstance("SHA-384", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-384", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA512_521() throws Exception { KeyPair keyPair = generateKeyPair(521); - MessageDigest md = MessageDigest.getInstance("SHA-512", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-512", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); @@ -268,14 +205,15 @@ public void testDatawithECDSA_SHA512_521() throws Exception { } //OSB Oracle Security Fix 8277233 test + @Test public void testPostiveSigBytes() throws Exception { - doTestPositiveSigBytes("EC", "SHA256withECDSA", this.providerName); - doTestPositiveSigBytes("EC", "SHA256withECDSA", this.providerName); + doTestPositiveSigBytes("EC", "SHA256withECDSA", this.getProviderName()); + doTestPositiveSigBytes("EC", "SHA256withECDSA", this.getProviderName()); - if (!providerName.equals("OpenJCEPlusFIPS")) { + if (!getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support DSA. So skip test - doTestPositiveSigBytes("DSA", "SHA256withDSA", this.providerName); - doTestPositiveSigBytes("DSA", "SHA256withDSA", this.providerName); + doTestPositiveSigBytes("DSA", "SHA256withDSA", this.getProviderName()); + doTestPositiveSigBytes("DSA", "SHA256withDSA", this.getProviderName()); } } @@ -307,10 +245,7 @@ void doTestPositiveSigBytes(String keyAlg, String sigAlg, String providerName) } } - - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_NoHash_256() throws Exception { KeyPair keyPair = generateKeyPair(256); //MessageDigest md = MessageDigest.getInstance("SHA-256", providerName); @@ -321,11 +256,9 @@ public void testDatawithECDSA_NoHash_256() throws Exception { doSignVerify("NONEwithECDSA", origMsg1, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + private KeyPair generateKeyPair(int keysize) throws Exception { - KeyPairGenerator ecKeyPairGen = KeyPairGenerator.getInstance("EC", providerName); + KeyPairGenerator ecKeyPairGen = KeyPairGenerator.getInstance("EC", getProviderName()); ecKeyPairGen.initialize(keysize); return ecKeyPairGen.generateKeyPair(); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop2.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop2.java index 1b449da4..416f8094 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop2.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECDSASignatureInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,379 +10,273 @@ import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.MessageDigest; +import org.junit.jupiter.api.Test; public class BaseTestECDSASignatureInterop2 extends BaseTestSignatureInterop { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - // -------------------------------------------------------------------------- - // - // - - // -------------------------------------------------------------------------- - // - // - public BaseTestECDSASignatureInterop2(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA1withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA1withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA224withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA256withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224withECDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA3-224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withECDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA3-256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withECDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA3-384withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withECDSA_192() throws Exception { KeyPair keyPair = generateKeyPair(192); doSignVerify("SHA3-512withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224withECDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA3-224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withECDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA3-256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withECDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA3-384withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withECDSA_224() throws Exception { KeyPair keyPair = generateKeyPair(224); doSignVerify("SHA3-512withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA3-224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA3-256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA3-384withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withECDSA_256() throws Exception { KeyPair keyPair = generateKeyPair(256); doSignVerify("SHA3-512withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA3-224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA3-256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA3-384withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withECDSA_384() throws Exception { KeyPair keyPair = generateKeyPair(384); doSignVerify("SHA3-512withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA3-224withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA3-256withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA3-384withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512withECDSA_521() throws Exception { KeyPair keyPair = generateKeyPair(521); doSignVerify("SHA3-512withECDSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA1_192() throws Exception { KeyPair keyPair = generateKeyPair(192); - MessageDigest md = MessageDigest.getInstance("SHA-1", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-1", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA224_224() throws Exception { KeyPair keyPair = generateKeyPair(224); - MessageDigest md = MessageDigest.getInstance("SHA-224", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-224", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA256_256() throws Exception { KeyPair keyPair = generateKeyPair(256); - MessageDigest md = MessageDigest.getInstance("SHA-256", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-256", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA384_384() throws Exception { KeyPair keyPair = generateKeyPair(384); - MessageDigest md = MessageDigest.getInstance("SHA-384", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-384", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_SHA512_521() throws Exception { KeyPair keyPair = generateKeyPair(521); - MessageDigest md = MessageDigest.getInstance("SHA-512", providerName); + MessageDigest md = MessageDigest.getInstance("SHA-512", getProviderName()); md.update(origMsg); byte[] digest = md.digest(); //System.out.println ("origMessage.length" + origMsg.length); doSignVerify("NONEwithECDSA", digest, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testDatawithECDSA_NoHash_256() throws Exception { KeyPair keyPair = generateKeyPair(256); //MessageDigest md = MessageDigest.getInstance("SHA-256", providerName); @@ -393,11 +287,8 @@ public void testDatawithECDSA_NoHash_256() throws Exception { doSignVerify("NONEwithECDSA", origMsg1, keyPair.getPrivate(), keyPair.getPublic()); } - // -------------------------------------------------------------------------- - // - // private KeyPair generateKeyPair(int keysize) throws Exception { - KeyPairGenerator ecKeyPairGen = KeyPairGenerator.getInstance("EC", providerName); + KeyPairGenerator ecKeyPairGen = KeyPairGenerator.getInstance("EC", getProviderName()); ecKeyPairGen.initialize(keysize); return ecKeyPairGen.generateKeyPair(); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImport.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImport.java index cabc27da..764e8462 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImport.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImport.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,43 +23,25 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestECKeyImport extends BaseTest { +public class BaseTestECKeyImport extends BaseTestJunit5 { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - - // -------------------------------------------------------------------------- - // - // - public BaseTestECKeyImport(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - /** * Generate a KeyPair using ECGEenParam and then import the key pair * * @throws Exception */ + @Test public void testCreateKeyPairECGenParamImport() throws Exception { //final String methodName = "testCreateKeyPairECGenParamImport"; ECGenParameterSpec ecgn = new ECGenParameterSpec("secp192k1"); - KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("EC", providerName); + KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("EC", getProviderName()); keyPairGen.initialize(ecgn); KeyPair keyPair = keyPairGen.generateKeyPair(); @@ -78,7 +60,7 @@ public void testCreateKeyPairECGenParamImport() throws Exception { // System.out.println (methodName + " privKeyBytes = " + // BaseUtils.bytesToHex(privKeyBytes)); - KeyFactory keyFactory = KeyFactory.getInstance("EC", providerName); + KeyFactory keyFactory = KeyFactory.getInstance("EC", getProviderName()); EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privKeyBytes); PrivateKey privateKey2 = keyFactory.generatePrivate(privateKeySpec); @@ -98,6 +80,7 @@ public void testCreateKeyPairECGenParamImport() throws Exception { * During the encoding, the provider should recognize that this is * same as a Known curve and encodes only the OID for named Curve */ + @Test public void testCreateKeyPairECParamImport() throws Exception { //final String methodName = "testCreateKeyPairECParamImport"; @@ -120,7 +103,7 @@ public void testCreateKeyPairECParamImport() throws Exception { int cofactor = 1; ECParameterSpec ecParamSpec = new ECParameterSpec(curve, g, order, cofactor); - KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("EC", providerName); + KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("EC", getProviderName()); keyPairGen.initialize(ecParamSpec); KeyPair keyPair = keyPairGen.generateKeyPair(); @@ -139,7 +122,7 @@ public void testCreateKeyPairECParamImport() throws Exception { // System.out.println (methodName + " privKeyBytes = " + // BaseUtils.bytesToHex(privKeyBytes)); - KeyFactory keyFactory = KeyFactory.getInstance("EC", providerName); + KeyFactory keyFactory = KeyFactory.getInstance("EC", getProviderName()); EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privKeyBytes); PrivateKey privateKey2 = keyFactory.generatePrivate(privateKeySpec); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImportInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImportInterop.java index a58742f0..ac7c2f1c 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImportInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyImportInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,43 +23,19 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestECKeyImportInterop extends BaseTestInterop { +public class BaseTestECKeyImportInterop extends BaseTestJunit5Interop { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); - - // -------------------------------------------------------------------------- - // - // - public BaseTestECKeyImportInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // + @Test public void testCreateKeyPairECGenParamImport() throws Exception { - doCreateKeyPairECGenParamImport(providerName, interopProviderName); - doCreateKeyPairECGenParamImport(interopProviderName, providerName); + doCreateKeyPairECGenParamImport(getProviderName(), getInteropProviderName()); + doCreateKeyPairECGenParamImport(getInteropProviderName(), getProviderName()); } - // -------------------------------------------------------------------------- - // - // public void doCreateKeyPairECGenParamImport(String generateProviderName, String importProviderName) throws Exception { @@ -97,14 +73,15 @@ public void doCreateKeyPairECGenParamImport(String generateProviderName, assertTrue(Arrays.equals(privateKey2.getEncoded(), privKeyBytes)); } + @Test public void testCreateKeyPairECParamCustomCurveImport() throws Exception { - doCreateKeyPairECParamCustomCurveImport(providerName, interopProviderName); + doCreateKeyPairECParamCustomCurveImport(getProviderName(), getInteropProviderName()); if (System.getProperty("os.name").equals("z/OS")) { System.out.println( "SunEC doesn't have the necessary EC algorithms, test BaseTestECKeyImportInterop.testCreateKeyPairECParamCustomCurveImport() skipped."); return; } - doCreateKeyPairECParamCustomCurveImport(interopProviderName, providerName); + doCreateKeyPairECParamCustomCurveImport(getInteropProviderName(), getProviderName()); } public void doCreateKeyPairECParamCustomCurveImport(String createProviderName, diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyPairGenerator.java index f134bcb6..2e89e947 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestECKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -18,48 +18,42 @@ import java.security.spec.ECParameterSpec; import java.security.spec.ECPoint; import java.security.spec.EllipticCurve; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestECKeyPairGenerator extends BaseTest { +public class BaseTestECKeyPairGenerator extends BaseTestJunit5 { KeyPairGenerator kpg = null; KeyPairGenerator kpgc = null; - public BaseTestECKeyPairGenerator(String providerName) { - super(providerName); - - } - - @Before - @Override - protected void setUp() throws Exception { - super.setUp(); - kpg = KeyPairGenerator.getInstance("EC", providerName); - kpgc = KeyPairGenerator.getInstance("EC", providerName); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @BeforeEach + public void setUp() throws Exception { + kpg = KeyPairGenerator.getInstance("EC", getProviderName()); + kpgc = KeyPairGenerator.getInstance("EC", getProviderName()); } + @Test public void testECKeyGen_192() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS no longer supports P-192 key gen return; } doECKeyGen(192); } + @Test public void testECKeyGen_256() throws Exception { doECKeyGen(256); } + @Test public void testECKeyGen_384() throws Exception { doECKeyGen(384); } + @Test public void testECKeyGen_521() throws Exception { doECKeyGen(521); } @@ -107,6 +101,7 @@ public void compareEcParameterSpec(ECParameterSpec ecParameterSpecPub, } + @Test public void testECKeyGenCurves_secp192k1() throws Exception { generictestECKeyGenCurve("secp192k1"); generictestECKeyGenCurve("1.3.132.0.31"); @@ -114,8 +109,9 @@ public void testECKeyGenCurves_secp192k1() throws Exception { } + @Test public void testPrintECCurves() throws Exception { - if (providerName.equalsIgnoreCase("OpenJCEPlus")) { + if (getProviderName().equalsIgnoreCase("OpenJCEPlus")) { generictestECKeyGenCurve("secp112r1"); generictestECKeyGenCurve("1.3.132.0.6"); @@ -218,6 +214,7 @@ public void testPrintECCurves() throws Exception { } + @Test public void testUnsupportedCurveNames() throws Exception { try { generictestECKeyGenCurve("NIST P-1929"); @@ -233,7 +230,7 @@ public void testUnsupportedCurveNames() throws Exception { assertTrue(true); } - if (providerName.equalsIgnoreCase("OpenJCEPlusFIPS")) { + if (getProviderName().equalsIgnoreCase("OpenJCEPlusFIPS")) { try { generictestECKeyGenCurve("secp112r1"); assertTrue(false); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignature.java b/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignature.java index 842aa746..048bebc9 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignature.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test; import static org.junit.Assert.assertTrue; -public class BaseTestEdDSASignature extends BaseTestSignature { +public class BaseTestEdDSASignature extends BaseTestJunit5Signature { static final byte[] origMsg = "this is the original message to be signed".getBytes(); @@ -270,7 +270,6 @@ private void runSignTest(String algorithm, AlgorithmParameterSpec params, String assertTrue("Signature verification failed", sig.verify(computedSig)); } - @Test public void testRunBasicEdDSATests() throws Exception { runBasicTest("EdDSA", null); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignatureInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignatureInterop.java index 8a205aec..2967f6ac 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignatureInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestEdDSASignatureInterop.java @@ -26,9 +26,8 @@ import org.bouncycastle.crypto.signers.Ed448Signer; import org.junit.jupiter.api.Test; import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertTrue; -public class BaseTestEdDSASignatureInterop extends BaseTestSignature { +public class BaseTestEdDSASignatureInterop extends BaseTestJunit5Signature { static final byte[] origMsg = "this is the original message to be signed".getBytes(); @@ -54,9 +53,7 @@ private KeyPair generateKeyPair(String alg) throws Exception { return xecKeyPairGen.generateKeyPair(); } - //-------------------------------------------------------------------------- - // - // + //Sign the message with OpenJCEPlus provided EdDSA private byte[] doSign(String sigAlgo, byte[] message, PrivateKey privateKey) throws Exception { Signature signing = Signature.getInstance(sigAlgo, getProviderName()); @@ -66,9 +63,7 @@ private byte[] doSign(String sigAlgo, byte[] message, PrivateKey privateKey) thr return signedBytes; } - //-------------------------------------------------------------------------- - // - // + //Verify the message with BouncyCastle provided Ed25519 protected void doVerifyEd25519(byte[] message, byte[] signedBytes, PublicKey publicKey) throws Exception { @@ -87,9 +82,7 @@ protected void doVerifyEd25519(byte[] message, byte[] signedBytes, PublicKey pub assertTrue("Signature verification failed ", signer.verifySignature(signedBytes)); } - //-------------------------------------------------------------------------- - // - // + //Verify the message with BouncyCastle provided Ed448 protected void doVerifyEd448(byte[] message, byte[] signedBytes, PublicKey publicKey) throws Exception { diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHKDF.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHKDF.java index adb8e0f4..f4d1969e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHKDF.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -32,8 +32,10 @@ import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHKDF extends ibm.jceplus.junit.base.BaseTest { +public class BaseTestHKDF extends BaseTestJunit5 { public String testName; public String algName; @@ -122,75 +124,62 @@ public class BaseTestHKDF extends ibm.jceplus.junit.base.BaseTest { + "b3bae548aa53d423b0d1f27ebba6f5e5" + "673a081d70cce7acfc48", "42"},}; - // -------------------------------------------------------------------------- - // - // - public BaseTestHKDF(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception { - - } - - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - + @Test public void testHKDF1() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1. So skip the test return; } - aesHKDF(128, "kda-hkdf-with-sha1", "AES", "AES", providerName); - aesHKDF(128, "kda-hkdf-with-sha-1", "AES", "AES", providerName); + aesHKDF(128, "kda-hkdf-with-sha1", "AES", "AES", getProviderName()); + aesHKDF(128, "kda-hkdf-with-sha-1", "AES", "AES", getProviderName()); } + @Test public void testHKDF224() throws Exception { - aesHKDF(192, "kda-hkdf-with-sha224", "AES", "AES", providerName); - aesHKDF(192, "kda-hkdf-with-sha-224", "AES", "AES", providerName); + aesHKDF(192, "kda-hkdf-with-sha224", "AES", "AES", getProviderName()); + aesHKDF(192, "kda-hkdf-with-sha-224", "AES", "AES", getProviderName()); } + @Test public void testHKDF256() throws Exception { - aesHKDF(192, "kda-hkdf-with-sha256", "AES", "AES", providerName); - aesHKDF(192, "kda-hkdf-with-sha-256", "AES", "AES", providerName); + aesHKDF(192, "kda-hkdf-with-sha256", "AES", "AES", getProviderName()); + aesHKDF(192, "kda-hkdf-with-sha-256", "AES", "AES", getProviderName()); } + @Test public void testHKDF384() throws Exception { - aesHKDF(256, "kda-hkdf-with-sha384", "AES", "AES", providerName); - aesHKDF(256, "kda-hkdf-with-sha-384", "AES", "AES", providerName); + aesHKDF(256, "kda-hkdf-with-sha384", "AES", "AES", getProviderName()); + aesHKDF(256, "kda-hkdf-with-sha-384", "AES", "AES", getProviderName()); } + @Test public void testHKDF512() throws Exception { - aesHKDF(256, "kda-hkdf-with-sha512", "AES", "AES", providerName); - aesHKDF(256, "kda-hkdf-with-sha-512", "AES", "AES", providerName); + aesHKDF(256, "kda-hkdf-with-sha512", "AES", "AES", getProviderName()); + aesHKDF(256, "kda-hkdf-with-sha-512", "AES", "AES", getProviderName()); } + @Test public void test3DesHKDF256() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String curveName = "secp256r1"; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 3DES. So skip the test return; } ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, providerName, providerName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getProviderName(), getProviderName()); HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, (long) (192 / 8), "DESede"); - KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", providerName); + KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", getProviderName()); hkdfDerive.init(hkdfDeriveSpec); SecretKey calcOkm = hkdfDerive.generateKey(); String strToEncrypt = "Hello string to be encrypted"; @@ -200,13 +189,14 @@ public void test3DesHKDF256() throws InvalidKeyException, NoSuchAlgorithmExcepti } + @Test public void testLongOKM() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, providerName, providerName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getProviderName(), getProviderName()); try { new HKDFParameterSpec(sharedSecret, null, null, @@ -218,6 +208,7 @@ public void testLongOKM() throws InvalidKeyException, NoSuchAlgorithmException, } + @Test public void testInvalidKeyAlgorithms1() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { @@ -234,8 +225,7 @@ public void testInvalidKeyAlgorithms1() throws InvalidKeyException, NoSuchAlgori } - - + @Test public void testInvalidKeyAlgorithms2() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { @@ -246,7 +236,7 @@ public void testInvalidKeyAlgorithms2() throws InvalidKeyException, NoSuchAlgori HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, (long) ((255 * 40)), "AES"); KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); hkdfDerive.init(hkdfDeriveSpec); assertTrue(false); } catch (InvalidAlgorithmParameterException iae) { @@ -255,22 +245,23 @@ public void testInvalidKeyAlgorithms2() throws InvalidKeyException, NoSuchAlgori } + @Test public void testEcdhHKDF1() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1. Skip test return; } String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, providerName, providerName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getProviderName(), getProviderName()); HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, (long) (192 / 8), "AES"); - KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha1", providerName); + KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha1", getProviderName()); hkdfDerive.init(hkdfDeriveSpec); SecretKey calcOkm = hkdfDerive.generateKey(); String strToEncrypt = "Hello string to be encrypted"; @@ -280,17 +271,18 @@ public void testEcdhHKDF1() throws InvalidKeyException, NoSuchAlgorithmException } + @Test public void testEcdhHKDF256() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, providerName, providerName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getProviderName(), getProviderName()); HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, (long) (256 / 8), "AES"); - KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", providerName); + KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", getProviderName()); hkdfDerive.init(hkdfDeriveSpec); SecretKey calcOkm = hkdfDerive.generateKey(); String strToEncrypt = "Hello string to be encrypted"; @@ -300,17 +292,18 @@ public void testEcdhHKDF256() throws InvalidKeyException, NoSuchAlgorithmExcepti } + @Test public void testEcdhHKDF512() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, providerName, providerName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getProviderName(), getProviderName()); HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, (long) (256 / 8), "AES"); - KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha512", providerName); + KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha512", getProviderName()); hkdfDerive.init(hkdfDeriveSpec); SecretKey calcOkm = hkdfDerive.generateKey(); String strToEncrypt = "Hello string to be encrypted"; @@ -415,6 +408,7 @@ private static byte[] hexStringToByteArray(String string) { return b; } + @Test public void testThroguhProvider() throws Exception { try { // HKDF hkdf = HKDF.getInstance("kda-hkdf-with-sha256", providerName); @@ -437,7 +431,7 @@ public void testThroguhProvider() throws Exception { // System.out.println("i=" + i); if (digestAlgo.equals("SHA256")) { KeyGenerator hkdfExtract = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); // System.out.println("HKDF digest algorithm " + // hkdfExtract.getDigestAlgorithm()); @@ -454,7 +448,7 @@ public void testThroguhProvider() throws Exception { assert (prkequal == true); KeyGenerator hkdfExpand = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); HKDFExpandParameterSpec expandSpec = new HKDFExpandParameterSpec(prkArray, infoArray, okmLength, "TlsEarlySecret"); hkdfExpand.init(expandSpec); @@ -465,12 +459,12 @@ public void testThroguhProvider() throws Exception { assert (okmequal == true); assert (calcOkmArray.length == okmLength); } else { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1. Skip test break; } KeyGenerator hkdfExtract = KeyGenerator.getInstance("kda-hkdf-with-sha1", - providerName); + getProviderName()); // System.out.println("HKDF digest algorithm " + // hkdfExtract.getDigestAlgorithm()); @@ -487,7 +481,7 @@ public void testThroguhProvider() throws Exception { assert (prkequal == true); KeyGenerator hkdfExpand = KeyGenerator.getInstance("kda-hkdf-with-sha1", - providerName); + getProviderName()); HKDFExpandParameterSpec expandSpec = new HKDFExpandParameterSpec(prkArray, infoArray, okmLength, "TlsEarlySecret"); hkdfExpand.init(expandSpec); @@ -516,6 +510,7 @@ public void testThroguhProvider() throws Exception { } // One OCK call does both extract and derive + @Test public void testDerive() throws Exception { try { @@ -537,7 +532,7 @@ public void testDerive() throws Exception { // System.out.println("i=" + i); if (digestAlgo.equals("SHA256")) { KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); // System.out.println("HKDF digest algorithm " + // hkdfExtract.getDigestAlgorithm()); @@ -554,13 +549,13 @@ public void testDerive() throws Exception { assert (okmequal == true); assert (calcOkmArray.length == okmLength); } else { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1. Skip test break; } KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha1", - providerName); + getProviderName()); // System.out.println("HKDF digest algorithm " + // hkdfExtract.getDigestAlgorithm()); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHKDFInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHKDFInterop.java index b6b8929b..f1f52f80 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHKDFInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHKDFInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -32,8 +32,10 @@ import org.bouncycastle.crypto.digests.SHA256Digest; import org.bouncycastle.crypto.generators.HKDFBytesGenerator; import org.bouncycastle.crypto.params.HKDFParameters; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHKDFInterop extends BaseTestInterop { +public class BaseTestHKDFInterop extends BaseTestJunit5Interop { String HKDF_KA[][] = { {"SHA256", "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", @@ -110,10 +112,7 @@ public class BaseTestHKDFInterop extends BaseTestInterop { + "b3bae548aa53d423b0d1f27ebba6f5e5" + "673a081d70cce7acfc48", "42"},}; - public BaseTestHKDFInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - + @Test public void testJcePlustoBC() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { @@ -135,7 +134,7 @@ public void testJcePlustoBC() throws InvalidAlgorithmParameterException, if (digestAlgo.equals("SHA256")) { KeyGenerator hkdfExtract = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); if (HKDF_KA[i][2].equals("")) { @@ -150,7 +149,7 @@ public void testJcePlustoBC() throws InvalidAlgorithmParameterException, boolean prkequal = Arrays.equals(prkArray, calcPrkArray); assert (prkequal == true); KeyGenerator hkdfExpand = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); HKDFExpandParameterSpec expandSpec = new HKDFExpandParameterSpec(prkArray, infoArray, okmLength, "TlsEarlySecret"); hkdfExpand.init(expandSpec); @@ -175,13 +174,13 @@ public void testJcePlustoBC() throws InvalidAlgorithmParameterException, } else { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1. Skip test break; } KeyGenerator hkdfExtract = KeyGenerator.getInstance("kda-hkdf-with-sha1", - providerName); + getProviderName()); if (HKDF_KA[i][2].equals("")) { @@ -197,7 +196,7 @@ public void testJcePlustoBC() throws InvalidAlgorithmParameterException, assert (prkequal == true); KeyGenerator hkdfExpand = KeyGenerator.getInstance("kda-hkdf-with-sha1", - providerName); + getProviderName()); HKDFExpandParameterSpec expandSpec = new HKDFExpandParameterSpec(prkArray, infoArray, okmLength, "TlsEarlySecret"); hkdfExpand.init(expandSpec); @@ -223,6 +222,7 @@ public void testJcePlustoBC() throws InvalidAlgorithmParameterException, } // One OCK call does both extract and derive + @Test public void testDerive() throws Exception { try { @@ -244,7 +244,7 @@ public void testDerive() throws Exception { if (digestAlgo.equals("SHA256")) { KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", - providerName); + getProviderName()); if (HKDF_KA[i][2].equals("")) { @@ -270,12 +270,12 @@ public void testDerive() throws Exception { hkdfBytesGeneratorBC.generateBytes(okmBC, 0, (int) okmLength); assertTrue(Arrays.equals(calcOkmArray, okmBC)); } else { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1. Skip test break; } KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha1", - providerName); + getProviderName()); if (HKDF_KA[i][2].equals("")) { @@ -311,37 +311,39 @@ public void testDerive() throws Exception { } } + @Test public void testEcdhHKDF256PlusToBC() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, providerName, providerName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getProviderName(), getProviderName()); HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, (long) (256 / 8), "AES"); - KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", providerName); + KeyGenerator hkdfDerive = KeyGenerator.getInstance("kda-hkdf-with-sha256", getProviderName()); hkdfDerive.init(hkdfDeriveSpec); SecretKey calcOkm = hkdfDerive.generateKey(); String strToEncrypt = "Hello string to be encrypted"; byte[] encryptedBytes = encrypt(calcOkm, strToEncrypt, "AES/ECB/PKCS5Padding"); String plainStr = decrypt(calcOkm, encryptedBytes, "AES/ECB/PKCS5Padding", - interopProviderName); + getInteropProviderName()); assertTrue(plainStr.equals(strToEncrypt)); } + @Test public void testEcdhHKDF256BCtoPlus() throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String curveName = "secp256r1"; ECGenParameterSpec ecgn = new ECGenParameterSpec(curveName); - byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, interopProviderName, - interopProviderName); + byte[] sharedSecret = compute_ecdh_key(curveName, ecgn, getInteropProviderName(), + getInteropProviderName()); HKDFParameterSpec hkdfDeriveSpec = new HKDFParameterSpec(sharedSecret, null, null, @@ -351,7 +353,7 @@ public void testEcdhHKDF256BCtoPlus() throws InvalidKeyException, NoSuchAlgorith SecretKey calcOkm = hkdfDerive.generateKey(); String strToEncrypt = "Hello string to be encrypted"; byte[] encryptedBytes = encrypt(calcOkm, strToEncrypt, "AES/ECB/PKCS5Padding", - interopProviderName); + getInteropProviderName()); String plainStr = decrypt(calcOkm, encryptedBytes, "AES/ECB/PKCS5Padding"); assertTrue(plainStr.equals(strToEncrypt)); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5.java index 261572d8..305dd877 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,10 +10,10 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacMD5 extends BaseTest { - static boolean warmup = false; - +public class BaseTestHmacMD5 extends BaseTestJunit5 { final byte[] key_1 = {(byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b}; @@ -157,29 +157,10 @@ public class BaseTestHmacMD5 extends BaseTest { (byte) 0xcd, (byte) 0xa0, (byte) 0xee, (byte) 0x1f, (byte) 0xb1, (byte) 0xf5, (byte) 0x62, (byte) 0xdb, (byte) 0x3a, (byte) 0xa5, (byte) 0x3e}; - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacMD5(String providerName) { - - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key1() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacMD5"); mac.init(key); mac.update(data_1); @@ -189,11 +170,9 @@ public void testHmacMD5_key1() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key2() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacMD5"); mac.init(key); mac.update(data_2); @@ -203,12 +182,10 @@ public void testHmacMD5_key2() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key3() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacMD5"); mac.init(key); mac.update(data_3); @@ -218,12 +195,10 @@ public void testHmacMD5_key3() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key4() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacMD5"); mac.init(key); mac.update(data_4); @@ -233,12 +208,10 @@ public void testHmacMD5_key4() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key5() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_5, "HmacMD5"); mac.init(key); mac.update(data_5); @@ -248,12 +221,10 @@ public void testHmacMD5_key5() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key6() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_6, "HmacMD5"); mac.init(key); mac.update(data_6); @@ -263,12 +234,10 @@ public void testHmacMD5_key6() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacMD5_key7() throws Exception { - Mac mac = Mac.getInstance("HmacMD5", providerName); + Mac mac = Mac.getInstance("HmacMD5", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_7, "HmacMD5"); mac.init(key); mac.update(data_7); @@ -277,22 +246,4 @@ public void testHmacMD5_key7() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_7)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacMD5", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacMD5"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5Interop.java index 363988b5..c17f8697 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5Interop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacMD5Interop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,11 +12,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -public class BaseTestHmacMD5Interop extends BaseTestInterop { - static boolean warmup = false; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +public class BaseTestHmacMD5Interop extends BaseTestJunit5Interop { final byte[] key_1 = {(byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b}; @@ -160,126 +159,77 @@ public class BaseTestHmacMD5Interop extends BaseTestInterop { (byte) 0xcd, (byte) 0xa0, (byte) 0xee, (byte) 0x1f, (byte) 0xb1, (byte) 0xf5, (byte) 0x62, (byte) 0xdb, (byte) 0x3a, (byte) 0xa5, (byte) 0x3e}; - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacMD5Interop(String providerName, String interopProviderName) { - - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void test_data1() throws Exception { - doHmac(data_1, providerName, interopProviderName); - doHmac(data_1, interopProviderName, providerName); + doHmac(data_1, getProviderName(), getInteropProviderName()); + doHmac(data_1, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data2() throws Exception { - doHmac(data_2, providerName, interopProviderName); - doHmac(data_2, interopProviderName, providerName); + doHmac(data_2, getProviderName(), getInteropProviderName()); + doHmac(data_2, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data3() throws Exception { - doHmac(data_3, providerName, interopProviderName); - doHmac(data_3, interopProviderName, providerName); + doHmac(data_3, getProviderName(), getInteropProviderName()); + doHmac(data_3, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data4() throws Exception { - doHmac(data_4, providerName, interopProviderName); - doHmac(data_4, interopProviderName, providerName); + doHmac(data_4, getProviderName(), getInteropProviderName()); + doHmac(data_4, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data5() throws Exception { - doHmac(data_5, providerName, interopProviderName); - doHmac(data_5, interopProviderName, providerName); + doHmac(data_5, getProviderName(), getInteropProviderName()); + doHmac(data_5, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data6() throws Exception { - doHmac(data_6, providerName, interopProviderName); - doHmac(data_6, interopProviderName, providerName); + doHmac(data_6, getProviderName(), getInteropProviderName()); + doHmac(data_6, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data7() throws Exception { - doHmac(data_7, providerName, interopProviderName); - doHmac(data_7, interopProviderName, providerName); + doHmac(data_7, getProviderName(), getInteropProviderName()); + doHmac(data_7, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_512() throws Exception { byte[] data_512 = new byte[512]; Random r = new Random(10); r.nextBytes(data_512); - doHmac(data_512, providerName, interopProviderName); - doHmac(data_512, interopProviderName, providerName); + doHmac(data_512, getProviderName(), getInteropProviderName()); + doHmac(data_512, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_2048() throws Exception { byte[] data_2048 = new byte[2048]; Random r = new Random(10); r.nextBytes(data_2048); - doHmac(data_2048, providerName, interopProviderName); - doHmac(data_2048, interopProviderName, providerName); + doHmac(data_2048, getProviderName(), getInteropProviderName()); + doHmac(data_2048, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_8192() throws Exception { byte[] data_8192 = new byte[8192]; Random r = new Random(10); r.nextBytes(data_8192); - doHmac(data_8192, providerName, interopProviderName); - doHmac(data_8192, interopProviderName, providerName); + doHmac(data_8192, getProviderName(), getInteropProviderName()); + doHmac(data_8192, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected void doHmac(byte[] data, String provider, String interopProvider) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5", provider); SecretKey key = keyGen.generateKey(); @@ -296,23 +246,5 @@ protected void doHmac(byte[] data, String provider, String interopProvider) thro assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest2)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacMD5", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacMD5"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1.java index 60f6c5ac..ce9786cc 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,12 +10,10 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA1 extends BaseTest { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +public class BaseTestHmacSHA1 extends BaseTestJunit5 { static final byte[] key_1 = {(byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, @@ -181,37 +179,9 @@ public class BaseTestHmacSHA1 extends BaseTest { (byte) 0x7b, (byte) 0xe1, (byte) 0xd5, (byte) 0x8b, (byte) 0xb9, (byte) 0x32, (byte) 0x4a, (byte) 0x9a, (byte) 0x5a, (byte) 0x04}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA1(String providerName) { - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA1"); mac.init(key); mac.update(data_1); @@ -220,11 +190,9 @@ public void testHmacSHA1_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA1"); mac.init(key); mac.update(data_2); @@ -233,11 +201,9 @@ public void testHmacSHA1_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA1"); mac.init(key); mac.update(data_3); @@ -246,11 +212,9 @@ public void testHmacSHA1_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key4() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA1"); mac.init(key); mac.update(data_4); @@ -259,11 +223,9 @@ public void testHmacSHA1_key4() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key5() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_5, "HmacSHA1"); mac.init(key); mac.update(data_5); @@ -272,11 +234,9 @@ public void testHmacSHA1_key5() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_5)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key6() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_6, "HmacSHA1"); mac.init(key); mac.update(data_6); @@ -285,11 +245,9 @@ public void testHmacSHA1_key6() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_6)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA1_key7() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_7, "HmacSHA1"); mac.init(key); mac.update(data_7); @@ -298,11 +256,9 @@ public void testHmacSHA1_key7() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_7)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA1"); mac.init(key); mac.update(data_4); @@ -313,11 +269,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA1"); mac.init(key); mac.update(data_4); @@ -331,32 +285,13 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA1", providerName); + Mac mac = Mac.getInstance("HmacSHA1", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 20); assertTrue("Unexpected mac length", isExpectedValue); } - - - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA1", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA1"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1Interop.java index 4126a6eb..3ed6ac0d 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1Interop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA1Interop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,13 +12,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA1Interop extends BaseTestInterop { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +public class BaseTestHmacSHA1Interop extends BaseTestJunit5Interop { static final byte[] key_1 = {(byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, (byte) 0x0b, @@ -184,124 +181,76 @@ public class BaseTestHmacSHA1Interop extends BaseTestInterop { (byte) 0x7b, (byte) 0xe1, (byte) 0xd5, (byte) 0x8b, (byte) 0xb9, (byte) 0x32, (byte) 0x4a, (byte) 0x9a, (byte) 0x5a, (byte) 0x04}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA1Interop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void test_data1() throws Exception { - doHmac(data_1, providerName, interopProviderName); - doHmac(data_1, interopProviderName, providerName); + doHmac(data_1, getProviderName(), getInteropProviderName()); + doHmac(data_1, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data2() throws Exception { - doHmac(data_2, providerName, interopProviderName); - doHmac(data_2, interopProviderName, providerName); + doHmac(data_2, getProviderName(), getInteropProviderName()); + doHmac(data_2, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data3() throws Exception { - doHmac(data_3, providerName, interopProviderName); - doHmac(data_3, interopProviderName, providerName); + doHmac(data_3, getProviderName(), getInteropProviderName()); + doHmac(data_3, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data4() throws Exception { - doHmac(data_4, providerName, interopProviderName); - doHmac(data_4, interopProviderName, providerName); + doHmac(data_4, getProviderName(), getInteropProviderName()); + doHmac(data_4, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data5() throws Exception { - doHmac(data_5, providerName, interopProviderName); - doHmac(data_5, interopProviderName, providerName); + doHmac(data_5, getProviderName(), getInteropProviderName()); + doHmac(data_5, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data6() throws Exception { - doHmac(data_6, providerName, interopProviderName); - doHmac(data_6, interopProviderName, providerName); + doHmac(data_6, getProviderName(), getInteropProviderName()); + doHmac(data_6, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data7() throws Exception { - doHmac(data_7, providerName, interopProviderName); - doHmac(data_7, interopProviderName, providerName); + doHmac(data_7, getProviderName(), getInteropProviderName()); + doHmac(data_7, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_512() throws Exception { byte[] data_512 = new byte[512]; Random r = new Random(10); r.nextBytes(data_512); - doHmac(data_512, providerName, interopProviderName); - doHmac(data_512, interopProviderName, providerName); + doHmac(data_512, getProviderName(), getInteropProviderName()); + doHmac(data_512, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_2048() throws Exception { byte[] data_2048 = new byte[2048]; Random r = new Random(10); r.nextBytes(data_2048); - doHmac(data_2048, providerName, interopProviderName); - doHmac(data_2048, interopProviderName, providerName); + doHmac(data_2048, getProviderName(), getInteropProviderName()); + doHmac(data_2048, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_8192() throws Exception { byte[] data_8192 = new byte[8192]; Random r = new Random(10); r.nextBytes(data_8192); - doHmac(data_8192, providerName, interopProviderName); - doHmac(data_8192, interopProviderName, providerName); + doHmac(data_8192, getProviderName(), getInteropProviderName()); + doHmac(data_8192, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected void doHmac(byte[] data, String provider, String interopProvider) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA1", provider); SecretKey key = keyGen.generateKey(); @@ -318,24 +267,5 @@ protected void doHmac(byte[] data, String provider, String interopProvider) thro assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest2)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA1", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA1"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224.java index 23a45570..c43a039b 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,12 +11,10 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA224 extends BaseTest { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +public class BaseTestHmacSHA224 extends BaseTestJunit5 { // test vectors from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_SHA224.pdf static final byte[] key_1 = {(byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, @@ -98,37 +96,9 @@ public class BaseTestHmacSHA224 extends BaseTest { (byte) 0x6c, (byte) 0xa4, (byte) 0xb4, (byte) 0xb1, (byte) 0xc2, (byte) 0x3d, (byte) 0x27, (byte) 0xbd, (byte) 0xe0, (byte) 0x67, (byte) 0xd6,}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA224(String providerName) { - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA224_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA224"); mac.init(key); mac.update(data_1); @@ -137,11 +107,9 @@ public void testHmacSHA224_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA224_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA224"); mac.init(key); mac.update(data_2); @@ -150,11 +118,9 @@ public void testHmacSHA224_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA224_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA224"); mac.init(key); mac.update(data_3); @@ -163,11 +129,9 @@ public void testHmacSHA224_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA224_key4() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA224"); mac.init(key); mac.update(data_4); @@ -179,11 +143,9 @@ public void testHmacSHA224_key4() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(truncatedDigest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA224"); mac.init(key); mac.update(data_3); @@ -194,11 +156,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA224"); mac.init(key); mac.update(data_3); @@ -212,32 +172,12 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA224", providerName); + Mac mac = Mac.getInstance("HmacSHA224", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 28); assertTrue("Unexpected mac length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA224", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA224"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224Interop.java index ee2c0a76..82e96465 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224Interop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA224Interop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,13 +12,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA224Interop extends BaseTestInterop { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +public class BaseTestHmacSHA224Interop extends BaseTestJunit5Interop { // test vectors from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_SHA224.pdf static final byte[] key_1 = {(byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, @@ -100,92 +97,52 @@ public class BaseTestHmacSHA224Interop extends BaseTestInterop { (byte) 0x6c, (byte) 0xa4, (byte) 0xb4, (byte) 0xb1, (byte) 0xc2, (byte) 0x3d, (byte) 0x27, (byte) 0xbd, (byte) 0xe0, (byte) 0x67, (byte) 0xd6,}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA224Interop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void test_data1() throws Exception { - doHmac(data_1, providerName, interopProviderName); - doHmac(data_1, interopProviderName, providerName); + doHmac(data_1, getProviderName(), getInteropProviderName()); + doHmac(data_1, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data2() throws Exception { - doHmac(data_2, providerName, interopProviderName); - doHmac(data_2, interopProviderName, providerName); + doHmac(data_2, getProviderName(), getInteropProviderName()); + doHmac(data_2, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data3() throws Exception { - doHmac(data_3, providerName, interopProviderName); - doHmac(data_3, interopProviderName, providerName); + doHmac(data_3, getProviderName(), getInteropProviderName()); + doHmac(data_3, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_512() throws Exception { byte[] data_512 = new byte[512]; Random r = new Random(10); r.nextBytes(data_512); - doHmac(data_512, providerName, interopProviderName); - doHmac(data_512, interopProviderName, providerName); + doHmac(data_512, getProviderName(), getInteropProviderName()); + doHmac(data_512, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_2048() throws Exception { byte[] data_2048 = new byte[2048]; Random r = new Random(10); r.nextBytes(data_2048); - doHmac(data_2048, providerName, interopProviderName); - doHmac(data_2048, interopProviderName, providerName); + doHmac(data_2048, getProviderName(), getInteropProviderName()); + doHmac(data_2048, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_8192() throws Exception { byte[] data_8192 = new byte[8192]; Random r = new Random(10); r.nextBytes(data_8192); - doHmac(data_8192, providerName, interopProviderName); - doHmac(data_8192, interopProviderName, providerName); + doHmac(data_8192, getProviderName(), getInteropProviderName()); + doHmac(data_8192, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected void doHmac(byte[] data, String provider, String interopProvider) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA224", provider); SecretKey key = keyGen.generateKey(); @@ -202,23 +159,5 @@ protected void doHmac(byte[] data, String provider, String interopProvider) thro assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest2)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA224", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA224"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256.java index b6104615..49b557f1 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,12 +10,10 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA256 extends BaseTest { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +public class BaseTestHmacSHA256 extends BaseTestJunit5 { // test vectors from http://www.ietf.org/proceedings/02jul/I-D/draft-ietf-ipsec-ciph-sha-256-01.txt final byte[] key_1 = {(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, @@ -271,37 +269,9 @@ public class BaseTestHmacSHA256 extends BaseTest { (byte) 0xfc, (byte) 0x2a, (byte) 0xc7, (byte) 0xd8, (byte) 0xe0, (byte) 0x64, (byte) 0xc3, (byte) 0xb2, (byte) 0xe6}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA256(String providerName) { - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA256"); mac.init(key); mac.update(data_1); @@ -310,11 +280,9 @@ public void testHmacSHA256_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA256"); mac.init(key); mac.update(data_2); @@ -323,11 +291,9 @@ public void testHmacSHA256_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA256"); mac.init(key); mac.update(data_3); @@ -336,11 +302,9 @@ public void testHmacSHA256_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key4() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA256"); mac.init(key); mac.update(data_4); @@ -349,11 +313,9 @@ public void testHmacSHA256_key4() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key5() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_5, "HmacSHA256"); mac.init(key); mac.update(data_5); @@ -362,11 +324,9 @@ public void testHmacSHA256_key5() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_5)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key6() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_6, "HmacSHA256"); mac.init(key); mac.update(data_6); @@ -375,11 +335,9 @@ public void testHmacSHA256_key6() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_6)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key7() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_7, "HmacSHA256"); mac.init(key); mac.update(data_7); @@ -388,11 +346,9 @@ public void testHmacSHA256_key7() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_7)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key8() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_8, "HmacSHA256"); mac.init(key); mac.update(data_8); @@ -401,11 +357,9 @@ public void testHmacSHA256_key8() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_8)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key9() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_9, "HmacSHA256"); mac.init(key); mac.update(data_9); @@ -414,11 +368,9 @@ public void testHmacSHA256_key9() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_9)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA256_key10() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_10, "HmacSHA256"); mac.init(key); mac.update(data_10); @@ -427,11 +379,9 @@ public void testHmacSHA256_key10() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_10)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA256"); mac.init(key); mac.update(data_4); @@ -442,11 +392,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA256"); mac.init(key); mac.update(data_4); @@ -460,32 +408,12 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA256", providerName); + Mac mac = Mac.getInstance("HmacSHA256", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 32); assertTrue("Unexpected mac length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA256", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA256"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256Interop.java index 3feb4f5e..f37a16d5 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256Interop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA256Interop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,14 +12,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -public class BaseTestHmacSHA256Interop extends BaseTestInterop { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +public class BaseTestHmacSHA256Interop extends BaseTestJunit5Interop { // test vectors from http://www.ietf.org/proceedings/02jul/I-D/draft-ietf-ipsec-ciph-sha-256-01.txt final byte[] key_1 = {(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b, @@ -274,148 +270,94 @@ public class BaseTestHmacSHA256Interop extends BaseTestInterop { (byte) 0xfc, (byte) 0x2a, (byte) 0xc7, (byte) 0xd8, (byte) 0xe0, (byte) 0x64, (byte) 0xc3, (byte) 0xb2, (byte) 0xe6}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA256Interop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void test_data1() throws Exception { - doHmac(data_1, providerName, interopProviderName); - doHmac(data_1, interopProviderName, providerName); + doHmac(data_1, getProviderName(), getInteropProviderName()); + doHmac(data_1, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data2() throws Exception { - doHmac(data_2, providerName, interopProviderName); - doHmac(data_2, interopProviderName, providerName); + doHmac(data_2, getProviderName(), getInteropProviderName()); + doHmac(data_2, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data3() throws Exception { - doHmac(data_3, providerName, interopProviderName); - doHmac(data_3, interopProviderName, providerName); + doHmac(data_3, getProviderName(), getInteropProviderName()); + doHmac(data_3, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data4() throws Exception { - doHmac(data_4, providerName, interopProviderName); - doHmac(data_4, interopProviderName, providerName); + doHmac(data_4, getProviderName(), getInteropProviderName()); + doHmac(data_4, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data5() throws Exception { - doHmac(data_5, providerName, interopProviderName); - doHmac(data_5, interopProviderName, providerName); + doHmac(data_5, getProviderName(), getInteropProviderName()); + doHmac(data_5, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data6() throws Exception { - doHmac(data_6, providerName, interopProviderName); - doHmac(data_6, interopProviderName, providerName); + doHmac(data_6, getProviderName(), getInteropProviderName()); + doHmac(data_6, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data7() throws Exception { - doHmac(data_7, providerName, interopProviderName); - doHmac(data_7, interopProviderName, providerName); + doHmac(data_7, getProviderName(), getInteropProviderName()); + doHmac(data_7, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data8() throws Exception { - doHmac(data_8, providerName, interopProviderName); - doHmac(data_8, interopProviderName, providerName); + doHmac(data_8, getProviderName(), getInteropProviderName()); + doHmac(data_8, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data9() throws Exception { - doHmac(data_9, providerName, interopProviderName); - doHmac(data_9, interopProviderName, providerName); + doHmac(data_9, getProviderName(), getInteropProviderName()); + doHmac(data_9, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data10() throws Exception { - doHmac(data_10, providerName, interopProviderName); - doHmac(data_10, interopProviderName, providerName); + doHmac(data_10, getProviderName(), getInteropProviderName()); + doHmac(data_10, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_512() throws Exception { byte[] data_512 = new byte[512]; Random r = new Random(10); r.nextBytes(data_512); - doHmac(data_512, providerName, interopProviderName); - doHmac(data_512, interopProviderName, providerName); + doHmac(data_512, getProviderName(), getInteropProviderName()); + doHmac(data_512, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_2048() throws Exception { byte[] data_2048 = new byte[2048]; Random r = new Random(10); r.nextBytes(data_2048); - doHmac(data_2048, providerName, interopProviderName); - doHmac(data_2048, interopProviderName, providerName); + doHmac(data_2048, getProviderName(), getInteropProviderName()); + doHmac(data_2048, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_8192() throws Exception { byte[] data_8192 = new byte[8192]; Random r = new Random(10); r.nextBytes(data_8192); - doHmac(data_8192, providerName, interopProviderName); - doHmac(data_8192, interopProviderName, providerName); + doHmac(data_8192, getProviderName(), getInteropProviderName()); + doHmac(data_8192, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected void doHmac(byte[] data, String provider, String interopProvider) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA256", provider); SecretKey key = keyGen.generateKey(); @@ -432,23 +374,5 @@ protected void doHmac(byte[] data, String provider, String interopProvider) thro assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest2)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA256", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA256"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384.java index d6f0482c..1de04820 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,13 +11,10 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA384 extends BaseTest { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; - +public class BaseTestHmacSHA384 extends BaseTestJunit5 { // test vectors from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_SHA384.pdf static final byte[] key_1 = BaseUtils.hexStringToByteArray( "0001020304050607" + "08090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" @@ -71,36 +68,9 @@ public class BaseTestHmacSHA384 extends BaseTest { static final byte[] digest_4 = BaseUtils .hexStringToByteArray("C48130D3DF703DD7CDAA56800DFBD2BA2458320E6E1F98FE"); - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA384(String providerName) { - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA384_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA384"); mac.init(key); mac.update(data_1); @@ -109,11 +79,9 @@ public void testHmacSHA384_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA384_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA384"); mac.init(key); mac.update(data_2); @@ -122,11 +90,9 @@ public void testHmacSHA384_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA384_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA384"); mac.init(key); mac.update(data_3); @@ -135,11 +101,9 @@ public void testHmacSHA384_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA384_key4() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA384"); mac.init(key); mac.update(data_4); @@ -152,11 +116,9 @@ public void testHmacSHA384_key4() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(truncatedDigest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA384"); mac.init(key); mac.update(data_1); @@ -167,11 +129,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA384"); mac.init(key); mac.update(data_1); @@ -185,32 +145,12 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA384", providerName); + Mac mac = Mac.getInstance("HmacSHA384", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 48); assertTrue("Unexpected mac length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA384", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA384"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384Interop.java index 1912a521..ff80a870 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384Interop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA384Interop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,14 +12,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -public class BaseTestHmacSHA384Interop extends BaseTestInterop { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +public class BaseTestHmacSHA384Interop extends BaseTestJunit5Interop { // test vectors from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_SHA384.pdf static final byte[] key_1 = BaseUtils.hexStringToByteArray( "0001020304050607" + "08090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" @@ -73,99 +69,58 @@ public class BaseTestHmacSHA384Interop extends BaseTestInterop { static final byte[] digest_4 = BaseUtils .hexStringToByteArray("C48130D3DF703DD7CDAA56800DFBD2BA2458320E6E1F98FE"); - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA384Interop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void test_data1() throws Exception { - doHmac(data_1, providerName, interopProviderName); - doHmac(data_1, interopProviderName, providerName); + doHmac(data_1, getProviderName(), getInteropProviderName()); + doHmac(data_1, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data2() throws Exception { - doHmac(data_2, providerName, interopProviderName); - doHmac(data_2, interopProviderName, providerName); + doHmac(data_2, getProviderName(), getInteropProviderName()); + doHmac(data_2, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data3() throws Exception { - doHmac(data_3, providerName, interopProviderName); - doHmac(data_3, interopProviderName, providerName); + doHmac(data_3, getProviderName(), getInteropProviderName()); + doHmac(data_3, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data4() throws Exception { - doHmac(data_4, providerName, interopProviderName); - doHmac(data_4, interopProviderName, providerName); + doHmac(data_4, getProviderName(), getInteropProviderName()); + doHmac(data_4, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_512() throws Exception { byte[] data_512 = new byte[512]; Random r = new Random(10); r.nextBytes(data_512); - doHmac(data_512, providerName, interopProviderName); - doHmac(data_512, interopProviderName, providerName); + doHmac(data_512, getProviderName(), getInteropProviderName()); + doHmac(data_512, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_2048() throws Exception { byte[] data_2048 = new byte[2048]; Random r = new Random(10); r.nextBytes(data_2048); - doHmac(data_2048, providerName, interopProviderName); - doHmac(data_2048, interopProviderName, providerName); + doHmac(data_2048, getProviderName(), getInteropProviderName()); + doHmac(data_2048, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_8192() throws Exception { byte[] data_8192 = new byte[8192]; Random r = new Random(10); r.nextBytes(data_8192); - doHmac(data_8192, providerName, interopProviderName); - doHmac(data_8192, interopProviderName, providerName); + doHmac(data_8192, getProviderName(), getInteropProviderName()); + doHmac(data_8192, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected void doHmac(byte[] data, String provider, String interopProvider) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA384", provider); SecretKey key = keyGen.generateKey(); @@ -182,23 +137,5 @@ protected void doHmac(byte[] data, String provider, String interopProvider) thro assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest2)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA384", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA384"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_224.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_224.java index 4444aab0..e4dbb2ea 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,11 +11,11 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; + +public class BaseTestHmacSHA3_224 extends BaseTestJunit5 { -public class BaseTestHmacSHA3_224 extends BaseTest { - //-------------------------------------------------------------------------- - // - // // test vectors fromhttps://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values#aMsgAuth private static byte[] NISTKEY_172; @@ -69,28 +69,9 @@ public class BaseTestHmacSHA3_224 extends BaseTest { .hexStringToByteArray("078695eecc227c636ad31d063a15dd05a7e819a66ec6d8de1e193e59"); } - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA3_224(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_224_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-224", providerName); + Mac mac = Mac.getInstance("HmacSHA3-224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-224"); mac.init(key); mac.update(data_1); @@ -99,11 +80,9 @@ public void testHmacSHA3_224_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_224_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-224", providerName); + Mac mac = Mac.getInstance("HmacSHA3-224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA3-224"); mac.init(key); mac.update(data_2); @@ -112,11 +91,9 @@ public void testHmacSHA3_224_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_224_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-224", providerName); + Mac mac = Mac.getInstance("HmacSHA3-224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA3-224"); mac.init(key); mac.update(data_3); @@ -125,11 +102,9 @@ public void testHmacSHA3_224_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-224", providerName); + Mac mac = Mac.getInstance("HmacSHA3-224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-224"); mac.init(key); mac.update(data_1); @@ -140,11 +115,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-224", providerName); + Mac mac = Mac.getInstance("HmacSHA3-224", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-224"); mac.init(key); mac.update(data_1); @@ -158,11 +131,9 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-224", providerName); + Mac mac = Mac.getInstance("HmacSHA3-224", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 28); assertTrue("Unexpected mac length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_256.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_256.java index 414ed7c6..079073d5 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,11 +11,11 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; + +public class BaseTestHmacSHA3_256 extends BaseTestJunit5 { -public class BaseTestHmacSHA3_256 extends BaseTest { - //-------------------------------------------------------------------------- - // - // // test vectors fromhttps://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values#aMsgAuth private static byte[] NISTKEY_172; @@ -69,28 +69,9 @@ public class BaseTestHmacSHA3_256 extends BaseTest { "9bcf2c238e235c3ce88404e813bd2f3a97185ac6f238c63d6229a00b07974258"); } - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA3_256(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_256_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-256", providerName); + Mac mac = Mac.getInstance("HmacSHA3-256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-256"); mac.init(key); mac.update(data_1); @@ -99,11 +80,9 @@ public void testHmacSHA3_256_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_256_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-256", providerName); + Mac mac = Mac.getInstance("HmacSHA3-256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA3-256"); mac.init(key); mac.update(data_2); @@ -112,11 +91,9 @@ public void testHmacSHA3_256_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_256_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-256", providerName); + Mac mac = Mac.getInstance("HmacSHA3-256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA3-256"); mac.init(key); mac.update(data_3); @@ -125,11 +102,9 @@ public void testHmacSHA3_256_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-256", providerName); + Mac mac = Mac.getInstance("HmacSHA3-256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-256"); mac.init(key); mac.update(data_1); @@ -140,11 +115,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-256", providerName); + Mac mac = Mac.getInstance("HmacSHA3-256", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-256"); mac.init(key); mac.update(data_1); @@ -158,11 +131,9 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-256", providerName); + Mac mac = Mac.getInstance("HmacSHA3-256", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 32); assertTrue("Unexpected mac length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_384.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_384.java index a0673816..06aa0127 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,11 +11,11 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; + +public class BaseTestHmacSHA3_384 extends BaseTestJunit5 { -public class BaseTestHmacSHA3_384 extends BaseTest { - //-------------------------------------------------------------------------- - // - // // test vectors fromhttps://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values#aMsgAuth private static byte[] NISTKEY_172; @@ -69,28 +69,9 @@ public class BaseTestHmacSHA3_384 extends BaseTest { "e5ae4c739f455279368ebf36d4f5354c95aa184c899d3870e460ebc288ef1f9470053f73f7c6da2a71bcaec38ce7d6ac"); } - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA3_384(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_384_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-384", providerName); + Mac mac = Mac.getInstance("HmacSHA3-384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-384"); mac.init(key); mac.update(data_1); @@ -99,11 +80,9 @@ public void testHmacSHA3_384_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_384_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-384", providerName); + Mac mac = Mac.getInstance("HmacSHA3-384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA3-384"); mac.init(key); mac.update(data_2); @@ -112,11 +91,9 @@ public void testHmacSHA3_384_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_384_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-384", providerName); + Mac mac = Mac.getInstance("HmacSHA3-384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA3-384"); mac.init(key); mac.update(data_3); @@ -125,11 +102,9 @@ public void testHmacSHA3_384_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-384", providerName); + Mac mac = Mac.getInstance("HmacSHA3-384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-384"); mac.init(key); mac.update(data_1); @@ -140,11 +115,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-384", providerName); + Mac mac = Mac.getInstance("HmacSHA3-384", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-384"); mac.init(key); mac.update(data_1); @@ -158,11 +131,9 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-384", providerName); + Mac mac = Mac.getInstance("HmacSHA3-384", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 48); assertTrue("Unexpected mac length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_512.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_512.java index 8b501a74..ca4dffc4 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA3_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,11 +11,11 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; + +public class BaseTestHmacSHA3_512 extends BaseTestJunit5 { -public class BaseTestHmacSHA3_512 extends BaseTest { - //-------------------------------------------------------------------------- - // - // // test vectors fromhttps://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values#aMsgAuth private static byte[] NISTKEY_172; @@ -71,28 +71,9 @@ public class BaseTestHmacSHA3_512 extends BaseTest { "5f464f5e5b7848e3885e49b2c385f0694985d0e38966242dc4a5fe3fea4b37d46b65ceced5dcf59438dd840bab22269f0ba7febdb9fcf74602a35666b2a32915"); } - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA3_512(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_512_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-512", providerName); + Mac mac = Mac.getInstance("HmacSHA3-512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-512"); mac.init(key); mac.update(data_1); @@ -101,11 +82,9 @@ public void testHmacSHA3_512_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_512_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-512", providerName); + Mac mac = Mac.getInstance("HmacSHA3-512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA3-512"); mac.init(key); mac.update(data_2); @@ -114,11 +93,9 @@ public void testHmacSHA3_512_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA3_512_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-512", providerName); + Mac mac = Mac.getInstance("HmacSHA3-512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA3-512"); mac.init(key); mac.update(data_3); @@ -127,11 +104,9 @@ public void testHmacSHA3_512_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-512", providerName); + Mac mac = Mac.getInstance("HmacSHA3-512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-512"); mac.init(key); mac.update(data_1); @@ -142,11 +117,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-512", providerName); + Mac mac = Mac.getInstance("HmacSHA3-512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA3-512"); mac.init(key); mac.update(data_1); @@ -160,11 +133,9 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA3-512", providerName); + Mac mac = Mac.getInstance("HmacSHA3-512", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 64); assertTrue("Unexpected mac length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512.java index 75766b0e..61992f0c 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,13 +12,10 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA512 extends BaseTest { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; - +public class BaseTestHmacSHA512 extends BaseTestJunit5 { // test vectors from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_SHA512.pdf static final byte[] key_1 = BaseUtils.hexStringToByteArray( "0001020304050607" + "08090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" @@ -72,36 +69,9 @@ public class BaseTestHmacSHA512 extends BaseTest { static final byte[] digest_4 = BaseUtils.hexStringToByteArray( "00F3E9A77BB0F06D" + "E15F160603E42B5028758808596664C03E1AB8FB2B076778"); - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA512(String providerName) { - super(providerName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA512_key1() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA512"); mac.init(key); mac.update(data_1); @@ -110,11 +80,9 @@ public void testHmacSHA512_key1() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA512_key2() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_2, "HmacSHA512"); mac.init(key); mac.update(data_2); @@ -123,11 +91,9 @@ public void testHmacSHA512_key2() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA512_key3() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_3, "HmacSHA512"); mac.init(key); mac.update(data_3); @@ -136,11 +102,9 @@ public void testHmacSHA512_key3() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA512_key4() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_4, "HmacSHA512"); mac.init(key); mac.update(data_4); @@ -153,11 +117,9 @@ public void testHmacSHA512_key4() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(truncatedDigest, digest_4)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reset() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA512"); mac.init(key); mac.update(data_1); @@ -168,11 +130,9 @@ public void test_reset() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_reuse() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA512"); mac.init(key); mac.update(data_1); @@ -186,32 +146,12 @@ public void test_reuse() throws Exception { assertTrue("Mac digest did not equal expected", Arrays.equals(digest2, digest_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_mac_length() throws Exception { - Mac mac = Mac.getInstance("HmacSHA512", providerName); + Mac mac = Mac.getInstance("HmacSHA512", getProviderName()); int macLength = mac.getMacLength(); boolean isExpectedValue = (macLength == 64); assertTrue("Unexpected mac length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA512", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA512"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512Interop.java index e4bae8f3..79ec9aff 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512Interop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestHmacSHA512Interop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,13 +13,10 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestHmacSHA512Interop extends BaseTestInterop { - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; +public class BaseTestHmacSHA512Interop extends BaseTestJunit5Interop { // test vectors from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/HMAC_SHA512.pdf static final byte[] key_1 = BaseUtils.hexStringToByteArray( @@ -74,99 +71,58 @@ public class BaseTestHmacSHA512Interop extends BaseTestInterop { static final byte[] digest_4 = BaseUtils.hexStringToByteArray( "00F3E9A77BB0F06D" + "E15F160603E42B5028758808596664C03E1AB8FB2B076778"); - //-------------------------------------------------------------------------- - // - // - public BaseTestHmacSHA512Interop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void test_data1() throws Exception { - doHmac(data_1, providerName, interopProviderName); - doHmac(data_1, interopProviderName, providerName); + doHmac(data_1, getProviderName(), getInteropProviderName()); + doHmac(data_1, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data2() throws Exception { - doHmac(data_2, providerName, interopProviderName); - doHmac(data_2, interopProviderName, providerName); + doHmac(data_2, getProviderName(), getInteropProviderName()); + doHmac(data_2, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data3() throws Exception { - doHmac(data_3, providerName, interopProviderName); - doHmac(data_3, interopProviderName, providerName); + doHmac(data_3, getProviderName(), getInteropProviderName()); + doHmac(data_3, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_data4() throws Exception { - doHmac(data_4, providerName, interopProviderName); - doHmac(data_4, interopProviderName, providerName); + doHmac(data_4, getProviderName(), getInteropProviderName()); + doHmac(data_4, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_512() throws Exception { byte[] data_512 = new byte[512]; Random r = new Random(10); r.nextBytes(data_512); - doHmac(data_512, providerName, interopProviderName); - doHmac(data_512, interopProviderName, providerName); + doHmac(data_512, getProviderName(), getInteropProviderName()); + doHmac(data_512, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_2048() throws Exception { byte[] data_2048 = new byte[2048]; Random r = new Random(10); r.nextBytes(data_2048); - doHmac(data_2048, providerName, interopProviderName); - doHmac(data_2048, interopProviderName, providerName); + doHmac(data_2048, getProviderName(), getInteropProviderName()); + doHmac(data_2048, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void test_payload_8192() throws Exception { byte[] data_8192 = new byte[8192]; Random r = new Random(10); r.nextBytes(data_8192); - doHmac(data_8192, providerName, interopProviderName); - doHmac(data_8192, interopProviderName, providerName); + doHmac(data_8192, getProviderName(), getInteropProviderName()); + doHmac(data_8192, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected void doHmac(byte[] data, String provider, String interopProvider) throws Exception { KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA512", provider); SecretKey key = keyGen.generateKey(); @@ -183,23 +139,5 @@ protected void doHmac(byte[] data, String provider, String interopProvider) thro assertTrue("Mac digest did not equal expected", Arrays.equals(digest, digest2)); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance("HmacSHA512", providerName); - SecretKeySpec key = new SecretKeySpec(key_1, "HmacSHA512"); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesExist.java b/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesExist.java index 53f932fe..70d23135 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesExist.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesExist.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,30 +14,14 @@ import java.util.Set; import java.util.TreeSet; import java.util.Vector; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestImplementationClassesExist extends BaseTest { - //-------------------------------------------------------------------------- - // - // - public BaseTestImplementationClassesExist(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} +public class BaseTestImplementationClassesExist extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // + @Test public void testImplementationClassesExist() throws Exception { - Provider provider = Security.getProvider(providerName); + Provider provider = Security.getProvider(getProviderName()); Set services = provider.getServices(); Iterator iterator = services.iterator(); TreeSet serviceClassNames = new TreeSet(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesFinal.java b/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesFinal.java index 20308108..a1faf52d 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesFinal.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestImplementationClassesFinal.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,30 +15,14 @@ import java.util.Set; import java.util.TreeSet; import java.util.Vector; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestImplementationClassesFinal extends BaseTest { - //-------------------------------------------------------------------------- - // - // - public BaseTestImplementationClassesFinal(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} +public class BaseTestImplementationClassesFinal extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // + @Test public void testImplementationClassesFinal() throws Exception { - Provider provider = Security.getProvider(providerName); + Provider provider = Security.getProvider(getProviderName()); Set services = provider.getServices(); Iterator iterator = services.iterator(); TreeSet serviceClassNames = new TreeSet(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestInterop.java deleted file mode 100644 index 191c8572..00000000 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestInterop.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright IBM Corp. 2023 - * - * Licensed under the Apache License 2.0 (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution. - */ - -package ibm.jceplus.junit.base; - -import junit.framework.TestCase; - -public class BaseTestInterop extends TestCase { - //-------------------------------------------------------------------------- - // - // - protected String providerName; - protected String interopProviderName; - - - //-------------------------------------------------------------------------- - // - // - public BaseTestInterop(String providerName, String interopProviderName) { - this.providerName = providerName; - this.interopProviderName = interopProviderName; - } -} - diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestInvalidArrayIndex.java b/src/test/java/ibm/jceplus/junit/base/BaseTestInvalidArrayIndex.java index 5aed98cc..835e463b 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestInvalidArrayIndex.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestInvalidArrayIndex.java @@ -15,29 +15,18 @@ import javax.crypto.spec.RC2ParameterSpec; import javax.crypto.spec.RC5ParameterSpec; import javax.crypto.spec.SecretKeySpec; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestInvalidArrayIndex extends BaseTest { +public class BaseTestInvalidArrayIndex extends BaseTestJunit5 { private static final byte[] BYTES = new byte[20]; static int IAE = 1; // IllegalArgumentException static int AIOOBE = 2; // ArrayIndexOutOfBoundsException - public static Test suite() { - - TestSuite suite = new TestSuite(BaseTestInvalidArrayIndex.class); - return suite; - - } - - public BaseTestInvalidArrayIndex(String arg1) { - super(arg1); - } - - - public static void testInvalidArrayIndex() throws Exception { + @Test + public void testInvalidArrayIndex() throws Exception { // test various spec classes with invalid array offset, length values // and see if the expected exception is thrown try { diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestIsAssignableFromOrder.java b/src/test/java/ibm/jceplus/junit/base/BaseTestIsAssignableFromOrder.java index 06c58ac4..ab00c6a3 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestIsAssignableFromOrder.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestIsAssignableFromOrder.java @@ -44,20 +44,11 @@ import javax.crypto.spec.OAEPParameterSpec; import javax.crypto.spec.PSource; import javax.crypto.spec.SecretKeySpec; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; -public class BaseTestIsAssignableFromOrder extends BaseTest { - - public static Test suite() { - TestSuite suite = new TestSuite(BaseTestIsAssignableFromOrder.class); - return suite; - } - - public BaseTestIsAssignableFromOrder(String providerName) { - super(providerName); - } +public class BaseTestIsAssignableFromOrder extends BaseTestJunit5 { + @Test public void testIsAssignableFromOrder() throws Exception { // AlgorithmParameters @@ -87,10 +78,10 @@ public void testIsAssignableFromOrder() throws Exception { private void testAlgSpec(String algorithm, AlgorithmParameterSpec spec) throws Exception { System.out.println("test AlgorithmParametersSpec: " + algorithm); - AlgorithmParameters ap1 = AlgorithmParameters.getInstance(algorithm, providerName); + AlgorithmParameters ap1 = AlgorithmParameters.getInstance(algorithm, getProviderName()); ap1.init(spec); - AlgorithmParameters ap2 = AlgorithmParameters.getInstance(algorithm, providerName); + AlgorithmParameters ap2 = AlgorithmParameters.getInstance(algorithm, getProviderName()); ap2.init(ap1.getEncoded()); List> classes = new ArrayList<>(); @@ -108,7 +99,7 @@ private void testSecretKeySpec(String algorithm, KeySpec spec, Class clazz) throws Exception { System.out.println("test SecretKeySpec: " + algorithm); - SecretKeyFactory kf = SecretKeyFactory.getInstance(algorithm, providerName); + SecretKeyFactory kf = SecretKeyFactory.getInstance(algorithm, getProviderName()); SecretKey key = kf.generateSecret(spec); kf.getKeySpec(key, KeySpec.class); @@ -120,7 +111,7 @@ private void testKeySpec(String algorithm, int size, Class cl throws Exception { System.out.println("test KeySpec: " + algorithm); - KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm, providerName); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm, getProviderName()); kpg.initialize(size); KeyPair kp = kpg.generateKeyPair(); @@ -133,7 +124,7 @@ private void testKeySpec(String algorithm, int size, Class cl EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(encodedpubk); EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedprvk); - KeyFactory kf = KeyFactory.getInstance(algorithm, providerName); + KeyFactory kf = KeyFactory.getInstance(algorithm, getProviderName()); PublicKey publicKey = kf.generatePublic(publicKeySpec); PrivateKey privateKey = kf.generatePrivate(privateKeySpec); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5.java b/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5.java index 74260646..beecac22 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5.java @@ -5,13 +5,15 @@ * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.base; - -public class BaseTestJunit5 { +abstract public class BaseTestJunit5 { private String providerName; + private int keysize = -1; + + private String algo = null; + /** * Sets the provider name that is to be used to execute this test. * @@ -27,7 +29,47 @@ public void setProviderName(String providerName) { * @return The provider name associated with this test case for use. */ public String getProviderName() { + if (this.providerName == null) { + throw new RuntimeException("Provider name is null."); + } return this.providerName; } -} + /** + * Sets the algorithm associated with this test. + * @param algorithm + */ + public void setAlgorithm(String algorithm) { + this.algo = algorithm; + } + + /** + * Gets the algorithm associated with this test. + * @return + */ + public String getAlgorithm() { + if (this.algo == null) { + throw new RuntimeException("Algorithm name is null."); + } + return this.algo; + } + + /** + * Sets the key size associated with this test. + * @param keySize + */ + public void setKeySize(int keySize) { + this.keysize = keySize; + } + + /** + * Gets the key size associated with this test. + * @return + */ + public int getKeySize() { + if (this.keysize == -1) { + throw new RuntimeException("Key size is not correct."); + } + return this.keysize; + } +} diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Interop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Interop.java new file mode 100644 index 00000000..a09d6729 --- /dev/null +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Interop.java @@ -0,0 +1,32 @@ +/* + * Copyright IBM Corp. 2023, 2024 + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution. + */ + +package ibm.jceplus.junit.base; + +public class BaseTestJunit5Interop extends BaseTestJunit5 { + + public String interopProviderName; + + /** + * Sets the provider name to interop with. + * + * @param providerName the provider name associated with this test case for use. + */ + public void setInteropProviderName(String providerName) { + this.interopProviderName = providerName; + } + + /** + * Gets the provider name that is to be used for interop. + * + * @return The provider name associated with the interop provider name. + */ + public String getInteropProviderName() { + return this.interopProviderName; + } +} diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSignature.java b/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Signature.java similarity index 56% rename from src/test/java/ibm/jceplus/junit/base/BaseTestSignature.java rename to src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Signature.java index 36fa120f..a715643e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSignature.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestJunit5Signature.java @@ -13,43 +13,7 @@ import java.security.Signature; import static org.junit.Assert.assertTrue; -public class BaseTestSignature extends BaseTestJunit5 { - - private int keysize = 0; - - private String algo = null; - - /** - * Sets the algorithm associated with this test. - * @param algorithm - */ - public void setAlgorithm(String algorithm) { - this.algo = algorithm; - } - - /** - * Gets the algorithm associated with this test. - * @return - */ - public String getAlgorithm() { - return this.algo; - } - - /** - * Sets the key size associated with this test. - * @param keySize - */ - public void setKeySize(int keySize) { - this.keysize = keySize; - } - - /** - * Gets the key size associated with this test. - * @return - */ - public int getKeySize() { - return this.keysize; - } +public class BaseTestJunit5Signature extends BaseTestJunit5 { protected void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey, PublicKey publicKey) throws Exception { @@ -65,4 +29,3 @@ protected void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKe assertTrue("Signature verification failed", verifying.verify(signedBytes)); } } - diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestMD5.java b/src/test/java/ibm/jceplus/junit/base/BaseTestMD5.java index 50d91697..08b3a950 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestMD5.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,12 +10,11 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestMD5 extends BaseTestMessageDigestClone { - //-------------------------------------------------------------------------- - // - // static byte[] each = {(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0, (byte) 0x73, (byte) 0x0, (byte) 0x75, (byte) 0x0, (byte) 0x62, (byte) 0x0, (byte) 0x2d, (byte) 0x0, (byte) 0x61, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, @@ -115,21 +114,10 @@ public class BaseTestMD5 extends BaseTestMessageDigestClone { (byte) 0xe3, (byte) 0xc9, (byte) 0x55, (byte) 0xac, (byte) 0x49, (byte) 0xda, (byte) 0x2e, (byte) 0x21, (byte) 0x07, (byte) 0xb6, (byte) 0x7a}; - - - //-------------------------------------------------------------------------- - // - // - public BaseTestMD5(String providerName) { - super(providerName, "MD5"); - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < each.length; i++) md.update(each[i]); @@ -142,24 +130,20 @@ public void testMD5() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_A() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] result = md.digest(); assertTrue("Digest did not match expected", Arrays.equals(result, md5_A)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_B() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(md5_B_input); byte[] result = md.digest(); @@ -167,12 +151,10 @@ public void testMD5_B() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_C() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(md5_C_input); byte[] result = md.digest(); @@ -180,12 +162,10 @@ public void testMD5_C() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_D() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(md5_D_input); byte[] result = md.digest(); @@ -193,12 +173,10 @@ public void testMD5_D() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_E() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(md5_E_input); byte[] result = md.digest(); @@ -206,12 +184,10 @@ public void testMD5_E() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_F() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(md5_F_input); byte[] result = md.digest(); @@ -219,12 +195,10 @@ public void testMD5_F() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testMD5_G() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(md5_G_input); byte[] result = md.digest(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestMessageDigestClone.java b/src/test/java/ibm/jceplus/junit/base/BaseTestMessageDigestClone.java index 40e09fa8..df47d95e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestMessageDigestClone.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestMessageDigestClone.java @@ -10,11 +10,11 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -abstract public class BaseTestMessageDigestClone extends BaseTest { - // message digest algorithm to be used in all tests - final String algorithm; +abstract public class BaseTestMessageDigestClone extends BaseTestJunit5 { final byte[] input_1 = {(byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61}; @@ -32,13 +32,9 @@ abstract public class BaseTestMessageDigestClone extends BaseTest { (byte) 0x6f, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x6e, (byte) 0x6f, (byte) 0x70, (byte) 0x71}; - public BaseTestMessageDigestClone(String providerName, String algorithm) { - super(providerName); - this.algorithm = algorithm; - } - + @Test public void testUpdateCloneSameUpdate() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(input_1); @@ -50,8 +46,9 @@ public void testUpdateCloneSameUpdate() throws Exception { assertArrayEquals(digest2, digest1, "Digest of original did not match clone's digest"); } + @Test public void testUpdateCloneDifferentUpdate() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(input_1); @@ -63,8 +60,9 @@ public void testUpdateCloneDifferentUpdate() throws Exception { assertFalse("Digest of original matches clone's digest when it shouldn't", Arrays.equals(digest1, digest2)); } + @Test public void testCloneSameUpdate() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); MessageDigest mdCopy = (MessageDigest) md.clone(); @@ -74,8 +72,9 @@ public void testCloneSameUpdate() throws Exception { assertArrayEquals(digest2, digest1, "Digest of original did not match clone's digest"); } + @Test public void testCloneDifferentUpdate() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); MessageDigest mdCopy = (MessageDigest) md.clone(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestMiniRSAPSS2.java b/src/test/java/ibm/jceplus/junit/base/BaseTestMiniRSAPSS2.java index 086c429c..7504d85f 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestMiniRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestMiniRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,15 +12,16 @@ import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; -import java.security.Provider; import java.security.Security; import java.security.Signature; import java.security.interfaces.RSAPublicKey; import java.security.spec.MGF1ParameterSpec; import java.security.spec.PSSParameterSpec; import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class BaseTestMiniRSAPSS2 extends BaseTest { +public class BaseTestMiniRSAPSS2 extends BaseTestJunit5 { String signingProvidersSignatureAlgorithmName = null; String verifyingProvidersSignatureAlgorithmName = null; @@ -37,26 +38,18 @@ public class BaseTestMiniRSAPSS2 extends BaseTest { static final byte[] dataToBeSignedLong = "this is text to test the RSAPSS Signature xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" .getBytes(); - static KeyPairGenerator rsaKeyPairGen = null; + KeyPairGenerator rsaKeyPairGen = null; - static KeyPair rsaKeyPair_OpenJCEPlus[] = new KeyPair[1]; - static KeyPair rsaKeyPair_SunRsaSign[] = new KeyPair[1]; - static KeyPair rsaKeyPair_OpenJCEPlusFIPS[] = new KeyPair[1]; + KeyPair rsaKeyPair_OpenJCEPlus[] = new KeyPair[1]; + KeyPair rsaKeyPair_SunRsaSign[] = new KeyPair[1]; + KeyPair rsaKeyPair_OpenJCEPlusFIPS[] = new KeyPair[1]; - static PSSParameterSpec pssParameterSpec = null; + PSSParameterSpec pssParameterSpec = null; - static int testCaseNumber = 1; + int testCaseNumber = 1; - Provider provider = null; - - - public BaseTestMiniRSAPSS2(String providerName) { - super(providerName); - } - - - - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { System.out.println( "==============================================================================="); @@ -67,22 +60,8 @@ protected void setUp() throws Exception { //signingProviderName = "OpenJCEPlus"; //verifyingProviderName = "OpenJCEPlus"; - signingProviderName = providerName; - verifyingProviderName = providerName; - - // Add the OpenJCEPlus provider to the provider's list - if (providerName.equals("OpenJCEPlus")) { - provider = (Provider) new com.ibm.crypto.plus.provider.OpenJCEPlus(); - } else { - provider = (Provider) new com.ibm.crypto.plus.provider.OpenJCEPlusFIPS(); - } - try { - Security.insertProviderAt(provider, 3); - } catch (Exception ex) { - System.out.println("Failed to create the " + providerName - + " provider. The following exception was thrown."); - ex.printStackTrace(); - } + signingProviderName = getProviderName(); + verifyingProviderName = getProviderName(); java.security.Provider[] providers = Security.getProviders(); System.out.println("The providers in the providers list are:"); @@ -102,7 +81,6 @@ protected void setUp() throws Exception { verifyingProvidersSignatureAlgorithmName = "RSAPSS"; } - System.out.println( "BaseTestRSAPSS2.java: setup(): Following the call to setUp(), signingProviderName = " + signingProviderName); @@ -143,14 +121,11 @@ protected void setUp() throws Exception { } } - - //================================================================================================================== // BEGINNING OF RSA-PSS SIGNATURE TESTS //================================================================================================================== - - + @Test public void testRSAPSS() throws Exception { KeyPair rsaKeyPair = null; @@ -210,7 +185,7 @@ public void testRSAPSS() throws Exception { + " ====================================================="); System.out.println( "===================================================================================="); - if (!providerName.equals("OpenJCEPlusFIPS")) { + if (!getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1 try { if (ii == 0) { @@ -1407,7 +1382,7 @@ public void testRSAPSS() throws Exception { + " ====================================================="); System.out.println( "===================================================================================="); - if (!providerName.equals("OpenJCEPlusFIPS")) { + if (!getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1 skip test try { if (ii == 0) { @@ -1768,6 +1743,7 @@ public void testRSAPSS() throws Exception { System.out.println("testRSAPSS(): TEST RESULT #" + (testCaseNumber - 1) + " => An unexpected exception was thrown with message = " + ex.getMessage()); + ex.printStackTrace(); Assert.fail(); } @@ -2092,7 +2068,7 @@ public void testRSAPSS() throws Exception { System.out.println( "===================================================================================="); - if (!providerName.equals("OpenJCEPlusFIPS") && ii == 0) { + if (!getProviderName().equals("OpenJCEPlusFIPS") && ii == 0) { //512 keysize not supported by FIPS try { if (ii == 0) { @@ -2177,31 +2153,8 @@ public void testRSAPSS() throws Exception { } // end loop for each RSA key size } // end testRSAPSS() - - - // public static void main(String[] args){ - // - // System.out.println("BaseTestRSAPSS2.java: main(): METHOD ENTRY"); - // - // BaseTestRSAPSS2 test = new BaseTestRSAPSS2(); - // - // try { - // test.mySetUp(); - // test.testRSAPSS(); - // } - // catch (Exception ex) - // { - // System.out.println("The following exception was thrown:"); - // ex.printStackTrace(); - // } - // - // System.out.println("\nBaseTestRSAPSS2.java: main(): METHOD EXIT"); - // } - - - // Compute the signature, but do not use PSSParameters class - private static boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, + private boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, String signingProvidersSignatureAlgorithmName, String verifingProvidersSignatureAlgorithmName, String signingProviderName, String verifyingProviderName, @@ -2289,7 +2242,7 @@ private static boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, - private static void showProviders() { + private void showProviders() { java.security.Provider[] providers = Security.getProviders(); System.out.println("\n================================================"); System.out.println("The security provider's list is:"); @@ -2308,7 +2261,7 @@ private static void showProviders() { /** * Converts a byte array to hex string */ - private static String toHexString(byte[] block) { + private String toHexString(byte[] block) { StringBuffer buf = new StringBuffer(); char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestPublicMethodsToMakeNonPublic.java b/src/test/java/ibm/jceplus/junit/base/BaseTestPublicMethodsToMakeNonPublic.java index 1b438efa..2bedd7ec 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestPublicMethodsToMakeNonPublic.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestPublicMethodsToMakeNonPublic.java @@ -19,27 +19,18 @@ import java.util.Vector; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -abstract public class BaseTestPublicMethodsToMakeNonPublic extends BaseTest { +abstract public class BaseTestPublicMethodsToMakeNonPublic extends BaseTestJunit5 { private boolean debug = false; private boolean debugAllChecked = false; - // -------------------------------------------------------------------------- - // - // - public BaseTestPublicMethodsToMakeNonPublic(String providerName) { - super(providerName); - } - // -------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} + + + // -------------------------------------------------------------------------- // Implementing testcase must override this method to indicate whether @@ -48,15 +39,12 @@ public void tearDown() throws Exception {} // reported as a test failure. // abstract public boolean isMethodMeantToBePublicAndExplicitlyCallableByUsers(Method method); - - // -------------------------------------------------------------------------- - // - // + @Test public void testCheckForPublicMethods() throws Exception { Vector publicMethodNamesToCheck = new Vector(); String[] classNames = getClassNamesInSamePackage( - Security.getProvider(providerName).getClass().getName()); + Security.getProvider(getProviderName()).getClass().getName()); for (int index = 0; index < classNames.length; ++index) { Method[] publicMethods = getPublicMethodsOfClass(classNames[index]); @@ -90,9 +78,7 @@ public void testCheckForPublicMethods() throws Exception { (publicMethodNamesToCheck.size() == 0)); } - // -------------------------------------------------------------------------- - // - // + private String[] getClassNamesInSamePackage(String className) { Vector v = new Vector(); @@ -120,9 +106,7 @@ private String[] getClassNamesInSamePackage(String className) { return v.toArray(new String[0]); } - // -------------------------------------------------------------------------- - // - // + private JarFile getJarContainingClass(String className) { try { Class c = Class.forName(className); @@ -143,9 +127,7 @@ private JarFile getJarContainingClass(String className) { return null; } - // -------------------------------------------------------------------------- - // - // + private String[] getClassNamesInJarFile(JarFile jarFile) { Vector v = new Vector(); @@ -275,9 +257,7 @@ private Method[] getPublicMethodsOfClass(String className) { return v.toArray(new Method[0]); } - // -------------------------------------------------------------------------- - // - // + private Method findMethod(Class c, Method method) { if (c == null) { return null; @@ -311,9 +291,7 @@ private Method findMethod(Class c, Method method) { return null; } - // -------------------------------------------------------------------------- - // - // + protected String getPrintFriendlyMethodSignature(Method method) { StringBuffer sb = new StringBuffer(); sb.append(method.getDeclaringClass().getName() + "." + method.getName()); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSA.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSA.java index 9a94a658..d4dcb583 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSA.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSA.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -39,21 +39,20 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.OAEPParameterSpec; import javax.crypto.spec.PSource; -import org.junit.Assume; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTestRSA extends BaseTestCipher { - //-------------------------------------------------------------------------- - // - // + static final char[] hexDigits = "0123456789abcdef".toCharArray(); static final byte[] plainText = "testmessage_a very long test message".getBytes(); static final int DEFAULT_KEY_SIZE = 2048; - //-------------------------------------------------------------------------- - // - // + protected KeyPairGenerator rsaKeyPairGen; protected KeyPair rsaKeyPair; protected RSAPublicKey rsaPub; @@ -61,28 +60,9 @@ public class BaseTestRSA extends BaseTestCipher { protected int specifiedKeySize = 0; protected boolean providerStripsLeadingZerosForNoPaddingDecrypt = false; // FIXME - IBMJCE tests will need this to be true - //-------------------------------------------------------------------------- - // - // - public BaseTestRSA(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // - public BaseTestRSA(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("RSA") >= keySize); - } - - //-------------------------------------------------------------------------- - // - // - protected void setUp() throws Exception { - rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", providerName); + @BeforeEach + public void setUp() throws Exception { + rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", getProviderName()); if (specifiedKeySize > 0) { rsaKeyPairGen.initialize(specifiedKeySize, null); } @@ -91,16 +71,12 @@ protected void setUp() throws Exception { rsaPriv = (RSAPrivateCrtKey) rsaKeyPair.getPrivate(); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher() throws Exception { encryptDecrypt("RSA"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAPlainCipher() throws Exception { KeyFactory kf; @@ -129,13 +105,13 @@ public void testRSAPlainCipher() throws Exception { String rin1 = "09:01:06:53:a7:96:09:63:ef:e1:3f:e9:8d:95:22:d1:0e:1b:87:c1:a2:41:b2:09:97:a3:5e:e0:a4:1d:59:91:21:e4:ca:87:bf:77:4a:7e:a2:22:ff:59:1e:bd:a4:80:aa:93:4a:41:56:95:5b:f4:57:df:fc:52:2f:46:9b:45:d7:03:ae:22:8e:67:9e:6c:b9:95:4f:bd:8e:e8:67:90:5b:fe:de:2f:11:22:2e:9d:30:93:6d:c0:48:00:cb:08:b9:c4:36:e9:03:7c:08:2d:68:42:cb:71:d0:7d:47:22:c1:58:c5:b8:2f:28:3e:98:78:11:6d:71:5b:3b:36:3c"; String rout1 = "4a:21:64:20:56:5f:27:0c:90:1d:f3:1b:64:8e:16:d3:af:79:ca:c6:65:56:19:77:8f:25:35:70:be:f3:15:b3:e3:d8:8f:04:ec:c3:60:59:d0:9a:66:be:1c:ad:f7:09:46:a9:09:46:12:5f:28:b6:28:b1:53:fb:fe:07:73:b8:8b:f8:83:64:8e:2d:45:ca:1a:fd:85:4a:2c:fa:fc:e6:58:f7:e4:83:68:8c:38:49:2b:f3:5c:c1:2d:24:6a:cd:22:6d:cb:f4:f1:8c:9e:1a:94:a7:4b:6f:d1:b4:b4:ab:56:8b:a3:a9:89:88:c3:5d:a8:47:2a:67:50:32:71:19"; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support plain keys return; } try { - kf = KeyFactory.getInstance("RSA", providerName); + kf = KeyFactory.getInstance("RSA", getProviderName()); } catch (NoSuchAlgorithmException e) { kf = KeyFactory.getInstance("RSA"); } @@ -189,7 +165,7 @@ public void testRSAPlainCipher() throws Exception { } private void plainKeyEncDec(String alg, int len, Key encKey, Key decKey) throws Exception { - Cipher c = Cipher.getInstance(alg, providerName); + Cipher c = Cipher.getInstance(alg, getProviderName()); byte[] b = new byte[len]; Random rnd = new Random(); @@ -210,7 +186,7 @@ private void plainKeyEncDec(String alg, int len, Key encKey, Key decKey) throws public void plainKeyCipher(String alg, int mode, Key key, String in, String out, boolean result) throws Exception { - Cipher c = Cipher.getInstance(alg, providerName); + Cipher c = Cipher.getInstance(alg, getProviderName()); c.init(mode, key); byte[] r = c.doFinal(parse(in)); byte[] s = parse(out); @@ -219,65 +195,47 @@ public void plainKeyCipher(String alg, int mode, Key key, String in, String out, } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_PKCS1Padding() throws Exception { encryptDecrypt("RSA/ECB/PKCS1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_NoPadding() throws Exception { encryptDecrypt("RSA/ECB/NoPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_ECB_PKCS1Padding() throws Exception { encryptDecrypt("RSA/ECB/PKCS1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_ECB_NoPadding() throws Exception { encryptDecrypt("RSA/ECB/NoPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_ECB_ZeroPadding() throws Exception { encryptDecrypt("RSA/ECB/ZeroPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithNoPad() throws Exception { encryptDecrypt("RSAwithNoPad"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherForSSL() throws Exception { encryptDecrypt("RSAforSSL"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_SSL_PKCS1Padding() throws Exception { encryptDecrypt("RSA/SSL/PKCS1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithOAEPPadding() throws Exception { byte[] message = getMessage_OAEP_SHA1(); if (message != null) { @@ -285,9 +243,7 @@ public void testRSACipherWithOAEPPadding() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA_1() throws Exception { byte[] message = getMessage_OAEP_SHA1(); if (message != null) { @@ -295,9 +251,7 @@ public void testRSACipherWithPaddingSHA_1() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA1() throws Exception { byte[] message = getMessage_OAEP_SHA1(); if (message != null) { @@ -305,9 +259,7 @@ public void testRSACipherWithPaddingSHA1() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA224() throws Exception { byte[] message = getMessage_OAEP_SHA224(); if (message != null) { @@ -315,9 +267,7 @@ public void testRSACipherWithPaddingSHA224() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA256() throws Exception { byte[] message = getMessage_OAEP_SHA256(); if (message != null) { @@ -325,9 +275,7 @@ public void testRSACipherWithPaddingSHA256() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA384() throws Exception { byte[] message = getMessage_OAEP_SHA384(); if (message != null) { @@ -335,9 +283,7 @@ public void testRSACipherWithPaddingSHA384() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA512() throws Exception { byte[] message = getMessage_OAEP_SHA512(); if (message != null) { @@ -345,13 +291,11 @@ public void testRSACipherWithPaddingSHA512() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAShortBuffer() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, rsaPub); @@ -366,9 +310,7 @@ public void testRSAShortBuffer() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAShortBuffer2() throws Exception { String algorithm = "RSA/ECB/NoPadding"; int outputByteLength = 64; @@ -376,7 +318,7 @@ public void testRSAShortBuffer2() throws Exception { try { - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); if (cipher.equals(null)) System.out.println("The cipher was null."); @@ -394,14 +336,12 @@ public void testRSAShortBuffer2() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSABadPadding() throws Exception { try { // Test RSA Cipher - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, rsaPub); @@ -418,13 +358,11 @@ public void testRSABadPadding() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAIllegalMode() throws Exception { // Test RSA Cipher - Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, rsaPub); @@ -441,151 +379,113 @@ public void testRSAIllegalMode() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_getParams() throws Exception { checkGetParamsNull("RSA"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_PKCS1Padding_getParams() throws Exception { checkGetParamsNull("RSA/ECB/PKCS1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_NoPadding_getParams() throws Exception { checkGetParamsNull("RSA/ECB/NoPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_ECB_PKCS1Padding_getParams() throws Exception { checkGetParamsNull("RSA/ECB/PKCS1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_ECB_NoPadding_getParams() throws Exception { checkGetParamsNull("RSA/ECB/NoPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_ECB_ZeroPadding_getParams() throws Exception { checkGetParamsNull("RSA/ECB/ZeroPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithNoPad_getParams() throws Exception { checkGetParamsNull("RSAwithNoPad"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherForSSL_getParams() throws Exception { checkGetParamsNull("RSAforSSL"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_SSL_PKCS1Padding_getParams() throws Exception { checkGetParamsNull("RSA/SSL/PKCS1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithOAEPPadding_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPPadding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA_1_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPWithSHA-1AndMGF1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA1_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPWithSHA1AndMGF1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA224_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPWithSHA-224AndMGF1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA256_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA384_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPWithSHA-384AndMGF1Padding"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherWithPaddingSHA512_getParams() throws Exception { checkGetParamsNotNull("RSA/ECB/OAEPWithSHA-512AndMGF1Padding"); } - //-------------------------------------------------------------------------- - // - // + public void checkGetParamsNull(String transformation) throws Exception { if (isTransformationValidButUnsupported(transformation)) { return; } - Cipher cp = Cipher.getInstance(transformation, providerName); + Cipher cp = Cipher.getInstance(transformation, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub); AlgorithmParameters algParams = cp.getParameters(); assertTrue("AlgorithmParameters not null", (algParams == null)); } - //-------------------------------------------------------------------------- - // - // + public void checkGetParamsNotNull(String transformation) throws Exception { if (isTransformationValidButUnsupported(transformation)) { return; } - Cipher cp = Cipher.getInstance(transformation, providerName); + Cipher cp = Cipher.getInstance(transformation, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub); AlgorithmParameters algParams = cp.getParameters(); assertTrue("AlgorithmParameters is null", (algParams != null)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherOutputSize() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub); int outputSize = cp.getOutputSize(1); @@ -596,12 +496,10 @@ public void testRSACipherOutputSize() throws Exception { assertTrue("Unexpected getOutputSize result", (outputSize == keySize / 8)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipherExceedInput() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub); int n = ((RSAKey) rsaPub).getModulus().bitLength(); @@ -616,49 +514,39 @@ public void testRSACipherExceedInput() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_cert() throws Exception { // FIXME } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_certnull() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, (Certificate) null); fail("Did not get InvalidKeyException"); } catch (InvalidKeyException e) { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_cert_sr() throws Exception { // FIXME } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_certnull_sr() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, (Certificate) null, new SecureRandom()); fail("Did not get InvalidKeyException"); } catch (InvalidKeyException e) { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub); byte[] cipherText = cp.doFinal(plainText); @@ -670,23 +558,19 @@ public void testRSACipher_init_key() throws Exception { assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_keynull() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, (Key) null); fail("Did not get InvalidKeyException"); } catch (InvalidKeyException e) { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_sr() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub, new SecureRandom()); byte[] cipherText = cp.doFinal(plainText); @@ -698,11 +582,9 @@ public void testRSACipher_init_key_sr() throws Exception { assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_srnull() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub, (SecureRandom) null); byte[] cipherText = cp.doFinal(plainText); @@ -714,9 +596,7 @@ public void testRSACipher_init_key_srnull() throws Exception { assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparms() throws Exception { // FIXME //AlgorithmParameters algParams = ??; @@ -732,11 +612,9 @@ public void testRSACipher_init_key_algparms() throws Exception { //assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmsnull() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub, (AlgorithmParameters) null); byte[] cipherText = cp.doFinal(plainText); @@ -748,9 +626,7 @@ public void testRSACipher_init_key_algparmsnull() throws Exception { assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspec() throws Exception { String transformation = "RSA/ECB/OAEPPadding"; AlgorithmParameterSpec algParams = new OAEPParameterSpec("SHA-1", @@ -764,11 +640,9 @@ public void testRSACipher_init_key_algparmspec() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspec_SHA1() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1 return; } @@ -783,9 +657,7 @@ public void testRSACipher_init_key_algparmspec_SHA1() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspec_SHA224() throws Exception { String oaepHashAlgorithm = "SHA-224"; String transformation = "RSA/ECB/OAEPWith" + oaepHashAlgorithm + "AndMGF1Padding"; @@ -797,9 +669,7 @@ public void testRSACipher_init_key_algparmspec_SHA224() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspec_SHA256() throws Exception { String oaepHashAlgorithm = "SHA-256"; String transformation = "RSA/ECB/OAEPWith" + oaepHashAlgorithm + "AndMGF1Padding"; @@ -811,9 +681,7 @@ public void testRSACipher_init_key_algparmspec_SHA256() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspec_SHA384() throws Exception { String oaepHashAlgorithm = "SHA-384"; String transformation = "RSA/ECB/OAEPWith" + oaepHashAlgorithm + "AndMGF1Padding"; @@ -825,9 +693,7 @@ public void testRSACipher_init_key_algparmspec_SHA384() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspec_SHA512() throws Exception { String oaepHashAlgorithm = "SHA-512"; String transformation = "RSA/ECB/OAEPWith" + oaepHashAlgorithm + "AndMGF1Padding"; @@ -839,16 +705,14 @@ public void testRSACipher_init_key_algparmspec_SHA512() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + public void doTestRSACipher_init_key_algparmspec_oaep(String transformation, AlgorithmParameterSpec algParams, byte[] message) throws Exception { if (isTransformationValidButUnsupported(transformation)) { return; } - Cipher cp = Cipher.getInstance(transformation, providerName); + Cipher cp = Cipher.getInstance(transformation, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub, algParams); byte[] cipherText = cp.doFinal(message); @@ -860,11 +724,9 @@ public void doTestRSACipher_init_key_algparmspec_oaep(String transformation, assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSACipher_init_key_algparmspecnull() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPub, (AlgorithmParameterSpec) null); byte[] cipherText = cp.doFinal(plainText); @@ -878,9 +740,7 @@ public void testRSACipher_init_key_algparmspecnull() throws Exception { - //-------------------------------------------------------------------------- - // - // + public void decryptDoFinalOutLen() throws Exception { String algorithm = "RSA"; @@ -889,12 +749,12 @@ public void decryptDoFinalOutLen() throws Exception { try { KeyPairGenerator RSAKeyPairGenerator = KeyPairGenerator.getInstance(keyType, - providerName); + getProviderName()); RSAKeyPairGenerator.initialize(keySize); KeyPair keyPair = RSAKeyPairGenerator.generateKeyPair(); Key publicKey = keyPair.getPublic(); - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] cipherText1 = cipher.update(plainText); @@ -905,7 +765,7 @@ public void decryptDoFinalOutLen() throws Exception { System.arraycopy(cipherText2, 0, encrpytedByteData, cipherText1.length, cipherText2.length); - RSAKeyPairGenerator = KeyPairGenerator.getInstance(keyType, providerName); + RSAKeyPairGenerator = KeyPairGenerator.getInstance(keyType, getProviderName()); RSAKeyPairGenerator.initialize(keySize); keyPair = RSAKeyPairGenerator.generateKeyPair(); @@ -927,34 +787,28 @@ public void decryptDoFinalOutLen() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + protected void encryptDecrypt(String algorithm) throws Exception { encryptDecryptDoFinal(algorithm, plainText); encryptDecryptUpdate(algorithm, plainText); encryptDecryptPartialUpdate(algorithm, plainText); } - //-------------------------------------------------------------------------- - // - // + protected void encryptDecrypt(String algorithm, byte[] message) throws Exception { encryptDecryptDoFinal(algorithm, message); encryptDecryptUpdate(algorithm, message); encryptDecryptPartialUpdate(algorithm, message); } - //-------------------------------------------------------------------------- - // - // + protected void encryptDecryptDoFinal(String algorithm, byte[] message) throws Exception { if (isTransformationValidButUnsupported(algorithm)) { return; } - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, rsaPub); @@ -968,16 +822,14 @@ protected void encryptDecryptDoFinal(String algorithm, byte[] message) throws Ex assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + protected void encryptDecryptUpdate(String algorithm, byte[] message) throws Exception { if (isTransformationValidButUnsupported(algorithm)) { return; } - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, rsaPub); @@ -993,16 +845,14 @@ protected void encryptDecryptUpdate(String algorithm, byte[] message) throws Exc assertTrue("Decrypted text does not match expected", success); } - //-------------------------------------------------------------------------- - // - // + protected void encryptDecryptPartialUpdate(String algorithm, byte[] message) throws Exception { if (isTransformationValidButUnsupported(algorithm)) { return; } - Cipher cp = Cipher.getInstance(algorithm, providerName); + Cipher cp = Cipher.getInstance(algorithm, getProviderName()); // Encrypt the plain text cp.init(Cipher.ENCRYPT_MODE, rsaPub); @@ -1055,9 +905,7 @@ private static boolean bytesAreZero(byte[] input, int offset, int length) { return true; } - //-------------------------------------------------------------------------- - // - // + private boolean decryptResultsMatch(String algorithm, byte[] originalText, byte[] decryptText) { boolean isAlgorithmNoPadding = algorithm.endsWith("NoPadding"); @@ -1086,44 +934,32 @@ && byteEqual(originalText, 0, decryptText, } } - //-------------------------------------------------------------------------- - // - // + private byte[] getMessage_OAEP_SHA1() { return getMessage_OAEP(20); } - //-------------------------------------------------------------------------- - // - // + private byte[] getMessage_OAEP_SHA224() { return getMessage_OAEP(28); } - //-------------------------------------------------------------------------- - // - // + private byte[] getMessage_OAEP_SHA256() { return getMessage_OAEP(32); } - //-------------------------------------------------------------------------- - // - // + private byte[] getMessage_OAEP_SHA384() { return getMessage_OAEP(48); } - //-------------------------------------------------------------------------- - // - // + private byte[] getMessage_OAEP_SHA512() { return getMessage_OAEP(64); } - //-------------------------------------------------------------------------- - // - // + private byte[] getMessage_OAEP(int digestLen) { int keySize = specifiedKeySize; if (keySize == 0) { @@ -1139,9 +975,7 @@ private byte[] getMessage_OAEP(int digestLen) { return message; } - //-------------------------------------------------------------------------- - // - // + public static String toString(byte[] b) { if (b == null) { return "(null)"; @@ -1158,9 +992,7 @@ public static String toString(byte[] b) { return sb.toString(); } - //-------------------------------------------------------------------------- - // - // + public static byte[] parse(String s) { try { int n = s.length(); @@ -1214,9 +1046,7 @@ public boolean isPaddingValidButUnsupported(String padding) { return super.isPaddingValidButUnsupported(padding); } - //-------------------------------------------------------------------------- - // - // + private static int nextNibble(StringReader r) throws IOException { while (true) { int ch = r.read(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKey.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKey.java index 7af483fb..cef1303d 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKey.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKey.java @@ -21,40 +21,26 @@ import java.security.spec.RSAPublicKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class BaseTestRSAKey extends BaseTestJunit5 { -public class BaseTestRSAKey extends BaseTest { - //-------------------------------------------------------------------------- - // - // protected KeyPairGenerator rsaKeyPairGen; protected KeyFactory rsaKeyFactory; - //-------------------------------------------------------------------------- - // - // - public BaseTestRSAKey(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", providerName); - rsaKeyFactory = KeyFactory.getInstance("RSA", providerName); + rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", getProviderName()); + rsaKeyFactory = KeyFactory.getInstance("RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 1024 bit keys return; } @@ -63,80 +49,62 @@ public void testRSAKeyGen_1024() throws Exception { rsaKeyPair.getPrivate(); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_2048() throws Exception { KeyPair rsaKeyPair = generateKeyPair(2048); rsaKeyPair.getPublic(); rsaKeyPair.getPrivate(); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_4096() throws Exception { KeyPair rsaKeyPair = generateKeyPair(4096); rsaKeyPair.getPublic(); rsaKeyPair.getPrivate(); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncoded_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 1024 bit keys return; } keyFactoryCreateFromEncoded(1024); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncoded_2048() throws Exception { keyFactoryCreateFromEncoded(2048); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncoded_4096() throws Exception { keyFactoryCreateFromEncoded(4096); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromKeySpec_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 1024 bit keys return; } keyFactoryCreateFromKeySpec(1024); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromKeySpec_2048() throws Exception { keyFactoryCreateFromKeySpec(2048); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromKeySpec_4096() throws Exception { keyFactoryCreateFromKeySpec(4096); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromKeySpec() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support 1024 bit keys return; } @@ -174,9 +142,7 @@ public void testRSAKeyFactoryCreateFromKeySpec() throws Exception { rsaKeyFactory.generatePublic(rsaPublicSpec); } - //-------------------------------------------------------------------------- - // - // + protected KeyPair generateKeyPair(int size) throws Exception { rsaKeyPairGen.initialize(size); KeyPair keyPair = rsaKeyPairGen.generateKeyPair(); @@ -200,9 +166,7 @@ protected KeyPair generateKeyPair(int size) throws Exception { return keyPair; } - //-------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromEncoded(int size) throws Exception { KeyPair rsaKeyPair = generateKeyPair(size); @@ -223,9 +187,7 @@ protected void keyFactoryCreateFromEncoded(int size) throws Exception { } } - //-------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromKeySpec(int size) throws Exception { KeyPair rsaKeyPair = generateKeyPair(size); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInterop.java index 708eab97..a94fda06 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInterop.java @@ -26,52 +26,31 @@ import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import javax.crypto.Cipher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -public class BaseTestRSAKeyInterop extends BaseTestInterop { +public class BaseTestRSAKeyInterop extends BaseTestJunit5Interop { - //-------------------------------------------------------------------------- - // - // protected KeyPairGenerator rsaKeyPairGenPlus; protected KeyFactory rsaKeyFactoryPlus; protected KeyPairGenerator rsaKeyPairGenJCE; protected KeyFactory rsaKeyFactoryJCE; - protected int keySize = 1024; byte[] origMsg = "this is the original message to be signed".getBytes(); - //-------------------------------------------------------------------------- - // - // - public BaseTestRSAKeyInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - public BaseTestRSAKeyInterop(String providerName, String interopProviderName, int size) { - super(providerName, interopProviderName); - this.keySize = size; - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - rsaKeyPairGenPlus = KeyPairGenerator.getInstance("RSA", providerName); - rsaKeyFactoryPlus = KeyFactory.getInstance("RSA", providerName); - rsaKeyPairGenJCE = KeyPairGenerator.getInstance("RSA", interopProviderName); - rsaKeyFactoryJCE = KeyFactory.getInstance("RSA", interopProviderName); + rsaKeyPairGenPlus = KeyPairGenerator.getInstance("RSA", getProviderName()); + rsaKeyFactoryPlus = KeyFactory.getInstance("RSA", getProviderName()); + rsaKeyPairGenJCE = KeyPairGenerator.getInstance("RSA", getInteropProviderName()); + rsaKeyFactoryJCE = KeyFactory.getInstance("RSA", getInteropProviderName()); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_PlusToJCE() throws Exception { - KeyPair rsaKeyPairPlus = generateKeyPair(rsaKeyPairGenPlus, this.keySize); + KeyPair rsaKeyPairPlus = generateKeyPair(rsaKeyPairGenPlus, getKeySize()); RSAPublicKey publicKeyPlus = (RSAPublicKey) rsaKeyPairPlus.getPublic(); RSAPrivateKey privateKeyPlus = (RSAPrivateKey) rsaKeyPairPlus.getPrivate(); byte[] publicKeyBytesPlus = publicKeyPlus.getEncoded(); @@ -92,11 +71,9 @@ public void testRSAKeyGen_PlusToJCE() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_JCEToPlus() throws Exception { - KeyPair rsaKeyPairJCE = generateKeyPair(rsaKeyPairGenJCE, this.keySize); + KeyPair rsaKeyPairJCE = generateKeyPair(rsaKeyPairGenJCE, getKeySize()); RSAPublicKey publicKeyJCE = (RSAPublicKey) rsaKeyPairJCE.getPublic(); RSAPrivateKey privateKeyJCE = (RSAPrivateKey) rsaKeyPairJCE.getPrivate(); byte[] publicKeyBytesJCE = publicKeyJCE.getEncoded(); @@ -117,44 +94,37 @@ public void testRSAKeyGen_JCEToPlus() throws Exception { } - - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncodedJCEtoPlus_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { // 1024 key size for FIPS not supported return; } keyFactoryCreateFromEncodedJCEToPlus(1024); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncodedPlusToJCE_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { // 1024 key size for FIPS not supported return; } keyFactoryCreateFromEncodedPlusToJCE(1024); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromKeySpecJCEToPlus_2048() throws Exception { keyFactoryCreateFromKeySpecJCEToPlus(2048); } + @Test public void testRSAKeyFactoryCreateFromKeySpecPlusToJCE_2048() throws Exception { keyFactoryCreateFromKeySpecPlusToJCE(2048); } /* - //-------------------------------------------------------------------------- - // - // + + @Test public void testRSAKeyFactoryCreateFromKeySpec() throws Exception { RSAPrivateCrtKeySpec crtSpec = new RSAPrivateCrtKeySpec( @@ -183,9 +153,7 @@ public void testRSAKeyFactoryCreateFromKeySpec() throws Exception { RSAPublicKey rsaPub = (RSAPublicKey) rsaKeyFactory.generatePublic(rsaPublicSpec); } */ - //-------------------------------------------------------------------------- - // - // + protected KeyPair generateKeyPair(KeyPairGenerator keyPairGen, int size) throws Exception { keyPairGen.initialize(size); KeyPair keyPair = keyPairGen.generateKeyPair(); @@ -209,9 +177,7 @@ protected KeyPair generateKeyPair(KeyPairGenerator keyPairGen, int size) throws return keyPair; } - //-------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromEncodedPlusToJCE(int size) throws Exception { KeyPair rsaKeyPairPlus = generateKeyPair(rsaKeyPairGenPlus, size); @@ -303,9 +269,7 @@ protected void keyFactoryCreateFromEncodedJCEToPlus(int size) throws Exception { } - //-------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromKeySpecJCEToPlus(int size) throws Exception { KeyPair rsaKeyPairJCE = generateKeyPair(rsaKeyPairGenJCE, size); @@ -392,15 +356,16 @@ protected void keyFactoryCreateFromKeySpecPlusToJCE(int size) throws Exception { } } + @Test public void testSignJCEAndVerifyPlus() { try { - rsaKeyPairGenJCE.initialize(this.keySize); + rsaKeyPairGenJCE.initialize(getKeySize()); KeyPair rsaKeyPairJCE = rsaKeyPairGenJCE.generateKeyPair(); rsaKeyPairJCE.getPublic(); RSAPrivateKey rsaPrivJCE = (RSAPrivateKey) rsaKeyPairJCE.getPrivate(); - Signature signingJCE = Signature.getInstance("SHA256WithRSA", interopProviderName); + Signature signingJCE = Signature.getInstance("SHA256WithRSA", getInteropProviderName()); signingJCE.initSign(rsaPrivJCE); signingJCE.update(origMsg); byte[] signedBytesJCE = signingJCE.sign(); @@ -413,7 +378,7 @@ public void testSignJCEAndVerifyPlus() { RSAPublicKey rsaPubPlus = (RSAPublicKey) rsaKeyFactoryPlus.generatePublic(x509SpecJCE); rsaKeyFactoryPlus.generatePrivate(pkcs8SpecJCE); - Signature verifyingPlus = Signature.getInstance("SHA256withRSA", providerName); + Signature verifyingPlus = Signature.getInstance("SHA256withRSA", getProviderName()); verifyingPlus.initVerify(rsaPubPlus); verifyingPlus.update(origMsg); assertTrue("Signature verification failed", verifyingPlus.verify(signedBytesJCE)); @@ -423,16 +388,17 @@ public void testSignJCEAndVerifyPlus() { } } + @Test public void testSignJCEAndVerifyPlusPrivateCrt() { try { - rsaKeyPairGenJCE.initialize(this.keySize); + rsaKeyPairGenJCE.initialize(getKeySize()); KeyPair rsaKeyPairJCE = rsaKeyPairGenJCE.generateKeyPair(); rsaKeyPairJCE.getPublic(); RSAPrivateCrtKey rsaPrivJCE = (RSAPrivateCrtKey) rsaKeyPairJCE.getPrivate(); - Signature signingJCE = Signature.getInstance("SHA256WithRSA", interopProviderName); + Signature signingJCE = Signature.getInstance("SHA256WithRSA", getInteropProviderName()); signingJCE.initSign(rsaPrivJCE); signingJCE.update(origMsg); byte[] signedBytesJCE = signingJCE.sign(); @@ -445,7 +411,7 @@ public void testSignJCEAndVerifyPlusPrivateCrt() { RSAPublicKey rsaPubPlus = (RSAPublicKey) rsaKeyFactoryPlus.generatePublic(x509SpecJCE); rsaKeyFactoryPlus.generatePrivate(pkcs8SpecJCE); - Signature verifyingPlus = Signature.getInstance("SHA256withRSA", providerName); + Signature verifyingPlus = Signature.getInstance("SHA256withRSA", getProviderName()); verifyingPlus.initVerify(rsaPubPlus); verifyingPlus.update(origMsg); assertTrue("Signature verification failed", verifyingPlus.verify(signedBytesJCE)); @@ -455,15 +421,16 @@ public void testSignJCEAndVerifyPlusPrivateCrt() { } } + @Test public void testSignPlusAndVerifyJCE() { try { - rsaKeyPairGenPlus.initialize(this.keySize); + rsaKeyPairGenPlus.initialize(getKeySize()); KeyPair rsaKeyPairPlus = rsaKeyPairGenPlus.generateKeyPair(); rsaKeyPairPlus.getPublic(); RSAPrivateKey rsaPrivPlus = (RSAPrivateKey) rsaKeyPairPlus.getPrivate(); - Signature signingPlus = Signature.getInstance("SHA256WithRSA", providerName); + Signature signingPlus = Signature.getInstance("SHA256WithRSA", getProviderName()); signingPlus.initSign(rsaPrivPlus); signingPlus.update(origMsg); byte[] signedBytesPlus = signingPlus.sign(); @@ -476,7 +443,7 @@ public void testSignPlusAndVerifyJCE() { RSAPublicKey rsaPubJCE = (RSAPublicKey) rsaKeyFactoryJCE.generatePublic(x509SpecPlus); rsaKeyFactoryJCE.generatePrivate(pkcs8SpecPlus); - Signature verifyingJCE = Signature.getInstance("SHA256withRSA", interopProviderName); + Signature verifyingJCE = Signature.getInstance("SHA256withRSA", getInteropProviderName()); verifyingJCE.initVerify(rsaPubJCE); verifyingJCE.update(origMsg); assertTrue("Signature verification", verifyingJCE.verify(signedBytesPlus)); @@ -490,16 +457,16 @@ public void testSignPlusAndVerifyJCE() { } - + @Test public void testSignPlusAndVerifyJCECrt() { try { - rsaKeyPairGenPlus.initialize(this.keySize); + rsaKeyPairGenPlus.initialize(getKeySize()); KeyPair rsaKeyPairPlus = rsaKeyPairGenPlus.generateKeyPair(); rsaKeyPairPlus.getPublic(); RSAPrivateCrtKey rsaPrivPlus = (RSAPrivateCrtKey) rsaKeyPairPlus.getPrivate(); - Signature signingPlus = Signature.getInstance("SHA256WithRSA", providerName); + Signature signingPlus = Signature.getInstance("SHA256WithRSA", getProviderName()); signingPlus.initSign(rsaPrivPlus); signingPlus.update(origMsg); byte[] signedBytesPlus = signingPlus.sign(); @@ -512,7 +479,7 @@ public void testSignPlusAndVerifyJCECrt() { RSAPublicKey rsaPubJCE = (RSAPublicKey) rsaKeyFactoryJCE.generatePublic(x509SpecPlus); rsaKeyFactoryJCE.generatePrivate(pkcs8SpecPlus); - Signature verifyingJCE = Signature.getInstance("SHA256withRSA", providerName); + Signature verifyingJCE = Signature.getInstance("SHA256withRSA", getProviderName()); verifyingJCE.initVerify(rsaPubJCE); verifyingJCE.update(origMsg); assertTrue("Signature verification failed", verifyingJCE.verify(signedBytesPlus)); @@ -522,6 +489,7 @@ public void testSignPlusAndVerifyJCECrt() { } } + @Test public void testEncryptPlusDecryptJCE() { try { @@ -531,12 +499,12 @@ public void testEncryptPlusDecryptJCE() { // public and Private key;" + // "encrypt with JCE and d/ecrypt with JCEPlus and vice versa").getBytes(); byte[] cipherText; - rsaKeyPairGenPlus.initialize(this.keySize); + rsaKeyPairGenPlus.initialize(getKeySize()); KeyPair rsaKeyPairPlus = rsaKeyPairGenPlus.generateKeyPair(); RSAPublicKey rsaPubPlus = (RSAPublicKey) rsaKeyPairPlus.getPublic(); rsaKeyPairPlus.getPrivate(); - Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherPlus.init(Cipher.ENCRYPT_MODE, rsaPubPlus); cipherText = cipherPlus.doFinal(msgBytes); @@ -549,7 +517,7 @@ public void testEncryptPlusDecryptJCE() { RSAPrivateCrtKey rsaPrivJCE = (RSAPrivateCrtKey) rsaKeyFactoryJCE .generatePrivate(pkcs8SpecPlus); - Cipher cipherJCE = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherJCE = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherJCE.init(Cipher.DECRYPT_MODE, rsaPrivJCE); byte[] decryptedBytes = cipherJCE.doFinal(cipherText); System.out.println("msgBytes = " + toHex(msgBytes)); @@ -561,6 +529,7 @@ public void testEncryptPlusDecryptJCE() { } } + @Test public void testEncryptJCEDecryptPlus() { byte[] msgBytes = ("This is a short message".getBytes()); //long message to be encrypted and decrypted using RSA public and Private key;" + @@ -568,12 +537,12 @@ public void testEncryptJCEDecryptPlus() { try { byte[] cipherText; - rsaKeyPairGenJCE.initialize(this.keySize); + rsaKeyPairGenJCE.initialize(getKeySize()); KeyPair rsaKeyPairJCE = rsaKeyPairGenJCE.generateKeyPair(); RSAPublicKey rsaPubJCE = (RSAPublicKey) rsaKeyPairJCE.getPublic(); rsaKeyPairJCE.getPrivate(); - Cipher cipherJCE = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherJCE = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherJCE.init(Cipher.ENCRYPT_MODE, rsaPubJCE); cipherText = cipherJCE.doFinal(msgBytes); @@ -586,7 +555,7 @@ public void testEncryptJCEDecryptPlus() { RSAPrivateCrtKey rsaPrivPlus = (RSAPrivateCrtKey) rsaKeyFactoryPlus .generatePrivate(pkcs8SpecJCE); - Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherPlus.init(Cipher.DECRYPT_MODE, rsaPrivPlus); byte[] decryptedBytes = cipherPlus.doFinal(cipherText); System.out.println("msgBytes = " + toHex(msgBytes)); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInteropBC.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInteropBC.java index 71747603..47872fe9 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAKeyInteropBC.java @@ -26,12 +26,14 @@ import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import javax.crypto.Cipher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class BaseTestRSAKeyInteropBC extends BaseTestJunit5Interop { -public class BaseTestRSAKeyInteropBC extends BaseTestInterop { - //-------------------------------------------------------------------------- - // - // protected KeyPairGenerator rsaKeyPairGenPlus; protected KeyFactory rsaKeyFactoryPlus; protected KeyPairGenerator rsaKeyPairGenBC; @@ -39,38 +41,18 @@ public class BaseTestRSAKeyInteropBC extends BaseTestInterop { byte[] origMsg = "this is the original message to be signed".getBytes(); - //-------------------------------------------------------------------------- - // - // - public BaseTestRSAKeyInteropBC(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - public BaseTestRSAKeyInteropBC(String providerName, String interopProviderName, int size) { - super(providerName, interopProviderName); - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - rsaKeyPairGenPlus = KeyPairGenerator.getInstance("RSA", providerName); - rsaKeyFactoryPlus = KeyFactory.getInstance("RSA", providerName); - rsaKeyPairGenBC = KeyPairGenerator.getInstance("RSA", interopProviderName); - rsaKeyFactoryBC = KeyFactory.getInstance("RSA", interopProviderName); + rsaKeyPairGenPlus = KeyPairGenerator.getInstance("RSA", getProviderName()); + rsaKeyFactoryPlus = KeyFactory.getInstance("RSA", getProviderName()); + rsaKeyPairGenBC = KeyPairGenerator.getInstance("RSA", getInteropProviderName()); + rsaKeyFactoryBC = KeyFactory.getInstance("RSA", getInteropProviderName()); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_PlusToBC() throws Exception { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } KeyPair rsaKeyPairPlus = generateKeyPair(rsaKeyPairGenPlus, keySize); @@ -95,12 +77,10 @@ public void testRSAKeyGen_PlusToBC() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyGen_BCToPlus() throws Exception { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } KeyPair rsaKeyPairBC = generateKeyPair(rsaKeyPairGenBC, keySize); @@ -124,42 +104,35 @@ public void testRSAKeyGen_BCToPlus() throws Exception { } - - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncodedBCtoPlus_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { return; } keyFactoryCreateFromEncodedBCToPlus(1024); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromEncodedPlusToBC_1024() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { return; } keyFactoryCreateFromEncodedPlusToBC(1024); } - //-------------------------------------------------------------------------- - // - // + @Test public void testRSAKeyFactoryCreateFromKeySpecBCToPlus_2048() throws Exception { keyFactoryCreateFromKeySpecBCToPlus(2048); } + @Test public void testRSAKeyFactoryCreateFromKeySpecPlusToBC_2048() throws Exception { keyFactoryCreateFromKeySpecPlusToBC(2048); } /* - //-------------------------------------------------------------------------- - // - // + + @Test public void testRSAKeyFactoryCreateFromKeySpec() throws Exception { RSAPrivateCrtKeySpec crtSpec = new RSAPrivateCrtKeySpec( @@ -188,9 +161,7 @@ public void testRSAKeyFactoryCreateFromKeySpec() throws Exception { RSAPublicKey rsaPub = (RSAPublicKey) rsaKeyFactory.generatePublic(rsaPublicSpec); } */ - //-------------------------------------------------------------------------- - // - // + protected KeyPair generateKeyPair(KeyPairGenerator keyPairGen, int size) throws Exception { keyPairGen.initialize(size); KeyPair keyPair = keyPairGen.generateKeyPair(); @@ -214,9 +185,7 @@ protected KeyPair generateKeyPair(KeyPairGenerator keyPairGen, int size) throws return keyPair; } - //-------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromEncodedPlusToBC(int size) throws Exception { KeyPair rsaKeyPairPlus = generateKeyPair(rsaKeyPairGenPlus, size); @@ -308,9 +277,7 @@ protected void keyFactoryCreateFromEncodedBCToPlus(int size) throws Exception { } - //-------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromKeySpecBCToPlus(int size) throws Exception { KeyPair rsaKeyPairBC = generateKeyPair(rsaKeyPairGenBC, size); @@ -396,11 +363,12 @@ protected void keyFactoryCreateFromKeySpecPlusToBC(int size) throws Exception { } } + @Test public void testSignBCAndVerifyPlus() { try { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } rsaKeyPairGenBC.initialize(keySize); @@ -408,7 +376,7 @@ public void testSignBCAndVerifyPlus() { rsaKeyPairBC.getPublic(); RSAPrivateKey rsaPrivBC = (RSAPrivateKey) rsaKeyPairBC.getPrivate(); - Signature signingBC = Signature.getInstance("SHA256WithRSA", interopProviderName); + Signature signingBC = Signature.getInstance("SHA256WithRSA", getInteropProviderName()); signingBC.initSign(rsaPrivBC); signingBC.update(origMsg); byte[] signedBytesBC = signingBC.sign(); @@ -421,7 +389,7 @@ public void testSignBCAndVerifyPlus() { RSAPublicKey rsaPubPlus = (RSAPublicKey) rsaKeyFactoryPlus.generatePublic(x509SpecBC); rsaKeyFactoryPlus.generatePrivate(pkcs8SpecBC); - Signature verifyingPlus = Signature.getInstance("SHA256withRSA", providerName); + Signature verifyingPlus = Signature.getInstance("SHA256withRSA", getProviderName()); verifyingPlus.initVerify(rsaPubPlus); verifyingPlus.update(origMsg); assertTrue("Signature verification failed", verifyingPlus.verify(signedBytesBC)); @@ -431,12 +399,13 @@ public void testSignBCAndVerifyPlus() { } } + @Test public void testSignBCAndVerifyPlusPrivateCrt() { try { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } rsaKeyPairGenBC.initialize(keySize); @@ -444,7 +413,7 @@ public void testSignBCAndVerifyPlusPrivateCrt() { rsaKeyPairBC.getPublic(); RSAPrivateCrtKey rsaPrivBC = (RSAPrivateCrtKey) rsaKeyPairBC.getPrivate(); - Signature signingBC = Signature.getInstance("SHA256WithRSA", interopProviderName); + Signature signingBC = Signature.getInstance("SHA256WithRSA", getInteropProviderName()); signingBC.initSign(rsaPrivBC); signingBC.update(origMsg); byte[] signedBytesBC = signingBC.sign(); @@ -457,7 +426,7 @@ public void testSignBCAndVerifyPlusPrivateCrt() { RSAPublicKey rsaPubPlus = (RSAPublicKey) rsaKeyFactoryPlus.generatePublic(x509SpecBC); rsaKeyFactoryPlus.generatePrivate(pkcs8SpecBC); - Signature verifyingPlus = Signature.getInstance("SHA256withRSA", providerName); + Signature verifyingPlus = Signature.getInstance("SHA256withRSA", getProviderName()); verifyingPlus.initVerify(rsaPubPlus); verifyingPlus.update(origMsg); assertTrue("Signature verification failed", verifyingPlus.verify(signedBytesBC)); @@ -467,11 +436,12 @@ public void testSignBCAndVerifyPlusPrivateCrt() { } } + @Test public void testSignPlusAndVerifyBC() { try { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } rsaKeyPairGenPlus.initialize(keySize); @@ -479,7 +449,7 @@ public void testSignPlusAndVerifyBC() { rsaKeyPairPlus.getPublic(); RSAPrivateKey rsaPrivPlus = (RSAPrivateKey) rsaKeyPairPlus.getPrivate(); - Signature signingPlus = Signature.getInstance("SHA256WithRSA", providerName); + Signature signingPlus = Signature.getInstance("SHA256WithRSA", getProviderName()); signingPlus.initSign(rsaPrivPlus); signingPlus.update(origMsg); byte[] signedBytesPlus = signingPlus.sign(); @@ -492,7 +462,7 @@ public void testSignPlusAndVerifyBC() { RSAPublicKey rsaPubBC = (RSAPublicKey) rsaKeyFactoryBC.generatePublic(x509SpecPlus); rsaKeyFactoryBC.generatePrivate(pkcs8SpecPlus); - Signature verifyingBC = Signature.getInstance("SHA256withRSA", interopProviderName); + Signature verifyingBC = Signature.getInstance("SHA256withRSA", getInteropProviderName()); verifyingBC.initVerify(rsaPubBC); verifyingBC.update(origMsg); assertTrue("Signature verification", verifyingBC.verify(signedBytesPlus)); @@ -506,12 +476,12 @@ public void testSignPlusAndVerifyBC() { } - + @Test public void testSignPlusAndVerifyBCCrt() { try { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } rsaKeyPairGenPlus.initialize(keySize); @@ -519,7 +489,7 @@ public void testSignPlusAndVerifyBCCrt() { rsaKeyPairPlus.getPublic(); RSAPrivateCrtKey rsaPrivPlus = (RSAPrivateCrtKey) rsaKeyPairPlus.getPrivate(); - Signature signingPlus = Signature.getInstance("SHA256WithRSA", providerName); + Signature signingPlus = Signature.getInstance("SHA256WithRSA", getProviderName()); signingPlus.initSign(rsaPrivPlus); signingPlus.update(origMsg); byte[] signedBytesPlus = signingPlus.sign(); @@ -532,7 +502,7 @@ public void testSignPlusAndVerifyBCCrt() { RSAPublicKey rsaPubBC = (RSAPublicKey) rsaKeyFactoryBC.generatePublic(x509SpecPlus); rsaKeyFactoryBC.generatePrivate(pkcs8SpecPlus); - Signature verifyingBC = Signature.getInstance("SHA256withRSA", providerName); + Signature verifyingBC = Signature.getInstance("SHA256withRSA", getProviderName()); verifyingBC.initVerify(rsaPubBC); verifyingBC.update(origMsg); assertTrue("Signature verification failed", verifyingBC.verify(signedBytesPlus)); @@ -542,6 +512,7 @@ public void testSignPlusAndVerifyBCCrt() { } } + @Test public void testEncryptPlusDecryptBC() { try { @@ -552,7 +523,7 @@ public void testEncryptPlusDecryptBC() { // "encrypt with BC and d/ecrypt with BCPlus and vice versa").getBytes(); byte[] cipherText; int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } rsaKeyPairGenPlus.initialize(keySize); @@ -560,7 +531,7 @@ public void testEncryptPlusDecryptBC() { RSAPublicKey rsaPubPlus = (RSAPublicKey) rsaKeyPairPlus.getPublic(); rsaKeyPairPlus.getPrivate(); - Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherPlus.init(Cipher.ENCRYPT_MODE, rsaPubPlus); cipherText = cipherPlus.doFinal(msgBytes); @@ -573,7 +544,7 @@ public void testEncryptPlusDecryptBC() { RSAPrivateCrtKey rsaPrivBC = (RSAPrivateCrtKey) rsaKeyFactoryBC .generatePrivate(pkcs8SpecPlus); - Cipher cipherBC = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherBC = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherBC.init(Cipher.DECRYPT_MODE, rsaPrivBC); byte[] decryptedBytes = cipherBC.doFinal(cipherText); System.out.println("msgBytes = " + toHex(msgBytes)); @@ -585,6 +556,7 @@ public void testEncryptPlusDecryptBC() { } } + @Test public void testEncryptBCDecryptPlus() { byte[] msgBytes = ("This is a short message".getBytes()); //long message to be encrypted and decrypted using RSA public and Private key;" + @@ -593,7 +565,7 @@ public void testEncryptBCDecryptPlus() { try { byte[] cipherText; int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } rsaKeyPairGenBC.initialize(keySize); @@ -601,7 +573,7 @@ public void testEncryptBCDecryptPlus() { RSAPublicKey rsaPubBC = (RSAPublicKey) rsaKeyPairBC.getPublic(); rsaKeyPairBC.getPrivate(); - Cipher cipherBC = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherBC = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherBC.init(Cipher.ENCRYPT_MODE, rsaPubBC); cipherText = cipherBC.doFinal(msgBytes); @@ -614,7 +586,7 @@ public void testEncryptBCDecryptPlus() { RSAPrivateCrtKey rsaPrivPlus = (RSAPrivateCrtKey) rsaKeyFactoryPlus .generatePrivate(pkcs8SpecBC); - Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", providerName); + Cipher cipherPlus = Cipher.getInstance("RSA/ECB/PKCS1Padding", getProviderName()); cipherPlus.init(Cipher.DECRYPT_MODE, rsaPrivPlus); byte[] decryptedBytes = cipherPlus.doFinal(cipherText); System.out.println("msgBytes = " + toHex(msgBytes)); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS.java index 57056966..774cdffc 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS.java @@ -23,8 +23,10 @@ import java.security.spec.RSAPrivateKeySpec; import java.security.spec.RSAPublicKeySpec; import java.security.spec.X509EncodedKeySpec; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestRSAPSS extends BaseTest { +public class BaseTestRSAPSS extends BaseTestJunit5 { String IBM_ALG = "RSASA-PSS"; //String BC_ALG = "SHA1withRSAandMGF1"; @@ -110,27 +112,16 @@ public class BaseTestRSAPSS extends BaseTest { static boolean printJunitTrace = false; - public BaseTestRSAPSS(String providerName) { - super(providerName); - printJunitTrace = Boolean - .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - protected void setUp() throws Exception { - - } - - @org.junit.Test + @Test public void testRSAPlainKeySignatureWithPSS() throws Exception { KeyFactory kf; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support RSA plain keys return; } - kf = KeyFactory.getInstance("RSA", providerName); + kf = KeyFactory.getInstance("RSA", getProviderName()); RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(N, E); PublicKey publicKey = kf.generatePublic(pubSpec); @@ -142,7 +133,7 @@ public void testRSAPlainKeySignatureWithPSS() throws Exception { 20, 1); // Generate Signature - Signature sig = Signature.getInstance("RSAPSS", providerName); + Signature sig = Signature.getInstance("RSAPSS", getProviderName()); if (pssParameter != null) { sig.setParameter(pssParameter); AlgorithmParameters algParams = sig.getParameters(); @@ -164,16 +155,16 @@ public void testRSAPlainKeySignatureWithPSS() throws Exception { assertTrue("signature is invalid!!", signatureVerified); } - @org.junit.Test + @Test public void testRSASignatureWithPSS_SHA1() throws Exception { try { //dotestSignature(content, IBM_ALG, 1024, null, providerName); int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } - dotestSignature(msg.getBytes(), IBM_ALG, keySize, null, providerName); + dotestSignature(msg.getBytes(), IBM_ALG, keySize, null, getProviderName()); } catch (Exception e) { e.printStackTrace(); @@ -186,18 +177,18 @@ public void testRSASignatureWithPSS_SHA1() throws Exception { * Generate a key once and use it for multiple tests - The OpenJCEPlusFIPS does not allow keysize < 2048 * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureWithPSSBigMsgMultiKeySize() throws Exception { try { int startSize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { startSize = 2048; } for (int i = startSize; i < 4096;) { if (printJunitTrace) System.out.println("keySize=" + i); - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", providerName); + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", getProviderName()); keyGen.initialize(i, new java.security.SecureRandom()); KeyPair keyPair = keyGen.genKeyPair(); dotestSignature(content3, IBM_ALG, keyPair, null); @@ -218,12 +209,12 @@ public void testRSASignatureWithPSSBigMsgMultiKeySize() throws Exception { * IBM vs BC * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureWithPSSMultiByteSize_timed() throws Exception { try { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } @@ -236,7 +227,7 @@ public void testRSASignatureWithPSSMultiByteSize_timed() throws Exception { System.out.println("msgSize=" + dynMsg.length); //dotestSignature(dynMsg, IBM_ALG, 512, null, providerName); - dotestSignature(dynMsg, IBM_ALG, keySize, null, providerName); + dotestSignature(dynMsg, IBM_ALG, keySize, null, getProviderName()); } } catch (Exception e) { @@ -249,10 +240,10 @@ public void testRSASignatureWithPSSMultiByteSize_timed() throws Exception { * Test after setting parameters * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureWithPSSParameterSpec() throws Exception { try { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertTrue(true); return; } @@ -269,12 +260,12 @@ public void testRSASignatureWithPSSParameterSpec() throws Exception { * SHA256 * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureSHA256() throws Exception { try { PSSParameterSpec pssParameter = specSHA256Salt20; - dotestSignature(content, IBM_ALG, 2048, pssParameter, providerName); + dotestSignature(content, IBM_ALG, 2048, pssParameter, getProviderName()); } catch (Exception e) { e.printStackTrace(); @@ -286,13 +277,13 @@ public void testRSASignatureSHA256() throws Exception { * SHA512 * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureSHA512() throws Exception { PSSParameterSpec pssParameter = new PSSParameterSpec("SHA512", "MGF1", MGF1ParameterSpec.SHA512, 20, 1); try { - dotestSignature(content, IBM_ALG, 2048, pssParameter, providerName); + dotestSignature(content, IBM_ALG, 2048, pssParameter, getProviderName()); } catch (Exception e) { e.printStackTrace(); @@ -304,12 +295,12 @@ public void testRSASignatureSHA512() throws Exception { * SHA384 * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureSHA384() throws Exception { try { PSSParameterSpec pssParameter = new PSSParameterSpec("SHA384", "MGF1", MGF1ParameterSpec.SHA384, 20, 1); - dotestSignature(content, IBM_ALG, 2048, pssParameter, providerName); + dotestSignature(content, IBM_ALG, 2048, pssParameter, getProviderName()); } catch (Exception e) { e.printStackTrace(); @@ -320,7 +311,7 @@ public void testRSASignatureSHA384() throws Exception { /** * SHA256 - test one byte */ - @org.junit.Test + @Test public void testRSASignatureSHA256OneByte() throws Exception { try { PSSParameterSpec pssParameterSpec = specSHA256Salt40; @@ -396,7 +387,7 @@ protected void dotestSignature(byte[] content, String algorithm, KeyPair keyPair // keyGen.initialize(keySize, new java.security.SecureRandom()); // KeyPair keyPair = keyGen.genKeyPair(); - Signature sig = Signature.getInstance(algorithm, providerName); + Signature sig = Signature.getInstance(algorithm, getProviderName()); if (pssParameterSpec != null) { if (printJunitTrace) System.out.println("calling sig.setParameter"); @@ -433,16 +424,16 @@ protected void dotestSignaturePSSParameterSpec(byte[] content, String algorithm, // Generate Signature - if (providerName.equals("OpenJCEPlusFIPS") && keySize == 1024) { + if (getProviderName().equals("OpenJCEPlusFIPS") && keySize == 1024) { assertTrue(true); return; } - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", providerName); + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", getProviderName()); keyGen.initialize(keySize, new java.security.SecureRandom()); KeyPair keyPair = keyGen.genKeyPair(); - Signature sig = Signature.getInstance(algorithm, providerName); + Signature sig = Signature.getInstance(algorithm, getProviderName()); // Set salt length PSSParameterSpec pss = new PSSParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1, 20, 1); @@ -476,11 +467,11 @@ protected void dotestSignaturePSSParameterSpec(byte[] content, String algorithm, // Generate Signature - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", providerName); + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", getProviderName()); keyGen.initialize(keySize, new java.security.SecureRandom()); KeyPair keyPair = keyGen.genKeyPair(); - Signature sig = Signature.getInstance(algorithm, providerName); + Signature sig = Signature.getInstance(algorithm, getProviderName()); // Set salt length if (pssParameterSpec != null) { sig.setParameter(pssParameterSpec); @@ -512,29 +503,29 @@ String toHex(byte[] data) { return buf.toString(); } - @org.junit.Test + @Test public void testRSAPSSKeyFactory() throws Exception { try { int keySize = 1024; - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { keySize = 2048; } if (printJunitTrace) - System.out.println("Test RSAPSS KeyFactory provider: " + providerName); - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", providerName); + System.out.println("Test RSAPSS KeyFactory provider: " + getProviderName()); + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", getProviderName()); keyGen.initialize(keySize, new java.security.SecureRandom()); KeyPair keyPair = keyGen.genKeyPair(); RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); - KeyFactory kf = KeyFactory.getInstance("RSASSA-PSS", providerName); + KeyFactory kf = KeyFactory.getInstance("RSASSA-PSS", getProviderName()); X509EncodedKeySpec x509KeySpec = kf.getKeySpec(publicKey, X509EncodedKeySpec.class); byte[] encodedKey = x509KeySpec.getEncoded(); X509EncodedKeySpec x509KeySpec2 = new X509EncodedKeySpec(encodedKey); - KeyFactory.getInstance("RSASSA-PSS", providerName); + KeyFactory.getInstance("RSASSA-PSS", getProviderName()); RSAPublicKey publicKey2 = (RSAPublicKey) kf.generatePublic(x509KeySpec2); assertTrue("Algorithm name different", publicKey.getAlgorithm().equalsIgnoreCase(publicKey2.getAlgorithm())); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS2.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS2.java index ef46ae7e..b9d75f23 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,9 +20,10 @@ import java.security.spec.MGF1ParameterSpec; import java.security.spec.PSSParameterSpec; import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -//public class BaseTestRSAPSS2 extends TestCase { -public class BaseTestRSAPSS2 extends BaseTest { +public class BaseTestRSAPSS2 extends BaseTestJunit5 { String signingProvidersSignatureAlgorithmName = null; String verifyingProvidersSignatureAlgorithmName = null; @@ -52,16 +53,8 @@ public class BaseTestRSAPSS2 extends BaseTest { Provider provider = null; static boolean printJunitTrace = false; - - public BaseTestRSAPSS2(String providerName) { - super(providerName); - printJunitTrace = Boolean - .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { if (printJunitTrace) System.out.println( @@ -73,8 +66,8 @@ protected void setUp() throws Exception { System.out.println( "==============================================================================="); - signingProviderName = providerName; - verifyingProviderName = providerName; + signingProviderName = getProviderName(); + verifyingProviderName = getProviderName(); // Add the OpenJCEPlus provider to the provider's list provider = new com.ibm.crypto.plus.provider.OpenJCEPlus(); try { @@ -217,8 +210,7 @@ protected void setUp() throws Exception { // BEGINNING OF RSA-PSS SIGNATURE TESTS //================================================================================================================== - - + @Test public void testRSAPSS() throws Exception { KeyPair rsaKeyPair = null; @@ -3722,6 +3714,7 @@ public void testRSAPSS() throws Exception { } // end testRSAPSS() // Test reuse of a signature object + @Test public void testRSAPSS_SameObjectTest() throws Exception { try { @@ -3811,29 +3804,6 @@ public void testRSAPSS_SameObjectTest() throws Exception { } } // end testRSAPSS_SameObjectTest()( ) - - - // public static void main(String[] args){ - // - // if (printJunitTrace) System.out.println("BaseTestRSAPSS2.java: main(): METHOD ENTRY"); - // - // BaseTestRSAPSS2 test = new BaseTestRSAPSS2(); - // - // try { - // test.mySetUp(); - // test.testRSAPSS(); - // } - // catch (Exception ex) - // { - // if (printJunitTrace) System.out.println("The following exception was thrown:"); - // ex.printStackTrace(); - // } - // - // if (printJunitTrace) System.out.println("\nBaseTestRSAPSS2.java: main(): METHOD EXIT"); - // } - - - // Compute the signature, but do not use PSSParameters class private static boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, String signingProvidersSignatureAlgorithmName, diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop.java index 8d4ae916..87c885e4 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,15 +16,15 @@ import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; -import java.security.Security; import java.security.Signature; import java.security.SignatureException; import java.security.spec.InvalidParameterSpecException; import java.security.spec.MGF1ParameterSpec; import java.security.spec.PSSParameterSpec; -import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestRSAPSSInterop extends BaseTestInterop { +public class BaseTestRSAPSSInterop extends BaseTestJunit5Interop { String JCEPlus_ALG = "RSASA-PSS"; String BC_ALG = "SHA1withRSAandMGF1"; @@ -98,21 +98,11 @@ public class BaseTestRSAPSSInterop extends BaseTestInterop { final int NONDEFAULT_PARAMS = 2; final int PARAMS_SALT40 = 3; - - public BaseTestRSAPSSInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - Security.addProvider(new BouncyCastleProvider()); - } - - protected void setUp() throws Exception { - - } - - @org.junit.Test + @Test public void testRSASignatureWithPSS_SHA1() throws Exception { try { - dotestSignature(content, JCEPlus_ALG, JCEPlus_ALG, 1024, null, providerName, - providerName); + dotestSignature(content, JCEPlus_ALG, JCEPlus_ALG, 1024, null, getProviderName(), + getProviderName()); } catch (Exception e) { e.printStackTrace(); @@ -125,77 +115,77 @@ public void testRSASignatureWithPSS_SHA1() throws Exception { * Generate a key once and use it for multiple tests - The OpenJCEPlusFIPS does not allow keysize < 1024 * @throws Exception */ - @org.junit.Test + @Test public void testRSAPSSBigMsgMultiKeySize() throws Exception { try { for (int i = 1024; i < 4096;) { - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", providerName); + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", getProviderName()); keyGen.initialize(i, new java.security.SecureRandom()); KeyPair keyPair = keyGen.genKeyPair(); /* Sign and Verify with JCEPlus only with PSSParameterSpec.DEFAULT */ - dotestSignature(content3, JCEPlus_ALG, JCEPlus_ALG, keyPair, null, providerName, - providerName); + dotestSignature(content3, JCEPlus_ALG, JCEPlus_ALG, keyPair, null, getProviderName(), + getProviderName()); - dotestSignature(oneByte, JCEPlus_ALG, JCEPlus_ALG, keyPair, null, providerName, - providerName); + dotestSignature(oneByte, JCEPlus_ALG, JCEPlus_ALG, keyPair, null, getProviderName(), + getProviderName()); dotestSignature(msg.getBytes(), JCEPlus_ALG, JCEPlus_ALG, keyPair, null, - providerName, providerName); + getProviderName(), getProviderName()); - dotestSignature(content, JCEPlus_ALG, JCEPlus_ALG, keyPair, null, providerName, - providerName); + dotestSignature(content, JCEPlus_ALG, JCEPlus_ALG, keyPair, null, getProviderName(), + getProviderName()); /* Sign and Verify with 2 providers with PSSParameterSpec.DEFAULT*/ - dotestSignature(content3, JCEPlus_ALG, SunJCE_ALG, keyPair, null, providerName, - interopProviderName); - dotestSignature(oneByte, JCEPlus_ALG, SunJCE_ALG, keyPair, null, providerName, - interopProviderName); + dotestSignature(content3, JCEPlus_ALG, SunJCE_ALG, keyPair, null, getProviderName(), + getInteropProviderName()); + dotestSignature(oneByte, JCEPlus_ALG, SunJCE_ALG, keyPair, null, getProviderName(), + getInteropProviderName()); dotestSignature(msg.getBytes(), JCEPlus_ALG, SunJCE_ALG, keyPair, null, - providerName, interopProviderName); - dotestSignature(content, JCEPlus_ALG, SunJCE_ALG, keyPair, null, providerName, - interopProviderName); + getProviderName(), getInteropProviderName()); + dotestSignature(content, JCEPlus_ALG, SunJCE_ALG, keyPair, null, getProviderName(), + getInteropProviderName()); /* Use Specified salt size - Generarte Signature with JCEPlus and Verify with JCE */ dotestSignatureProviderAToProviderB(content, JCEPlus_ALG, SunJCE_ALG, keyPair, 20, - providerName, interopProviderName); + getProviderName(), getInteropProviderName()); dotestSignatureProviderAToProviderB(content, JCEPlus_ALG, SunJCE_ALG, keyPair, 30, - providerName, interopProviderName); + getProviderName(), getInteropProviderName()); dotestSignatureProviderAToProviderB(content, JCEPlus_ALG, SunJCE_ALG, keyPair, 40, - providerName, interopProviderName); + getProviderName(), getInteropProviderName()); /* Use Specified salt size - Generarte Signature with JCE and Verify with JCEPlus */ dotestSignatureProviderAToProviderB(content, SunJCE_ALG, JCEPlus_ALG, keyPair, 20, - interopProviderName, providerName); + getInteropProviderName(), getProviderName()); dotestSignatureProviderAToProviderB(content, SunJCE_ALG, JCEPlus_ALG, keyPair, 30, - interopProviderName, providerName); + getInteropProviderName(), getProviderName()); dotestSignatureProviderAToProviderB(content, SunJCE_ALG, JCEPlus_ALG, keyPair, 40, - interopProviderName, providerName); + getInteropProviderName(), getProviderName()); /* Use Specified salt size - Generarte Signature with JCEPlus and Verify with BC */ dotestSignatureProviderAToProviderB(content, JCEPlus_ALG, BC_ALG, keyPair, 20, - providerName, BCProvider); + getProviderName(), BCProvider); dotestSignatureProviderAToProviderB(content, JCEPlus_ALG, SunJCE_ALG, keyPair, 30, - providerName, BCProvider); + getProviderName(), BCProvider); dotestSignatureProviderAToProviderB(content, JCEPlus_ALG, SunJCE_ALG, keyPair, 40, - providerName, BCProvider); + getProviderName(), BCProvider); /* Use Specified salt size - Generarte Signature with BC and Verify with JCEPlus */ dotestSignatureProviderAToProviderB(content, BC_ALG, JCEPlus_ALG, keyPair, 20, - BCProvider, providerName); + BCProvider, getProviderName()); dotestSignatureProviderAToProviderB(content, BC_ALG, JCEPlus_ALG, keyPair, 30, - BCProvider, providerName); + BCProvider, getProviderName()); dotestSignatureProviderAToProviderB(content, BC_ALG, JCEPlus_ALG, keyPair, 40, - BCProvider, providerName); + BCProvider, getProviderName()); i = i + 512; @@ -216,7 +206,7 @@ public void testRSAPSSBigMsgMultiKeySize() throws Exception { * IBM vs BC * @throws Exception */ - @org.junit.Test + @Test public void testRSASignatureWithPSSMultiByteSize_timed() throws Exception { try { for (int i = 1; i <= 10; i++) { @@ -225,15 +215,15 @@ public void testRSASignatureWithPSSMultiByteSize_timed() throws Exception { System.arraycopy(elevenBytes, 0, dynMsg, j * 11, 11); } // //System.out.println("msgSize=" + dynMsg.length); - dotestSignature(dynMsg, JCEPlus_ALG, JCEPlus_ALG, 1024, null, providerName, - providerName); - dotestSignature(dynMsg, JCEPlus_ALG, BC_ALG, 1024, null, providerName, BCProvider); - dotestSignature(dynMsg, BC_ALG, JCEPlus_ALG, 1024, null, BCProvider, providerName); + dotestSignature(dynMsg, JCEPlus_ALG, JCEPlus_ALG, 1024, null, getProviderName(), + getProviderName()); + dotestSignature(dynMsg, JCEPlus_ALG, BC_ALG, 1024, null, getProviderName(), BCProvider); + dotestSignature(dynMsg, BC_ALG, JCEPlus_ALG, 1024, null, BCProvider, getProviderName()); - dotestSignature(dynMsg, JCEPlus_ALG, SunJCE_ALG, 1024, null, providerName, - interopProviderName); - dotestSignature(dynMsg, SunJCE_ALG, JCEPlus_ALG, 1024, null, interopProviderName, - providerName); + dotestSignature(dynMsg, JCEPlus_ALG, SunJCE_ALG, 1024, null, getProviderName(), + getInteropProviderName()); + dotestSignature(dynMsg, SunJCE_ALG, JCEPlus_ALG, 1024, null, getInteropProviderName(), + getProviderName()); } @@ -242,16 +232,12 @@ public void testRSASignatureWithPSSMultiByteSize_timed() throws Exception { assertTrue(false); } } - // - // - // /** Test multiple raw messages generated by IBM and verified by BC * * @throws Exception */ - - @org.junit.Test + @Test public void testRSASignatureWithPSSMultiByteSize_IBM2BC2() throws Exception { try { for (int i = 1; i <= 301; i++) { @@ -260,11 +246,11 @@ public void testRSASignatureWithPSSMultiByteSize_IBM2BC2() throws Exception { System.arraycopy(elevenBytes, 0, dynMsg, j * 11, 11); } //System.out.println("msgSize=" + dynMsg.length); - doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, BC_ALG, 1024, 20, providerName, + doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, BC_ALG, 1024, 20, getProviderName(), BCProvider); - doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, BC_ALG, 1024, 40, providerName, + doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, BC_ALG, 1024, 40, getProviderName(), BCProvider); - doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, BC_ALG, 1024, -1, providerName, + doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, BC_ALG, 1024, -1, getProviderName(), BCProvider); // doSignatureJCEPlusToOther(dynMsg, JCEPlus_ALG, SunJCE_ALG, 1024, 20, providerName, interopProviderName); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop2.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop2.java index 5bd48912..492e6fcb 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop2.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,9 +19,10 @@ import java.security.spec.MGF1ParameterSpec; import java.security.spec.PSSParameterSpec; import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -//public class BaseTestRSAPSSInterop2 extends TestCase { -public class BaseTestRSAPSSInterop2 extends BaseTest { +public class BaseTestRSAPSSInterop2 extends BaseTestJunit5 { String signingProvidersSignatureAlgorithmName = null; String verifyingProvidersSignatureAlgorithmName = null; @@ -51,15 +52,8 @@ public class BaseTestRSAPSSInterop2 extends BaseTest { Provider provider = null; static boolean printJunitTrace = false; - public BaseTestRSAPSSInterop2(String providerName) { - super(providerName); - printJunitTrace = Boolean - .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { if (printJunitTrace) System.out.println( @@ -216,8 +210,7 @@ protected void setUp() throws Exception { // BEGINNING OF RSA-PSS SIGNATURE TESTS //================================================================================================================== - - + @Test public void testRSAPSS() throws Exception { KeyPair rsaKeyPair = null; @@ -3438,29 +3431,6 @@ public void testRSAPSS() throws Exception { } // end loop for each RSA key size } // end testRSAPSS() - - - // public static void main(String[] args){ - // - // if (printJunitTrace) System.out.println("BaseTestRSAPSSInterop2.java: main(): METHOD ENTRY"); - // - // BaseTestRSAPSSInterop2 test = new BaseTestRSAPSSInterop2(); - // - // try { - // test.mySetUp(); - // test.testRSAPSS(); - // } - // catch (Exception ex) - // { - // if (printJunitTrace) System.out.println("The following exception was thrown:"); - // ex.printStackTrace(); - // } - // - // if (printJunitTrace) System.out.println("\nBaseTestRSAPSSInterop2.java: main(): METHOD EXIT"); - // } - - - // Compute the signature, but do not use PSSParameters class private static boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, String signingProvidersSignatureAlgorithmName, diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop3.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop3.java index d4174f59..197c7bcd 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop3.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSInterop3.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,16 +12,16 @@ import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; -import java.security.Provider; import java.security.Security; import java.security.Signature; import java.security.interfaces.RSAPublicKey; import java.security.spec.MGF1ParameterSpec; import java.security.spec.PSSParameterSpec; import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -//public class BaseTestRSAPSSInterop3 extends TestCase { -public class BaseTestRSAPSSInterop3 extends BaseTest { +public class BaseTestRSAPSSInterop3 extends BaseTestJunit5 { String signingProvidersSignatureAlgorithmName = null; String verifyingProvidersSignatureAlgorithmName = null; @@ -38,30 +38,23 @@ public class BaseTestRSAPSSInterop3 extends BaseTest { static final byte[] dataToBeSignedLong = "this is text to test the RSAPSS Signature xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" .getBytes(); - static KeyPairGenerator rsaKeyPairGen = null; + KeyPairGenerator rsaKeyPairGen = null; - static KeyPair rsaKeyPair_OpenJCEPlus[] = new KeyPair[6]; - static KeyPair rsaKeyPair_SunRsaSign[] = new KeyPair[6]; - static KeyPair rsaKeyPair_OpenJCEPlusFIPS[] = new KeyPair[6]; + KeyPair rsaKeyPair_OpenJCEPlus[] = new KeyPair[6]; + KeyPair rsaKeyPair_SunRsaSign[] = new KeyPair[6]; + KeyPair rsaKeyPair_OpenJCEPlusFIPS[] = new KeyPair[6]; - static PSSParameterSpec pssParameterSpec = null; + PSSParameterSpec pssParameterSpec = null; - static int testCaseNumber = 1; + int testCaseNumber = 1; - Provider provider = null; - static boolean printJunitTrace = false; + boolean printJunitTrace = false; + @BeforeEach + public void setUp() throws Exception { - public BaseTestRSAPSSInterop3(String providerName) { - super(providerName); printJunitTrace = Boolean .valueOf(System.getProperty("com.ibm.jceplus.junit.printJunitTrace")); - } - - - - protected void setUp() throws Exception { - if (printJunitTrace) System.out.println( "======================================================================================"); @@ -75,18 +68,6 @@ protected void setUp() throws Exception { signingProviderName = "OpenJCEPlus"; verifyingProviderName = "SunRsaSign"; - // Add the OpenJCEPlus provider to the provider's list - provider = (Provider) new com.ibm.crypto.plus.provider.OpenJCEPlus(); - - try { - Security.insertProviderAt(provider, 3); - } catch (Exception ex) { - if (printJunitTrace) - System.out.println( - "Failed to create the OpenJCEPlus provider. The following exception was thrown."); - ex.printStackTrace(); - } - java.security.Provider[] providers = Security.getProviders(); if (printJunitTrace) System.out.println("The providers in the providers list are:"); @@ -218,8 +199,7 @@ protected void setUp() throws Exception { // BEGINNING OF RSA-PSS SIGNATURE TESTS //================================================================================================================== - - + @Test public void testRSAPSS() throws Exception { KeyPair rsaKeyPair = null; @@ -3434,31 +3414,8 @@ public void testRSAPSS() throws Exception { } // end loop for each RSA key size } // end testRSAPSS() - - - // public static void main(String[] args){ - // - // if (printJunitTrace) System.out.println("BaseTestRSAPSSInterop3.java: main(): METHOD ENTRY"); - // - // BaseTestRSAPSSInterop3 test = new BaseTestRSAPSSInterop3(); - // - // try { - // test.mySetUp(); - // test.testRSAPSS(); - // } - // catch (Exception ex) - // { - // if (printJunitTrace) System.out.println("The following exception was thrown:"); - // ex.printStackTrace(); - // } - // - // if (printJunitTrace) System.out.println("\nBaseTestRSAPSSInterop3.java: main(): METHOD EXIT"); - // } - - - // Compute the signature, but do not use PSSParameters class - private static boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, + private boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, String signingProvidersSignatureAlgorithmName, String verifingProvidersSignatureAlgorithmName, String signingProviderName, String verifyingProviderName, @@ -3558,56 +3515,4 @@ private static boolean doSignature(byte[] dataToBeSigned, KeyPair rsaKeyPair, throw ex; } } // end doSignature( ) - - - - private static void showProviders() { - java.security.Provider[] providers = Security.getProviders(); - if (printJunitTrace) - System.out.println("\n================================================"); - if (printJunitTrace) - System.out.println("The security provider's list is:"); - for (int i = 0; i < providers.length; ++i) { - if (printJunitTrace) - System.out.print("provider \""); - if (printJunitTrace) - System.out.print(providers[i].getName()); - if (printJunitTrace) - System.out.print("\": "); - if (printJunitTrace) - System.out.println(providers[i].toString()); - // if (printJunitTrace) System.out.println(providers[i].getInfo()); - if (printJunitTrace) - System.out.println(); - } - - if (printJunitTrace) - System.out.println("================================================\n\n\n"); - } - - - - /** * Converts a byte array to hex string */ - private static String toHexString(byte[] block) { - StringBuffer buf = new StringBuffer(); - char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', - 'E', 'F'}; - int len = block.length; - int high = 0; - int low = 0; - - for (int i = 0; i < len; i++) { - if (i % 16 == 0) - buf.append('\n'); - high = ((block[i] & 0xf0) >> 4); - low = (block[i] & 0x0f); - buf.append(hexChars[high]); - buf.append(hexChars[low]); - buf.append(' '); - } - - return buf.toString(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSSignature.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSSignature.java index 9d03a46e..9122026c 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSSignature.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSAPSSSignature.java @@ -55,7 +55,7 @@ import sun.security.x509.X500Name; import static org.junit.Assert.assertTrue; -public class BaseTestRSAPSSSignature extends BaseTestSignature { +public class BaseTestRSAPSSSignature extends BaseTestJunit5Signature { String IBM_ALG = "RSAPSS"; String BC_ALG = "SHA1withRSAandMGF1"; @@ -1383,8 +1383,7 @@ private void doGenKeyPairBC(String alias, String dname, String keyAlgName, int k } - - + @Test public void testReadDefaultParams3rdPartyCertificates() throws IOException, CertificateException, InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, InvalidParameterSpecException, diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignature.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignature.java index 357cc9bb..d4d0f676 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignature.java @@ -26,13 +26,11 @@ import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.Assert.assertTrue; + +public class BaseTestRSASignature extends BaseTestJunit5Signature { -public class BaseTestRSASignature extends BaseTestSignature { - //-------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); static final BigInteger N = new BigInteger( diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureChunkUpdate.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureChunkUpdate.java index 97687ba2..b68cb65f 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureChunkUpdate.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureChunkUpdate.java @@ -17,7 +17,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class BaseTestRSASignatureChunkUpdate extends BaseTestSignature { +public class BaseTestRSASignatureChunkUpdate extends BaseTestJunit5Signature { static final String KEY_ALGO = "RSA"; static final int KEY_SIZE = 2048; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureInterop.java index 5eec1103..8b3b2eb1 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSASignatureInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,144 +9,94 @@ import java.security.KeyPair; import java.security.KeyPairGenerator; +import org.junit.jupiter.api.Test; public class BaseTestRSASignatureInterop extends BaseTestSignatureInterop { - //-------------------------------------------------------------------------- - // - // + static final byte[] origMsg = "this is the original message to be signed I changed to a very long message to make sure enough bytes are there for copying." .getBytes(); - int keySize = 1024; - - //-------------------------------------------------------------------------- - // - // - - - //-------------------------------------------------------------------------- - // - // - public BaseTestRSASignatureInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - //-------------------------------------------------------------------------- - // - // - public BaseTestRSASignatureInterop(String providerName, String interopProviderName, - int keySize) { - super(providerName, interopProviderName); - this.keySize = keySize; - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1withRSA() throws Exception { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { //FIPS does not support SHA1 return; } - KeyPair keyPair = generateKeyPair(this.keySize); + KeyPair keyPair = generateKeyPair(getKeySize()); doSignVerify("SHA1withRSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA224withRSA() throws Exception { - KeyPair keyPair = generateKeyPair(this.keySize); + KeyPair keyPair = generateKeyPair(getKeySize()); doSignVerify("SHA224withRSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA256withRSA() throws Exception { - KeyPair keyPair = generateKeyPair(this.keySize); + KeyPair keyPair = generateKeyPair(getKeySize()); doSignVerify("SHA256withRSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA384withRSA() throws Exception { - KeyPair keyPair = generateKeyPair(this.keySize); + KeyPair keyPair = generateKeyPair(getKeySize()); doSignVerify("SHA384withRSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA512withRSA() throws Exception { - KeyPair keyPair = generateKeyPair(this.keySize); + KeyPair keyPair = generateKeyPair(getKeySize()); doSignVerify("SHA512withRSA", origMsg, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + /* RSAforSSL is not supported in other cryptographic providers in order to do interopt testing + @Test public void testRSAforSSL_hash1() throws Exception { - KeyPair keyPair = generateKeyPair( this.keySize); + KeyPair keyPair = generateKeyPair( getKeySize()); byte[] sslHash = Arrays.copyOf(origMsg, 1); doSignVerify("RSAforSSL", sslHash, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + + @Test public void testRSAforSSL_hash5() throws Exception { - KeyPair keyPair = generateKeyPair( this.keySize); + KeyPair keyPair = generateKeyPair( getKeySize()); byte[] sslHash = Arrays.copyOf(origMsg, 5); doSignVerify("RSAforSSL", sslHash, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + + @Test public void testRSAforSSL_hash20() throws Exception { - KeyPair keyPair = generateKeyPair( this.keySize); + KeyPair keyPair = generateKeyPair( getKeySize()); byte[] sslHash = Arrays.copyOf(origMsg, 20); doSignVerify("RSAforSSL", sslHash, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + + @Test public void testRSAforSSL_hash36() throws Exception { - KeyPair keyPair = generateKeyPair( this.keySize); + KeyPair keyPair = generateKeyPair( getKeySize()); byte[] sslHash = Arrays.copyOf(origMsg, 36); doSignVerify("RSAforSSL", sslHash, keyPair.getPrivate(), keyPair.getPublic()); } - //-------------------------------------------------------------------------- - // - // + + @Test public void testRSAforSSL_hash40() throws Exception { - KeyPair keyPair = generateKeyPair(this.keySize); + KeyPair keyPair = generateKeyPair(getKeySize()); byte[] sslHash = Arrays.copyOf(origMsg, 40); doSignVerify("RSAforSSL", sslHash, keyPair.getPrivate(), keyPair.getPublic()); } */ - //-------------------------------------------------------------------------- - // - // - protected KeyPair generateKeyPair(int keysize) throws Exception { - KeyPairGenerator rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", providerName); + + private KeyPair generateKeyPair(int keysize) throws Exception { + KeyPairGenerator rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", getProviderName()); rsaKeyPairGen.initialize(keysize); return rsaKeyPairGen.generateKeyPair(); } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckDisabled.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckDisabled.java index efd59651..8b39f0b5 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckDisabled.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckDisabled.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,52 +12,36 @@ import java.security.interfaces.RSAPrivateCrtKey; import java.security.interfaces.RSAPublicKey; import javax.crypto.Cipher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestRSATypeCheckDisabled extends BaseTestJunit5 { -public class BaseTestRSATypeCheckDisabled extends BaseTest { - // -------------------------------------------------------------------------- - // - // static final int DEFAULT_KEY_SIZE = 2048; - // -------------------------------------------------------------------------- - // - // KeyPairGenerator rsaKeyPairGen; KeyPair rsaKeyPair; RSAPublicKey rsaPub; RSAPrivateCrtKey rsaPriv; - // -------------------------------------------------------------------------- - // - // - public BaseTestRSATypeCheckDisabled(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - protected void setUp() throws Exception { - rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", providerName); + @BeforeEach + public void setUp() throws Exception { + rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", getProviderName()); rsaKeyPairGen.initialize(DEFAULT_KEY_SIZE, null); rsaKeyPair = rsaKeyPairGen.generateKeyPair(); rsaPub = (RSAPublicKey) rsaKeyPair.getPublic(); rsaPriv = (RSAPrivateCrtKey) rsaKeyPair.getPrivate(); } - // -------------------------------------------------------------------------- - // - // + @Test public void testPrivateKeyEncrypt() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPriv); } - // -------------------------------------------------------------------------- - // - // + @Test public void testPublicKeyDecrypt() throws Exception { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.DECRYPT_MODE, rsaPub); } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckEnabled.java b/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckEnabled.java index 4c4f5e1d..39503359 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckEnabled.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestRSATypeCheckEnabled.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,45 +13,34 @@ import java.security.interfaces.RSAPrivateCrtKey; import java.security.interfaces.RSAPublicKey; import javax.crypto.Cipher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class BaseTestRSATypeCheckEnabled extends BaseTestJunit5 { -public class BaseTestRSATypeCheckEnabled extends BaseTest { - // -------------------------------------------------------------------------- - // - // static final int DEFAULT_KEY_SIZE = 2048; - // -------------------------------------------------------------------------- - // - // + KeyPairGenerator rsaKeyPairGen; KeyPair rsaKeyPair; RSAPublicKey rsaPub; RSAPrivateCrtKey rsaPriv; - // -------------------------------------------------------------------------- - // - // - public BaseTestRSATypeCheckEnabled(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - protected void setUp() throws Exception { - rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", providerName); + @BeforeEach + public void setUp() throws Exception { + rsaKeyPairGen = KeyPairGenerator.getInstance("RSA", getProviderName()); rsaKeyPairGen.initialize(DEFAULT_KEY_SIZE, null); rsaKeyPair = rsaKeyPairGen.generateKeyPair(); rsaPub = (RSAPublicKey) rsaKeyPair.getPublic(); rsaPriv = (RSAPrivateCrtKey) rsaKeyPair.getPrivate(); } - // -------------------------------------------------------------------------- - // - // + @Test public void testPrivateKeyEncrypt() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.ENCRYPT_MODE, rsaPriv); fail("Expected InvalidKeyException did not occur"); } catch (InvalidKeyException ike) { @@ -59,12 +48,10 @@ public void testPrivateKeyEncrypt() throws Exception { } } - // -------------------------------------------------------------------------- - // - // + @Test public void testPublicKeyDecrypt() throws Exception { try { - Cipher cp = Cipher.getInstance("RSA", providerName); + Cipher cp = Cipher.getInstance("RSA", getProviderName()); cp.init(Cipher.DECRYPT_MODE, rsaPub); fail("Expected InvalidKeyException did not occur"); } catch (InvalidKeyException ike) { diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA1.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA1.java index cea1ced8..f685638c 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA1.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,13 +9,11 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA1 extends BaseTestMessageDigestClone { - static boolean warmup = false; - - //-------------------------------------------------------------------------- - // - // static byte[] each = {(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0, (byte) 0x73, (byte) 0x0, (byte) 0x75, (byte) 0x0, (byte) 0x62, (byte) 0x0, (byte) 0x2d, (byte) 0x0, @@ -70,28 +68,15 @@ public class BaseTestSHA1 extends BaseTestMessageDigestClone { (byte) 0xC4, (byte) 0xDA, (byte) 0xA4, (byte) 0xF6, (byte) 0x1E, (byte) 0xEB, (byte) 0x2B, (byte) 0xDB, (byte) 0xAD, (byte) 0x27, (byte) 0x31, (byte) 0x65, (byte) 0x34, (byte) 0x01, (byte) 0x6F}; - - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA1(String providerName) { - super(providerName, "SHA-1"); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } + @BeforeAll + public void setUp() { + setAlgorithm("SHA1"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < each.length; i++) md.update(each[i]); @@ -105,12 +90,10 @@ public void testSHA1() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1_A() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(sha_A_input); byte[] result = md.digest(); @@ -118,12 +101,10 @@ public void testSHA1_A() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1_B() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(sha_B_input); byte[] result = md.digest(); @@ -131,12 +112,10 @@ public void testSHA1_B() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1_C() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int counter = 0; counter < 1000000; counter++) { md.update((byte) 0x61); } @@ -147,12 +126,10 @@ public void testSHA1_C() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(sha_A_input); md.reset(); md.update(sha_B_input); @@ -162,18 +139,17 @@ public void testSHA1_reset() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA1_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 20); assertTrue("Unexpected digest length", isExpectedValue); } + @Test public void testSHA1_ArrayOutofBoundsException() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] bytes = new byte[] {1, 1, 1, 1, 1}; try { md.update(bytes, -1, 1); @@ -183,21 +159,5 @@ public void testSHA1_ArrayOutofBoundsException() throws Exception { } } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - for (long i = 0; i < 10000; i++) { - md.update(sha_A_input); - md.digest(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA224.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA224.java index a0c72f6d..0c46c9a2 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA224.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,14 +10,11 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA224 extends BaseTestMessageDigestClone { - static boolean warmup = false; - - //-------------------------------------------------------------------------- - // - // - static final byte[] input_1 = {(byte) 0x61, (byte) 0x62, (byte) 0x63}; static final byte[] digest_1 = {(byte) 0x23, (byte) 0x09, (byte) 0x7d, (byte) 0x22, (byte) 0x34, (byte) 0x05, (byte) 0xd8, (byte) 0x22, (byte) 0x86, (byte) 0x42, (byte) 0xa4, @@ -33,43 +30,27 @@ public class BaseTestSHA224 extends BaseTestMessageDigestClone { (byte) 0xc6, (byte) 0x45, (byte) 0x5c, (byte) 0xb4, (byte) 0xf5, (byte) 0x8b, (byte) 0x19, (byte) 0x52, (byte) 0x52, (byte) 0x25, (byte) 0x25,}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA224(String providerName) { - super(providerName, "SHA-224"); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } + @BeforeAll + public void setUp() { + setAlgorithm("SHA-224"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA224_1() throws Exception { boolean result = checkDigest(input_1, digest_1); assertTrue("Digest did not match expected, testSHA224_1:", result); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA224_2() throws Exception { boolean result = checkDigest(input_2, digest_2); assertTrue("Digest did not match expected, testSHA224_2", result); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA224_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(input_1); md.reset(); md.update(input_2); @@ -78,23 +59,19 @@ public void testSHA224_reset() throws Exception { assertTrue("Digest did not match expected", Arrays.equals(result, digest_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA224_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 28); assertTrue("Unexpected digest length", isExpectedValue); } - //-------------------------------------------------------------------------- - // - // + private boolean checkDigest(byte[] input, byte[] out) { boolean result = false; try { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input); result = Arrays.equals(digest, out); @@ -104,21 +81,5 @@ private boolean checkDigest(byte[] input, byte[] out) { return result; } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - for (long i = 0; i < 10000; i++) { - md.update(input_1); - md.digest(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256.java index d36f2090..b64df6ea 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,13 +10,11 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA256 extends BaseTestMessageDigestClone { - static boolean warmup = false; - - //-------------------------------------------------------------------------- - // - // final byte[] input_1 = {(byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61}; @@ -57,26 +55,14 @@ public class BaseTestSHA256 extends BaseTestMessageDigestClone { }; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA256(String providerName) { - super(providerName, "SHA-256"); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } + @BeforeAll + public void setUp() { + setAlgorithm("SHA-256"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA256() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < 100000; i++) md.update(input_1); @@ -85,21 +71,17 @@ public void testSHA256() throws Exception { assertTrue("Digest did not match expected", Arrays.equals(digest, result_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA256_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input_2); assertTrue("Digest did not match expected", Arrays.equals(digest, result_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA256_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(input_1); md.reset(); md.update(input_2); @@ -108,39 +90,19 @@ public void testSHA256_reset() throws Exception { assertTrue("Digest did not match expected", Arrays.equals(result, result_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA256_MultiBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input_3); assertTrue("Digest did not match expected", Arrays.equals(digest, result_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA256_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 32); assertTrue("Unexpected digest length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - for (long i = 0; i < 10000; i++) { - md.update(input_1); - md.digest(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256Clone_SharedMD.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256Clone_SharedMD.java index 4932fbb9..c8abb41e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256Clone_SharedMD.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA256Clone_SharedMD.java @@ -11,15 +11,13 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -public class BaseTestSHA256Clone_SharedMD extends BaseTest { +public class BaseTestSHA256Clone_SharedMD extends BaseTestJunit5 { static MessageDigest md = null; - //-------------------------------------------------------------------------- - // - // - final byte[] input = {(byte) 0x61, (byte) 0x62, (byte) 0x63}; final byte[] result = {(byte) 0xba, (byte) 0x78, (byte) 0x16, (byte) 0xbf, (byte) 0x8f, @@ -29,19 +27,15 @@ public class BaseTestSHA256Clone_SharedMD extends BaseTest { (byte) 0x9c, (byte) 0xb4, (byte) 0x10, (byte) 0xff, (byte) 0x61, (byte) 0xf2, (byte) 0x00, (byte) 0x15, (byte) 0xad}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA256Clone_SharedMD(String providerName) throws NoSuchAlgorithmException, NoSuchProviderException { - super(providerName); + @BeforeEach + public void setUp() throws NoSuchAlgorithmException, NoSuchProviderException { + setAlgorithm("SHA256"); if (md == null) { - md = MessageDigest.getInstance("SHA-256", providerName); + md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); } } - //-------------------------------------------------------------------------- - // - // + @Test public void testCloneSharedMD() throws Exception { MessageDigest mdCopy = (MessageDigest) md.clone(); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA384.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA384.java index d9c86d7a..96969a6f 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA384.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,13 +10,11 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA384 extends BaseTestMessageDigestClone { - static boolean warmup = false; - - //-------------------------------------------------------------------------- - // - // final byte[] input_1 = {(byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61}; @@ -73,27 +71,15 @@ public class BaseTestSHA384 extends BaseTestMessageDigestClone { (byte) 0xc3, (byte) 0xe9, (byte) 0xfa, (byte) 0x91, (byte) 0x74, (byte) 0x60, (byte) 0x39}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA384(String providerName) { - super(providerName, "SHA-384"); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } + @BeforeAll + public void setUp() { + setAlgorithm("SHA-384"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA384() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < 100000; i++) md.update(input_1); @@ -103,24 +89,20 @@ public void testSHA384() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA384_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input_2); assertTrue("Digest did not match expected", Arrays.equals(digest, result_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA384_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(input_1); md.reset(); md.update(input_2); @@ -130,12 +112,10 @@ public void testSHA384_reset() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA384_MultiBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input_3); @@ -143,29 +123,11 @@ public void testSHA384_MultiBlock() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA384_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 48); assertTrue("Unexpected digest length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - for (long i = 0; i < 10000; i++) { - md.update(input_1); - md.digest(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_224KAT.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_224KAT.java index 240d6cc7..928fd332 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_224KAT.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_224KAT.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,14 +9,12 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA3_224KAT extends BaseTestMessageDigestClone { - //-------------------------------------------------------------------------- - // - // - - final String[][] tests = {{ "31c82d71785b7ca6b651cb6c8c9ad5e2aceb0b0633c088d33aa247ada7a594ff4936c023251319820a9b19fc6c48de8a6f7ada214176ccdaadaeef51ed43714ac0c8269bbd497e46e78bb5e58196494b2471b1680e2d4c6dbd249831bd83a4d3be06c8a2e903933974aa05ee748bfe6ef359f7a143edf0d4918da916bd6f15e26a790cff514b40a5da7f72e1ed2fe63a05b8149587bea05653718cc8980eadbfeca85b7c9c286dd040936585938be7f98219700c83a9443c2856a80ff46852b26d1b1edf72a30203cf6c44a10fa6eaf1920173cedfb5c4cf3ac665b37a86ed02155bbbf17dc2e786af9478fe0889d86c5bfa85a242eb0854b1482b7bd16f67f80bef9c7a628f05a107936a64273a97b0088b0e515451f916b5656230a12ba6dc78", "aab23c9e7fb9d7dacefdfd0b1ae85ab1374abff7c4e3f7556ecae412"}, @@ -496,18 +494,14 @@ public class BaseTestSHA3_224KAT extends BaseTestMessageDigestClone { {"e65de91fdcb7606f14dbcfc94c9c94a57240a6b2c31ed410346c4dc011526559e44296fc988cc589de2dc713d0e82492d4991bd8c4c5e6c74c753fc09345225e1db8d565f0ce26f5f5d9f404a28cf00bd655a5fe04edb682942d675b86235f235965ad422ba5081a21865b8209ae81763e1c4c0cccbccdaad539cf773413a50f5ff1267b9238f5602adc06764f775d3c", "26ec9df54d9afe11710772bfbeccc83d9d0439d3530777c81b8ae6a3"}}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA3_224KAT(String providerName) { - super(providerName, "SHA3-224"); + @BeforeAll + public void setUp() { + setAlgorithm("SHA3-224"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224KAT() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int x = 0; x < tests.length; x++) { md.update(BaseUtils.hexStringToByteArray(tests[x][0])); byte[] digest = md.digest(); @@ -517,22 +511,18 @@ public void testSHA3_224KAT() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[0][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[0][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(BaseUtils.hexStringToByteArray(tests[0][0])); md.reset(); md.update(BaseUtils.hexStringToByteArray(tests[1][0])); @@ -542,22 +532,18 @@ public void testSHA3_224_reset() throws Exception { Arrays.equals(result, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224_MultiBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[1][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_224_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 28); assertTrue("Unexpected digest length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_256KAT.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_256KAT.java index 1617b24a..06302c08 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_256KAT.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_256KAT.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,14 +9,12 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA3_256KAT extends BaseTestMessageDigestClone { - //-------------------------------------------------------------------------- - // - // - - final String[][] tests = {{ "b1caa396771a09a1db9bc20543e988e359d47c2a616417bbca1b62cb02796a888fc6eeff5c0b5c3d5062fcb4256f6ae1782f492c1cf03610b4a1fb7b814c057878e1190b9835425c7a4a0e182ad1f91535ed2a35033a5d8c670e21c575ff43c194a58a82d4a1a44881dd61f9f8161fc6b998860cbe4975780be93b6f87980bad0a99aa2cb7556b478ca35d1f3746c33e2bb7c47af426641cc7bbb3425e2144820345e1d0ea5b7da2c3236a52906acdc3b4d34e474dd714c0c40bf006a3a1d889a632983814bbc4a14fe5f159aa89249e7c738b3b73666bac2a615a83fd21ae0a1ce7352ade7b278b587158fd2fabb217aa1fe31d0bda53272045598015a8ae4d8cec226fefa58daa05500906c4d85e7567", "cb5648a1d61c6c5bdacd96f81c9591debc3950dcf658145b8d996570ba881a05"}, @@ -484,18 +482,14 @@ public class BaseTestSHA3_256KAT extends BaseTestMessageDigestClone { {"56ea14d7fcb0db748ff649aaa5d0afdc2357528a9aad6076d73b2805b53d89e73681abfad26bee6c0f3d20215295f354f538ae80990d2281be6de0f6919aa9eb048c26b524f4d91ca87b54c0c54aa9b54ad02171e8bf31e8d158a9f586e92ffce994ecce9a5185cc80364d50a6f7b94849a914242fcb73f33a86ecc83c3403630d20650ddb8cd9c4", "4beae3515ba35ec8cbd1d94567e22b0d7809c466abfbafe9610349597ba15b45"}}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA3_256KAT(String providerName) { - super(providerName, "SHA3-256"); + @BeforeAll + public void setUp() { + setAlgorithm("SHA3-256"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256KAT() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int x = 0; x < tests.length; x++) { md.update(BaseUtils.hexStringToByteArray(tests[x][0])); @@ -506,22 +500,18 @@ public void testSHA3_256KAT() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[0][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[0][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(BaseUtils.hexStringToByteArray(tests[0][0])); md.reset(); md.update(BaseUtils.hexStringToByteArray(tests[1][0])); @@ -531,22 +521,18 @@ public void testSHA3_256_reset() throws Exception { Arrays.equals(result, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256_MultiBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[1][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_256_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 32); assertTrue("Unexpected digest length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_384KAT.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_384KAT.java index 7895b3a1..88c0f299 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_384KAT.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_384KAT.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,14 +9,12 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA3_384KAT extends BaseTestMessageDigestClone { - //-------------------------------------------------------------------------- - // - // - - final String[][] tests = {{ "5fe35923b4e0af7dd24971812a58425519850a506dfa9b0d254795be785786c319a2567cbaa5e35bcf8fe83d943e23fa5169b73adc1fcf8b607084b15e6a013df147e46256e4e803ab75c110f77848136be7d806e8b2f868c16c3a90c14463407038cb7d9285079ef162c6a45cedf9c9f066375c969b5fcbcda37f02aacff4f31cded3767570885426bebd9eca877e44674e9ae2f0c24cdd0e7e1aaf1ff2fe7f80a1c4f5078eb34cd4f06fa94a2d1eab5806ca43fd0f06c60b63d5402b95c70c21ea65a151c5cfaf8262a46be3c722264b", "3054d249f916a6039b2a9c3ebec1418791a0608a170e6d36486035e5f92635eaba98072a85373cb54e2ae3f982ce132b"}, @@ -425,18 +423,14 @@ public class BaseTestSHA3_384KAT extends BaseTestMessageDigestClone { {"92c41d34bd249c182ad4e18e3b856770766f1757209675020d4c1cf7b6f7686c8c1472678c7c412514e63eb9f5aee9f5c9d5cb8d8748ab7a5465059d9cbbb8a56211ff32d4aaa23a23c86ead916fe254cc6b2bff7a9553df1551b531f95bb41cbbc4acddbd372921", "71307eec1355f73e5b726ed9efa1129086af81364e30a291f684dfade693cc4bc3d6ffcb7f3b4012a21976ff9edcab61"}}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA3_384KAT(String providerName) { - super(providerName, "SHA3-384"); + @BeforeAll + public void setUp() { + setAlgorithm("SHA3-384"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384KAT() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int x = 0; x < tests.length; x++) { md.update(BaseUtils.hexStringToByteArray(tests[x][0])); @@ -447,22 +441,18 @@ public void testSHA3_384KAT() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[0][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[0][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(BaseUtils.hexStringToByteArray(tests[0][0])); md.reset(); md.update(BaseUtils.hexStringToByteArray(tests[1][0])); @@ -472,22 +462,18 @@ public void testSHA3_384_reset() throws Exception { Arrays.equals(result, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_3844_MultiBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[1][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_384_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 48); assertTrue("Unexpected digest length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_512KAT.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_512KAT.java index 9824a88f..85c66c1c 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_512KAT.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA3_512KAT.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,14 +9,12 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA3_512KAT extends BaseTestMessageDigestClone { - //-------------------------------------------------------------------------- - // - // - - final String[][] tests = {{ "664ef2e3a7059daf1c58caf52008c5227e85cdcb83b4c59457f02c508d4f4f69f826bd82c0cffc5cb6a97af6e561c6f96970005285e58f21ef6511d26e709889a7e513c434c90a3cf7448f0caeec7114c747b2a0758a3b4503a7cf0c69873ed31d94dbef2b7b2f168830ef7da3322c3d3e10cafb7c2c33c83bbf4c46a31da90cff3bfd4ccc6ed4b310758491eeba603a76", "e5825ff1a3c070d5a52fbbe711854a440554295ffb7a7969a17908d10163bfbe8f1d52a676e8a0137b56a11cdf0ffbb456bc899fc727d14bd8882232549d914e"}, @@ -361,18 +359,14 @@ public class BaseTestSHA3_512KAT extends BaseTestMessageDigestClone { {"0ce9f8c3a990c268f34efd9befdb0f7c4ef8466cfdb01171f8de70dc5fefa92acbe93d29e2ac1a5c2979129f1ab08c0e77de7924ddf68a209cdfa0adc62f85c18637d9c6b33f4ff8", "b018a20fcf831dde290e4fb18c56342efe138472cbe142da6b77eea4fce52588c04c808eb32912faa345245a850346faec46c3a16d39bd2e1ddb1816bc57d2da"}}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA3_512KAT(String providerName) { - super(providerName, "SHA3-512"); + @BeforeAll + public void setUp() { + setAlgorithm("SHA3-512"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512KAT() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int x = 0; x < tests.length; x++) { md.update(BaseUtils.hexStringToByteArray(tests[x][0])); @@ -383,22 +377,18 @@ public void testSHA3_512KAT() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[0][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[0][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512_reset() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(BaseUtils.hexStringToByteArray(tests[0][0])); md.reset(); md.update(BaseUtils.hexStringToByteArray(tests[1][0])); @@ -408,22 +398,18 @@ public void testSHA3_512_reset() throws Exception { Arrays.equals(result, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512_MultiBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(BaseUtils.hexStringToByteArray(tests[1][0])); assertTrue("Digest did not match expected", Arrays.equals(digest, BaseUtils.hexStringToByteArray(tests[1][1]))); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA3_512_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 64); assertTrue("Unexpected digest length", isExpectedValue); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512.java index 64a8988d..3bfbae92 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,13 +10,11 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA512 extends BaseTestMessageDigestClone { - static boolean warmup = false; - - //-------------------------------------------------------------------------- - // - // final byte[] input_1 = {(byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61}; @@ -79,28 +77,14 @@ public class BaseTestSHA512 extends BaseTestMessageDigestClone { (byte) 0xdd, (byte) 0x26, (byte) 0x54, (byte) 0x5e, (byte) 0x96, (byte) 0xe5, (byte) 0x5b, (byte) 0x87, (byte) 0x4b, (byte) 0xe9, (byte) 0x09}; - //-------------------------------------------------------------------------- - // - // - public BaseTestSHA512(String providerName) { - super(providerName, "SHA-512"); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } + @BeforeAll + public void setUp() { + setAlgorithm("SHA-512"); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA512() throws Exception { - - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < 100000; i++) md.update(input_1); byte[] digest = md.digest(); @@ -109,12 +93,9 @@ public void testSHA512() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA_reset() throws Exception { - - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); md.update(input_1); md.reset(); md.update(input_2); @@ -124,54 +105,29 @@ public void testSHA_reset() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA512_SingleBlock() throws Exception { - - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input_2); assertTrue("Digest did not match expected", Arrays.equals(digest, result_2)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA512_MultiBlock() throws Exception { - - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); byte[] digest = md.digest(input_3); assertTrue("Digest did not match expected", Arrays.equals(digest, result_3)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA512_digestLength() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); int digestLength = md.getDigestLength(); boolean isExpectedValue = (digestLength == 64); assertTrue("Unexpected digest length", isExpectedValue); } - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); - for (long i = 0; i < 10000; i++) { - md.update(input_1); - md.digest(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_224.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_224.java index 45af1844..c625ceaa 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_224.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,28 +10,34 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA512_224 extends BaseTestMessageDigestClone { // Test vectors obtained from // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_224.pdf - public BaseTestSHA512_224(String providerName) { - super(providerName, "SHA-512/224"); + @BeforeAll + public void setUp() { + setAlgorithm("SHA512/224"); } + @Test public void testSHA512_224_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); assertTrue(Arrays.equals(md.digest("abc".getBytes("UTF-8")), hexStrToBytes("4634270F707B6A54DAAE7530460842E20E37ED265CEEE9A43E8924AA"))); } + @Test public void testSHA512_224_TwoBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); assertTrue(Arrays.equals( md.digest(("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu") @@ -40,6 +46,7 @@ public void testSHA512_224_TwoBlock() throws Exception { } + @Test public void testSHA512_224_varmsgs() throws Exception { String[] calculatedDigests = {"6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4", //0 @@ -56,7 +63,7 @@ public void testSHA512_224_varmsgs() throws Exception { String msg = ""; int j = 0; - MessageDigest mdIBM = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest mdIBM = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < 10000; i++) { @@ -73,13 +80,12 @@ public void testSHA512_224_varmsgs() throws Exception { } - - + @Test public void testSHA512_224_withUpdates() throws Exception { String calcDigest = "367f4e38fba70b22c8d975e1079b5f9f8b3ac971e2ef049c704b1132"; - MessageDigest mdIBM = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest mdIBM = MessageDigest.getInstance(getAlgorithm(), getProviderName()); String msgarrays[] = {"Hello0", "Hello1", "Hello2", "Hello3", "Hello4", "longmessage5", "longermessage6,", "verylongmessage7"}; for (int i = 0; i < msgarrays.length; i++) { diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_256.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_256.java index 095080bc..c388fb8e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_256.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSHA512_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,27 +10,33 @@ import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestSHA512_256 extends BaseTestMessageDigestClone { // Test vectors obtained from // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_256.pdf - public BaseTestSHA512_256(String providerName) { - super(providerName, "SHA-512/256"); + @BeforeAll + public void setUp() { + setAlgorithm("SHA512/256"); } + @Test public void testSHA512_256_SingleBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); assertTrue(Arrays.equals(md.digest("abc".getBytes("UTF-8")), hexStrToBytes("53048E2681941EF99B2E29B76B4C7DABE4C2D0C634FC6D46E0E2F13107E7AF23"))); } + @Test public void testSHA512_256_TwoBlock() throws Exception { - MessageDigest md = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); assertTrue(Arrays.equals( md.digest(("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" @@ -39,6 +45,7 @@ public void testSHA512_256_TwoBlock() throws Exception { hexStrToBytes("3928E184FB8690F840DA3988121D31BE65CB9D3EF83EE6146FEAC861E19B563A"))); } + @Test public void testSHA512_256_varmsgs() throws Exception { String calculatedDigests[] = { "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a", //i=0 @@ -50,7 +57,7 @@ public void testSHA512_256_varmsgs() throws Exception { String msg = ""; int j = 0; - MessageDigest mdIBM = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest mdIBM = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < 10000; i++) { @@ -67,11 +74,12 @@ public void testSHA512_256_varmsgs() throws Exception { } + @Test public void testSHA512_256_withUpdates() throws Exception { String calcDigest = "c171b3719fc985090fd9db086061e2b63539f326bc4d989bbe9ac37b7d038022"; - MessageDigest mdIBM = MessageDigest.getInstance(this.algorithm, providerName); + MessageDigest mdIBM = MessageDigest.getInstance(getAlgorithm(), getProviderName()); String msgarrays[] = {"Hello0", "Hello1", "Hello2", "Hello3", "Hello4", "longmessage5", "longermessage6,", "verylongmessage7"}; for (int i = 0; i < msgarrays.length; i++) { diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestSignatureInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestSignatureInterop.java index d6899e9e..ba143b73 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestSignatureInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestSignatureInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,38 +11,17 @@ import java.security.PrivateKey; import java.security.PublicKey; import java.security.Signature; +import static org.junit.Assert.assertTrue; -public class BaseTestSignatureInterop extends BaseTestInterop { +public class BaseTestSignatureInterop extends BaseTestJunit5Interop { - //-------------------------------------------------------------------------- - // - // - public BaseTestSignatureInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception {} - - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // protected void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey, PublicKey publicKey) throws Exception { - doSignVerify(sigAlgo, message, privateKey, publicKey, providerName, interopProviderName); - doSignVerify(sigAlgo, message, privateKey, publicKey, interopProviderName, providerName); + doSignVerify(sigAlgo, message, privateKey, publicKey, getProviderName(), getInteropProviderName()); + doSignVerify(sigAlgo, message, privateKey, publicKey, getInteropProviderName(), getProviderName()); } - //-------------------------------------------------------------------------- - // - // + protected static void doSignVerify(String sigAlgo, byte[] message, PrivateKey privateKey, PublicKey publicKey, String signProvider, String verifyProvider) throws Exception { Signature signing = Signature.getInstance(sigAlgo, signProvider); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestTruncatedDigest.java b/src/test/java/ibm/jceplus/junit/base/BaseTestTruncatedDigest.java index 9cc61716..0bbe2307 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestTruncatedDigest.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestTruncatedDigest.java @@ -16,7 +16,7 @@ import org.junit.jupiter.api.Test; import static org.junit.Assert.assertTrue; -public class BaseTestTruncatedDigest extends BaseTestSignature { +public class BaseTestTruncatedDigest extends BaseTestJunit5Signature { String IBM_ALG = "RSAPSS"; diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestXDH.java b/src/test/java/ibm/jceplus/junit/base/BaseTestXDH.java index b222e626..560b5297 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestXDH.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestXDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -30,29 +30,26 @@ import java.security.spec.XECPublicKeySpec; import java.util.Arrays; import javax.crypto.KeyAgreement; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestXDH extends ibm.jceplus.junit.base.BaseTest { - - public BaseTestXDH(String providerName) { - super(providerName); - } - - public void setUp() throws Exception {} - - public void tearDown() throws Exception {} +public class BaseTestXDH extends BaseTestJunit5 { + @Test public void testXDH_X25519() throws Exception { String curveName = "X25519"; NamedParameterSpec nps = new NamedParameterSpec(curveName); compute_xdh_key(curveName, nps); } + @Test public void testXDH_X448() throws Exception { String curveName = "X448"; NamedParameterSpec nps = new NamedParameterSpec(curveName); compute_xdh_key(curveName, nps); } + @Test public void testXDH_runBasicTests() throws Exception { System.out.println( @@ -60,6 +57,7 @@ public void testXDH_runBasicTests() throws Exception { runBasicTests(); } + @Test public void testXDH_runKAT() throws Exception { System.out.println( @@ -67,6 +65,7 @@ public void testXDH_runKAT() throws Exception { runKAT(); } + @Test public void testXDH_runSmallOrderTest() throws Exception { System.out.println( @@ -74,6 +73,7 @@ public void testXDH_runSmallOrderTest() throws Exception { runSmallOrderTest(); } + @Test public void testXDH_runNonCanonicalTest() throws Exception { System.out.println( @@ -81,6 +81,7 @@ public void testXDH_runNonCanonicalTest() throws Exception { runNonCanonicalTest(); } + @Test public void testXDH_runCurveMixTest() throws Exception { System.out.println( @@ -95,7 +96,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) KeyPairGenerator kpgA = null; try { - kpgA = KeyPairGenerator.getInstance("XDH", providerName); + kpgA = KeyPairGenerator.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -116,7 +117,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) // set up KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("XDH", providerName); + keyAgreeA = KeyAgreement.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -134,7 +135,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) KeyPairGenerator kpgB = null; try { - kpgB = KeyPairGenerator.getInstance("XDH", providerName); + kpgB = KeyPairGenerator.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -158,7 +159,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("XDH", providerName); + keyAgreeB = KeyAgreement.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -216,7 +217,7 @@ private void runBasicTests() throws Exception { private void runBasicTest(String name, Object param) throws Exception { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(name, providerName); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(name, getProviderName()); AlgorithmParameterSpec paramSpec = null; System.out.println("Name: " + name); @@ -229,13 +230,13 @@ private void runBasicTest(String name, Object param) throws Exception { } KeyPair kp = kpg.generateKeyPair(); - KeyAgreement ka = KeyAgreement.getInstance(name, providerName); + KeyAgreement ka = KeyAgreement.getInstance(name, getProviderName()); ka.init(kp.getPrivate(), paramSpec); ka.doPhase(kp.getPublic(), true); byte[] secret = ka.generateSecret(); - KeyFactory kf = KeyFactory.getInstance(name, providerName); + KeyFactory kf = KeyFactory.getInstance(name, getProviderName()); // Test with X509 and PKCS8 key specs X509EncodedKeySpec pubSpec = kf.getKeySpec(kp.getPublic(), X509EncodedKeySpec.class); //System.out.println("After getKeySpec"); @@ -478,7 +479,7 @@ private void runKAT() throws Exception { private void runDiffieHellmanTest(String a_pri, String b_pub, String result) throws Exception { - KeyFactory kf = KeyFactory.getInstance("XDH", providerName); + KeyFactory kf = KeyFactory.getInstance("XDH", getProviderName()); byte[] a_pri_ba = BaseUtils.hexStringToByteArray(a_pri); KeySpec privateSpec = new PKCS8EncodedKeySpec(a_pri_ba); PrivateKey privateKey = kf.generatePrivate(privateSpec); @@ -486,7 +487,7 @@ private void runDiffieHellmanTest(String a_pri, String b_pub, String result) thr KeySpec publicSpec = new X509EncodedKeySpec(b_pub_ba); PublicKey publicKey = kf.generatePublic(publicSpec); - KeyAgreement ka = KeyAgreement.getInstance("XDH", providerName); + KeyAgreement ka = KeyAgreement.getInstance("XDH", getProviderName()); ka.init(privateKey); ka.doPhase(publicKey, true); @@ -506,7 +507,7 @@ private void runDiffieHellmanTest(String curveName, String a_pri, String b_pub, System.out.println("Test curve = " + curveName); NamedParameterSpec paramSpec = new NamedParameterSpec(curveName); - KeyFactory kf = KeyFactory.getInstance("XDH", providerName); + KeyFactory kf = KeyFactory.getInstance("XDH", getProviderName()); KeySpec privateSpec = new XECPrivateKeySpec(paramSpec, BaseUtils.hexStringToByteArray(a_pri)); PrivateKey privateKey = kf.generatePrivate(privateSpec); boolean clearHighBit = curveName.equals("X25519"); @@ -525,7 +526,7 @@ private void runDiffieHellmanTest(String curveName, String a_pri, String b_pub, byte[] encodedPublicKey = publicKey.getEncoded(); System.out.println("Encoded public: " + byteArrayToHexString(encodedPublicKey)); - KeyAgreement ka = KeyAgreement.getInstance("XDH", providerName); + KeyAgreement ka = KeyAgreement.getInstance("XDH", getProviderName()); //System.out.println("1"); ka.init(privateKey); //System.out.println("2"); @@ -557,7 +558,7 @@ private void runCurveMixTest() throws Exception { private void runCurveMixTest(String name, Object param) throws Exception { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(name, providerName); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(name, getProviderName()); try { if (param instanceof Integer) { @@ -582,11 +583,11 @@ private void runCurveMixTest(String name, Object param) throws Exception { //System.out.println("Other name = "+otherName); //System.out.println("Name = "+name); - KeyPairGenerator otherKpg = KeyPairGenerator.getInstance(otherName, providerName); + KeyPairGenerator otherKpg = KeyPairGenerator.getInstance(otherName, getProviderName()); KeyPair otherKp = otherKpg.generateKeyPair(); // ensure the KeyFactory rejects incorrect keys - KeyFactory kf = KeyFactory.getInstance(name, providerName); + KeyFactory kf = KeyFactory.getInstance(name, getProviderName()); try { kf.getKeySpec(otherKp.getPublic(), XECPublicKeySpec.class); throw new RuntimeException(name + " KeyFactory accepted " + param.toString() + " key"); @@ -613,7 +614,7 @@ private void runCurveMixTest(String name, Object param) throws Exception { // expected } - KeyFactory otherKf = KeyFactory.getInstance(otherName, providerName); + KeyFactory otherKf = KeyFactory.getInstance(otherName, getProviderName()); XECPublicKeySpec otherPubSpec = otherKf.getKeySpec(otherKp.getPublic(), XECPublicKeySpec.class); try { @@ -632,7 +633,7 @@ private void runCurveMixTest(String name, Object param) throws Exception { } // ensure the KeyAgreement rejects incorrect keys - KeyAgreement ka = KeyAgreement.getInstance(name, providerName); + KeyAgreement ka = KeyAgreement.getInstance(name, getProviderName()); try { ka.init(otherKp.getPrivate()); throw new RuntimeException( diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHInterop.java b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHInterop.java index f7928a88..90229ac4 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHInterop.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,8 +17,9 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Base64; +import org.junit.jupiter.api.Test; -public class BaseTestXDHInterop extends BaseTestInterop { +public class BaseTestXDHInterop extends BaseTestJunit5Interop { static final byte[] origMsg = "this is the original message to be signed".getBytes(); // The below strings are base64 encoded X25519/X448 public/private keys generated using OpenJDK @@ -28,46 +29,42 @@ public class BaseTestXDHInterop extends BaseTestInterop { String openJDK_private_X448 = "MEYCAQAwBwYDK2VvBQAEOOJFsgLYxgAIEWuN1FLAGWDzGQRSataAbPLDc1wv5aky4T8hevyWbYdhggc1OCcqQ93gY8rqVTDb"; // OpenJDK does not currently support FFDHE hence interop testing for FFDHE is not possible - public BaseTestXDHInterop(String providerName, String interopProviderName) { - super(providerName, interopProviderName); - } - - public void setUp() throws Exception {} - - public void tearDown() throws Exception {} - + @Test public void testXDHInterop_X25519_OpenJDK() throws Exception { byte[] openJDK_public_bytes = Base64.getDecoder().decode(openJDK_public_X25519); byte[] openJDK_private_bytes = Base64.getDecoder().decode(openJDK_private_X25519); - buildOpenJCEPlusKeys("X25519", openJDK_public_bytes, openJDK_private_bytes, providerName); + buildOpenJCEPlusKeys("X25519", openJDK_public_bytes, openJDK_private_bytes, getProviderName()); } + @Test public void testXDHMulti_x448_OpenJDK() throws Exception { byte[] openJDK_public_bytes = Base64.getDecoder().decode(openJDK_public_X448); byte[] openJDK_private_bytes = Base64.getDecoder().decode(openJDK_private_X448); - buildOpenJCEPlusKeys("X448", openJDK_public_bytes, openJDK_private_bytes, providerName); + buildOpenJCEPlusKeys("X448", openJDK_public_bytes, openJDK_private_bytes, getProviderName()); } + @Test public void testXDH_X448_KeyGeneration() throws Exception { - System.out.println("Testing XDH key generated with provider " + interopProviderName + " using provider " + providerName); + System.out.println("Testing XDH key generated with provider " + getInteropProviderName() + " using provider " + getProviderName()); - KeyPairGenerator kpg = KeyPairGenerator.getInstance("XDH", interopProviderName); + KeyPairGenerator kpg = KeyPairGenerator.getInstance("XDH", getInteropProviderName()); AlgorithmParameterSpec paramSpec = new NamedParameterSpec("X448"); kpg.initialize(paramSpec); KeyPair kp = kpg.generateKeyPair(); - buildOpenJCEPlusKeys("X448", kp.getPublic().getEncoded(), kp.getPrivate().getEncoded(), providerName); + buildOpenJCEPlusKeys("X448", kp.getPublic().getEncoded(), kp.getPrivate().getEncoded(), getProviderName()); } + @Test public void testXDH_X25519_KeyGeneration() throws Exception { - System.out.println("Testing XDH key generated with provider " + interopProviderName + " using provider " + providerName); + System.out.println("Testing XDH key generated with provider " + getInteropProviderName() + " using provider " + getProviderName()); - KeyPairGenerator kpg = KeyPairGenerator.getInstance("XDH", interopProviderName); + KeyPairGenerator kpg = KeyPairGenerator.getInstance("XDH", getInteropProviderName()); AlgorithmParameterSpec paramSpec = new NamedParameterSpec("X25519"); kpg.initialize(paramSpec); KeyPair kp = kpg.generateKeyPair(); - buildOpenJCEPlusKeys("X25519", kp.getPublic().getEncoded(), kp.getPrivate().getEncoded(), providerName); + buildOpenJCEPlusKeys("X25519", kp.getPublic().getEncoded(), kp.getPrivate().getEncoded(), getProviderName()); } void buildOpenJCEPlusKeys(String idString, byte[] publicKeyBytes, byte[] privateKeyBytes, diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyImport.java b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyImport.java index ac912265..913a2a6e 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyImport.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyImport.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,23 +23,19 @@ import java.security.spec.XECPublicKeySpec; import java.util.Arrays; import java.util.Base64; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestXDHKeyImport extends ibm.jceplus.junit.base.BaseTest { - - public BaseTestXDHKeyImport(String providerName) { - super(providerName); - } - - public void setUp() throws Exception {} - - public void tearDown() throws Exception {} +public class BaseTestXDHKeyImport extends BaseTestJunit5 { + @Test public void testCreateKeyPairNamedParamImport_X25519() throws Exception { createKeyPairNamedParamImport("X25519"); createKeyPairXDHParamImport("X25519"); createKeyPairLocalParamImport("X25519"); } + @Test public void testCreateKeyPairNamedParamImport_X448() throws Exception { createKeyPairNamedParamImport("X448"); createKeyPairXDHParamImport("X448"); @@ -73,7 +69,7 @@ public void createKeyPairNamedParamImport(String alg) throws Exception { //final String methodName = "testCreateKeyPairNamedParamImport"; NamedParameterSpec nps = new NamedParameterSpec(alg); - KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("XDH", providerName); + KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("XDH", getProviderName()); keyPairGen.initialize(nps); KeyPair keyPair = keyPairGen.generateKeyPair(); @@ -92,7 +88,7 @@ public void createKeyPairNamedParamImport(String alg) throws Exception { // System.out.println (methodName + " privKeyBytes = " + // BaseUtils.bytesToHex(privKeyBytes)); - KeyFactory keyFactory = KeyFactory.getInstance("XDH", providerName); + KeyFactory keyFactory = KeyFactory.getInstance("XDH", getProviderName()); EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privKeyBytes); PrivateKey privateKey2 = keyFactory.generatePrivate(privateKeySpec); @@ -185,7 +181,7 @@ public void createKeyPairXDHParamImport(String alg) throws Exception { } NamedParameterSpec paramSpec = new NamedParameterSpec(alg); - KeyFactory kf = KeyFactory.getInstance("XDH", providerName); + KeyFactory kf = KeyFactory.getInstance("XDH", getProviderName()); XECPublicKeySpec xdhPublic = new XECPublicKeySpec(paramSpec, u); XECPrivateKeySpec xdhPrivate = new XECPrivateKeySpec(paramSpec, scalar); @@ -206,7 +202,7 @@ public void createKeyPairXDHParamImport(String alg) throws Exception { * @throws Exception */ void createKeyPairLocalParamImport(String alg) throws Exception { - KeyPairGenerator kpg = KeyPairGenerator.getInstance(alg, providerName); + KeyPairGenerator kpg = KeyPairGenerator.getInstance(alg, getProviderName()); // KeyPairGenerator kpg = KeyPairGenerator.getInstance("XDH"); NamedParameterSpec paramSpec = new NamedParameterSpec(alg); System.out.println("Alg = " + alg); @@ -216,7 +212,7 @@ void createKeyPairLocalParamImport(String alg) throws Exception { PrivateKey pvk = kp.getPrivate(); PublicKey pbk = kp.getPublic(); - KeyFactory kf = KeyFactory.getInstance(alg, providerName); + KeyFactory kf = KeyFactory.getInstance(alg, getProviderName()); // KeyFactory kf = KeyFactory.getInstance("XDH"); XECPublicKeySpec xdhPublic = kf.getKeySpec(kp.getPublic(), XECPublicKeySpec.class); XECPrivateKeySpec xdhPrivate = kf.getKeySpec(kp.getPrivate(), XECPrivateKeySpec.class); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyPairGenerator.java index 9da99fe4..fa31d50a 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,51 +13,51 @@ import java.security.interfaces.XECPrivateKey; import java.security.interfaces.XECPublicKey; import java.security.spec.NamedParameterSpec; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class BaseTestXDHKeyPairGenerator extends ibm.jceplus.junit.base.BaseTest { +public class BaseTestXDHKeyPairGenerator extends BaseTestJunit5 { KeyPairGenerator kpg = null; KeyPairGenerator kpgc = null; - @Before - @Override - protected void setUp() throws Exception { - super.setUp(); - kpg = KeyPairGenerator.getInstance("XDH", providerName); - kpgc = KeyPairGenerator.getInstance("XDH", providerName); + @BeforeEach + public void setUp() throws Exception { + kpg = KeyPairGenerator.getInstance("XDH", getProviderName()); + kpgc = KeyPairGenerator.getInstance("XDH", getProviderName()); } - public BaseTestXDHKeyPairGenerator(String providerName) { - super(providerName); - } - - public void tearDown() throws Exception {} - + @Test public void testXECKeyGen_X255() throws Exception { doXECKeyGen(255); } + @Test public void testXECKeyGen_X448() throws Exception { doXECKeyGen(448); } + @Test public void testXECKeyGen_FFDHE2048() throws Exception { doXECKeyGen(2048); } + @Test public void testXECKeyGen_FFDHE3072() throws Exception { doXECKeyGen(3072); } + @Test public void testXECKeyGen_FFDHE4096() throws Exception { doXECKeyGen(4096); } + @Test public void testXECKeyGen_FFDHE6144() throws Exception { doXECKeyGen(6144); } + @Test public void testXECKeyGen_FFDHE8192() throws Exception { doXECKeyGen(8192); } @@ -82,6 +82,7 @@ public void doXECKeyGen(int keypairSize) throws Exception { //System.out.println("ECPrivate: " + ecpr.getS()); } + @Test public void testXECKeyGenCurves() throws Exception { generictestXECKeyGenCurve("X25519"); generictestXECKeyGenCurve("X448"); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHMultiParty.java b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHMultiParty.java index 7a5089bb..73e1d172 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseTestXDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseTestXDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,19 +19,13 @@ import java.security.spec.NamedParameterSpec; import java.util.Arrays; import javax.crypto.KeyAgreement; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestXDHMultiParty extends BaseTest { +public class BaseTestXDHMultiParty extends BaseTestJunit5 { static final byte[] origMsg = "this is the original message to be signed".getBytes(); - - public BaseTestXDHMultiParty(String providerName) { - super(providerName); - } - - public void setUp() throws Exception {} - - public void tearDown() throws Exception {} - + @Test public void testXDHMulti_x25519() throws Exception { String curveName = "X25519"; @@ -39,7 +33,7 @@ public void testXDHMulti_x25519() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { assertTrue(true); return; @@ -47,6 +41,7 @@ public void testXDHMulti_x25519() throws Exception { assertTrue(false); } + @Test public void testXDHMulti_x448() throws Exception { String curveName = "X448"; @@ -54,7 +49,7 @@ public void testXDHMulti_x448() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { assertTrue(true); return; @@ -62,6 +57,7 @@ public void testXDHMulti_x448() throws Exception { assertTrue(false); } + @Test public void testXDHMulti_ffdhe2048() throws Exception { String curveName = "FFDHE2048"; @@ -69,7 +65,7 @@ public void testXDHMulti_ffdhe2048() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { assertTrue(true); return; @@ -77,6 +73,7 @@ public void testXDHMulti_ffdhe2048() throws Exception { assertTrue(false); } + @Test public void testXDHMulti_ffdhe3072() throws Exception { String curveName = "FFDHE3072"; @@ -84,7 +81,7 @@ public void testXDHMulti_ffdhe3072() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { assertTrue(true); return; @@ -92,6 +89,7 @@ public void testXDHMulti_ffdhe3072() throws Exception { assertTrue(false); } + @Test public void testXDHMulti_ffdhe4096() throws Exception { String curveName = "FFDHE4096"; @@ -99,7 +97,7 @@ public void testXDHMulti_ffdhe4096() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { assertTrue(true); return; @@ -107,6 +105,7 @@ public void testXDHMulti_ffdhe4096() throws Exception { assertTrue(false); } + @Test public void testXDHMulti_ffdhe6144() throws Exception { String curveName = "FFDHE6144"; @@ -114,7 +113,7 @@ public void testXDHMulti_ffdhe6144() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { assertTrue(true); return; @@ -122,6 +121,7 @@ public void testXDHMulti_ffdhe6144() throws Exception { assertTrue(false); } + @Test public void testXDHMulti_ffdhe8192() throws Exception { String curveName = "FFDHE8192"; @@ -129,7 +129,7 @@ public void testXDHMulti_ffdhe8192() throws Exception { NamedParameterSpec nps = new NamedParameterSpec(curveName); try { - compute_xdh_multiparty_oneprovider(curveName, nps, providerName); + compute_xdh_multiparty_oneprovider(curveName, nps, getProviderName()); } catch (IllegalStateException e) { //System.out.println(e.getMessage()); assertTrue(true); diff --git a/src/test/java/ibm/jceplus/junit/base/BaseUtils.java b/src/test/java/ibm/jceplus/junit/base/BaseUtils.java index 5026c218..fb5ab983 100644 --- a/src/test/java/ibm/jceplus/junit/base/BaseUtils.java +++ b/src/test/java/ibm/jceplus/junit/base/BaseUtils.java @@ -11,9 +11,7 @@ import java.security.Provider; abstract public class BaseUtils { - //-------------------------------------------------------------------------- - // - // + public static final String PROVIDER_BC = "BC"; // BouncyCastle public static final String PROVIDER_SUN = "SUN"; // SUN public static final String PROVIDER_SunJCE = "SunJCE"; // SunJCE @@ -51,9 +49,7 @@ public static byte[] generateBytes(int length) { return bytes; } - //-------------------------------------------------------------------------- - // - // + public static byte[] hexStringToByteArray(String string) { String s = string.trim().replaceAll(" +", ""); // remove all spaces @@ -66,17 +62,13 @@ public static byte[] hexStringToByteArray(String string) { return b; } - //-------------------------------------------------------------------------- - // - // + public static Provider loadProvider(String providerName, String providerClassName) throws Exception { return loadProvider(providerName, providerClassName, true); } - //-------------------------------------------------------------------------- - // - // + public static Provider loadProvider(String providerName, String providerClassName, boolean addToProviderList) throws Exception { Provider provider = java.security.Security.getProvider(providerName); @@ -90,23 +82,17 @@ public static Provider loadProvider(String providerName, String providerClassNam return provider; } - //-------------------------------------------------------------------------- - // - // + public static Provider loadProviderBC() throws Exception { return loadProvider(PROVIDER_BC, "org.bouncycastle.jce.provider.BouncyCastleProvider"); } - //-------------------------------------------------------------------------- - // - // + public static Provider loadProviderOpenJCEPlus() throws Exception { return loadProvider(PROVIDER_OpenJCEPlus, "com.ibm.crypto.plus.provider.OpenJCEPlus"); } - //-------------------------------------------------------------------------- - // - // + public static Provider loadProviderOpenJCEPlusFIPS() throws Exception { return loadProvider(PROVIDER_OpenJCEPlusFIPS, "com.ibm.crypto.plus.provider.OpenJCEPlusFIPS"); diff --git a/src/test/java/ibm/jceplus/junit/base/Record.java b/src/test/java/ibm/jceplus/junit/base/Record.java index 9e625a51..dda7ccd5 100644 --- a/src/test/java/ibm/jceplus/junit/base/Record.java +++ b/src/test/java/ibm/jceplus/junit/base/Record.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAES.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAES.java index 67b051b3..6c4df073 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAES.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAES.java @@ -9,16 +9,16 @@ import ibm.jceplus.junit.base.BaseTestCipher; import java.security.AlgorithmParameters; -import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; import java.util.Random; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; -import org.junit.Assume; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; public class BaseTestMemStressAES extends BaseTestCipher { @@ -26,11 +26,6 @@ public class BaseTestMemStressAES extends BaseTestCipher { static int iteration = 0; static final byte[] plainText1024 = new byte[1024]; static final byte[] plainText16 = "12345678".getBytes(); - - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; protected SecretKey key = null; protected AlgorithmParameters params = null; protected Cipher cp = null; @@ -38,58 +33,20 @@ public class BaseTestMemStressAES extends BaseTestCipher { protected int specifiedKeySize = 0; static int numTimes = 100; boolean printheapstats = false; - int DEFAULT_KEYSIZE = 256; byte[] encodedKey = null; KeyGenerator keyGenerator = null; SecretKey keyFromIBMJCE = null; - - - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressAES(String providerName) { - super(providerName); - this.specifiedKeySize = DEFAULT_KEYSIZE; - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - } - } - - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressAES(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - } - - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - encodedKey = new byte[(specifiedKeySize > 0 ? specifiedKeySize : 128) / 8]; + this.specifiedKeySize = getKeySize(); + encodedKey = new byte[specifiedKeySize / 8]; r.nextBytes(plainText1024); //key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); - keyGenerator = KeyGenerator.getInstance("AES", "OpenJCEPlus"); - keyGenerator.init(DEFAULT_KEYSIZE); + keyGenerator = KeyGenerator.getInstance("AES", getProviderName()); + keyGenerator.init(getKeySize()); keyFromIBMJCE = keyGenerator.generateKey(); String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); @@ -102,14 +59,7 @@ public void setUp() throws Exception { System.out.println("Testing AES " + this.specifiedKeySize); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testAES() throws Exception { Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; @@ -144,16 +94,14 @@ public void testAES() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + private void encryptDecryptData(String algorithm) throws Exception { byte[] clearText = {(byte) 0x0, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09, (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, (byte) 0x14, (byte) 0x15}; - SecretKeyFactory kf = SecretKeyFactory.getInstance("AES", providerName); + SecretKeyFactory kf = SecretKeyFactory.getInstance("AES", getProviderName()); //test KeyFactory routines. kf.translateKey(keyFromIBMJCE); @@ -161,7 +109,7 @@ private void encryptDecryptData(String algorithm) throws Exception { AlgorithmParameters params = null; // Encrypt once - Cipher cipher = Cipher.getInstance(algorithm, providerName); + Cipher cipher = Cipher.getInstance(algorithm, getProviderName()); cipher.init(Cipher.ENCRYPT_MODE, key); @@ -173,78 +121,4 @@ private void encryptDecryptData(String algorithm) throws Exception { byte[] plainTextDecrypted = cipher.doFinal(cipherData); assertTrue(Arrays.equals(clearText, plainTextDecrypted)); } // end encryptDecryptData() - - - - //-------------------------------------------------------------------------- - // warmup functions for enable fastjni - // - static public void warmup() throws Exception { - java.security.Provider java_provider = null; - int modeInt; - boolean stream = false; - SecretKeySpec skey; - int key_size = 128; - byte[] skey_bytes = new byte[key_size / 8]; - int len = 4096; - byte[] iv; - byte[] data = plainText16; - byte[] out; - Cipher cipher; - Random r; - try { - java_provider = java.security.Security.getProvider("OpenJCEPlus"); - if (java_provider == null) { - java_provider = new com.ibm.crypto.plus.provider.OpenJCEPlus(); - java.security.Security.insertProviderAt(java_provider, 1); - } - - r = new Random(10); - String mode = "encrypt_stream"; - String cipherMode = "AES/CBC/NoPadding"; - - if (mode.contains("encrypt")) - modeInt = 1; - else if (mode.contains("decrypt")) - modeInt = 0; - else - throw new RuntimeException("Unsupported mode"); - - if (mode.contains("block")) - stream = false; - else if (mode.contains("stream")) - stream = true; - else - throw new RuntimeException("block mode or stream mode must be specified"); - - r.nextBytes(skey_bytes); - skey = new SecretKeySpec(skey_bytes, "AES"); - - - for (int i = 0; i < numTimes; i++) { - cipher = Cipher.getInstance(cipherMode, java_provider); - out = new byte[len]; - iv = new byte[16]; - r.nextBytes(iv); - AlgorithmParameterSpec iviv = new IvParameterSpec(iv); - - if (modeInt == 0) - cipher.init(Cipher.DECRYPT_MODE, skey, iviv); - else - cipher.init(Cipher.ENCRYPT_MODE, skey, iviv); - if (stream) { - for (long j = 0; j < 9; j++) - cipher.update(data, 0, data.length, out); - } else { - for (long k = 0; k < 9; k++) { - cipher.update(data, 0, data.length, out); - // cipher.doFinal(); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAESGCM.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAESGCM.java index 50a5aa28..61463c95 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAESGCM.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressAESGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,25 +8,24 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.lang.reflect.Method; import java.security.AlgorithmParameters; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; -import org.junit.Assume; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestMemStressAESGCM extends BaseTest { +public class BaseTestMemStressAESGCM extends BaseTestJunit5 { // 16 bytes: PASSED static final byte[] plainText16 = "1234567812345678".getBytes(); static final byte[] plainText1024 = new byte[1024]; - // -------------------------------------------------------------------------- - // - // protected KeyGenerator aesKeyGen; protected SecretKey key; protected AlgorithmParameters params = null; @@ -38,28 +37,9 @@ public class BaseTestMemStressAESGCM extends BaseTest { int numTimes = 100; boolean printheapstats = false; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressAESGCM(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressAESGCM(String providerName, int keySize) throws Exception { - super(providerName); - this.specifiedKeySize = keySize; - - Assume.assumeTrue(javax.crypto.Cipher.getMaxAllowedKeyLength("AES") >= keySize); - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - aesKeyGen = KeyGenerator.getInstance("AES", providerName); + aesKeyGen = KeyGenerator.getInstance("AES", getProviderName()); if (specifiedKeySize > 0) { aesKeyGen.init(specifiedKeySize); } @@ -73,18 +53,10 @@ public void setUp() throws Exception { System.out.println("Testing AESGCM"); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - - // -------------------------------------------------------------------------- - // - // + @Test public void testAES_GCM() throws Exception { // Test AES GCM Cipher - cp = Cipher.getInstance("AES/GCM/NoPadding", providerName); + cp = Cipher.getInstance("AES/GCM/NoPadding", getProviderName()); Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; long prevFreeMemory = rt.freeMemory(); @@ -111,14 +83,8 @@ public void testAES_GCM() throws Exception { prevFreeMemory = currentFreeMemory; } } - - - } - // -------------------------------------------------------------------------- - // - // protected void encryptDecrypt(Cipher cp) throws Exception { cp.init(Cipher.ENCRYPT_MODE, key); byte[] cipherText = cp.doFinal(plainText1024); @@ -130,38 +96,23 @@ protected void encryptDecrypt(Cipher cp) throws Exception { assertTrue(java.util.Arrays.equals(plainText1024, newPlainText)); } - // -------------------------------------------------------------------------- - // - // protected void encryptDecrypt(String algorithm) throws Exception { - encryptDecrypt(algorithm, false); - } - // -------------------------------------------------------------------------- - // - // protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlockSize) throws Exception { encryptDecrypt(algorithm, requireLengthMultipleBlockSize, null); } - // -------------------------------------------------------------------------- - // - // protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams) throws Exception { encryptDecrypt(algorithm, requireLengthMultipleBlockSize, algParams, plainText1024); } - // -------------------------------------------------------------------------- - // - // protected void encryptDecrypt(String algorithm, boolean requireLengthMultipleBlockSize, AlgorithmParameters algParams, byte[] message) throws Exception { encryptDecryptDoFinal(algorithm, requireLengthMultipleBlockSize, algParams, message); - } // -------------------------------------------------------------------------- @@ -171,7 +122,7 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult AlgorithmParameters algParams, byte[] message) throws Exception { - cp = Cipher.getInstance(algorithm, providerName); + cp = Cipher.getInstance(algorithm, getProviderName()); if (algParams == null) { cp.init(Cipher.ENCRYPT_MODE, key); } else { @@ -210,4 +161,3 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult } - diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressChaCha20Poly1305.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressChaCha20Poly1305.java index 98a7f60c..e1068d3a 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressChaCha20Poly1305.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressChaCha20Poly1305.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,11 +15,13 @@ import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTestMemStressChaCha20Poly1305 extends BaseTestCipher implements ChaCha20Constants { - //-------------------------------------------------------------------------- - // - // + // 14 bytes: PASSED static final byte[] PLAIN_TEXT_14 = "12345678123456".getBytes(); @@ -53,9 +55,7 @@ public class BaseTestMemStressChaCha20Poly1305 extends BaseTestCipher implements static final IvParameterSpec CHACHA20_POLY1305_PARAM_SPEC = new IvParameterSpec(NONCE_12_BYTE); - //-------------------------------------------------------------------------- - // - // + protected KeyGenerator keyGen = null; protected SecretKey key = null; protected IvParameterSpec paramSpec = null; @@ -65,19 +65,9 @@ public class BaseTestMemStressChaCha20Poly1305 extends BaseTestCipher implements int numTimes = 100; boolean printheapstats = false; - - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressChaCha20Poly1305(String providerName) { - super(providerName); - } - - //-------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { - keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, providerName); + keyGen = KeyGenerator.getInstance(CHACHA20_ALGORITHM, getProviderName()); if (specifiedKeySize > 0) { keyGen.init(specifiedKeySize); } @@ -91,14 +81,13 @@ public void setUp() throws Exception { System.out.println("Testing ChaChaPoly1305"); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} + + //-------------------------------------------------------------------------- // Run encrypt/decrypt test using just doFinal calls // + @Test public void testChaCha20Poly1305EncryptDecryptDoFinalWithAAD() throws Exception { Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; @@ -109,7 +98,7 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithAAD() throws Exception long prevUsedMemory = 0; for (int i = 0; i < numTimes; i++) { try { - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.ENCRYPT_MODE, key, CHACHA20_POLY1305_PARAM_SPEC); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); byte[] cipherText = cp.doFinal(PLAIN_TEXT); @@ -117,7 +106,7 @@ public void testChaCha20Poly1305EncryptDecryptDoFinalWithAAD() throws Exception paramSpec = cp.getParameters().getParameterSpec(IvParameterSpec.class); // Verify the text - cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, providerName); + cp = Cipher.getInstance(CHACHA20_POLY1305_ALGORITHM, getProviderName()); cp.init(Cipher.DECRYPT_MODE, key, paramSpec); cp.updateAAD(CHACHA20_POLY1305_AAD, 0, CHACHA20_POLY1305_AAD.length); byte[] newPlainText = cp.doFinal(cipherText, 0, cipherText.length); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDH.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDH.java index 810ef5c7..cb224f1b 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDH.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDH.java @@ -8,7 +8,7 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; @@ -21,12 +21,13 @@ import java.util.Arrays; import javax.crypto.KeyAgreement; import javax.crypto.spec.DHParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; + +public class BaseTestMemStressDH extends BaseTestJunit5 { -public class BaseTestMemStressDH extends BaseTest { - // -------------------------------------------------------------------------- - // - // static final byte[] origMsg = "this is the original message to be signed".getBytes(); static DHParameterSpec algParameterSpec; @@ -38,22 +39,7 @@ public class BaseTestMemStressDH extends BaseTest { boolean printheapstats = false; int dhSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressDH(String providerName) { - super(providerName); - - } - - public BaseTestMemStressDH(String providerName, int dhSize) { - super(providerName); - this.dhSize = dhSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -64,15 +50,7 @@ public void setUp() throws Exception { System.out.println("Testing DH"); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testDH() throws Exception { DHParameterSpec dhps = generateDHParameters(dhSize); @@ -108,7 +86,7 @@ void compute_dh_key(AlgorithmParameterSpec algParameterSpec) throws NoSuchAlgori KeyPairGenerator kpgA = null; try { - kpgA = KeyPairGenerator.getInstance("DH", providerName); + kpgA = KeyPairGenerator.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -129,7 +107,7 @@ void compute_dh_key(AlgorithmParameterSpec algParameterSpec) throws NoSuchAlgori // set up KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("DH", providerName); + keyAgreeA = KeyAgreement.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -147,7 +125,7 @@ void compute_dh_key(AlgorithmParameterSpec algParameterSpec) throws NoSuchAlgori KeyPairGenerator kpgB = null; try { - kpgB = KeyPairGenerator.getInstance("DH", providerName); + kpgB = KeyPairGenerator.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -169,7 +147,7 @@ void compute_dh_key(AlgorithmParameterSpec algParameterSpec) throws NoSuchAlgori KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("DH", providerName); + keyAgreeB = KeyAgreement.getInstance("DH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -213,7 +191,7 @@ void compute_dh_key(AlgorithmParameterSpec algParameterSpec) throws NoSuchAlgori private DHParameterSpec generateDHParameters(int size) throws Exception { AlgorithmParameterGenerator algParamGen = AlgorithmParameterGenerator.getInstance("DH", - providerName); + getProviderName()); algParamGen.init(size); AlgorithmParameters algParams = algParamGen.generateParameters(); DHParameterSpec dhps = algParams.getParameterSpec(DHParameterSpec.class); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyFactory.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyFactory.java index 8ecc5538..79c96468 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,7 +7,7 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -17,12 +17,12 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import javax.crypto.spec.DHParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressDHKeyFactory extends BaseTestJunit5 { -public class BaseTestMemStressDHKeyFactory extends BaseTest { - // -------------------------------------------------------------------------- - // - // static DHParameterSpec algParameterSpec; @@ -31,22 +31,7 @@ public class BaseTestMemStressDHKeyFactory extends BaseTest { boolean printheapstats = false; int dhSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressDHKeyFactory(String providerName) { - super(providerName); - - } - - public BaseTestMemStressDHKeyFactory(String providerName, int dhSize) { - super(providerName); - this.dhSize = dhSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -57,15 +42,7 @@ public void setUp() throws Exception { System.out.println("Testing DHKeyFactory "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testDHKeyFactory() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyPair.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyPair.java index 5e043f75..f90c76f2 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDHKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,7 +7,7 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.math.BigInteger; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -15,12 +15,12 @@ import java.security.PublicKey; import javax.crypto.KeyAgreement; import javax.crypto.spec.DHParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressDHKeyPair extends BaseTestJunit5 { -public class BaseTestMemStressDHKeyPair extends BaseTest { - // -------------------------------------------------------------------------- - // - // static DHParameterSpec algParameterSpec; @@ -29,22 +29,7 @@ public class BaseTestMemStressDHKeyPair extends BaseTest { boolean printheapstats = false; int dhSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressDHKeyPair(String providerName) { - super(providerName); - - } - - public BaseTestMemStressDHKeyPair(String providerName, int dhSize) { - super(providerName); - this.dhSize = dhSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -55,15 +40,7 @@ public void setUp() throws Exception { System.out.println("Testing DHKeyPair "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testDHKeyPair() throws Exception { Runtime rt = Runtime.getRuntime(); @@ -105,6 +82,7 @@ public void testDHKeyPair() throws Exception { } } + @Test public void testDHKeyPairWithComputeSecret() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyFactory.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyFactory.java index ec6f8fa1..4856c569 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,7 +8,7 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -18,12 +18,12 @@ import java.security.spec.EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressDSAKeyFactory extends BaseTestJunit5 { -public class BaseTestMemStressDSAKeyFactory extends BaseTest { - // -------------------------------------------------------------------------- - // - // static DSAParameterSpec algParameterSpec; @@ -32,22 +32,7 @@ public class BaseTestMemStressDSAKeyFactory extends BaseTest { boolean printheapstats = false; int dhSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressDSAKeyFactory(String providerName) { - super(providerName); - - } - - public BaseTestMemStressDSAKeyFactory(String providerName, int dhSize) { - super(providerName); - this.dhSize = dhSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -58,15 +43,7 @@ public void setUp() throws Exception { System.out.println("Testing DSAKeyFactory "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testDSAKeyFactory() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyPair.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyPair.java index bbf779f1..1f492fc0 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSAKeyPair.java @@ -7,7 +7,7 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -19,12 +19,13 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.fail; + +public class BaseTestMemStressDSAKeyPair extends BaseTestJunit5 { -public class BaseTestMemStressDSAKeyPair extends BaseTest { - // -------------------------------------------------------------------------- - // - // static DSAParameterSpec algParameterSpec; @@ -34,22 +35,7 @@ public class BaseTestMemStressDSAKeyPair extends BaseTest { protected KeyFactory dsaKeyFactory; int dsaSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressDSAKeyPair(String providerName) { - super(providerName); - - } - - public BaseTestMemStressDSAKeyPair(String providerName, int dsaSize) { - super(providerName); - this.dsaSize = dsaSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -58,18 +44,10 @@ public void setUp() throws Exception { printheapstats = Boolean .valueOf(System.getProperty("com.ibm.jceplus.memstress.printheapstats")); System.out.println("Testing DSAKeyPair "); - dsaKeyFactory = KeyFactory.getInstance("DSA", providerName); + dsaKeyFactory = KeyFactory.getInstance("DSA", getProviderName()); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testDSAKeyPair() throws Exception { Runtime rt = Runtime.getRuntime(); @@ -130,9 +108,7 @@ protected void keyFactoryCreateFromEncoded(int size) throws Exception { } } - // -------------------------------------------------------------------------- - // - // + protected void keyFactoryCreateFromKeySpec(int size) throws Exception { KeyPair dsaKeyPair = generateKeyPair(size); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSASignature.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSASignature.java index 28585e07..000d24c4 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDSASignature.java @@ -8,23 +8,23 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTestSignature; +import ibm.jceplus.junit.base.BaseTestJunit5Signature; import java.security.InvalidKeyException; import java.security.InvalidParameterException; import java.security.KeyPair; import java.security.KeyPairGenerator; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; -public class BaseTestMemStressDSASignature extends BaseTestSignature { +public class BaseTestMemStressDSASignature extends BaseTestJunit5Signature { static final byte[] origMsg = "this is the original message to be signed".getBytes(); int numTimes = 100; boolean printheapstats = false; String algo = "SHA256withDSA"; - @Before + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDigest.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDigest.java index c9f7e670..ec3b15a5 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDigest.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressDigest.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,46 +8,33 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class BaseTestMemStressDigest extends BaseTest { +public class BaseTestMemStressDigest extends BaseTestJunit5 { int numTimes = 100; boolean printheapstats = false; - protected String digestAlg = null; String pText = "Hello World"; - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { numTimes = Integer.valueOf(numTimesStr); } printheapstats = Boolean .valueOf(System.getProperty("com.ibm.jceplus.memstress.printheapstats")); - System.out.println("Testing " + digestAlg); + System.out.println("Testing " + getAlgorithm()); } - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressDigest(String providerName) { - super(providerName); - this.digestAlg = "SHA-256"; - } - - public BaseTestMemStressDigest(String providerName, String algo) { - super(providerName); - this.digestAlg = algo; - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testDigestWithUpdates() throws Exception { - MessageDigest md = MessageDigest.getInstance(digestAlg, providerName); + MessageDigest md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); for (int i = 0; i < 100000; i++) md.update(pText.getBytes("UTF-8")); @@ -55,9 +42,7 @@ public void testDigestWithUpdates() throws Exception { } - //-------------------------------------------------------------------------- - // - // + @Test public void testDigest_SingleBlock() throws Exception { Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; @@ -80,7 +65,7 @@ public void testDigest_SingleBlock() throws Exception { prevUsedMemory = prevTotalMemory - prevFreeMemory; if (currentTotalMemory != prevTotalMemory || currentFreeMemory != prevFreeMemory) { if (printheapstats) { - System.out.println(digestAlg + " Iteration = " + i + " " + "Total: = " + System.out.println(getAlgorithm() + " Iteration = " + i + " " + "Total: = " + currentTotalMemory + " " + "currentUsed: = " + currentUsedMemory + " " + "freeMemory: " + currentFreeMemory + " prevUsedMemory: " + prevUsedMemory); @@ -95,7 +80,7 @@ public void testDigest_SingleBlock() throws Exception { private byte[] digest(byte[] input) { MessageDigest md; try { - md = MessageDigest.getInstance(digestAlg, providerName); + md = MessageDigest.getInstance(getAlgorithm(), getProviderName()); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { throw new IllegalArgumentException(e); } diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECDSASignature.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECDSASignature.java index c2a085b5..48d23002 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECDSASignature.java @@ -7,13 +7,13 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTestSignature; +import ibm.jceplus.junit.base.BaseTestJunit5Signature; import java.security.KeyPair; import java.security.KeyPairGenerator; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class BaseTestMemStressECDSASignature extends BaseTestSignature { +public class BaseTestMemStressECDSASignature extends BaseTestJunit5Signature { int numTimes = 100; boolean printheapstats = false; @@ -23,7 +23,7 @@ public class BaseTestMemStressECDSASignature extends BaseTestSignature { int curveSize = 256; - @Before + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyFactory.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyFactory.java index c778d35e..f7acbd6a 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,7 +7,7 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -17,12 +17,12 @@ import java.security.spec.EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressECKeyFactory extends BaseTestJunit5 { -public class BaseTestMemStressECKeyFactory extends BaseTest { - // -------------------------------------------------------------------------- - // - // static ECParameterSpec algParameterSpec; @@ -31,22 +31,7 @@ public class BaseTestMemStressECKeyFactory extends BaseTest { boolean printheapstats = false; int dhSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressECKeyFactory(String providerName) { - super(providerName); - - } - - public BaseTestMemStressECKeyFactory(String providerName, int dhSize) { - super(providerName); - this.dhSize = dhSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -57,15 +42,7 @@ public void setUp() throws Exception { System.out.println("Testing ECKeyFactory "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testECKeyFactory() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyPair.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyPair.java index f2c80b0a..435d43cc 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressECKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,19 +8,19 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.spec.ECGenParameterSpec; import java.security.spec.ECParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressECKeyPair extends BaseTestJunit5 { -public class BaseTestMemStressECKeyPair extends BaseTest { - // -------------------------------------------------------------------------- - // - // static ECParameterSpec algParameterSpec; @@ -31,44 +31,20 @@ public class BaseTestMemStressECKeyPair extends BaseTest { KeyPairGenerator kpgc = null; int ecSize = 0; - - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressECKeyPair(String providerName) { - super(providerName); - - } - - public BaseTestMemStressECKeyPair(String providerName, int ecSize) { - super(providerName); - this.ecSize = ecSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { numTimes = Integer.valueOf(numTimesStr); } - kpg = KeyPairGenerator.getInstance("EC", providerName); - kpgc = KeyPairGenerator.getInstance("EC", providerName); + kpg = KeyPairGenerator.getInstance("EC", getProviderName()); + kpgc = KeyPairGenerator.getInstance("EC", getProviderName()); printheapstats = Boolean .valueOf(System.getProperty("com.ibm.jceplus.memstress.printheapstats")); System.out.println("Testing ECKeyPair "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testECKeyPair() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHKDF.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHKDF.java index 69e54b18..bcd2812b 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHKDF.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,6 +8,7 @@ package ibm.jceplus.junit.base.memstress; +import ibm.jceplus.junit.base.BaseTestJunit5; import ibm.security.internal.spec.HKDFExpandParameterSpec; import ibm.security.internal.spec.HKDFExtractParameterSpec; import java.io.IOException; @@ -26,9 +27,11 @@ import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; - -public class BaseTestMemStressHKDF extends ibm.jceplus.junit.base.BaseTest { +public class BaseTestMemStressHKDF extends BaseTestJunit5 { public String testName; public String algName; @@ -46,25 +49,7 @@ public class BaseTestMemStressHKDF extends ibm.jceplus.junit.base.BaseTest { int keysize = 192; String algo = "kda-hkdf-with-sha256"; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressHKDF(String providerName) { - super(providerName); - } - - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressHKDF(String providerName, String algo, int keyszie) { - super(providerName); - this.keysize = keyszie; - this.algo = algo; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -75,13 +60,7 @@ public void setUp() throws Exception { System.out.println("Testing HKDF keysize=" + this.keysize + " algorihm=" + this.algo); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - - + @Test public void testHKDF() throws Exception { Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; @@ -91,7 +70,7 @@ public void testHKDF() throws Exception { long currentUsedMemory = 0; long prevUsedMemory = 0; for (int i = 0; i < numTimes; i++) { - aesHKDF(192, "kda-hkdf-with-sha256", "AES", "AES", providerName); + aesHKDF(192, "kda-hkdf-with-sha256", "AES", "AES", getProviderName()); currentTotalMemory = rt.totalMemory(); currentFreeMemory = rt.freeMemory(); currentUsedMemory = currentTotalMemory - currentFreeMemory; @@ -120,8 +99,8 @@ private void aesHKDF(int aesKeySize, String hashAlg, String extractAlg, String e SecretKey psk = keyGen.generateKey(); // System.out.println("Generated secretKey=" + psk); MessageDigest md = MessageDigest.getInstance(hashAlg.replace("kda-hkdf-with-", ""), - providerName); - KeyGenerator hkdfExtract = KeyGenerator.getInstance(hashAlg, providerName); + getProviderName()); + KeyGenerator hkdfExtract = KeyGenerator.getInstance(hashAlg, getProviderName()); byte[] zeros = new byte[md.getDigestLength()]; hkdfExtract.init(new HKDFExtractParameterSpec(psk.getEncoded(), zeros, extractAlg)); @@ -131,7 +110,7 @@ private void aesHKDF(int aesKeySize, String hashAlg, String extractAlg, String e byte[] label = ("tls13 res binder").getBytes(); byte[] hkdfInfo = createHkdfInfo(label, new byte[0], md.getDigestLength()); - KeyGenerator hkdfExpand = KeyGenerator.getInstance(hashAlg, providerName); + KeyGenerator hkdfExpand = KeyGenerator.getInstance(hashAlg, getProviderName()); hkdfExpand.init(new HKDFExpandParameterSpec(earlySecret, hkdfInfo, (aesKeySize / 8)/* md.getDigestLength() */, expandAlg)); SecretKey expandSecretKey = hkdfExpand.generateKey(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHmacSHA.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHmacSHA.java index e868186d..90326da3 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHmacSHA.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressHmacSHA.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,18 +7,17 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestMemStressHmacSHA extends BaseTest { +public class BaseTestMemStressHmacSHA extends BaseTestJunit5 { /* This test by default tests HmacSHAWith256 */ - //-------------------------------------------------------------------------- - // - // - static boolean warmup = false; int numTimes = 100; boolean printheapstats = false; String hmacAlgo = "HmacSHA256"; @@ -43,50 +42,11 @@ public class BaseTestMemStressHmacSHA extends BaseTest { byte[] digest_1, data_1, key_1; - - - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressHmacSHA(String providerName) { - super(providerName); + @BeforeEach + public void setUp() throws Exception { this.data_1 = def_data_1.clone(); this.key_1 = def_key_1.clone(); this.digest_1 = def_digest_1.clone(); - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - public BaseTestMemStressHmacSHA(String providerName, String digestAlgo, String hmacAlgo, - byte[] data1, byte[] key1, byte[] digest1) { - super(providerName); - this.data_1 = data1.clone(); - this.key_1 = key1.clone(); - this.digest_1 = digest1.clone(); - this.hmacAlgo = hmacAlgo; - try { - if (warmup == false) { - warmup = true; - warmup(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - - } - - //-------------------------------------------------------------------------- - // - // - public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { numTimes = Integer.valueOf(numTimesStr); @@ -96,16 +56,9 @@ public void setUp() throws Exception { System.out.println("Testing HmacSHA " + this.hmacAlgo); } - //-------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - //-------------------------------------------------------------------------- - // - // + @Test public void testHmacSHA_key1() throws Exception { - Mac mac = Mac.getInstance(this.hmacAlgo, providerName); + Mac mac = Mac.getInstance(this.hmacAlgo, getProviderName()); SecretKeySpec key = new SecretKeySpec(key_1, this.hmacAlgo); Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; @@ -137,25 +90,5 @@ public void testHmacSHA_key1() throws Exception { } } } - - - - //-------------------------------------------------------------------------- - // - // - public void warmup() throws Exception { - - try { - Mac mac = Mac.getInstance(this.hmacAlgo, providerName); - SecretKeySpec key = new SecretKeySpec(key_1, this.hmacAlgo); - for (long i = 0; i < 10000; i++) { - mac.init(key); - mac.update(data_1); - mac.doFinal(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyFactory.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyFactory.java index 29438cf6..e8e53660 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,7 +7,7 @@ */ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -16,33 +16,18 @@ import java.security.spec.EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressRSAKeyFactory extends BaseTestJunit5 { -public class BaseTestMemStressRSAKeyFactory extends BaseTest { - // -------------------------------------------------------------------------- - // - // int numTimes = 100; boolean printheapstats = false; int rsaSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressRSAKeyFactory(String providerName) { - super(providerName); - - } - - public BaseTestMemStressRSAKeyFactory(String providerName, int rsaSize) { - super(providerName); - this.rsaSize = rsaSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -53,15 +38,7 @@ public void setUp() throws Exception { System.out.println("Testing RSAKeyFactory "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testRSAKeyFactory() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyPair.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyPair.java index 80dc3a38..21c0844f 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,14 +8,14 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyPairGenerator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BaseTestMemStressRSAKeyPair extends BaseTestJunit5 { -public class BaseTestMemStressRSAKeyPair extends BaseTest { - // -------------------------------------------------------------------------- - // - // @@ -23,22 +23,7 @@ public class BaseTestMemStressRSAKeyPair extends BaseTest { boolean printheapstats = false; int rsaSize = 2048; - // -------------------------------------------------------------------------- - // - // - public BaseTestMemStressRSAKeyPair(String providerName) { - super(providerName); - - } - - public BaseTestMemStressRSAKeyPair(String providerName, int rsaSize) { - super(providerName); - this.rsaSize = rsaSize; - } - - // -------------------------------------------------------------------------- - // - // + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -49,15 +34,7 @@ public void setUp() throws Exception { System.out.println("Testing RSAKeyPair "); } - // -------------------------------------------------------------------------- - // - // - public void tearDown() throws Exception {} - - // -------------------------------------------------------------------------- - // - // - + @Test public void testRSAKeyPair() throws Exception { Runtime rt = Runtime.getRuntime(); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAPSS2.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAPSS2.java index af45d43b..53d3bbae 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,14 +8,17 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.Signature; import java.security.spec.MGF1ParameterSpec; import java.security.spec.PSSParameterSpec; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestMemStressRSAPSS2 extends BaseTest { +public class BaseTestMemStressRSAPSS2 extends BaseTestJunit5 { String IBM_ALG = "RSASA-PSS"; @@ -52,16 +55,8 @@ public class BaseTestMemStressRSAPSS2 extends BaseTest { boolean printheapstats = false; int keysize = 2048; - public BaseTestMemStressRSAPSS2(String providerName) { - super(providerName); - } - - public BaseTestMemStressRSAPSS2(String providerName, int keysize) { - super(providerName); - this.keysize = keysize; - } - - protected void setUp() throws Exception { + @BeforeAll + public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { numTimes = Integer.valueOf(numTimesStr); @@ -78,7 +73,7 @@ protected void setUp() throws Exception { * * @throws Exception */ - @org.junit.Test + @Test public void testRSAPSSSignature() throws Exception { Runtime rt = Runtime.getRuntime(); @@ -89,7 +84,7 @@ public void testRSAPSSSignature() throws Exception { long currentUsedMemory = 0; long prevUsedMemory = 0; - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", providerName); + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", getProviderName()); keyGen.initialize(this.keysize, new java.security.SecureRandom()); KeyPair keyPair = keyGen.genKeyPair(); PSSParameterSpec pssparamSpec = new PSSParameterSpec("SHA-1", "MGF1", @@ -134,7 +129,7 @@ public void testRSAPSSSignature() throws Exception { protected void dotestSignature(byte[] content, String algorithm, KeyPair keyPair, PSSParameterSpec pssParameterSpec) throws Exception { - Signature sig = Signature.getInstance(algorithm, providerName); + Signature sig = Signature.getInstance(algorithm, getProviderName()); if (pssParameterSpec != null) { // System.out.println ("calling sig.setParameter"); sig.setParameter(pssParameterSpec); @@ -148,7 +143,7 @@ protected void dotestSignature(byte[] content, String algorithm, KeyPair keyPair sig.update(content); // Check Signature - // Signature verifySig = Signature.getInstance("SHA1withRSA/PSS", providerName); + // Signature verifySig = Signature.getInstance("SHA1withRSA/PSS", getProviderName()); // verifySig.initVerify(cert); // verifySig.update(content); boolean signatureVerified = sig.verify(sigBytes); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSASignature.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSASignature.java index e936f6ca..9dd8541b 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSASignature.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressRSASignature.java @@ -8,20 +8,20 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTestSignature; +import ibm.jceplus.junit.base.BaseTestJunit5Signature; import java.security.KeyPair; import java.security.KeyPairGenerator; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class BaseTestMemStressRSASignature extends BaseTestSignature { +public class BaseTestMemStressRSASignature extends BaseTestJunit5Signature { static final byte[] origMsg = "this is the original message to be signed".getBytes(); int numTimes = 100; boolean printheapstats = false; String algo = "SHA256withRSA"; - @Before + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHA.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHA.java index dd235546..da262df3 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHA.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHA.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,17 +8,18 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.MessageDigest; import java.util.Arrays; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestMemStressSHA extends BaseTest { +public class BaseTestMemStressSHA extends BaseTestJunit5 { /* This test by default tests SHA-256 */ - //-------------------------------------------------------------------------- - // - // + byte[] input_1, result_1, input_2, result_2; final byte[] def_input_1 = {(byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, @@ -46,7 +47,8 @@ public class BaseTestMemStressSHA extends BaseTest { boolean printheapstats = false; protected String digestAlg = "SHA-256"; - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { numTimes = Integer.valueOf(numTimesStr); @@ -56,35 +58,9 @@ protected void setUp() throws Exception { System.out.println("Testing " + digestAlg); } - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressSHA(String providerName) { - super(providerName); - this.input_1 = def_input_1.clone(); - this.input_2 = def_input_2.clone(); - this.result_1 = def_result_1.clone(); - this.result_2 = def_result_2.clone(); - } - - - /* This constructor must be used for digests other than SHA-256" */ - public BaseTestMemStressSHA(String providerName, String algorithm, byte[] input1, - byte[] result1, byte[] input2, byte[] result2) { - super(providerName); - this.input_1 = input1.clone(); - this.input_2 = input2.clone(); - this.result_1 = result1.clone(); - this.result_2 = result2.clone(); - this.digestAlg = algorithm; - - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA() throws Exception { - MessageDigest md = MessageDigest.getInstance(digestAlg, providerName); + MessageDigest md = MessageDigest.getInstance(digestAlg, getProviderName()); for (int i = 0; i < 100000; i++) md.update(input_1); @@ -93,9 +69,7 @@ public void testSHA() throws Exception { assertTrue("Digest did not match expected", Arrays.equals(digest, result_1)); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA_SingleBlock() throws Exception { Runtime rt = Runtime.getRuntime(); long prevTotalMemory = 0; @@ -106,7 +80,7 @@ public void testSHA_SingleBlock() throws Exception { long prevUsedMemory = 0; for (int i = 0; i < numTimes; i++) { - MessageDigest md = MessageDigest.getInstance(digestAlg, providerName); + MessageDigest md = MessageDigest.getInstance(digestAlg, getProviderName()); byte[] digest = md.digest(input_2); assertTrue("Digest did not match expected", Arrays.equals(digest, result_2)); diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHAClone.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHAClone.java index 3cf4b559..0f1b09cf 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHAClone.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressSHAClone.java @@ -8,17 +8,17 @@ package ibm.jceplus.junit.base.memstress; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.MessageDigest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -public class BaseTestMemStressSHAClone extends BaseTest { +public class BaseTestMemStressSHAClone extends BaseTestJunit5 { /* This test by default tests SHA-256 */ - //-------------------------------------------------------------------------- - // - // + byte[] input_1, result_1, input_2, result_2; final byte[] def_input_1 = {(byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, (byte) 0x61, @@ -46,7 +46,8 @@ public class BaseTestMemStressSHAClone extends BaseTest { protected String digestAlg = "SHA-256"; - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { numTimes = Integer.valueOf(numTimesStr); @@ -54,35 +55,9 @@ protected void setUp() throws Exception { System.out.println("Testing " + digestAlg); } - //-------------------------------------------------------------------------- - // - // - public BaseTestMemStressSHAClone(String providerName) { - super(providerName); - this.input_1 = def_input_1.clone(); - this.input_2 = def_input_2.clone(); - this.result_1 = def_result_1.clone(); - this.result_2 = def_result_2.clone(); - } - - - /* This constructor must be used for digests other than SHA-256" */ - public BaseTestMemStressSHAClone(String providerName, String algorithm, byte[] input1, - byte[] result1, byte[] input2, byte[] result2) { - super(providerName); - this.input_1 = input1.clone(); - this.input_2 = input2.clone(); - this.result_1 = result1.clone(); - this.result_2 = result2.clone(); - this.digestAlg = algorithm; - - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testSHA() throws Exception { - MessageDigest md = MessageDigest.getInstance(digestAlg, providerName); + MessageDigest md = MessageDigest.getInstance(digestAlg, getProviderName()); MessageDigest[] mdCopies = new MessageDigest[numTimes]; for (int i = 0; i < numTimes; i++) { diff --git a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressXDH.java b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressXDH.java index 23366b8d..958664d7 100644 --- a/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressXDH.java +++ b/src/test/java/ibm/jceplus/junit/base/memstress/BaseTestMemStressXDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,6 +8,7 @@ package ibm.jceplus.junit.base.memstress; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.KeyPair; @@ -17,24 +18,18 @@ import java.security.spec.NamedParameterSpec; import java.util.Arrays; import javax.crypto.KeyAgreement; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertTrue; -public class BaseTestMemStressXDH extends ibm.jceplus.junit.base.BaseTest { +public class BaseTestMemStressXDH extends BaseTestJunit5 { /* This class by default tests "X25519" */ int numTimes = 100; boolean printheapstats = false; String curveName = "X25519"; - //"X448"; - public BaseTestMemStressXDH(String providerName) { - super(providerName); - } - - public BaseTestMemStressXDH(String providerName, String curveName) { - super(providerName); - this.curveName = curveName; - } - + @BeforeEach public void setUp() throws Exception { String numTimesStr = System.getProperty("com.ibm.jceplus.memstress.numtimes"); if (numTimesStr != null) { @@ -45,8 +40,7 @@ public void setUp() throws Exception { System.out.println("Testing XDH curveName=" + curveName); } - public void tearDown() throws Exception {} - + @Test public void testXDH() throws Exception { Runtime rt = Runtime.getRuntime(); @@ -86,7 +80,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) KeyPairGenerator kpgA = null; try { - kpgA = KeyPairGenerator.getInstance("XDH", providerName); + kpgA = KeyPairGenerator.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -107,7 +101,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) // set up KeyAgreement keyAgreeA = null; try { - keyAgreeA = KeyAgreement.getInstance("XDH", providerName); + keyAgreeA = KeyAgreement.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -125,7 +119,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) KeyPairGenerator kpgB = null; try { - kpgB = KeyPairGenerator.getInstance("XDH", providerName); + kpgB = KeyPairGenerator.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -149,7 +143,7 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) KeyAgreement keyAgreeB = null; try { - keyAgreeB = KeyAgreement.getInstance("XDH", providerName); + keyAgreeB = KeyAgreement.getInstance("XDH", getProviderName()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw e; @@ -188,7 +182,6 @@ void compute_xdh_key(String idString, NamedParameterSpec algParameterSpec) byte[] sharedSecretB = keyAgreeB.generateSecret(); assertTrue(Arrays.equals(sharedSecretA, sharedSecretB)); - } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES.java index 2cb38702..c87033e2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES.java @@ -1,52 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES extends ibm.jceplus.junit.base.BaseTestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAES() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestAES(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES256Interop.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES256Interop.java index b96d37df..c3dcf545 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES256Interop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES256Interop.java @@ -1,58 +1,26 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ -package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +package ibm.jceplus.junit.openjceplus; -public class TestAES256Interop extends ibm.jceplus.junit.base.BaseTestAESInterop { +import ibm.jceplus.junit.base.BaseTestAESInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; - //-------------------------------------------------------------------------- - // - // - static { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES256Interop extends BaseTestAESInterop { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderTestSuite(); - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 256; - - //-------------------------------------------------------------------------- - // - // - public TestAES256Interop() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE, KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES256Interop.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM.java index ca5ee0a9..ac08c3e2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCM; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCM extends ibm.jceplus.junit.base.BaseTestAESCCM { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCM extends BaseTestAESCCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM2.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM2.java index 16cca100..4b2d440f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCM2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCM2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCM2 extends ibm.jceplus.junit.base.BaseTestAESCCM2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCM2 extends BaseTestAESCCM2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCM2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCM2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMInteropBC.java index f7cdcadf..d88abcd6 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCMInteropBC; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCMInteropBC extends ibm.jceplus.junit.base.BaseTestAESCCMInteropBC { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCMInteropBC extends BaseTestAESCCMInteropBC { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCMInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCMInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMParameters.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMParameters.java index 32f0e449..d2488d30 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMParameters.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCCMParameters.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCMParameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCMParameters extends ibm.jceplus.junit.base.BaseTestAESCCMParameters { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCMParameters extends BaseTestAESCCMParameters { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCMParameters() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCMParameters.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCipherInputStreamExceptions.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCipherInputStreamExceptions.java index 36453b3f..57c5afef 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCipherInputStreamExceptions.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCipherInputStreamExceptions.java @@ -22,4 +22,3 @@ public void beforeAll() { setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCopySafe.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCopySafe.java index f951483b..3e4ba281 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCopySafe.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESCopySafe.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCopySafe; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCopySafe extends ibm.jceplus.junit.base.BaseTestAESCopySafe { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCopySafe extends BaseTestAESCopySafe { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCopySafe() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCopySafe.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM.java index 96d58b76..f8fc61d5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCM; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCM extends ibm.jceplus.junit.base.BaseTestAESGCM { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCM extends BaseTestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMBufferIV.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMBufferIV.java index 591646ee..390bad50 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMBufferIV.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMBufferIV.java @@ -1,31 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMBufferIV; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMBufferIV extends ibm.jceplus.junit.base.BaseTestAESGCMBufferIV { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMBufferIV extends BaseTestAESGCMBufferIV { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestAESGCMBufferIV() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMBufferIV.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCM.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCM.java index bf95033e..e6480406 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCM; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMCICOWithGCM extends ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCM { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMCICOWithGCM extends BaseTestAESGCMCICOWithGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMCICOWithGCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCMAndAAD.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCMAndAAD.java index 1b9b136f..3bafe9cd 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCMAndAAD.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMCICOWithGCMAndAAD.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMCICOWithGCMAndAAD - extends ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMCICOWithGCMAndAAD extends BaseTestAESGCMCICOWithGCMAndAAD { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCMAndAAD() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMCICOWithGCMAndAAD.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMLong.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMLong.java index 2d54ae95..2bd201bd 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMLong.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMLong.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMLong; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMLong extends ibm.jceplus.junit.base.BaseTestAESGCMLong { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMLong extends BaseTestAESGCMLong { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMLong() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMLong.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMNonExpanding.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMNonExpanding.java index f4c95ed7..458391d6 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMNonExpanding.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMNonExpanding.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMNonExpanding extends ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMNonExpanding extends BaseTestAESGCMNonExpanding { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMNonExpanding() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMNonExpanding.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMSameBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMSameBuffer.java index fbd87183..d07fac5f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMSameBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMSameBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMSameBuffer; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMSameBuffer extends ibm.jceplus.junit.base.BaseTestAESGCMSameBuffer { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMSameBuffer extends BaseTestAESGCMSameBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMSameBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMSameBuffer.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdate.java index 3b84b726..da91acef 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMUpdate; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMUpdate extends ibm.jceplus.junit.base.BaseTestAESGCMUpdate { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMUpdate extends BaseTestAESGCMUpdate { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdate() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdate(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMUpdate.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdateInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdateInteropBC.java index 5d54a15e..8fee727f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdateInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMUpdateInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,46 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMUpdateInteropBC; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMUpdateInteropBC - extends ibm.jceplus.junit.base.BaseTestAESGCMUpdateInteropBC { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMUpdateInteropBC extends BaseTestAESGCMUpdateInteropBC { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdateInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMUpdateInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithByteBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithByteBuffer.java index ee037b02..1b16f98e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMWithByteBuffer; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMWithByteBuffer extends ibm.jceplus.junit.base.BaseTestAESGCMWithByteBuffer { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMWithByteBuffer extends BaseTestAESGCMWithByteBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithByteBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMWithByteBuffer.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithKeyAndIvCheck.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithKeyAndIvCheck.java index 8002a18c..3d9fcfe1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithKeyAndIvCheck.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCMWithKeyAndIvCheck.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMWithKeyAndIvCheck - extends ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMWithKeyAndIvCheck extends BaseTestAESGCMWithKeyAndIvCheck { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithKeyAndIvCheck() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMWithKeyAndIvCheck.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_128.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_128.java index 42dff999..63fae5c2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_128.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_128 extends TestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_128() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_128.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_192.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_192.java index 12c48d9f..f321f230 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_192.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_192 extends TestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 192; - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_192() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_192.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_256.java index 443339f8..d7f40d62 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_256 extends TestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 256; - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_256() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_ExtIV.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_ExtIV.java index d2c7f74e..eef3cf15 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_ExtIV.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_ExtIV.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCM_ExtIV; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCM_ExtIV extends ibm.jceplus.junit.base.BaseTestAESGCM_ExtIV { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCM_ExtIV extends BaseTestAESGCM_ExtIV { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_ExtIV() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_ExtIV.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_IntIV.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_IntIV.java index 165c4807..ccec0393 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_IntIV.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAESGCM_IntIV.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCM_IntIV; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCM_IntIV extends ibm.jceplus.junit.base.BaseTestAESGCM_IntIV { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCM_IntIV extends BaseTestAESGCM_IntIV { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_IntIV() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_IntIV.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_128.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_128.java index 22795c4b..c1cc3a54 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_128.java @@ -1,50 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_128 extends TestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_128 extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - //-------------------------------------------------------------------------- - // - // - public TestAES_128() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES_128.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_192.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_192.java index 43b8b538..bdb0a83e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_192.java @@ -1,50 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_192 extends TestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_192 extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 192; - - //-------------------------------------------------------------------------- - // - // - public TestAES_192() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES_192.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_256.java index 4e0a31e8..1efe431b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAES_256.java @@ -1,50 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_256 extends TestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_256 extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 256; - - //-------------------------------------------------------------------------- - // - // - public TestAES_256() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAliases.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAliases.java index b60b5fea..0a1dec01 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAliases.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAliases.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,6 +8,7 @@ package ibm.jceplus.junit.openjceplus; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.KeyFactory; @@ -19,542 +20,377 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKeyFactory; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAliases extends ibm.jceplus.junit.base.BaseTest { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAliases extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void setUp() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestAliases() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_3DES() throws Exception { - AlgorithmParameters.getInstance("3DES", providerName); + AlgorithmParameters.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_AESGCM() throws Exception { - AlgorithmParameters.getInstance("AESGCM", providerName); + AlgorithmParameters.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParamGen_AESGCM() throws Exception { - AlgorithmParameterGenerator.getInstance("AESGCM", providerName); + AlgorithmParameterGenerator.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testCipher_3DES() throws Exception { - Cipher.getInstance("3DES", providerName); + Cipher.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyFactory_DSAKeyFactory() throws Exception { - KeyFactory.getInstance("DSAKeyFactory", providerName); + KeyFactory.getInstance("DSAKeyFactory", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_3DES() throws Exception { - KeyGenerator.getInstance("3DES", providerName); + KeyGenerator.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA1() throws Exception { - KeyGenerator.getInstance("HMACwithSHA1", providerName); + KeyGenerator.getInstance("HMACwithSHA1", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA224() throws Exception { - KeyGenerator.getInstance("HMACwithSHA224", providerName); + KeyGenerator.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA256() throws Exception { - KeyGenerator.getInstance("HMACwithSHA256", providerName); + KeyGenerator.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA384() throws Exception { - KeyGenerator.getInstance("HMACwithSHA384", providerName); + KeyGenerator.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA512() throws Exception { - KeyGenerator.getInstance("HMACwithSHA512", providerName); + KeyGenerator.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyPairGen_OID_1_3_14_3_2_12() throws Exception { - KeyPairGenerator.getInstance("OID.1.3.14.3.2.12", providerName); + KeyPairGenerator.getInstance("OID.1.3.14.3.2.12", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + //public void testKeyStore_PKCS12KS() throws Exception { - // KeyStore.getInstance("PKCS12KS", providerName); + // KeyStore.getInstance("PKCS12KS", getProviderName()); //} - - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA1() throws Exception { - Mac.getInstance("HMACwithSHA1", providerName); + Mac.getInstance("HMACwithSHA1", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA224() throws Exception { - Mac.getInstance("HMACwithSHA224", providerName); + Mac.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA256() throws Exception { - Mac.getInstance("HMACwithSHA256", providerName); + Mac.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA384() throws Exception { - Mac.getInstance("HMACwithSHA384", providerName); + Mac.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA512() throws Exception { - Mac.getInstance("HMACwithSHA512", providerName); + Mac.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA224() throws Exception { - MessageDigest.getInstance("SHA224", providerName); + MessageDigest.getInstance("SHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA2() throws Exception { - MessageDigest.getInstance("SHA2", providerName); + MessageDigest.getInstance("SHA2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_2() throws Exception { - MessageDigest.getInstance("SHA-2", providerName); + MessageDigest.getInstance("SHA-2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA256() throws Exception { - MessageDigest.getInstance("SHA256", providerName); + MessageDigest.getInstance("SHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA3() throws Exception { - MessageDigest.getInstance("SHA3", providerName); + MessageDigest.getInstance("SHA3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_3() throws Exception { - MessageDigest.getInstance("SHA-3", providerName); + MessageDigest.getInstance("SHA-3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA384() throws Exception { - MessageDigest.getInstance("SHA384", providerName); + MessageDigest.getInstance("SHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA5() throws Exception { - MessageDigest.getInstance("SHA5", providerName); + MessageDigest.getInstance("SHA5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_5() throws Exception { - MessageDigest.getInstance("SHA-5", providerName); + MessageDigest.getInstance("SHA-5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA512() throws Exception { - MessageDigest.getInstance("SHA512", providerName); + MessageDigest.getInstance("SHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecretKeyFactory_3DES() throws Exception { - SecretKeyFactory.getInstance("3DES", providerName); + SecretKeyFactory.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA2DRBG() throws Exception { - SecureRandom.getInstance("SHA2DRBG", providerName); + SecureRandom.getInstance("SHA2DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA5DRBG() throws Exception { - SecureRandom.getInstance("SHA5DRBG", providerName); + SecureRandom.getInstance("SHA5DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withDSA() throws Exception { - Signature.getInstance("SHA-1withDSA", providerName); + Signature.getInstance("SHA-1withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_DSA() throws Exception { - Signature.getInstance("SHA-1/DSA", providerName); + Signature.getInstance("SHA-1/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA1_DSA() throws Exception { - Signature.getInstance("SHA1/DSA", providerName); + Signature.getInstance("SHA1/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_DSA() throws Exception { - Signature.getInstance("SHA/DSA", providerName); + Signature.getInstance("SHA/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_DSS() throws Exception { - Signature.getInstance("DSS", providerName); + Signature.getInstance("DSS", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithDSA() throws Exception { - Signature.getInstance("SHAwithDSA", providerName); + Signature.getInstance("SHAwithDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_DSAWithSHA1() throws Exception { - Signature.getInstance("DSAWithSHA1", providerName); + Signature.getInstance("DSAWithSHA1", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_OID_1_3_14_3_2_13() throws Exception { - Signature.getInstance("OID.1.3.14.3.2.13", providerName); + Signature.getInstance("OID.1.3.14.3.2.13", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_OID_1_3_14_3_2_27() throws Exception { - Signature.getInstance("OID.1.3.14.3.2.27", providerName); + Signature.getInstance("OID.1.3.14.3.2.27", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_224withDSA() throws Exception { - Signature.getInstance("SHA-224withDSA", providerName); + Signature.getInstance("SHA-224withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_224_DSA() throws Exception { - Signature.getInstance("SHA-224/DSA", providerName); + Signature.getInstance("SHA-224/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_DSA() throws Exception { - Signature.getInstance("SHA224/DSA", providerName); + Signature.getInstance("SHA224/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withDSA() throws Exception { - Signature.getInstance("SHA2withDSA", providerName); + Signature.getInstance("SHA2withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_2withDSA() throws Exception { - Signature.getInstance("SHA-2withDSA", providerName); + Signature.getInstance("SHA-2withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_256withDSA() throws Exception { - Signature.getInstance("SHA-256withDSA", providerName); + Signature.getInstance("SHA-256withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_2_DSA() throws Exception { - Signature.getInstance("SHA-2/DSA", providerName); + Signature.getInstance("SHA-2/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_DSA() throws Exception { - Signature.getInstance("SHA2/DSA", providerName); + Signature.getInstance("SHA2/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithECDSA() throws Exception { - Signature.getInstance("SHAwithECDSA", providerName); + Signature.getInstance("SHAwithECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withECDSA() throws Exception { - Signature.getInstance("SHA-1withECDSA", providerName); + Signature.getInstance("SHA-1withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_ECDSA() throws Exception { - Signature.getInstance("SHA/ECDSA", providerName); + Signature.getInstance("SHA/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_ECDSA() throws Exception { - Signature.getInstance("SHA-1/ECDSA", providerName); + Signature.getInstance("SHA-1/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_ECDSA() throws Exception { - Signature.getInstance("SHA224/ECDSA", providerName); + Signature.getInstance("SHA224/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withECDSA() throws Exception { - Signature.getInstance("SHA2withECDSA", providerName); + Signature.getInstance("SHA2withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_ECDSA() throws Exception { - Signature.getInstance("SHA2/ECDSA", providerName); + Signature.getInstance("SHA2/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withECDSA() throws Exception { - Signature.getInstance("SHA3withECDSA", providerName); + Signature.getInstance("SHA3withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_ECDSA() throws Exception { - Signature.getInstance("SHA3/ECDSA", providerName); + Signature.getInstance("SHA3/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withECDSA() throws Exception { - Signature.getInstance("SHA5withECDSA", providerName); + Signature.getInstance("SHA5withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_ECDSA() throws Exception { - Signature.getInstance("SHA5/ECDSA", providerName); + Signature.getInstance("SHA5/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withRSA() throws Exception { - Signature.getInstance("SHA-1withRSA", providerName); + Signature.getInstance("SHA-1withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithRSA() throws Exception { - Signature.getInstance("SHAwithRSA", providerName); + Signature.getInstance("SHAwithRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_RSA() throws Exception { - Signature.getInstance("SHA-1/RSA", providerName); + Signature.getInstance("SHA-1/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA1_RSA() throws Exception { - Signature.getInstance("SHA1/RSA", providerName); + Signature.getInstance("SHA1/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_RSA() throws Exception { - Signature.getInstance("SHA/RSA", providerName); + Signature.getInstance("SHA/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_RSA() throws Exception { - Signature.getInstance("RSA", providerName); + Signature.getInstance("RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_RSA() throws Exception { - Signature.getInstance("SHA224/RSA", providerName); + Signature.getInstance("SHA224/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withRSA() throws Exception { - Signature.getInstance("SHA2withRSA", providerName); + Signature.getInstance("SHA2withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_RSA() throws Exception { - Signature.getInstance("SHA2/RSA", providerName); + Signature.getInstance("SHA2/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withRSA() throws Exception { - Signature.getInstance("SHA3withRSA", providerName); + Signature.getInstance("SHA3withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_RSA() throws Exception { - Signature.getInstance("SHA3/RSA", providerName); + Signature.getInstance("SHA3/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withRSA() throws Exception { - Signature.getInstance("SHA5withRSA", providerName); + Signature.getInstance("SHA5withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_RSA() throws Exception { - Signature.getInstance("SHA5/RSA", providerName); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAliases.class); - return suite; + Signature.getInstance("SHA5/RSA", getProviderName()); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java index 401d6ba4..888aa3fd 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestAll.java @@ -11,40 +11,126 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; -@SelectClasses({TestAES.class, TestAES_128.class, TestAES256Interop.class, TestAESCCM.class, - TestAESCCM2.class, TestAESCCMParameters.class, TestAESCCMInteropBC.class, TestAESGCM.class, - TestAESGCMUpdate.class, TestAESGCMUpdateInteropBC.class, TestAESGCM_128.class, - TestAESGCM_ExtIV.class, TestAESGCM_IntIV.class, TestAESCipherInputStreamExceptions.class, - TestAESCopySafe.class, TestAESGCMNonExpanding.class, TestAESGCMSameBuffer.class, - TestAESGCMWithByteBuffer.class, TestAESGCMCICOWithGCM.class, - TestAESGCMCICOWithGCMAndAAD.class, TestAESGCMLong.class, TestAESGCMBufferIV.class, - TestAliases.class, TestByteArrayOutputDelay.class, TestChaCha20.class, - TestChaCha20KAT.class, TestChaCha20NoReuse.class, TestChaCha20Poly1305.class, - TestChaCha20Poly1305ByteBuffer.class, TestChaCha20Poly1305ChunkUpdate.class, - TestDESede.class, TestDHKeyPairGenerator.class, TestDH.class, TestDHMultiParty.class, - TestDHInteropSunJCE.class, TestDHKeyFactory.class, TestDSAKey.class, TestDSASignature.class, - TestDSASignatureInteropSUN.class, TestDSASignatureInteropBC.class, TestECDH.class, - TestECDHInteropSunEC.class, TestECDHKeyAgreementParamValidation.class, TestECDHMultiParty.class, - TestECDSASignature.class, TestECDSASignatureInteropSunEC.class, TestECDSASignatureInteropBC.class, - TestECKeyImport.class, TestECKeyImportInteropSunEC.class, TestECKeyPairGenerator.class, - TestHKDF.class, TestHKDFInterop.class, TestHmacMD5.class, TestHmacMD5InteropSunJCE.class, - TestHmacSHA1.class, TestHmacSHA1InteropSunJCE.class, TestHmacSHA224.class, - TestHmacSHA224InteropSunJCE.class, TestHmacSHA256.class, TestHmacSHA256InteropSunJCE.class, - TestHmacSHA384.class, TestHmacSHA384InteropSunJCE.class, TestHmacSHA512.class, - TestHmacSHA512InteropSunJCE.class, TestHmacSHA3_224.class, TestHmacSHA3_256.class, - TestHmacSHA3_384.class, TestHmacSHA3_512.class, TestImplementationClassesExist.class, - TestImplementationClassesFinal.class, TestMD5.class, - TestInvalidArrayIndex.class, TestPublicMethodsToMakeNonPublic.class, TestResetByteBuffer.class, TestRSA.class, - TestRSA_512.class, TestRSA_1024.class, TestRSA_2048.class, TestRSAKey.class, TestRSAPSS.class, - TestRSAPSSInterop.class, TestRSAPSS2.class, TestMiniRSAPSS2.class, TestRSAPSSInterop2.class, - TestRSAPSSInterop3.class, TestRSASignature.class, TestRSASignatureInteropSunRsaSign.class, - TestRSASignatureChunkUpdate.class, TestRSATypeCheckDefault.class, TestSHA1.class, - TestSHA224.class, TestSHA256.class, TestSHA384.class, TestSHA512.class, - TestSHA512_224.class, TestSHA512_256.class, TestSHA3_224.class, TestSHA3_256.class, - TestSHA3_384.class, TestSHA3_512.class, TestRSAKeyInterop.class, TestRSAKeyInteropBC.class, - TestEdDSASignature.class, TestEdDSASignatureInterop.class, TestXDH.class, - TestXDHInterop.class, TestXDHInteropBC.class, TestXDHMultiParty.class, TestXDHKeyPairGenerator.class, - TestXDHKeyImport.class, TestIsAssignableFromOrder.class}) +@SelectClasses({ + TestAES_128.class, + TestAES_192.class, + TestAES_256.class, + TestAES.class, + TestAES256Interop.class, + TestAESCCM.class, + TestAESCCM2.class, + TestAESCCMInteropBC.class, + TestAESCCMParameters.class, + TestAESCipherInputStreamExceptions.class, + TestAESCopySafe.class, + TestAESGCM_128.class, + TestAESGCM_192.class, + TestAESGCM_256.class, + TestAESGCM_ExtIV.class, + TestAESGCM_IntIV.class, + TestAESGCM.class, + TestAESGCMBufferIV.class, + TestAESGCMCICOWithGCM.class, + TestAESGCMCICOWithGCMAndAAD.class, + TestAESGCMLong.class, + TestAESGCMNonExpanding.class, + TestAESGCMSameBuffer.class, + TestAESGCMUpdate.class, + TestAESGCMUpdateInteropBC.class, + TestAESGCMWithByteBuffer.class, + TestAliases.class, + TestByteArrayOutputDelay.class, + TestChaCha20.class, + TestChaCha20KAT.class, + TestChaCha20NoReuse.class, + TestChaCha20Poly1305.class, + TestChaCha20Poly1305ByteBuffer.class, + TestChaCha20Poly1305ChunkUpdate.class, + TestDESede.class, + TestDH.class, + TestDHInteropSunJCE.class, + TestDHKeyFactory.class, + TestDHKeyPairGenerator.class, + TestDHMultiParty.class, + TestDSAKey.class, + TestDSASignature.class, + TestDSASignatureInteropBC.class, + TestDSASignatureInteropSUN.class, + TestECDH.class, + TestECDHInteropBC.class, + TestECDHInteropSunEC.class, + TestECDHKeyAgreementParamValidation.class, + TestECDHMultiParty.class, + TestECDSASignature.class, + TestECDSASignatureInteropBC.class, + TestECDSASignatureInteropSunEC.class, + TestECKeyImport.class, + TestECKeyImportInteropSunEC.class, + TestECKeyPairGenerator.class, + TestEdDSASignature.class, + TestEdDSASignatureInterop.class, + TestHKDF.class, + TestHKDFInterop.class, + TestHmacMD5.class, + TestHmacMD5InteropSunJCE.class, + TestHmacSHA1.class, + TestHmacSHA1InteropSunJCE.class, + TestHmacSHA224.class, + TestHmacSHA224InteropSunJCE.class, + TestHmacSHA256.class, + TestHmacSHA256InteropSunJCE.class, + TestHmacSHA3_224.class, + TestHmacSHA3_256.class, + TestHmacSHA3_384.class, + TestHmacSHA3_512.class, + TestHmacSHA384.class, + TestHmacSHA384InteropSunJCE.class, + TestHmacSHA512.class, + TestHmacSHA512InteropSunJCE.class, + TestImplementationClassesExist.class, + TestImplementationClassesFinal.class, + TestInvalidArrayIndex.class, + TestIsAssignableFromOrder.class, + TestMD5.class, + TestMiniRSAPSS2.class, + TestPublicMethodsToMakeNonPublic.class, + TestResetByteBuffer.class, + TestRSA_1024.class, + TestRSA_2048.class, + TestRSA_4096.class, + TestRSA_512.class, + TestRSA.class, + TestRSAKey.class, + TestRSAKeyInterop.class, + TestRSAKeyInteropBC.class, + TestRSAPSS.class, + TestRSAPSS2.class, + TestRSAPSSInterop.class, + TestRSAPSSInterop2.class, + TestRSAPSSInterop3.class, + TestRSASignature.class, + TestRSASignatureChunkUpdate.class, + TestRSASignatureInteropSunRsaSign.class, + TestRSATypeCheckDefault.class, + TestRSATypeCheckEnabled.class, + TestSHA1.class, + TestSHA224.class, + TestSHA256.class, + TestSHA3_224.class, + TestSHA3_256.class, + TestSHA3_384.class, + TestSHA3_512.class, + TestSHA384.class, + TestSHA512_224.class, + TestSHA512_256.class, + TestSHA512.class, + TestXDH.class, + TestXDHInterop.class, + TestXDHInteropBC.class, + TestXDHKeyImport.class, + TestXDHKeyPairGenerator.class, + TestXDHMultiParty.class +}) @Suite public class TestAll { diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestByteArrayOutputDelay.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestByteArrayOutputDelay.java index 176e8f8d..6aaf4109 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestByteArrayOutputDelay.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestByteArrayOutputDelay.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import java.io.IOException; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseByteArrayOutputDelayTest; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestByteArrayOutputDelay extends ibm.jceplus.junit.base.BaseByteArrayOutputDelayTest { +@TestInstance(Lifecycle.PER_CLASS) +public class TestByteArrayOutputDelay extends BaseByteArrayOutputDelayTest { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestByteArrayOutputDelay() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws IOException { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestByteArrayOutputDelay.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20.java index 082c3b5a..53aeb6e5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20 extends ibm.jceplus.junit.base.BaseTestChaCha20 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20 extends BaseTestChaCha20 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestChaCha20() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestChaCha20.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20KAT.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20KAT.java index f5aa45ea..7803082b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20KAT.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20KAT.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20KAT extends ibm.jceplus.junit.base.BaseTestChaCha20KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20KAT extends BaseTestChaCha20KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestChaCha20KAT() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestChaCha20KAT.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20NoReuse.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20NoReuse.java index 64d4be44..0a45279f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20NoReuse.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20NoReuse.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20NoReuse; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20NoReuse extends ibm.jceplus.junit.base.BaseTestChaCha20NoReuse { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20NoReuse extends BaseTestChaCha20NoReuse { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestChaCha20NoReuse() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestChaCha20NoReuse.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305.java index 78c8b25c..9bb742da 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20Poly1305; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20Poly1305 extends ibm.jceplus.junit.base.BaseTestChaCha20Poly1305 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20Poly1305 extends BaseTestChaCha20Poly1305 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestChaCha20Poly1305() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestChaCha20Poly1305.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ByteBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ByteBuffer.java index 20c4150a..54a0a1df 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20Poly1305ByteBuffer; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20Poly1305ByteBuffer - extends ibm.jceplus.junit.base.BaseTestChaCha20Poly1305ByteBuffer { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20Poly1305ByteBuffer extends BaseTestChaCha20Poly1305ByteBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestChaCha20Poly1305ByteBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestChaCha20Poly1305ByteBuffer.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ChunkUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ChunkUpdate.java index 7fbe74d1..7906fdeb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ChunkUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestChaCha20Poly1305ChunkUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,27 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20Poly1305ChunkUpdate; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20Poly1305ChunkUpdate - extends ibm.jceplus.junit.base.BaseTestChaCha20Poly1305ChunkUpdate { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20Poly1305ChunkUpdate extends BaseTestChaCha20Poly1305ChunkUpdate { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestChaCha20Poly1305ChunkUpdate() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - TestSuite suite = new TestSuite( - ibm.jceplus.junit.openjceplus.TestChaCha20Poly1305ChunkUpdate.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDESede.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDESede.java index 865f559e..d808c50f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDESede.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDESede.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,44 +8,24 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDESede; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDESede extends ibm.jceplus.junit.base.BaseTestDESede { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDESede extends BaseTestDESede { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestDESede() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDESede.class); - return suite; - } - - // -------------------------------------------------------------------------- - // This method is to check whether a mode is valid for the cipher - // but not supported by a given provider. - // + /** + * This method is to check whether a mode is valid for the cipher + * but not supported by a given provider. + */ @Override public boolean isModeValidButUnsupported(String mode) { if (mode.equalsIgnoreCase("CFB") || mode.equalsIgnoreCase("CFB64") @@ -56,4 +36,3 @@ public boolean isModeValidButUnsupported(String mode) { return super.isModeValidButUnsupported(mode); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDH.java index 45b16746..3853f8d8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDH; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDH extends ibm.jceplus.junit.base.BaseTestDH { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDH extends BaseTestDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDH.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHInteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHInteropSunJCE.java index acab0d24..e702210d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHInteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHInteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHInteropSunJCE extends ibm.jceplus.junit.base.BaseTestDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHInteropSunJCE extends BaseTestDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHInteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHInteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); + setKeySize(4096); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyFactory.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyFactory.java index fdc90a6e..b374cc8b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHKeyFactory; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHKeyFactory extends ibm.jceplus.junit.base.BaseTestDHKeyFactory { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHKeyFactory extends BaseTestDHKeyFactory { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHKeyFactory() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHKeyFactory.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyPairGenerator.java index 42583335..6f1abe4d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHKeyPairGenerator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHKeyPairGenerator extends ibm.jceplus.junit.base.BaseTestDHKeyPairGenerator { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHKeyPairGenerator extends BaseTestDHKeyPairGenerator { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHKeyPairGenerator() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHKeyPairGenerator.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHMultiParty.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHMultiParty.java index ac6b605c..c895ddf9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHMultiParty; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHMultiParty extends ibm.jceplus.junit.base.BaseTestDHMultiParty { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHMultiParty extends BaseTestDHMultiParty { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHMultiParty() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHMultiParty.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSAKey.java index 0a351a4b..1a624b37 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSAKey.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDSAKey; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDSAKey extends ibm.jceplus.junit.base.BaseTestDSAKey { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDSAKey extends BaseTestDSAKey { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDSAKey.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignature.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignature.java index 47f6a601..d083e371 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignature.java @@ -7,6 +7,7 @@ */ package ibm.jceplus.junit.openjceplus; + import ibm.jceplus.junit.base.BaseTestDSASignature; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropBC.java index 4f6a5136..ecc19a5f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDSASignatureInterop2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDSASignatureInteropBC extends ibm.jceplus.junit.base.BaseTestDSASignatureInterop2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDSASignatureInteropBC extends BaseTestDSASignatureInterop2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestDSASignatureInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDSASignatureInteropBC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropSUN.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropSUN.java index 072db119..bca43672 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropSUN.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestDSASignatureInteropSUN.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDSASignatureInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDSASignatureInteropSUN extends ibm.jceplus.junit.base.BaseTestDSASignatureInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDSASignatureInteropSUN extends BaseTestDSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDSASignatureInteropSUN() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SUN); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDSASignatureInteropSUN.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SUN); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDH.java index a3f9aca8..2b4e152e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDH; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDH extends ibm.jceplus.junit.base.BaseTestECDH { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDH extends BaseTestECDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDH.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropBC.java index 81fb7383..f1a93530 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDHInteropBC extends ibm.jceplus.junit.base.BaseTestECDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDHInteropBC extends BaseTestECDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDHInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropSunEC.java index 2724cf80..c25e4512 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDHInteropSunEC extends ibm.jceplus.junit.base.BaseTestECDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDHInteropSunEC extends BaseTestECDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDHInteropSunEC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHMultiParty.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHMultiParty.java index f2ba5c2b..0899b2e6 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDHMultiParty; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDHMultiParty extends ibm.jceplus.junit.base.BaseTestECDHMultiParty { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDHMultiParty extends BaseTestECDHMultiParty { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHMultiParty() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDHMultiParty.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropBC.java index f512b310..b36540db 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,46 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDSASignatureInterop2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDSASignatureInteropBC - extends ibm.jceplus.junit.base.BaseTestECDSASignatureInterop2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDSASignatureInteropBC extends BaseTestECDSASignatureInterop2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestECDSASignatureInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDSASignatureInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropSunEC.java index b6604b64..5cb68eba 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECDSASignatureInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDSASignatureInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDSASignatureInteropSunEC - extends ibm.jceplus.junit.base.BaseTestECDSASignatureInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDSASignatureInteropSunEC extends BaseTestECDSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDSASignatureInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDSASignatureInteropSunEC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImport.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImport.java index 1e82e827..96fb0643 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImport.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImport.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECKeyImport; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECKeyImport extends ibm.jceplus.junit.base.BaseTestECKeyImport { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECKeyImport extends BaseTestECKeyImport { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECKeyImport() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECKeyImport.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImportInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImportInteropSunEC.java index 29984b8e..9265a59d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImportInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyImportInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECKeyImportInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECKeyImportInteropSunEC extends ibm.jceplus.junit.base.BaseTestECKeyImportInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECKeyImportInteropSunEC extends BaseTestECKeyImportInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECKeyImportInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECKeyImportInteropSunEC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyPairGenerator.java index 21c61a11..5b2122f7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestECKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECKeyPairGenerator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECKeyPairGenerator extends ibm.jceplus.junit.base.BaseTestECKeyPairGenerator { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECKeyPairGenerator extends BaseTestECKeyPairGenerator { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECKeyPairGenerator() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECKeyPairGenerator.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestEdDSASignature.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestEdDSASignature.java index 1eadb214..26f691f1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestEdDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestEdDSASignature.java @@ -14,6 +14,7 @@ @TestInstance(Lifecycle.PER_CLASS) public class TestEdDSASignature extends BaseTestEdDSASignature { + @BeforeAll public void beforeAll() { Utils.loadProviderTestSuite(); diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDF.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDF.java index 07d6ac8c..5a0d9873 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDF.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHKDF; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHKDF extends ibm.jceplus.junit.base.BaseTestHKDF { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHKDF extends BaseTestHKDF { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHKDF() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHKDF.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDFInterop.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDFInterop.java index 6cb47810..e3244d09 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDFInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHKDFInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHKDFInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHKDFInterop extends ibm.jceplus.junit.base.BaseTestHKDFInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHKDFInterop extends BaseTestHKDFInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestHKDFInterop() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHKDFInterop.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5.java index 7abe621b..d5ccca57 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacMD5; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacMD5 extends ibm.jceplus.junit.base.BaseTestHmacMD5 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacMD5 extends BaseTestHmacMD5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacMD5.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5InteropSunJCE.java index b7037811..bdec53a2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacMD5InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacMD5Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacMD5InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacMD5Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacMD5InteropSunJCE extends BaseTestHmacMD5Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacMD5InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1.java index f073d569..bb5cbfba 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA1; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA1 extends ibm.jceplus.junit.base.BaseTestHmacSHA1 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA1 extends BaseTestHmacSHA1 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA1() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA1.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1InteropSunJCE.java index ae69c6ab..7934ba47 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA1InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA1Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA1InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA1Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA1InteropSunJCE extends BaseTestHmacSHA1Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA1InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA1InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224.java index e889768e..7b47a164 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA224 extends ibm.jceplus.junit.base.BaseTestHmacSHA224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA224 extends BaseTestHmacSHA224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224InteropSunJCE.java index ddb1d781..f37dcd3d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA224InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA224Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA224InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA224Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA224InteropSunJCE extends BaseTestHmacSHA224Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA224InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA224InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256.java index 827fa9cd..6023bdbb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA256 extends ibm.jceplus.junit.base.BaseTestHmacSHA256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA256 extends BaseTestHmacSHA256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256InteropSunJCE.java index 182d5a4c..7236bbc9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA256InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA256Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA256InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA256Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA256InteropSunJCE extends BaseTestHmacSHA256Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA256InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384.java index a96eb3dd..6497ad01 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA384; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA384 extends ibm.jceplus.junit.base.BaseTestHmacSHA384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA384 extends BaseTestHmacSHA384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384InteropSunJCE.java index eb8a2bdd..1d5000ae 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA384InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA384Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA384InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA384Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA384InteropSunJCE extends BaseTestHmacSHA384Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA384InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA384InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_224.java index 8b093507..b2885376 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_224 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_224 extends BaseTestHmacSHA3_224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_256.java index 20ea82de..0f7b4412 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_256 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_256 extends BaseTestHmacSHA3_256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_384.java index c70f1ace..a7a3a0d9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_384; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_384 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_384 extends BaseTestHmacSHA3_384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_512.java index 4310591b..9c0a844d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA3_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_512; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_512 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_512 extends BaseTestHmacSHA3_512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512.java index dac18415..3b07dad7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA512; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA512 extends ibm.jceplus.junit.base.BaseTestHmacSHA512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA512 extends BaseTestHmacSHA512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512InteropSunJCE.java index c6f44313..9f7a93fb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestHmacSHA512InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA512Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA512InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA512Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA512InteropSunJCE extends BaseTestHmacSHA512Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA512InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA512InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesExist.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesExist.java index c67237f8..e40b2818 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesExist.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesExist.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestImplementationClassesExist; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestImplementationClassesExist - extends ibm.jceplus.junit.base.BaseTestImplementationClassesExist { +@TestInstance(Lifecycle.PER_CLASS) +public class TestImplementationClassesExist extends BaseTestImplementationClassesExist { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestImplementationClassesExist() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestImplementationClassesExist.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesFinal.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesFinal.java index b743573f..ffb78033 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesFinal.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestImplementationClassesFinal.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestImplementationClassesFinal; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestImplementationClassesFinal - extends ibm.jceplus.junit.base.BaseTestImplementationClassesFinal { +@TestInstance(Lifecycle.PER_CLASS) +public class TestImplementationClassesFinal extends BaseTestImplementationClassesFinal { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestImplementationClassesFinal() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestImplementationClassesFinal.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestInvalidArrayIndex.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestInvalidArrayIndex.java index f9808761..af6f341a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestInvalidArrayIndex.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestInvalidArrayIndex.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestInvalidArrayIndex; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestInvalidArrayIndex extends ibm.jceplus.junit.base.BaseTestInvalidArrayIndex { +@TestInstance(Lifecycle.PER_CLASS) +public class TestInvalidArrayIndex extends BaseTestInvalidArrayIndex { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestInvalidArrayIndex() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestInvalidArrayIndex.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestIsAssignableFromOrder.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestIsAssignableFromOrder.java index 8a207cbb..87ea82d0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestIsAssignableFromOrder.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestIsAssignableFromOrder.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2024 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestIsAssignableFromOrder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestIsAssignableFromOrder extends ibm.jceplus.junit.base.BaseTestIsAssignableFromOrder { +@TestInstance(Lifecycle.PER_CLASS) +public class TestIsAssignableFromOrder extends BaseTestIsAssignableFromOrder { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - public TestIsAssignableFromOrder() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - // -------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestIsAssignableFromOrder.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestMD5.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestMD5.java index 35b077bf..eb2edfca 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestMD5; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestMD5 extends ibm.jceplus.junit.base.BaseTestMD5 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestMD5 extends BaseTestMD5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMD5() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMD5.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("MD5"); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestMiniRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestMiniRSAPSS2.java index 0c710bdf..de59d3be 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestMiniRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestMiniRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestMiniRSAPSS2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestMiniRSAPSS2 extends ibm.jceplus.junit.base.BaseTestMiniRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestMiniRSAPSS2 extends BaseTestMiniRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMiniRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - // -------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMiniRSAPSS2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestPublicMethodsToMakeNonPublic.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestPublicMethodsToMakeNonPublic.java index d4d9eef9..181903a9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestPublicMethodsToMakeNonPublic.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestPublicMethodsToMakeNonPublic.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,47 +8,22 @@ package ibm.jceplus.junit.openjceplus; +import ibm.jceplus.junit.base.BaseTestPublicMethodsToMakeNonPublic; import java.lang.reflect.Method; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestPublicMethodsToMakeNonPublic - extends ibm.jceplus.junit.base.BaseTestPublicMethodsToMakeNonPublic { +@TestInstance(Lifecycle.PER_CLASS) +public class TestPublicMethodsToMakeNonPublic extends BaseTestPublicMethodsToMakeNonPublic { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestPublicMethodsToMakeNonPublic() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // public boolean isMethodMeantToBePublicAndExplicitlyCallableByUsers(Method method) { return false; } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestPublicMethodsToMakeNonPublic.class); - return suite; - } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA.java index 1b019f37..85cb6851 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA extends ibm.jceplus.junit.base.BaseTestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSA() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSA(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKey.java index 3a59e9f4..eb0378bc 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKey.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAKey; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAKey extends ibm.jceplus.junit.base.BaseTestRSAKey { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAKey extends BaseTestRSAKey { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAKey.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInterop.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInterop.java index 4dbe8743..96034738 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,54 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAKeyInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAKeyInterop extends ibm.jceplus.junit.base.BaseTestRSAKeyInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAKeyInterop extends BaseTestRSAKeyInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); + setKeySize(1024); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInterop() { - //super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_IBMJCE); // Invalid - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign); // Passed - //super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_OpenJCEPlus); // Passed - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInterop(int keySize) throws Exception { - //super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_IBMJCE, keySize); - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign, keySize); // Passed - //super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_OpenJCEPlus, keySize); // Passed - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAKeyInterop.class); - return suite; - } - - // -------------------------------------------------------------------------- - // This method is to check whether an algorithm is valid for the cipher - // but not supported by a given provider. - // } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInteropBC.java index d81077f5..fd9afe88 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAKeyInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,57 +8,20 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAKeyInteropBC; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAKeyInteropBC extends ibm.jceplus.junit.base.BaseTestRSAKeyInteropBC { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAKeyInteropBC extends BaseTestRSAKeyInteropBC { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInteropBC(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAKeyInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); + setKeySize(1024); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS.java index cbd83ed7..e00dfe06 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSS; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS extends ibm.jceplus.junit.base.BaseTestRSAPSS { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS extends BaseTestRSAPSS { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSS.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS2.java index 44ac6250..a92284d0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSS2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS2 extends ibm.jceplus.junit.base.BaseTestRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS2 extends BaseTestRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSS2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop.java index 52d42276..f205ecef 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSSInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop extends BaseTestRSAPSSInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop() { - //super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - super(Utils.TEST_SUITE_PROVIDER_NAME, "SunRsaSign"); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSSInterop.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop2.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop2.java index 8bd178ef..75ba09c5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSSInterop2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop2 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop2 extends BaseTestRSAPSSInterop2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSSInterop2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop3.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop3.java index 383745a0..f7427f14 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop3.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSAPSSInterop3.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSSInterop3; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop3 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop3 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop3 extends BaseTestRSAPSSInterop3 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop3() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSSInterop3.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSASignatureInteropSunRsaSign.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSASignatureInteropSunRsaSign.java index aad19bfb..d83a738b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSASignatureInteropSunRsaSign.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSASignatureInteropSunRsaSign.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSASignatureInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSASignatureInteropSunRsaSign - extends ibm.jceplus.junit.base.BaseTestRSASignatureInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSASignatureInteropSunRsaSign extends BaseTestRSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSASignatureInteropSunRsaSign() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSASignatureInteropSunRsaSign.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); + setKeySize(1024); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDefault.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDefault.java index 66e94f09..f09b87e1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDefault.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDefault.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -// If not specified, the default RSA type check value is enabled -// -public class TestRSATypeCheckDefault extends ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSATypeCheckDefault extends BaseTestRSATypeCheckEnabled { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSATypeCheckDefault() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSATypeCheckDefault.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDisabled.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDisabled.java index bf467dde..e82fdcf9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDisabled.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckDisabled.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,50 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSATypeCheckDisabled; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -/** - * - * This test should not be included in the TestAll test suite and should be - * run as a standalone testcase. This testcase sets a System property to - * modify the behavior of the OpenJCEPlus provider. This - * property value is read by the provider once during static initialization. - */ -public class TestRSATypeCheckDisabled extends ibm.jceplus.junit.base.BaseTestRSATypeCheckDisabled { - //-------------------------------------------------------------------------- - // - // - static { - try { - System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "false"); - } catch (Throwable t) { - t.printStackTrace(System.out); - } +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSATypeCheckDisabled extends BaseTestRSATypeCheckDisabled { + @BeforeAll + public void beforeAll() { + System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "false"); Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSATypeCheckDisabled() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSATypeCheckDisabled.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckEnabled.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckEnabled.java index 04f0fd9c..cc8ea9f2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckEnabled.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSATypeCheckEnabled.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,50 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -/** - * - * This test should not be included in the TestAll test suite and should be - * run as a standalone testcase. This testcase sets a System property to - * modify the behavior of the OpenJCEPlus provider. This - * property value is read by the provider once during static initialization. - */ -public class TestRSATypeCheckEnabled extends ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled { - //-------------------------------------------------------------------------- - // - // - static { - try { - System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "true"); - } catch (Throwable t) { - t.printStackTrace(System.out); - } +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSATypeCheckEnabled extends BaseTestRSATypeCheckEnabled { + @BeforeAll + public void beforeAll() { + System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "true"); Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSATypeCheckEnabled() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSATypeCheckEnabled.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_1024.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_1024.java index 866829f6..02540b6b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_1024.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_1024.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_1024 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_1024 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 1024; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_1024() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_1024.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(1024); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_2048.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_2048.java index 24c3bac8..aeaa9011 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_2048.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_2048.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_2048 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_2048 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 2048; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_2048() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_2048.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_4096.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_4096.java index 30d46741..b0edb718 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_4096.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_4096.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_4096 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_4096 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 4096; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_4096() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_4096.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(4096); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_512.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_512.java index 822535ee..f3fb74a5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestRSA_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_512 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_512 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 512; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_512() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(512); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA1.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA1.java index cfb3c4bc..793d8e16 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA1.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA1; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA1 extends ibm.jceplus.junit.base.BaseTestSHA1 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA1 extends BaseTestSHA1 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA1() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA1.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA224.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA224.java index bfff1937..4c47db95 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA224 extends ibm.jceplus.junit.base.BaseTestSHA224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA224 extends BaseTestSHA224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA256.java index 8f1ca297..8ff76366 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA256 extends ibm.jceplus.junit.base.BaseTestSHA256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA256 extends BaseTestSHA256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA384.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA384.java index ebfe8ab5..b685f835 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA384; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA384 extends ibm.jceplus.junit.base.BaseTestSHA384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA384 extends BaseTestSHA384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_224.java index 31fcd093..79495b32 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_224.java @@ -1,45 +1,23 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_224KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_224 extends ibm.jceplus.junit.base.BaseTestSHA3_224KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_224 extends BaseTestSHA3_224KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_256.java index 717d4c36..d0590d51 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_256KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_256 extends ibm.jceplus.junit.base.BaseTestSHA3_256KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_256 extends BaseTestSHA3_256KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_384.java index 80893418..a8fe3bb8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_384KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_384 extends ibm.jceplus.junit.base.BaseTestSHA3_384KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_384 extends BaseTestSHA3_384KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_512.java index 963faf42..493958cb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA3_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_512KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_512 extends ibm.jceplus.junit.base.BaseTestSHA3_512KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_512 extends BaseTestSHA3_512KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512.java index dc619625..8662aac4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA512; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA512 extends ibm.jceplus.junit.base.BaseTestSHA512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA512 extends BaseTestSHA512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_224.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_224.java index 1354b3ff..92ce25c8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA512_224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA512_224 extends ibm.jceplus.junit.base.BaseTestSHA512_224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA512_224 extends BaseTestSHA512_224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA512_224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_256.java index c09417d3..6baeddd9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestSHA512_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA512_256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA512_256 extends ibm.jceplus.junit.base.BaseTestSHA512_256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA512_256 extends BaseTestSHA512_256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA512_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestTruncatedDigest.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestTruncatedDigest.java index 573c4a60..dd7fc747 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestTruncatedDigest.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestTruncatedDigest.java @@ -14,6 +14,7 @@ @TestInstance(Lifecycle.PER_CLASS) public class TestTruncatedDigest extends BaseTestTruncatedDigest { + @BeforeAll public void beforeAll() { Utils.loadProviderTestSuite(); diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDH.java index 4864f9b2..91e4becb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestXDH; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDH extends ibm.jceplus.junit.base.BaseTestXDH { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDH extends BaseTestXDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestXDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestXDH.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInterop.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInterop.java index 86c4e192..e5b3b889 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestXDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHInterop extends ibm.jceplus.junit.base.BaseTestXDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHInterop extends BaseTestXDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestXDHInterop() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestXDHInterop.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInteropBC.java index 90285097..16a81338 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,44 +8,19 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestXDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHInteropBC extends ibm.jceplus.junit.base.BaseTestXDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHInteropBC extends BaseTestXDHInterop { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - // -------------------------------------------------------------------------- - // - // - public TestXDHInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - // -------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestXDHInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyImport.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyImport.java index ea09e2ae..6ed09e76 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyImport.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyImport.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestXDHKeyImport; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHKeyImport extends ibm.jceplus.junit.base.BaseTestXDHKeyImport { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHKeyImport extends BaseTestXDHKeyImport { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestXDHKeyImport() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestXDHKeyImport.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyPairGenerator.java index 09349aa0..1da748f7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,50 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import java.security.KeyPairGenerator; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.junit.Before; +import ibm.jceplus.junit.base.BaseTestXDHKeyPairGenerator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHKeyPairGenerator extends ibm.jceplus.junit.base.BaseTestXDHKeyPairGenerator { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHKeyPairGenerator extends BaseTestXDHKeyPairGenerator { - KeyPairGenerator kpg = null; - KeyPairGenerator kpgc = null; - - @Before - @Override - protected void setUp() throws Exception { - super.setUp(); - kpg = KeyPairGenerator.getInstance("XDH", providerName); - kpgc = KeyPairGenerator.getInstance("XDH", providerName); - } - - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestXDHKeyPairGenerator() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestXDHKeyPairGenerator.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHMultiParty.java b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHMultiParty.java index f146a302..63624ee8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/TestXDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,17 @@ package ibm.jceplus.junit.openjceplus; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestXDHMultiParty; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHMultiParty extends ibm.jceplus.junit.base.BaseTestXDHMultiParty { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHMultiParty extends BaseTestXDHMultiParty { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestXDHMultiParty() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestXDHMultiParty.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/Utils.java b/src/test/java/ibm/jceplus/junit/openjceplus/Utils.java index 285778c8..82b439e4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/Utils.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,14 +10,10 @@ abstract public class Utils extends ibm.jceplus.junit.base.BaseUtils { - //-------------------------------------------------------------------------- - // - // + public static final String TEST_SUITE_PROVIDER_NAME = PROVIDER_OpenJCEPlus; - //-------------------------------------------------------------------------- - // - // + public static java.security.Provider loadProviderTestSuite() { if (System.getProperty("os.name").equals("z/OS")) { Utils.PROVIDER_SunEC = "BC"; //jpf SunEC doesn't have the necessary EC algorithms use BouncyCastle instead "SunEC"; diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAES256.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAES256.java index 8b518c1c..b25282a9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAES256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAES256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressAES; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressAES256 extends BaseTestMemStressAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressAES256() throws Exception { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 256); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressAES256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAESGCM.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAESGCM.java index e4fd6558..f277e153 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAESGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAESGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressAESGCM; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressAESGCM extends BaseTestMemStressAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressAESGCM() throws Exception { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 256); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressAESGCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAll.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAll.java index 3b3bb6b3..288b3fe0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAll.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressAll.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,14 +11,27 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; -@SelectClasses({TestMemStressAES256.class, TestMemStressAESGCM.class, - TestMemStressChaChaPoly1305.class, TestMemStressDH.class, TestMemStressDHKeyPair.class, - TestMemStressDHKeyFactory.class, TestMemStressDSASignature.class, - TestMemStressDSAKeyPair.class, TestMemStressDSAKeyFactory.class, - TestMemStressECKeyPair.class, TestMemStressECKeyFactory.class, - TestMemStressECDSASignature.class, TestMemStressHKDF.class, TestMemStressHmacSHA256.class, - TestMemStressRSAPSS2.class, TestMemStressRSASignature.class, TestMemStressSHA256.class, - TestMemStressXDH_X25519.class, TestMemStressXDH_X448.class}) +@SelectClasses({ + TestMemStressAES256.class, + TestMemStressAESGCM.class, + TestMemStressChaChaPoly1305.class, + TestMemStressDH.class, + TestMemStressDHKeyFactory.class, + TestMemStressDHKeyPair.class, + TestMemStressDSAKeyFactory.class, + TestMemStressDSAKeyPair.class, + TestMemStressDSASignature.class, + TestMemStressECDSASignature.class, + TestMemStressECKeyFactory.class, + TestMemStressECKeyPair.class, + TestMemStressHKDF.class, + TestMemStressHmacSHA256.class, + TestMemStressRSAPSS2.class, + TestMemStressRSASignature.class, + TestMemStressSHA256.class, + TestMemStressXDH_X25519.class, + TestMemStressXDH_X448.class +}) @Suite public class TestMemStressAll { diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressChaChaPoly1305.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressChaChaPoly1305.java index 4c3eacb6..2b8d7fcf 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressChaChaPoly1305.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressChaChaPoly1305.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressChaCha20Poly1305; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressChaChaPoly1305 extends BaseTestMemStressChaCha20Poly1305 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressChaChaPoly1305() { - - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressChaChaPoly1305.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDH.java index cd9f643b..efd6cb47 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDH; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressDH extends BaseTestMemStressDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressDH() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressDH.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyFactory.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyFactory.java index 50eacb06..851ccb8a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDHKeyFactory; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressDHKeyFactory extends BaseTestMemStressDHKeyFactory { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressDHKeyFactory() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressDHKeyFactory.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyPair.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyPair.java index 9eb09664..21ff4841 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDHKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDHKeyPair; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressDHKeyPair extends BaseTestMemStressDHKeyPair { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressDHKeyPair() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressDHKeyPair.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyFactory.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyFactory.java index 4724b131..c1f52d1c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDSAKeyFactory; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressDSAKeyFactory extends BaseTestMemStressDSAKeyFactory { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressDSAKeyFactory() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressDSAKeyFactory.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyPair.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyPair.java index b1b0afb0..9d73c279 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressDSAKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDSAKeyPair; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressDSAKeyPair extends BaseTestMemStressDSAKeyPair { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressDSAKeyPair() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressDSAKeyPair.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyFactory.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyFactory.java index 9de4f387..71c3e25b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressECKeyFactory; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressECKeyFactory extends BaseTestMemStressECKeyFactory { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressECKeyFactory() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressECKeyFactory.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyPair.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyPair.java index 80473fbd..a6a6c703 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressECKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressECKeyPair; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressECKeyPair extends BaseTestMemStressECKeyPair { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressECKeyPair() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressECKeyPair.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHKDF.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHKDF.java index f30e12fb..e128a34b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHKDF.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,18 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressHKDF; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressHKDF extends BaseTestMemStressHKDF { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressHKDF() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, "kda-hkdf-with-sha256", 192); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressHKDF.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("kda-hkdf-with-sha256"); + setKeySize(192); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHmacSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHmacSHA256.java index 1390d65b..0826d0d3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHmacSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressHmacSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressHmacSHA; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressHmacSHA256 extends BaseTestMemStressHmacSHA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressHmacSHA256() { - - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressHmacSHA256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressMD5.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressMD5.java index f0973b9a..7b4253f8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDigest; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressMD5 extends BaseTestMemStressDigest { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressMD5() throws Exception { - - super(Utils.TEST_SUITE_PROVIDER_NAME, "MD5"); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressMD5.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("MD5"); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyFactory.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyFactory.java index c1de4338..66300f31 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressRSAKeyFactory; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressRSAKeyFactory extends BaseTestMemStressRSAKeyFactory { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressRSAKeyFactory() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressRSAKeyFactory.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyPair.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyPair.java index 2dbeadeb..75de3863 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyPair.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAKeyPair.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressRSAKeyPair; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressRSAKeyPair extends BaseTestMemStressRSAKeyPair { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressRSAKeyPair() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressRSAKeyPair.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAPSS2.java index b0984b0d..ed34e297 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressRSAPSS2; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressRSAPSS2 extends BaseTestMemStressRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressRSAPSS2() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressRSAPSS2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressSHA256.java index 943af053..0025fc37 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressDigest; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressSHA256 extends BaseTestMemStressDigest { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMemStressSHA256() throws Exception { - - super(Utils.TEST_SUITE_PROVIDER_NAME, "SHA-256"); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressSHA256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("SHA-256"); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X25519.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X25519.java index 01f6b170..6f53e5f0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X25519.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X25519.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressXDH; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressXDH_X25519 extends BaseTestMemStressXDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - //-------------------------------------------------------------------------- - // - // - - public TestMemStressXDH_X25519() { - super(Utils.TEST_SUITE_PROVIDER_NAME, "X25519"); - } - - - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressXDH_X25519.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("X25519"); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X448.java b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X448.java index 1ba1b440..4591dc4d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X448.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/memstress/TestMemStressXDH_X448.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,36 +10,17 @@ import ibm.jceplus.junit.base.memstress.BaseTestMemStressXDH; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestMemStressXDH_X448 extends BaseTestMemStressXDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestMemStressXDH_X448() { - - super(Utils.TEST_SUITE_PROVIDER_NAME, "X448"); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMemStressXDH_X448.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("X448"); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCipherInputStreamExceptions.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCipherInputStreamExceptions.java index 6235016a..b8c75627 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCipherInputStreamExceptions.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCipherInputStreamExceptions.java @@ -23,4 +23,3 @@ public void beforeAll() { setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCopySafe.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCopySafe.java index 499e859f..69c1fd8f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCopySafe.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESCopySafe.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,38 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESCopySafe; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESCopySafe extends BaseTestAESCopySafe { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCopySafe() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestAESCopySafe.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESCopySafe() throws Exception { - System.out.println("executing testAESCopySafe"); - BaseTestAESCopySafe bt = new BaseTestAESCopySafe(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCM.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCM.java index f478da34..c6b35e17 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,38 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCM; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMCICOWithGCM extends BaseTestAESGCMCICOWithGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestAESGCMCICOWithGCM.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMCICOWithGCM() throws Exception { - System.out.println("executing testAESGCMCICOWithGCM"); - BaseTestAESGCMCICOWithGCM bt = new BaseTestAESGCMCICOWithGCM(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCMAndAAD.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCMAndAAD.java index 61b0c569..14259faa 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCMAndAAD.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMCICOWithGCMAndAAD.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; +import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMCICOWithGCMAndAAD - extends ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMCICOWithGCMAndAAD extends BaseTestAESGCMCICOWithGCMAndAAD { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCMAndAAD() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMCICOWithGCMAndAAD.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMLong.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMLong.java index 5ed64618..4261ed6b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMLong.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMLong.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,36 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMLong; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMLong extends BaseTestAESGCMLong { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMLong() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAESGCMLong.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMLong() throws Exception { - BaseTestAESGCMLong bt = new BaseTestAESGCMLong(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMNonExpanding.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMNonExpanding.java index 1387146e..2e352376 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMNonExpanding.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMNonExpanding.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; +import ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMNonExpanding extends ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMNonExpanding extends BaseTestAESGCMNonExpanding { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMNonExpanding() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMNonExpanding.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMSameBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMSameBuffer.java index 49b02e26..e957da2f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMSameBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMSameBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMSameBuffer; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMSameBuffer extends BaseTestAESGCMSameBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMSameBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {TestAESGCMSameBuffer.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMSameBuffer() throws Exception { - System.out.println("executing testAESGCMSameBuffer"); - BaseTestAESGCMSameBuffer bt = new BaseTestAESGCMSameBuffer(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMUpdate.java index 22c5197d..2b95e9e8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,38 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMUpdate; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMUpdate extends BaseTestAESGCMUpdate { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdate() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestAESGCMUpdate.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void TestAESGCMUpdate() throws Exception { - System.out.println("executing testAESGCMUpdate"); - BaseTestAESGCMUpdate bt = new BaseTestAESGCMUpdate(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithByteBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithByteBuffer.java index b6a12176..8feb25b3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMWithByteBuffer; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMWithByteBuffer extends BaseTestAESGCMWithByteBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithByteBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {TestAESGCMWithByteBuffer.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMWithByteBuffer() throws Exception { - System.out.println("executing testAESGCMWithByteBuffer"); - BaseTestAESGCMWithByteBuffer bt = new BaseTestAESGCMWithByteBuffer(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithKeyAndIvCheck.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithKeyAndIvCheck.java index 8c0fbcf1..bf764f44 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithKeyAndIvCheck.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCMWithKeyAndIvCheck.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; +import ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck; import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMWithKeyAndIvCheck - extends ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMWithKeyAndIvCheck extends BaseTestAESGCMWithKeyAndIvCheck { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithKeyAndIvCheck() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMWithKeyAndIvCheck.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_128.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_128.java index 941b83a3..6a9e01e8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_128.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,43 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAESGCM; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_128 extends BaseTestAESGCM { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAESGCM_128() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAESGCM_128.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAESGCM_128"); - BaseTestAESGCM bs = new BaseTestAESGCM(providerName, 128); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_192.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_192.java index 285e15e6..43a26b79 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_192.java @@ -1,52 +1,27 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplus.multithread; import ibm.jceplus.junit.base.BaseTestAESGCM; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_192 extends BaseTestAESGCM { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAESGCM_192() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAESGCM_192.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAESGCM_192"); - BaseTestAESGCM bs = new BaseTestAESGCM(providerName, 192); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_256.java index a1f93ade..8ebb8f4e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAESGCM_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,43 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAESGCM; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_256 extends BaseTestAESGCM { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAESGCM_256() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAESGCM_256.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCM_256() throws Exception { - System.out.println("executing testAESGCM_256"); - BaseTestAESGCM bs = new BaseTestAESGCM(providerName, 256); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_128.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_128.java index 40607b23..19f914b0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_128.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,52 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAES; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAES_128 extends BaseTestAES { - static boolean first = true; - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAES_128() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } - - // -------------------------------------------------------------------------- - // - // - public TestAES_128(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAES_128.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAES_128"); - BaseTestAES bs = new BaseTestAES(providerName, 128); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_192.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_192.java index 7a47f46a..fec62992 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_192.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,52 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAES; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_192 extends ibm.jceplus.junit.base.BaseTestAES { - static boolean first = true; - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 192; - - // -------------------------------------------------------------------------- - // - // - public TestAES_192() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_192 extends BaseTestAES { + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } - - // -------------------------------------------------------------------------- - // - // - public TestAES_192(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAES_192.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAES_192"); - ibm.jceplus.junit.base.BaseTestAES bs = new BaseTestAES(providerName, 192); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_256.java index 64c1c2d9..8c8ddca7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAES_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,42 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAES; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAES_256 extends BaseTestAES { - static boolean first = true; - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - public TestAES_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - - } - - // -------------------------------------------------------------------------- - // - // - public TestAES_256(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - public void testAES_256() throws Exception { - BaseTestAES bs = new BaseTestAES(providerName, 256); - System.out.println("executing testAES_256"); - bs.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAES_256.class.getName()}; - junit.textui.TestRunner.main(nargs); + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } - - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAliases.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAliases.java index a170e399..35e7141f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAliases.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestAliases.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,7 +8,7 @@ package ibm.jceplus.junit.openjceplus.multithread; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import ibm.jceplus.junit.openjceplus.Utils; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; @@ -21,558 +21,384 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKeyFactory; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAliases extends BaseTest { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAliases extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void setUp() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestAliases() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_3DES() throws Exception { - AlgorithmParameters.getInstance("3DES", providerName); + AlgorithmParameters.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_AESGCM() throws Exception { - AlgorithmParameters.getInstance("AESGCM", providerName); + AlgorithmParameters.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParamGen_AESGCM() throws Exception { - AlgorithmParameterGenerator.getInstance("AESGCM", providerName); + AlgorithmParameterGenerator.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testCipher_3DES() throws Exception { - Cipher.getInstance("3DES", providerName); + Cipher.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyFactory_DSAKeyFactory() throws Exception { - KeyFactory.getInstance("DSAKeyFactory", providerName); + KeyFactory.getInstance("DSAKeyFactory", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_3DES() throws Exception { - KeyGenerator.getInstance("3DES", providerName); + KeyGenerator.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA1() throws Exception { - KeyGenerator.getInstance("HMACwithSHA1", providerName); + KeyGenerator.getInstance("HMACwithSHA1", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA224() throws Exception { - KeyGenerator.getInstance("HMACwithSHA224", providerName); + KeyGenerator.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA256() throws Exception { - KeyGenerator.getInstance("HMACwithSHA256", providerName); + KeyGenerator.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA384() throws Exception { - KeyGenerator.getInstance("HMACwithSHA384", providerName); + KeyGenerator.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA512() throws Exception { - KeyGenerator.getInstance("HMACwithSHA512", providerName); + KeyGenerator.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyPairGen_OID_1_3_14_3_2_12() throws Exception { - KeyPairGenerator.getInstance("OID.1.3.14.3.2.12", providerName); + KeyPairGenerator.getInstance("OID.1.3.14.3.2.12", getProviderName()); } - //-------------------------------------------------------------------------- - // - // //public void testKeyStore_PKCS12KS() throws Exception { - // KeyStore.getInstance("PKCS12KS", providerName); + // KeyStore.getInstance("PKCS12KS", getProviderName()); //} - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA1() throws Exception { - Mac.getInstance("HMACwithSHA1", providerName); + Mac.getInstance("HMACwithSHA1", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA224() throws Exception { - Mac.getInstance("HMACwithSHA224", providerName); + Mac.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA256() throws Exception { - Mac.getInstance("HMACwithSHA256", providerName); + Mac.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA384() throws Exception { - Mac.getInstance("HMACwithSHA384", providerName); + Mac.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA512() throws Exception { - Mac.getInstance("HMACwithSHA512", providerName); + Mac.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA224() throws Exception { - MessageDigest.getInstance("SHA224", providerName); + MessageDigest.getInstance("SHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA2() throws Exception { - MessageDigest.getInstance("SHA2", providerName); + MessageDigest.getInstance("SHA2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_2() throws Exception { - MessageDigest.getInstance("SHA-2", providerName); + MessageDigest.getInstance("SHA-2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA256() throws Exception { - MessageDigest.getInstance("SHA256", providerName); + MessageDigest.getInstance("SHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA3() throws Exception { - MessageDigest.getInstance("SHA3", providerName); + MessageDigest.getInstance("SHA3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_3() throws Exception { - MessageDigest.getInstance("SHA-3", providerName); + MessageDigest.getInstance("SHA-3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA384() throws Exception { - MessageDigest.getInstance("SHA384", providerName); + MessageDigest.getInstance("SHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA5() throws Exception { - MessageDigest.getInstance("SHA5", providerName); + MessageDigest.getInstance("SHA5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_5() throws Exception { - MessageDigest.getInstance("SHA-5", providerName); + MessageDigest.getInstance("SHA-5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA512() throws Exception { - MessageDigest.getInstance("SHA512", providerName); + MessageDigest.getInstance("SHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecretKeyFactory_3DES() throws Exception { - SecretKeyFactory.getInstance("3DES", providerName); + SecretKeyFactory.getInstance("3DES", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA2DRBG() throws Exception { - SecureRandom.getInstance("SHA2DRBG", providerName); + SecureRandom.getInstance("SHA2DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA5DRBG() throws Exception { - SecureRandom.getInstance("SHA5DRBG", providerName); + SecureRandom.getInstance("SHA5DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withDSA() throws Exception { - Signature.getInstance("SHA-1withDSA", providerName); + Signature.getInstance("SHA-1withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_DSA() throws Exception { - Signature.getInstance("SHA-1/DSA", providerName); + Signature.getInstance("SHA-1/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA1_DSA() throws Exception { - Signature.getInstance("SHA1/DSA", providerName); + Signature.getInstance("SHA1/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_DSA() throws Exception { - Signature.getInstance("SHA/DSA", providerName); + Signature.getInstance("SHA/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_DSS() throws Exception { - Signature.getInstance("DSS", providerName); + Signature.getInstance("DSS", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithDSA() throws Exception { - Signature.getInstance("SHAwithDSA", providerName); + Signature.getInstance("SHAwithDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_DSAWithSHA1() throws Exception { - Signature.getInstance("DSAWithSHA1", providerName); + Signature.getInstance("DSAWithSHA1", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_OID_1_3_14_3_2_13() throws Exception { - Signature.getInstance("OID.1.3.14.3.2.13", providerName); + Signature.getInstance("OID.1.3.14.3.2.13", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_OID_1_3_14_3_2_27() throws Exception { - Signature.getInstance("OID.1.3.14.3.2.27", providerName); + Signature.getInstance("OID.1.3.14.3.2.27", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_224withDSA() throws Exception { - Signature.getInstance("SHA-224withDSA", providerName); + Signature.getInstance("SHA-224withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_224_DSA() throws Exception { - Signature.getInstance("SHA-224/DSA", providerName); + Signature.getInstance("SHA-224/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_DSA() throws Exception { - Signature.getInstance("SHA224/DSA", providerName); + Signature.getInstance("SHA224/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withDSA() throws Exception { - Signature.getInstance("SHA2withDSA", providerName); + Signature.getInstance("SHA2withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_2withDSA() throws Exception { - Signature.getInstance("SHA-2withDSA", providerName); + Signature.getInstance("SHA-2withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_256withDSA() throws Exception { - Signature.getInstance("SHA-256withDSA", providerName); + Signature.getInstance("SHA-256withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_2_DSA() throws Exception { - Signature.getInstance("SHA-2/DSA", providerName); + Signature.getInstance("SHA-2/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_DSA() throws Exception { - Signature.getInstance("SHA2/DSA", providerName); + Signature.getInstance("SHA2/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithECDSA() throws Exception { - Signature.getInstance("SHAwithECDSA", providerName); + Signature.getInstance("SHAwithECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withECDSA() throws Exception { - Signature.getInstance("SHA-1withECDSA", providerName); + Signature.getInstance("SHA-1withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_ECDSA() throws Exception { - Signature.getInstance("SHA/ECDSA", providerName); + Signature.getInstance("SHA/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_ECDSA() throws Exception { - Signature.getInstance("SHA-1/ECDSA", providerName); + Signature.getInstance("SHA-1/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_ECDSA() throws Exception { - Signature.getInstance("SHA224/ECDSA", providerName); + Signature.getInstance("SHA224/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withECDSA() throws Exception { - Signature.getInstance("SHA2withECDSA", providerName); + Signature.getInstance("SHA2withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_ECDSA() throws Exception { - Signature.getInstance("SHA2/ECDSA", providerName); + Signature.getInstance("SHA2/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withECDSA() throws Exception { - Signature.getInstance("SHA3withECDSA", providerName); + Signature.getInstance("SHA3withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_ECDSA() throws Exception { - Signature.getInstance("SHA3/ECDSA", providerName); + Signature.getInstance("SHA3/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withECDSA() throws Exception { - Signature.getInstance("SHA5withECDSA", providerName); + Signature.getInstance("SHA5withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_ECDSA() throws Exception { - Signature.getInstance("SHA5/ECDSA", providerName); + Signature.getInstance("SHA5/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withRSA() throws Exception { - Signature.getInstance("SHA-1withRSA", providerName); + Signature.getInstance("SHA-1withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithRSA() throws Exception { - Signature.getInstance("SHAwithRSA", providerName); + Signature.getInstance("SHAwithRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_RSA() throws Exception { - Signature.getInstance("SHA-1/RSA", providerName); + Signature.getInstance("SHA-1/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA1_RSA() throws Exception { - Signature.getInstance("SHA1/RSA", providerName); + Signature.getInstance("SHA1/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_RSA() throws Exception { - Signature.getInstance("SHA/RSA", providerName); + Signature.getInstance("SHA/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_RSA() throws Exception { - Signature.getInstance("RSA", providerName); + Signature.getInstance("RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_RSA() throws Exception { - Signature.getInstance("SHA224/RSA", providerName); + Signature.getInstance("SHA224/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withRSA() throws Exception { - Signature.getInstance("SHA2withRSA", providerName); + Signature.getInstance("SHA2withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_RSA() throws Exception { - Signature.getInstance("SHA2/RSA", providerName); + Signature.getInstance("SHA2/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withRSA() throws Exception { - Signature.getInstance("SHA3withRSA", providerName); + Signature.getInstance("SHA3withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_RSA() throws Exception { - Signature.getInstance("SHA3/RSA", providerName); + Signature.getInstance("SHA3/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withRSA() throws Exception { - Signature.getInstance("SHA5withRSA", providerName); + Signature.getInstance("SHA5withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_RSA() throws Exception { - Signature.getInstance("SHA5/RSA", providerName); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAliases.class.getName()}; - junit.textui.TestRunner.main(nargs); + Signature.getInstance("SHA5/RSA", getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAliases() throws Exception { System.out.println("executing testAliases SHA5/RSA"); - Signature.getInstance("SHA5/RSA", providerName); - } - //-------------------------------------------------------------------------- - // - // - // public static void main(String[] args) throws Exception { - // junit.textui.TestRunner.run(suite()); - // } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAliases.class); - return suite; + Signature.getInstance("SHA5/RSA", getProviderName()); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDESede.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDESede.java index 975906b0..8fe44f17 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDESede.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDESede.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,45 +10,24 @@ import ibm.jceplus.junit.base.BaseTestDESede; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDESede extends BaseTestDESede { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - // -------------------------------------------------------------------------- - // - // - public TestDESede() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestDESede.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testDESede() throws Exception { - System.out.println("executing testDESede"); - BaseTestDESede bt = new BaseTestDESede(providerName); - bt.run(); - } - - - // -------------------------------------------------------------------------- - // This method is to check whether a mode is valid for the cipher - // but not supported by a given provider. - // + /** + * + * This method is to check whether a mode is valid for the cipher + * but not supported by a given provider. + */ @Override public boolean isModeValidButUnsupported(String mode) { if (mode.equalsIgnoreCase("CFB") || mode.equalsIgnoreCase("CFB64") diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDH.java index 1c4c346f..d57bff15 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,36 +10,17 @@ import ibm.jceplus.junit.base.BaseTestDH; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDH extends BaseTestDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - isMulti = true; - } - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestDH.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testDH() throws Exception { - System.out.println("executing testDH"); - BaseTestDH bt = new BaseTestDH(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setMulti(true); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSAKey.java index e66e2276..1f51cb46 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSAKey.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,43 +10,16 @@ import ibm.jceplus.junit.base.BaseTestDSAKey; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDSAKey extends BaseTestDSAKey { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - // -------------------------------------------------------------------------- - // - // - public TestDSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - - - public void testDSAKey() throws Exception { - - System.out.println("executing testDSAKey"); - BaseTestDSAKey bt = new BaseTestDSAKey(providerName); - bt.run(); - - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestDSAKey.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSASignatureInteropSUN.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSASignatureInteropSUN.java index 3c0b62b4..fdf878fb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSASignatureInteropSUN.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestDSASignatureInteropSUN.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,17 @@ import ibm.jceplus.junit.base.BaseTestDSASignatureInterop; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDSASignatureInteropSUN extends BaseTestDSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SUN); } - - //-------------------------------------------------------------------------- - // - // - public TestDSASignatureInteropSUN() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SUN); - } - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestDSASignatureInteropSUN.class - .getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testDSASignatureInteropSUN() throws Exception { - System.out.println("executing testDSASignatureInteropSUN"); - BaseTestDSASignatureInterop bt = new BaseTestDSASignatureInterop(providerName, - Utils.PROVIDER_SUN); - bt.run(); - } - - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDH.java index 8547d5e0..bfb85b73 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,62 +10,17 @@ import ibm.jceplus.junit.base.BaseTestECDH; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestECDH extends BaseTestECDH { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setMulti(true); } - - // -------------------------------------------------------------------------- - // - // - public TestECDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - isMulti = true; - } - - // -------------------------------------------------------------------------- - // - // - // public static void main(String[] args) throws Exception { - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static void testECDH () throws Exception { - // - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static Test suite() { - // TestSuite suite = new TestSuite(TestECDH.class); - // return suite; - // } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestECDH.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testECDH() throws Exception { - System.out.println("executing testECDH"); - BaseTestECDH bt = new BaseTestECDH(providerName); - bt.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDHInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDHInteropSunEC.java index 9d3a3f14..de8e5d2c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDHInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestECDHInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,17 @@ import ibm.jceplus.junit.base.BaseTestECDHInterop; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestECDHInteropSunEC extends BaseTestECDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public void testECDHInteropSunEC() throws Exception { - System.out.println("executing testECDHInteropSunEC"); - BaseTestECDHInterop bt = new BaseTestECDHInterop(providerName, Utils.PROVIDER_SunEC); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestECDHInteropSunEC.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHKDF.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHKDF.java index 98dad51c..d873afab 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHKDF.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,16 @@ import ibm.jceplus.junit.base.BaseTestHKDF; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHKDF extends BaseTestHKDF { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHKDF() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestHKDF.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testHKDF() throws Exception { - System.out.println("executing testHKDF"); - BaseTestHKDF bt = new BaseTestHKDF(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5.java index 03521121..04c3a7aa 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,36 +10,16 @@ import ibm.jceplus.junit.base.BaseTestHmacMD5; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHmacMD5 extends BaseTestHmacMD5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public void testHmacMD5() throws Exception { - System.out.println("executing testHmacMD5"); - BaseTestHmacMD5 bt = new BaseTestHmacMD5(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestHmacMD5.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5InteropSunJCE.java index 01d4945e..845e787e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacMD5InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,19 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestHmacMD5Interop; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHmacMD5InteropSunJCE extends BaseTestHmacMD5Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - public void testHmacMD5Interop() throws Exception { - System.out.println("executing testHmacMD5Interop"); - BaseTestHmacMD5Interop bt = new BaseTestHmacMD5Interop(providerName, Utils.PROVIDER_SunJCE); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestHmacMD5InteropSunJCE.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256.java index 15c68f4b..422a80b2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,34 +11,16 @@ import ibm.jceplus.junit.base.BaseTestHmacSHA256; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA256 extends ibm.jceplus.junit.base.BaseTestHmacSHA256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA256 extends BaseTestHmacSHA256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacMD5() throws Exception { - System.out.println("executing testHmacSHA256"); - BaseTestHmacSHA256 bt = new BaseTestHmacSHA256(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestHmacSHA256.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256InteropSunJCE.java index 36ce46a3..fb5ef5d2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA256InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,19 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestHmacSHA256Interop; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHmacSHA256InteropSunJCE extends BaseTestHmacSHA256Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - public void testHmacSHA256Interop() throws Exception { - System.out.println("executing testHmacSHA256Interop"); - BaseTestHmacSHA256Interop bt = new BaseTestHmacSHA256Interop(providerName, - Utils.PROVIDER_SunJCE); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestHmacSHA256InteropSunJCE.class - .getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_224.java index 8b6eca20..eb836189 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestHmacSHA3_224; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_224 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_224 extends BaseTestHmacSHA3_224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_224() throws Exception { - System.out.println("executing testHmacSHA3_224"); - BaseTestHmacSHA3_224 bt = new BaseTestHmacSHA3_224(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestHmacSHA3_224.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_256.java index 1400bbe4..5ecc08cf 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestHmacSHA3_256; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_256 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_256 extends BaseTestHmacSHA3_256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_256() throws Exception { - System.out.println("executing testHmacSHA3_256"); - BaseTestHmacSHA3_256 bt = new BaseTestHmacSHA3_256(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestHmacSHA3_256.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_384.java index e2f2ee0f..c25ff39a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestHmacSHA3_384; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_384 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_384 extends BaseTestHmacSHA3_384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_384() throws Exception { - System.out.println("executing testHmacSHA3_384"); - BaseTestHmacSHA3_384 bt = new BaseTestHmacSHA3_384(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestHmacSHA3_384.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_512.java index 609987c3..d5010805 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestHmacSHA3_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestHmacSHA3_512; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_512 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_512 extends BaseTestHmacSHA3_512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_512() throws Exception { - System.out.println("executing testHmacSHA3_512"); - BaseTestHmacSHA3_512 bt = new BaseTestHmacSHA3_512(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestHmacSHA3_512.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestMiniRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestMiniRSAPSS2.java index 40f8e76b..8435dd94 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestMiniRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestMiniRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestMiniRSAPSS2; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestMiniRSAPSS2 extends ibm.jceplus.junit.base.BaseTestMiniRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestMiniRSAPSS2 extends BaseTestMiniRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestMiniRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestMiniRSAPSS2.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testMiniRSAPSS2() throws Exception { - System.out.println("executing testRSAPSS2"); - BaseTestMiniRSAPSS2 bt = new BaseTestMiniRSAPSS2(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAKey.java index a236154d..e942347a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAKey.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,41 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAKey; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestRSAKey extends BaseTestRSAKey { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public void testRSAKey() throws Exception { - - System.out.println("executing testRSAKey"); - BaseTestRSAKey bt = new BaseTestRSAKey(providerName); - bt.run(); - - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestRSAKey.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS.java index 78f01986..9c84343c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSS; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS extends ibm.jceplus.junit.base.BaseTestRSAPSS { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS extends BaseTestRSAPSS { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestRSAPSS.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSS() throws Exception { - System.out.println("executing testRSAPSS"); - BaseTestRSAPSS bt = new BaseTestRSAPSS(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS2.java index b7a7120d..8e569991 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSS2; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS2 extends ibm.jceplus.junit.base.BaseTestRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS2 extends BaseTestRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestRSAPSS2.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSS2() throws Exception { - System.out.println("executing testRSAPSS2"); - BaseTestRSAPSS2 bt = new BaseTestRSAPSS2(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop2.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop2.java index eb667001..ef7e76ac 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSSInterop2; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop2 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop2 extends BaseTestRSAPSSInterop2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestRSAPSSInterop2.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSSInterop2() throws Exception { - System.out.println("executing testRSAPSSInterop2"); - BaseTestRSAPSSInterop2 bt = new BaseTestRSAPSSInterop2(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop3.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop3.java index 01be724e..860969bc 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop3.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSAPSSInterop3.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSSInterop3; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop3 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop3 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop3 extends BaseTestRSAPSSInterop3 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop3() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestRSAPSSInterop3.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSSInterop3() throws Exception { - System.out.println("executing testRSAPSSInterop3"); - BaseTestRSAPSSInterop3 bt = new BaseTestRSAPSSInterop3(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSASignatureInteropSunRsaSign.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSASignatureInteropSunRsaSign.java index 92796755..c262ac56 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSASignatureInteropSunRsaSign.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSASignatureInteropSunRsaSign.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,42 +10,18 @@ import ibm.jceplus.junit.base.BaseTestRSASignatureInterop; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestRSASignatureInteropSunRsaSign extends BaseTestRSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSASignatureInteropSunRsaSign() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign); - } - - //-------------------------------------------------------------------------- - // - // - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestRSASignatureInteropSunRsaSign.class - .getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSASignatureInteropSunRsaSign() throws Exception { - System.out.println("executing testRSASignatureInteropSunRsaSign"); - BaseTestRSASignatureInterop bt = new BaseTestRSASignatureInterop(providerName, - Utils.PROVIDER_SunRsaSign); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); + setKeySize(1024); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSA_2048.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSA_2048.java index 3bd8e563..74d92b1e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSA_2048.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestRSA_2048.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,44 +10,17 @@ import ibm.jceplus.junit.base.BaseTestRSA; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestRSA_2048 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 2048; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_2048() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - public void testRSA_2048() throws Exception { - - System.out.println("executing testRSA_2048"); - BaseTestRSA bt = new BaseTestRSA(providerName, KEY_SIZE); - bt.run(); - - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestRSA_2048.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA256Clone_SharedMD.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA256Clone_SharedMD.java index a146f4a4..46b4d85a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA256Clone_SharedMD.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA256Clone_SharedMD.java @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; +import ibm.jceplus.junit.base.BaseTestSHA256Clone_SharedMD; import ibm.jceplus.junit.openjceplus.Utils; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA256Clone_SharedMD extends ibm.jceplus.junit.base.BaseTestSHA256Clone_SharedMD { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA256Clone_SharedMD extends BaseTestSHA256Clone_SharedMD { - - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA256Clone_SharedMD() throws NoSuchAlgorithmException, NoSuchProviderException { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA256Clone_SharedMD.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_224.java index d9fa70f0..90771a4d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestSHA3_224KAT; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_224 extends ibm.jceplus.junit.base.BaseTestSHA3_224KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_224 extends BaseTestSHA3_224KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_224() throws Exception { - System.out.println("executing testSHA3_224"); - BaseTestSHA3_224KAT bt = new BaseTestSHA3_224KAT(providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestSHA3_224.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_256.java index 85c45d79..c89a7798 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,36 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; +import ibm.jceplus.junit.base.BaseTestSHA3_256KAT; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_256 extends ibm.jceplus.junit.base.BaseTestSHA3_256KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_256 extends BaseTestSHA3_256KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_256() throws Exception { - System.out.println("executing testSHA3_256"); - ibm.jceplus.junit.base.BaseTestSHA3_256KAT bt = new ibm.jceplus.junit.base.BaseTestSHA3_256KAT( - providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestSHA3_256.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_384.java index ef25dcc2..0a661ea5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestSHA3_384KAT; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_384 extends ibm.jceplus.junit.base.BaseTestSHA3_384KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_384 extends BaseTestSHA3_384KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_384() throws Exception { - System.out.println("executing testSHA3_384"); - BaseTestSHA3_384KAT bt = new BaseTestSHA3_384KAT(providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestSHA3_384.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_512.java index 276de615..816f69ba 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA3_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestSHA3_512KAT; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_512 extends ibm.jceplus.junit.base.BaseTestSHA3_512KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_512 extends BaseTestSHA3_512KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_512() throws Exception { - System.out.println("executing testSHA3_512"); - BaseTestSHA3_512KAT bt = new BaseTestSHA3_512KAT(providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestSHA3_512.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512.java index 719bba72..b232942b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,37 +8,18 @@ package ibm.jceplus.junit.openjceplus.multithread; - import ibm.jceplus.junit.base.BaseTestSHA512; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA512 extends BaseTestSHA512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA512() throws Exception { - System.out.println("executing testSHA512"); - BaseTestSHA512 bt = new BaseTestSHA512(providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestSHA512.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_224.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_224.java index c0cd052d..e7619626 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_224.java @@ -1,32 +1,25 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ -package ibm.jceplus.junit.openjceplus.multithread; +package ibm.jceplus.junit.openjceplus.multithread; import ibm.jceplus.junit.base.BaseTestSHA512_224; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA512_224 extends BaseTestSHA512_224 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA512_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA512_224() throws Exception { - System.out.println("executing testSHA512_224"); - BaseTestSHA512_224 bt = new BaseTestSHA512_224(providerName); - - bt.run(); - + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_256.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_256.java index 39f1fef6..f09cbe75 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestSHA512_256.java @@ -1,57 +1,25 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplus.multithread; import ibm.jceplus.junit.base.BaseTestSHA512_256; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA512_256 extends BaseTestSHA512_256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA512_256() throws Exception { - System.out.println("executing testSHA512_256"); - BaseTestSHA512_256 bt = new BaseTestSHA512_256(providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestSHA512_256.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - //-------------------------------------------------------------------------- - // - // - // public static void main(String[] args) throws Exception { - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static Test suite() { - // TestSuite suite = new TestSuite(TestSHA512_256.class); - // return suite; - // } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDH.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDH.java index a38a0551..fd59e3c4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,61 +10,16 @@ import ibm.jceplus.junit.base.BaseTestXDH; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestXDH extends BaseTestXDH { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - // -------------------------------------------------------------------------- - // - // - public TestXDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - // public static void main(String[] args) throws Exception { - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static void testECDH () throws Exception { - // - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static Test suite() { - // TestSuite suite = new TestSuite(TestXDH.class); - // return suite; - // } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestXDH.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testXDH() throws Exception { - System.out.println("exuting testXDH"); - BaseTestXDH bt = new BaseTestXDH(providerName); - bt.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyImport.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyImport.java index eb7992d0..a3a60572 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyImport.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyImport.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,38 +10,16 @@ import ibm.jceplus.junit.base.BaseTestXDHKeyImport; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHKeyImport extends ibm.jceplus.junit.base.BaseTestXDHKeyImport { - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - public TestXDHKeyImport() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHKeyImport extends BaseTestXDHKeyImport { - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestXDHKeyImport.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testECDSASignature() throws Exception { - System.out.println("executing TestXDHKeyImport"); - BaseTestXDHKeyImport bt = new BaseTestXDHKeyImport(providerName); - bt.run(); + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyPairGenerator.java index 34d350ce..2aa7d239 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.BaseTestXDHKeyPairGenerator; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHKeyPairGenerator extends ibm.jceplus.junit.base.BaseTestXDHKeyPairGenerator { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHKeyPairGenerator extends BaseTestXDHKeyPairGenerator { - - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - public TestXDHKeyPairGenerator() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestXDHKeyPairGenerator.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testXDH() throws Exception { - System.out.println("exuting testXDH"); - BaseTestXDHKeyPairGenerator bt = new BaseTestXDHKeyPairGenerator(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHMultiParty.java b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHMultiParty.java index 5b26ef60..8d927ae3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/openjceplus/multithread/TestXDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.BaseTestXDHMultiParty; import ibm.jceplus.junit.openjceplus.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestXDHMultiParty extends ibm.jceplus.junit.base.BaseTestXDHMultiParty { +@TestInstance(Lifecycle.PER_CLASS) +public class TestXDHMultiParty extends BaseTestXDHMultiParty { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - // -------------------------------------------------------------------------- - // - // - public TestXDHMultiParty() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplus.multithread.TestXDHMultiParty.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testECDSASignature() throws Exception { - System.out.println("executing TestXDHKeyImport"); - BaseTestXDHMultiParty bt = new BaseTestXDHMultiParty(providerName); - bt.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES.java index 36949dd1..53199e52 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES.java @@ -1,52 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES extends ibm.jceplus.junit.base.BaseTestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAES() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestAES(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES256Interop.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES256Interop.java index 0eae998c..17cb4d4d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES256Interop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES256Interop.java @@ -1,57 +1,26 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ -package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +package ibm.jceplus.junit.openjceplusfips; -public class TestAES256Interop extends ibm.jceplus.junit.base.BaseTestAESInterop { +import ibm.jceplus.junit.base.BaseTestAESInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; - //-------------------------------------------------------------------------- - // - // - static { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES256Interop extends BaseTestAESInterop { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 256; - - //-------------------------------------------------------------------------- - // - // - public TestAES256Interop() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE, KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES256Interop.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM.java index c0e72697..55f6b420 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCM; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCM extends ibm.jceplus.junit.base.BaseTestAESCCM { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCM extends BaseTestAESCCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM2.java index 841cc76f..af1fa87b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCM2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCM2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCM2 extends ibm.jceplus.junit.base.BaseTestAESCCM2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCM2 extends BaseTestAESCCM2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCM2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCM2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMInteropBC.java index e2e824cc..87936f98 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,19 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCMInteropBC; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCMInteropBC extends ibm.jceplus.junit.base.BaseTestAESCCMInteropBC { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCMInteropBC extends BaseTestAESCCMInteropBC { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCMInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCMInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMParameters.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMParameters.java index 63d48517..7e4342a0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMParameters.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCCMParameters.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCCMParameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCCMParameters extends ibm.jceplus.junit.base.BaseTestAESCCMParameters { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCCMParameters extends BaseTestAESCCMParameters { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCCMParameters() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCCMParameters.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCipherInputStreamExceptions.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCipherInputStreamExceptions.java index 0be9a82f..b51a27b9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCipherInputStreamExceptions.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCipherInputStreamExceptions.java @@ -9,7 +9,6 @@ package ibm.jceplus.junit.openjceplusfips; import ibm.jceplus.junit.base.BaseTestAESCipherInputStreamExceptions; -import ibm.jceplus.junit.openjceplus.Utils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; @@ -23,4 +22,3 @@ public void beforeAll() { setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCopySafe.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCopySafe.java index d20c344b..9d799046 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCopySafe.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESCopySafe.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESCopySafe; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESCopySafe extends ibm.jceplus.junit.base.BaseTestAESCopySafe { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESCopySafe extends BaseTestAESCopySafe { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCopySafe() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESCopySafe.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM.java index a47fcaae..76684cc2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCM; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCM extends ibm.jceplus.junit.base.BaseTestAESGCM { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCM extends BaseTestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMBufferIV.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMBufferIV.java index 0d78abbe..cc9d4e81 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMBufferIV.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMBufferIV.java @@ -1,31 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMBufferIV; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMBufferIV extends ibm.jceplus.junit.base.BaseTestAESGCMBufferIV { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMBufferIV extends BaseTestAESGCMBufferIV { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestAESGCMBufferIV() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMBufferIV.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCM.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCM.java index 76395f10..ee564af5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCM.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCM; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMCICOWithGCM extends ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCM { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMCICOWithGCM extends BaseTestAESGCMCICOWithGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMCICOWithGCM.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCMAndAAD.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCMAndAAD.java index a029d6d1..2c8b5d6a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCMAndAAD.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMCICOWithGCMAndAAD.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMCICOWithGCMAndAAD - extends ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMCICOWithGCMAndAAD extends BaseTestAESGCMCICOWithGCMAndAAD { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCMAndAAD() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMCICOWithGCMAndAAD.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMLong.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMLong.java index e6169e78..d92510e0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMLong.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMLong.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMLong; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMLong extends ibm.jceplus.junit.base.BaseTestAESGCMLong { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMLong extends BaseTestAESGCMLong { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMLong() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMLong.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMNonExpanding.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMNonExpanding.java index fe2af755..89a5283e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMNonExpanding.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMNonExpanding.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMNonExpanding extends ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMNonExpanding extends BaseTestAESGCMNonExpanding { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMNonExpanding() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMNonExpanding.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMSameBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMSameBuffer.java index a2701371..baf474f4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMSameBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMSameBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMSameBuffer; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMSameBuffer extends ibm.jceplus.junit.base.BaseTestAESGCMSameBuffer { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMSameBuffer extends BaseTestAESGCMSameBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMSameBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMSameBuffer.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMUpdate.java index 09337fe1..1f343a53 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMUpdate; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMUpdate extends ibm.jceplus.junit.base.BaseTestAESGCMUpdate { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMUpdate extends BaseTestAESGCMUpdate { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdate() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdate(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMUpdate.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithByteBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithByteBuffer.java index bac2ccb5..96935698 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMWithByteBuffer; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMWithByteBuffer extends ibm.jceplus.junit.base.BaseTestAESGCMWithByteBuffer { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMWithByteBuffer extends BaseTestAESGCMWithByteBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithByteBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMWithByteBuffer.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithKeyAndIvCheck.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithKeyAndIvCheck.java index df003aac..44129db5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithKeyAndIvCheck.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCMWithKeyAndIvCheck.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMWithKeyAndIvCheck - extends ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMWithKeyAndIvCheck extends BaseTestAESGCMWithKeyAndIvCheck { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithKeyAndIvCheck() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMWithKeyAndIvCheck.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_128.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_128.java index 23a5a2e9..b4a478f7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_128.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_128 extends TestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_128() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_128.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_192.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_192.java index 3180ee02..bc35dc47 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_192.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_192 extends TestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 192; - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_192() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_192.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_256.java index fc613dc1..b0d0f2fd 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_256 extends TestAESGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 256; - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_256() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_ExtIV.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_ExtIV.java index 277f2e7d..b5aed07b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_ExtIV.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_ExtIV.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCM_ExtIV; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCM_ExtIV extends ibm.jceplus.junit.base.BaseTestAESGCM_ExtIV { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCM_ExtIV extends BaseTestAESGCM_ExtIV { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_ExtIV() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_ExtIV.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_IntIV.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_IntIV.java index 60712c31..8474b286 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_IntIV.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAESGCM_IntIV.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAESGCM_IntIV; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCM_IntIV extends ibm.jceplus.junit.base.BaseTestAESGCM_IntIV { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCM_IntIV extends BaseTestAESGCM_IntIV { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCM_IntIV() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCM_IntIV.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_128.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_128.java index eb5e01ff..40174f73 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_128.java @@ -1,50 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_128 extends TestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_128 extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - //-------------------------------------------------------------------------- - // - // - public TestAES_128() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES_128.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_192.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_192.java index e55ac64e..864dd18f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_192.java @@ -1,50 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_192 extends TestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_192 extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 192; - - //-------------------------------------------------------------------------- - // - // - public TestAES_192() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES_192.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_256.java index c8e1574f..c3b35a71 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAES_256.java @@ -1,50 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestAES; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_256 extends TestAES { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_256 extends BaseTestAES { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 256; - - //-------------------------------------------------------------------------- - // - // - public TestAES_256() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAES_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAliases.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAliases.java index b5a979ab..03f6dc02 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAliases.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAliases.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,6 +8,7 @@ package ibm.jceplus.junit.openjceplusfips; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.KeyFactory; @@ -16,429 +17,327 @@ import java.security.Signature; import javax.crypto.KeyGenerator; import javax.crypto.Mac; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAliases extends ibm.jceplus.junit.base.BaseTest { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAliases extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void setUp() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestAliases() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_AESGCM() throws Exception { - AlgorithmParameters.getInstance("AESGCM", providerName); + AlgorithmParameters.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParamGen_AESGCM() throws Exception { - AlgorithmParameterGenerator.getInstance("AESGCM", providerName); + AlgorithmParameterGenerator.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyFactory_DSAKeyFactory() throws Exception { - KeyFactory.getInstance("DSAKeyFactory", providerName); + KeyFactory.getInstance("DSAKeyFactory", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA224() throws Exception { - KeyGenerator.getInstance("HMACwithSHA224", providerName); + KeyGenerator.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA256() throws Exception { - KeyGenerator.getInstance("HMACwithSHA256", providerName); + KeyGenerator.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA384() throws Exception { - KeyGenerator.getInstance("HMACwithSHA384", providerName); + KeyGenerator.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA512() throws Exception { - KeyGenerator.getInstance("HMACwithSHA512", providerName); + KeyGenerator.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA224() throws Exception { - Mac.getInstance("HMACwithSHA224", providerName); + Mac.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA256() throws Exception { - Mac.getInstance("HMACwithSHA256", providerName); + Mac.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA384() throws Exception { - Mac.getInstance("HMACwithSHA384", providerName); + Mac.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA512() throws Exception { - Mac.getInstance("HMACwithSHA512", providerName); + Mac.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA224() throws Exception { - MessageDigest.getInstance("SHA224", providerName); + MessageDigest.getInstance("SHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA2() throws Exception { - MessageDigest.getInstance("SHA2", providerName); + MessageDigest.getInstance("SHA2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_2() throws Exception { - MessageDigest.getInstance("SHA-2", providerName); + MessageDigest.getInstance("SHA-2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA256() throws Exception { - MessageDigest.getInstance("SHA256", providerName); + MessageDigest.getInstance("SHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA3() throws Exception { - MessageDigest.getInstance("SHA3", providerName); + MessageDigest.getInstance("SHA3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_3() throws Exception { - MessageDigest.getInstance("SHA-3", providerName); + MessageDigest.getInstance("SHA-3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA384() throws Exception { - MessageDigest.getInstance("SHA384", providerName); + MessageDigest.getInstance("SHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA5() throws Exception { - MessageDigest.getInstance("SHA5", providerName); + MessageDigest.getInstance("SHA5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_5() throws Exception { - MessageDigest.getInstance("SHA-5", providerName); + MessageDigest.getInstance("SHA-5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA512() throws Exception { - MessageDigest.getInstance("SHA512", providerName); + MessageDigest.getInstance("SHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA2DRBG() throws Exception { - SecureRandom.getInstance("SHA2DRBG", providerName); + SecureRandom.getInstance("SHA2DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA5DRBG() throws Exception { - SecureRandom.getInstance("SHA5DRBG", providerName); + SecureRandom.getInstance("SHA5DRBG", getProviderName()); } // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_1withDSA() throws Exception { - // Signature.getInstance("SHA-1withDSA", providerName); + // Signature.getInstance("SHA-1withDSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_1_DSA() throws Exception { - // Signature.getInstance("SHA-1/DSA", providerName); + // Signature.getInstance("SHA-1/DSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA1_DSA() throws Exception { - // Signature.getInstance("SHA1/DSA", providerName); + // Signature.getInstance("SHA1/DSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_DSA() throws Exception { - // Signature.getInstance("SHA/DSA", providerName); + // Signature.getInstance("SHA/DSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_DSS() throws Exception { - // Signature.getInstance("DSS", providerName); + // Signature.getInstance("DSS", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHAwithDSA() throws Exception { - // Signature.getInstance("SHAwithDSA", providerName); + // Signature.getInstance("SHAwithDSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_DSAWithSHA1() throws Exception { - // Signature.getInstance("DSAWithSHA1", providerName); + // Signature.getInstance("DSAWithSHA1", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_OID_1_3_14_3_2_13() throws Exception { - // Signature.getInstance("OID.1.3.14.3.2.13", providerName); + // Signature.getInstance("OID.1.3.14.3.2.13", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_OID_1_3_14_3_2_27() throws Exception { - // Signature.getInstance("OID.1.3.14.3.2.27", providerName); + // Signature.getInstance("OID.1.3.14.3.2.27", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_224withDSA() throws Exception { - // Signature.getInstance("SHA-224withDSA", providerName); + // Signature.getInstance("SHA-224withDSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_224_DSA() throws Exception { - // Signature.getInstance("SHA-224/DSA", providerName); + // Signature.getInstance("SHA-224/DSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA224_DSA() throws Exception { - // Signature.getInstance("SHA224/DSA", providerName); + // Signature.getInstance("SHA224/DSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA2withDSA() throws Exception { - // Signature.getInstance("SHA2withDSA", providerName); + // Signature.getInstance("SHA2withDSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_2withDSA() throws Exception { - // Signature.getInstance("SHA-2withDSA", providerName); + // Signature.getInstance("SHA-2withDSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_256withDSA() throws Exception { - // Signature.getInstance("SHA-256withDSA", providerName); + // Signature.getInstance("SHA-256withDSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA_2_DSA() throws Exception { - // Signature.getInstance("SHA-2/DSA", providerName); + // Signature.getInstance("SHA-2/DSA", getProviderName()); // } // // //-------------------------------------------------------------------------- // // // // // public void testSignature_SHA2_DSA() throws Exception { - // Signature.getInstance("SHA2/DSA", providerName); + // Signature.getInstance("SHA2/DSA", getProviderName()); // } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_ECDSA() throws Exception { - Signature.getInstance("SHA224/ECDSA", providerName); + Signature.getInstance("SHA224/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withECDSA() throws Exception { - Signature.getInstance("SHA2withECDSA", providerName); + Signature.getInstance("SHA2withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_ECDSA() throws Exception { - Signature.getInstance("SHA2/ECDSA", providerName); + Signature.getInstance("SHA2/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withECDSA() throws Exception { - Signature.getInstance("SHA3withECDSA", providerName); + Signature.getInstance("SHA3withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_ECDSA() throws Exception { - Signature.getInstance("SHA3/ECDSA", providerName); + Signature.getInstance("SHA3/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withECDSA() throws Exception { - Signature.getInstance("SHA5withECDSA", providerName); + Signature.getInstance("SHA5withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_ECDSA() throws Exception { - Signature.getInstance("SHA5/ECDSA", providerName); + Signature.getInstance("SHA5/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + // public void testSignature_RSA() throws Exception { - // Signature.getInstance("RSA", providerName); + // Signature.getInstance("RSA", getProviderName()); // } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_RSA() throws Exception { - Signature.getInstance("SHA224/RSA", providerName); + Signature.getInstance("SHA224/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withRSA() throws Exception { - Signature.getInstance("SHA2withRSA", providerName); + Signature.getInstance("SHA2withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_RSA() throws Exception { - Signature.getInstance("SHA2/RSA", providerName); + Signature.getInstance("SHA2/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withRSA() throws Exception { - Signature.getInstance("SHA3withRSA", providerName); + Signature.getInstance("SHA3withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_RSA() throws Exception { - Signature.getInstance("SHA3/RSA", providerName); + Signature.getInstance("SHA3/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withRSA() throws Exception { - Signature.getInstance("SHA5withRSA", providerName); + Signature.getInstance("SHA5withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_RSA() throws Exception { - Signature.getInstance("SHA5/RSA", providerName); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAliases.class); - return suite; + Signature.getInstance("SHA5/RSA", getProviderName()); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAll.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAll.java index 7ce3cd54..3593157b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAll.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestAll.java @@ -11,32 +11,92 @@ import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; -@SelectClasses({TestAES.class, TestAES_128.class, TestAES256Interop.class, TestAESCCM.class, - TestAESCCM2.class, TestAESCCMParameters.class, TestAESCCMInteropBC.class, TestAESGCM.class, - TestAESGCMUpdate.class, TestAESGCM_128.class, TestAESGCM_ExtIV.class, - TestAESGCM_IntIV.class, TestAESCipherInputStreamExceptions.class, - TestAESCopySafe.class, TestAESGCMNonExpanding.class, TestAESGCMCICOWithGCM.class, - TestAESGCMSameBuffer.class, TestAESGCMWithByteBuffer.class, - TestAESGCMCICOWithGCMAndAAD.class, TestAESGCMLong.class, TestAESGCMBufferIV.class, - TestAliases.class, TestDHKeyPairGenerator.class, TestDH.class, TestDHMultiParty.class, - TestDHInteropSunJCE.class, TestDHKeyFactory.class, TestDSAKey.class, TestECDH.class, - TestECDHInteropSunEC.class, TestECDHKeyAgreementParamValidation.class, TestECDHMultiParty.class, - TestECDSASignature.class, TestECDSASignatureInteropSunEC.class, TestECKeyImport.class, - TestECKeyImportInteropSunEC.class, TestECKeyPairGenerator.class, TestHKDF.class, - TestHKDFInterop.class, TestHmacSHA224.class, TestHmacSHA224InteropSunJCE.class, - TestHmacSHA256.class, TestHmacSHA256InteropSunJCE.class, TestHmacSHA384.class, - TestHmacSHA384InteropSunJCE.class, TestHmacSHA512.class, TestHmacSHA512InteropSunJCE.class, - TestHmacSHA3_224.class, TestHmacSHA3_256.class, TestHmacSHA3_384.class, - TestHmacSHA3_512.class, TestImplementationClassesExist.class, - TestImplementationClassesFinal.class, TestInvalidArrayIndex.class, - TestPublicMethodsToMakeNonPublic.class, TestResetByteBuffer.class, TestRSA.class, TestRSA_2048.class, TestRSAKey.class, - TestRSAPSS.class, TestMiniRSAPSS2.class, TestRSASignature.class, - TestRSASignatureInteropSunRsaSign.class, TestRSASignatureChunkUpdate.class, - TestRSATypeCheckDefault.class, TestSHA1.class, TestSHA224.class, TestSHA256.class, - TestSHA384.class, TestSHA512.class, TestRSAPSSInterop2.class, TestRSAPSSInterop3.class, - TestSHA3_224.class, TestSHA3_256.class, TestSHA3_384.class, TestSHA3_512.class, - TestRSAKeyInterop.class, TestRSAKeyInteropBC.class, TestRSAPSS2.class, - TestFIPSVerifyOnlyTest.class, TestRSASignatureWithSpecificSize.class}) +@SelectClasses({ + TestAES_256.class, + TestAES.class, + TestAES256Interop.class, + TestAESCCM.class, + TestAESCCM2.class, + TestAESCCMInteropBC.class, + TestAESCCMParameters.class, + TestAESCipherInputStreamExceptions.class, + TestAESCopySafe.class, + TestAESGCM_128.class, + TestAESGCM_192.class, + TestAESGCM_256.class, + TestAESGCM_ExtIV.class, + TestAESGCM_IntIV.class, + TestAESGCM.class, + TestAESGCMBufferIV.class, + TestAESGCMCICOWithGCM.class, + TestAESGCMCICOWithGCMAndAAD.class, + TestAESGCMLong.class, + TestAESGCMNonExpanding.class, + TestAESGCMSameBuffer.class, + TestAESGCMUpdate.class, + TestAESGCMWithByteBuffer.class, + TestAliases.class, + TestDH.class, + TestDHInteropSunJCE.class, + TestDHKeyFactory.class, + TestDHKeyPairGenerator.class, + TestDHMultiParty.class, + TestDSAKey.class, + TestECDH.class, + TestECDHInteropSunEC.class, + TestECDHKeyAgreementParamValidation.class, + TestECDHMultiParty.class, + TestECDSASignature.class, + TestECDSASignatureInteropSunEC.class, + TestECKeyImport.class, + TestECKeyImportInteropSunEC.class, + TestECKeyPairGenerator.class, + TestFIPSVerifyOnlyTest.class, + TestHKDF.class, + TestHKDFInterop.class, + TestHmacSHA224.class, + TestHmacSHA224InteropSunJCE.class, + TestHmacSHA256.class, + TestHmacSHA256InteropSunJCE.class, + TestHmacSHA3_224.class, + TestHmacSHA3_256.class, + TestHmacSHA3_384.class, + TestHmacSHA3_512.class, + TestHmacSHA384.class, + TestHmacSHA384InteropSunJCE.class, + TestHmacSHA512.class, + TestHmacSHA512InteropSunJCE.class, + TestImplementationClassesExist.class, + TestImplementationClassesFinal.class, + TestInvalidArrayIndex.class, + TestMiniRSAPSS2.class, + TestPublicMethodsToMakeNonPublic.class, + TestResetByteBuffer.class, + TestRSA_2048.class, + TestRSA_4096.class, + TestRSA.class, + TestRSAKey.class, + TestRSAKeyInterop.class, + TestRSAKeyInteropBC.class, + TestRSAPSS.class, + TestRSAPSS2.class, + TestRSAPSSInterop2.class, + TestRSAPSSInterop3.class, + TestRSASignature.class, + TestRSASignatureChunkUpdate.class, + TestRSASignatureInteropSunRsaSign.class, + TestRSASignatureWithSpecificSize.class, + TestRSATypeCheckDefault.class, + TestSHA1.class, + TestSHA224.class, + TestSHA256.class, + TestSHA3_224.class, + TestSHA3_256.class, + TestSHA3_384.class, + TestSHA3_512.class, + TestSHA384.class, + TestSHA512.class +}) @Suite public class TestAll { diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20.java index 9edaa289..cdcf1b57 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestChaCha20; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestChaCha20 extends ibm.jceplus.junit.base.BaseTestChaCha20 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20 extends BaseTestChaCha20 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestChaCha20() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestChaCha20.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20Poly1305ChunkUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20Poly1305ChunkUpdate.java index abf1c3ea..90da0227 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20Poly1305ChunkUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestChaCha20Poly1305ChunkUpdate.java @@ -1,32 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ -package ibm.jceplus.junit.openjceplusfips; - -import junit.framework.Test; -import junit.framework.TestSuite; -public class TestChaCha20Poly1305ChunkUpdate - extends ibm.jceplus.junit.base.BaseTestChaCha20Poly1305ChunkUpdate { - static { - Utils.loadProviderTestSuite(); - } +package ibm.jceplus.junit.openjceplusfips; - public TestChaCha20Poly1305ChunkUpdate() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } +import ibm.jceplus.junit.base.BaseTestChaCha20Poly1305ChunkUpdate; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } +@TestInstance(Lifecycle.PER_CLASS) +public class TestChaCha20Poly1305ChunkUpdate extends BaseTestChaCha20Poly1305ChunkUpdate { - public static Test suite() { - TestSuite suite = new TestSuite( - ibm.jceplus.junit.openjceplusfips.TestChaCha20Poly1305ChunkUpdate.class); - return suite; + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDESede.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDESede.java index a4a3bb50..d9dc9eb4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDESede.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDESede.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,46 +8,24 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDESede; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDESede extends ibm.jceplus.junit.base.BaseTestDESede { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDESede extends BaseTestDESede { - private static final boolean PROVIDER_SUPPORTS_ENCRYPT = true; - - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestDESede() { - super(Utils.TEST_SUITE_PROVIDER_NAME, PROVIDER_SUPPORTS_ENCRYPT); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDESede.class); - return suite; - } - - // -------------------------------------------------------------------------- - // This method is to check whether a mode is valid for the cipher - // but not supported by a given provider. - // + /** + * This method is to check whether a mode is valid for the cipher + * but not supported by a given provider. + */ @Override public boolean isModeValidButUnsupported(String mode) { if (mode.equalsIgnoreCase("CFB") || mode.equalsIgnoreCase("CFB64") @@ -58,4 +36,3 @@ public boolean isModeValidButUnsupported(String mode) { return super.isModeValidButUnsupported(mode); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDH.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDH.java index 0794c6b2..38bfc2fc 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDH; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDH extends ibm.jceplus.junit.base.BaseTestDH { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDH extends BaseTestDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDH.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHInteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHInteropSunJCE.java index 7c9bcf95..658d6270 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHInteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHInteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,19 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHInteropSunJCE extends ibm.jceplus.junit.base.BaseTestDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHInteropSunJCE extends BaseTestDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHInteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHInteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyFactory.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyFactory.java index 0201fc9a..690731f3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyFactory.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHKeyFactory; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHKeyFactory extends ibm.jceplus.junit.base.BaseTestDHKeyFactory { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHKeyFactory extends BaseTestDHKeyFactory { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHKeyFactory() { - super(Utils.PROVIDER_SunJCE, Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHKeyFactory.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyPairGenerator.java index d3149c2b..cb4135c4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHKeyPairGenerator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHKeyPairGenerator extends ibm.jceplus.junit.base.BaseTestDHKeyPairGenerator { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHKeyPairGenerator extends BaseTestDHKeyPairGenerator { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHKeyPairGenerator() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHKeyPairGenerator.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHMultiParty.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHMultiParty.java index 9b22ff1d..2db4eb17 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDHMultiParty; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDHMultiParty extends ibm.jceplus.junit.base.BaseTestDHMultiParty { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDHMultiParty extends BaseTestDHMultiParty { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDHMultiParty() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDHMultiParty.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSAKey.java index c1d0c424..427e8180 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSAKey.java @@ -8,16 +8,19 @@ package ibm.jceplus.junit.openjceplusfips; +import ibm.jceplus.junit.base.BaseTestDSAKey; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDSAKey extends ibm.jceplus.junit.base.BaseTestDSAKey { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDSAKey extends BaseTestDSAKey { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestDSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } @Disabled("DSA key generation is not available in FIPS mode.") @@ -32,4 +35,3 @@ public void testDSAKeyGen_2048() throws Exception {} @Override public void testDSAKeyGenFromParams_1024() throws Exception {} } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignature.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignature.java index 4a394df2..d93270c1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignature.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignature.java @@ -7,6 +7,7 @@ */ package ibm.jceplus.junit.openjceplusfips; + import ibm.jceplus.junit.base.BaseTestDSASignature; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignatureInteropSUN.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignatureInteropSUN.java index 479c2335..3380e60b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignatureInteropSUN.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestDSASignatureInteropSUN.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestDSASignatureInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestDSASignatureInteropSUN extends ibm.jceplus.junit.base.BaseTestDSASignatureInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestDSASignatureInteropSUN extends BaseTestDSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestDSASignatureInteropSUN() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SUN); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestDSASignatureInteropSUN.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SUN); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDH.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDH.java index fc9d04aa..aef7a24a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDH; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDH extends ibm.jceplus.junit.base.BaseTestECDH { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDH extends BaseTestECDH { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDH.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHInteropSunEC.java index 2063c4c2..66705b64 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDHInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDHInteropSunEC extends ibm.jceplus.junit.base.BaseTestECDHInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDHInteropSunEC extends BaseTestECDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDHInteropSunEC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHMultiParty.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHMultiParty.java index 1d62c0e3..4d190a6e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHMultiParty.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDHMultiParty.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDHMultiParty; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDHMultiParty extends ibm.jceplus.junit.base.BaseTestECDHMultiParty { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDHMultiParty extends BaseTestECDHMultiParty { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHMultiParty() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDHMultiParty.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDSASignatureInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDSASignatureInteropSunEC.java index 118fc79c..4301cbda 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDSASignatureInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECDSASignatureInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECDSASignatureInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECDSASignatureInteropSunEC - extends ibm.jceplus.junit.base.BaseTestECDSASignatureInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECDSASignatureInteropSunEC extends BaseTestECDSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDSASignatureInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECDSASignatureInteropSunEC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImport.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImport.java index e8e75f35..ce72047c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImport.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImport.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECKeyImport; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECKeyImport extends ibm.jceplus.junit.base.BaseTestECKeyImport { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECKeyImport extends BaseTestECKeyImport { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECKeyImport() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECKeyImport.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImportInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImportInteropSunEC.java index d1084b4c..33eb460f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImportInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyImportInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECKeyImportInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECKeyImportInteropSunEC extends ibm.jceplus.junit.base.BaseTestECKeyImportInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECKeyImportInteropSunEC extends BaseTestECKeyImportInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECKeyImportInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECKeyImportInteropSunEC.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyPairGenerator.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyPairGenerator.java index 8be10ea6..8e8cdbaf 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyPairGenerator.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestECKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestECKeyPairGenerator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestECKeyPairGenerator extends ibm.jceplus.junit.base.BaseTestECKeyPairGenerator { +@TestInstance(Lifecycle.PER_CLASS) +public class TestECKeyPairGenerator extends BaseTestECKeyPairGenerator { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECKeyPairGenerator() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestECKeyPairGenerator.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestFIPSVerifyOnlyTest.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestFIPSVerifyOnlyTest.java index d8df7fa0..a4f6b021 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestFIPSVerifyOnlyTest.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestFIPSVerifyOnlyTest.java @@ -1,12 +1,14 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips; +import ibm.jceplus.junit.base.BaseTestJunit5; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -14,25 +16,22 @@ import java.security.PublicKey; import java.security.Signature; import java.security.spec.X509EncodedKeySpec; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class TestFIPSVerifyOnlyTest extends ibm.jceplus.junit.base.BaseTest { +@TestInstance(Lifecycle.PER_CLASS) +public class TestFIPSVerifyOnlyTest extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - public TestFIPSVerifyOnlyTest() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testFIPSDSAVerifyOnlyTest() { try { assertTrue(doVerify("DSA", "SHA256withDSA", 1024, "OpenJCEPlus", "OpenJCEPlusFIPS")); @@ -43,9 +42,7 @@ public void testFIPSDSAVerifyOnlyTest() { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testFIPSECDSAVerifyOnlyTest() { try { assertTrue(doVerify("EC", "SHA256withECDSA", 192, "OpenJCEPlus", "OpenJCEPlusFIPS")); @@ -55,9 +52,7 @@ public void testFIPSECDSAVerifyOnlyTest() { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testFIPSRSAVerifyOnlyTest() { try { assertTrue(doVerify("RSA", "SHA256withRSA", 1024, "OpenJCEPlus", "OpenJCEPlusFIPS")); @@ -67,10 +62,7 @@ public void testFIPSRSAVerifyOnlyTest() { } } - //-------------------------------------------------------------------------- - // - // - public boolean doVerify(String keyAlg, String sigAlg, int keySize, String keygenProv, + private boolean doVerify(String keyAlg, String sigAlg, int keySize, String keygenProv, String testProv) { Signature signature1 = null; KeyFactory kf2; @@ -118,19 +110,4 @@ public boolean doVerify(String keyAlg, String sigAlg, int keySize, String keygen } - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestFIPSVerifyOnlyTest.class); - return suite; - } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDF.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDF.java index 60f9a6a6..ac15ccf1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDF.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHKDF; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHKDF extends ibm.jceplus.junit.base.BaseTestHKDF { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHKDF extends BaseTestHKDF { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHKDF() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHKDF.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDFInterop.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDFInterop.java index e4951f54..63520a63 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDFInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHKDFInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,48 +8,19 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHKDFInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHKDFInterop extends ibm.jceplus.junit.base.BaseTestHKDFInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHKDFInterop extends BaseTestHKDFInterop { - //-------------------------------------------------------------------------- - // - // - - - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - - //-------------------------------------------------------------------------- - // - // - public TestHKDFInterop() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHKDFInterop.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5.java index 2543835e..3d33b28d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacMD5; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacMD5 extends ibm.jceplus.junit.base.BaseTestHmacMD5 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacMD5 extends BaseTestHmacMD5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacMD5.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5InteropSunJCE.java index 30e13e41..0fa5483b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacMD5InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacMD5Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacMD5InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacMD5Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacMD5InteropSunJCE extends BaseTestHmacMD5Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacMD5InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1.java index 00634fa6..778b139c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA1; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA1 extends ibm.jceplus.junit.base.BaseTestHmacSHA1 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA1 extends BaseTestHmacSHA1 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA1() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA1.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1InteropSunJCE.java index de7be9e6..55b7feec 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA1InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA1Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA1InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA1Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA1InteropSunJCE extends BaseTestHmacSHA1Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA1InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA1InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224.java index a32a3076..629f03a1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA224 extends ibm.jceplus.junit.base.BaseTestHmacSHA224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA224 extends BaseTestHmacSHA224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224InteropSunJCE.java index 972b276c..0bbe6734 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA224InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA224Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA224InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA224Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA224InteropSunJCE extends BaseTestHmacSHA224Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA224InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA224InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256.java index 9f05ada2..77c7f19a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA256 extends ibm.jceplus.junit.base.BaseTestHmacSHA256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA256 extends BaseTestHmacSHA256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256InteropSunJCE.java index 8de23945..827328ae 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA256InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA256Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA256InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA256Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA256InteropSunJCE extends BaseTestHmacSHA256Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA256InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384.java index 2bb0aec2..d3bd9853 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA384; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA384 extends ibm.jceplus.junit.base.BaseTestHmacSHA384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA384 extends BaseTestHmacSHA384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384InteropSunJCE.java index 36958bcc..dae4f7a1 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA384InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA384Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA384InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA384Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA384InteropSunJCE extends BaseTestHmacSHA384Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA384InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA384InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_224.java index 68ef5d17..65ecf7ff 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_224.java @@ -1,44 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_224 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_224 extends BaseTestHmacSHA3_224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_256.java index 6b3c043a..902c388e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_256.java @@ -1,44 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_256 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_256 extends BaseTestHmacSHA3_256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_384.java index 095bb225..9002f546 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_384.java @@ -1,44 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_384; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_384 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_384 extends BaseTestHmacSHA3_384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_512.java index 7f0ef2f4..aafec0be 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA3_512.java @@ -1,44 +1,24 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA3_512; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_512 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_512 extends BaseTestHmacSHA3_512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA3_512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512.java index 820e5b1d..e8498fd0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA512; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA512 extends ibm.jceplus.junit.base.BaseTestHmacSHA512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA512 extends BaseTestHmacSHA512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512InteropSunJCE.java index 5dedb200..8e1f40a3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestHmacSHA512InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestHmacSHA512Interop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA512InteropSunJCE extends ibm.jceplus.junit.base.BaseTestHmacSHA512Interop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA512InteropSunJCE extends BaseTestHmacSHA512Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA512InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestHmacSHA512InteropSunJCE.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesExist.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesExist.java index 503d3d59..73944879 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesExist.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesExist.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestImplementationClassesExist; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestImplementationClassesExist - extends ibm.jceplus.junit.base.BaseTestImplementationClassesExist { +@TestInstance(Lifecycle.PER_CLASS) +public class TestImplementationClassesExist extends BaseTestImplementationClassesExist { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestImplementationClassesExist() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestImplementationClassesExist.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesFinal.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesFinal.java index 30b38ee1..701c5186 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesFinal.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestImplementationClassesFinal.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestImplementationClassesFinal; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestImplementationClassesFinal - extends ibm.jceplus.junit.base.BaseTestImplementationClassesFinal { +@TestInstance(Lifecycle.PER_CLASS) +public class TestImplementationClassesFinal extends BaseTestImplementationClassesFinal { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestImplementationClassesFinal() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestImplementationClassesFinal.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestInvalidArrayIndex.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestInvalidArrayIndex.java index de643cde..322a34dc 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestInvalidArrayIndex.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestInvalidArrayIndex.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestInvalidArrayIndex; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestInvalidArrayIndex extends ibm.jceplus.junit.base.BaseTestInvalidArrayIndex { +@TestInstance(Lifecycle.PER_CLASS) +public class TestInvalidArrayIndex extends BaseTestInvalidArrayIndex { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestInvalidArrayIndex() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestInvalidArrayIndex.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMD5.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMD5.java index 0e5c3e04..37c7ca56 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestMD5; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestMD5 extends ibm.jceplus.junit.base.BaseTestMD5 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestMD5 extends BaseTestMD5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMD5() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMD5.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setAlgorithm("MD5"); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMiniRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMiniRSAPSS2.java index 7ce1d1a5..c8cddedb 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMiniRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestMiniRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import ibm.jceplus.junit.openjceplus.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestMiniRSAPSS2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestMiniRSAPSS2 extends ibm.jceplus.junit.base.BaseTestMiniRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestMiniRSAPSS2 extends BaseTestMiniRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestMiniRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - // -------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestMiniRSAPSS2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestPublicMethodsToMakeNonPublic.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestPublicMethodsToMakeNonPublic.java index 1d2ac2d6..f53b8f26 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestPublicMethodsToMakeNonPublic.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestPublicMethodsToMakeNonPublic.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,47 +8,22 @@ package ibm.jceplus.junit.openjceplusfips; +import ibm.jceplus.junit.base.BaseTestPublicMethodsToMakeNonPublic; import java.lang.reflect.Method; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestPublicMethodsToMakeNonPublic - extends ibm.jceplus.junit.base.BaseTestPublicMethodsToMakeNonPublic { +@TestInstance(Lifecycle.PER_CLASS) +public class TestPublicMethodsToMakeNonPublic extends BaseTestPublicMethodsToMakeNonPublic { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestPublicMethodsToMakeNonPublic() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // public boolean isMethodMeantToBePublicAndExplicitlyCallableByUsers(Method method) { return false; } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestPublicMethodsToMakeNonPublic.class); - return suite; - } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA.java index be474fd3..04c6c821 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA extends ibm.jceplus.junit.base.BaseTestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSA() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSA(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKey.java index 15b1af41..ca118abf 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKey.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAKey; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAKey extends ibm.jceplus.junit.base.BaseTestRSAKey { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAKey extends BaseTestRSAKey { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAKey.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInterop.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInterop.java index 3137abac..27a62ce4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,45 +8,19 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAKeyInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAKeyInterop extends ibm.jceplus.junit.base.BaseTestRSAKeyInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAKeyInterop extends BaseTestRSAKeyInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - try { - Utils.loadProviderOpenJCEPlusFIPS(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); + setKeySize(2048); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInterop() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAKeyInterop.class); - return suite; - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInteropBC.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInteropBC.java index 5f33cae4..9aed0277 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInteropBC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAKeyInteropBC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,57 +8,20 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAKeyInteropBC; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAKeyInteropBC extends ibm.jceplus.junit.base.BaseTestRSAKeyInteropBC { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAKeyInteropBC extends BaseTestRSAKeyInteropBC { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() throws Exception { Utils.loadProviderTestSuite(); - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - try { - Utils.loadProviderBC(); - } catch (Exception e) { - e.printStackTrace(System.out); - System.exit(1); - } - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInteropBC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKeyInteropBC(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_BC, keySize); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAKeyInteropBC.class); - return suite; + Utils.loadProviderBC(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_BC); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS.java index 7f12df09..386c1ec0 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSS; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS extends ibm.jceplus.junit.base.BaseTestRSAPSS { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS extends BaseTestRSAPSS { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSS.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS2.java index 2c40f421..3f7b1672 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSS2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS2 extends ibm.jceplus.junit.base.BaseTestRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS2 extends BaseTestRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSS2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop.java index d5fa9077..33b377f6 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSSInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop extends BaseTestRSAPSSInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSSInterop.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop2.java index bb1f7545..b43a29c3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSSInterop2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop2 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop2 extends BaseTestRSAPSSInterop2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSSInterop2.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop3.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop3.java index 6cccd213..603e2087 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop3.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSAPSSInterop3.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSAPSSInterop3; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop3 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop3 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop3 extends BaseTestRSAPSSInterop3 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop3() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSAPSSInterop3.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignature.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignature.java index 0d8f8aaa..fe591fd3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignature.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignature.java @@ -15,6 +15,7 @@ @TestInstance(Lifecycle.PER_CLASS) public class TestRSASignature extends BaseTestRSASignature { + @BeforeAll public void beforeAll() { Utils.loadProviderTestSuite(); diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureChunkUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureChunkUpdate.java index 4ac134cf..e622d920 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureChunkUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureChunkUpdate.java @@ -1,12 +1,12 @@ /* - * Copyright IBM Corp. 2024 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ -package ibm.jceplus.junit.openjceplusfips; +package ibm.jceplus.junit.openjceplusfips; import ibm.jceplus.junit.base.BaseTestRSASignatureChunkUpdate; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureInteropSunRsaSign.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureInteropSunRsaSign.java index 0492290e..428fd8b5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureInteropSunRsaSign.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSASignatureInteropSunRsaSign.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,19 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSASignatureInterop; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSASignatureInteropSunRsaSign - extends ibm.jceplus.junit.base.BaseTestRSASignatureInterop { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSASignatureInteropSunRsaSign extends BaseTestRSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSASignatureInteropSunRsaSign() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign, 2048); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSASignatureInteropSunRsaSign.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDefault.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDefault.java index 76b0d059..ee4207c9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDefault.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDefault.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -// If not specified, the default RSA type check value is enabled -// -public class TestRSATypeCheckDefault extends ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSATypeCheckDefault extends BaseTestRSATypeCheckEnabled { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSATypeCheckDefault() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSATypeCheckDefault.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDisabled.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDisabled.java index f378295b..bedd2495 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDisabled.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckDisabled.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,55 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSATypeCheckDisabled; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -/** - * - * This test should not be included in the TestAll test suite and should be - * run as a standalone testcase. This testcase sets a System property to - * modify the behavior of the OpenJCEPlus provider. This - * property value is read by the provider once during static initialization. - */ -public class TestRSATypeCheckDisabled extends ibm.jceplus.junit.base.BaseTestRSATypeCheckDisabled { - // -------------------------------------------------------------------------- - // - // - static { - try { - System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "false"); - } catch (Throwable t) { - t.printStackTrace(System.out); - } - } +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSATypeCheckDisabled extends BaseTestRSATypeCheckDisabled { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { + System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "false"); Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSATypeCheckDisabled() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSATypeCheckDisabled.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckEnabled.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckEnabled.java index 2a593b14..ad9c5308 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckEnabled.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSATypeCheckEnabled.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,55 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -/** - * - * This test should not be included in the TestAll test suite and should be - * run as a standalone testcase. This testcase sets a System property to - * modify the behavior of the OpenJCEPlus provider. This - * property value is read by the provider once during static initialization. - */ -public class TestRSATypeCheckEnabled extends ibm.jceplus.junit.base.BaseTestRSATypeCheckEnabled { - // -------------------------------------------------------------------------- - // - // - static { - try { - System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "true"); - } catch (Throwable t) { - t.printStackTrace(System.out); - } - } +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSATypeCheckEnabled extends BaseTestRSATypeCheckEnabled { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { + System.setProperty("com.ibm.crypto.provider.DoRSATypeChecking", "true"); Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSATypeCheckEnabled() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSATypeCheckEnabled.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_1024.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_1024.java index 9de2a6b4..344a5ff3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_1024.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_1024.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_1024 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_1024 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 1024; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_1024() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_1024.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(1024); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_2048.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_2048.java index b4d40d55..a5527916 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_2048.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_2048.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_2048 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_2048 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 2048; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_2048() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_2048.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_4096.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_4096.java index cfc6b2d4..f84d856f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_4096.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestRSA_4096.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestRSA; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSA_4096 extends TestRSA { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSA_4096 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 4096; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_4096() throws Exception { - super(KEY_SIZE); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestRSA_4096.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(4096); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA1.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA1.java index f520b3a5..5476f145 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA1.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA1; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA1 extends ibm.jceplus.junit.base.BaseTestSHA1 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA1 extends BaseTestSHA1 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA1() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA1.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA224.java index 13228197..8ca6e2ea 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA224.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA224; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA224 extends ibm.jceplus.junit.base.BaseTestSHA224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA224 extends BaseTestSHA224 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA256.java index 2750edf3..aa3b1f9d 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA256; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA256 extends ibm.jceplus.junit.base.BaseTestSHA256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA256 extends BaseTestSHA256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA384.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA384.java index 29ab4b8c..04bf0ea2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA384; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA384 extends ibm.jceplus.junit.base.BaseTestSHA384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA384 extends BaseTestSHA384 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_224.java index 1887781d..29928f60 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_224.java @@ -1,45 +1,23 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ - package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_224KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_224 extends ibm.jceplus.junit.base.BaseTestSHA3_224KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_224 extends BaseTestSHA3_224KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_224.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_256.java index c8a4e006..9fbc1e11 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_256KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_256 extends ibm.jceplus.junit.base.BaseTestSHA3_256KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_256 extends BaseTestSHA3_256KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_256.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_384.java index 23f21a51..182b5b95 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_384KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_384 extends ibm.jceplus.junit.base.BaseTestSHA3_384KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_384 extends BaseTestSHA3_384KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_384.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_512.java index bd3e1f11..fd791183 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA3_512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA3_512KAT; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_512 extends ibm.jceplus.junit.base.BaseTestSHA3_512KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_512 extends BaseTestSHA3_512KAT { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA3_512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA512.java index 329447d2..3c7205a3 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/TestSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,38 +8,17 @@ package ibm.jceplus.junit.openjceplusfips; -import junit.framework.Test; -import junit.framework.TestSuite; +import ibm.jceplus.junit.base.BaseTestSHA512; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA512 extends ibm.jceplus.junit.base.BaseTestSHA512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA512 extends BaseTestSHA512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA512.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/Utils.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/Utils.java index c6dcab21..b4d1c48e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/Utils.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,14 +10,8 @@ abstract public class Utils extends ibm.jceplus.junit.base.BaseUtils { - //-------------------------------------------------------------------------- - // - // public static final String TEST_SUITE_PROVIDER_NAME = PROVIDER_OpenJCEPlusFIPS; - //-------------------------------------------------------------------------- - // - // public static java.security.Provider loadProviderTestSuite() { try { return loadProviderOpenJCEPlusFIPS(); diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/integration/TestTLS.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/integration/TestTLS.java index 8d374fdd..803f60ab 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/integration/TestTLS.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/integration/TestTLS.java @@ -90,5 +90,4 @@ public static void cleanup() throws Exception { public void testTLS(String tlsProtocol, String keyType, String cipher) throws Exception { runServerClient(tlsProtocol, keyType, cipher); } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCipherInputStreamExceptions.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCipherInputStreamExceptions.java index fd6c8fdf..8b53bb0b 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCipherInputStreamExceptions.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCipherInputStreamExceptions.java @@ -9,7 +9,7 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestAESCipherInputStreamExceptions; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; @@ -23,4 +23,3 @@ public void beforeAll() { setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCopySafe.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCopySafe.java index 2f3811d7..56e7b945 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCopySafe.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESCopySafe.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,38 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESCopySafe; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESCopySafe extends BaseTestAESCopySafe { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESCopySafe() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAESCopySafe.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESCopySafe() throws Exception { - System.out.println("executing testAESCopySafe"); - BaseTestAESCopySafe bt = new BaseTestAESCopySafe(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCM.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCM.java index 90061e73..d29e7ba6 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCM.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCM.java @@ -1,46 +1,25 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCM; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMCICOWithGCM extends BaseTestAESGCMCICOWithGCM { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCM() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestAESGCMCICOWithGCM.class - .getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMCICOWithGCM() throws Exception { - System.out.println("executing testAESGCMCICOWithGCM"); - BaseTestAESGCMCICOWithGCM bt = new BaseTestAESGCMCICOWithGCM(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCMAndAAD.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCMAndAAD.java index 97a10c09..d2bd5ed2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCMAndAAD.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMCICOWithGCMAndAAD.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,18 @@ package ibm.jceplus.junit.openjceplusfips.multithread; +import ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD; import ibm.jceplus.junit.openjceplusfips.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMCICOWithGCMAndAAD - extends ibm.jceplus.junit.base.BaseTestAESGCMCICOWithGCMAndAAD { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMCICOWithGCMAndAAD extends BaseTestAESGCMCICOWithGCMAndAAD { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMCICOWithGCMAndAAD() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMCICOWithGCMAndAAD.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMLong.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMLong.java index 85efc5d2..25ca877c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMLong.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMLong.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,36 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMLong; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMLong extends BaseTestAESGCMLong { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMLong() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplus.multithread.TestAESGCMLong.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMLong() throws Exception { - BaseTestAESGCMLong bt = new BaseTestAESGCMLong(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMNonExpanding.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMNonExpanding.java index 840bd65f..e912a054 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMNonExpanding.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMNonExpanding.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,18 @@ package ibm.jceplus.junit.openjceplusfips.multithread; +import ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding; import ibm.jceplus.junit.openjceplusfips.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMNonExpanding extends ibm.jceplus.junit.base.BaseTestAESGCMNonExpanding { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMNonExpanding extends BaseTestAESGCMNonExpanding { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMNonExpanding() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMNonExpanding.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMSameBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMSameBuffer.java index c0df298b..f5eb91f8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMSameBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMSameBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMSameBuffer; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMSameBuffer extends BaseTestAESGCMSameBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMSameBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {TestAESGCMSameBuffer.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMSameBuffer() throws Exception { - System.out.println("executing testAESGCMSameBuffer"); - BaseTestAESGCMSameBuffer bt = new BaseTestAESGCMSameBuffer(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMUpdate.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMUpdate.java index c37d465f..c87604b5 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMUpdate.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,38 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMUpdate; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMUpdate extends BaseTestAESGCMUpdate { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMUpdate() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAESGCMUpdate.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void TestAESGCMUpdate() throws Exception { - System.out.println("executing testAESGCMUpdate"); - BaseTestAESGCMUpdate bt = new BaseTestAESGCMUpdate(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithByteBuffer.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithByteBuffer.java index 2af2b2f5..23ac1d0a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithByteBuffer.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithByteBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,16 @@ import ibm.jceplus.junit.base.BaseTestAESGCMWithByteBuffer; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCMWithByteBuffer extends BaseTestAESGCMWithByteBuffer { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithByteBuffer() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {TestAESGCMWithByteBuffer.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCMSameBuffer() throws Exception { - System.out.println("executing testAESGCMWithByteBuffer"); - BaseTestAESGCMWithByteBuffer bt = new BaseTestAESGCMWithByteBuffer(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithKeyAndIvCheck.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithKeyAndIvCheck.java index d3406989..2205f597 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithKeyAndIvCheck.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCMWithKeyAndIvCheck.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,40 +8,18 @@ package ibm.jceplus.junit.openjceplusfips.multithread; +import ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck; import ibm.jceplus.junit.openjceplusfips.Utils; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAESGCMWithKeyAndIvCheck - extends ibm.jceplus.junit.base.BaseTestAESGCMWithKeyAndIvCheck { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAESGCMWithKeyAndIvCheck extends BaseTestAESGCMWithKeyAndIvCheck { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestAESGCMWithKeyAndIvCheck() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAESGCMWithKeyAndIvCheck.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_128.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_128.java index f9640cb6..c6972a71 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_128.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,44 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAESGCM; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_128 extends BaseTestAESGCM { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAESGCM_128() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAESGCM_128.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAESGCM_128"); - BaseTestAESGCM bs = new BaseTestAESGCM(providerName, 128); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_192.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_192.java index 13961c49..0b7352a7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_192.java @@ -1,53 +1,27 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestAESGCM; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_192 extends BaseTestAESGCM { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAESGCM_192() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAESGCM_192.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAESGCM_192"); - BaseTestAESGCM bs = new BaseTestAESGCM(providerName, 192); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_256.java index 9e890a65..5406b31f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAESGCM_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,44 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAESGCM; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAESGCM_256 extends BaseTestAESGCM { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAESGCM_256() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAESGCM_256.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAESGCM_256() throws Exception { - System.out.println("executing testAESGCM_256"); - BaseTestAESGCM bs = new BaseTestAESGCM(providerName, 256); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_128.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_128.java index b511c8d6..09c5c00f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_128.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_128.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,53 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAES; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAES_128 extends BaseTestAES { - static boolean first = true; - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 128; - - // -------------------------------------------------------------------------- - // - // - public TestAES_128() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(128); } - - // -------------------------------------------------------------------------- - // - // - public TestAES_128(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAES_128.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAES_128"); - BaseTestAES bs = new BaseTestAES(providerName, 128); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_192.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_192.java index eeb0c8d2..f86cb5b8 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_192.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_192.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,53 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAES; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestAES_192 extends ibm.jceplus.junit.base.BaseTestAES { - static boolean first = true; - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 192; - - // -------------------------------------------------------------------------- - // - // - public TestAES_192() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); +@TestInstance(Lifecycle.PER_CLASS) +public class TestAES_192 extends BaseTestAES { + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(192); } - - // -------------------------------------------------------------------------- - // - // - public TestAES_192(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAES_192.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testAES_192() throws Exception { - System.out.println("executing testAES_192"); - ibm.jceplus.junit.base.BaseTestAES bs = new BaseTestAES(providerName, 192); - bs.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_256.java index 04b43443..804c54cd 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAES_256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,43 +10,17 @@ import ibm.jceplus.junit.base.BaseTestAES; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestAES_256 extends BaseTestAES { - static boolean first = true; - // -------------------------------------------------------------------------- - // - // - static { - Utils.loadProviderTestSuite(); - } - - // -------------------------------------------------------------------------- - // - // - public TestAES_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - - } - - // -------------------------------------------------------------------------- - // - // - public TestAES_256(int keySize) throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, keySize); - } - public void testAES_256() throws Exception { - BaseTestAES bs = new BaseTestAES(providerName, 256); - System.out.println("executing testAES_256"); - bs.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAES_256.class.getName()}; - junit.textui.TestRunner.main(nargs); + @BeforeAll + public void beforeAll() { + Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(256); } - - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAliases.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAliases.java index 8a4f38a2..ceb40d7e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAliases.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestAliases.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,7 +8,7 @@ package ibm.jceplus.junit.openjceplusfips.multithread; -import ibm.jceplus.junit.base.BaseTest; +import ibm.jceplus.junit.base.BaseTestJunit5; import ibm.jceplus.junit.openjceplusfips.Utils; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; @@ -22,33 +22,27 @@ import javax.crypto.KeyGenerator; import javax.crypto.Mac; import javax.crypto.SecretKeyFactory; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class TestAliases extends BaseTest { +@TestInstance(Lifecycle.PER_CLASS) +public class TestAliases extends BaseTestJunit5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void setUp() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - //-------------------------------------------------------------------------- - // - // - public TestAliases() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_3DES() throws Exception { try { - AlgorithmParameters.getInstance("3DES", providerName); + AlgorithmParameters.getInstance("3DES", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: 3DES for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -57,28 +51,22 @@ public void testAlgParams_3DES() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParams_AESGCM() throws Exception { - AlgorithmParameters.getInstance("AESGCM", providerName); + AlgorithmParameters.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testAlgParamGen_AESGCM() throws Exception { - AlgorithmParameterGenerator.getInstance("AESGCM", providerName); + AlgorithmParameterGenerator.getInstance("AESGCM", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testCipher_3DES() throws Exception { try { - Cipher.getInstance("3DES", providerName); + Cipher.getInstance("3DES", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("No such algorithm: 3DES", nsae.getMessage()); return; } else { @@ -87,21 +75,17 @@ public void testCipher_3DES() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyFactory_DSAKeyFactory() throws Exception { - KeyFactory.getInstance("DSAKeyFactory", providerName); + KeyFactory.getInstance("DSAKeyFactory", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_3DES() throws Exception { try { - KeyGenerator.getInstance("3DES", providerName); + KeyGenerator.getInstance("3DES", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: 3DES for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -110,14 +94,12 @@ public void testKeyGen_3DES() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA1() throws Exception { try { - KeyGenerator.getInstance("HMACwithSHA1", providerName); + KeyGenerator.getInstance("HMACwithSHA1", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: HMACwithSHA1 for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -126,42 +108,32 @@ public void testKeyGen_HMACwithSHA1() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA224() throws Exception { - KeyGenerator.getInstance("HMACwithSHA224", providerName); + KeyGenerator.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA256() throws Exception { - KeyGenerator.getInstance("HMACwithSHA256", providerName); + KeyGenerator.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA384() throws Exception { - KeyGenerator.getInstance("HMACwithSHA384", providerName); + KeyGenerator.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyGen_HMACwithSHA512() throws Exception { - KeyGenerator.getInstance("HMACwithSHA512", providerName); + KeyGenerator.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testKeyPairGen_OID_1_3_14_3_2_12() throws Exception { try { - KeyPairGenerator.getInstance("OID.1.3.14.3.2.12", providerName); + KeyPairGenerator.getInstance("OID.1.3.14.3.2.12", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: OID.1.3.14.3.2.12 for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -170,21 +142,16 @@ public void testKeyPairGen_OID_1_3_14_3_2_12() throws Exception { } } - //-------------------------------------------------------------------------- - // - // //public void testKeyStore_PKCS12KS() throws Exception { - // KeyStore.getInstance("PKCS12KS", providerName); + // KeyStore.getInstance("PKCS12KS", getProviderName()); //} - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA1() throws Exception { try { - Mac.getInstance("HMACwithSHA1", providerName); + Mac.getInstance("HMACwithSHA1", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: HMACwithSHA1 for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -193,112 +160,82 @@ public void testMac_HMACwithSHA1() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA224() throws Exception { - Mac.getInstance("HMACwithSHA224", providerName); + Mac.getInstance("HMACwithSHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA256() throws Exception { - Mac.getInstance("HMACwithSHA256", providerName); + Mac.getInstance("HMACwithSHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA384() throws Exception { - Mac.getInstance("HMACwithSHA384", providerName); + Mac.getInstance("HMACwithSHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMac_HMACwithSHA512() throws Exception { - Mac.getInstance("HMACwithSHA512", providerName); + Mac.getInstance("HMACwithSHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA224() throws Exception { - MessageDigest.getInstance("SHA224", providerName); + MessageDigest.getInstance("SHA224", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA2() throws Exception { - MessageDigest.getInstance("SHA2", providerName); + MessageDigest.getInstance("SHA2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_2() throws Exception { - MessageDigest.getInstance("SHA-2", providerName); + MessageDigest.getInstance("SHA-2", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA256() throws Exception { - MessageDigest.getInstance("SHA256", providerName); + MessageDigest.getInstance("SHA256", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA3() throws Exception { - MessageDigest.getInstance("SHA3", providerName); + MessageDigest.getInstance("SHA3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_3() throws Exception { - MessageDigest.getInstance("SHA-3", providerName); + MessageDigest.getInstance("SHA-3", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA384() throws Exception { - MessageDigest.getInstance("SHA384", providerName); + MessageDigest.getInstance("SHA384", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA5() throws Exception { - MessageDigest.getInstance("SHA5", providerName); + MessageDigest.getInstance("SHA5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA_5() throws Exception { - MessageDigest.getInstance("SHA-5", providerName); + MessageDigest.getInstance("SHA-5", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testMessageDigest_SHA512() throws Exception { - MessageDigest.getInstance("SHA512", providerName); + MessageDigest.getInstance("SHA512", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecretKeyFactory_3DES() throws Exception { try { - SecretKeyFactory.getInstance("3DES", providerName); + SecretKeyFactory.getInstance("3DES", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: 3DES for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -307,28 +244,22 @@ public void testSecretKeyFactory_3DES() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA2DRBG() throws Exception { - SecureRandom.getInstance("SHA2DRBG", providerName); + SecureRandom.getInstance("SHA2DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSecureRandom_SHA5DRBG() throws Exception { - SecureRandom.getInstance("SHA5DRBG", providerName); + SecureRandom.getInstance("SHA5DRBG", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withDSA() throws Exception { try { - Signature.getInstance("SHA-1withDSA", providerName); + Signature.getInstance("SHA-1withDSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA-1withDSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -337,14 +268,12 @@ public void testSignature_SHA_1withDSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_DSA() throws Exception { try { - Signature.getInstance("SHA-1/DSA", providerName); + Signature.getInstance("SHA-1/DSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA-1/DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -353,14 +282,12 @@ public void testSignature_SHA_1_DSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA1_DSA() throws Exception { try { - Signature.getInstance("SHA1/DSA", providerName); + Signature.getInstance("SHA1/DSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA1/DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -369,14 +296,12 @@ public void testSignature_SHA1_DSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_DSA() throws Exception { try { - Signature.getInstance("SHA/DSA", providerName); + Signature.getInstance("SHA/DSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA/DSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -385,14 +310,12 @@ public void testSignature_SHA_DSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_DSS() throws Exception { try { - Signature.getInstance("DSS", providerName); + Signature.getInstance("DSS", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSS for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -401,14 +324,12 @@ public void testSignature_DSS() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithDSA() throws Exception { try { - Signature.getInstance("SHAwithDSA", providerName); + Signature.getInstance("SHAwithDSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHAwithDSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -417,14 +338,12 @@ public void testSignature_SHAwithDSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_DSAWithSHA1() throws Exception { try { - Signature.getInstance("DSAWithSHA1", providerName); + Signature.getInstance("DSAWithSHA1", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: DSAWithSHA1 for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -433,14 +352,12 @@ public void testSignature_DSAWithSHA1() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_OID_1_3_14_3_2_13() throws Exception { try { - Signature.getInstance("OID.1.3.14.3.2.13", providerName); + Signature.getInstance("OID.1.3.14.3.2.13", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: OID.1.3.14.3.2.13 for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -449,14 +366,12 @@ public void testSignature_OID_1_3_14_3_2_13() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_OID_1_3_14_3_2_27() throws Exception { try { - Signature.getInstance("OID.1.3.14.3.2.27", providerName); + Signature.getInstance("OID.1.3.14.3.2.27", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: OID.1.3.14.3.2.27 for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -465,70 +380,52 @@ public void testSignature_OID_1_3_14_3_2_27() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_224withDSA() throws Exception { - Signature.getInstance("SHA-224withDSA", providerName); + Signature.getInstance("SHA-224withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_224_DSA() throws Exception { - Signature.getInstance("SHA-224/DSA", providerName); + Signature.getInstance("SHA-224/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_DSA() throws Exception { - Signature.getInstance("SHA224/DSA", providerName); + Signature.getInstance("SHA224/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withDSA() throws Exception { - Signature.getInstance("SHA2withDSA", providerName); + Signature.getInstance("SHA2withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_2withDSA() throws Exception { - Signature.getInstance("SHA-2withDSA", providerName); + Signature.getInstance("SHA-2withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_256withDSA() throws Exception { - Signature.getInstance("SHA-256withDSA", providerName); + Signature.getInstance("SHA-256withDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_2_DSA() throws Exception { - Signature.getInstance("SHA-2/DSA", providerName); + Signature.getInstance("SHA-2/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_DSA() throws Exception { - Signature.getInstance("SHA2/DSA", providerName); + Signature.getInstance("SHA2/DSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithECDSA() throws Exception { try { - Signature.getInstance("SHAwithECDSA", providerName); + Signature.getInstance("SHAwithECDSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHAwithECDSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -537,14 +434,12 @@ public void testSignature_SHAwithECDSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withECDSA() throws Exception { try { - Signature.getInstance("SHA-1withECDSA", providerName); + Signature.getInstance("SHA-1withECDSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA-1withECDSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -553,14 +448,12 @@ public void testSignature_SHA_1withECDSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_ECDSA() throws Exception { try { - Signature.getInstance("SHA/ECDSA", providerName); + Signature.getInstance("SHA/ECDSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA/ECDSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -569,14 +462,12 @@ public void testSignature_SHA_ECDSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_ECDSA() throws Exception { try { - Signature.getInstance("SHA-1/ECDSA", providerName); + Signature.getInstance("SHA-1/ECDSA", getProviderName()); } catch (NoSuchAlgorithmException nsae) { - if (providerName.equals("OpenJCEPlusFIPS")) { + if (getProviderName().equals("OpenJCEPlusFIPS")) { assertEquals("no such algorithm: SHA-1/ECDSA for provider OpenJCEPlusFIPS", nsae.getMessage()); return; } else { @@ -585,170 +476,111 @@ public void testSignature_SHA_1_ECDSA() throws Exception { } } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_ECDSA() throws Exception { - Signature.getInstance("SHA224/ECDSA", providerName); + Signature.getInstance("SHA224/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withECDSA() throws Exception { - Signature.getInstance("SHA2withECDSA", providerName); + Signature.getInstance("SHA2withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_ECDSA() throws Exception { - Signature.getInstance("SHA2/ECDSA", providerName); + Signature.getInstance("SHA2/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withECDSA() throws Exception { - Signature.getInstance("SHA3withECDSA", providerName); + Signature.getInstance("SHA3withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_ECDSA() throws Exception { - Signature.getInstance("SHA3/ECDSA", providerName); + Signature.getInstance("SHA3/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withECDSA() throws Exception { - Signature.getInstance("SHA5withECDSA", providerName); + Signature.getInstance("SHA5withECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_ECDSA() throws Exception { - Signature.getInstance("SHA5/ECDSA", providerName); + Signature.getInstance("SHA5/ECDSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1withRSA() throws Exception { - Signature.getInstance("SHA-1withRSA", providerName); + Signature.getInstance("SHA-1withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHAwithRSA() throws Exception { - Signature.getInstance("SHAwithRSA", providerName); + Signature.getInstance("SHAwithRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_1_RSA() throws Exception { - Signature.getInstance("SHA-1/RSA", providerName); + Signature.getInstance("SHA-1/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA1_RSA() throws Exception { - Signature.getInstance("SHA1/RSA", providerName); + Signature.getInstance("SHA1/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA_RSA() throws Exception { - Signature.getInstance("SHA/RSA", providerName); + Signature.getInstance("SHA/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_RSA() throws Exception { - Signature.getInstance("RSA", providerName); + Signature.getInstance("RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA224_RSA() throws Exception { - Signature.getInstance("SHA224/RSA", providerName); + Signature.getInstance("SHA224/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2withRSA() throws Exception { - Signature.getInstance("SHA2withRSA", providerName); + Signature.getInstance("SHA2withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA2_RSA() throws Exception { - Signature.getInstance("SHA2/RSA", providerName); + Signature.getInstance("SHA2/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3withRSA() throws Exception { - Signature.getInstance("SHA3withRSA", providerName); + Signature.getInstance("SHA3withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA3_RSA() throws Exception { - Signature.getInstance("SHA3/RSA", providerName); + Signature.getInstance("SHA3/RSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5withRSA() throws Exception { - Signature.getInstance("SHA5withRSA", providerName); + Signature.getInstance("SHA5withRSA", getProviderName()); } - //-------------------------------------------------------------------------- - // - // + @Test public void testSignature_SHA5_RSA() throws Exception { - Signature.getInstance("SHA5/RSA", providerName); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestAliases.class.getName()}; - junit.textui.TestRunner.main(nargs); + Signature.getInstance("SHA5/RSA", getProviderName()); } - // -------------------------------------------------------------------------- - // - // + @Test public void testAliases() throws Exception { System.out.println("executing testAliases SHA5/RSA"); - Signature.getInstance("SHA5/RSA", providerName); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestAliases.class); - return suite; + Signature.getInstance("SHA5/RSA", getProviderName()); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDESede.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDESede.java index 412ceadb..b42c4a63 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDESede.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDESede.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,45 +10,24 @@ import ibm.jceplus.junit.base.BaseTestDESede; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDESede extends BaseTestDESede { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - // -------------------------------------------------------------------------- - // - // - public TestDESede() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestDESede.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testDESede() throws Exception { - System.out.println("executing testDESede"); - BaseTestDESede bt = new BaseTestDESede(providerName); - bt.run(); - } - - - // -------------------------------------------------------------------------- - // This method is to check whether a mode is valid for the cipher - // but not supported by a given provider. - // + /** + * + * This method is to check whether a mode is valid for the cipher + * but not supported by a given provider. + */ @Override public boolean isModeValidButUnsupported(String mode) { if (mode.equalsIgnoreCase("CFB") || mode.equalsIgnoreCase("CFB64") diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDH.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDH.java index e660e27e..7085dea9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDH.java @@ -10,22 +10,17 @@ import ibm.jceplus.junit.base.BaseTestDH; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDH extends BaseTestDH { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - isMulti = true; - } - - public void testDH() throws Exception { - System.out.println("executing testDH"); - BaseTestDH bt = new BaseTestDH(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setMulti(true); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSAKey.java index a3e31e8b..0b694348 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSAKey.java @@ -10,16 +10,18 @@ import ibm.jceplus.junit.base.BaseTestDSAKey; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDSAKey extends BaseTestDSAKey { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestDSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } @Disabled("DSA key generation is not available in FIPS mode.") diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSASignatureInteropSUN.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSASignatureInteropSUN.java index 4d89904c..9769b6e9 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSASignatureInteropSUN.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestDSASignatureInteropSUN.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,17 @@ import ibm.jceplus.junit.base.BaseTestDSASignatureInterop; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestDSASignatureInteropSUN extends BaseTestDSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SUN); } - - //-------------------------------------------------------------------------- - // - // - public TestDSASignatureInteropSUN() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SUN); - } - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestDSASignatureInteropSUN.class - .getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testDSASignatureInteropSUN() throws Exception { - System.out.println("executing testDSASignatureInteropSUN"); - BaseTestDSASignatureInterop bt = new BaseTestDSASignatureInterop(providerName, - Utils.PROVIDER_SUN); - bt.run(); - } - - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDH.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDH.java index 38eb5b9a..1eff3500 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDH.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDH.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,61 +10,17 @@ import ibm.jceplus.junit.base.BaseTestECDH; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestECDH extends BaseTestECDH { - // -------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setMulti(true); } - - // -------------------------------------------------------------------------- - // - // - public TestECDH() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - // public static void main(String[] args) throws Exception { - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static void testECDH () throws Exception { - // - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static Test suite() { - // TestSuite suite = new TestSuite(TestECDH.class); - // return suite; - // } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestECDH.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testECDH() throws Exception { - System.out.println("executing testECDH"); - BaseTestECDH bt = new BaseTestECDH(providerName); - bt.run(); - } - } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDHInteropSunEC.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDHInteropSunEC.java index 283fa971..86451aa2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDHInteropSunEC.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestECDHInteropSunEC.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,17 @@ import ibm.jceplus.junit.base.BaseTestECDHInterop; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestECDHInteropSunEC extends BaseTestECDHInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestECDHInteropSunEC() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunEC); - } - - //-------------------------------------------------------------------------- - // - // - public void testECDHInteropSunEC() throws Exception { - System.out.println("executing testECDHInteropSunEC"); - BaseTestECDHInterop bt = new BaseTestECDHInterop(providerName, Utils.PROVIDER_SunEC); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestECDHInteropSunEC.class.getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunEC); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHKDF.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHKDF.java index 47cc1c76..3b504d71 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHKDF.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHKDF.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,38 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestHKDF; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHKDF extends BaseTestHKDF { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHKDF() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestHKDF.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testHKDF() throws Exception { - System.out.println("executing testHKDF"); - BaseTestHKDF bt = new BaseTestHKDF(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5.java index 105c17ea..325dba08 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,37 +10,16 @@ import ibm.jceplus.junit.base.BaseTestHmacMD5; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHmacMD5 extends BaseTestHmacMD5 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - - - public void testHmacMD5() throws Exception { - System.out.println("executing testHmacMD5"); - BaseTestHmacMD5 bt = new BaseTestHmacMD5(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestHmacMD5.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5InteropSunJCE.java index 2c5479bc..979890ec 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacMD5InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,19 @@ package ibm.jceplus.junit.openjceplusfips.multithread; - import ibm.jceplus.junit.base.BaseTestHmacMD5Interop; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHmacMD5InteropSunJCE extends BaseTestHmacMD5Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacMD5InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - public void testHmacMD5Interop() throws Exception { - System.out.println("executing testHmacMD5Interop"); - BaseTestHmacMD5Interop bt = new BaseTestHmacMD5Interop(providerName, Utils.PROVIDER_SunJCE); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestHmacMD5InteropSunJCE.class - .getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256.java index 517f56e3..0cba3f11 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,35 +11,16 @@ import ibm.jceplus.junit.base.BaseTestHmacSHA256; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA256 extends ibm.jceplus.junit.base.BaseTestHmacSHA256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA256 extends BaseTestHmacSHA256 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacMD5() throws Exception { - System.out.println("executing testHmacSHA256"); - BaseTestHmacSHA256 bt = new BaseTestHmacSHA256(providerName); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestHmacSHA256.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256InteropSunJCE.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256InteropSunJCE.java index f5d78a91..e9d3e8b2 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256InteropSunJCE.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA256InteropSunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,39 +8,19 @@ package ibm.jceplus.junit.openjceplusfips.multithread; - import ibm.jceplus.junit.base.BaseTestHmacSHA256Interop; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestHmacSHA256InteropSunJCE extends BaseTestHmacSHA256Interop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestHmacSHA256InteropSunJCE() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunJCE); - } - - public void testHmacSHA256Interop() throws Exception { - System.out.println("executing testHmacSHA256Interop"); - BaseTestHmacSHA256Interop bt = new BaseTestHmacSHA256Interop(providerName, - Utils.PROVIDER_SunJCE); - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestHmacSHA256InteropSunJCE.class - .getName()}; - junit.textui.TestRunner.main(nargs); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunJCE); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_224.java index 759dd8e6..faf88916 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_224.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestHmacSHA3_224; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_224 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_224 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_224 extends BaseTestHmacSHA3_224 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestHmacSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_224() throws Exception { - System.out.println("executing testHmacSHA3_224"); - BaseTestHmacSHA3_224 bt = new BaseTestHmacSHA3_224(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_256.java index f85bd15d..399c0963 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_256.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestHmacSHA3_256; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_256 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_256 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_256 extends BaseTestHmacSHA3_256 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestHmacSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_256() throws Exception { - System.out.println("executing testHmacSHA3_256"); - BaseTestHmacSHA3_256 bt = new BaseTestHmacSHA3_256(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_384.java index 88c97f7c..e0d3d9ab 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_384.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestHmacSHA3_384; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_384 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_384 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_384 extends BaseTestHmacSHA3_384 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestHmacSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_384() throws Exception { - System.out.println("executing testHmacSHA3_384"); - BaseTestHmacSHA3_384 bt = new BaseTestHmacSHA3_384(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_512.java index ccf4bc84..125a3e76 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestHmacSHA3_512.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestHmacSHA3_512; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestHmacSHA3_512 extends ibm.jceplus.junit.base.BaseTestHmacSHA3_512 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestHmacSHA3_512 extends BaseTestHmacSHA3_512 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestHmacSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testHmacSHA3_512() throws Exception { - System.out.println("executing testHmacSHA3_512"); - BaseTestHmacSHA3_512 bt = new BaseTestHmacSHA3_512(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestMiniRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestMiniRSAPSS2.java index 8b84e885..ff7916f6 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestMiniRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestMiniRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestMiniRSAPSS2; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestMiniRSAPSS2 extends ibm.jceplus.junit.base.BaseTestMiniRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestMiniRSAPSS2 extends BaseTestMiniRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestMiniRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestMiniRSAPSS2.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testMiniRSAPSS2() throws Exception { - System.out.println("executing testRSAPSS2"); - BaseTestMiniRSAPSS2 bt = new BaseTestMiniRSAPSS2(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAKey.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAKey.java index f3a65b40..eac5447e 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAKey.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAKey.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,41 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAKey; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestRSAKey extends BaseTestRSAKey { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAKey() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public void testRSAKey() throws Exception { - - System.out.println("executing testRSAKey"); - BaseTestRSAKey bt = new BaseTestRSAKey(providerName); - bt.run(); - - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestRSAKey.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS.java index b9ee02b5..219254df 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,39 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSS; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS extends ibm.jceplus.junit.base.BaseTestRSAPSS { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS extends BaseTestRSAPSS { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestRSAPSS.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSS() throws Exception { - System.out.println("executing testRSAPSS"); - BaseTestRSAPSS bt = new BaseTestRSAPSS(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS2.java index e883b278..ea2c6b5c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSS2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSS2; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSS2 extends ibm.jceplus.junit.base.BaseTestRSAPSS2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSS2 extends BaseTestRSAPSS2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSS2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestRSAPSS2.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSS2() throws Exception { - System.out.println("executing testRSAPSS2"); - BaseTestRSAPSS2 bt = new BaseTestRSAPSS2(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop2.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop2.java index f7e1d7db..083385a4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop2.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop2.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSSInterop2; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop2 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop2 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop2 extends BaseTestRSAPSSInterop2 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop2() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestRSAPSSInterop2.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSSInterop2() throws Exception { - System.out.println("executing testRSAPSSInterop2"); - BaseTestRSAPSSInterop2 bt = new BaseTestRSAPSSInterop2(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop3.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop3.java index a3bbc434..d715f69a 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop3.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSAPSSInterop3.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,40 +10,16 @@ import ibm.jceplus.junit.base.BaseTestRSAPSSInterop3; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestRSAPSSInterop3 extends ibm.jceplus.junit.base.BaseTestRSAPSSInterop3 { +@TestInstance(Lifecycle.PER_CLASS) +public class TestRSAPSSInterop3 extends BaseTestRSAPSSInterop3 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestRSAPSSInterop3() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestRSAPSSInterop3.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSAPSSInterop3() throws Exception { - System.out.println("executing testRSAPSSInterop3"); - BaseTestRSAPSSInterop3 bt = new BaseTestRSAPSSInterop3(providerName); - bt.run(); - } - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSASignatureInteropSunRsaSign.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSASignatureInteropSunRsaSign.java index 3c540a3f..bf315ef4 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSASignatureInteropSunRsaSign.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSASignatureInteropSunRsaSign.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,42 +10,18 @@ import ibm.jceplus.junit.base.BaseTestRSASignatureInterop; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestRSASignatureInteropSunRsaSign extends BaseTestRSASignatureInterop { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestRSASignatureInteropSunRsaSign() { - super(Utils.TEST_SUITE_PROVIDER_NAME, Utils.PROVIDER_SunRsaSign, 2048); - } - - //-------------------------------------------------------------------------- - // - // - - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestRSASignatureInteropSunRsaSign.class - .getName()}; - junit.textui.TestRunner.main(nargs); - } - - // -------------------------------------------------------------------------- - // - // - public void testRSASignatureInteropSunRsaSign() throws Exception { - System.out.println("executing testRSASignatureInteropSunRsaSign"); - BaseTestRSASignatureInterop bt = new BaseTestRSASignatureInterop(providerName, - Utils.PROVIDER_SunRsaSign); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setInteropProviderName(Utils.PROVIDER_SunRsaSign); + setKeySize(2048); } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSA_2048.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSA_2048.java index df3a7ffb..2728a99c 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSA_2048.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestRSA_2048.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,45 +10,17 @@ import ibm.jceplus.junit.base.BaseTestRSA; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestRSA_2048 extends BaseTestRSA { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); + setKeySize(2048); } - - //-------------------------------------------------------------------------- - // - // - private static final int KEY_SIZE = 2048; - - //-------------------------------------------------------------------------- - // - // - public TestRSA_2048() throws Exception { - super(Utils.TEST_SUITE_PROVIDER_NAME, KEY_SIZE); - } - - public void testRSA_2048() throws Exception { - - System.out.println("executing testRSA_2048"); - BaseTestRSA bt = new BaseTestRSA(providerName, KEY_SIZE); - bt.run(); - - } - - // -------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - String[] nargs = { - ibm.jceplus.junit.openjceplusfips.multithread.TestRSA_2048.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA256Clone_SharedMD.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA256Clone_SharedMD.java index 75aaa37d..85cc4a21 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA256Clone_SharedMD.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA256Clone_SharedMD.java @@ -8,43 +8,18 @@ package ibm.jceplus.junit.openjceplusfips.multithread; +import ibm.jceplus.junit.base.BaseTestSHA256Clone_SharedMD; import ibm.jceplus.junit.openjceplusfips.Utils; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA256Clone_SharedMD extends ibm.jceplus.junit.base.BaseTestSHA256Clone_SharedMD { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA256Clone_SharedMD extends BaseTestSHA256Clone_SharedMD { - - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - //-------------------------------------------------------------------------- - // - // - public TestSHA256Clone_SharedMD() throws NoSuchAlgorithmException, NoSuchProviderException { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - //-------------------------------------------------------------------------- - // - // - public static void main(String[] args) throws Exception { - junit.textui.TestRunner.run(suite()); - } - - //-------------------------------------------------------------------------- - // - // - public static Test suite() { - TestSuite suite = new TestSuite(TestSHA256Clone_SharedMD.class); - return suite; + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } - - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_224.java index 22c39ad3..37f1dfb7 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_224.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestSHA3_224KAT; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_224 extends ibm.jceplus.junit.base.BaseTestSHA3_224KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_224 extends BaseTestSHA3_224KAT { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA3_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_224() throws Exception { - System.out.println("executing testSHA3_224"); - BaseTestSHA3_224KAT bt = new BaseTestSHA3_224KAT(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_256.java index 2e613adc..4ab49d7f 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_256.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestSHA3_256KAT; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA3_256 extends BaseTestSHA3_256KAT { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA3_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_256() throws Exception { - System.out.println("executing testSHA3_256"); - BaseTestSHA3_256KAT bt = new BaseTestSHA3_256KAT(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_384.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_384.java index 538f0c88..0e6792fd 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_384.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_384.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023,2024 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestSHA3_384KAT; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_384 extends ibm.jceplus.junit.base.BaseTestSHA3_384KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_384 extends BaseTestSHA3_384KAT { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA3_384() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_384() throws Exception { - System.out.println("executing testSHA3_384"); - BaseTestSHA3_384KAT bt = new BaseTestSHA3_384KAT(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_512.java index 6b073ea9..9e10e906 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA3_512.java @@ -9,21 +9,17 @@ package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestSHA3_512KAT; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; -public class TestSHA3_512 extends ibm.jceplus.junit.base.BaseTestSHA3_512KAT { +@TestInstance(Lifecycle.PER_CLASS) +public class TestSHA3_512 extends BaseTestSHA3_512KAT { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA3_512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA3_512() throws Exception { - System.out.println("executing testSHA3_512"); - BaseTestSHA3_512KAT bt = new BaseTestSHA3_512KAT(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512.java index b6d6b270..c20ef342 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512.java @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2023 + * Copyright IBM Corp. 2023, 2024 * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -8,52 +8,18 @@ package ibm.jceplus.junit.openjceplusfips.multithread; - import ibm.jceplus.junit.base.BaseTestSHA512; import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA512 extends BaseTestSHA512 { - //-------------------------------------------------------------------------- - // - // - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } - - //-------------------------------------------------------------------------- - // - // - public TestSHA512() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA512() throws Exception { - System.out.println("executing testSHA512"); - BaseTestSHA512 bt = new BaseTestSHA512(providerName); - - bt.run(); - - } - - public static void main(String[] args) { - String[] nargs = {ibm.jceplus.junit.openjceplusfips.multithread.TestSHA512.class.getName()}; - junit.textui.TestRunner.main(nargs); - } - - //-------------------------------------------------------------------------- - // - // - // public static void main(String[] args) throws Exception { - // junit.textui.TestRunner.run(suite()); - // } - // - // //-------------------------------------------------------------------------- - // // - // // - // public static Test suite() { - // TestSuite suite = new TestSuite(TestSHA512.class); - // return suite; - // } } - diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_224.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_224.java index f360594d..0399f133 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_224.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_224.java @@ -5,24 +5,21 @@ * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestSHA512_224; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA512_224 extends BaseTestSHA512_224 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA512_224() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA512_224() throws Exception { - System.out.println("executing testSHA512_224"); - BaseTestSHA512_224 bt = new BaseTestSHA512_224(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } } diff --git a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_256.java b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_256.java index 955ab860..f50e7d54 100644 --- a/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_256.java +++ b/src/test/java/ibm/jceplus/junit/openjceplusfips/multithread/TestSHA512_256.java @@ -5,24 +5,21 @@ * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution. */ + package ibm.jceplus.junit.openjceplusfips.multithread; import ibm.jceplus.junit.base.BaseTestSHA512_256; -import ibm.jceplus.junit.openjceplus.Utils; +import ibm.jceplus.junit.openjceplusfips.Utils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +@TestInstance(Lifecycle.PER_CLASS) public class TestSHA512_256 extends BaseTestSHA512_256 { - static { + @BeforeAll + public void beforeAll() { Utils.loadProviderTestSuite(); - } - - public TestSHA512_256() { - super(Utils.TEST_SUITE_PROVIDER_NAME); - } - - public void testSHA512_256() throws Exception { - System.out.println("executing testSHA512_256"); - BaseTestSHA512_256 bt = new BaseTestSHA512_256(providerName); - bt.run(); + setProviderName(Utils.TEST_SUITE_PROVIDER_NAME); } }