Skip to content

Commit

Permalink
port further upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
afk11 committed Nov 21, 2019
1 parent 785c869 commit 2ed4936
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion secp256k1/php_secp256k1.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ PHP_FUNCTION(secp256k1_xonly_pubkey_from_pubkey);
PHP_FUNCTION(secp256k1_xonly_pubkey_to_pubkey);
PHP_FUNCTION(secp256k1_xonly_privkey_tweak_add);
PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add);
PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_verify);
PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_test);

/* Recovery module */
#ifdef SECP256K1_MODULE_RECOVERY
Expand Down
14 changes: 7 additions & 7 deletions secp256k1/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_add, I
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_verify, IS_LONG, NULL, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_test, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_verify, IS_LONG, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_xonly_pubkey_tweak_test, IS_LONG, 0)
#endif
ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0)
ZEND_ARG_TYPE_INFO(0, outputPubKey, IS_RESOURCE, 0)
Expand Down Expand Up @@ -659,7 +659,7 @@ const zend_function_entry secp256k1_functions[] = {
PHP_FE(secp256k1_xonly_pubkey_from_pubkey, arginfo_secp256k1_xonly_pubkey_from_pubkey)
PHP_FE(secp256k1_xonly_privkey_tweak_add, arginfo_secp256k1_xonly_privkey_tweak_add)
PHP_FE(secp256k1_xonly_pubkey_tweak_add, arginfo_secp256k1_xonly_pubkey_tweak_add)
PHP_FE(secp256k1_xonly_pubkey_tweak_verify, arginfo_secp256k1_xonly_pubkey_tweak_verify)
PHP_FE(secp256k1_xonly_pubkey_tweak_test, arginfo_secp256k1_xonly_pubkey_tweak_test)
// secp256k1_recovery.h
#ifdef SECP256K1_MODULE_RECOVERY
PHP_FE(secp256k1_ecdsa_recoverable_signature_parse_compact, arginfo_secp256k1_ecdsa_recoverable_signature_parse_compact)
Expand Down Expand Up @@ -2019,9 +2019,9 @@ PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_add)
}
/* }}} */

/* {{{ proto int secp256k1_xonly_pubkey_tweak_verify(resource context, resource output_pubkey, resource internal_pubkey, string tweak32)
/* {{{ proto int secp256k1_xonly_pubkey_tweak_test(resource context, resource output_pubkey, bool hasSquareY, resource internal_pubkey, string tweak32)
* Tweak a public key by adding tweak times the generator to it. */
PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_verify)
PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_test)
{
zval *zCtx, *zOutputPubKey, *zInternalPubKey;
secp256k1_context *ctx;
Expand All @@ -2043,11 +2043,11 @@ PHP_FUNCTION(secp256k1_xonly_pubkey_tweak_verify)
}

if (zTweak32->len != SECRETKEY_LENGTH) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "secp256k1_xonly_pubkey_tweak_verify(): Parameter 4 should be 32 bytes");
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "secp256k1_xonly_pubkey_tweak_test(): Parameter 5 should be 32 bytes");
return;
}

result = secp256k1_xonly_pubkey_tweak_verify(ctx, output_pubkey, (int)has_square_y, internal_pubkey, (unsigned char *)zTweak32->val);
result = secp256k1_xonly_pubkey_tweak_test(ctx, output_pubkey, (int)has_square_y, internal_pubkey, (unsigned char *)zTweak32->val);

RETURN_LONG(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ $privKey = str_repeat("\x41", 32);

$pubkey = null;
$xonlyPubKey = null;
$sign = null;
$hasSquareY = null;
$pubkey2 = null;
$result = secp256k1_ec_pubkey_create($ctx, $pubkey, $privKey);
echo $result . PHP_EOL;
echo get_resource_type($pubkey) . PHP_EOL;

$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $sign, $pubkey);
$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $hasSquareY, $pubkey);
echo $result . PHP_EOL;

echo "sign: $sign\n";
echo "hasSquareY: $hasSquareY\n";

$serialized = null;
$result = secp256k1_xonly_pubkey_serialize($ctx, $serialized, $xonlyPubKey);
Expand All @@ -36,6 +36,6 @@ echo bin2hex($serialized) . PHP_EOL;
1
secp256k1_pubkey
1
sign: 1
hasSquareY: 0
1
eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ $privKey = str_repeat("\x42", 32);

