From 4751522162a0789359cc3d6e870b73c74336aa2e Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 7 Jul 2016 13:22:14 -0500 Subject: [PATCH 1/3] Changed openssl's RAND_bytes() to sodium's randombytes_buf() --- bitcoin/tx.c | 2 +- daemon/secrets.c | 10 +++------- daemon/wallet.c | 5 ++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index d6c6714d4..b547fbb15 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -497,7 +497,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, tx->output = tal_arr(tx, struct bitcoin_tx_output, tx->output_count); for (i = 0; i < tx->output_count; i++) pull_output(tx, cursor, max, tx->output + i); - + if (flag & SEGREGATED_WITNESS_FLAG) { for (i = 0; i < tx->input_count; i++) pull_witness(tx->input, i, cursor, max); diff --git a/daemon/secrets.c b/daemon/secrets.c index 7e0e23537..9794b9106 100644 --- a/daemon/secrets.c +++ b/daemon/secrets.c @@ -13,11 +13,11 @@ #include #include #include -#include #include #include #include #include +#include struct secret { /* Secret ID of our node; public is dstate->id. */ @@ -147,8 +147,7 @@ static void new_keypair(struct lightningd_state *dstate, struct privkey *privkey, struct pubkey *pubkey) { do { - if (RAND_bytes(privkey->secret, sizeof(privkey->secret)) != 1) - fatal("Could not get random bytes for privkey"); + randombytes_buf(privkey->secret, sizeof(privkey->secret)); } while (!pubkey_from_privkey(dstate->secpctx, privkey, pubkey)); } @@ -158,10 +157,7 @@ void peer_secrets_init(struct peer *peer) new_keypair(peer->dstate, &peer->secrets->commit, &peer->local.commitkey); new_keypair(peer->dstate, &peer->secrets->final, &peer->local.finalkey); - if (RAND_bytes(peer->secrets->revocation_seed.u.u8, - sizeof(peer->secrets->revocation_seed.u.u8)) != 1) - fatal("Could not get random bytes for revocation seed"); - + randombytes_buf(peer->secrets->revocation_seed.u.u8, sizeof(peer->secrets->revocation_seed.u.u8)); shachain_init(&peer->their_preimages); } diff --git a/daemon/wallet.c b/daemon/wallet.c index 795e5011a..c1dfd1b5a 100644 --- a/daemon/wallet.c +++ b/daemon/wallet.c @@ -12,7 +12,7 @@ #include "log.h" #include "wallet.h" #include -#include +#include struct wallet { struct list_node list; @@ -25,8 +25,7 @@ static void new_keypair(struct lightningd_state *dstate, struct privkey *privkey, struct pubkey *pubkey) { do { - if (RAND_bytes(privkey->secret, sizeof(privkey->secret)) != 1) - fatal("Could not get random bytes for privkey"); + randombytes_buf(privkey->secret, sizeof(privkey->secret)); } while (!pubkey_from_privkey(dstate->secpctx, privkey, pubkey)); } From dc2d83bfbea66b9be926e89ad166e88bb4587351 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 7 Jul 2016 13:42:28 -0500 Subject: [PATCH 2/3] Replace OpenSSL's RAND_bytes() with libsodium's randombytes_buf() --- daemon/secrets.c | 2 +- daemon/wallet.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon/secrets.c b/daemon/secrets.c index 9794b9106..aac0ed9b3 100644 --- a/daemon/secrets.c +++ b/daemon/secrets.c @@ -147,7 +147,7 @@ static void new_keypair(struct lightningd_state *dstate, struct privkey *privkey, struct pubkey *pubkey) { do { - randombytes_buf(privkey->secret, sizeof(privkey->secret)); + randombytes_buf(privkey->secret, sizeof(privkey->secret)); } while (!pubkey_from_privkey(dstate->secpctx, privkey, pubkey)); } diff --git a/daemon/wallet.c b/daemon/wallet.c index c1dfd1b5a..f56584f20 100644 --- a/daemon/wallet.c +++ b/daemon/wallet.c @@ -25,7 +25,7 @@ static void new_keypair(struct lightningd_state *dstate, struct privkey *privkey, struct pubkey *pubkey) { do { - randombytes_buf(privkey->secret, sizeof(privkey->secret)); + randombytes_buf(privkey->secret, sizeof(privkey->secret)); } while (!pubkey_from_privkey(dstate->secpctx, privkey, pubkey)); } From ae52977e4262dc10387d51a224028f28e004e815 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 7 Jul 2016 13:49:01 -0500 Subject: [PATCH 3/3] fixed whitespace --- bitcoin/tx.c | 2 +- daemon/secrets.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index b547fbb15..d6c6714d4 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -497,7 +497,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, tx->output = tal_arr(tx, struct bitcoin_tx_output, tx->output_count); for (i = 0; i < tx->output_count; i++) pull_output(tx, cursor, max, tx->output + i); - + if (flag & SEGREGATED_WITNESS_FLAG) { for (i = 0; i < tx->input_count; i++) pull_witness(tx->input, i, cursor, max); diff --git a/daemon/secrets.c b/daemon/secrets.c index aac0ed9b3..d36f84024 100644 --- a/daemon/secrets.c +++ b/daemon/secrets.c @@ -157,7 +157,7 @@ void peer_secrets_init(struct peer *peer) new_keypair(peer->dstate, &peer->secrets->commit, &peer->local.commitkey); new_keypair(peer->dstate, &peer->secrets->final, &peer->local.finalkey); - randombytes_buf(peer->secrets->revocation_seed.u.u8, sizeof(peer->secrets->revocation_seed.u.u8)); + randombytes_buf(peer->secrets->revocation_seed.u.u8, sizeof(peer->secrets->revocation_seed.u.u8)); shachain_init(&peer->their_preimages); }