Test that encrypting and decrypting the message does not alter it. */
| 61 | |
| 62 | /* Test that encrypting and decrypting the message does not alter it. */ |
| 63 | static 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. */ |
| 84 | static void test_decrypt_header(const u8 *buf) |
no test coverage detected