-
Notifications
You must be signed in to change notification settings - Fork 37
/
secp256k1_ec_pubkey_tweak_mul_basic.phpt
114 lines (93 loc) · 3.25 KB
/
secp256k1_ec_pubkey_tweak_mul_basic.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
--TEST--
secp256k1_ec_pubkey_tweak_mul works
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
?>
--FILE--
<?php
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
$secKeyOne = str_repeat("\x00", 31) . "\x01";
$secKeyTwo = str_repeat("\x00", 31) . "\x02";
$secKeyFour = str_repeat("\x00", 31) . "\x02";
$secKeyEight = str_repeat("\x00", 31) . "\x08";
$secKeySixteen = str_repeat("\x00", 31) . "\x0f";
/** @var resource $pubKey */
$pubKey = null;
$serKey = '';
$cmpKey = null;
$serCmp = '';
$result = secp256k1_ec_pubkey_create($context, $pubKey, $secKeyOne);
echo $result . PHP_EOL;
// 1
$result = secp256k1_ec_pubkey_tweak_mul($context, $pubKey, $secKeyTwo);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_create($context, $cmpKey, $secKeyTwo);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serKey, $pubKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serCmp, $cmpKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
// 2
$result = secp256k1_ec_pubkey_tweak_mul($context, $pubKey, $secKeyTwo);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_create($context, $cmpKey, $secKeyFour);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serKey, $pubKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serCmp, $cmpKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
// 4
$result = secp256k1_ec_pubkey_tweak_mul($context, $pubKey, $secKeyTwo);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_create($context, $cmpKey, $secKeyEight);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serKey, $pubKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serCmp, $cmpKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
// 8
$result = secp256k1_ec_pubkey_tweak_mul($context, $pubKey, $secKeyTwo);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_create($context, $cmpKey, $secKeySixteen);
echo $result . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serKey, $pubKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
$result = secp256k1_ec_pubkey_serialize($context, $serCmp, $cmpKey, SECP256K1_EC_COMPRESSED);
echo $result . PHP_EOL;
echo unpack("H*", $serKey)[1] . PHP_EOL;
// 16
?>
--EXPECT--
1
1
1
1
02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5
1
02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5
1
1
1
02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13
1
02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13
1
1
1
022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01
1
022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01
1
1
1
03e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a
1
03e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a