Skip to content

Commit 95b893e

Browse files
committed
secp256k1_schnorrsig_pubkey_x: final tests of these functions
1 parent 346382e commit 95b893e

12 files changed

Lines changed: 312 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
secp256k1_nonce_function_bipschnorr returns 0 if attempt != 0
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$output = '';
12+
$msg32 = str_repeat('A', 32);
13+
$key32 = str_repeat('Z', 32);
14+
$algo = NULL;
15+
16+
$result = secp256k1_nonce_function_bipschnorr($output, $msg32, $key32, $_algo=null, $_data=null, $_attempt=0);
17+
echo $result . PHP_EOL;
18+
echo unpack("H*", $output)[1] . PHP_EOL;
19+
20+
$result = secp256k1_nonce_function_bipschnorr($output, $msg32, $key32, $_algo=null, $_data=null, $_attempt=1);
21+
echo $result . PHP_EOL;
22+
23+
?>
24+
--EXPECT--
25+
1
26+
a0b9a53702d507e80caf8ff0a1b5803f47a26e1f5a4d5143aabb29705ada87ed
27+
0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_create returns false if parameter parsing fails
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
12+
13+
$result = secp256k1_schnorrsig_pubkey_create();
14+
echo $result . PHP_EOL;
15+
16+
?>
17+
--EXPECT--
18+
secp256k1_schnorrsig_pubkey_create() expects exactly 3 parameters, 0 given
19+
0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_create returns 0 if seckey isn't valid
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
12+
13+
$secKeyOrder = pack("H*", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
14+
15+
$pub = null;
16+
$result = secp256k1_schnorrsig_pubkey_create($context, $pub, $secKeyOrder);
17+
echo $result . PHP_EOL;
18+
19+
?>
20+
--EXPECT--
21+
0
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_create throws an exception if seckey is incorrect size
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
12+
13+
$chars31 = str_repeat("A", 31);
14+
$chars33 = str_repeat("A", 33);
15+
$chars0 = "";
16+
17+
$pub = null;
18+
try {
19+
$result = secp256k1_schnorrsig_pubkey_create($context, $pub, $chars31);
20+
} catch (\Exception $e) {
21+
echo $e->getMessage() . PHP_EOL;
22+
}
23+
24+
try {
25+
$result = secp256k1_schnorrsig_pubkey_create($context, $pub, $chars33);
26+
} catch (\Exception $e) {
27+
echo $e->getMessage() . PHP_EOL;
28+
}
29+
30+
try {
31+
$result = secp256k1_schnorrsig_pubkey_create($context, $pub, $chars0);
32+
} catch (\Exception $e) {
33+
echo $e->getMessage() . PHP_EOL;
34+
}
35+
36+
?>
37+
--EXPECT--
38+
secp256k1_schnorrsig_pubkey_create(): Parameter 2 should be 32 bytes
39+
secp256k1_schnorrsig_pubkey_create(): Parameter 2 should be 32 bytes
40+
secp256k1_schnorrsig_pubkey_create(): Parameter 2 should be 32 bytes
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_create errors if context is wrong resource type
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
?>
7+
--FILE--
8+
<?php
9+
10+
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
11+
12+
$key = str_repeat("A", 32);
13+
$keyOut = null;
14+
$context = tmpfile();
15+
$result = secp256k1_schnorrsig_pubkey_create($context, $keyOut, $key);
16+
echo $result . PHP_EOL;
17+
18+
?>
19+
--EXPECT--
20+
secp256k1_schnorrsig_pubkey_create(): supplied resource is not a valid secp256k1_context resource
21+
0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_parse returns false if parameter parsing fails
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
12+
13+
$result = secp256k1_schnorrsig_pubkey_parse();
14+
echo $result . PHP_EOL;
15+
16+
?>
17+
--EXPECT--
18+
secp256k1_schnorrsig_pubkey_parse() expects exactly 3 parameters, 0 given
19+
0
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_parse throws an exception if seckey is incorrect size
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
12+
13+
$chars31 = str_repeat("A", 31);
14+
$chars33 = str_repeat("A", 33);
15+
$chars0 = "";
16+
17+
$pub = null;
18+
try {
19+
$result = secp256k1_schnorrsig_pubkey_parse($context, $pub, $chars31);
20+
} catch (\Exception $e) {
21+
echo $e->getMessage() . PHP_EOL;
22+
}
23+
24+
try {
25+
$result = secp256k1_schnorrsig_pubkey_parse($context, $pub, $chars33);
26+
} catch (\Exception $e) {
27+
echo $e->getMessage() . PHP_EOL;
28+
}
29+
30+
try {
31+
$result = secp256k1_schnorrsig_pubkey_parse($context, $pub, $chars0);
32+
} catch (\Exception $e) {
33+
echo $e->getMessage() . PHP_EOL;
34+
}
35+
36+
?>
37+
--EXPECT--
38+
secp256k1_schnorrsig_pubkey_parse(): Parameter 3 should be 32 bytes
39+
secp256k1_schnorrsig_pubkey_parse(): Parameter 3 should be 32 bytes
40+
secp256k1_schnorrsig_pubkey_parse(): Parameter 3 should be 32 bytes
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_parse errors if context is wrong resource type
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
12+
13+
$key = str_repeat("A", 32);
14+
$keyOut = null;
15+
$context = tmpfile();
16+
$result = secp256k1_schnorrsig_pubkey_parse($context, $keyOut, $key);
17+
echo $result . PHP_EOL;
18+
19+
?>
20+
--EXPECT--
21+
secp256k1_schnorrsig_pubkey_parse(): supplied resource is not a valid secp256k1_context resource
22+
0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_parse rejects invalid keys
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
12+
13+
$pubKeyIn = pack("H*", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
14+
15+
$pubKey = null;
16+
$pubKeyOut = '';
17+
$result = secp256k1_schnorrsig_pubkey_parse($ctx, $pubKey, $pubKeyIn);
18+
echo $result . PHP_EOL;
19+
20+
?>
21+
--EXPECT--
22+
0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
secp256k1_schnorrsig_pubkey_serialize returns false if parameter parsing fails
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
6+
if (!function_exists("secp256k1_schnorrsig_verify")) print "skip no schnorrsig support";
7+
?>
8+
--FILE--
9+
<?php
10+
11+
set_error_handler(function($code, $str) { echo $str . PHP_EOL; });
12+
13+
$result = secp256k1_schnorrsig_pubkey_serialize();
14+
echo $result . PHP_EOL;
15+
16+
?>
17+
--EXPECT--
18+
secp256k1_schnorrsig_pubkey_serialize() expects exactly 3 parameters, 0 given
19+
0

0 commit comments

Comments
 (0)