diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..73941cb4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Test extension +on: [push] +env: + SECP256K1_REMOTE: "https://github.com/bitcoin-core/secp256k1.git" + SECP256K1_COMMIT: efad3506a8937162e8010f5839fdf3771dfcf516 + SECP256K1_CONFIGURE: "--enable-tests=no --enable-benchmark=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-extrakeys" + EXT_SECP256K1_CONFIGURE: "--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig --with-module-extrakeys" +jobs: + test: + runs-on: ubuntu-18.04 + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + - run: cd /tmp && git clone ${SECP256K1_REMOTE} libsecp256k1 && cd libsecp256k1 && git checkout ${SECP256K1_COMMIT} && ./autogen.sh && ./configure ${SECP256K1_CONFIGURE} && make -j$(nproc) && sudo make install + - run: cd secp256k1 && php -v && phpize && ./configure ${EXT_SECP256K1_CONFIGURE} && make -j$(nproc) && sudo make install + - run: composer update + - run: travis/verify_stubs.sh + - run: cd secp256k1/ && REPORT_EXIT_STATUS=1 make test || (find tests/*.log -type f -exec cat {} + ; exit 1) && cd .. + - run: travis/run_coverage_test.sh + - run: travis/run_valgrind_test.sh + - run: travis/validate_examples.sh diff --git a/.travis.yml b/.travis.yml index d06403f5..3945d6b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ sudo: required env: global: - SECP256K1_REMOTE=https://github.com/bitcoin-core/secp256k1.git - - SECP256K1_COMMIT=fa3301713549d118e57ebe6551d062903ddd6b63 + - SECP256K1_COMMIT=efad3506a8937162e8010f5839fdf3771dfcf516 - DOCKER_CACHE_DIR=/home/travis/docker cache: @@ -18,27 +18,26 @@ matrix: env: - COVERAGE=true - PHPQA_PHP_VERSION=7.3.7 - - SECP256K1_REMOTE=https://github.com/jonasnick/secp256k1.git - - SECP256K1_COMMIT=a228e2f54d64692230ccb2937b12dd746c5157ed - - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig" - - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig" + - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-extrakeys" + - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig --with-module-extrakeys" - php: 7.3 env: - VALGRIND=true - PHPQA_PHP_VERSION=7.3.7 - - SECP256K1_REMOTE=https://github.com/jonasnick/secp256k1.git - - SECP256K1_COMMIT=a228e2f54d64692230ccb2937b12dd746c5157ed - - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig" - - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig" + - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-extrakeys" + - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig --with-module-extrakeys" - php: 7.2 env: - - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery" + - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-extrakeys" + - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig --with-module-extrakeys" - php: 7.1 env: - - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery" + - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-extrakeys" + - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig --with-module-extrakeys" - php: 7.0 env: - - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery" + - SECP256K1_CONFIGURE="--enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-extrakeys" + - EXT_SECP256K1_CONFIGURE="--with-secp256k1-config --with-module-recovery --with-module-ecdh --with-module-schnorrsig --with-module-extrakeys" before_install: - sudo apt-get install -qq libssl-dev diff --git a/secp256k1/config.m4 b/secp256k1/config.m4 index 3b0dea78..14f6e34a 100755 --- a/secp256k1/config.m4 +++ b/secp256k1/config.m4 @@ -29,6 +29,12 @@ PHP_ARG_WITH([module-schnorrsig], [Include schnorrsig support])], [no], [no]) +PHP_ARG_WITH([module-extrakeys], + [whether to build secp256k1 with extrakeys support], + [AS_HELP_STRING([--with-module-extrakeys], + [Include extrakeys support])], + [no], + [no]) if test "$PHP_SECP256K1" != "no"; then dnl Write more examples of tests here... @@ -91,12 +97,21 @@ if test "$PHP_SECP256K1" != "no"; then ]) fi + if test "$PHP_MODULE_EXTRAKEYS" = "yes"; then + PHP_CHECK_LIBRARY($LIBNAME,secp256k1_xonly_pubkey_parse, + [ + AC_DEFINE(SECP256K1_MODULE_EXTRAKEYS, 1, [ ]) + ],[ + AC_MSG_ERROR([missing libraries for secp256k1 extrakeys support]) + ],[]) + fi + if test "$PHP_MODULE_SCHNORRSIG" = "yes"; then PHP_CHECK_LIBRARY($LIBNAME,secp256k1_schnorrsig_verify, [ AC_DEFINE(SECP256K1_MODULE_SCHNORRSIG, 1, [ ]) ],[ - AC_MSG_ERROR([missing libraries for secp256k1 recovery support]) + AC_MSG_ERROR([missing libraries for secp256k1 schnorrsig support]) ],[]) fi else diff --git a/secp256k1/php_secp256k1.h b/secp256k1/php_secp256k1.h index cbc4c12d..7a51bfa3 100755 --- a/secp256k1/php_secp256k1.h +++ b/secp256k1/php_secp256k1.h @@ -24,8 +24,13 @@ extern zend_module_entry secp256k1_module_entry; #ifdef SECP256K1_MODULE_RECOVERY #define SECP256K1_RECOVERABLE_SIG_RES_NAME "secp256k1_ecdsa_recoverable_signature" #endif + +#ifdef SECP256K1_MODULE_EXTRAKEYS +#define SECP256K1_XONLY_PUBKEY_RES_NAME "secp256k1_xonly_pubkey" +#define SECP256K1_KEYPAIR_RES_NAME "secp256k1_keypair" +#endif + #ifdef SECP256K1_MODULE_SCHNORRSIG -#define SECP256K1_SCHNORRSIG_RES_NAME "secp256k1_schnorrsig" #endif #ifdef ZTS @@ -35,6 +40,7 @@ extern zend_module_entry secp256k1_module_entry; #endif #define MAX_SIGNATURE_LENGTH 72 +#define SCHNORRSIG_LENGTH 64 #define COMPACT_SIGNATURE_LENGTH 64 #define PUBKEY_COMPRESSED_LENGTH 33 #define PUBKEY_UNCOMPRESSED_LENGTH 65 @@ -90,14 +96,26 @@ PHP_FUNCTION(secp256k1_ecdsa_recoverable_signature_parse_compact); PHP_FUNCTION(secp256k1_ecdh); #endif /* end of ecdh module */ + +/* extrakeys module */ +#ifdef SECP256K1_MODULE_EXTRAKEYS +PHP_FUNCTION(secp256k1_xonly_pubkey_parse); +PHP_FUNCTION(secp256k1_xonly_pubkey_serialize); +PHP_FUNCTION(secp256k1_xonly_pubkey_from_pubkey); +PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add); +PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add_check); +PHP_FUNCTION(secp256k1_keypair_create); +PHP_FUNCTION(secp256k1_keypair_sec); +PHP_FUNCTION(secp256k1_keypair_pub); +PHP_FUNCTION(secp256k1_keypair_xonly_pub); +PHP_FUNCTION(secp256k1_keypair_xonly_tweak_add); +#endif /* end of schnorrsig module */ + /* schnorr module */ #ifdef SECP256K1_MODULE_SCHNORRSIG -PHP_FUNCTION(secp256k1_schnorrsig_serialize); -PHP_FUNCTION(secp256k1_schnorrsig_parse); PHP_FUNCTION(secp256k1_schnorrsig_sign); PHP_FUNCTION(secp256k1_schnorrsig_verify); -PHP_FUNCTION(secp256k1_schnorrsig_verify_batch); -PHP_FUNCTION(secp256k1_nonce_function_bipschnorr); +PHP_FUNCTION(secp256k1_nonce_function_bip340); #endif /* end of schnorrsig module */ #endif /* PHP_SECP256K1_H */ diff --git a/secp256k1/secp256k1.c b/secp256k1/secp256k1.c index afa5bc8c..2eb39db4 100755 --- a/secp256k1/secp256k1.c +++ b/secp256k1/secp256k1.c @@ -23,9 +23,10 @@ typedef struct secp256k1_scratch_space_wrapper { secp256k1_scratch_space* scratch; } secp256k1_scratch_space_wrapper; -// php_secp256k1_nonce_function_data embeds state required for secp256k1_ecdsa_sign to -// call a userland PHP function, as well as containing an (optional) zval* to be -// unpacked and used as arbitrary data to the custom nonce function +// php_secp256k1_nonce_function_data is used to provide data to an invocation +// of php_secp256k1_nonce_function_callback or php_secp256k1_nonce_function_hardened_callback. +// It contains function call information for the userland PHP function, and any +// extra data for the nonce function if provided. typedef struct php_secp256k1_nonce_function_data { zend_fcall_info* fci; zend_fcall_info_cache* fcc; @@ -115,6 +116,84 @@ static int php_secp256k1_nonce_function_callback(unsigned char *nonce32, const u return result; } + +// php_secp256k1_nonce_function_hardened_callback is an implementation of secp256k1_nonce_function_hardened +// designed to call a PHP land function to calculate a nonce for the Schnorr signature algorithm in +// secp256k1_schnorrsig_sig. It expects that the arbitrary data pointer is a pointer to a +// *php_secp256k1_nonce_function_data so it has sufficient context to call the specified PHP function, and +// pass optional additional data if present. It writes the nonce provided by the PHP function to *nonce32 +// for the signing algorithm to continue. +static int php_secp256k1_nonce_function_hardened_callback(unsigned char *nonce32, const unsigned char *msg32, + const unsigned char *key32, const unsigned char *xonly_pk32, + const unsigned char *algo16, void *data) { + php_secp256k1_nonce_function_data* callback; + zend_string* output_str; + zval retval, zvalout; + zval args[6]; + int result, i; + + callback = (php_secp256k1_nonce_function_data*) data; + callback->fci->size = sizeof(*(callback->fci)); + callback->fci->object = NULL; + callback->fci->retval = &retval; + callback->fci->params = args; + callback->fci->param_count = 6; + ZVAL_NEW_STR(&zvalout, zend_string_init("", 0, 0)); + + // wrt ownership, args 0-4 are managed by us in order to + // receive the result, and pass inputs. The final argument + // is provided by the caller and must not be dtor'd! + ZVAL_NEW_REF(&args[0], &zvalout); + ZVAL_STR(&args[1], zend_string_init((const char *) msg32, 32, 0)); + ZVAL_STR(&args[2], zend_string_init((const char *) key32, 32, 0)); + ZVAL_STR(&args[3], zend_string_init((const char *) xonly_pk32, 32, 0)); + ZVAL_STR(&args[4], zend_string_init((const char *) algo16, 16, 0)); + if (callback->data != NULL) { + zval* data = callback->data; + args[5] = *data; + } else { + ZVAL_NULL(&args[5]); + } + + result = zend_call_function(callback->fci, callback->fcc) == SUCCESS; + + // check function invocation result + if (result) { + // now respect return value + if (Z_TYPE(retval) == IS_FALSE) { + result = 0; + } else if (Z_TYPE(retval) == IS_TRUE) { + result = 1; + } else if (Z_TYPE(retval) == IS_LONG) { + result = Z_LVAL(retval); + } + } + + // there's more! what if the length doesn't match? avoid. + if (result) { + output_str = Z_STR_P(Z_REFVAL(args[0])); + if (output_str->len != 32) { + // this perhaps ought to be an exception, + // as these callbacks _MUST_ write 32 bytes + result = 0; + } + } + + // callback OK & length correct + if (result) { + memcpy(nonce32, output_str->val, 32); + } + + // zval_dtor on our args. arg 5 is managed elsewhere. + zval_dtor(&args[0]); + zval_dtor(&args[1]); + zval_dtor(&args[2]); + zval_dtor(&args[3]); + zval_dtor(&args[4]); + + return result; +} + /* Function argument documentation */ #if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) @@ -460,40 +539,129 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_ecdh, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, outputLen, IS_LONG, 1) ZEND_ARG_INFO(0, data) ZEND_END_ARG_INFO(); +#endif + +//extrakeys +#ifdef SECP256K1_MODULE_EXTRAKEYS + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_parse, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_parse, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, pubkey, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(0, input32, IS_STRING, 0) +ZEND_END_ARG_INFO(); +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_serialize, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_serialize, IS_LONG, 0) #endif -//schnorrsig -#ifdef SECP256K1_MODULE_SCHNORRSIG + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, pubkey, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, pubkey, IS_RESOURCE, 0) +ZEND_END_ARG_INFO(); + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_from_pubkey, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_from_pubkey, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, pubkey, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(1, pk_parity, IS_LONG, 1) + ZEND_ARG_TYPE_INFO(0, pubkey, IS_RESOURCE, 0) +ZEND_END_ARG_INFO(); + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_add, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_add, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, output_pubkey, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(0, internal_pubkey, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(0, tweak, IS_STRING, 0) +ZEND_END_ARG_INFO(); + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_add_check, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_add_check, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(0, tweaked_pubkey32, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, tweaked_pubkey_parity, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, internal_pubkey, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(0, tweak32, IS_STRING, 0) +ZEND_END_ARG_INFO(); + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_create, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_create, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, keypair, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(0, seckey, IS_STRING, 0) +ZEND_END_ARG_INFO(); + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_sec, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_sec, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, seckey, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, keypair, IS_RESOURCE, 0) +ZEND_END_ARG_INFO(); + +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_pub, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_pub, IS_LONG, 0) +#endif + ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, pubkey, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(0, keypair, IS_RESOURCE, 0) +ZEND_END_ARG_INFO(); + #if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_serialize, IS_LONG, NULL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_xonly_pub, IS_LONG, NULL, 0) #else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_serialize, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_xonly_pub, IS_LONG, 0) #endif ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_TYPE_INFO(1, sigout, IS_STRING, 1) - ZEND_ARG_TYPE_INFO(0, schnorrsig, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(1, pubkey, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(1, pk_parity, IS_LONG, 1) + ZEND_ARG_TYPE_INFO(0, keypair, IS_RESOURCE, 0) ZEND_END_ARG_INFO(); #if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_parse, IS_LONG, NULL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_xonly_tweak_add, IS_LONG, NULL, 0) #else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_parse, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_keypair_xonly_tweak_add, IS_LONG, 0) #endif ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_TYPE_INFO(1, sigout, IS_RESOURCE, 1) - ZEND_ARG_TYPE_INFO(0, sigin, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(1, keypair, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(0, tweak32, IS_STRING, 0) ZEND_END_ARG_INFO(); +#endif +//schnorrsig +#ifdef SECP256K1_MODULE_SCHNORRSIG #if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_sign, IS_LONG, NULL, 0) #else ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_sign, IS_LONG, 0) #endif ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_TYPE_INFO(1, ecdsaSignatureOut, IS_RESOURCE, 1) + ZEND_ARG_TYPE_INFO(1, sig64, IS_RESOURCE, 1) ZEND_ARG_TYPE_INFO(0, msg32, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, secretKey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, keypair, IS_RESOURCE, 0) ZEND_ARG_CALLABLE_INFO(0, noncefp, 1) ZEND_ARG_INFO(0, ndata) ZEND_END_ARG_INFO(); @@ -504,37 +672,23 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_verify, IS_LON ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_verify, IS_LONG, 0) #endif ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_TYPE_INFO(0, schnorrsig, IS_RESOURCE, 0) + ZEND_ARG_TYPE_INFO(0, sig64, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, msg32, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pubkey, IS_RESOURCE, 0) ZEND_END_ARG_INFO(); #if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_verify_batch, IS_LONG, NULL, 0) -#else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_schnorrsig_verify_batch, IS_LONG, 0) -#endif - ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_TYPE_INFO(0, scratch, IS_RESOURCE, 0) - ZEND_ARG_TYPE_INFO(0, pubkeys, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO(0, msg32s, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO(0, sigs, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO(0, numsigs, IS_LONG, 0) -ZEND_END_ARG_INFO(); - -#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_nonce_function_bipschnorr, IS_LONG, NULL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_nonce_function_bip340, IS_LONG, NULL, 0) #else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_nonce_function_bipschnorr, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_nonce_function_bip340, IS_LONG, 0) #endif ZEND_ARG_TYPE_INFO(1, nonce32, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, msg32, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key32, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, algo16, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, xonly_pk32, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, algo16, IS_STRING, 0) ZEND_ARG_INFO(0, data) - ZEND_ARG_TYPE_INFO(0, attempt, IS_LONG, 0) ZEND_END_ARG_INFO(); - #endif /* {{{ resource_functions[] * @@ -593,15 +747,24 @@ const zend_function_entry secp256k1_functions[] = { #ifdef SECP256K1_MODULE_ECDH PHP_FE(secp256k1_ecdh, arginfo_secp256k1_ecdh) #endif - + // secp256k1_extrakeys.h +#ifdef SECP256K1_MODULE_EXTRAKEYS + PHP_FE(secp256k1_xonly_pubkey_parse, arginfo_secp256k1_xonly_pubkey_parse) + PHP_FE(secp256k1_xonly_pubkey_serialize, arginfo_secp256k1_xonly_pubkey_serialize) + PHP_FE(secp256k1_xonly_pubkey_from_pubkey, arginfo_secp256k1_xonly_pubkey_from_pubkey) + PHP_FE(secp256k1_xonly_pubkey_tweak_add, arginfo_secp256k1_xonly_pubkey_tweak_add) + PHP_FE(secp256k1_xonly_pubkey_tweak_add_check, arginfo_secp256k1_xonly_pubkey_tweak_add_check) + PHP_FE(secp256k1_keypair_create, arginfo_secp256k1_keypair_create) + PHP_FE(secp256k1_keypair_sec, arginfo_secp256k1_keypair_sec) + PHP_FE(secp256k1_keypair_pub, arginfo_secp256k1_keypair_pub) + PHP_FE(secp256k1_keypair_xonly_pub, arginfo_secp256k1_keypair_xonly_pub) + PHP_FE(secp256k1_keypair_xonly_tweak_add, arginfo_secp256k1_keypair_xonly_tweak_add) +#endif // secp256k1_schnorr.h #ifdef SECP256K1_MODULE_SCHNORRSIG - PHP_FE(secp256k1_schnorrsig_serialize, arginfo_secp256k1_schnorrsig_serialize) - PHP_FE(secp256k1_schnorrsig_parse, arginfo_secp256k1_schnorrsig_parse) PHP_FE(secp256k1_schnorrsig_sign, arginfo_secp256k1_schnorrsig_sign) PHP_FE(secp256k1_schnorrsig_verify, arginfo_secp256k1_schnorrsig_verify) - PHP_FE(secp256k1_schnorrsig_verify_batch, arginfo_secp256k1_schnorrsig_verify_batch) - PHP_FE(secp256k1_nonce_function_bipschnorr, arginfo_secp256k1_nonce_function_bipschnorr) + PHP_FE(secp256k1_nonce_function_bip340, arginfo_secp256k1_nonce_function_bip340) #endif PHP_FE_END /* Must be the last line in resource_functions[] */ @@ -613,8 +776,9 @@ static int le_secp256k1_ctx; static int le_secp256k1_pubkey; static int le_secp256k1_sig; static int le_secp256k1_scratch_space; -static int le_secp256k1_schnorrsig; static int le_secp256k1_recoverable_sig; +static int le_secp256k1_xonly_pubkey; +static int le_secp256k1_keypair; /* dtor functions */ static void secp256k1_ctx_dtor(zend_resource *rsrc TSRMLS_DC) @@ -660,16 +824,22 @@ static void secp256k1_recoverable_sig_dtor(zend_resource * rsrc TSRMLS_DC) } #endif -#ifdef SECP256K1_MODULE_SCHNORRSIG -static void secp256k1_schnorrsig_dtor(zend_resource * rsrc TSRMLS_DC) +#ifdef SECP256K1_MODULE_EXTRAKEYS +static void secp256k1_xonly_pubkey_dtor(zend_resource * rsrc TSRMLS_DC) { - secp256k1_schnorrsig *sig = (secp256k1_schnorrsig*) rsrc->ptr; - if (sig) { - efree(sig); + secp256k1_xonly_pubkey *pubkey = (secp256k1_xonly_pubkey*) rsrc->ptr; + if (pubkey) { + efree(pubkey); + } +} +static void secp256k1_keypair_dtor(zend_resource * rsrc TSRMLS_DC) +{ + secp256k1_keypair *pubkey = (secp256k1_keypair*) rsrc->ptr; + if (pubkey) { + efree(pubkey); } } #endif - // helper functions to extract pointers from resource zvals // attempt to read a sec256k1_context* from the provided resource zval @@ -688,7 +858,7 @@ static secp256k1_pubkey* php_get_secp256k1_pubkey(zval *pkey) { } // attempt to read a sec256k1_scratch_space * from the provided resource zval -static secp256k1_scratch_space_wrapper * php_get_secp256k1_scratch_space(zval *psig) { +static secp256k1_scratch_space_wrapper* php_get_secp256k1_scratch_space(zval *psig) { return (secp256k1_scratch_space_wrapper *)zend_fetch_resource2_ex(psig, SECP256K1_SCRATCH_SPACE_RES_NAME, le_secp256k1_scratch_space, -1); } @@ -699,10 +869,13 @@ static secp256k1_ecdsa_recoverable_signature* php_get_secp256k1_ecdsa_recoverabl } #endif -#ifdef SECP256K1_MODULE_SCHNORRSIG -// attempt to read a sec256k1_schnorrsig* from the provided resource zval -static secp256k1_schnorrsig* php_get_secp256k1_schnorr_signature(zval *psig) { - return (secp256k1_schnorrsig *)zend_fetch_resource2_ex(psig, SECP256K1_SCHNORRSIG_RES_NAME, le_secp256k1_schnorrsig, -1); +#ifdef SECP256K1_MODULE_EXTRAKEYS +// attempt to read a sec256k1_ecdsa_recoverable_signature* from the provided resource zval +static secp256k1_xonly_pubkey* php_get_secp256k1_xonly_pubkey(zval *precsig) { + return (secp256k1_xonly_pubkey *)zend_fetch_resource2_ex(precsig, SECP256K1_XONLY_PUBKEY_RES_NAME, le_secp256k1_xonly_pubkey, -1); +} +static secp256k1_keypair* php_get_secp256k1_keypair(zval *precsig) { + return (secp256k1_keypair *)zend_fetch_resource2_ex(precsig, SECP256K1_KEYPAIR_RES_NAME, le_secp256k1_keypair, -1); } #endif @@ -737,11 +910,12 @@ PHP_MINIT_FUNCTION(secp256k1) { le_secp256k1_recoverable_sig = zend_register_list_destructors_ex(secp256k1_recoverable_sig_dtor, NULL, SECP256K1_RECOVERABLE_SIG_RES_NAME, module_number); #endif -#ifdef SECP256K1_MODULE_SCHNORRSIG - REGISTER_STRING_CONSTANT("SECP256K1_TYPE_SCHNORRSIG", SECP256K1_SCHNORRSIG_RES_NAME, CONST_CS | CONST_PERSISTENT); - le_secp256k1_schnorrsig = zend_register_list_destructors_ex(secp256k1_schnorrsig_dtor, NULL, SECP256K1_SCHNORRSIG_RES_NAME, module_number); +#ifdef SECP256K1_MODULE_EXTRAKEYS + REGISTER_STRING_CONSTANT("SECP256K1_TYPE_XONLY_PUBKEY", SECP256K1_XONLY_PUBKEY_RES_NAME, CONST_CS | CONST_PERSISTENT); + le_secp256k1_xonly_pubkey = zend_register_list_destructors_ex(secp256k1_xonly_pubkey_dtor, NULL, SECP256K1_XONLY_PUBKEY_RES_NAME, module_number); + REGISTER_STRING_CONSTANT("SECP256K1_TYPE_KEYPAIR", SECP256K1_KEYPAIR_RES_NAME, CONST_CS | CONST_PERSISTENT); + le_secp256k1_keypair = zend_register_list_destructors_ex(secp256k1_keypair_dtor, NULL, SECP256K1_KEYPAIR_RES_NAME, module_number); #endif - return SUCCESS; } @@ -849,14 +1023,14 @@ PHP_FUNCTION(secp256k1_context_randomize) zval *zCtx, *zSeed = NULL; secp256k1_context *ctx; unsigned char *seed32 = NULL; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z", &zCtx, &zSeed) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (zSeed != NULL) { @@ -883,14 +1057,14 @@ PHP_FUNCTION(secp256k1_ecdsa_signature_parse_der) secp256k1_context *ctx; secp256k1_ecdsa_signature *sig; zend_string *sigin; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSig, &sigin) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } sig = (secp256k1_ecdsa_signature *) emalloc(sizeof(secp256k1_ecdsa_signature)); @@ -916,18 +1090,18 @@ PHP_FUNCTION(secp256k1_ecdsa_signature_serialize_der) secp256k1_ecdsa_signature *sig; size_t sigoutlen = MAX_SIGNATURE_LENGTH; unsigned char sigout[MAX_SIGNATURE_LENGTH]; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zSigOut, &zSig) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((sig = php_get_secp256k1_ecdsa_signature(zSig)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } result = secp256k1_ecdsa_signature_serialize_der(ctx, sigout, &sigoutlen, sig); @@ -948,14 +1122,14 @@ PHP_FUNCTION(secp256k1_ecdsa_signature_parse_compact) secp256k1_context *ctx; secp256k1_ecdsa_signature *sig; zend_string *input64; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSig, &input64) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (input64->len != COMPACT_SIGNATURE_LENGTH) { @@ -985,18 +1159,18 @@ PHP_FUNCTION(secp256k1_ecdsa_signature_serialize_compact) secp256k1_context *ctx; secp256k1_ecdsa_signature *sig; unsigned char sigOut[COMPACT_SIGNATURE_LENGTH]; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zSigOut, &zSig) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((sig = php_get_secp256k1_ecdsa_signature(zSig)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } result = secp256k1_ecdsa_signature_serialize_compact(ctx, sigOut, sig); @@ -1015,14 +1189,14 @@ PHP_FUNCTION(ecdsa_signature_parse_der_lax) secp256k1_context *ctx; secp256k1_ecdsa_signature *sig; zend_string *sigin; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSig, &sigin) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } sig = (secp256k1_ecdsa_signature *) emalloc(sizeof(secp256k1_ecdsa_signature)); @@ -1046,18 +1220,18 @@ PHP_FUNCTION(secp256k1_ecdsa_signature_normalize) zval *zCtx, *zSigIn, *zSigOut; secp256k1_context *ctx; secp256k1_ecdsa_signature *sigout, *sigin; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zSigOut, &zSigIn) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((sigin = php_get_secp256k1_ecdsa_signature(zSigIn)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } sigout = (secp256k1_ecdsa_signature *) emalloc(sizeof(secp256k1_ecdsa_signature)); @@ -1077,22 +1251,22 @@ PHP_FUNCTION(secp256k1_ecdsa_verify) { secp256k1_ecdsa_signature *sig; secp256k1_pubkey *pubkey; zend_string *msg32; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrSr", &zCtx, &zSig, &msg32, &zPubKey) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((sig = php_get_secp256k1_ecdsa_signature(zSig)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } result = secp256k1_ecdsa_verify(ctx, sig, (unsigned char *) msg32->val, pubkey); @@ -1113,15 +1287,15 @@ PHP_FUNCTION (secp256k1_ecdsa_sign) zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; php_secp256k1_nonce_function_data calldata; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/SS|fz", &zCtx, &zSig, &msg32, &seckey, &fci, &fcc, &zData) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (msg32->len != HASH_LENGTH) { @@ -1169,14 +1343,14 @@ PHP_FUNCTION(secp256k1_ec_seckey_verify) zval *zCtx; secp256k1_context *ctx; zend_string *seckey; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rS", &zCtx, &seckey) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (seckey->len != SECRETKEY_LENGTH) { @@ -1200,14 +1374,14 @@ PHP_FUNCTION(secp256k1_ec_pubkey_create) secp256k1_pubkey *pubkey; zend_string *seckey; zend_resource *pubKeyResource; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zPubKey, &seckey) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (seckey->len != SECRETKEY_LENGTH) { @@ -1235,14 +1409,14 @@ PHP_FUNCTION(secp256k1_ec_privkey_negate) { zval *zCtx, *zPrivKey; secp256k1_context *ctx; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/", &zCtx, &zPrivKey) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (Z_STRLEN_P(zPrivKey) != SECRETKEY_LENGTH) { @@ -1268,18 +1442,18 @@ PHP_FUNCTION(secp256k1_ec_pubkey_negate) zval *zCtx, *zPubKey; secp256k1_context *ctx; secp256k1_pubkey *pubkey; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &zCtx, &zPubKey) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } result = secp256k1_ec_pubkey_negate(ctx, pubkey); @@ -1296,14 +1470,14 @@ PHP_FUNCTION(secp256k1_ec_pubkey_parse) secp256k1_context *ctx; secp256k1_pubkey *pubkey; zend_string *pubkeyin; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zPubKey, &pubkeyin) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } pubkey = (secp256k1_pubkey *) emalloc(sizeof(secp256k1_pubkey)); @@ -1327,20 +1501,20 @@ PHP_FUNCTION(secp256k1_ec_pubkey_serialize) zval *zCtx, *zPubKey, *zPubOut; secp256k1_context *ctx; secp256k1_pubkey * pubkey; - int result = 0; + int result; size_t pubkeylen; zend_long flags; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/rl", &zCtx, &zPubOut, &zPubKey, &flags) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } pubkeylen = (flags == SECP256K1_EC_COMPRESSED) ? PUBKEY_COMPRESSED_LENGTH : PUBKEY_UNCOMPRESSED_LENGTH; @@ -1364,14 +1538,14 @@ PHP_FUNCTION(secp256k1_ec_privkey_tweak_add) zend_string *zTweak; unsigned char *tweak; unsigned char newseckey[SECRETKEY_LENGTH]; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSecKey, &zTweak) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (Z_STRLEN_P(zSecKey) != SECRETKEY_LENGTH) { @@ -1401,18 +1575,18 @@ PHP_FUNCTION(secp256k1_ec_pubkey_tweak_add) secp256k1_context *ctx; secp256k1_pubkey *pubkey; zend_string *zTweak; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrS", &zCtx, &zPubKey, &zTweak) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (zTweak->len != SECRETKEY_LENGTH) { @@ -1433,14 +1607,14 @@ PHP_FUNCTION(secp256k1_ec_privkey_tweak_mul) unsigned char newseckey[SECRETKEY_LENGTH]; zend_string *zTweak; secp256k1_context *ctx; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSecKey, &zTweak) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (Z_STRLEN_P(zSecKey) != SECRETKEY_LENGTH) { @@ -1472,18 +1646,18 @@ PHP_FUNCTION(secp256k1_ec_pubkey_tweak_mul) unsigned char *newpubkey; size_t newpubkeylen; zend_string *zTweak; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrS", &zCtx, &zPubKey, &zTweak) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (zTweak->len != SECRETKEY_LENGTH) { @@ -1719,14 +1893,14 @@ PHP_FUNCTION(secp256k1_ecdsa_recoverable_signature_parse_compact) secp256k1_ecdsa_recoverable_signature *sig; zend_string *zSig64In; long recid; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/Sl", &zCtx, &zSig, &zSig64In, &recid) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (zSig64In->len != 64) { @@ -1761,18 +1935,18 @@ PHP_FUNCTION(secp256k1_ecdsa_recoverable_signature_convert) secp256k1_context *ctx; secp256k1_ecdsa_signature * nSig; secp256k1_ecdsa_recoverable_signature * rSig; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zNormalSig, &zRecoverableSig) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((rSig = php_get_secp256k1_ecdsa_recoverable_signature(zRecoverableSig)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } nSig = emalloc(sizeof(secp256k1_ecdsa_recoverable_signature)); @@ -1794,18 +1968,18 @@ PHP_FUNCTION(secp256k1_ecdsa_recoverable_signature_serialize_compact) secp256k1_context *ctx; secp256k1_ecdsa_recoverable_signature *recsig; unsigned char sig[COMPACT_SIGNATURE_LENGTH]; - int result = 0, recid; + int result, recid; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/z/r", &zCtx, &zSigOut, &zRecId, &zRecSig) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((recsig = php_get_secp256k1_ecdsa_recoverable_signature(zRecSig)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } result = secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, recsig); @@ -1828,14 +2002,14 @@ PHP_FUNCTION(secp256k1_ecdsa_sign_recoverable) secp256k1_context *ctx; zend_string *msg32, *seckey; secp256k1_ecdsa_recoverable_signature *newsig; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/SS", &zCtx, &zSig, &msg32, &seckey) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if (msg32->len != HASH_LENGTH) { @@ -1871,18 +2045,18 @@ PHP_FUNCTION(secp256k1_ecdsa_recover) secp256k1_pubkey *pubkey; secp256k1_ecdsa_recoverable_signature *sig; zend_string *msg32; - int result = 0; + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/rS", &zCtx, &zPubKey, &zSig, &msg32) == FAILURE) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } if ((sig = php_get_secp256k1_ecdsa_recoverable_signature(zSig)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); } pubkey = (secp256k1_pubkey *) emalloc(sizeof(secp256k1_pubkey)); @@ -2033,52 +2207,120 @@ PHP_FUNCTION(secp256k1_ecdh) #endif /* End EcDH module functions */ -/* Begin schnorr module functions */ -#ifdef SECP256K1_MODULE_SCHNORRSIG +/* Begin extrakeys module functions */ +#ifdef SECP256K1_MODULE_EXTRAKEYS -/* {{{ proto int secp256k1_schnorrsig_serialize(resource context, string &result, resource schnorrsig) - * Serialize a Schnorr signature. */ -PHP_FUNCTION(secp256k1_schnorrsig_serialize) +/* {{{ proto int secp256k1_xonly_pubkey_parse(resource secp256k1_context, resource &pubKey, string input32) + * Parse a 32-byte sequence into a xonly_pubkey object. + * + * Returns: 1 if the public key was fully valid. + * 0 if the public key could not be parsed or is invalid. + * + * Args: ctx: a secp256k1 context object (cannot be NULL). + * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a + * parsed version of input. If not, it's set to an invalid value. + * (cannot be NULL). + * In: input32: pointer to a serialized xonly_pubkey (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_xonly_pubkey_parse) { - zval *zCtx, *zSchnorrSig, *zSigOut; + zval *zCtx, *zPubKey; secp256k1_context *ctx; - secp256k1_schnorrsig *sig; - unsigned char sigout[COMPACT_SIGNATURE_LENGTH]; + secp256k1_xonly_pubkey *pubkey; + zend_string *input32; int result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zSigOut, &zSchnorrSig) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zPubKey, &input32) == FAILURE) { RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { RETURN_LONG(0); + } else if (input32->len != 32) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "secp256k1_xonly_pubkey_parse(): Parameter 3 should be 32 bytes"); + return; + } + + pubkey = (secp256k1_xonly_pubkey *) emalloc(sizeof(secp256k1_xonly_pubkey)); + result = secp256k1_xonly_pubkey_parse(ctx, pubkey, (unsigned char *)input32->val); + if (result) { + zval_dtor(zPubKey); + ZVAL_RES(zPubKey, zend_register_resource(pubkey, le_secp256k1_xonly_pubkey)); + } else { + // only free when operation fails, won't return this resource + efree(pubkey); + } + + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto int secp256k1_xonly_pubkey_serialize(resource secp256k1_context, string &output32, resource pubkey) + * Serialize an xonly_pubkey object into a 32-byte sequence. + * + * Returns: 1 always. + * + * Args: ctx: a secp256k1 context object (cannot be NULL). + * Out: output32: a pointer to a 32-byte array to place the serialized key in + * (cannot be NULL). + * In: pubkey: a pointer to a secp256k1_xonly_pubkey containing an + * initialized public key (cannot be NULL). + */ +PHP_FUNCTION(secp256k1_xonly_pubkey_serialize) +{ + zval *zCtx, *zOutput32, *zPubKey; + secp256k1_context *ctx; + secp256k1_xonly_pubkey *pubkey; + unsigned char output32[32]; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zOutput32, &zPubKey) == FAILURE) { + RETURN_LONG(0); } - if ((sig = php_get_secp256k1_schnorr_signature(zSchnorrSig)) == NULL) { + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if ((pubkey = php_get_secp256k1_xonly_pubkey(zPubKey)) == NULL) { RETURN_LONG(0); } - result = secp256k1_schnorrsig_serialize(ctx, sigout, sig); + result = secp256k1_xonly_pubkey_serialize(ctx, output32, pubkey); if (result) { - zval_dtor(zSigOut); - ZVAL_STRINGL(zSigOut, (const char *)&sigout, COMPACT_SIGNATURE_LENGTH); + zval_dtor(zOutput32); + ZVAL_STRINGL(zOutput32, (char *)&output32, 32); + } else { + // only free when operation fails, won't return this resource + efree(pubkey); } RETURN_LONG(result); } /* }}} */ -/* {{{ proto int secp256k1_schnorrsig_parse(resource ctx, resource &sig, string sigIn) - * Parse a Schnorr signature. */ -PHP_FUNCTION(secp256k1_schnorrsig_parse) +/* {{{ proto int secp256k1_xonly_pubkey_from_pubkey(resource context, resource &xonly_pubkey, int &pk_parity, resource pubkey) + * Converts a secp256k1_pubkey into a secp256k1_xonly_pubkey. + * + * Returns: 1 if the public key was successfully converted + * 0 otherwise + * + * Args: ctx: pointer to a context object (cannot be NULL) + * Out: xonly_pubkey: pointer to an x-only public key object for placing the + * converted public key (cannot be NULL) + * pk_parity: pointer to an integer that will be set to 1 if the point + * encoded by xonly_pubkey is the negation of the pubkey and + * set to 0 otherwise. (can be NULL) + * In: pubkey: pointer to a public key that is converted (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_xonly_pubkey_from_pubkey) { - zval *zCtx, *zSchnorrSig; + zval *zCtx, *zXOnlyPubKey, *zPkParity, *zPubKey; secp256k1_context *ctx; - secp256k1_schnorrsig *sig; - zend_string *sigin; + secp256k1_pubkey *pubkey; + secp256k1_xonly_pubkey *xonly_pubkey; + int parity; int result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSchnorrSig, &sigin) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/z/r", &zCtx, &zXOnlyPubKey, &zPkParity, &zPubKey) == FAILURE) { RETURN_LONG(0); } @@ -2086,233 +2328,528 @@ PHP_FUNCTION(secp256k1_schnorrsig_parse) RETURN_LONG(0); } - if (sigin->len != COMPACT_SIGNATURE_LENGTH) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "secp256k1_schnorrsig_parse(): Parameter 3 should be 64 bytes"); - return; + if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { + RETURN_LONG(0); } - sig = (secp256k1_schnorrsig *) emalloc(sizeof(secp256k1_schnorrsig)); - result = secp256k1_schnorrsig_parse(ctx, sig, (const unsigned char *) sigin->val); + xonly_pubkey = (secp256k1_xonly_pubkey *) emalloc(sizeof(secp256k1_xonly_pubkey)); + result = secp256k1_xonly_pubkey_from_pubkey(ctx, xonly_pubkey, &parity, pubkey); if (result) { - zval_dtor(zSchnorrSig); - ZVAL_RES(zSchnorrSig, zend_register_resource(sig, le_secp256k1_schnorrsig)); - } else { - // only free when operation fails, won't return this resource - efree(sig); + zval_dtor(zXOnlyPubKey); + ZVAL_RES(zXOnlyPubKey, zend_register_resource(xonly_pubkey, le_secp256k1_xonly_pubkey)); + zval_dtor(zPkParity); + ZVAL_LONG(zPkParity, parity); } - RETURN_LONG(result); } /* }}} */ - -/* {{{ proto int secp256k1_schnorrsig_sign(resource context, resource &sig, string msg32, string key32) - * Create an ECDSA signature. */ -PHP_FUNCTION (secp256k1_schnorrsig_sign) +/* {{{ proto int secp256k1_xonly_pubkey_tweak_add(resource context, resource output_pubkey, resource internal_pubkey, string tweak32) + * Tweak an x-only public key by adding the generator multiplied with tweak32 + * to it. + * + * Note that the resulting point can not in general be represented by an x-only + * pubkey because it may have an odd Y coordinate. Instead, the output_pubkey + * is a normal secp256k1_pubkey. + * + * Returns: 0 if the arguments are invalid or the resulting public key would be + * invalid (only when the tweak is the negation of the corresponding + * secret key). 1 otherwise. + * + * Args: ctx: pointer to a context object initialized for verification + * (cannot be NULL) + * Out: output_pubkey: pointer to a public key to store the result. Will be set + * to an invalid value if this function returns 0 (cannot + * be NULL) + * In: internal_pubkey: pointer to an x-only pubkey to apply the tweak to. + * (cannot be NULL). + * tweak32: pointer to a 32-byte tweak. If the tweak is invalid + * according to secp256k1_ec_seckey_verify, this function + * returns 0. For uniformly random 32-byte arrays the + * chance of being invalid is negligible (around 1 in + * 2^128) (cannot be NULL). + */ +PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add) { - zval *zCtx, *zSig, *zNData = NULL; - zend_string *msg32, *seckey; + zval *zCtx, *zOutputPubkey, *zInternalPubkey; secp256k1_context *ctx; - secp256k1_schnorrsig *newsig; - secp256k1_nonce_function noncefp = NULL; - zend_fcall_info fci; - zend_fcall_info_cache fcc; - php_secp256k1_nonce_function_data calldata; - void* ndata = NULL; - int result = 0; + secp256k1_pubkey *output_pubkey; + secp256k1_xonly_pubkey *internal_pubkey; + zend_string *zTweak; + int result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/SS|fz", - &zCtx, &zSig, &msg32, &seckey, &fci, &fcc, &zNData) == FAILURE) { - RETURN_LONG(result); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/z/S", &zCtx, &zOutputPubkey, &zInternalPubkey, &zTweak) == FAILURE) { + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); + } else if ((internal_pubkey = php_get_secp256k1_xonly_pubkey(zInternalPubkey)) == NULL) { + RETURN_LONG(0); + } else if (zTweak->len != SECRETKEY_LENGTH) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_xonly_pubkey_tweak_add(): Parameter 4 should be 32 bytes"); + return; } - if (msg32->len != HASH_LENGTH) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 - TSRMLS_CC, "secp256k1_schnorrsig_sign(): Parameter 3 should be 32 bytes"); - return; + output_pubkey = (secp256k1_pubkey *) emalloc(sizeof(secp256k1_pubkey)); + result = secp256k1_xonly_pubkey_tweak_add(ctx, output_pubkey, internal_pubkey, (unsigned char *)zTweak->val); + if (result) { + zval_dtor(zOutputPubkey); + ZVAL_RES(zOutputPubkey, zend_register_resource(output_pubkey, le_secp256k1_xonly_pubkey)); } + RETURN_LONG(result); +} +/* }}} */ - if (seckey->len != SECRETKEY_LENGTH) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 - TSRMLS_CC, "secp256k1_schnorrsig_sign(): Parameter 4 should be 32 bytes"); +/* {{{ proto int secp256k1_xonly_pubkey_tweak_add_check(resource context, string tweaked_pubkey32, int tweaked_pk_parity, resource internal_pubkey, string tweak32) + * Checks that a tweaked pubkey is the result of calling + * secp256k1_xonly_pubkey_tweak_add with internal_pubkey and tweak32. + * + * The tweaked pubkey is represented by its 32-byte x-only serialization and + * its pk_parity, which can both be obtained by converting the result of + * tweak_add to a secp256k1_xonly_pubkey. + * + * Note that this alone does _not_ verify that the tweaked pubkey is a + * commitment. If the tweak is not chosen in a specific way, the tweaked pubkey + * can easily be the result of a different internal_pubkey and tweak. + * + * Returns: 0 if the arguments are invalid or the tweaked pubkey is not the + * result of tweaking the internal_pubkey with tweak32. 1 otherwise. + * Args: ctx: pointer to a context object initialized for verification + * (cannot be NULL) + * In: tweaked_pubkey32: pointer to a serialized xonly_pubkey (cannot be NULL) + * tweaked_pk_parity: the parity of the tweaked pubkey (whose serialization + * is passed in as tweaked_pubkey32). This must match the + * pk_parity value that is returned when calling + * secp256k1_xonly_pubkey with the tweaked pubkey, or + * this function will fail. + * internal_pubkey: pointer to an x-only public key object to apply the + * tweak to (cannot be NULL) + * tweak32: pointer to a 32-byte tweak (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add_check) +{ + zval *zCtx, *zInternalPubkey; + secp256k1_context *ctx; + secp256k1_xonly_pubkey *internal_pubkey; + zend_string *tweakedPubKey32, *tweak32; + long tweakedPubKeyParity; + int result = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rSlz/S", &zCtx, &tweakedPubKey32, &tweakedPubKeyParity, &zInternalPubkey, &tweak32) == FAILURE) { + RETURN_LONG(0); + } + + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if (tweakedPubKey32->len != SECRETKEY_LENGTH) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_xonly_pubkey_tweak_add_check(): Parameter 2 should be 32 bytes"); + return; + } else if ((internal_pubkey = php_get_secp256k1_xonly_pubkey(zInternalPubkey)) == NULL) { + RETURN_LONG(0); + } else if (tweak32->len != SECRETKEY_LENGTH) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_xonly_pubkey_tweak_add_check(): Parameter 5 should be 32 bytes"); return; } - if (ZEND_NUM_ARGS() > 4) { - noncefp = php_secp256k1_nonce_function_callback; - calldata.fci = &fci; - calldata.fcc = &fcc; - if (zNData == NULL) { - calldata.data = NULL; - } else { - calldata.data = zNData; - } - ndata = (void *) &calldata; + result = secp256k1_xonly_pubkey_tweak_add_check(ctx, (unsigned char *)tweakedPubKey32->val, (int) tweakedPubKeyParity, internal_pubkey, (unsigned char *)tweak32->val); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto int secp256k1_keypair_create(resource secp256k1_context, resource &keypair, string seckey) + * Compute the keypair for a secret key. + * + * Returns: 1: secret was valid, keypair is ready to use + * 0: secret was invalid, try again with a different secret + * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL) + * Out: keypair: pointer to the created keypair (cannot be NULL) + * In: seckey: pointer to a 32-byte secret key (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_keypair_create) +{ + zval *zCtx, *zKeyPair; + zend_string *seckey; + secp256k1_context *ctx; + secp256k1_keypair *keypair; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zKeyPair, &seckey) == FAILURE) { + RETURN_LONG(0); } - newsig = (secp256k1_schnorrsig *) emalloc(sizeof(secp256k1_schnorrsig)); - result = secp256k1_schnorrsig_sign(ctx, newsig, - (unsigned char *) msg32->val, (unsigned char *) seckey->val, noncefp, ndata); + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if (seckey->len != 32) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_keypair_create(): Parameter 3 should be 32 bytes"); + return; + } + + keypair = (secp256k1_keypair *) emalloc(sizeof(secp256k1_keypair)); + result = secp256k1_keypair_create(ctx, keypair, (unsigned char *)seckey->val); if (result) { - zval_dtor(zSig); - ZVAL_RES(zSig, zend_register_resource(newsig, le_secp256k1_schnorrsig)); + zval_dtor(zKeyPair); + ZVAL_RES(zKeyPair, zend_register_resource(keypair, le_secp256k1_keypair)); } else { // only free when operation fails, won't return this resource - efree(newsig); + efree(keypair); } RETURN_LONG(result); } /* }}} */ -/* {{{ proto int secp256k1_schnorrsig_verify(resource context, resource sig, string msg32, resource pubKey) - * Verify a Schnorr signature. */ -PHP_FUNCTION(secp256k1_schnorrsig_verify) { - zval *zCtx, *zSchnorrSig, *zPubKey; +/* {{{ proto int secp256k1_keypair_sec(resource secp256k1_context, string &seckey, resource keypair) + * Get the secret key from a keypair. + * + * Returns: 0 if the arguments are invalid. 1 otherwise. + * Args: ctx: pointer to a context object (cannot be NULL) + * Out: seckey: pointer to a 32-byte buffer for the secret key (cannot be NULL) + * In: keypair: pointer to a keypair (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_keypair_sec) +{ + zval *zCtx, *zSecKey, *zKeyPair; secp256k1_context *ctx; - secp256k1_schnorrsig *sig; - secp256k1_pubkey *pubkey; - zend_string *msg32; - int result = 0; + secp256k1_keypair *keypair; + unsigned char seckey[SECRETKEY_LENGTH]; + int result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrSr", &zCtx, &zSchnorrSig, &msg32, &zPubKey) == FAILURE) { - RETURN_LONG(result); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zSecKey, &zKeyPair) == FAILURE) { + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); + } else if ((keypair = php_get_secp256k1_keypair(zKeyPair)) == NULL) { + RETURN_LONG(0); } - if ((sig = php_get_secp256k1_schnorr_signature(zSchnorrSig)) == NULL) { - RETURN_LONG(result); + result = secp256k1_keypair_sec(ctx, seckey, keypair); + if (result) { + zval_dtor(zSecKey); + ZVAL_STRINGL(zSecKey, (const char *) seckey, SECRETKEY_LENGTH); } - if (msg32->len != HASH_LENGTH) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 - TSRMLS_CC, "secp256k1_schnorrsig_verify(): Parameter 3 should be 32 bytes"); - return; + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto int secp256k1_keypair_pub(resource secp256k1_context, resource &pubkey, resource keypair) + * Get the public key from a keypair. + * + * Returns: 0 if the arguments are invalid. 1 otherwise. + * Args: ctx: pointer to a context object (cannot be NULL) + * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to + * the keypair public key. If not, it's set to an invalid value. + * (cannot be NULL) + * In: keypair: pointer to a keypair (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_keypair_pub) +{ + zval *zCtx, *zPubKey, *zKeyPair; + secp256k1_context *ctx; + secp256k1_keypair *keypair; + secp256k1_pubkey *pubkey; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/r", &zCtx, &zPubKey, &zKeyPair) == FAILURE) { + RETURN_LONG(0); } - if ((pubkey = php_get_secp256k1_pubkey(zPubKey)) == NULL) { - RETURN_LONG(result); + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if ((keypair = php_get_secp256k1_keypair(zKeyPair)) == NULL) { + RETURN_LONG(0); + } + + pubkey = (secp256k1_pubkey *) emalloc(sizeof(secp256k1_pubkey)); + result = secp256k1_keypair_pub(ctx, pubkey, keypair); + if (result) { + zval_dtor(zPubKey); + ZVAL_RES(zPubKey, zend_register_resource(pubkey, le_secp256k1_pubkey)); + } else { + efree(pubkey); } - result = secp256k1_schnorrsig_verify(ctx, sig, (unsigned char *) msg32->val, pubkey); RETURN_LONG(result); } /* }}} */ -/* {{{ proto int secp256k1_schnorrsig_verify(resource context, resource scratch, array sigs, array msg32s, array keys, long numsigs) - * Verify a Schnorr signature. */ -PHP_FUNCTION(secp256k1_schnorrsig_verify_batch) +/* {{{ proto int secp256k1_keypair_xonly_pub(resource secp256k1_context, resource &pubkey, &pkParity, resource keypair) + * Get the x-only public key from a keypair. + * + * This is the same as calling secp256k1_keypair_pub and then + * secp256k1_xonly_pubkey_from_pubkey. + * + * Returns: 0 if the arguments are invalid. 1 otherwise. + * Args: ctx: pointer to a context object (cannot be NULL) + * Out: pubkey: pointer to an xonly_pubkey object. If 1 is returned, it is set + * to the keypair public key after converting it to an + * xonly_pubkey. If not, it's set to an invalid value (cannot be + * NULL). + * pk_parity: pointer to an integer that will be set to the pk_parity + * argument of secp256k1_xonly_pubkey_from_pubkey (can be NULL). + * In: keypair: pointer to a keypair (cannot be NULL) + * */ +PHP_FUNCTION(secp256k1_keypair_xonly_pub) { - zval *zCtx, *zScratch, *zSigArray, *zMsg32Array, *zPubKeyArray, *arrayZval; - zend_long numsigs; + zval *zCtx, *zXOnlyPub, *zPkParity, *zKeyPair; secp256k1_context *ctx; - secp256k1_scratch_space_wrapper *scratch_wrap; - HashTable *arr_hash; - const secp256k1_schnorrsig **sigs, *sig; - const secp256k1_pubkey ** pubkeys, *pubkey; - const unsigned char * *msg32s, *msg32; - zend_string *arrayKeyStr; + secp256k1_keypair *keypair; + secp256k1_xonly_pubkey *pubkey; + int pk_parity; + int result; - size_t array_count; - int result = 0, i = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/z/r", &zCtx, &zXOnlyPub, &zPkParity, &zKeyPair) == FAILURE) { + RETURN_LONG(0); + } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rraaal", - &zCtx, &zScratch, &zSigArray, &zMsg32Array, &zPubKeyArray, &numsigs) == FAILURE) { - RETURN_LONG(result); + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if ((keypair = php_get_secp256k1_keypair(zKeyPair)) == NULL) { + RETURN_LONG(0); + } + + pubkey = (secp256k1_xonly_pubkey *) emalloc(sizeof(secp256k1_xonly_pubkey)); + result = secp256k1_keypair_xonly_pub(ctx, pubkey, &pk_parity, keypair); + if (result) { + zval_dtor(zXOnlyPub); + ZVAL_RES(zXOnlyPub, zend_register_resource(pubkey, le_secp256k1_xonly_pubkey)); + zval_dtor(zPkParity); + ZVAL_LONG(zPkParity, pk_parity); + } else { + // only free when operation fails, won't return this resource + efree(pubkey); + } + + RETURN_LONG(result); +} +/* }}} */ + + +/* {{{ proto int secp256k1_keypair_xonly_tweak_add(resource secp256k1_context, resource &keypair, resource tweak32) + * Tweak a keypair by adding tweak32 to the secret key and updating the public + * key accordingly. + * + * Calling this function and then secp256k1_keypair_pub results in the same + * public key as calling secp256k1_keypair_xonly_pub and then + * secp256k1_xonly_pubkey_tweak_add. + * + * Returns: 0 if the arguments are invalid or the resulting keypair would be + * invalid (only when the tweak is the negation of the keypair's + * secret key). 1 otherwise. + * + * Args: ctx: pointer to a context object initialized for verification + * (cannot be NULL) + * In/Out: keypair: pointer to a keypair to apply the tweak to. Will be set to + * an invalid value if this function returns 0 (cannot be + * NULL). + * In: tweak32: pointer to a 32-byte tweak. If the tweak is invalid according + * to secp256k1_ec_seckey_verify, this function returns 0. For + * uniformly random 32-byte arrays the chance of being invalid + * is negligible (around 1 in 2^128) (cannot be NULL). + */ +PHP_FUNCTION(secp256k1_keypair_xonly_tweak_add) +{ + zval *zCtx, *zKeyPair; + zend_string *tweak32; + secp256k1_context *ctx; + secp256k1_keypair *keypair; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zKeyPair, &tweak32) == FAILURE) { + RETURN_LONG(0); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_LONG(result); + RETURN_LONG(0); + } else if ((keypair = php_get_secp256k1_keypair(zKeyPair)) == NULL) { + RETURN_LONG(0); + } else if (tweak32->len != 32) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_keypair_xonly_tweak_add(): Parameter 3 should be 32 bytes"); + return; } - if ((scratch_wrap = php_get_secp256k1_scratch_space(zScratch)) == NULL) { - RETURN_LONG(result); + result = secp256k1_keypair_xonly_tweak_add(ctx, keypair, (unsigned char *) tweak32->val); + RETURN_LONG(result); +} +/* }}} */ + +#endif +/* End extrakeys module functions */ + +/* Begin schnorr module functions */ +#ifdef SECP256K1_MODULE_SCHNORRSIG + +/* {{{ proto int secp256k1_schnorrsig_sign(resource context, string &sig64, string msg32, resource keypair, + * callable? noncefp = null, mixed? ndata = null) + * Create a Schnorr signature. + * + * Does _not_ strictly follow BIP-340 because it does not verify the resulting + * signature. Instead, you can manually use secp256k1_schnorrsig_verify and + * abort if it fails. + * + * Otherwise BIP-340 compliant if the noncefp argument is NULL or + * secp256k1_nonce_function_bip340 and the ndata argument is 32-byte auxiliary + * randomness. + * + * Returns 1 on success, 0 on failure. + * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL) + * Out: sig64: pointer to a 64-byte array to store the serialized signature (cannot be NULL) + * In: msg32: the 32-byte message being signed (cannot be NULL) + * keypair: pointer to an initialized keypair (cannot be NULL) + * noncefp: pointer to a nonce generation function. If NULL, secp256k1_nonce_function_bip340 is used + * ndata: pointer to arbitrary data used by the nonce generation + * function (can be NULL). If it is non-NULL and + * secp256k1_nonce_function_bip340 is used, then ndata must be a + * pointer to 32-byte auxiliary randomness as per BIP-340. + */ +PHP_FUNCTION (secp256k1_schnorrsig_sign) +{ + zval *zCtx, *zSig, *zKeyPair, *zNData = NULL; + zend_string *msg32; + secp256k1_keypair *keypair; + zend_fcall_info fci; + zend_fcall_info_cache fcc; + secp256k1_context *ctx; + unsigned char newsig[SCHNORRSIG_LENGTH]; + secp256k1_nonce_function_hardened noncefp = NULL; + php_secp256k1_nonce_function_data calldata; + void* ndata = NULL; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/Sr|fz", + &zCtx, &zSig, &msg32, &zKeyPair, &fci, &fcc, &zNData) == FAILURE) { + RETURN_LONG(0); } - if ((size_t) numsigs != (size_t) zend_hash_num_elements(Z_ARRVAL_P(zPubKeyArray)) || - (size_t) numsigs != (size_t) zend_hash_num_elements(Z_ARRVAL_P(zMsg32Array)) || - (size_t) numsigs != (size_t) zend_hash_num_elements(Z_ARRVAL_P(zSigArray))) { - RETURN_LONG(result); + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if (msg32->len != HASH_LENGTH) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_schnorrsig_sign(): Parameter 3 should be 32 bytes"); + return; + } else if ((keypair = php_get_secp256k1_keypair(zKeyPair)) == NULL) { + RETURN_LONG(0); } - sigs = emalloc(sizeof(secp256k1_schnorrsig *) * numsigs); - arr_hash = Z_ARRVAL_P(zSigArray); - ZEND_HASH_FOREACH_KEY_VAL(arr_hash, i, arrayKeyStr, arrayZval) { - if ((sig = php_get_secp256k1_schnorr_signature(arrayZval)) == NULL) { - efree(sigs); - RETURN_LONG(result); + if (ZEND_NUM_ARGS() > 4) { + noncefp = php_secp256k1_nonce_function_hardened_callback; + calldata.fci = &fci; + calldata.fcc = &fcc; + if (zNData == NULL) { + calldata.data = NULL; + } else { + calldata.data = zNData; } - sigs[i++] = sig; - } ZEND_HASH_FOREACH_END(); + ndata = (void *) &calldata; + } - msg32s = emalloc(sizeof(unsigned char *) * numsigs); - arr_hash = Z_ARRVAL_P(zMsg32Array); - ZEND_HASH_FOREACH_KEY_VAL(arr_hash, i, arrayKeyStr, arrayZval) { - if (Z_TYPE_P(arrayZval) != IS_STRING || Z_STRLEN_P(arrayZval) != 32) { - efree(sigs); - efree(msg32s); - RETURN_LONG(result); - } - msg32s[i++] = (unsigned char *) Z_STRVAL_P(arrayZval); - } ZEND_HASH_FOREACH_END(); + result = secp256k1_schnorrsig_sign(ctx, newsig, + (unsigned char *) msg32->val, keypair, noncefp, ndata); + if (result) { + ZVAL_STRINGL(zSig, (const char *) newsig, SCHNORRSIG_LENGTH); + } - pubkeys = emalloc(sizeof(secp256k1_pubkey *) * numsigs); - arr_hash = Z_ARRVAL_P(zPubKeyArray); - ZEND_HASH_FOREACH_KEY_VAL(arr_hash, i, arrayKeyStr, arrayZval) { - if ((pubkey = php_get_secp256k1_pubkey(arrayZval)) == NULL) { - efree(sigs); - efree(msg32s); - efree(pubkeys); - RETURN_LONG(result); - } - pubkeys[i++] = pubkey; - } ZEND_HASH_FOREACH_END(); + RETURN_LONG(result); +} +/* }}} */ - result = secp256k1_schnorrsig_verify_batch(ctx, scratch_wrap->scratch, - sigs, msg32s, pubkeys, numsigs); - efree(msg32s); - efree(sigs); - efree(pubkeys); +/* {{{ proto int secp256k1_schnorrsig_verify(resource context, resource sig, string msg32, resource pubKey) + * Verify a Schnorr signature. + * + * Returns: 1: correct signature + * 0: incorrect signature + * Args: ctx: a secp256k1 context object, initialized for verification. + * In: sig64: pointer to the 64-byte signature to verify (cannot be NULL) + * msg32: the 32-byte message being verified (cannot be NULL) + * pubkey: pointer to an x-only public key to verify with (cannot be NULL) + */ +PHP_FUNCTION(secp256k1_schnorrsig_verify) { + zval *zCtx, *zXOnlyPubKey; + zend_string *zSchnorrSig; + secp256k1_context *ctx; + secp256k1_xonly_pubkey *pubkey; + zend_string *msg32; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rSSr", &zCtx, &zSchnorrSig, &msg32, &zXOnlyPubKey) == FAILURE) { + RETURN_LONG(0); + } + if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { + RETURN_LONG(0); + } else if (zSchnorrSig->len != SCHNORRSIG_LENGTH) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_schnorrsig_verify(): Parameter 2 should be 64 bytes"); + return; + } else if (msg32->len != HASH_LENGTH) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_schnorrsig_verify(): Parameter 3 should be 32 bytes"); + return; + } else if ((pubkey = php_get_secp256k1_xonly_pubkey(zXOnlyPubKey)) == NULL) { + RETURN_LONG(0); + } + + result = secp256k1_schnorrsig_verify(ctx, (unsigned char *) zSchnorrSig->val, (unsigned char *) msg32->val, pubkey); RETURN_LONG(result); } /* }}} */ -/* {{{ proto long secp256k1_nonce_function_bipschnorr(string &nonce32, string msg32, string key32, string algo16, data, long attempt) - * An implementation of the nonce generation function as defined in BIP-schnorr. - * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of - * extra entropy. */ -PHP_FUNCTION(secp256k1_nonce_function_bipschnorr) +/* {{{ proto long secp256k1_nonce_function_bip340(string &nonce32, string msg32, string key32, string xonly_pk32, string algo16, mixed data) + * An implementation of the nonce generation function as defined in Bitcoin + * Improvement Proposal 340 "Schnorr Signatures for secp256k1" + * (https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki). + * + * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of + * auxiliary random data as defined in BIP-340. If the data pointer is NULL, + * schnorrsig_sign does not produce BIP-340 compliant signatures. The algo16 + * argument must be non-NULL, otherwise the function will fail and return 0. + * The hash will be tagged with algo16 after removing all terminating null + * bytes. Therefore, to create BIP-340 compliant signatures, algo16 must be set + * to "BIP0340/nonce\0\0\0" */ +PHP_FUNCTION(secp256k1_nonce_function_bip340) { int result; zval *zNonce32; - zend_string *zMsg32, *zKey32; - zval *zAlgo16 = NULL, *zData = NULL; + zend_string *zMsg32, *zKey32, *zXOnlyPk32, *zAlgo16; + zval *zData = NULL; unsigned char *nonce32; - unsigned char *algo16 = NULL; unsigned char *data = NULL; - long attempt; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/SSzzl", &zNonce32, &zMsg32, &zKey32, &zAlgo16, &zData, &attempt) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/SSSSz", &zNonce32, &zMsg32, &zKey32, &zXOnlyPk32, &zAlgo16, &zData) == FAILURE) { RETURN_LONG(0); } - if (!php_nonce_function_extract_algo(zAlgo16, &algo16)) { - RETURN_LONG(0); + if (zMsg32->len != 32) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_nonce_function_bip340(): Parameter 2 should be 32 bytes"); + return; + } else if (zKey32->len != 32) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_nonce_function_bip340(): Parameter 3 should be 32 bytes"); + return; + } else if (zXOnlyPk32->len != 32) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_nonce_function_bip340(): Parameter 4 should be 32 bytes"); + return; + } else if (zAlgo16->len != 16) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "secp256k1_nonce_function_bip340(): Parameter 5 should be 16 bytes"); + return; } else if (!php_nonce_function_extract_data(zData, &data)) { RETURN_LONG(0); } nonce32 = emalloc(32); - result = secp256k1_nonce_function_bipschnorr(nonce32, (unsigned char *)zMsg32->val, - (unsigned char *)zKey32->val, algo16, data, attempt); + result = secp256k1_nonce_function_bip340(nonce32, (unsigned char *)zMsg32->val, (unsigned char *)zKey32->val, + (unsigned char *)zXOnlyPk32->val, (unsigned char *)zAlgo16->val, data); if (result) { zval_dtor(zNonce32); ZVAL_STRINGL(zNonce32, (const char *) nonce32, 32); diff --git a/secp256k1/tests/secp256k1_keypair_create.phpt b/secp256k1/tests/secp256k1_keypair_create.phpt new file mode 100644 index 00000000..953a206b --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_create.phpt @@ -0,0 +1,20 @@ +--TEST-- +secp256k1_keypair_create works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 diff --git a/secp256k1/tests/secp256k1_keypair_create_error1.phpt b/secp256k1/tests/secp256k1_keypair_create_error1.phpt new file mode 100644 index 00000000..6322ad06 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_create_error1.phpt @@ -0,0 +1,25 @@ +--TEST-- +secp256k1_keypair_create errors if key parameter is not 32 bytes +--SKIPIF-- + +--FILE-- +getMessage().PHP_EOL; +} + +?> +--EXPECT-- +secp256k1_keypair_create(): Parameter 3 should be 32 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_create_error2.phpt b/secp256k1/tests/secp256k1_keypair_create_error2.phpt new file mode 100644 index 00000000..0fc44bd1 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_create_error2.phpt @@ -0,0 +1,20 @@ +--TEST-- +secp256k1_keypair_create fails when seckey is invalid +--SKIPIF-- + +--FILE-- + +--EXPECT-- +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_create_error3.phpt b/secp256k1/tests/secp256k1_keypair_create_error3.phpt new file mode 100644 index 00000000..56ffef69 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_create_error3.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_keypair_create errors on invalid parameters +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_create() expects exactly 3 parameters, 0 given +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_create_error4.phpt b/secp256k1/tests/secp256k1_keypair_create_error4.phpt new file mode 100644 index 00000000..8cf90797 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_create_error4.phpt @@ -0,0 +1,22 @@ +--TEST-- +secp256k1_keypair_create returns 0 if context resource is wrong type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_create(): supplied resource is not a valid secp256k1_context resource +0 diff --git a/secp256k1/tests/secp256k1_keypair_create_error5.phpt b/secp256k1/tests/secp256k1_keypair_create_error5.phpt new file mode 100644 index 00000000..bae9749d --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_create_error5.phpt @@ -0,0 +1,24 @@ +--TEST-- +secp256k1_keypair_create returns 0 if seckey length != 32 +--SKIPIF-- + +--FILE-- +getMessage().PHP_EOL; +} + + +?> +--EXPECT-- +secp256k1_keypair_create(): Parameter 3 should be 32 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_pub_basic.phpt b/secp256k1/tests/secp256k1_keypair_pub_basic.phpt new file mode 100644 index 00000000..b62120a6 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_pub_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +secp256k1_keypair_pub works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_pub_error1.phpt b/secp256k1/tests/secp256k1_keypair_pub_error1.phpt new file mode 100644 index 00000000..18d5acf8 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_pub_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_keypair_pub errors if parameter parsing fails +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_pub() expects exactly 3 parameters, 0 given +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_pub_error2.phpt b/secp256k1/tests/secp256k1_keypair_pub_error2.phpt new file mode 100644 index 00000000..6c50d72c --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_pub_error2.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_keypair_pub returns 0 if context is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_keypair_pub(): supplied resource is not a valid secp256k1_context resource +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_pub_error3.phpt b/secp256k1/tests/secp256k1_keypair_pub_error3.phpt new file mode 100644 index 00000000..af2b8544 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_pub_error3.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_keypair_pub errors if keypair is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_keypair_pub(): supplied resource is not a valid secp256k1_keypair resource +0 diff --git a/secp256k1/tests/secp256k1_keypair_sec_basic.phpt b/secp256k1/tests/secp256k1_keypair_sec_basic.phpt new file mode 100644 index 00000000..94665e31 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_sec_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_keypair_sec works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +0000000000000000000000000000000000000000000000000000000000000003 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_sec_error1.phpt b/secp256k1/tests/secp256k1_keypair_sec_error1.phpt new file mode 100644 index 00000000..65fa5314 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_sec_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_keypair_sec errors if parameter parsing fails +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_sec() expects exactly 3 parameters, 0 given +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_sec_error2.phpt b/secp256k1/tests/secp256k1_keypair_sec_error2.phpt new file mode 100644 index 00000000..d7f5a10b --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_sec_error2.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_keypair_sec returns 0 if context is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_keypair_sec(): supplied resource is not a valid secp256k1_context resource +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_sec_error3.phpt b/secp256k1/tests/secp256k1_keypair_sec_error3.phpt new file mode 100644 index 00000000..26065f38 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_sec_error3.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_keypair_sec errors if keypair is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_keypair_sec(): supplied resource is not a valid secp256k1_keypair resource +0 diff --git a/secp256k1/tests/secp256k1_keypair_xonly_pub_basic.phpt b/secp256k1/tests/secp256k1_keypair_xonly_pub_basic.phpt new file mode 100644 index 00000000..1fa198b1 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_xonly_pub_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +secp256k1_keypair_xonly_pub works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +Parity 0 +1 +f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_xonly_pub_error1.phpt b/secp256k1/tests/secp256k1_keypair_xonly_pub_error1.phpt new file mode 100644 index 00000000..44eb8fab --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_xonly_pub_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_keypair_xonly_pub errors if parameter parsing fails +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_xonly_pub() expects exactly 4 parameters, 0 given +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_xonly_pub_error2.phpt b/secp256k1/tests/secp256k1_keypair_xonly_pub_error2.phpt new file mode 100644 index 00000000..49493098 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_xonly_pub_error2.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_keypair_xonly_pub returns 0 if context is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_keypair_xonly_pub(): supplied resource is not a valid secp256k1_context resource +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_keypair_xonly_pub_error3.phpt b/secp256k1/tests/secp256k1_keypair_xonly_pub_error3.phpt new file mode 100644 index 00000000..0ece8dd3 --- /dev/null +++ b/secp256k1/tests/secp256k1_keypair_xonly_pub_error3.phpt @@ -0,0 +1,22 @@ +--TEST-- +secp256k1_keypair_xonly_pub errors if keypair is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_xonly_pub(): supplied resource is not a valid secp256k1_keypair resource +0 diff --git a/secp256k1/tests/secp256k1_schnorrsig_serialize_error1.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_error1.phpt similarity index 62% rename from secp256k1/tests/secp256k1_schnorrsig_serialize_error1.phpt rename to secp256k1/tests/secp256k1_nonce_function_bip340_error1.phpt index fa79432d..97a6c98a 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_serialize_error1.phpt +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_error1.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_serialize errors if parameter parsing fails +secp256k1_nonce_function_bip340 returns 0 if parameter parsing fails --SKIPIF-- --FILE-- --EXPECT-- -secp256k1_schnorrsig_serialize() expects exactly 3 parameters, 0 given +secp256k1_nonce_function_bip340() expects exactly 6 parameters, 0 given 0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bip340_error2.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_error2.phpt new file mode 100644 index 00000000..c94a5a3f --- /dev/null +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_error2.phpt @@ -0,0 +1,43 @@ +--TEST-- +secp256k1_nonce_function_bip340 throws if parameters have the wrong length +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} +try { + secp256k1_nonce_function_bip340($output, $msg32, substr($key32, 0, 31), $xonlyPubKey32, $algo16, $auxRand); +} catch (\Exception $e) { + echo $e->getMessage() . PHP_EOL; +} +try { + secp256k1_nonce_function_bip340($output, $msg32, $key32, substr($xonlyPubKey32, 0, 31), $algo16, $auxRand); +} catch (\Exception $e) { + echo $e->getMessage() . PHP_EOL; +} +try { + secp256k1_nonce_function_bip340($output, $msg32, $key32, $xonlyPubKey32, substr($algo16, 0, 15), $auxRand); +} catch (\Exception $e) { + echo $e->getMessage() . PHP_EOL; +} +?> +--EXPECT-- +secp256k1_nonce_function_bip340(): Parameter 2 should be 32 bytes +secp256k1_nonce_function_bip340(): Parameter 3 should be 32 bytes +secp256k1_nonce_function_bip340(): Parameter 4 should be 32 bytes +secp256k1_nonce_function_bip340(): Parameter 5 should be 16 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bip340_error_algo16_wrong_size.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_error_algo16_wrong_size.phpt new file mode 100644 index 00000000..52c97eb3 --- /dev/null +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_error_algo16_wrong_size.phpt @@ -0,0 +1,38 @@ +--TEST-- +secp256k1_nonce_function_bip340 returns 0 if algo16 is neither NULL, or a 16 byte string +--SKIPIF-- + +--FILE-- +getMessage().PHP_EOL; +} + + +try { + secp256k1_nonce_function_bip340($output, $msg32, $key32, $xonlyPubKey32, $algo16 = "BIP0340/nonce\x00\x00\x00\x00", $auxRand); // 17 +} catch (\Exception $e) { + echo $e->getMessage().PHP_EOL; +} + +$result = secp256k1_nonce_function_bip340($output, $msg32, $key32, $xonlyPubKey32, $algo16 = "BIP0340/nonce\x00\x00\x00", $auxRand); // 16 +echo $result . PHP_EOL; +echo unpack("H*", $output)[1] . PHP_EOL; +?> +--EXPECT-- +secp256k1_nonce_function_bip340(): Parameter 5 should be 16 bytes +secp256k1_nonce_function_bip340(): Parameter 5 should be 16 bytes +1 +1d2dc1652fee3ad08434469f9ad30536a5787feccfa308e8fb396c8030dd1c69 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bip340_error_data_wrong_size.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_error_data_wrong_size.phpt new file mode 100644 index 00000000..ef6c1228 --- /dev/null +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_error_data_wrong_size.phpt @@ -0,0 +1,29 @@ +--TEST-- +secp256k1_nonce_function_bip340 returns 0 if data string length is not 32 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +0 +0 +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bip340_error_data_wrong_type.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_error_data_wrong_type.phpt new file mode 100644 index 00000000..b6cec5b1 --- /dev/null +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_error_data_wrong_type.phpt @@ -0,0 +1,30 @@ +--TEST-- +secp256k1_nonce_function_bip340 returns 0 if data is neither NULL, or a 32 byte string +--SKIPIF-- + +--FILE-- + +--EXPECT-- +0 +0 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bip340_test.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_test.phpt new file mode 100644 index 00000000..d55de4e6 --- /dev/null +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_test.phpt @@ -0,0 +1,25 @@ +--TEST-- +secp256k1_nonce_function_bip340 returns a result +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1d2dc1652fee3ad08434469f9ad30536a5787feccfa308e8fb396c8030dd1c69 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bip340_test2.phpt b/secp256k1/tests/secp256k1_nonce_function_bip340_test2.phpt new file mode 100644 index 00000000..db0957ef --- /dev/null +++ b/secp256k1/tests/secp256k1_nonce_function_bip340_test2.phpt @@ -0,0 +1,36 @@ +--TEST-- +secp256k1_nonce_function_bip340 respects extra data +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1d2dc1652fee3ad08434469f9ad30536a5787feccfa308e8fb396c8030dd1c69 +1 +bb410c40d713cdf9007c503f3973d37795ecddc646775cc67e72a00ac0dd97af +1 +723ae4b7180a186ba64f96024c3e3dda920258e66fefdee17871f547261700e4 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error1.phpt b/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error1.phpt deleted file mode 100644 index ea3bf608..00000000 --- a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error1.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -secp256k1_nonce_function_bipschnorr returns 0 if parameter parsing fails ---SKIPIF-- - ---FILE-- - ---EXPECT-- -secp256k1_nonce_function_bipschnorr() expects exactly 6 parameters, 0 given -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_algo16_wrong_size.phpt b/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_algo16_wrong_size.phpt deleted file mode 100644 index 86f4540f..00000000 --- a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_algo16_wrong_size.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -secp256k1_nonce_function_bipschnorr returns 0 if algo16 is neither NULL, or a 16 byte string ---SKIPIF-- - ---FILE-- - ---EXPECT-- -0 -0 -1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_data_wrong_size.phpt b/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_data_wrong_size.phpt deleted file mode 100644 index 10d8d5bf..00000000 --- a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_data_wrong_size.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -secp256k1_nonce_function_bipschnorr returns 0 if data string length is not 32 ---SKIPIF-- - ---FILE-- - ---EXPECT-- -0 -0 -1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_data_wrong_type.phpt b/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_data_wrong_type.phpt deleted file mode 100644 index f9fef407..00000000 --- a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_error_data_wrong_type.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -secp256k1_nonce_function_bipschnorr returns 0 if data is neither NULL, or a 32 byte string ---SKIPIF-- - ---FILE-- - ---EXPECT-- -0 -0 -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_test.phpt b/secp256k1/tests/secp256k1_nonce_function_bipschnorr_test.phpt deleted file mode 100644 index f9e487c9..00000000 --- a/secp256k1/tests/secp256k1_nonce_function_bipschnorr_test.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -secp256k1_nonce_function_bipschnorr returns a result ---SKIPIF-- - ---FILE-- - ---EXPECT-- -1 -a9be39328bdf208e8b9e3cfafe7909c9816314193139c93f2d092efa8de68703 -1 -c437c1fda591773cba3c9aa3a0676de698bc8abbde9b19ae6ae5163d3815e447 -1 -03da74950c67f923871c0052de77dd137b26943e1d4eacb573590aa82820b0a4 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_parse_basic.phpt b/secp256k1/tests/secp256k1_schnorrsig_parse_basic.phpt deleted file mode 100644 index 5c2514e5..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_parse_basic.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_parse works ---SKIPIF-- - ---FILE-- - ---EXPECT-- -1 -secp256k1_schnorrsig diff --git a/secp256k1/tests/secp256k1_schnorrsig_parse_error1.phpt b/secp256k1/tests/secp256k1_schnorrsig_parse_error1.phpt deleted file mode 100644 index c97e45f6..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_parse_error1.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_parse errors when context is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -secp256k1_schnorrsig_parse(): supplied resource is not a valid secp256k1_context resource -int(0) \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_parse_error2.phpt b/secp256k1/tests/secp256k1_schnorrsig_parse_error2.phpt deleted file mode 100644 index 51a300cd..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_parse_error2.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_parse errors when signature is invalid ---SKIPIF-- - ---FILE-- -getMessage(); -} -?> ---EXPECT-- -secp256k1_schnorrsig_parse(): Parameter 3 should be 64 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_parse_error3.phpt b/secp256k1/tests/secp256k1_schnorrsig_parse_error3.phpt deleted file mode 100644 index e2dc220d..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_parse_error3.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_parse errors if parameter parsing fails ---SKIPIF-- - ---FILE-- - ---EXPECT-- -secp256k1_schnorrsig_parse() expects exactly 3 parameters, 0 given -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_serialize_basic.phpt b/secp256k1/tests/secp256k1_schnorrsig_serialize_basic.phpt deleted file mode 100644 index cf022c9b..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_serialize_basic.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_serialize works ---SKIPIF-- - ---FILE-- - ---EXPECT-- -1 -1 -7a8e3bdc7c64f31b119a849e8bb39ddbdc0a64abd4cadcc5cfc15d3ec06354ed4719389aedb16b2dd13552eed546b24350d6e636ac454ea72afc1ffd0cf421b7 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_serialize_error2.phpt b/secp256k1/tests/secp256k1_schnorrsig_serialize_error2.phpt deleted file mode 100644 index d3e4e478..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_serialize_error2.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_serialize errors if context is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -1 -secp256k1_schnorrsig_serialize(): supplied resource is not a valid secp256k1_context resource -0 diff --git a/secp256k1/tests/secp256k1_schnorrsig_serialize_error3.phpt b/secp256k1/tests/secp256k1_schnorrsig_serialize_error3.phpt deleted file mode 100644 index bd6365e4..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_serialize_error3.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_serialize errors if secp256k1_schnorrsig is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -secp256k1_schnorrsig_serialize(): supplied resource is not a valid secp256k1_schnorrsig resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_basic.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_basic.phpt index 1537ef87..ca2a8193 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_basic.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_sign works +secp256k1_schnorrsig_sign works with bip vector 0 --SKIPIF-- --EXPECT-- 1 1 -b8edb50a96431b8a15c71f128f1f9bc9dd2e01c75894f757d0ee4aa6a1ca60fc9753f61ce15907f7a1adcac85e3f93cb256c01d040b575b0bf74e8b9661a75fa \ No newline at end of file +1 +F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9 +1 +E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0 +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_basic2.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_basic2.phpt index 96a160bb..74df9005 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_basic2.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_basic2.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_sign works with a different key +secp256k1_schnorrsig_sign works with bip vector 1 --SKIPIF-- --EXPECT-- 1 1 -b2579a4e31562773bf4b3717527013f9e996f0a712b4606321f16e705b9a5e179b6cd094edfcfcb1cd82c1ac46e496423fc51a9a8f4fbcde4f8b9bc8207f6c87 \ No newline at end of file +1 +DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659 +1 +6896BD60EEAE296DB48A229FF71DFE071BDE413E6D43F917DC8DCF8C78DE33418906D11AC976ABCCB20B091292BFF4EA897EFCB639EA871CFA95F6DE339E4B0A +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_basic3.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_basic3.phpt new file mode 100644 index 00000000..4dcfff00 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_basic3.phpt @@ -0,0 +1,52 @@ +--TEST-- +secp256k1_schnorrsig_sign works with bip vector 2 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8 +1 +5831AAEED7B44BB74E5EAB94BA9D4294C49BCF2A60728D8B4C200F50DD313C1BAB745879A5AD954A72C45A91C3A51D3C7ADEA98D82F8481E0E1E03674A6F3FB7 +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_basic4.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_basic4.phpt new file mode 100644 index 00000000..cdf485f0 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_basic4.phpt @@ -0,0 +1,52 @@ +--TEST-- +secp256k1_schnorrsig_sign works with bip vector 3 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +25D1DFF95105F5253C4022F628A996AD3A0D95FBF21D468A1B33F8C160D8F517 +1 +7EB0509757E246F19449885651611CB965ECC1A187DD51B64FDA1EDC9637D5EC97582B9CB13DB3933705B32BA982AF5AF25FD78881EBB32771FC5922EFC66EA3 +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_int_data.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_int_data.phpt index 540aaf75..cbd2262c 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_int_data.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_int_data.phpt @@ -9,34 +9,34 @@ if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig s --EXPECT-- +1 triggered callback int(42) 1 -1 -24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c76badaec2bc699660d7a17f3457c5e4aeef226a5890676675cc25b7ee7a25de2 \ No newline at end of file +E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_stdclass_data.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_stdclass_data.phpt index e4081eaf..f13304f9 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_stdclass_data.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_stdclass_data.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_sign works a user provided nonce function, with additional data (stdClass) +secp256k1_schnorrsig_sign works a user provided nonce function, with additional \stdClass data --SKIPIF-- --EXPECT-- +1 triggered callback object(stdClass)#2 (0) { } 1 -1 -24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c76badaec2bc699660d7a17f3457c5e4aeef226a5890676675cc25b7ee7a25de2 \ No newline at end of file +E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_string_data.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_string_data.phpt index e15a571e..4a3ebbf0 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_string_data.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_nonce_and_string_data.phpt @@ -9,33 +9,34 @@ if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig s --EXPECT-- -triggered callback -string(4) "ABCD" 1 +triggered callback +string(4) "1234" 1 -24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c76badaec2bc699660d7a17f3457c5e4aeef226a5890676675cc25b7ee7a25de2 \ No newline at end of file +E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp.phpt index c9a9b9f7..4acc71be 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_sign works a user provided nonce function, no additional data +secp256k1_schnorrsig_sign works a user provided nonce function, with no additional data --SKIPIF-- --EXPECT-- -triggered callback 1 +triggered callback +NULL 1 -24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c76badaec2bc699660d7a17f3457c5e4aeef226a5890676675cc25b7ee7a25de2 \ No newline at end of file +E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp_and_data_uses_use.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp_and_data_uses_use.phpt index 008fb39c..9dd1d5ce 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp_and_data_uses_use.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_custom_noncefp_and_data_uses_use.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_sign works a user provided nonce function, with additional string data, and can use 'use' +secp256k1_schnorrsig_sign works a user provided nonce function, which uses 'use's --SKIPIF-- --EXPECT-- -triggered callback -string(4) "ABCD" -string(14) "THIS IS EXTRA!" 1 +triggered callback +NULL +string(14) "This is extra!" 1 -24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c76badaec2bc699660d7a17f3457c5e4aeef226a5890676675cc25b7ee7a25de2 \ No newline at end of file +E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_error1.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_error1.phpt index ceecc17c..3cf2bd03 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_error1.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_error1.phpt @@ -13,18 +13,16 @@ set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); $ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); // fixture came from our signatures.yml -$sigIn = hex2bin("132382ca59240c2e14ee7ff61d90fc63276325f4cbe8169fc53ade4a407c2fc84d86fbe3bde6975dd5a91fdc95ad6544dcdf0dab206f02224ce7e2b151bd82ab"); +$sigIn = null; $msg32 = \pack("H*", "9e5755ec2f328cc8635a55415d0e9a09c2b6f2c9b0343c945fbbfe08247a4cbe"); $priv = \pack("H*", "31a84594060e103f5a63eb742bd46cf5f5900d8406e2726dedfc61c7cf43ebad"); -$sig = null; -$result = secp256k1_schnorrsig_parse($ctx, $sig, $sigIn); +$keypair = null; +$result = secp256k1_keypair_create($ctx, $keypair, $priv); echo $result.PHP_EOL; $ctx = tmpfile(); - -$sig = null; -$result = secp256k1_schnorrsig_sign($ctx, $sig, $msg32, $priv); +$result = secp256k1_schnorrsig_sign($ctx, $sigIn, $msg32, $keypair); echo $result . PHP_EOL; ?> diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_error2.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_error2.phpt index 8d2bfe94..a8f00698 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_error2.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_error2.phpt @@ -11,19 +11,23 @@ if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig s set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); // fixture came from our signatures.yml -$sigIn = hex2bin("30440220132382ca59240c2e14ee7ff61d90fc63276325f4cbe8169fc53ade4a407c2fc802204d86fbe3bde6975dd5a91fdc95ad6544dcdf0dab206f02224ce7e2b151bd82ab"); $msg32 = \pack("H*", "9e5755ec2f328cc8635a55415d"); $priv = \pack("H*", "31a84594060e103f5a63eb742bd46cf5f5900d8406e2726dedfc61c7cf43ebad"); $ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); +$keypair = null; +$result = secp256k1_keypair_create($ctx, $keypair, $priv); +echo $result.PHP_EOL; + $sig = null; try { - secp256k1_schnorrsig_sign($ctx, $sig, $msg32, $priv); + secp256k1_schnorrsig_sign($ctx, $sig, $msg32, $keypair); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; } ?> --EXPECT-- +1 secp256k1_schnorrsig_sign(): Parameter 3 should be 32 bytes diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_error3.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_error3.phpt deleted file mode 100644 index 3f192c4a..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_error3.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_sign errors if key parameter is not 32 bytes ---SKIPIF-- - ---FILE-- -getMessage() . PHP_EOL; -} - -?> ---EXPECT-- -secp256k1_schnorrsig_sign(): Parameter 4 should be 32 bytes diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_error5.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_error5.phpt deleted file mode 100644 index f7e754c9..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_error5.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_sign fails when seckey is invalid ---SKIPIF-- - ---FILE-- - ---EXPECT-- -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_sign_with_noncefp_bipschnorr.phpt b/secp256k1/tests/secp256k1_schnorrsig_sign_with_noncefp_bipschnorr.phpt index 7cbcb952..c949c9e2 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_sign_with_noncefp_bipschnorr.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_sign_with_noncefp_bipschnorr.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_sign with secp256k1_nonce_function_bipschnorr matches default +secp256k1_schnorrsig_sign with secp256k1_nonce_function_bip340 matches default --SKIPIF-- --EXPECT-- 1 -secp256k1_schnorrsig -1 1 -secp256k1_schnorrsig 1 Signatures are equal: 1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_basic.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_basic.phpt index a51004cd..e7f41f2b 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_basic.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_basic.phpt @@ -10,23 +10,19 @@ if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig s $ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); -$sigBin = pack("H*", "b8edb50a96431b8a15c71f128f1f9bc9dd2e01c75894f757d0ee4aa6a1ca60fc9753f61ce15907f7a1adcac85e3f93cb256c01d040b575b0bf74e8b9661a75fa"); -$msg32 = hash('sha256', "a message", true); -$pubKeyBin = pack("H*", "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619"); +$sig64 = pack("H*", "E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0"); +$msg32 = hex2bin("0000000000000000000000000000000000000000000000000000000000000000"); +$pubKeyBin = pack("H*", "F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9"); $sig = null; $pubKey = null; -$result = secp256k1_schnorrsig_parse($ctx, $sig, $sigBin); +$result = secp256k1_xonly_pubkey_parse($ctx, $pubKey, $pubKeyBin); echo $result.PHP_EOL; -$result = secp256k1_ec_pubkey_parse($ctx, $pubKey, $pubKeyBin); -echo $result.PHP_EOL; - -$result = secp256k1_schnorrsig_verify($ctx, $sig, $msg32, $pubKey); +$result = secp256k1_schnorrsig_verify($ctx, $sig64, $msg32, $pubKey); echo $result.PHP_EOL; ?> --EXPECT-- 1 -1 1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch.phpt deleted file mode 100644 index 0bd66eda..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch.phpt +++ /dev/null @@ -1,66 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch works, and returns an error if batch fails ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -1 -tests: -1 -0 -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error1.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error1.phpt deleted file mode 100644 index 05bbfaca..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error1.phpt +++ /dev/null @@ -1,67 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_batch_verify detects an error ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -1 -tests: -1 -1 -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error2.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error2.phpt deleted file mode 100644 index ff7571e7..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error2.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors when parameter parsing fails ---SKIPIF-- - ---FILE-- - ---EXPECT-- -secp256k1_schnorrsig_verify_batch() expects exactly 6 parameters, 0 given -int(0) \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error3.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error3.phpt deleted file mode 100644 index 2f569f25..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error3.phpt +++ /dev/null @@ -1,59 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors when context is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -1 -tests: -secp256k1_schnorrsig_verify_batch(): supplied resource is not a valid secp256k1_context resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error4.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error4.phpt deleted file mode 100644 index d1ab597e..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error4.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors when scratch space is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -tests: -secp256k1_schnorrsig_verify_batch(): supplied resource is not a valid secp256k1_scratch_space resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error5.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error5.phpt deleted file mode 100644 index 3884e62f..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error5.phpt +++ /dev/null @@ -1,66 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors when array count is wrong ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -1 -tests: -0 -0 -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error6.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error6.phpt deleted file mode 100644 index 16bdaf24..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error6.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors when the signature array has the wrong type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -tests: -secp256k1_schnorrsig_verify_batch(): supplied resource is not a valid secp256k1_schnorrsig resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error7.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error7.phpt deleted file mode 100644 index a686d337..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error7.phpt +++ /dev/null @@ -1,56 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors when the key array has the wrong type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -tests: -secp256k1_schnorrsig_verify_batch(): supplied resource is not a valid secp256k1_pubkey resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error8.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error8.phpt deleted file mode 100644 index 3f18b429..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_batch_error8.phpt +++ /dev/null @@ -1,55 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify_batch errors if msg32 has a non-string in the array ---SKIPIF-- - ---FILE-- - ---EXPECT-- -setup: -1 -1 -1 -1 -1 -tests: -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector10.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector10.phpt new file mode 100644 index 00000000..b6981c8c --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector10.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 10 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector11.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector11.phpt new file mode 100644 index 00000000..11253e03 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector11.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 11 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector12.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector12.phpt new file mode 100644 index 00000000..e13fef5c --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector12.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 12 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector13.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector13.phpt new file mode 100644 index 00000000..a2ac1be7 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector13.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 13 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector14.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector14.phpt new file mode 100644 index 00000000..0c897b16 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector14.phpt @@ -0,0 +1,24 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 14 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector4.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector4.phpt new file mode 100644 index 00000000..ba9556ab --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector4.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 4 - returns true +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector5.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector5.phpt new file mode 100644 index 00000000..b188f5ad --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector5.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 5 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +0 diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector6.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector6.phpt new file mode 100644 index 00000000..d3725431 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector6.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 6 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector7.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector7.phpt new file mode 100644 index 00000000..a30eea7a --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector7.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 7 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector8.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector8.phpt new file mode 100644 index 00000000..bffd63db --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector8.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 8 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector9.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector9.phpt new file mode 100644 index 00000000..cd87c678 --- /dev/null +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_bipvector9.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_schnorrsig_verify - bip vector 9 - returns false +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_error1.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_error1.phpt index 2804ec20..73b49189 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_error1.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_error1.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_verify errors if provided an invalid resource as a context +secp256k1_schnorrsig_verify errors if provided invalid resource as context --SKIPIF-- --EXPECT-- 1 -1 secp256k1_schnorrsig_verify(): supplied resource is not a valid secp256k1_context resource 0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_error2.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_error2.phpt index c502068a..6f7cbcb3 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_error2.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_error2.phpt @@ -10,27 +10,21 @@ if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig s $ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); -$sigBin = pack("H*", "b8edb50a96431b8a15c71f128f1f9bc9dd2e01c75894f757d0ee4aa6a1ca60fc9753f61ce15907f7a1adcac85e3f93cb256c01d040b575b0bf74e8b9661a75fa"); +$sig64 = pack("H*", "E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0"); $msg32 = substr(hash('sha256', "a message", true), 0, 16); // half necessary size -$pubKeyBin = pack("H*", "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619"); -$sig = null; +$pubKeyBin = pack("H*", "F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9"); $pubKey = null; -$result = secp256k1_schnorrsig_parse($ctx, $sig, $sigBin); -echo $result.PHP_EOL; - -$result = secp256k1_ec_pubkey_parse($ctx, $pubKey, $pubKeyBin); +$result = secp256k1_xonly_pubkey_parse($ctx, $pubKey, $pubKeyBin); echo $result.PHP_EOL; try { - echo secp256k1_schnorrsig_verify($ctx, $sig, $msg32, $pubKey); + echo secp256k1_schnorrsig_verify($ctx, $sig64, $msg32, $pubKey); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; } - ?> --EXPECT-- 1 -1 secp256k1_schnorrsig_verify(): Parameter 3 should be 32 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_error4.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_error4.phpt index 8baf84aa..a1970c42 100644 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_error4.phpt +++ b/secp256k1/tests/secp256k1_schnorrsig_verify_error4.phpt @@ -1,5 +1,5 @@ --TEST-- -secp256k1_schnorrsig_verify returns an error on invalid input +secp256k1_schnorrsig_verify errors when pubkey is wrong resource type --SKIPIF-- --EXPECT-- -1 -1 -1 -1 -1 -0 -0 +secp256k1_schnorrsig_verify(): supplied resource is not a valid secp256k1_xonly_pubkey resource 0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_error5.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_error5.phpt deleted file mode 100644 index bd0cffb6..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_error5.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify errors when signature is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -1 -secp256k1_schnorrsig_verify(): supplied resource is not a valid secp256k1_schnorrsig resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_schnorrsig_verify_error6.phpt b/secp256k1/tests/secp256k1_schnorrsig_verify_error6.phpt deleted file mode 100644 index 353904e0..00000000 --- a/secp256k1/tests/secp256k1_schnorrsig_verify_error6.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -secp256k1_schnorrsig_verify errors when pubkey is wrong resource type ---SKIPIF-- - ---FILE-- - ---EXPECT-- -1 -secp256k1_schnorrsig_verify(): supplied resource is not a valid secp256k1_pubkey resource -0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic.phpt new file mode 100644 index 00000000..27672d6e --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +secp256k1_xonly_pubkey_from_pubkey works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +Parity 0 +1 +f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error1.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error1.phpt new file mode 100644 index 00000000..c7e1b29f --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_xonly_pubkey_from_pubkey errors if parameter parsing fails +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_xonly_pubkey_from_pubkey() expects exactly 4 parameters, 0 given +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error2.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error2.phpt new file mode 100644 index 00000000..9afc2905 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error2.phpt @@ -0,0 +1,28 @@ +--TEST-- +secp256k1_xonly_pubkey_from_pubkey errors when context is wrong type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_xonly_pubkey_from_pubkey(): supplied resource is not a valid secp256k1_context resource +0 diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error3.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error3.phpt new file mode 100644 index 00000000..4e2c3466 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_from_pubkey_error3.phpt @@ -0,0 +1,22 @@ +--TEST-- +secp256k1_xonly_pubkey_from_pubkey errors when pubkey is wrong type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_xonly_pubkey_from_pubkey(): supplied resource is not a valid secp256k1_pubkey resource +0 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..90222e1a --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_basic.phpt @@ -0,0 +1,58 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +1 +02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +1 +1 +1 +e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_basic1.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_basic1.phpt new file mode 100644 index 00000000..dc24ccd2 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_basic1.phpt @@ -0,0 +1,50 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add_check works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +1 +1 +e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +1 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error1.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error1.phpt new file mode 100644 index 00000000..199ca758 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add_check errors if parameter parsing fails +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_xonly_pubkey_tweak_add_check() expects exactly 5 parameters, 0 given +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error2.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error2.phpt new file mode 100644 index 00000000..19cc5974 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error2.phpt @@ -0,0 +1,53 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add_check errors if context is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +1 +1 +e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +secp256k1_xonly_pubkey_tweak_add_check(): supplied resource is not a valid secp256k1_context resource +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error3.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error3.phpt new file mode 100644 index 00000000..559f72af --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error3.phpt @@ -0,0 +1,53 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add_check errors if internal pubkey is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +1 +1 +1 +e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +secp256k1_xonly_pubkey_tweak_add_check(): supplied resource is not a valid secp256k1_xonly_pubkey resource +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error4.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error4.phpt new file mode 100644 index 00000000..ff30433d --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error4.phpt @@ -0,0 +1,55 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add_check returns 0 if tweaked_pubkey32 is not 32 bytes +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +1 +1 +1 +1 +1 +e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +secp256k1_xonly_pubkey_tweak_add_check(): Parameter 2 should be 32 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error5.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error5.phpt new file mode 100644 index 00000000..8e672561 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_check_error5.phpt @@ -0,0 +1,55 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add_check throws if tweak32 is not 32 bytes +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +1 +1 +1 +1 +1 +e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +secp256k1_xonly_pubkey_tweak_add_check(): Parameter 5 should be 32 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error1.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error1.phpt new file mode 100644 index 00000000..b86122dd --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add works +--SKIPIF-- + +--FILE-- + +--EXPECT-- +secp256k1_keypair_xonly_tweak_add() expects exactly 3 parameters, 0 given +0 diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error2.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error2.phpt new file mode 100644 index 00000000..cc0feb56 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error2.phpt @@ -0,0 +1,27 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add errors when context is wrong type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +secp256k1_keypair_xonly_tweak_add(): supplied resource is not a valid secp256k1_context resource +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error3.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error3.phpt new file mode 100644 index 00000000..b4261254 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error3.phpt @@ -0,0 +1,35 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add errors when xonly pubkey is wrong resource type +--SKIPIF-- + +--FILE-- + +--EXPECT-- +1 +1 +secp256k1_xonly_pubkey_tweak_add(): supplied resource is not a valid secp256k1_xonly_pubkey resource +0 diff --git a/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error4.phpt b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error4.phpt new file mode 100644 index 00000000..1c1d5489 --- /dev/null +++ b/secp256k1/tests/secp256k1_xonly_pubkey_tweak_add_error4.phpt @@ -0,0 +1,54 @@ +--TEST-- +secp256k1_xonly_pubkey_tweak_add throws if tweak32 length != 32 +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +1 +1 +1 +1 +02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 +1 +secp256k1_xonly_pubkey_tweak_add(): Parameter 4 should be 32 bytes \ No newline at end of file diff --git a/stubs/const.php b/stubs/const.php index d6f84de9..27781251 100644 --- a/stubs/const.php +++ b/stubs/const.php @@ -17,4 +17,5 @@ const SECP256K1_TAG_PUBKEY_HYBRID_EVEN = 6; const SECP256K1_TAG_PUBKEY_HYBRID_ODD = 7; const SECP256K1_TYPE_RECOVERABLE_SIG = "secp256k1_ecdsa_recoverable_signature"; -const SECP256K1_TYPE_SCHNORRSIG = "secp256k1_schnorrsig"; +const SECP256K1_TYPE_XONLY_PUBKEY = "secp256k1_xonly_pubkey"; +const SECP256K1_TYPE_KEYPAIR = "secp256k1_keypair"; diff --git a/stubs/functions.php b/stubs/functions.php index 56d76e39..a065bd8a 100644 --- a/stubs/functions.php +++ b/stubs/functions.php @@ -395,42 +395,78 @@ function secp256k1_ecdsa_recover($context, &$ecPublicKey, $ecdsaRecoverableSigna */ function secp256k1_ecdh($context, string &$result, $ecPublicKey, string $privKey, ?callable $hashfxn, ?int $outputLen, $data): int {} /** - * Serialize a Schnorr signature. - * - * Returns: 1 - * Args: ctx: a secp256k1 context object - * Out: out64: pointer to a 64-byte array to store the serialized signature - * In: sig: pointer to the signature - * - * See secp256k1_schnorrsig_parse for details about the encoding. * @param resource $context - * @param string|null $sigout - * @param resource $schnorrsig + * @param resource|null $pubkey + * @param string $input32 * @return int */ -function secp256k1_schnorrsig_serialize($context, ?string &$sigout, $schnorrsig): int {} +function secp256k1_xonly_pubkey_parse($context, &$pubkey, string $input32): int {} +/** + * @param resource $context + * @param string|null $pubkey + * @return int + */ +function secp256k1_xonly_pubkey_serialize($context, ?string &$pubkey): int {} +/** + * @param resource $context + * @param resource|null $pubkey + * @param int|null $pk_parity + * @return int + */ +function secp256k1_xonly_pubkey_from_pubkey($context, &$pubkey, ?int &$pk_parity): int {} +/** + * @param resource $context + * @param resource|null $output_pubkey + * @param resource $internal_pubkey + * @param string $tweak + * @return int + */ +function secp256k1_xonly_pubkey_tweak_add($context, &$output_pubkey, $internal_pubkey, string $tweak): int {} +/** + * @param resource $context + * @param string $tweaked_pubkey32 + * @param int $tweaked_pubkey_parity + * @param resource $internal_pubkey + * @param string $tweak32 + * @return int + */ +function secp256k1_xonly_pubkey_tweak_add_check($context, string $tweaked_pubkey32, int $tweaked_pubkey_parity, $internal_pubkey, string $tweak32): int {} /** - * Parse a Schnorr signature. - * - * Returns: 1 when the signature could be parsed, 0 otherwise. - * Args: ctx: a secp256k1 context object - * Out: sig: pointer to a signature object - * In: in64: pointer to the 64-byte signature to be parsed - * - * The signature is serialized in the form R||s, where R is a 32-byte public - * key (x-coordinate only; the y-coordinate is considered to be the unique - * y-coordinate satisfying the curve equation that is a quadratic residue) - * and s is a 32-byte big-endian scalar. - * - * After the call, sig will always be initialized. If parsing failed or the - * encoded numbers are out of range, signature validation with it is - * guaranteed to fail for every message and public key. * @param resource $context - * @param resource|null $sigout - * @param string $sigin + * @param resource|null $keypair + * @param string $seckey * @return int */ -function secp256k1_schnorrsig_parse($context, &$sigout, string $sigin): int {} +function secp256k1_keypair_create($context, &$keypair, string $seckey): int {} +/** + * @param resource $context + * @param string|null $seckey + * @param resource $keypair + * @return int + */ +function secp256k1_keypair_sec($context, ?string &$seckey, $keypair): int {} +/** + * @param resource $context + * @param resource|null $pubkey + * @param resource $keypair + * @return int + */ +function secp256k1_keypair_pub($context, &$pubkey, $keypair): int {} +/** + * @param resource $context + * @param resource|null $pubkey + * @param int|null $pk_parity + * @param resource $keypair + * @return int + */ +function secp256k1_keypair_xonly_pub($context, &$pubkey, ?int &$pk_parity, $keypair): int {} +/** + * @param resource $context + * @param resource $keypair + * @param string $tweak32 + * @return int + */ +function secp256k1_keypair_xonly_tweak_add($context, &$keypair, string $tweak32): int {} /** * Create a Schnorr signature. * @@ -442,14 +478,14 @@ function secp256k1_schnorrsig_parse($context, &$sigout, string $sigin): int {} * noncefp: pointer to a nonce generation function. If NULL, secp256k1_nonce_function_bipschnorr is used * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL) * @param resource $context - * @param resource|null $ecdsaSignatureOut + * @param resource|null $sig64 * @param string $msg32 - * @param string $secretKey + * @param resource $keypair * @param callable|null $noncefp * @param $ndata * @return int */ -function secp256k1_schnorrsig_sign($context, &$ecdsaSignatureOut, string $msg32, string $secretKey, ?callable $noncefp, $ndata): int {} +function secp256k1_schnorrsig_sign($context, &$sig64, string $msg32, $keypair, ?callable $noncefp, $ndata): int {} /** * Verify a Schnorr signature. * @@ -460,44 +496,19 @@ function secp256k1_schnorrsig_sign($context, &$ecdsaSignatureOut, string $msg32, * msg32: the 32-byte message being verified (cannot be NULL) * pubkey: pointer to a public key to verify with (cannot be NULL) * @param resource $context - * @param resource $schnorrsig + * @param string $sig64 * @param string $msg32 * @param resource $pubkey * @return int */ -function secp256k1_schnorrsig_verify($context, $schnorrsig, string $msg32, $pubkey): int {} +function secp256k1_schnorrsig_verify($context, string $sig64, string $msg32, $pubkey): int {} /** - * Verifies a set of Schnorr signatures. - * - * Returns 1 if all succeeded, 0 otherwise. In particular, returns 1 if n_sigs is 0. - * - * Args: ctx: a secp256k1 context object, initialized for verification. - * scratch: scratch space used for the multiexponentiation - * In: sig: array of signatures, or NULL if there are no signatures - * msg32: array of messages, or NULL if there are no signatures - * pk: array of public keys, or NULL if there are no signatures - * n_sigs: number of signatures in above arrays. Must be smaller than - * 2^31 and smaller than half the maximum size_t value. Must be 0 - * if above arrays are NULL. - * @param resource $context - * @param resource $scratch - * @param array $pubkeys - * @param array $msg32s - * @param array $sigs - * @param int $numsigs - * @return int - */ -function secp256k1_schnorrsig_verify_batch($context, $scratch, array $pubkeys, array $msg32s, array $sigs, int $numsigs): int {} -/** - * An implementation of the nonce generation function as defined in BIP-schnorr. - * If a data pointer is passed, it is assumed to be a pointer to 32 bytes of - * extra entropy. * @param string|null $nonce32 * @param string $msg32 * @param string $key32 - * @param string|null $algo16 + * @param string $xonly_pk32 + * @param string $algo16 * @param $data - * @param int $attempt * @return int */ -function secp256k1_nonce_function_bipschnorr(?string &$nonce32, string $msg32, string $key32, ?string $algo16, $data, int $attempt): int {} \ No newline at end of file +function secp256k1_nonce_function_bip340(?string &$nonce32, string $msg32, string $key32, string $xonly_pk32, string $algo16, $data): int {} \ No newline at end of file diff --git a/travis/phpqa/Dockerfile b/travis/phpqa/Dockerfile index 42159f65..4378888f 100644 --- a/travis/phpqa/Dockerfile +++ b/travis/phpqa/Dockerfile @@ -6,8 +6,8 @@ ARG BUILD_PHP_SHA256="0d42089729be7b2bb0308cbe189c2782f9cb4b07078c8a235495be5874 ARG BUILD_CHECK_SIGNATURE=true ARG BUILD_CUSTOM_URL='' ARG BUILD_REPO_URL='' -ARG BUILD_SECP256K1_REPO="https://github.com/jonasnick/secp256k1.git" -ARG BUILD_SECP256K1_COMMIT="a228e2f54d64692230ccb2937b12dd746c5157ed" +ARG BUILD_SECP256K1_REPO="https://github.com/bitcoin-core/secp256k1.git" +ARG BUILD_SECP256K1_COMMIT="efad3506a8937162e8010f5839fdf3771dfcf516" ENV PHPIZE_DEPS \ autoconf \ @@ -27,7 +27,7 @@ ENV PHP_INI_DIR /usr/local/etc/php ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2" ENV PHP_CPPFLAGS="$PHP_CFLAGS" ENV PHP_LDFLAGS="-Wl,-O1 -Wl,--hash-style=both -pie" -ENV SECP256K1_CONFIGURE_FLAGS="--enable-benchmark=no --enable-tests=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-schnorrsig" +ENV SECP256K1_CONFIGURE_FLAGS="--enable-benchmark=no --enable-tests=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-extrakeys --enable-module-schnorrsig" ENV GPG_KEYS="$BUILD_GPG_KEYS" ENV PHP_VERSION="$BUILD_PHP_VERSION" ENV PHP_URL="https://secure.php.net/get/php-$PHP_VERSION.tar.xz/from/this/mirror" diff --git a/travis/phpqa/scripts/coverage.sh b/travis/phpqa/scripts/coverage.sh index 13462780..e620508c 100755 --- a/travis/phpqa/scripts/coverage.sh +++ b/travis/phpqa/scripts/coverage.sh @@ -19,6 +19,7 @@ rm configure && ./buildconf --force --with-module-ecdh \ --with-module-recovery \ --with-module-schnorrsig \ + --with-module-extrakeys \ --with-libdir="lib/$debMultiarch" \ $PHP_EXTRA_CONFIGURE_ARGS \ && make -j "$(nproc)" \ diff --git a/travis/phpqa/scripts/valgrind.sh b/travis/phpqa/scripts/valgrind.sh index b5d385ef..7f86fc00 100755 --- a/travis/phpqa/scripts/valgrind.sh +++ b/travis/phpqa/scripts/valgrind.sh @@ -18,6 +18,7 @@ rm configure && ./buildconf --force --with-module-ecdh \ --with-module-recovery \ --with-module-schnorrsig \ + --with-module-extrakeys \ --with-libdir="lib/$debMultiarch" \ $PHP_EXTRA_CONFIGURE_ARGS \ && make -j "$(nproc)" \