Browse Source

crypto_state: move to its own file.

In particular, the main daemon needs to pass it about (marshal/unmarshal)
but it won't need to actually use it after the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
2394c9a2e7
  1. 1
      channeld/Makefile
  2. 1
      closingd/Makefile
  3. 1
      common/Makefile
  4. 22
      common/crypto_state.c
  5. 20
      common/crypto_state.h
  6. 20
      common/cryptomsg.c
  7. 14
      common/cryptomsg.h
  8. 1
      gossipd/Makefile
  9. 1
      handshaked/Makefile
  10. 1
      lightningd/Makefile
  11. 1
      openingd/Makefile

1
channeld/Makefile

@ -33,6 +33,7 @@ ALL_GEN_HEADERS += $(LIGHTNINGD_CHANNEL_HEADERS_GEN)
# Common source we use. # Common source we use.
CHANNELD_COMMON_OBJS := \ CHANNELD_COMMON_OBJS := \
common/channel_config.o \ common/channel_config.o \
common/crypto_state.o \
common/crypto_sync.o \ common/crypto_sync.o \
common/cryptomsg.o \ common/cryptomsg.o \
common/daemon_conn.o \ common/daemon_conn.o \

1
closingd/Makefile

@ -43,6 +43,7 @@ $(LIGHTNINGD_CLOSING_OBJS): $(LIGHTNINGD_HEADERS)
# Common source we use. # Common source we use.
CLOSINGD_COMMON_OBJS := \ CLOSINGD_COMMON_OBJS := \
common/close_tx.o \ common/close_tx.o \
common/crypto_state.o \
common/crypto_sync.o \ common/crypto_sync.o \
common/cryptomsg.o \ common/cryptomsg.o \
common/daemon_conn.o \ common/daemon_conn.o \

1
common/Makefile

@ -3,6 +3,7 @@ COMMON_SRC := \
common/channel_config.c \ common/channel_config.c \
common/close_tx.c \ common/close_tx.c \
common/configdir.c \ common/configdir.c \
common/crypto_state.c \
common/crypto_sync.c \ common/crypto_sync.c \
common/cryptomsg.c \ common/cryptomsg.c \
common/daemon_conn.c \ common/daemon_conn.c \

22
common/crypto_state.c

@ -0,0 +1,22 @@
#include <common/crypto_state.h>
#include <wire/wire.h>
void towire_crypto_state(u8 **ptr, const struct crypto_state *cs)
{
towire_u64(ptr, cs->rn);
towire_u64(ptr, cs->sn);
towire_secret(ptr, &cs->sk);
towire_secret(ptr, &cs->rk);
towire_secret(ptr, &cs->s_ck);
towire_secret(ptr, &cs->r_ck);
}
void fromwire_crypto_state(const u8 **ptr, size_t *max, struct crypto_state *cs)
{
cs->rn = fromwire_u64(ptr, max);
cs->sn = fromwire_u64(ptr, max);
fromwire_secret(ptr, max, &cs->sk);
fromwire_secret(ptr, max, &cs->rk);
fromwire_secret(ptr, max, &cs->s_ck);
fromwire_secret(ptr, max, &cs->r_ck);
}

20
common/crypto_state.h

@ -0,0 +1,20 @@
#ifndef LIGHTNING_COMMON_CRYPTO_STATE_H
#define LIGHTNING_COMMON_CRYPTO_STATE_H
#include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/short_types/short_types.h>
#include <stddef.h>
struct crypto_state {
/* Received and sent nonces. */
u64 rn, sn;
/* Sending and receiving keys. */
struct secret sk, rk;
/* Chaining key for re-keying */
struct secret s_ck, r_ck;
};
void towire_crypto_state(u8 **pptr, const struct crypto_state *cs);
void fromwire_crypto_state(const u8 **ptr, size_t *max, struct crypto_state *cs);
#endif /* LIGHTNING_COMMON_CRYPTO_STATE_H */

20
common/cryptomsg.c

