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

Function run

tests/fuzz/fuzz-bip32.c:11–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11void run(const uint8_t *data, size_t size)
12{
13 struct ext_key xkey;
14 struct bip32_key_version version;
15 u8 *wire_buff;
16 const uint8_t **xkey_chunks, **ver_chunks, *wire_ptr;
17 size_t wire_max;
18 u8 fingerprint[BIP32_KEY_FINGERPRINT_LEN];
19
20 if (size < BIP32_SERIALIZED_LEN)
21 return;
22
23 xkey_chunks = get_chunks(NULL, data, size, BIP32_SERIALIZED_LEN);
24 for (size_t i = 0; i < tal_count(xkey_chunks); i++) {
25 wire_max = tal_bytelen(xkey_chunks[i]);
26 wire_ptr = xkey_chunks[i];
27
28 fromwire_ext_key(&wire_ptr, &wire_max, &xkey);
29 if (wire_ptr) {
30 // Check key validity by attempting to get the
31 // fingerprint, which will fail if the key is invalid.
32 if (bip32_key_get_fingerprint(&xkey, fingerprint,
33 sizeof(fingerprint)))
34 continue;
35
36 // Since the key is valid, we should be able to
37 // serialize it again successfully.
38 wire_buff = tal_arr(NULL, uint8_t, BIP32_SERIALIZED_LEN);
39 towire_ext_key(&wire_buff, &xkey);
40 tal_free(wire_buff);
41 }
42 }
43 tal_free(xkey_chunks);
44
45 ver_chunks = get_chunks(NULL, data, size, 8);
46 for (size_t i = 0; i < tal_count(ver_chunks); i++) {
47 wire_max = tal_bytelen(ver_chunks[i]);
48 wire_ptr = ver_chunks[i];
49
50 fromwire_bip32_key_version(&wire_ptr, &wire_max, &version);
51 if (wire_ptr) {
52 wire_buff = tal_arr(NULL, uint8_t, 8);
53 towire_bip32_key_version(&wire_buff, &version);
54 tal_free(wire_buff);
55 }
56 }
57 tal_free(ver_chunks);
58}

Callers

nothing calls this directly

Calls 7

get_chunksFunction · 0.85
tal_bytelenFunction · 0.85
fromwire_ext_keyFunction · 0.85
towire_ext_keyFunction · 0.85
tal_freeFunction · 0.85
towire_bip32_key_versionFunction · 0.85

Tested by

no test coverage detected