Dash Core  0.12.2.1
P2P Digital Currency
NativeSecp256k1.java
Go to the documentation of this file.
1 package org.bitcoin;
2 
3 import java.nio.ByteBuffer;
4 import java.nio.ByteOrder;
5 
6 import com.google.common.base.Preconditions;
7 
8 
14 public class NativeSecp256k1 {
15  public static final boolean enabled;
16  static {
17  boolean isEnabled = true;
18  try {
19  System.loadLibrary("javasecp256k1");
20  } catch (UnsatisfiedLinkError e) {
21  isEnabled = false;
22  }
23  enabled = isEnabled;
24  }
25 
26  private static ThreadLocal<ByteBuffer> nativeECDSABuffer = new ThreadLocal<ByteBuffer>();
35  public static boolean verify(byte[] data, byte[] signature, byte[] pub) {
36  Preconditions.checkArgument(data.length == 32 && signature.length <= 520 && pub.length <= 520);
37 
38  ByteBuffer byteBuff = nativeECDSABuffer.get();
39  if (byteBuff == null) {
40  byteBuff = ByteBuffer.allocateDirect(32 + 8 + 520 + 520);
41  byteBuff.order(ByteOrder.nativeOrder());
42  nativeECDSABuffer.set(byteBuff);
43  }
44  byteBuff.rewind();
45  byteBuff.put(data);
46  byteBuff.putInt(signature.length);
47  byteBuff.putInt(pub.length);
48  byteBuff.put(signature);
49  byteBuff.put(pub);
50  return secp256k1_ecdsa_verify(byteBuff) == 1;
51  }
52 
59  private static native int secp256k1_ecdsa_verify(ByteBuffer byteBuff);
60 }
static ThreadLocal< ByteBuffer > nativeECDSABuffer
static final boolean enabled
static boolean verify(byte[] data, byte[] signature, byte[] pub)
static native int secp256k1_ecdsa_verify(ByteBuffer byteBuff)