Subject: [Classpathx-crypto] GCJ JUnit result.

From: Olivier LF <[email-masked]>
Date: Mon, 1 Jul 2002 23:37:02 +1000

> 3. can we get the library integrated with the gcj release --from
> Olivier's tests it sounded like our JCE adapters fill a missing niche in
> their distribution?

Sorry for the delay! I am stuck with another home project for the moment
and don't seem to get anything going!

Anyway, this is the output I get from the JUnit test suite under GCJ
version: gcc (GCC) 3.2 20020518.

 From this result, it looks very broken but I don't think it is. All the
basic tests from the crypto.tools directory are running just fine. I
think that gnu-crypto is essentially working with GCJ. 
The JUnit test suite is more likely to be badly broken because of
missing security classes in GCJ than compilation problems or 
compiler/runtime bugs.

Oli

This is only a snippets of the output, I attach the full file as well.

.........................................
.................................>>> dss: SEED: d38e1e61cc37f5ffcabfe5da132298286e085b19
>>> dss: counter: 2
>>> dss: q: de09f1902cf484f232fee5d27262372d1c6072d7
>>> dss: p: be6189c7df2a7cdf657a81faa2c809f5c5c9ce4d47ed4021fdb8fd55afc140e6ebc8b1df5defadeb422b9f4964eb6d2958940ee84ed8032ce50ac5b611841f87
>>> dss: g: 6444111a41ad5e86dccb6fbb63a0bc6a1b85b7af338a269a14056cbd8afb9458ba1c6016b14f5331ec6400f2ebd83f0f17cdd54a510050648dd8f5aa3d35ffc
.>>> dss: SEED: bd86a3974bc22bd3f08c342361075249ef516797
>>> dss: counter: 56
>>> dss: q: 96460a696d1e361b4840d641c696955314b5d061
>>> dss: p: e4e862371e938d890bb7838bb2d50dd079a384406f28e1d1a719f4d886f7e08b9d4c76fc15976f6793fffe98c9356c93b64eae43551561a0a8446f2c80e66cff
>>> dss: g: c1d24777284832cf120427c854866ff270c349aa091834161fea360801f76ed432d7f615732fdaf6df2a4d274a86db58061e48ff1ec39e88385333d9638ed69
F.>>> dss: SEED: d78931c08e94cf508a9121d194823300dcfe900f
>>> dss: counter: 417
>>> dss: q: aeefc632ffed90b4103202b8b3c9311eb23009e7
>>> dss: p: 9cab4e49c636313f8bd548aa2bbf79b5049ceedcdd7f130d41b9ab8533f81ca93366fbe619bc0a63a338b49925c44752ea4c35b8840164889cdb21fc54ceeead
>>> dss: g: 2a651864ab3b9a2f0a05bb24a1ad72578abecc8160391a9964b6d42a126ae0dd1deb678063e2ddc190d80afbe10ba64225c605735207b16358ab640f88424974
F.>>> dss: SEED: b411c7108639999a028fd5766ba8482a130fbfcb
>>> dss: counter: 181
>>> dss: q: bb593e212739720fb3a98fa06818448ce03e5965
>>> dss: p: 886b602f67146f295cf4357e249d70750c86381cb5e2bc8eb195d654bb8869e5595172e967c9d9efd621d2806ad391b15583f01903ded7dc8d84491c68f6ffeb
>>> dss: g: 3642955454bc0d9c9b20f6420bd7cfcd9fe6ceeb43212c083eb42cf16d8a44fddd8ecd56f062625a2ac05055ff2eebb86c60a56b62dcbbf53a3ccc9654d31a66
F.E.E.E.E.
E.E.E.E..UMAC test vector: 5FD764A6D3A9FD9D
..java.security.NoSuchAlgorithmException: SHA
   at 0x403eeee6: java.security.NoSuchAlgorithmException.NoSuchAlgorithmException(java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ee972: java.security.MessageDigest.getInstance(java.lang.String, java.lang.String, java.security.Provider) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ee8ab: java.security.MessageDigest.getInstance(java.lang.String, java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x080585eb: test::jce::TestOfProvider::testSha() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfProvider.java:85)

F.java.security.NoSuchAlgorithmException: Whirlpool
   at 0x0805867b: test::jce::TestOfProvider::testWhirlpool() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfProvider.java:95)

