-
Notifications
You must be signed in to change notification settings - Fork 37
/
secp256k1_ec_privkey_tweak_add_basic.phpt
58 lines (49 loc) · 1.62 KB
/
secp256k1_ec_privkey_tweak_add_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
--TEST--
secp256k1_ec_privkey_tweak_add works
--SKIPIF--
<?php
if (!extension_loaded("secp256k1")) print "skip extension not loaded";
?>
--FILE--
<?php
$context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
$secKeyTweaked = "";
$secKeyZero = str_repeat("\x00", 32);
$secKeyTwo = str_repeat("\x00", 31) . "\x02";
$secKeyOne = str_repeat("\x00", 31) . "\x01";
$secKeyOrderMinusOne = pack("H*", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140");
// (n-1) + 0 = (n-1)
$key = $secKeyOrderMinusOne;
$result = secp256k1_ec_privkey_tweak_add($context, $key, $secKeyZero);
echo $result . PHP_EOL;
echo unpack("H*", $key)[1] . PHP_EOL;
// (n-j) + j = n, bad
$key = $secKeyOrderMinusOne;
$result = secp256k1_ec_privkey_tweak_add($context, $key, $secKeyOne);
echo $result . PHP_EOL;
echo unpack("H*", $key)[1] . PHP_EOL;
$result = secp256k1_ec_seckey_verify($context, $key);
echo $result . PHP_EOL;
// (n-j) + j + 1 = n + 1 mod n = 1, fine!
$key = $secKeyOrderMinusOne;
$result = secp256k1_ec_privkey_tweak_add($context, $key, $secKeyTwo);
echo $result . PHP_EOL;
echo unpack("H*", $key)[1] . PHP_EOL;
$result = secp256k1_ec_seckey_verify($context, $key);
echo $result . PHP_EOL;
// 1 + 2 = 3
$result = secp256k1_ec_privkey_tweak_add($context, $key, $secKeyTwo);
echo $result . PHP_EOL;
echo unpack("H*", $key)[1] . PHP_EOL;
?>
--EXPECT--
1
fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140
0
0000000000000000000000000000000000000000000000000000000000000000
0
1
0000000000000000000000000000000000000000000000000000000000000001
1
1
0000000000000000000000000000000000000000000000000000000000000003