Creating native binaries using GNU-Crypto
Stefan Prelle
prelle@informatik.uni-bremen.de
Thu Dec 11 14:24:00 GMT 2003
Hello,
On Thu, 2003-12-11 at 10:25, Raif S. Naffah wrote:
> can you provide a minimal code that causes the exception; i.e. after
> adding the GnuCrypto Provider, and when acquiring an algorithm.
This is not so simple as I thought since when trying to produce such an
example I got totally different results.
I started with the following example:
public class GetClassTest {
public static void main(String[] args) {
try {
Class cls = Class.forName("gnu.crypto.jce.GnuCrypto");
System.out.println("Shouldn't be null: "+cls);
} catch (Exception e){
e.printStackTrace();
}
}
}
and compiled it using
gcj -g -O2 -o GetClassTest --main=GetClassTest GetClassTest.java
/home/prelle/platform/linuxpc/lib/lib-gnu-crypto.so
/home/prelle/platform/linuxpc/lib/lib-javax-crypto.so
This went fine and on execution I got
Shouldn't be null: class gnu.crypto.jce.GnuCrypto
In my original full blown code this didn't work.
Then I modified the code:
import java.security.Provider;
import java.security.Security;
import javax.crypto.Mac;
public class GetClassTest {
public static void main(String[] args) {
try {
Class cls = Class.forName("gnu.crypto.jce.GnuCrypto");
System.out.println("Shouldn't be null: "+cls);
Provider prov = (Provider)cls.newInstance();
Security.addProvider(prov);
Mac mac = Mac.getInstance("HMAC-MD5");
System.out.println("Mac is "+mac);
} catch (Exception e){
e.printStackTrace();
}
}
}
Since I was using javax.crypto I added
-I/home/prelle/platform/linuxpc/share/javax-crypto.jar
to my compile command.
On execution the program segfaulted on calling the newInstance() method
of the class I got. Here is a backtrace using gdb.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 17909)]
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
#1 0x40579319 in java.io.FilterInputStream.read(byte[], int, int)
(this=0x80e9000, buf=0x80e9000, offset=135172096, len=135172096)
at ../../../gcc/libjava/java/io/FilterInputStream.java:189
#2 0x40570d6d in java.io.BufferedInputStream.refill() (this=0x80a1ee0)
at ../../../gcc/libjava/java/io/BufferedInputStream.java:352
#3 0x40579b88 in java.io.InputStreamReader.refill() (this=0x80a1f00) at
../../../gcc/libjava/java/io/InputStreamReader.java:290
#4 0x40579f0e in java.io.InputStreamReader.read(char[], int, int)
(this=0x80a1f00, buf=0x80e9000, offset=135172096, length=8192)
at ../../../gcc/libjava/java/io/InputStreamReader.java:235
#5 0x405718c3 in java.io.BufferedReader.fill() (this=0x80e4480) at
../../../gcc/libjava/java/io/BufferedReader.java:358
#6 0x40571bbb in java.io.BufferedReader.read() (this=0x80a1f00) at
../../../gcc/libjava/java/io/BufferedReader.java:381
#7 0x40571d12 in java.io.BufferedReader.readLine() (this=0x80e4480) at
../../../gcc/libjava/java/io/BufferedReader.java:453
#8 0x405b0b6c in java.util.Properties.load(java.io.InputStream)
(this=0x80e1f50, inStream=0x80e9000)
at ../../../gcc/libjava/java/util/Properties.java:187
#9 0x405a91a4 in java.util.Hashtable.put(java.lang.Object,
java.lang.Object) (this=0x80e1f50, key=0x80e6550, value=0x809ca20)
at ../../../gcc/libjava/java/util/Hashtable.java:456
#10 0x4065ca8c in java.security.Provider.put(java.lang.Object,
java.lang.Object) (this=0x80a1f00, key=0x80e9000, value=0x80e4480)
at ../../../gcc/libjava/java/security/Provider.java:149
#11 0x40091a96 in gnu.crypto.jce.GnuCrypto.GnuCrypto() (this=0x80a1f00)
at gnu/crypto/jce/GnuCrypto.java:86
#12 0x4054a81c in java::lang::Class::newInstance() (this=0x80e1f50) at
../../../gcc/libjava/java/lang/natClass.cc:730
#13 0x08048ffc in GetClassTest.main(java.lang.String[]) (args=0x8079fe0)
at GetClassTest.java:12
This is not the same problem I had in my full blown library using
autotools. I'm still trying to find the difference.
Regards,
Stefan
More information about the Java
mailing list