mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
lightningd: remove secpctx
Use the global in the few remaining places. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a4fdaab5b3
commit
36c8fc7ef8
3 changed files with 9 additions and 11 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "protobuf_convert.h"
|
#include "protobuf_convert.h"
|
||||||
#include "secrets.h"
|
#include "secrets.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <ccan/build_assert/build_assert.h>
|
#include <ccan/build_assert/build_assert.h>
|
||||||
#include <ccan/crypto/sha256/sha256.h>
|
#include <ccan/crypto/sha256/sha256.h>
|
||||||
#include <ccan/endian/endian.h>
|
#include <ccan/endian/endian.h>
|
||||||
|
@ -507,7 +508,7 @@ static struct io_plan *keys_exchanged(struct io_conn *conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Derive shared secret. */
|
/* Derive shared secret. */
|
||||||
if (!secp256k1_ecdh(neg->dstate->secpctx, shared_secret,
|
if (!secp256k1_ecdh(secp256k1_ctx, shared_secret,
|
||||||
&sessionkey.pubkey, neg->seckey)) {
|
&sessionkey.pubkey, neg->seckey)) {
|
||||||
log_unusual(neg->log, "Bad ECDH");
|
log_unusual(neg->log, "Bad ECDH");
|
||||||
return io_close(conn);
|
return io_close(conn);
|
||||||
|
@ -590,13 +591,12 @@ static struct io_plan *session_key_len_receive(struct io_conn *conn,
|
||||||
session_key_receive, neg);
|
session_key_receive, neg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gen_sessionkey(secp256k1_context *ctx,
|
static void gen_sessionkey(u8 seckey[32],
|
||||||
u8 seckey[32],
|
|
||||||
secp256k1_pubkey *pubkey)
|
secp256k1_pubkey *pubkey)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
randombytes_buf(seckey, 32);
|
randombytes_buf(seckey, 32);
|
||||||
} while (!secp256k1_ec_pubkey_create(ctx, pubkey, seckey));
|
} while (!secp256k1_ec_pubkey_create(secp256k1_ctx, pubkey, seckey));
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct io_plan *write_sessionkey(struct io_conn *conn,
|
static struct io_plan *write_sessionkey(struct io_conn *conn,
|
||||||
|
@ -638,10 +638,10 @@ struct io_plan *peer_crypto_setup_(struct io_conn *conn,
|
||||||
neg->expected_id = id;
|
neg->expected_id = id;
|
||||||
neg->log = log;
|
neg->log = log;
|
||||||
|
|
||||||
gen_sessionkey(dstate->secpctx, neg->seckey, &sessionkey);
|
gen_sessionkey(neg->seckey, &sessionkey);
|
||||||
|
|
||||||
outputlen = sizeof(neg->our_sessionpubkey);
|
outputlen = sizeof(neg->our_sessionpubkey);
|
||||||
secp256k1_ec_pubkey_serialize(dstate->secpctx,
|
secp256k1_ec_pubkey_serialize(secp256k1_ctx,
|
||||||
neg->our_sessionpubkey, &outputlen,
|
neg->our_sessionpubkey, &outputlen,
|
||||||
&sessionkey,
|
&sessionkey,
|
||||||
SECP256K1_EC_COMPRESSED);
|
SECP256K1_EC_COMPRESSED);
|
||||||
|
|
|
@ -356,8 +356,6 @@ static struct lightningd_state *lightningd_state(void)
|
||||||
timers_init(&dstate->timers, time_mono());
|
timers_init(&dstate->timers, time_mono());
|
||||||
txwatch_hash_init(&dstate->txwatches);
|
txwatch_hash_init(&dstate->txwatches);
|
||||||
txowatch_hash_init(&dstate->txowatches);
|
txowatch_hash_init(&dstate->txowatches);
|
||||||
secp256k1_ctx = dstate->secpctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
|
||||||
list_head_init(&dstate->bitcoin_req);
|
list_head_init(&dstate->bitcoin_req);
|
||||||
list_head_init(&dstate->wallet);
|
list_head_init(&dstate->wallet);
|
||||||
list_head_init(&dstate->unpaid);
|
list_head_init(&dstate->unpaid);
|
||||||
|
@ -483,6 +481,9 @@ int main(int argc, char *argv[])
|
||||||
errx(1, "Compiled against protobuf %s, but have %s",
|
errx(1, "Compiled against protobuf %s, but have %s",
|
||||||
PROTOBUF_C_VERSION, protobuf_c_version());
|
PROTOBUF_C_VERSION, protobuf_c_version());
|
||||||
|
|
||||||
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
|
||||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||||
"\n"
|
"\n"
|
||||||
"A bitcoin lightning daemon.",
|
"A bitcoin lightning daemon.",
|
||||||
|
|
|
@ -107,9 +107,6 @@ struct lightningd_state {
|
||||||
/* Any outstanding "pay" commands. */
|
/* Any outstanding "pay" commands. */
|
||||||
struct list_head pay_commands;
|
struct list_head pay_commands;
|
||||||
|
|
||||||
/* Crypto tables for global use. */
|
|
||||||
secp256k1_context *secpctx;
|
|
||||||
|
|
||||||
/* Our private key */
|
/* Our private key */
|
||||||
struct secret *secret;
|
struct secret *secret;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue