Package org.bitcoin

Class NativeSecp256k1


  • public class NativeSecp256k1
    extends java.lang.Object

    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 
      Constructor Description
      NativeSecp256k1()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      static long cloneContext()
      Clone context
      static byte[] computePubkey​(byte[] seckey)
      libsecp256k1 Compute Pubkey - computes public key from secret key
      static byte[] createECDHSecret​(byte[] seckey, byte[] pubkey)
      libsecp256k1 create ECDH secret - constant time ECDH calculation
      static byte[] privKeyTweakAdd​(byte[] privkey, byte[] tweak)
      libsecp256k1 PrivKey Tweak-Add - Tweak privkey by adding to it
      static byte[] privKeyTweakMul​(byte[] privkey, byte[] tweak)
      libsecp256k1 PrivKey Tweak-Mul - Tweak privkey by multiplying to it
      static byte[] pubKeyTweakAdd​(byte[] pubkey, byte[] tweak)
      libsecp256k1 PubKey Tweak-Add - Tweak pubkey by adding to it
      static byte[] pubKeyTweakMul​(byte[] pubkey, byte[] tweak)
      libsecp256k1 PubKey Tweak-Mul - Tweak pubkey by multiplying to it
      static boolean randomize​(byte[] seed)
      libsecp256k1 randomize - updates the context randomization
      static byte[] schnorrSign​(byte[] data, byte[] sec)  
      static boolean secKeyVerify​(byte[] seckey)
      libsecp256k1 Seckey Verify - returns 1 if valid, 0 if invalid
      static byte[] sign​(byte[] data, byte[] sec)
      libsecp256k1 Create an ECDSA signature.
      static boolean verify​(byte[] data, byte[] signature, byte[] pub)
      Verifies the given secp256k1 signature in native code.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NativeSecp256k1

        public NativeSecp256k1()
    • Method Detail

      • 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 bytes
        signature - The signature
        pub - The public key which did the signing
        Returns:
        true if correct signature
        Throws:
        NativeSecp256k1Util.AssertFailException - never thrown?
      • 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
      • 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
      • 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 exponentiation
        pubkey - byte array of public key used in exponentiation
        Returns:
        the secret
        Throws:
        NativeSecp256k1Util.AssertFailException - assertion failure