mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 09:40:19 +01:00
cryptomsg: add towire/fromwire for crypto state.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
89a06734c4
commit
6a089ce112
2 changed files with 34 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <sodium/crypto_aead_chacha20poly1305.h>
|
#include <sodium/crypto_aead_chacha20poly1305.h>
|
||||||
#include <status.h>
|
#include <status.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
|
#include <wire/wire.h>
|
||||||
#include <wire/wire_io.h>
|
#include <wire/wire_io.h>
|
||||||
|
|
||||||
struct crypto_state {
|
struct crypto_state {
|
||||||
|
@ -320,3 +321,31 @@ struct crypto_state *crypto_state(struct peer *peer,
|
||||||
|
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void towire_crypto_state(u8 **ptr, const struct crypto_state *cs)
|
||||||
|
{
|
||||||
|
towire_u64(ptr, cs->rn);
|
||||||
|
towire_u64(ptr, cs->sn);
|
||||||
|
towire_sha256(ptr, &cs->sk);
|
||||||
|
towire_sha256(ptr, &cs->rk);
|
||||||
|
towire_sha256(ptr, &cs->s_ck);
|
||||||
|
towire_sha256(ptr, &cs->r_ck);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct crypto_state *fromwire_crypto_state(const tal_t *ctx,
|
||||||
|
const u8 **ptr, size_t *max)
|
||||||
|
{
|
||||||
|
struct crypto_state *cs = tal(ctx, struct crypto_state);
|
||||||
|
|
||||||
|
cs->rn = fromwire_u64(ptr, max);
|
||||||
|
cs->sn = fromwire_u64(ptr, max);
|
||||||
|
fromwire_sha256(ptr, max, &cs->sk);
|
||||||
|
fromwire_sha256(ptr, max, &cs->rk);
|
||||||
|
fromwire_sha256(ptr, max, &cs->s_ck);
|
||||||
|
fromwire_sha256(ptr, max, &cs->r_ck);
|
||||||
|
cs->peer = (struct peer *)ctx;
|
||||||
|
|
||||||
|
if (!*ptr)
|
||||||
|
return tal_free(cs);
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define LIGHTNING_LIGHTNINGD_CRYPTOMSG_H
|
#define LIGHTNING_LIGHTNINGD_CRYPTOMSG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
|
#include <ccan/tal/tal.h>
|
||||||
|
|
||||||
struct io_conn;
|
struct io_conn;
|
||||||
struct peer;
|
struct peer;
|
||||||
|
@ -29,4 +30,8 @@ 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);
|
||||||
|
struct crypto_state *fromwire_crypto_state(const tal_t *ctx,
|
||||||
|
const u8 **ptr, size_t *max);
|
||||||
|
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_CRYPTOMSG_H */
|
#endif /* LIGHTNING_LIGHTNINGD_CRYPTOMSG_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue