-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Kerin
committed
Nov 4, 2018
1 parent
f2859f9
commit fa67060
Showing
141 changed files
with
3,718 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--TEST-- | ||
Case where referenced zvals are being modified. Only the provided copy should be modified. | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ||
$mainKey = "0123abcd0123abcd0123abcd0123abcd"; | ||
$secKeyOne = str_repeat("\x00", 31) . "\x01"; | ||
|
||
class Something { | ||
private $key; | ||
public function __construct($key) { | ||
$this->key = $key; | ||
} | ||
public function getKey() { | ||
return $this->key; | ||
} | ||
} | ||
|
||
echo $mainKey . PHP_EOL; | ||
$something = new Something($mainKey); | ||
$copyKey = $something->getKey(); | ||
|
||
$result = secp256k1_ec_privkey_tweak_add($context, $copyKey, $secKeyOne); | ||
echo $result . PHP_EOL; | ||
echo $copyKey . PHP_EOL; | ||
echo $mainKey . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
0123abcd0123abcd0123abcd0123abcd | ||
1 | ||
0123abcd0123abcd0123abcd0123abce | ||
0123abcd0123abcd0123abcd0123abcd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--TEST-- | ||
secp256k1_ec_privkey_tweak_mul case where referenced zvals are being modified. Only the provided copy should be modified. | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ||
|
||
$mainKey = str_repeat("\x00", 31) . "\x08"; | ||
$secKey8 = str_repeat("\x00", 31) . "\x02"; | ||
|
||
class Something { | ||
private $key; | ||
public function __construct($key) { | ||
$this->key = $key; | ||
} | ||
public function getKey() { | ||
return $this->key; | ||
} | ||
} | ||
|
||
echo unpack("H*", $mainKey)[1] . PHP_EOL; | ||
$something = new Something($mainKey); | ||
$copyKey = $something->getKey(); | ||
|
||
$result = secp256k1_ec_privkey_tweak_mul($context, $copyKey, $secKey8); | ||
echo $result . PHP_EOL; | ||
echo unpack("H*", $copyKey)[1] . PHP_EOL; | ||
echo unpack("H*", $mainKey)[1] . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
0000000000000000000000000000000000000000000000000000000000000008 | ||
1 | ||
0000000000000000000000000000000000000000000000000000000000000010 | ||
0000000000000000000000000000000000000000000000000000000000000008 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
ecdsa_signature_parse_der_lax works like secp256k1_ecdsa_signature_parse_der | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
declare(strict_types=1); | ||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN); | ||
$sig = hex2bin("304402207a8e3bdc7c64f31b119a849e8bb39ddbdc0a64abd4cadcc5cfc15d3ec06354ed02204719389aedb16b2dd13552eed546b24350d6e636ac454ea72afc1ffd0cf421b7"); | ||
|
||
// Parse signature using lax DER encoding - not sure if fixture violates any rules | ||
/** @var resource $laxSig */ | ||
$laxSig = null; | ||
$result = ecdsa_signature_parse_der_lax($ctx, $laxSig, $sig); | ||
echo $result . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
ecdsa_signature_parse_der_lax returns null if context is wrong resource type | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$ctx = tmpfile(); | ||
$sig = hex2bin("304402207a8e3bdc7c64f31b119a849e8bb39ddbdc0a64abd4cadcc5cfc15d3ec06354ed02204719389aedb16b2dd13552eed546b24350d6e636ac454ea72afc1ffd0cf421b7"); | ||
|
||
// Parse signature using lax DER encoding | ||
/** @var resource $laxSig */ | ||
$laxSig = null; | ||
$result = ecdsa_signature_parse_der_lax($ctx, $laxSig, $sig); | ||
echo $result . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
ecdsa_signature_parse_der_lax(): supplied resource is not a valid secp256k1_context resource | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
ecdsa_signature_parse_der_lax errors signature is garbage | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx = \secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ||
$sig = \hex2bin("3001024242"); | ||
|
||
// Parse signature using lax DER encoding | ||
$result = ecdsa_signature_parse_der_lax($ctx, $laxSig, $sig); | ||
echo $result . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
ecdsa_signature_parse_der_lax returns false if parameter parsing fails | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$result = ecdsa_signature_parse_der_lax(); | ||
echo $result . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
ecdsa_signature_parse_der_lax() expects exactly 3 parameters, 0 given | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Code coverage for PHP_MINFO_FUNCTION(secp256k1) | ||
--SKIPIF-- | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
--FILE-- | ||
<?php | ||
ob_start(); | ||
phpinfo(INFO_MODULES); | ||
$v = ob_get_clean(); | ||
$r = preg_match('/secp256k1 support .* enabled/', $v); | ||
if ($r !== 1) | ||
var_dump($r); | ||
echo "Done\n"; | ||
?> | ||
--EXPECTF-- | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
secp256k1_context_clone works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
echo get_resource_type($ctx) . "\n"; | ||
|
||
$clone = secp256k1_context_clone($ctx); | ||
echo get_resource_type($clone) . "\n"; | ||
?> | ||
--EXPECT-- | ||
secp256k1_context | ||
secp256k1_context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
secp256k1_context_clone returns false if provided the wrong type | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$handle = tmpfile(); | ||
$result = secp256k1_context_clone($handle); | ||
echo gettype($result) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
secp256k1_context_clone(): supplied resource is not a valid secp256k1_context resource | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
secp256k1_context_clone returns false if missing flags argument | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$ctx1 = secp256k1_context_clone(); | ||
echo gettype($ctx1) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
secp256k1_context_clone() expects exactly 1 parameter, 0 given | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
secp256k1_context_create works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx1 = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
echo get_resource_type($ctx1) . "\n"; | ||
$ctx2 = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); | ||
echo get_resource_type($ctx2) . "\n"; | ||
$ctx3 = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); | ||
echo get_resource_type($ctx3) . "\n"; | ||
?> | ||
--EXPECT-- | ||
secp256k1_context | ||
secp256k1_context | ||
secp256k1_context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
secp256k1_context_create returns false if provided invalid flags | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$ctx1 = secp256k1_context_create(SECP256K1_CONTEXT_SIGN << 2 | (SECP256K1_CONTEXT_VERIFY+2>>1)); | ||
echo gettype($ctx1) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
secp256k1_context_create returns false if missing flags argument | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$ctx1 = secp256k1_context_create(); | ||
echo gettype($ctx1) . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
secp256k1_context_create() expects exactly 1 parameter, 0 given | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--TEST-- | ||
secp256k1_context_destroy works | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); | ||
echo get_resource_type($ctx) . "\n"; | ||
|
||
secp256k1_context_destroy($ctx); | ||
echo get_resource_type($ctx) . "\n"; | ||
?> | ||
--EXPECT-- | ||
secp256k1_context | ||
Unknown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
secp256k1_context_destroy returns false if provided the wrong resource type | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$handle = tmpfile(); | ||
$result = secp256k1_context_destroy($handle); | ||
echo gettype($result) . PHP_EOL; | ||
echo ($result ? "true" : "false") . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
secp256k1_context_destroy(): supplied resource is not a valid secp256k1_context resource | ||
boolean | ||
false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
secp256k1_context_destroy returns false if missing flags argument | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("secp256k1")) print "skip extension not loaded"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); | ||
|
||
$ctx1 = secp256k1_context_destroy(); | ||
echo gettype($ctx1) . PHP_EOL; | ||
echo ($ctx1 ? "true" : "false") . PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
secp256k1_context_destroy() expects exactly 1 parameter, 0 given | ||
boolean | ||
false |
Oops, something went wrong.