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

Function test_encrypt_decrypt_equality

tests/fuzz/fuzz-cryptomsg.c:63–81  ·  view source on GitHub ↗

Test that encrypting and decrypting the message does not alter it. */

Source from the content-addressed store, hash-verified

61
62/* Test that encrypting and decrypting the message does not alter it. */
63static void test_encrypt_decrypt_equality(const u8 *msg)
64{
65 struct crypto_state cs_out = init_cs_out;
66 struct crypto_state cs_in = init_cs_in;
67 u8 *dec, *enc;
68 u16 len;
69
70 enc = cryptomsg_encrypt_msg(msg, &cs_out, msg);
71
72 assert(cryptomsg_decrypt_header(&cs_in, enc, &len));
73
74 /* Trim header. */
75 memmove(enc, enc + CRYPTOMSG_HDR_SIZE,
76 tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE);
77 tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE);
78
79 dec = cryptomsg_decrypt_body(msg, &cs_in, enc);
80 assert(tal_arr_eq(dec, msg));
81}
82
83/* Test header decryption of arbitrary bytes. */
84static void test_decrypt_header(const u8 *buf)

Callers 1

runFunction · 0.85

Calls 4

cryptomsg_encrypt_msgFunction · 0.85
cryptomsg_decrypt_headerFunction · 0.85
tal_bytelenFunction · 0.85
cryptomsg_decrypt_bodyFunction · 0.85

Tested by

no test coverage detected