views:

103

answers:

1

I want to generate JNI wrappers from C/C++ code.

Here is my interface file.

/* aes_security.i */
%module jni_security_example
%{
  #include "pbkdf2.h"
%}

extern int pbkdf2_sha1 (const char *passphrase, size_t passphraseLength,
       const char *SSID, size_t SSIDlen,
       unsigned int iterationCount,
       char *aeskey, size_t keyLength);

extern int GenrateIV_16_Bytes(unsigned char *IV);

Here is snippet of SWIG-generated Java code

 public static int pbkdf2_sha1(String passphrase, long passphraseLength,
 String SSID, long SSIDlen, long encryptGrade, String key,
 long keyLength) {
   return cot_jni_security_exampleJNI.pbkdf2_sha1(passphrase,
  passphraseLength, SSID, SSIDlen, encryptGrade, key,    keyLength);
 }

public static int GenrateIV_16_Bytes(SWIGTYPE_p_unsigned_char IV) {
  return cot_jni_security_exampleJNI
     .GenrateIV_16_Bytes(SWIGTYPE_p_unsigned_char.getCPtr(IV));
 }

Here is how I'm invoking the JNI code.

private String PASSPHRASE = "password";
private String SSID = "dummyssid";
private long iterationCount = 4096;

public String pbkdf2SHA1() {

  int keyLength = 32;
  char[] aesKey = new char[keyLength];
  int result = pbkdf2_sha1(PASSPHRASE, (long) PASSPHRASE.length(), SSID,
  SSID.length(), iterationCount, aesKey.toString(),
  (long) keyLength);
  Log.e(TAG, "Result " + result);

  return  new String(aesKey);

 }

The code compiles but when I run it crashes somewhere in the C code. Any help will be appreciated.

Thanks.

A: 

I donno Java or JNI. However there might be some problem in your C Code. try calling pbkdf2_sha1() from a C Interface. If it crashes its a problem in C Code. Otherwise find out the Crash point. May be there is a problem in casting when it takes arguments