Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/java/org/bitcoin/NativeSecp256k1.java
Show First 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | public static synchronized boolean randomize(byte[] seed) throws AssertFailException{ | ||||
w.lock(); | w.lock(); | ||||
try { | try { | ||||
return secp256k1_context_randomize(byteBuff, Secp256k1Context.getContext()) == 1; | return secp256k1_context_randomize(byteBuff, Secp256k1Context.getContext()) == 1; | ||||
} finally { | } finally { | ||||
w.unlock(); | w.unlock(); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Verifies the given Schnorr signature in native code. | |||||
* Calling when enabled == false is undefined (probably library not loaded) | |||||
* | |||||
* @param data The data which was signed, must be exactly 32 bytes | |||||
* @param signature The signature is exactly 64 bytes | |||||
* @param pub The public key which did the signing which is the same ECDSA | |||||
*/ | |||||
public static boolean schnorrVerify(byte[] data, byte[] signature, byte[] pub) { | |||||
checkArgument(data.length == 32 && signature.length == 64 && (pub.length == 33 || pub.length == 65)); | |||||
ByteBuffer byteBuff = nativeECDSABuffer.get(); | |||||
if (byteBuff == null || byteBuff.capacity() < 32 + 64 + pub.length) { | |||||
byteBuff = ByteBuffer.allocateDirect(32 + 64 + pub.length); | |||||
byteBuff.order(ByteOrder.nativeOrder()); | |||||
nativeECDSABuffer.set(byteBuff); | |||||
} | |||||
byteBuff.rewind(); | |||||
byteBuff.put(data); | |||||
byteBuff.put(signature); | |||||
byteBuff.put(pub); | |||||
r.lock(); | |||||
try { | |||||
return secp256k1_schnorr_verify(byteBuff, Secp256k1Context.getContext(), pub.length) == 1; | |||||
} finally { | |||||
r.unlock(); | |||||
} | |||||
} | |||||
private static native long secp256k1_ctx_clone(long context); | private static native long secp256k1_ctx_clone(long context); | ||||
private static native int secp256k1_context_randomize(ByteBuffer byteBuff, long context); | private static native int secp256k1_context_randomize(ByteBuffer byteBuff, long context); | ||||
private static native byte[][] secp256k1_privkey_tweak_add(ByteBuffer byteBuff, long context); | private static native byte[][] secp256k1_privkey_tweak_add(ByteBuffer byteBuff, long context); | ||||
private static native byte[][] secp256k1_privkey_tweak_mul(ByteBuffer byteBuff, long context); | private static native byte[][] secp256k1_privkey_tweak_mul(ByteBuffer byteBuff, long context); | ||||
private static native byte[][] secp256k1_pubkey_tweak_add(ByteBuffer byteBuff, long context, int pubLen); | private static native byte[][] secp256k1_pubkey_tweak_add(ByteBuffer byteBuff, long context, int pubLen); | ||||
private static native byte[][] secp256k1_pubkey_tweak_mul(ByteBuffer byteBuff, long context, int pubLen); | private static native byte[][] secp256k1_pubkey_tweak_mul(ByteBuffer byteBuff, long context, int pubLen); | ||||
private static native void secp256k1_destroy_context(long context); | private static native void secp256k1_destroy_context(long context); | ||||
private static native int secp256k1_ecdsa_verify(ByteBuffer byteBuff, long context, int sigLen, int pubLen); | private static native int secp256k1_ecdsa_verify(ByteBuffer byteBuff, long context, int sigLen, int pubLen); | ||||
private static native byte[][] secp256k1_ecdsa_sign(ByteBuffer byteBuff, long context); | private static native byte[][] secp256k1_ecdsa_sign(ByteBuffer byteBuff, long context); | ||||
private static native int secp256k1_ec_seckey_verify(ByteBuffer byteBuff, long context); | private static native int secp256k1_ec_seckey_verify(ByteBuffer byteBuff, long context); | ||||
private static native byte[][] secp256k1_ec_pubkey_create(ByteBuffer byteBuff, long context); | private static native byte[][] secp256k1_ec_pubkey_create(ByteBuffer byteBuff, long context); | ||||
private static native byte[][] secp256k1_ec_pubkey_parse(ByteBuffer byteBuff, long context, int inputLen); | private static native byte[][] secp256k1_ec_pubkey_parse(ByteBuffer byteBuff, long context, int inputLen); | ||||
private static native int secp256k1_schnorr_verify(ByteBuffer byteBuff, long context, int pubLen); | |||||
private static native byte[][] secp256k1_ecdh(ByteBuffer byteBuff, long context, int inputLen); | private static native byte[][] secp256k1_ecdh(ByteBuffer byteBuff, long context, int inputLen); | ||||
} | } |