Added wrapper for safe supply of random bytes for use in Java side.

This commit is contained in:
gardners 2011-10-23 18:54:10 +10:30
parent 77757f550d
commit 4636cd6577

13
jni.c
View File

@ -8,6 +8,19 @@ JNIEXPORT jint JNICALL Java_to_yp_cr_NaCl_moose
return 1;
}
JNIEXPORT jint JNICALL Java_to_yp_cr_NaCl_nativeRandomBytes
(JNIEnv *env, jobject obj, jbyteArray bytes)
{
int l=(*env)->GetArrayLength(env, bytes);
if (l<1) return -1;
jbyte *b = (*env)->GetPrimitiveArrayCritical(env, bytes, NULL);
randombytes(b,l);
if (b) (*env)->ReleasePrimitiveArrayCritical(env, bytes, b, 0);
return 0;
}
// Lto/yp/cr/NaCl$CryptoBoxKeypair;.method ([B[B)I
JNIEXPORT jint JNICALL Java_to_yp_cr_NaCl_nativeCryptoBoxKeypair
(JNIEnv *env, jobject obj, jbyteArray jsk, jbyteArray jpk)