1
- #include " test/test_pivx.h"
2
-
3
- #include " uint256.h"
4
- #include " utilstrencodings.h"
1
+ // Copyright (c) 2021 The PIVX Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or https://www.opensource.org/licenses/mit-license.php .
5
4
6
- #include < sodium.h>
5
+ #include " test/test_pivx.h"
6
+ #include " sapling/sodium_sanity.h"
7
7
#include < boost/test/unit_test.hpp>
8
8
9
9
BOOST_FIXTURE_TEST_SUITE (libsodium_consensus_tests, TestingSetup)
10
10
11
- void TestLibsodiumEd25519SignatureVerification(
12
- const std::string &scope,
13
- const std::string &msg,
14
- std::vector<unsigned char > pubkey,
15
- std::vector<unsigned char > sig)
16
- {
17
- BOOST_CHECK_EQUAL (
18
- crypto_sign_verify_detached (
19
- sig.data (),
20
- (const unsigned char *)msg.data (), msg.size (),
21
- pubkey.data ()),
22
- 0 );
23
- }
24
-
25
11
BOOST_AUTO_TEST_CASE(LibsodiumPubkeyValidation)
26
12
{
27
- // libsodium <= 1.0.15 accepts valid signatures for a non-zero pubkey with
28
- // small order; this is currently part of our consensus rules.
29
- // libsodium >= 1.0.16 rejects all pubkeys with small order.
30
- //
31
- // These test vectors were generated by finding pairs of points (A, P) both
32
- // in the eight-torsion subgroup such that R = B + P and R = [1] B - [k] A
33
- // (where SHA512(bytes(R) || bytes(A) || message) represents k in
34
- // little-endian order, as in Ed25519).
35
- TestLibsodiumEd25519SignatureVerification (
36
- " Test vector 1" ,
37
- " zcash ed25519 libsodium compatibility" ,
38
- ParseHex (" 0100000000000000000000000000000000000000000000000000000000000000" ),
39
- ParseHex (" 58666666666666666666666666666666666666666666666666666666666666660100000000000000000000000000000000000000000000000000000000000000" ));
40
- TestLibsodiumEd25519SignatureVerification (
41
- " Test vector 2" ,
42
- " zcash ed25519 libsodium compatibility" ,
43
- ParseHex (" 0000000000000000000000000000000000000000000000000000000000000080" ),
44
- ParseHex (" 58666666666666666666666666666666666666666666666666666666666666660100000000000000000000000000000000000000000000000000000000000000" ));
45
- TestLibsodiumEd25519SignatureVerification (
46
- " Test vector 3" ,
47
- " zcash ed25519 libsodium compatibility" ,
48
- ParseHex (" 26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85" ),
49
- ParseHex (" da99e28ba529cdde35a25fba9059e78ecaee239f99755b9b1aa4f65df00803e20100000000000000000000000000000000000000000000000000000000000000" ));
50
- TestLibsodiumEd25519SignatureVerification (
51
- " Test vector 4" ,
52
- " zcash ed25519 libsodium compatibility" ,
53
- ParseHex (" c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a" ),
54
- ParseHex (" 95999999999999999999999999999999999999999999999999999999999999990100000000000000000000000000000000000000000000000000000000000000" ));
55
- TestLibsodiumEd25519SignatureVerification (
56
- " Test vector 5" ,
57
- " zcash ed25519 libsodium compatibility" ,
58
- ParseHex (" 26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85" ),
59
- ParseHex (" 13661d745ad63221ca5da0456fa618713511dc60668aa464e55b09a20ff7fc1d0100000000000000000000000000000000000000000000000000000000000000" ));
60
-
61
- // libsodium <= 1.0.15 contains a blocklist of small-order points that R is
62
- // checked against. However, it does not contain all canonical small-order
63
- // points; in particular, it is missing the negative of one of the points.
64
- //
65
- // This test case is the only pair of points (A, R) both in the eight-torsion
66
- // subgroup, that satisfies R = [0] B - [k] A and also evades the blocklist.
67
- TestLibsodiumEd25519SignatureVerification (
68
- " Small order R that is not rejected by libsodium <= 1.0.15" ,
69
- " zcash ed25519 libsodium compatibility" ,
70
- ParseHex (" c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a" ),
71
- ParseHex (" 26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc850000000000000000000000000000000000000000000000000000000000000000" ));
13
+ libsodium_sanity_test ();
72
14
}
73
15
74
16
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments