Package org.bitcoin
Class NativeSecp256k1
java.lang.Object
org.bitcoin.NativeSecp256k1
This class holds native methods to handle ECDSA verification.
You can find an example library that can be used for this at https://github.com/bitcoin/secp256k1
To build secp256k1 for use with bitcoinj, run `./configure --enable-jni --enable-experimental --enable-module-schnorr --enable-module-ecdh` and `make` then copy `.libs/libsecp256k1.so` to your system library path or point the JVM to the folder containing it with -Djava.library.path
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanup()libsecp256k1 Cleanup - This destroys the secp256k1 context object This should be called at the end of the program for proper cleanup of the context.static longClone contextstatic byte[]computePubkey(byte[] seckey) libsecp256k1 Compute Pubkey - computes public key from secret keystatic byte[]createECDHSecret(byte[] seckey, byte[] pubkey) libsecp256k1 create ECDH secret - constant time ECDH calculationstatic byte[]privKeyTweakAdd(byte[] privkey, byte[] tweak) libsecp256k1 PrivKey Tweak-Add - Tweak privkey by adding to itstatic byte[]privKeyTweakMul(byte[] privkey, byte[] tweak) libsecp256k1 PrivKey Tweak-Mul - Tweak privkey by multiplying to itstatic byte[]pubKeyTweakAdd(byte[] pubkey, byte[] tweak) libsecp256k1 PubKey Tweak-Add - Tweak pubkey by adding to itstatic byte[]pubKeyTweakMul(byte[] pubkey, byte[] tweak) libsecp256k1 PubKey Tweak-Mul - Tweak pubkey by multiplying to itstatic booleanrandomize(byte[] seed) libsecp256k1 randomize - updates the context randomizationstatic byte[]schnorrSign(byte[] data, byte[] sec) static booleansecKeyVerify(byte[] seckey) libsecp256k1 Seckey Verify - returns 1 if valid, 0 if invalidstatic byte[]sign(byte[] data, byte[] sec) libsecp256k1 Create an ECDSA signature.static booleanverify(byte[] data, byte[] signature, byte[] pub) Verifies the given secp256k1 signature in native code.
-
Constructor Details
-
NativeSecp256k1
public NativeSecp256k1()
-
-
Method Details
-
verify
public static boolean verify(byte[] data, byte[] signature, byte[] pub) throws NativeSecp256k1Util.AssertFailException Verifies the given secp256k1 signature in native code. Calling when enabled == false is undefined (probably library not loaded)- Parameters:
data- The data which was signed, must be exactly 32 bytessignature- The signaturepub- The public key which did the signing- Returns:
- true if correct signature
- Throws:
NativeSecp256k1Util.AssertFailException- never thrown?
-
sign
libsecp256k1 Create an ECDSA signature.- Parameters:
data- Message hash, 32 bytessec- Secret key, 32 bytes- Returns:
- sig byte array of signature
- Throws:
NativeSecp256k1Util.AssertFailException- on bad signature length
-
secKeyVerify
public static boolean secKeyVerify(byte[] seckey) libsecp256k1 Seckey Verify - returns 1 if valid, 0 if invalid- Parameters:
seckey- ECDSA Secret key, 32 bytes- Returns:
- true if valid, false if invalid
-
computePubkey
libsecp256k1 Compute Pubkey - computes public key from secret key- Parameters:
seckey- ECDSA Secret key, 32 bytes- Returns:
- pubkey ECDSA Public key, 33 or 65 bytes
- Throws:
NativeSecp256k1Util.AssertFailException- if bad pubkey length
-
cleanup
public static void cleanup()libsecp256k1 Cleanup - This destroys the secp256k1 context object This should be called at the end of the program for proper cleanup of the context. -
cloneContext
public static long cloneContext()Clone context- Returns:
- context reference
-
privKeyTweakMul
public static byte[] privKeyTweakMul(byte[] privkey, byte[] tweak) throws NativeSecp256k1Util.AssertFailException libsecp256k1 PrivKey Tweak-Mul - Tweak privkey by multiplying to it- Parameters:
tweak- some bytes to tweak withprivkey- 32-byte seckey- Returns:
- The tweaked private key
- Throws:
NativeSecp256k1Util.AssertFailException- assertion failure
-
privKeyTweakAdd
public static byte[] privKeyTweakAdd(byte[] privkey, byte[] tweak) throws NativeSecp256k1Util.AssertFailException libsecp256k1 PrivKey Tweak-Add - Tweak privkey by adding to it- Parameters:
tweak- some bytes to tweak withprivkey- 32-byte seckey- Returns:
- The tweaked private key
- Throws:
NativeSecp256k1Util.AssertFailException- assertion failure
-
pubKeyTweakAdd
public static byte[] pubKeyTweakAdd(byte[] pubkey, byte[] tweak) throws NativeSecp256k1Util.AssertFailException libsecp256k1 PubKey Tweak-Add - Tweak pubkey by adding to it- Parameters:
tweak- some bytes to tweak withpubkey- 32-byte seckey- Returns:
- The tweaked private key
- Throws:
NativeSecp256k1Util.AssertFailException- assertion failure
-
pubKeyTweakMul
public static byte[] pubKeyTweakMul(byte[] pubkey, byte[] tweak) throws NativeSecp256k1Util.AssertFailException libsecp256k1 PubKey Tweak-Mul - Tweak pubkey by multiplying to it- Parameters:
tweak- some bytes to tweak withpubkey- 32-byte seckey- Returns:
- The tweaked private key
- Throws:
NativeSecp256k1Util.AssertFailException- assertion failure
-
createECDHSecret
public static byte[] createECDHSecret(byte[] seckey, byte[] pubkey) throws NativeSecp256k1Util.AssertFailException libsecp256k1 create ECDH secret - constant time ECDH calculation- Parameters:
seckey- byte array of secret key used in exponentiationpubkey- byte array of public key used in exponentiation- Returns:
- the secret
- Throws:
NativeSecp256k1Util.AssertFailException- assertion failure
-
randomize
libsecp256k1 randomize - updates the context randomization- Parameters:
seed- 32-byte random seed- Returns:
- true if successful, false otherwise
- Throws:
NativeSecp256k1Util.AssertFailException- never thrown?
-
schnorrSign
public static byte[] schnorrSign(byte[] data, byte[] sec) throws NativeSecp256k1Util.AssertFailException - Parameters:
data- data to signsec- secret key- Returns:
- Signature or byte[0]
- Throws:
NativeSecp256k1Util.AssertFailException- assertion failure
-