MCPcopy Create free account
hub / github.com/ElementsProject/lightning / encode_msg

Function encode_msg

tests/fuzz/fuzz-init_received.c:86–115  ·  view source on GitHub ↗

Encodes the given message. Stores the decrypting crypto_state in `cs`. */

Source from the content-addressed store, hash-verified

84
85/* Encodes the given message. Stores the decrypting crypto_state in `cs`. */
86static u8 *encode_msg(const tal_t *ctx, const void *message, size_t size, struct crypto_state *cs)
87{
88 struct crypto_state cs_out, cs_in;
89 struct secret sk, rk, ck;
90 u16 len;
91
92 void *msg = tal_dup_arr(ctx, char, message, size, 0);
93
94 ck = secret_from_hex("0x919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01");
95 sk = secret_from_hex("0x969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9");
96 rk = secret_from_hex("0xbb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442");
97
98 cs_out.sn = cs_out.rn = cs_in.sn = cs_in.rn = 0;
99 cs_out.sk = cs_in.rk = sk;
100 cs_out.rk = cs_in.sk = rk;
101 cs_out.s_ck = cs_out.r_ck = cs_in.s_ck = cs_in.r_ck = ck;
102
103 u8 *encoded_msg = cryptomsg_encrypt_msg(ctx, &cs_out, msg);
104
105 if (!cryptomsg_decrypt_header(&cs_in, encoded_msg, &len))
106 abort();
107
108 /* Trim header */
109 memmove(encoded_msg, encoded_msg + CRYPTOMSG_HDR_SIZE,
110 tal_bytelen(encoded_msg) - CRYPTOMSG_HDR_SIZE);
111 tal_resize(&encoded_msg, tal_bytelen(encoded_msg) - CRYPTOMSG_HDR_SIZE);
112
113 *cs = cs_in;
114 return encoded_msg;
115}
116
117static struct io_plan *do_nothing(struct io_conn *conn, void *side)
118{

Callers 1

runFunction · 0.85

Calls 5

cryptomsg_encrypt_msgFunction · 0.85
cryptomsg_decrypt_headerFunction · 0.85
abortFunction · 0.85
tal_bytelenFunction · 0.85
secret_from_hexFunction · 0.70

Tested by

no test coverage detected