20import java.nio.ByteBuffer;
21import java.nio.ByteOrder;
23import java.math.BigInteger;
24import java.util.concurrent.locks.Lock;
25import java.util.concurrent.locks.ReentrantReadWriteLock;
26import static org.bitcoin.NativeSecp256k1Util.*;
42 private static final Lock
r =
rwl.readLock();
43 private static final Lock
w =
rwl.writeLock();
53 public static boolean verify(
byte[] data,
byte[] signature,
byte[]
pub) {
54 checkArgument(data.length == 32 && signature.length <= 520 &&
pub.length <= 520);
84 public static byte[]
sign(
byte[] data,
byte[]
sec)
throws AssertFailException{
85 checkArgument(data.length == 32 &&
sec.length <= 32);
110 assertEquals(
sigArr.length,
sigLen,
"Got bad signature length.");
121 checkArgument(
seckey.length == 32);
151 checkArgument(
seckey.length == 32);
175 assertEquals(
pubArr.length,
pubLen,
"Got bad pubkey length.");
197 }
finally {
r.unlock(); }
207 checkArgument(
privkey.length == 32);
234 assertEquals(
retVal, 1,
"Failed return value check.");
246 checkArgument(
privkey.length == 32);
273 assertEquals(
retVal, 1,
"Failed return value check.");
285 checkArgument(pubkey.length == 33 || pubkey.length == 65);
310 assertEquals(
pubArr.length,
pubLen,
"Got bad pubkey length.");
312 assertEquals(
retVal, 1,
"Failed return value check.");
324 checkArgument(pubkey.length == 33 || pubkey.length == 65);
349 assertEquals(
pubArr.length,
pubLen,
"Got bad pubkey length.");
351 assertEquals(
retVal, 1,
"Failed return value check.");
363 checkArgument(
seckey.length <= 32 && pubkey.length <= 65);
386 assertEquals(
resArr.length, 32,
"Got bad result length.");
387 assertEquals(
retVal, 1,
"Failed return value check.");
397 public static synchronized boolean randomize(
byte[] seed)
throws AssertFailException{
398 checkArgument(seed.length == 32 || seed ==
null);
425 checkArgument(data.length == 32 &&
seckey.length <= 32);
449 assertEquals(
sigArr.length, 64,
"Got bad signature length.");
463 checkArgument(data.length == 32 && signature.length == 64 && (
pub.length == 33 ||
pub.length == 65));
static byte[] createECDHSecret(byte[] seckey, byte[] pubkey)
libsecp256k1 create ECDH secret - constant time ECDH calculation
static boolean schnorrVerify(byte[] data, byte[] signature, byte[] pub)
Verifies the given Schnorr signature in native code.
static native int secp256k1_schnorr_verify(ByteBuffer byteBuff, long context, int pubLen)
static native byte[][] secp256k1_ecdh(ByteBuffer byteBuff, long context, int inputLen)
static byte[] privKeyTweakAdd(byte[] privkey, byte[] tweak)
libsecp256k1 PrivKey Tweak-Add - Tweak privkey by adding to it
static native byte[][] secp256k1_schnorr_sign(ByteBuffer byteBuff, long context)
static byte[] pubKeyTweakMul(byte[] pubkey, byte[] tweak)
libsecp256k1 PubKey Tweak-Mul - Tweak pubkey by multiplying to it
static ThreadLocal< ByteBuffer > nativeByteBuffer
static native byte[][] secp256k1_ec_pubkey_create(ByteBuffer byteBuff, long context)
static final ReentrantReadWriteLock rwl
static native long secp256k1_ctx_clone(long context)
static native int secp256k1_ecdsa_verify(ByteBuffer byteBuff, long context, int sigLen, int pubLen)
static byte[] sign(byte[] data, byte[] sec)
libsecp256k1 Create an ECDSA signature.
static synchronized boolean randomize(byte[] seed)
libsecp256k1 randomize - updates the context randomization
static boolean verify(byte[] data, byte[] signature, byte[] pub)
Verifies the given secp256k1 signature in native code.
static byte[] pubKeyTweakAdd(byte[] pubkey, byte[] tweak)
libsecp256k1 PubKey Tweak-Add - Tweak pubkey by adding to it
static long cloneContext()
static native byte[][] secp256k1_ec_pubkey_parse(ByteBuffer byteBuff, long context, int inputLen)
static byte[] privKeyTweakMul(byte[] privkey, byte[] tweak)
libsecp256k1 PrivKey Tweak-Mul - Tweak privkey by multiplying to it
static native byte[][] secp256k1_privkey_tweak_add(ByteBuffer byteBuff, long context)
static native byte[][] secp256k1_privkey_tweak_mul(ByteBuffer byteBuff, long context)
static native byte[][] secp256k1_pubkey_tweak_mul(ByteBuffer byteBuff, long context, int pubLen)
static native void secp256k1_destroy_context(long context)
static byte[] schnorrSign(byte[] data, byte[] seckey)
libsecp256k1 Create a Schnorr signature.
static byte[] computePubkey(byte[] seckey)
libsecp256k1 Compute Pubkey - computes public key from secret key
static native byte[][] secp256k1_pubkey_tweak_add(ByteBuffer byteBuff, long context, int pubLen)
static synchronized void cleanup()
libsecp256k1 Cleanup - This destroys the secp256k1 context object This should be called at the end of...
static native byte[][] secp256k1_ecdsa_sign(ByteBuffer byteBuff, long context)
static boolean secKeyVerify(byte[] seckey)
libsecp256k1 Seckey Verify - returns 1 if valid, 0 if invalid
static native int secp256k1_ec_seckey_verify(ByteBuffer byteBuff, long context)
static native int secp256k1_context_randomize(ByteBuffer byteBuff, long context)
This class holds the context reference used in native methods to handle ECDSA operations.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...