From d29c13f1247a5caf1a296a288256838a139cbcbf Mon Sep 17 00:00:00 2001 From: Thomas Kerin Date: Thu, 10 Oct 2019 15:42:08 +0100 Subject: [PATCH] basic tests for xonly_[pubkey|privkey]_tweak_add, and xonly_pubkey_tweak_verify --- secp256k1/secp256k1.c | 4 +- ...cp256k1_xonly_privkey_tweak_add_basic.phpt | 40 ++++++++++++++ .../secp256k1_xonly_pubkey_create_error1.phpt | 1 - ...256k1_xonly_pubkey_from_pubkey_basic1.phpt | 41 ++++++++++++++ ...256k1_xonly_pubkey_from_pubkey_basic2.phpt | 41 ++++++++++++++ ...cp256k1_xonly_pubkey_to_pubkey_basic1.phpt | 36 ++++++++++++ ...cp256k1_xonly_pubkey_to_pubkey_basic2.phpt | 36 ++++++++++++ ...ecp256k1_xonly_pubkey_tweak_add_basic.phpt | 55 +++++++++++++++++++ .../secp256k1_xonly_pubkey_tweak_verify.phpt | 39 +++++++++++++ stubs/functions.php | 39 +++++++++++++ 10 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 secp256k1/tests/secp256k1_xonly_privkey_tweak_add_basic.phpt create mode 100644 secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic1.phpt create mode 100644 secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic2.phpt create mode 100644 secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic1.phpt create mode 100644 secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic2.phpt create mode 100644 secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_basic.phpt create mode 100644 secp256k1/tests/secp256k1_xonly_pubkey_tweak_verify.phpt diff --git a/secp256k1/secp256k1.c b/secp256k1/secp256k1.c index 4bd9f100..e094262a 100755 --- a/secp256k1/secp256k1.c +++ b/secp256k1/secp256k1.c @@ -2031,7 +2031,7 @@ PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add) zend_string *zTweak; int result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrS", &zCtx, &zOutputPubKey, &zInternalPubKey, &zTweak) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/rS", &zCtx, &zOutputPubKey, &zInternalPubKey, &zTweak) == FAILURE) { RETURN_LONG(0); } @@ -2069,7 +2069,7 @@ PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_verify) zend_string *zTweak32; int result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrS", &zCtx, &zOutputPubKey, &zInternalPubKey, &zTweak32) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrrS", &zCtx, &zOutputPubKey, &zInternalPubKey, &zTweak32) == FAILURE) { RETURN_LONG(0); } diff --git a/secp256k1/tests/secp256k1_xonly_privkey_tweak_add_basic.phpt b/secp256k1/tests/secp256k1_xonly_privkey_tweak_add_basic.phpt new file mode 100644 index 00000000..a537f05c --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_privkey_tweak_add_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +secp256k1_xonly_privkey_tweak_add works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_xonly_pubkey +1 +private keys equal \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_create_error1.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_create_error1.phpt index 048ee5c3..75f11422 100644 --- a/secp256k1/tests/secp256k1_xonly_pubkey_create_error1.phpt +++ b/secp256k1/tests/secp256k1_xonly_pubkey_create_error1.phpt @@ -3,7 +3,6 @@ secp256k1_xonly_pubkey_create returns false if parameter parsing fails --SKIPIF-- --FILE-- +--FILE-- + +--EXPECT-- +1 +secp256k1_pubkey +1 +sign: 1 +1 +eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic2.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic2.phpt new file mode 100644 index 00000000..aeb71dc5 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic2.phpt @@ -0,0 +1,41 @@ +--TEST-- +secp256k1_xonly_pubkey_from_pubkey works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_pubkey +1 +sign: 0 +1 +24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic1.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic1.phpt new file mode 100644 index 00000000..a5057c73 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic1.phpt @@ -0,0 +1,36 @@ +--TEST-- +secp256k1_xonly_pubkey_to_pubkey works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_xonly_pubkey +1 +1 +02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic2.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic2.phpt new file mode 100644 index 00000000..03e74c83 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_to_pubkey_basic2.phpt @@ -0,0 +1,36 @@ +--TEST-- +secp256k1_xonly_pubkey_to_pubkey works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_xonly_pubkey +1 +1 +0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_basic.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_basic.phpt new file mode 100644 index 00000000..10df1092 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_xonly_pubkey +1 +secp256k1_xonly_pubkey +1 +1 +1 +public keys equal \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_verify.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_verify.phpt new file mode 100644 index 00000000..6d8bc4f8 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_verify.phpt @@ -0,0 +1,39 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_verify works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_xonly_pubkey +1 +0 +1 \ No newline at end of file diff --git a/stubs/functions.php b/stubs/functions.php index 43d03cec..9b1ef686 100644 --- a/stubs/functions.php +++ b/stubs/functions.php @@ -324,6 +324,45 @@ function secp256k1_xonly_pubkey_parse($context, &$pubkey, string $input32): int * @return int */ function secp256k1_xonly_pubkey_serialize($context, ?string &$output32, $pubkey): int {} +/** + * @param resource $context + * @param resource|null $xonly_pubkey + * @param int|null $sign + * @param resource $pubkey + * @return int + */ +function secp256k1_xonly_pubkey_from_pubkey($context, &$xonly_pubkey, ?int &$sign, $pubkey): int {} +/** + * @param resource $context + * @param resource|null $pubkey + * @param resource $xonly_pubkey + * @param int $sign + * @return int + */ +function secp256k1_xonly_pubkey_to_pubkey($context, &$pubkey, $xonly_pubkey, int $sign): int {} +/** + * @param resource $context + * @param string $seckey + * @param string $tweak32 + * @return int + */ +function secp256k1_xonly_privkey_tweak_add($context, string &$seckey, string $tweak32): int {} +/** + * @param resource $context + * @param resource|null $outputPubKey + * @param resource $internalPubKey + * @param string $tweak32 + * @return int + */ +function secp256k1_xonly_pubkey_tweak_add($context, &$outputPubKey, $internalPubKey, string $tweak32): int {} +/** + * @param resource $context + * @param resource $outputPubKey + * @param resource $internalPubKey + * @param string $tweak32 + * @return int + */ +function secp256k1_xonly_pubkey_tweak_verify($context, $outputPubKey, $internalPubKey, string $tweak32): int {} /** * Parse a compact ECDSA signature (64 bytes + recovery id). *