1 #include "config.h"
2 #include <tests/fuzz/libfuzz.h>
3
4 #include <common/bip32.h>
5 #include <wally_bip32.h>
6
init(int * argc,char *** argv)7 void init(int *argc, char ***argv)
8 {
9 }
10
run(const uint8_t * data,size_t size)11 void 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
19 if (size < BIP32_SERIALIZED_LEN)
20 return;
21
22 xkey_chunks = get_chunks(NULL, data, size, BIP32_SERIALIZED_LEN);
23 for (size_t i = 0; i < tal_count(xkey_chunks); i++) {
24 wire_max = tal_bytelen(xkey_chunks[i]);
25 wire_ptr = xkey_chunks[i];
26
27 fromwire_ext_key(&wire_ptr, &wire_max, &xkey);
28 if (wire_ptr) {
29 wire_buff = tal_arr(NULL, uint8_t, BIP32_SERIALIZED_LEN);
30 towire_ext_key(&wire_buff, &xkey);
31 tal_free(wire_buff);
32 }
33 }
34 tal_free(xkey_chunks);
35
36 ver_chunks = get_chunks(NULL, data, size, 4);
37 for (size_t i = 0; i < tal_count(ver_chunks); i++) {
38 wire_max = tal_bytelen(ver_chunks[i]);
39 wire_ptr = ver_chunks[i];
40
41 fromwire_bip32_key_version(&wire_ptr, &wire_max, &version);
42 if (wire_ptr) {
43 wire_buff = tal_arr(NULL, uint8_t, 4);
44 towire_bip32_key_version(&wire_buff, &version);
45 tal_free(wire_buff);
46 }
47 }
48 tal_free(ver_chunks);
49 }
50