$pubkey = null;
$xonlyPubKey = null;
$sign = null;
$hasSquareY = null;
$pubkey2 = null;
$result = secp256k1_ec_pubkey_create($ctx, $pubkey, $privKey);
echo $result . PHP_EOL;
echo get_resource_type($pubkey) . PHP_EOL;

$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $sign, $pubkey);
$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $hasSquareY, $pubkey);
echo $result . PHP_EOL;

echo "sign: $sign\n";
echo "hasSquareY: $hasSquareY\n";

$serialized = null;
$result = secp256k1_xonly_pubkey_serialize($ctx, $serialized, $xonlyPubKey);
Expand All @@ -36,6 +36,6 @@ echo bin2hex($serialized) . PHP_EOL;
1
secp256k1_pubkey
1
sign: 0
hasSquareY: 1
1
24653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ $privKey = str_repeat("\x41", 32);

$pubkey = null;
$xonlyPubKey = null;
$sign = null;
$hasSquareY = null;
$pubkey2 = null;
$result = secp256k1_ec_pubkey_create($ctx, $pubkey, $privKey);
echo $result . PHP_EOL;
echo get_resource_type($pubkey) . PHP_EOL;

$badCtx = tmpfile();
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
$result = secp256k1_xonly_pubkey_from_pubkey($badCtx, $xonlyPubKey, $sign, $pubkey);
$result = secp256k1_xonly_pubkey_from_pubkey($badCtx, $xonlyPubKey, $hasSquareY, $pubkey);
echo $result . PHP_EOL;

?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $privKey = str_repeat("\x42", 32);

$badPubKey = tmpfile();
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $sign, $badPubKey);
$result = secp256k1_xonly_pubkey_from_pubkey($ctx, $xonlyPubKey, $hasSquareY, $badPubKey);
echo $result . PHP_EOL;

?>
Expand Down
6 changes: 3 additions & 3 deletions secp256k1/tests/secp256k1_xonly_pubkey_tweak_verify.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
secp256k1_xonly_pubkey_tweak_verify works
secp256k1_xonly_pubkey_tweak_test works
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
Expand All @@ -25,10 +25,10 @@ $hasSquareY = null;
$result = secp256k1_xonly_pubkey_tweak_add($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak);
echo $result . PHP_EOL;

$result = secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweakInvalid);
$result = secp256k1_xonly_pubkey_tweak_test($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweakInvalid);
echo $result.PHP_EOL;

$result = secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak);
$result = secp256k1_xonly_pubkey_tweak_test($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak);
echo $result.PHP_EOL;

?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
secp256k1_xonly_pubkey_tweak_verify errors if parameter parsing fails
secp256k1_xonly_pubkey_tweak_test errors if parameter parsing fails
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
Expand All @@ -9,10 +9,10 @@ if (!extension_loaded("secp256k1")) print "skip extension not loaded";

set_error_handler(function($code, $str) { echo $str . PHP_EOL; });

$result = secp256k1_xonly_pubkey_tweak_verify();
$result = secp256k1_xonly_pubkey_tweak_test();
echo $result . PHP_EOL;

?>
--EXPECT--
secp256k1_xonly_pubkey_tweak_verify() expects exactly 5 parameters, 0 given
secp256k1_xonly_pubkey_tweak_test() expects exactly 5 parameters, 0 given
0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
secp256k1_xonly_pubkey_tweak_verify errors if context is wrong resource type
secp256k1_xonly_pubkey_tweak_test errors if context is wrong resource type
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
Expand Down Expand Up @@ -27,13 +27,13 @@ echo $result . PHP_EOL;
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });

$badCtx = tmpfile();
$result = secp256k1_xonly_pubkey_tweak_verify($badCtx, $tweakedPub, $hasSquareY, $pubkey1, $tweak);
$result = secp256k1_xonly_pubkey_tweak_test($badCtx, $tweakedPub, $hasSquareY, $pubkey1, $tweak);
echo $result.PHP_EOL;

