Skip to content

Commit

Permalink
Use safeRewind for schnorr and adaptor sig functions (#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman authored and nkohen committed Aug 28, 2020
1 parent 5463d2f commit e1db81d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions secp256k1jni/src/main/java/org/bitcoin/NativeSecp256k1.java
Expand Up @@ -530,7 +530,8 @@ public static byte[] schnorrSign(byte[] data, byte[] secKey, byte[] auxRand) thr
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(data);
byteBuff.put(secKey);
byteBuff.put(auxRand);
Expand Down Expand Up @@ -567,7 +568,8 @@ public static byte[] schnorrSignWithNonce(byte[] data, byte[] secKey, byte[] non
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(data);
byteBuff.put(secKey);
byteBuff.put(nonce);
Expand Down Expand Up @@ -597,7 +599,8 @@ public static byte[] schnorrComputeSigPoint(byte[] data, byte[] nonce, byte[] pu
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(data);
byteBuff.put(nonce);
byteBuff.put(pubkey);
Expand Down Expand Up @@ -636,7 +639,8 @@ public static boolean schnorrVerify(byte[] sig, byte[] data, byte[] pubx) throws
byteBuffer.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuffer);
}
byteBuffer.rewind();

safeRewind(byteBuffer);
byteBuffer.put(sig);
byteBuffer.put(data);
byteBuffer.put(pubx);
Expand Down Expand Up @@ -685,7 +689,8 @@ public static byte[] adaptorSign(byte[] seckey, byte[] adaptorPoint, byte[] data
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(seckey);
byteBuff.put(adaptorPoint);
byteBuff.put(data);
Expand Down Expand Up @@ -727,7 +732,8 @@ public static boolean adaptorVerify(byte[] adaptorSig, byte[] pubKey, byte[] dat
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(adaptorSig);
byteBuff.put(pubKey);
byteBuff.put(data);
Expand All @@ -751,7 +757,8 @@ public static byte[] adaptorAdapt(byte[] adaptorSec, byte[] adaptorSig) throws A
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(adaptorSec);
byteBuff.put(adaptorSig);

Expand Down Expand Up @@ -782,7 +789,8 @@ public static byte[] adaptorExtractSecret(byte[] sig, byte[] adaptorSig, byte[]
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();

safeRewind(byteBuff);
byteBuff.put(sig);
byteBuff.put(adaptorSig);
byteBuff.put(adaptor);
Expand Down

0 comments on commit e1db81d

Please sign in to comment.