mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
Fixing bug in java -> c interface for secp256k1, fixing tests case for secp256k1
This commit is contained in:
parent
486d652814
commit
6799a86782
@ -287,7 +287,7 @@ public class NativeSecp256k1 {
|
|||||||
* @param tweak some bytes to tweak with
|
* @param tweak some bytes to tweak with
|
||||||
* @param pubkey 32-byte seckey
|
* @param pubkey 32-byte seckey
|
||||||
*/
|
*/
|
||||||
public static byte[] pubKeyTweakAdd(byte[] pubkey, byte[] tweak) throws AssertFailException{
|
public static byte[] pubKeyTweakAdd(byte[] pubkey, byte[] tweak, boolean fCompressed) throws AssertFailException{
|
||||||
checkInvariant(pubkey.length == 33 || pubkey.length == 65);
|
checkInvariant(pubkey.length == 33 || pubkey.length == 65);
|
||||||
|
|
||||||
ByteBuffer byteBuff = nativeECDSABuffer.get();
|
ByteBuffer byteBuff = nativeECDSABuffer.get();
|
||||||
@ -303,7 +303,7 @@ public class NativeSecp256k1 {
|
|||||||
byte[][] retByteArray;
|
byte[][] retByteArray;
|
||||||
r.lock();
|
r.lock();
|
||||||
try {
|
try {
|
||||||
retByteArray = secp256k1_pubkey_tweak_add(byteBuff,Secp256k1Context.getContext(), pubkey.length);
|
retByteArray = secp256k1_pubkey_tweak_add(byteBuff,Secp256k1Context.getContext(), pubkey.length, fCompressed);
|
||||||
} finally {
|
} finally {
|
||||||
r.unlock();
|
r.unlock();
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ public class NativeSecp256k1 {
|
|||||||
* @param tweak some bytes to tweak with
|
* @param tweak some bytes to tweak with
|
||||||
* @param pubkey 32-byte seckey
|
* @param pubkey 32-byte seckey
|
||||||
*/
|
*/
|
||||||
public static byte[] pubKeyTweakMul(byte[] pubkey, byte[] tweak) throws AssertFailException{
|
public static byte[] pubKeyTweakMul(byte[] pubkey, byte[] tweak, boolean fCompressed) throws AssertFailException{
|
||||||
checkInvariant(pubkey.length == 33 || pubkey.length == 65);
|
checkInvariant(pubkey.length == 33 || pubkey.length == 65);
|
||||||
|
|
||||||
ByteBuffer byteBuff = nativeECDSABuffer.get();
|
ByteBuffer byteBuff = nativeECDSABuffer.get();
|
||||||
@ -342,7 +342,7 @@ public class NativeSecp256k1 {
|
|||||||
byte[][] retByteArray;
|
byte[][] retByteArray;
|
||||||
r.lock();
|
r.lock();
|
||||||
try {
|
try {
|
||||||
retByteArray = secp256k1_pubkey_tweak_mul(byteBuff,Secp256k1Context.getContext(), pubkey.length);
|
retByteArray = secp256k1_pubkey_tweak_mul(byteBuff,Secp256k1Context.getContext(), pubkey.length, fCompressed);
|
||||||
} finally {
|
} finally {
|
||||||
r.unlock();
|
r.unlock();
|
||||||
}
|
}
|
||||||
@ -428,9 +428,9 @@ public class NativeSecp256k1 {
|
|||||||
|
|
||||||
private static native byte[][] secp256k1_privkey_tweak_mul(ByteBuffer byteBuff, long context);
|
private static native byte[][] secp256k1_privkey_tweak_mul(ByteBuffer byteBuff, long context);
|
||||||
|
|
||||||
private static native byte[][] secp256k1_pubkey_tweak_add(ByteBuffer byteBuff, long context, int pubLen);
|
private static native byte[][] secp256k1_pubkey_tweak_add(ByteBuffer byteBuff, long context, int pubLen, boolean fCompressed);
|
||||||
|
|
||||||
private static native byte[][] secp256k1_pubkey_tweak_mul(ByteBuffer byteBuff, long context, int pubLen);
|
private static native byte[][] secp256k1_pubkey_tweak_mul(ByteBuffer byteBuff, long context, int pubLen, boolean fCompressed);
|
||||||
|
|
||||||
private static native void secp256k1_destroy_context(long context);
|
private static native void secp256k1_destroy_context(long context);
|
||||||
|
|
||||||
|
@ -152,9 +152,9 @@ public class NativeSecp256k1Test {
|
|||||||
byte[] pub = BaseEncoding.base16().lowerCase().decode("040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
|
byte[] pub = BaseEncoding.base16().lowerCase().decode("040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
|
||||||
byte[] data = BaseEncoding.base16().lowerCase().decode("3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase()); //sha256hash of "tweak"
|
byte[] data = BaseEncoding.base16().lowerCase().decode("3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase()); //sha256hash of "tweak"
|
||||||
|
|
||||||
byte[] resultArr = NativeSecp256k1.pubKeyTweakAdd( pub , data );
|
byte[] resultArr = NativeSecp256k1.pubKeyTweakAdd( pub , data, false );
|
||||||
String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
||||||
assertEquals( sigString , "0311C6790F4B663CCE607BAAE08C43557EDC1A4D11D88DFCB3D841D0C6A941AF52" , "testPrivKeyAdd_2");
|
assertEquals( sigString , "0411C6790F4B663CCE607BAAE08C43557EDC1A4D11D88DFCB3D841D0C6A941AF525A268E2A863C148555C48FB5FBA368E88718A46E205FABC3DBA2CCFFAB0796EF" , "testPrivKeyAdd_2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,11 +165,10 @@ public class NativeSecp256k1Test {
|
|||||||
byte[] pub = BaseEncoding.base16().lowerCase().decode("040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
|
byte[] pub = BaseEncoding.base16().lowerCase().decode("040A629506E1B65CD9D2E0BA9C75DF9C4FED0DB16DC9625ED14397F0AFC836FAE595DC53F8B0EFE61E703075BD9B143BAC75EC0E19F82A2208CAEB32BE53414C40".toLowerCase());
|
||||||
byte[] data = BaseEncoding.base16().lowerCase().decode("3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase()); //sha256hash of "tweak"
|
byte[] data = BaseEncoding.base16().lowerCase().decode("3982F19BEF1615BCCFBB05E321C10E1D4CBA3DF0E841C2E41EEB6016347653C3".toLowerCase()); //sha256hash of "tweak"
|
||||||
|
|
||||||
byte[] resultArr = NativeSecp256k1.pubKeyTweakMul( pub , data );
|
byte[] resultArr = NativeSecp256k1.pubKeyTweakMul( pub , data, false );
|
||||||
String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
String sigString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
||||||
assertEquals( sigString , "03E0FE6FE55EBCA626B98A807F6CAF654139E14E5E3698F01A9A658E21DC1D2791" , "testPrivKeyMul_2");
|
assertEquals( sigString , "04E0FE6FE55EBCA626B98A807F6CAF654139E14E5E3698F01A9A658E21DC1D2791EC060D4F412A794D5370F672BC94B722640B5F76914151CFCA6E712CA48CC589", "testPrivKeyMul_2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This tests seed randomization
|
* This tests seed randomization
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user