Handle inputs/outputs and nulls correctly.

This commit is contained in:
kngako
2024-08-07 02:48:25 +02:00
parent 23739e13a8
commit 86d7d9835f
6 changed files with 123 additions and 62 deletions

View File

@@ -264,9 +264,10 @@ public class Secp256k1CFunctions {
* this function returns 0. For uniformly random 32-byte arrays the
* chance of being invalid is negligible (around 1 in 2^128).
*
* @return output_pubkey: pointer to a public key to store the result. Will be set
* to an invalid value if this function returns 0. If you
* do not need it, this arg can be NULL.
* @return
* [0] output_pubkey: pointer to a public key to store the result. Will be set to an invalid value if this
* function returns 0. If you do not need it, this arg can be NULL.
* [1] tweak_cache: pointer to a `frost_tweak_cache` struct initialized by `frost_pubkey_tweak`
*/
public static native byte[][] secp256k1_frost_pubkey_xonly_tweak_add(long ctx, byte[] tweakCache, byte[] tweak32);
@@ -348,7 +349,7 @@ public class Secp256k1CFunctions {
* @param tweak_cache pointer to frost_tweak_cache struct (can be NULL)
*
* @return
* pointer to struct to store the partial signature
* partial_sig: pointer to struct to store the partial signature
* TODO: [1] secnonce: pointer to the secnonce struct created in frost_nonce_gen that has been never used in a
* partial_sign call before
*
@@ -377,6 +378,7 @@ public class Secp256k1CFunctions {
* `secp256k1_frost_compute_pubshare`
* @param session pointer to the session that was created with `frost_nonce_process`
* @param tweakCache pointer to frost_tweak_cache struct (can be NULL)
*
* @return 0 if the arguments are invalid or the partial signature does not verify, 1 otherwise
*/
public static native int secp256k1_frost_partial_sig_verify(long ctx, byte[] partialSig, byte[] publicNonce, byte[] publicShare, byte[] session, byte[] tweakCache);

View File

@@ -130,24 +130,23 @@ public object NativeSecp256k1 : Secp256k1 {
}
override fun frostSharesGen(
pok64: ByteArray,
seed32: ByteArray,
threshold: Int,
totalSigners: Int,
ids33: Array<ByteArray>
): Pair<Array<ByteArray>, Array<ByteArray>> {
): Triple<Array<ByteArray>, Array<ByteArray>, ByteArray> {
val result = Secp256k1CFunctions.secp256k1_frost_shares_gen(
Secp256k1Context.getContext(),
pok64,
seed32,
threshold,
totalSigners,
ids33
)
return Pair(
return Triple(
result[0],
result[1]
result[1],
result[2].first() // This is bad code...
)
}
@@ -217,7 +216,7 @@ public object NativeSecp256k1 : Secp256k1 {
)
}
override fun frostPublicKeyXonlyTweakAdd(tweakCache: ByteArray, tweak32: ByteArray): Pair<ByteArray, ByteArray> {
override fun frostPublicKeyXonlyTweakAdd(tweakCache: ByteArray, tweak32: ByteArray): Pair<ByteArray?, ByteArray> {
val result = Secp256k1CFunctions.secp256k1_frost_pubkey_xonly_tweak_add(
Secp256k1Context.getContext(),
tweakCache,
@@ -232,9 +231,9 @@ public object NativeSecp256k1 : Secp256k1 {
override fun frostNonceGen(
sessionId32: ByteArray,
share: ByteArray,
msg32: ByteArray,
publicKey: ByteArray,
share: ByteArray?,
msg32: ByteArray?,
publicKey: ByteArray?,
extraInput32: ByteArray?
): Pair<ByteArray, ByteArray> {
val result = Secp256k1CFunctions.secp256k1_frost_nonce_gen(
@@ -258,7 +257,7 @@ public object NativeSecp256k1 : Secp256k1 {
publicKey: ByteArray,
id33: ByteArray,
ids33: Array<ByteArray>,
tweakCache: ByteArray,
tweakCache: ByteArray?,
adaptor: ByteArray?
): ByteArray {
return Secp256k1CFunctions.secp256k1_frost_nonce_process(
@@ -277,7 +276,7 @@ public object NativeSecp256k1 : Secp256k1 {
secnonce: ByteArray,
share: ByteArray,
session: ByteArray,
tweakCache: ByteArray
tweakCache: ByteArray?
): ByteArray {
return Secp256k1CFunctions.secp256k1_frost_partial_sign(
Secp256k1Context.getContext(),
@@ -293,7 +292,7 @@ public object NativeSecp256k1 : Secp256k1 {
publicNonce: ByteArray,
publicShare: ByteArray,
session: ByteArray,
tweakCache: ByteArray
tweakCache: ByteArray?
): Int {
return Secp256k1CFunctions.secp256k1_frost_partial_sig_verify(
Secp256k1Context.getContext(),