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

Function main

common/test/run-cryptomsg.c:127–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127int main(int argc, char *argv[])
128{
129 struct crypto_state cs_out, cs_in;
130 struct secret sk, rk, ck;
131 const void *msg;
132 size_t i;
133
134 common_setup(argv[0]);
135 msg = tal_dup_arr(tmpctx, char, "hello", 5, 0);
136
137 /* BOLT #8:
138 *
139 * name: transport-initiator successful handshake
140 *...
141 * # ck,temp_k3=0x919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01,0x981a46c820fb7a241bc8184ba4bb1f01bcdfafb00dde80098cb8c38db9141520
142 * # encryptWithAD(0x981a46c820fb7a241bc8184ba4bb1f01bcdfafb00dde80098cb8c38db9141520, 0x000000000000000000000000, 0x5dcb5ea9b4ccc755e0e3456af3990641276e1d5dc9afd82f974d90a47c918660, <empty>)
143 * # t=0x8dc68b1c466263b47fdf31e560e139ba
144 * output: 0x00b9e3a702e93e3a9948c2ed6e5fd7590a6e1c3a0344cfc9d5b57357049aa22355361aa02e55a8fc28fef5bd6d71ad0c38228dc68b1c466263b47fdf31e560e139ba
145 * # HKDF(0x919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01,zero)
146 * output: sk,rk=0x969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9,0xbb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442
147 */
148 ck = secret_from_hex("0x919219dbb2920afa8db80f9a51787a840bcf111ed8d588caf9ab4be716e42b01");
149 sk = secret_from_hex("0x969ab31b4d288cedf6218839b27a3e2140827047f2c0f01bf5c04435d43511a9");
150 rk = secret_from_hex("0xbb9020b8965f4df047e07f955f3c4b88418984aadc5cdb35096b9ea8fa5c3442");
151
152 cs_out.sn = cs_out.rn = cs_in.sn = cs_in.rn = 0;
153 cs_out.sk = cs_in.rk = sk;
154 cs_out.rk = cs_in.sk = rk;
155 cs_out.s_ck = cs_out.r_ck = cs_in.s_ck = cs_in.r_ck = ck;
156
157 for (i = 0; i < 1002; i++) {
158 u8 *dec, *enc;
159 u16 len;
160
161 enc = cryptomsg_encrypt_msg(tmpctx, &cs_out, msg);
162
163 /* BOLT #8:
164 *
165 * output 0: 0xcf2b30ddf0cf3f80e7c35a6e6730b59fe802473180f396d88a8fb0db8cbcf25d2f214cf9ea1d95
166 */
167 if (i == 0)
168 check_result(enc, "cf2b30ddf0cf3f80e7c35a6e6730b59fe802473180f396d88a8fb0db8cbcf25d2f214cf9ea1d95");
169 /* BOLT #8:
170 *
171 * output 1: 0x72887022101f0b6753e0c7de21657d35a4cb2a1f5cde2650528bbc8f837d0f0d7ad833b1a256a1
172 */
173 if (i == 1)
174 check_result(enc, "72887022101f0b6753e0c7de21657d35a4cb2a1f5cde2650528bbc8f837d0f0d7ad833b1a256a1");
175
176 /* BOLT #8:
177 *
178 * output 500: 0x178cb9d7387190fa34db9c2d50027d21793c9bc2d40b1e14dcf30ebeeeb220f48364f7a4c68bf8
179 * output 501: 0x1b186c57d44eb6de4c057c49940d79bb838a145cb528d6e8fd26dbe50a60ca2c104b56b60e45bd
180 */
181 if (i == 500)
182 check_result(enc, "178cb9d7387190fa34db9c2d50027d21793c9bc2d40b1e14dcf30ebeeeb220f48364f7a4c68bf8");
183 if (i == 501)
184 check_result(enc, "1b186c57d44eb6de4c057c49940d79bb838a145cb528d6e8fd26dbe50a60ca2c104b56b60e45bd");

Callers

nothing calls this directly

Calls 10

common_setupFunction · 0.85
cryptomsg_encrypt_msgFunction · 0.85
cryptomsg_decrypt_headerFunction · 0.85
abortFunction · 0.85
tal_bytelenFunction · 0.85
cryptomsg_decrypt_bodyFunction · 0.85
memeqFunction · 0.85
common_shutdownFunction · 0.85
secret_from_hexFunction · 0.70
check_resultFunction · 0.70

Tested by

no test coverage detected