mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 14:50:42 +01:00
Create safeRewind() helper method in secp256k1jni (#1546)
This commit is contained in:
parent
e16ef65b11
commit
cc25387b11
1 changed files with 38 additions and 12 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.bitcoin;
|
package org.bitcoin;
|
||||||
|
|
||||||
|
import java.nio.Buffer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
@ -59,7 +60,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(data);
|
byteBuff.put(data);
|
||||||
byteBuff.put(signature);
|
byteBuff.put(signature);
|
||||||
byteBuff.put(pub);
|
byteBuff.put(pub);
|
||||||
|
@ -88,7 +90,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(data);
|
byteBuff.put(data);
|
||||||
byteBuff.put(seckey);
|
byteBuff.put(seckey);
|
||||||
|
|
||||||
|
@ -125,7 +128,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(seckey);
|
byteBuff.put(seckey);
|
||||||
|
|
||||||
r.lock();
|
r.lock();
|
||||||
|
@ -153,7 +157,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(seckey);
|
byteBuff.put(seckey);
|
||||||
|
|
||||||
byte[][] retByteArray;
|
byte[][] retByteArray;
|
||||||
|
@ -209,7 +214,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(seckey);
|
byteBuff.put(seckey);
|
||||||
byteBuff.put(tweak);
|
byteBuff.put(tweak);
|
||||||
|
|
||||||
|
@ -248,7 +254,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(seckey);
|
byteBuff.put(seckey);
|
||||||
byteBuff.put(tweak);
|
byteBuff.put(tweak);
|
||||||
|
|
||||||
|
@ -288,7 +295,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(pubkey);
|
byteBuff.put(pubkey);
|
||||||
byteBuff.put(tweak);
|
byteBuff.put(tweak);
|
||||||
|
|
||||||
|
@ -328,7 +336,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(pubkey);
|
byteBuff.put(pubkey);
|
||||||
byteBuff.put(tweak);
|
byteBuff.put(tweak);
|
||||||
|
|
||||||
|
@ -366,7 +375,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(pubkey);
|
byteBuff.put(pubkey);
|
||||||
|
|
||||||
byte[][] retByteArray;
|
byte[][] retByteArray;
|
||||||
|
@ -405,7 +415,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(pubkey);
|
byteBuff.put(pubkey);
|
||||||
|
|
||||||
byte[][] retByteArray;
|
byte[][] retByteArray;
|
||||||
|
@ -436,7 +447,8 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
|
||||||
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(seckey);
|
byteBuff.put(seckey);
|
||||||
byteBuff.put(pubkey);
|
byteBuff.put(pubkey);
|
||||||
|
|
||||||
|
@ -471,7 +483,7 @@ public class NativeSecp256k1 {
|
||||||
byteBuff.order(ByteOrder.nativeOrder());
|
byteBuff.order(ByteOrder.nativeOrder());
|
||||||
nativeECDSABuffer.set(byteBuff);
|
nativeECDSABuffer.set(byteBuff);
|
||||||
}
|
}
|
||||||
byteBuff.rewind();
|
safeRewind(byteBuff);
|
||||||
byteBuff.put(seed);
|
byteBuff.put(seed);
|
||||||
|
|
||||||
w.lock();
|
w.lock();
|
||||||
|
@ -482,6 +494,20 @@ public class NativeSecp256k1 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This helper method is needed to resolve issue 1524 on bitcoin-s
|
||||||
|
* This is because the API changed for ByteBuffer between jdks < 9 and jdk >= 9
|
||||||
|
* In the earlier versions of the jdk, a [[java.nio.Buffer]] is returned, but greather than jdk 8
|
||||||
|
* returns a [[ByteBuffer]]. This causes issues when compiling with jdk 11 but running with jdk 8
|
||||||
|
* as the APIs are incompatible.
|
||||||
|
* @see https://github.com/bitcoin-s/bitcoin-s/issues/1524
|
||||||
|
* @param byteBuff
|
||||||
|
*/
|
||||||
|
private static void safeRewind(ByteBuffer byteBuff) {
|
||||||
|
((Buffer) byteBuff).rewind();
|
||||||
|
}
|
||||||
|
|
||||||
private static native long secp256k1_ctx_clone(long context);
|
private static native long secp256k1_ctx_clone(long context);
|
||||||
|
|
||||||
private static native int secp256k1_context_randomize(ByteBuffer byteBuff, long context);
|
private static native int secp256k1_context_randomize(ByteBuffer byteBuff, long context);
|
||||||
|
|
Loading…
Add table
Reference in a new issue