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

Function run

tests/fuzz/fuzz-hsm_secret.c:21–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21void run(const uint8_t *data, size_t size)
22{
23 /* LibFuzzer won't generate inputs larger than
24 * crypto_pwhash_argon2id_PASSWD_MAX in practice, but hey. */
25 if (size > sizeof(struct secret) && size < crypto_pwhash_argon2id_PASSWD_MAX) {
26 struct secret *hsm_secret, *encryption_key;
27 char *passphrase;
28 u8 encrypted_data[ENCRYPTED_HSM_SECRET_LEN];
29 struct hsm_secret *decrypted_hsm;
30 enum hsm_secret_error err;
31
32 /* Take the first 32 bytes as the plaintext hsm_secret seed,
33 * and the remaining ones as the passphrase. */
34 hsm_secret = (struct secret *)tal_dup_arr(NULL, u8, data, sizeof(struct secret), 0);
35 mlock_tal_memory(hsm_secret);
36 passphrase = to_string(NULL, data + sizeof(struct secret), size - sizeof(struct secret));
37
38 /* A valid seed, a valid passphrase. This should not fail. */
39 encryption_key = get_encryption_key(NULL, passphrase);
40 assert(encryption_key);
41
42 /* Roundtrip: encrypt then decrypt */
43 assert(encrypt_legacy_hsm_secret(encryption_key, hsm_secret, encrypted_data));
44 decrypted_hsm = extract_hsm_secret(NULL, encrypted_data, ENCRYPTED_HSM_SECRET_LEN,
45 passphrase, &err);
46 assert(decrypted_hsm);
47 assert(err == HSM_SECRET_OK);
48 assert(decrypted_hsm->type == HSM_SECRET_ENCRYPTED);
49 assert(memeq(hsm_secret->data, sizeof(hsm_secret->data),
50 decrypted_hsm->secret_data, sizeof(hsm_secret->data)));
51
52 tal_free(hsm_secret);
53 tal_free(passphrase);
54 tal_free(encryption_key);
55 tal_free(decrypted_hsm);
56 }
57}

Callers

nothing calls this directly

Calls 7

mlock_tal_memoryFunction · 0.85
get_encryption_keyFunction · 0.85
extract_hsm_secretFunction · 0.85
memeqFunction · 0.85
tal_freeFunction · 0.85
to_stringFunction · 0.70

Tested by

no test coverage detected