3 import com.google.common.io.BaseEncoding;
4 import java.util.Arrays;
5 import java.math.BigInteger;
6 import javax.xml.bind.DatatypeConverter;
19 boolean result =
false;
20 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"CF80CD8AED482D5D1527D7DC72FCEFF84E6326592848447D2DC0B0E87DFC9A90".toLowerCase());
21 byte[] sig = BaseEncoding.base16().lowerCase().decode(
"3044022079BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F817980220294F14E883B3F525B5367756C2A11EF6CF84B730B36C17CB0C56F0AAB2C98589".toLowerCase());
22 byte[] pub = BaseEncoding.base16().lowerCase().decode(
"040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
25 assertEquals( result,
true ,
"testVerifyPos");
32 boolean result =
false;
33 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"CF80CD8AED482D5D1527D7DC72FCEFF84E6326592848447D2DC0B0E87DFC9A91".toLowerCase());
34 byte[] sig = BaseEncoding.base16().lowerCase().decode(
"3044022079BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F817980220294F14E883B3F525B5367756C2A11EF6CF84B730B36C17CB0C56F0AAB2C98589".toLowerCase());
35 byte[] pub = BaseEncoding.base16().lowerCase().decode(
"040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
39 assertEquals( result,
false ,
"testVerifyNeg");
46 boolean result =
false;
47 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
51 assertEquals( result,
true ,
"testSecKeyVerifyPos");
58 boolean result =
false;
59 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".toLowerCase());
63 assertEquals( result,
false ,
"testSecKeyVerifyNeg");
70 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
73 String pubkeyString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
74 assertEquals( pubkeyString ,
"04C591A8FF19AC9C4E4E5793673B83123437E975285E7B442F4EE2654DFFCA5E2D2103ED494718C697AC9AEBCFD19612E224DB46661011863ED2FC54E71861E2A6" ,
"testPubKeyCreatePos");
81 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".toLowerCase());
84 String pubkeyString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
85 assertEquals( pubkeyString,
"" ,
"testPubKeyCreateNeg");
93 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"CF80CD8AED482D5D1527D7DC72FCEFF84E6326592848447D2DC0B0E87DFC9A90".toLowerCase());
94 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
97 String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
98 assertEquals( sigString,
"30440220182A108E1448DC8F1FB467D06A0F3BB8EA0533584CB954EF8DA112F1D60E39A202201C66F36DA211C087F3AF88B50EDF4F9BDAA6CF5FD6817E74DCA34DB12390C6E9" ,
"testSignPos");
105 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"CF80CD8AED482D5D1527D7DC72FCEFF84E6326592848447D2DC0B0E87DFC9A90".toLowerCase());
106 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".toLowerCase());
109 String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
110 assertEquals( sigString,
"" ,
"testSignNeg");
117 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
118 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase());
121 String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
122 assertEquals( sigString ,
"A168571E189E6F9A7E2D657A4B53AE99B909F7E712D1C23CED28093CD57C88F3" ,
"testPrivKeyAdd_1");
129 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
130 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase());
133 String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
134 assertEquals( sigString ,
"97F8184235F101550F3C71C927507651BD3F1CDB4A5A33B8986ACF0DEE20FFFC" ,
"testPrivKeyMul_1");
141 byte[] pub = BaseEncoding.base16().lowerCase().decode(
"040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
142 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase());
145 String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
146 assertEquals( sigString ,
"0411C6790F4B663CCE607BAAE08C43557EDC1A4D11D88DFCB3D841D0C6A941AF525A268E2A863C148555C48FB5FBA368E88718A46E205FABC3DBA2CCFFAB0796EF" ,
"testPrivKeyAdd_2");
153 byte[] pub = BaseEncoding.base16().lowerCase().decode(
"040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
154 byte[]
data = BaseEncoding.base16().lowerCase().decode(
"3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase());
157 String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
158 assertEquals( sigString ,
"04E0FE6FE55EBCA626B98A807F6CAF654139E14E5E3698F01A9A658E21DC1D2791EC060D4F412A794D5370F672BC94B722640B5F76914151CFCA6E712CA48CC589" ,
"testPrivKeyMul_2");
165 byte[] seed = BaseEncoding.base16().lowerCase().decode(
"A441B15FE9A3CF56661190A0B93B9DEC7D04127288CC87250967CF3B52894D11".toLowerCase());
167 assertEquals( result,
true,
"testRandomize");
172 byte[] sec = BaseEncoding.base16().lowerCase().decode(
"67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
173 byte[] pub = BaseEncoding.base16().lowerCase().decode(
"040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
176 String ecdhString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
177 assertEquals( ecdhString,
"2A2A67007A926E6594AF3EB564FC74005B37A9C8AEF2033C4552051B5C87F043" ,
"testCreateECDHSecret");
180 public static void main(String[] args)
throws AssertFailException{
223 System.out.println(
" All tests passed." );
static void main(String[] args)
static byte[] pubKeyTweakAdd(byte[] pubkey, byte[] tweak)
libsecp256k1 PubKey Tweak-Add - Tweak pubkey by adding to it
This class holds test cases defined for testing this library.
static void testSignNeg()
This tests sign() for a invalid secretkey.
static void testPrivKeyTweakAdd_2()
This tests private key tweak-add uncompressed.
static void testPrivKeyTweakMul_1()
This tests private key tweak-mul.
static void testRandomize()
This tests seed randomization.
static boolean verify(byte[] data, byte[] signature, byte[] pub)
Verifies the given secp256k1 signature in native code.
static void testPrivKeyTweakMul_2()
This tests private key tweak-mul uncompressed.
static byte[] privKeyTweakAdd(byte[] privkey, byte[] tweak)
libsecp256k1 PrivKey Tweak-Add - Tweak privkey by adding to it
static byte[] computePubkey(byte[] seckey)
libsecp256k1 Compute Pubkey - computes public key from secret key
static byte[] pubKeyTweakMul(byte[] pubkey, byte[] tweak)
libsecp256k1 PubKey Tweak-Mul - Tweak pubkey by multiplying to it
static boolean isEnabled()
static byte[] createECDHSecret(byte[] seckey, byte[] pubkey)
libsecp256k1 create ECDH secret - constant time ECDH calculation
static byte[] sign(byte[] data, byte[] sec)
libsecp256k1 Create an ECDSA signature.
static void testSecKeyVerifyPos()
This tests secret key verify() for a valid secretkey.
static void testPubKeyCreatePos()
This tests public key create() for a valid secretkey.
static void testVerifyPos()
This tests verify() for a valid signature.
static synchronized boolean randomize(byte[] seed)
libsecp256k1 randomize - updates the context randomization
static boolean secKeyVerify(byte[] seckey)
libsecp256k1 Seckey Verify - returns 1 if valid, 0 if invalid
static void testSignPos()
This tests sign() for a valid secretkey.
static void testVerifyNeg()
This tests verify() for a non-valid signature.
static void testCreateECDHSecret()
static void testSecKeyVerifyNeg()
This tests secret key verify() for a invalid secretkey.
This class holds the context reference used in native methods to handle ECDSA operations.
static byte[] privKeyTweakMul(byte[] privkey, byte[] tweak)
libsecp256k1 PrivKey Tweak-Mul - Tweak privkey by multiplying to it
static synchronized void cleanup()
libsecp256k1 Cleanup - This destroys the secp256k1 context object This should be called at the end of...
static void testPubKeyCreateNeg()
This tests public key create() for a invalid secretkey.
static void testPrivKeyTweakAdd_1()
This tests private key tweak-add.