F...java.security.NoSuchAlgorithmException: ripemd128
   at 0x08057fd2: test::jce::TestOfMessageDigest::testEquality() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfMessageDigest.java:114)

F.E..E.E..E.E
Time: 440.928
There were 13 errors:
1) testKeyPairGeneration(test.sig.rsa.TestOfRSAKeyGeneration)
java.lang.ArithmeticException: not invertible
   at 0x40308f56: java.lang.ArithmeticException.ArithmeticException(java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403d53a9: java.math.BigInteger.modInverse(java.math.BigInteger) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x0805ee1f: test::sig::rsa::TestOfRSAKeyGeneration::testKeyPairGeneration() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAKeyGeneration.java:101)

2) testRSAParams(test.sig.rsa.TestOfRSAKeyGeneration)
java.lang.ArithmeticException: not invertible
   at 0x0805f05a: test::sig::rsa::TestOfRSAKeyGeneration::testRSAParams() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAKeyGeneration.java:118)

3) testRSAPrimitives(test.sig.rsa.TestOfRSAKeyGeneration)
java.lang.ArithmeticException: not invertible
   at 0x0805f63b: test::sig::rsa::TestOfRSAKeyGeneration::testRSAPrimitives() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAKeyGeneration.java:168)

4) testSigWithDefaults(test.sig.rsa.TestOfRSAPSSSignature)
java.lang.ArithmeticException: not invertible
   at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x0805feb4: test::sig::rsa::TestOfRSAPSSSignature::setUp() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAPSSSignature.java:153)

5) testSigWithShaSalt16(test.sig.rsa.TestOfRSAPSSSignature)
java.lang.ArithmeticException: not invertible
   at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x0805feb4: test::sig::rsa::TestOfRSAPSSSignature::setUp() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAPSSSignature.java:153)

6) testSigWithRipeMD160Salt8(test.sig.rsa.TestOfRSAPSSSignature)
java.lang.ArithmeticException: not invertible
   at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x0805feb4: test::sig::rsa::TestOfRSAPSSSignature::setUp() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAPSSSignature.java:153)

7) testKeyPairRawCodec(test.sig.rsa.TestOfRSACodec)
java.lang.ArithmeticException: not invertible
   at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x0805eb95: test::sig::rsa::TestOfRSACodec::setUp() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSACodec.java:148)

8) testSignatureRawCodec(test.sig.rsa.TestOfRSACodec)
   at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x0805eb95: test::sig::rsa::TestOfRSACodec::setUp() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSACodec.java:148)

