From 4636cd6577fecc6fd47bb57ce3a13c8543ca2832 Mon Sep 17 00:00:00 2001 From: gardners Date: Sun, 23 Oct 2011 18:54:10 +1030 Subject: [PATCH] Added wrapper for safe supply of random bytes for use in Java side. --- jni.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jni.c b/jni.c index 136ba12e..93af17ba 100644 --- a/jni.c +++ b/jni.c @@ -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)