@ -371,23 +371,3 @@ void init_peer_crypto_state(struct peer *peer, struct peer_crypto_state *pcs)
pcs->peer = peer; pcs->peer = peer;
pcs->out = pcs->in = NULL; pcs->out = pcs->in = NULL;
} }
void towire_crypto_state(u8 **ptr, const struct crypto_state *cs)
{
towire_u64(ptr, cs->rn);
towire_u64(ptr, cs->sn);
towire_secret(ptr, &cs->sk);
towire_secret(ptr, &cs->rk);
towire_secret(ptr, &cs->s_ck);
towire_secret(ptr, &cs->r_ck);
}
void fromwire_crypto_state(const u8 **ptr, size_t *max, struct crypto_state *cs)
{
cs->rn = fromwire_u64(ptr, max);
cs->sn = fromwire_u64(ptr, max);
fromwire_secret(ptr, max, &cs->sk);
fromwire_secret(ptr, max, &cs->rk);
fromwire_secret(ptr, max, &cs->s_ck);
fromwire_secret(ptr, max, &cs->r_ck);
}

14
common/cryptomsg.h

@ -1,22 +1,13 @@
#ifndef LIGHTNING_COMMON_CRYPTOMSG_H #ifndef LIGHTNING_COMMON_CRYPTOMSG_H
#define LIGHTNING_COMMON_CRYPTOMSG_H #define LIGHTNING_COMMON_CRYPTOMSG_H
#include "config.h" #include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <common/crypto_state.h>
struct io_conn; struct io_conn;
struct peer; struct peer;
struct crypto_state {
/* Received and sent nonces. */
u64 rn, sn;
/* Sending and receiving keys. */
struct secret sk, rk;
/* Chaining key for re-keying */
struct secret s_ck, r_ck;
};
struct peer_crypto_state { struct peer_crypto_state {
struct crypto_state cs; struct crypto_state cs;
@ -46,9 +37,6 @@ struct io_plan *peer_write_message(struct io_conn *conn,
struct io_plan *(*next)(struct io_conn *, struct io_plan *(*next)(struct io_conn *,
struct peer *)); struct peer *));
void towire_crypto_state(u8 **pptr, const struct crypto_state *cs);
void fromwire_crypto_state(const u8 **ptr, size_t *max, struct crypto_state *cs);
/* Low-level functions for sync comms: doesn't discard unknowns! */ /* Low-level functions for sync comms: doesn't discard unknowns! */
u8 *cryptomsg_encrypt_msg(const tal_t *ctx, u8 *cryptomsg_encrypt_msg(const tal_t *ctx,
struct crypto_state *cs, struct crypto_state *cs,

1
gossipd/Makefile

@ -33,6 +33,7 @@ LIGHTNINGD_HEADERS_GEN += $(LIGHTNINGD_GOSSIP_HEADERS)
# Common source we use. # Common source we use.
GOSSIPD_COMMON_OBJS := \ GOSSIPD_COMMON_OBJS := \
common/crypto_state.o \
common/crypto_sync.o \ common/crypto_sync.o \
common/cryptomsg.o \ common/cryptomsg.o \
common/daemon_conn.o \ common/daemon_conn.o \

1
handshaked/Makefile

@ -36,6 +36,7 @@ $(LIGHTNINGD_HANDSHAKE_OBJS): $(LIGHTNINGD_HEADERS)
# Common source we use. # Common source we use.
HANDSHAKED_COMMON_OBJS := \ HANDSHAKED_COMMON_OBJS := \
common/crypto_state.o \
common/crypto_sync.o \ common/crypto_sync.o \
common/cryptomsg.o \ common/cryptomsg.o \
common/daemon_conn.o \ common/daemon_conn.o \

1
lightningd/Makefile

@ -17,6 +17,7 @@ LIGHTNINGD_COMMON_OBJS := \
common/bip32.o \ common/bip32.o \
common/channel_config.o \ common/channel_config.o \
common/configdir.o \ common/configdir.o \
common/crypto_state.o \
common/cryptomsg.o \ common/cryptomsg.o \
common/derive_basepoints.o \ common/derive_basepoints.o \
common/funding_tx.o \ common/funding_tx.o \

1
openingd/Makefile

@ -37,6 +37,7 @@ LIGHTNINGD_HEADERS_NOGEN += $(LIGHTNINGD_OPENING_HEADERS_NOGEN)
OPENINGD_COMMON_OBJS := \ OPENINGD_COMMON_OBJS := \
common/bip32.o \ common/bip32.o \
common/channel_config.o \ common/channel_config.o \
common/crypto_state.o \
common/crypto_sync.o \ common/crypto_sync.o \
common/cryptomsg.o \ common/cryptomsg.o \
common/daemon_conn.o \ common/daemon_conn.o \

Loading…
Cancel
Save