9) testCloneability(test.jce.TestOfMessageDigest)
java.security.NoSuchAlgorithmException: ripemd128
   at 0x403ec266: java.security.GeneralSecurityException.GeneralSecurityException(java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403eeee6: java.security.NoSuchAlgorithmException.NoSuchAlgorithmException(java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ee972: java.security.MessageDigest.getInstance(java.lang.String, java.lang.String, java.security.Provider) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ee8ab: java.security.MessageDigest.getInstance(java.lang.String, java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x0805836f: test::jce::TestOfMessageDigest::testCloneability() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfMessageDigest.java:144)

10) testDSAKeyPairGenerator(test.jce.TestOfKeyPairGenerator)
java.lang.NullPointerException
   at 0x40311cef: java.lang.NullPointerException.NullPointerException() (/usr/local/gcc/lib/libgcj.so.3)
   at 0x402f5b89: java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x402f5bbf: java.lang.Class.forName(java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ed448: java.security.KeyPairGenerator.getInstance(java.lang.String, java.lang.String, java.security.Provider) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ed3eb: java.security.KeyPairGenerator.getInstance(java.lang.String, java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x08057770: test::jce::TestOfKeyPairGenerator::testDSAKeyPairGenerator() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfKeyPairGenerator.java:95)

11) testRSAKeyPairGenerator(test.jce.TestOfKeyPairGenerator)
java.lang.NullPointerException
   at 0x40075edd: gnu.crypto.sig.rsa.RSAKeyPairGenerator.nextRandomBytes(byte[]) (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x40075b12: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x40062ca0: gnu.crypto.jce.KeyPairGeneratorAdapter.generateKeyPair() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x403ebda4: java.security.DummyKeyPairGenerator.generateKeyPair() (/usr/local/gcc/lib/libgcj.so.3)
   at 0x08058aba: test::jce::TestOfSignature::testRSAPSSRawSignature() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfSignature.java:111)

12) testDSSRawSignature(test.jce.TestOfSignature)
java.lang.NullPointerException
   at 0x40311cef: java.lang.NullPointerException.NullPointerException() (/usr/local/gcc/lib/libgcj.so.3)
   at 0x402f5b89: java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x402f5bbf: java.lang.Class.forName(java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ed448: java.security.KeyPairGenerator.getInstance(java.lang.String, java.lang.String, java.security.Provider) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x403ed3eb: java.security.KeyPairGenerator.getInstance(java.lang.String, java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
   at 0x08058991: test::jce::TestOfSignature::testDSSRawSignature() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfSignature.java:89)

13) testRSAPSSRawSignature(test.jce.TestOfSignature)
java.lang.NullPointerException
   at 0x40075edd: gnu.crypto.sig.rsa.RSAKeyPairGenerator.nextRandomBytes(byte[]) (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x40075b12: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x40062ca0: gnu.crypto.jce.KeyPairGeneratorAdapter.generateKeyPair() (/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
   at 0x403ebda4: java.security.DummyKeyPairGenerator.generateKeyPair() (/usr/local/gcc/lib/libgcj.so.3)
   at 0x08058aba: test::jce::TestOfSignature::testRSAPSSRawSignature() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfSignature.java:111)

There were 7 failures:
1) testSignature(test.sig.dss.TestOfDSSSignature)junit.framework.AssertionFailedError: Verify own signature
   at 0x0805e5de: test::sig::dss::TestOfDSSSignature::testSignature() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/dss/TestOfDSSSignature.java:110)

2) testKeyPairRawCodec(test.sig.dss.TestOfDSSCodec)junit.framework.AssertionFailedError: DSS public key Raw encoder/decoder test
   at 0x400a3136: junit.framework.AssertionFailedError.AssertionFailedError(java.lang.String) (/home/olivier/tmp/jjj/lib/lib-junit.so.1)
   at 0x0805da15: test::sig::dss::TestOfDSSCodec::testKeyPairRawCodec() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/dss/TestOfDSSCodec.java:111)

3) testSignatureRawCodec(test.sig.dss.TestOfDSSCodec)junit.framework.AssertionFailedError: Signature Raw encoder/decoder test
   at 0x400a3136: junit.framework.AssertionFailedError.AssertionFailedError(java.lang.String) (/home/olivier/tmp/jjj/lib/lib-junit.so.1)
   at 0x0805dc6f: test::sig::dss::TestOfDSSCodec::testSignatureRawCodec() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/dss/TestOfDSSCodec.java:139)

4) testSha(test.jce.TestOfProvider)junit.framework.AssertionFailedError: testSha()
   at 0x400a3136: junit.framework.AssertionFailedError.AssertionFailedError(java.lang.String) (/home/olivier/tmp/jjj/lib/lib-junit.so.1)
   at 0x08058638: test::jce::TestOfProvider::testSha() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfProvider.java:88)

