Remove init_and_check_sodium from crypto/common.h
This removes the last implicit dependency on libsodium from libzcashconsensus. As of zcash/zcash#4893 we no longer depend on libsodium for Ed25519 signature verification.
This commit is contained in:
parent
c4ea423827
commit
6c280abfac
|
@ -13,7 +13,6 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sodium.h"
|
||||
#include "compat/endian.h"
|
||||
|
||||
#if defined(NDEBUG)
|
||||
|
@ -85,42 +84,4 @@ void static inline WriteBE64(unsigned char* ptr, uint64_t x)
|
|||
memcpy(ptr, (char*)&v, 8);
|
||||
}
|
||||
|
||||
int inline init_and_check_sodium()
|
||||
{
|
||||
if (sodium_init() == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// What follows is a runtime test that ensures the version of libsodium
|
||||
// we're linked against checks that signatures are canonical (s < L).
|
||||
const unsigned char message[1] = { 0 };
|
||||
|
||||
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
|
||||
unsigned char sk[crypto_sign_SECRETKEYBYTES];
|
||||
unsigned char sig[crypto_sign_BYTES];
|
||||
|
||||
crypto_sign_keypair(pk, sk);
|
||||
crypto_sign_detached(sig, NULL, message, sizeof(message), sk);
|
||||
|
||||
assert(crypto_sign_verify_detached(sig, message, sizeof(message), pk) == 0);
|
||||
|
||||
// Copied from libsodium/crypto_sign/ed25519/ref10/open.c
|
||||
static const unsigned char L[32] =
|
||||
{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
|
||||
0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
|
||||
|
||||
// Add L to S, which starts at sig[32].
|
||||
unsigned int s = 0;
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
s = sig[32 + i] + L[i] + (s >> 8);
|
||||
sig[32 + i] = s & 0xff;
|
||||
}
|
||||
|
||||
assert(crypto_sign_verify_detached(sig, message, sizeof(message), pk) != 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // BITCOIN_CRYPTO_COMMON_H
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "gmock/gmock.h"
|
||||
#include "crypto/common.h"
|
||||
#include "key.h"
|
||||
#include "pubkey.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "librustzcash.h"
|
||||
#include <sodium.h>
|
||||
|
||||
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
||||
|
||||
|
@ -16,7 +16,7 @@ struct ECCryptoClosure
|
|||
ECCryptoClosure instance_of_eccryptoclosure;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
assert(init_and_check_sodium() != -1);
|
||||
assert(sodium_init() != -1);
|
||||
ECC_Start();
|
||||
|
||||
fs::path sapling_spend = ZC_GetParamsDir() / "sapling-spend.params";
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#endif
|
||||
|
||||
#include "init.h"
|
||||
#include "crypto/common.h"
|
||||
#include "addrman.h"
|
||||
#include "amount.h"
|
||||
#include "checkpoints.h"
|
||||
|
@ -59,6 +58,7 @@
|
|||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/interprocess/sync/file_lock.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <sodium.h>
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
#include "zmq/zmqnotificationinterface.h"
|
||||
|
@ -1158,7 +1158,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
|
||||
|
||||
// Initialize libsodium
|
||||
if (init_and_check_sodium() == -1) {
|
||||
if (sodium_init() == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include "test_bitcoin.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
|
||||
#include "chainparams.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "consensus/validation.h"
|
||||
|
@ -28,6 +26,7 @@
|
|||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <sodium.h>
|
||||
|
||||
#include "librustzcash.h"
|
||||
|
||||
|
@ -70,7 +69,7 @@ JoinSplitTestingSetup::~JoinSplitTestingSetup()
|
|||
|
||||
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
|
||||
{
|
||||
assert(init_and_check_sodium() != -1);
|
||||
assert(sodium_init() != -1);
|
||||
ECC_Start();
|
||||
SetupEnvironment();
|
||||
SetupNetworking();
|
||||
|
|
Loading…
Reference in New Issue