Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schnorrsig revised #165

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 11 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
17 changes: 16 additions & 1 deletion secp256k1/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions secp256k1/php_secp256k1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 */
Loading