5) testWhirlpool(test.jce.TestOfProvider)junit.framework.AssertionFailedError: testWhirlpool()
   at 0x400a3136: junit.framework.AssertionFailedError.AssertionFailedError(java.lang.String) (/home/olivier/tmp/jjj/lib/lib-junit.so.1)
   at 0x080586c8: test::jce::TestOfProvider::testWhirlpool() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfProvider.java:98)

6) testShaPRNG(test.jce.TestOfProvider)junit.framework.AssertionFailedError: testShaPRNG()
   at 0x400a3136: junit.framework.AssertionFailedError.AssertionFailedError(java.lang.String) (/home/olivier/tmp/jjj/lib/lib-junit.so.1)
   at 0x08058758: test::jce::TestOfProvider::testShaPRNG() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfProvider.java:108)

7) testEquality(test.jce.TestOfMessageDigest)junit.framework.AssertionFailedError: MessageDigest.getInstance(ripemd128): java.security.NoSuchAlgorithmException: ripemd128
   at 0x400a3136: junit.framework.AssertionFailedError.AssertionFailedError(java.lang.String) (/home/olivier/tmp/jjj/lib/lib-junit.so.1)
   at 0x08058244: test::jce::TestOfMessageDigest::testEquality() (/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfMessageDigest.java:118)

FAILURES!!!
Tests run: 101,  Failures: 7,  Errors: 13

-- 
----------------------------------------------------------------------
Olivier Louchart-Fletcher
Email: [email-masked]

---

From: "Raif S. Naffah" <[email-masked]>
Date: Wed, 03 Jul 2002 19:24:47 +1000

it does not look as bad is it might first seems ;-)

Olivier LF wrote:
 > ...
 > ...
 >    at 0x403eeee6: 
java.security.NoSuchAlgorithmException.NoSuchAlgorithmException(java.lang.String) 
(/usr/local/gcc/lib/libgcj.so.3)
 >    at 0x403ee972: 
java.security.MessageDigest.getInstance(java.lang.String, 
java.lang.String, java.security.Provider) (/usr/local/gcc/lib/libgcj.so.3)
 >    at 0x403ee8ab: 
java.security.MessageDigest.getInstance(java.lang.String, 
java.lang.String) (/usr/local/gcc/lib/libgcj.so.3)
 >    at 0x080585eb: test::jce::TestOfProvider::testSha() 
(/home/olivier/program/cvsrsh/crypto/gcj/source/test/jce/TestOfProvider.java:85)

i had a look at the classpath implementation of the
MessageDigest.getInstance and i know why this is throwing the exception:
the implemetation *does not* handle algorithm aliasing at all!

a simple fix is to replace the following line in the above method (with
2 arguments) with the following:

- return getInstance(p.getProperty("MessageDigest." + algorithm),
algorithm, p);

+ // try the name as is
+ String className = p.getProperty("MessageDigest." + algorithm);
+ if (className == null) { // try all uppercase
+    String upper = algorithm.toUpperCase();
+    className = p.getProperty("MessageDigest." + upper);
+    if (className == null) { // try if it's an alias
+       String alias = p.getProperty("Alg.Alias.MessageDigest." +
algorithm);
+       if (alias == null) { // spit the dummy
+          throw new NoSuchAlgorithmException(algorithm);
+       }
+       className = p.getProperty("MessageDigest." + alias);
+       if (className == null) {
+          throw new NoSuchAlgorithmException(algorithm);
+       }
+    }
+ }
+ return getInstance(className, algorithm, p);

 > F.java.security.NoSuchAlgorithmException: Whirlpool

idem

 > F...java.security.NoSuchAlgorithmException: ripemd128

idem

 >    at 0x40308f56: 
java.lang.ArithmeticException.ArithmeticException(java.lang.String) 
(/usr/local/gcc/lib/libgcj.so.3)
 >    at 0x403d53a9: 
