File: jni.cc

package info (click to toggle)
libequihash 1.0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208 kB
  • sloc: cpp: 391; ansic: 235; sh: 75; makefile: 56; python: 44
file content (42 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <jni.h>

extern "C" {

#include "equihash.h"

JNIEXPORT jbyteArray JNICALL Java_org_hsbp_equihash_Equihash_solve(JNIEnv *env,
		jobject ignore, jint n, jint k, jbyteArray seed) {
	jbyte* bufferPtrSeed = env->GetByteArrayElements(seed, NULL);
	const jsize seedLen = env->GetArrayLength(seed);

	const size_t csolLen = solsize(n, k);
	jbyteArray csol = env->NewByteArray(csolLen);
	jbyte* bufferPtrCSol = env->GetByteArrayElements(csol, NULL);

	int result = solve(n, k, (const uint8_t*)bufferPtrSeed, seedLen,
			(uint8_t*)bufferPtrCSol, csolLen);

	env->ReleaseByteArrayElements(csol, bufferPtrCSol, result ? 0 : JNI_ABORT);
	env->ReleaseByteArrayElements(seed, bufferPtrSeed, JNI_ABORT);

	return result ? csol : NULL;
}

JNIEXPORT jboolean JNICALL Java_org_hsbp_equihash_Equihash_verify(JNIEnv *env,
		jobject ignore, jint n, jint k, jbyteArray seed, jbyteArray sol) {
	jbyte* bufferPtrSeed = env->GetByteArrayElements(seed, NULL);
	jsize seedLen = env->GetArrayLength(seed);

	jbyte* bufferPtrSol  = env->GetByteArrayElements( sol, NULL);
	jsize  solLen = env->GetArrayLength( sol);

	int result = verify(n, k, (const uint8_t*)bufferPtrSeed, seedLen,
			(const uint8_t*)bufferPtrSol, solLen);

	env->ReleaseByteArrayElements( sol, bufferPtrSol , JNI_ABORT);
	env->ReleaseByteArrayElements(seed, bufferPtrSeed, JNI_ABORT);

	return result == 1 ? JNI_TRUE : JNI_FALSE;
}

}