5050import org .bouncycastle .crypto .engines .AESLightEngine ;
5151import org .bouncycastle .crypto .engines .BlowfishEngine ;
5252import org .bouncycastle .crypto .engines .CAST5Engine ;
53+ import org .bouncycastle .crypto .engines .CAST6Engine ;
5354import org .bouncycastle .crypto .engines .CamelliaEngine ;
5455import org .bouncycastle .crypto .engines .CamelliaLightEngine ;
5556import org .bouncycastle .crypto .engines .ChaCha7539Engine ;
6061import org .bouncycastle .crypto .engines .HC128Engine ;
6162import org .bouncycastle .crypto .engines .HC256Engine ;
6263import org .bouncycastle .crypto .engines .IDEAEngine ;
64+ import org .bouncycastle .crypto .engines .ISAACEngine ;
6365import org .bouncycastle .crypto .engines .RC4Engine ;
6466import org .bouncycastle .crypto .engines .RC532Engine ;
6567import org .bouncycastle .crypto .engines .RC564Engine ;
6668import org .bouncycastle .crypto .engines .RSAEngine ;
6769import org .bouncycastle .crypto .engines .RijndaelEngine ;
70+ import org .bouncycastle .crypto .engines .SEEDEngine ;
6871import org .bouncycastle .crypto .engines .SM2Engine ;
6972import org .bouncycastle .crypto .engines .SM4Engine ;
7073import org .bouncycastle .crypto .engines .Salsa20Engine ;
7174import org .bouncycastle .crypto .engines .SerpentEngine ;
75+ import org .bouncycastle .crypto .engines .Shacal2Engine ;
7276import org .bouncycastle .crypto .engines .SkipjackEngine ;
7377import org .bouncycastle .crypto .engines .TEAEngine ;
7478import org .bouncycastle .crypto .engines .ThreefishEngine ;
@@ -190,6 +194,7 @@ public void performTest()
190194 testARIA ();
191195 testIDEA ();
192196 testCAST5 ();
197+ testCAST6 ();
193198 testCamelliaLight ();
194199 testCamellia ();
195200 testBlowfish ();
@@ -205,13 +210,17 @@ public void performTest()
205210 testSM2Cipher ();
206211 testSM4 ();
207212 testTEA ();
213+ testXTEA ();
208214 testThreefish ();
209215 testSalsa20AndXSalsa20AndChaCha ();
210216 testZuc128AndZuc256 ();
211217 testVMPCAndVMPCKSA ();
212218 testRC532AndRC564 ();
213219 testRijndael ();
214220 testHC128AndHC256 ();
221+ testSEED ();
222+ testISAAC ();
223+ testShacal2 ();
215224 }
216225
217226 private void test112bits ()
@@ -716,6 +725,24 @@ private void testCAST5()
716725 isEquals ("service does not provide 256 bits of security only 128" , e .getMessage ());
717726 }
718727
728+ engine .init (false , new KeyParameter (new byte [16 ]));
729+
730+ CryptoServicesRegistrar .setServicesConstraints (null );
731+ }
732+
733+ private void testSEED ()
734+ {
735+ CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (256 ));
736+ SEEDEngine engine = new SEEDEngine ();
737+ try
738+ {
739+ engine .init (true , new KeyParameter (new byte [16 ]));
740+ fail ("no exception!" );
741+ }
742+ catch (CryptoServiceConstraintsException e )
743+ {
744+ isEquals ("service does not provide 256 bits of security only 128" , e .getMessage ());
745+ }
719746
720747 engine .init (false , new KeyParameter (new byte [16 ]));
721748
@@ -1617,12 +1644,12 @@ private void testECIESKEM()
16171644 ecKp .init (new ECKeyGenerationParameters (new ECDomainParameters (X962NamedCurves .getByName ("prime192v1" )), random ));
16181645 AsymmetricCipherKeyPair kp = ecKp .generateKeyPair ();
16191646
1620- byte [] out = new byte [49 ];
1647+ byte [] out = new byte [49 ];
16211648 ECIESKeyEncapsulation kem = new ECIESKeyEncapsulation (kdf , random );
16221649
16231650 kem .init (kp .getPublic ());
16241651 KeyParameter key1 = (KeyParameter )kem .encrypt (out , 128 );
1625-
1652+
16261653 CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (128 , 80 ));
16271654
16281655
@@ -1686,6 +1713,88 @@ private void testTEA()
16861713 CryptoServicesRegistrar .setServicesConstraints (null );
16871714 }
16881715
1716+ private void testXTEA ()
1717+ {
1718+ CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (256 , 128 ));
1719+ TEAEngine engine = new TEAEngine ();
1720+ try
1721+ {
1722+ engine .init (true , new KeyParameter (new byte [16 ]));
1723+ fail ("no exception!" );
1724+ }
1725+ catch (CryptoServiceConstraintsException e )
1726+ {
1727+ isEquals ("service does not provide 256 bits of security only 128" , e .getMessage ());
1728+ }
1729+
1730+ engine .init (false , new KeyParameter (new byte [16 ]));
1731+
1732+ CryptoServicesRegistrar .setServicesConstraints (null );
1733+ }
1734+
1735+ private void testCAST6 ()
1736+ {
1737+ CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (256 , 128 ));
1738+ CAST6Engine engine = new CAST6Engine ();
1739+ try
1740+ {
1741+ engine .init (true , new KeyParameter (new byte [16 ]));
1742+ fail ("no exception!" );
1743+ }
1744+ catch (CryptoServiceConstraintsException e )
1745+ {
1746+ isEquals ("service does not provide 256 bits of security only 128" , e .getMessage ());
1747+ }
1748+
1749+ engine .init (false , new KeyParameter (new byte [16 ])); // should work
1750+
1751+ engine .init (true , new KeyParameter (new byte [32 ])); // should work
1752+
1753+ CryptoServicesRegistrar .setServicesConstraints (null );
1754+ }
1755+
1756+ private void testISAAC ()
1757+ {
1758+ CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (256 , 128 ));
1759+ ISAACEngine engine = new ISAACEngine ();
1760+ try
1761+ {
1762+ engine .init (true , new KeyParameter (new byte [16 ]));
1763+ fail ("no exception!" );
1764+ }
1765+ catch (CryptoServiceConstraintsException e )
1766+ {
1767+ isEquals ("service does not provide 256 bits of security only 128" , e .getMessage ());
1768+ }
1769+
1770+ engine .init (false , new KeyParameter (new byte [16 ])); // should work
1771+
1772+ engine .init (true , new KeyParameter (new byte [32 ])); // should work
1773+
1774+ CryptoServicesRegistrar .setServicesConstraints (null );
1775+ }
1776+
1777+ private void testShacal2 ()
1778+ {
1779+ CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (256 , 128 ));
1780+ Shacal2Engine engine = new Shacal2Engine ();
1781+ try
1782+ {
1783+ engine .init (true , new KeyParameter (new byte [16 ]));
1784+ fail ("no exception!" );
1785+ }
1786+ catch (CryptoServiceConstraintsException e )
1787+ {
1788+ isEquals ("service does not provide 256 bits of security only 128" , e .getMessage ());
1789+ }
1790+
1791+ engine .init (false , new KeyParameter (new byte [16 ])); // should work
1792+
1793+ engine .init (true , new KeyParameter (new byte [32 ])); // should work
1794+
1795+ CryptoServicesRegistrar .setServicesConstraints (null );
1796+ }
1797+
16891798 private void testThreefish ()
16901799 {
16911800 CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (384 , 256 ));
@@ -1778,7 +1887,7 @@ private void testZuc128AndZuc256()
17781887 }
17791888 catch (CryptoServiceConstraintsException e )
17801889 {
1781- isEquals (e .getMessage (),"service does not provide 256 bits of security only 128" , e .getMessage ());
1890+ isEquals (e .getMessage (), "service does not provide 256 bits of security only 128" , e .getMessage ());
17821891 }
17831892
17841893 xengine .init (true , new ParametersWithIV (new KeyParameter (new byte [32 ]), new byte [25 ]));
@@ -1800,7 +1909,7 @@ private void testVMPCAndVMPCKSA()
18001909 }
18011910 catch (CryptoServiceConstraintsException e )
18021911 {
1803- isEquals (e .getMessage (),"service does not provide 256 bits of security only 128" , e .getMessage ());
1912+ isEquals (e .getMessage (), "service does not provide 256 bits of security only 128" , e .getMessage ());
18041913 }
18051914
18061915 xengine .init (true , new ParametersWithIV (new KeyParameter (new byte [32 ]), new byte [25 ]));
@@ -1822,7 +1931,7 @@ private void testRC532AndRC564()
18221931 }
18231932 catch (CryptoServiceConstraintsException e )
18241933 {
1825- isEquals (e .getMessage (),"service does not provide 256 bits of security only 128" , e .getMessage ());
1934+ isEquals (e .getMessage (), "service does not provide 256 bits of security only 128" , e .getMessage ());
18261935 }
18271936
18281937 try
@@ -1832,7 +1941,7 @@ private void testRC532AndRC564()
18321941 }
18331942 catch (CryptoServiceConstraintsException e )
18341943 {
1835- isEquals (e .getMessage (),"service does not provide 256 bits of security only 128" , e .getMessage ());
1944+ isEquals (e .getMessage (), "service does not provide 256 bits of security only 128" , e .getMessage ());
18361945 }
18371946
18381947 xengine .init (true , new RC5Parameters (new byte [32 ], 12 ));
@@ -1861,6 +1970,7 @@ private void testRijndael()
18611970
18621971 CryptoServicesRegistrar .setServicesConstraints (null );
18631972 }
1973+
18641974 private void testHC128AndHC256 ()
18651975 {
18661976 CryptoServicesRegistrar .setServicesConstraints (new LegacyBitsOfSecurityConstraint (256 , 128 ));
@@ -1873,7 +1983,7 @@ private void testHC128AndHC256()
18731983 }
18741984 catch (CryptoServiceConstraintsException e )
18751985 {
1876- isEquals (e .getMessage (),"service does not provide 256 bits of security only 128" , e .getMessage ());
1986+ isEquals (e .getMessage (), "service does not provide 256 bits of security only 128" , e .getMessage ());
18771987 }
18781988
18791989 xengine .init (false , new ParametersWithIV (new KeyParameter (new byte [16 ]), new byte [16 ]));
@@ -1905,12 +2015,12 @@ private void testSM2Cipher()
19052015 }
19062016 catch (CryptoServiceConstraintsException e )
19072017 {
1908- isEquals (e .getMessage (),"service does not provide 256 bits of security only 128" , e .getMessage ());
2018+ isEquals (e .getMessage (), "service does not provide 256 bits of security only 128" , e .getMessage ());
19092019 }
19102020
19112021 // decryption should be okay
19122022 engine .init (false , kp .getPrivate ());
1913-
2023+
19142024 CryptoServicesRegistrar .setServicesConstraints (null );
19152025 }
19162026
0 commit comments