java.math.BigInteger.modInverse(java.math.BigInteger) 
(/usr/local/gcc/lib/libgcj.so.3)
 >    at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() 
(/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
 >    at 0x0805ee1f: 
test::sig::rsa::TestOfRSAKeyGeneration::testKeyPairGeneration() 
(/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSAKeyGeneration.java:101)

looking at gnu.crypto.rsa.RSAKeyPairGenerator, and the classpath
BigInteger implementation, the exception is thrown from line 205 (in the
RSA keypair generator):

d = e.modInverse(phi);

the problem is that if we made it to that line, this exception should
not be thrown, hence the cause may be in how modInverse is implemented 
in the concrete BigInteger class.  i'll inspect the source later.

 > java.lang.ArithmeticException: not invertible...
 > java.lang.ArithmeticException: not invertible...
 > java.lang.ArithmeticException: not invertible...
 > java.lang.ArithmeticException: not invertible...
 > java.lang.ArithmeticException: not invertible...
 > java.lang.ArithmeticException: not invertible...

idem.

 >    at 0x40075ccb: gnu.crypto.sig.rsa.RSAKeyPairGenerator.generate() 
(/home/olivier/tmp/ccc/source/.libs/lib-gnu-crypto.so.1)
 >    at 0x0805eb95: test::sig::rsa::TestOfRSACodec::setUp() 
(/home/olivier/program/cvsrsh/crypto/gcj/source/test/sig/rsa/TestOfRSACodec.java:148)

suspect (without knowing at which line it was thrown) that it's at the 
same place as 2) - 7) above.

 > java.security.NoSuchAlgorithmException: ripemd128

same as the Failures earlier.

 > java.lang.NullPointerException...
 > java.lang.NullPointerException...
 > java.lang.NullPointerException...
 > java.lang.NullPointerException...

similar problem (and similar work-around) to the MessageDigest.getInstance()

cheers;
rsn

---

From: Olivier LF <[email-masked]>
Date: Wed, 3 Jul 2002 23:38:28 +1000

> the implemetation *does not* handle algorithm aliasing at all!

First of all be aware that "classpath" and "gcj" don't always share
the same code. They are merging differences step by step. 
In gcj the classes are under:

   gcc/libjava/java

> + return getInstance(className, algorithm, p);

The gcj implementation of MessageDigest looks the same as classpath.
I haven't tried your patch yet. I did try the naive approach of replacing:

   MessageDigest md = MessageDigest.getInstance("SHA", GNU);
   ...
   ...
   MessageDigest md = MessageDigest.getInstance("WHirlpool", GNU);

with:

   MessageDigest md = MessageDigest.getInstance("SHA-160", GNU);
   ...
   ...
   MessageDigest md = MessageDigest.getInstance("WHIRLPOOL", GNU);

In TestOfProvider.java, I now get:

java.lang.ClassCastException: gnu.crypto.jce.Sha160Spi cannot be cast to
java.security.MessageDigest
...
...
java.lang.ClassCastException: gnu.crypto.jce.WhirlpoolSpi cannot be cast
to java.security.MessageDigest

???

Oli

---

From: "Raif S. Naffah" <[email-masked]>
Date: Thu, 04 Jul 2002 02:31:55 +1000

Olivier LF wrote:
> ...I did try the naive approach of replacing:
> 

this is a 2nd bug in the MessageDigest implementation (method 
getInstance with 3 args) caused by the line:

MessageDigest m =
       (MessageDigest) Class.forName(classname).newInstance();

the fix is:

1. to catch the ClassCastException,
2. test if the newly instantiated class is an instance of 
java.security.MessageDigestSpi,
3. if it isnt throw the exception, otherwise
4. wrap the newly instantiated class in a proxy class that channels the 
MessageDigest calls to the wrapped Spi class.

how about that!  we started testing our code, and ended up testing the 
gcj/classpath.

do you have enough info to file bug reports?

cheers;
rsn