?>
--EXPECT--
1
secp256k1_xonly_pubkey
1
secp256k1_xonly_pubkey_tweak_verify(): supplied resource is not a valid secp256k1_context resource
secp256k1_xonly_pubkey_tweak_test(): supplied resource is not a valid secp256k1_context resource
0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
secp256k1_xonly_pubkey_tweak_verify errors if output_pubkey is wrong type
secp256k1_xonly_pubkey_tweak_test errors if output_pubkey is wrong type
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
Expand All @@ -26,13 +26,13 @@ echo $result . PHP_EOL;

set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
$badTweakedPub = tmpfile();
$result = secp256k1_xonly_pubkey_tweak_verify($ctx, $badTweakedPub, $hasSquareY, $pubkey1, $tweak);
$result = secp256k1_xonly_pubkey_tweak_test($ctx, $badTweakedPub, $hasSquareY, $pubkey1, $tweak);
echo $result.PHP_EOL;

?>
--EXPECT--
1
secp256k1_xonly_pubkey
1
secp256k1_xonly_pubkey_tweak_verify(): supplied resource is not a valid secp256k1_xonly_pubkey resource
secp256k1_xonly_pubkey_tweak_test(): supplied resource is not a valid secp256k1_xonly_pubkey resource
0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
secp256k1_xonly_pubkey_tweak_verify errors if internal pubkey is wrong type
secp256k1_xonly_pubkey_tweak_test errors if internal pubkey is wrong type
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
Expand All @@ -26,13 +26,13 @@ echo $result . PHP_EOL;

$badInternal = tmpfile();
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
$result = secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $hasSquareY, $badInternal, $tweak);
$result = secp256k1_xonly_pubkey_tweak_test($ctx, $tweakedPub, $hasSquareY, $badInternal, $tweak);
echo $result.PHP_EOL;

?>
--EXPECT--
1
secp256k1_xonly_pubkey
1
secp256k1_xonly_pubkey_tweak_verify(): supplied resource is not a valid secp256k1_xonly_pubkey resource
secp256k1_xonly_pubkey_tweak_test(): supplied resource is not a valid secp256k1_xonly_pubkey resource
0
16 changes: 8 additions & 8 deletions secp256k1/tests/secp256k1_xonly_pubkey_tweak_verify_error5.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
secp256k1_xonly_pubkey_tweak_verify throws if tweak is not 32 bytes
secp256k1_xonly_pubkey_tweak_test throws if tweak is not 32 bytes
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
Expand All @@ -25,10 +25,10 @@ echo get_resource_type($pubkey1) . PHP_EOL;
$hasSquareY = null;
$result = secp256k1_xonly_pubkey_tweak_add($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak);
echo $result . PHP_EOL;
$expecting = "secp256k1_xonly_pubkey_tweak_verify(): Parameter 4 should be 32 bytes";
$expecting = "secp256k1_xonly_pubkey_tweak_test(): Parameter 5 should be 32 bytes";

try {
secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweakEmpty);
secp256k1_xonly_pubkey_tweak_test($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweakEmpty);
} catch (\Exception $e) {
if ($e->getMessage() !== $expecting) {
echo "ERROR\n";
Expand All @@ -37,7 +37,7 @@ try {
}

try {
secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak31);
secp256k1_xonly_pubkey_tweak_test($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak31);
} catch (\Exception $e) {
if ($e->getMessage() !== $expecting) {
echo "ERROR\n";
Expand All @@ -46,7 +46,7 @@ try {
}

try {
secp256k1_xonly_pubkey_tweak_verify($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak33);
secp256k1_xonly_pubkey_tweak_test($ctx, $tweakedPub, $hasSquareY, $pubkey1, $tweak33);
} catch (\Exception $e) {
if ($e->getMessage() !== $expecting) {
echo "ERROR\n";
Expand All @@ -58,6 +58,6 @@ try {
1
secp256k1_xonly_pubkey
1
secp256k1_xonly_pubkey_tweak_verify(): Parameter 4 should be 32 bytes
secp256k1_xonly_pubkey_tweak_verify(): Parameter 4 should be 32 bytes
secp256k1_xonly_pubkey_tweak_verify(): Parameter 4 should be 32 bytes
secp256k1_xonly_pubkey_tweak_test(): Parameter 5 should be 32 bytes
secp256k1_xonly_pubkey_tweak_test(): Parameter 5 should be 32 bytes
secp256k1_xonly_pubkey_tweak_test(): Parameter 5 should be 32 bytes

0 comments on commit 2ed4936

Please sign in to comment.