| 10 | } |
| 11 | |
| 12 | void run(const uint8_t *data, size_t size) |
| 13 | { |
| 14 | /* 4294967295 is crypto_pwhash_argon2id_PASSWD_MAX. libfuzzer won't |
| 15 | * generate inputs that large in practice, but hey. */ |
| 16 | if (size > 32 && size < 4294967295) { |
| 17 | struct secret *hsm_secret, decrypted_hsm_secret, encryption_key; |
| 18 | char *passphrase; |
| 19 | struct encrypted_hsm_secret encrypted_secret; |
| 20 | char *emsg; |
| 21 | |
| 22 | /* Take the first 32 bytes as the plaintext hsm_secret seed, |
| 23 | * and the remaining ones as the passphrase. */ |
| 24 | hsm_secret = (struct secret *)tal_dup_arr(NULL, u8, data, 32, 0); |
| 25 | passphrase = to_string(NULL, data + 32, size - 32); |
| 26 | |
| 27 | /* A valid seed, a valid passphrase. This should not fail. */ |
| 28 | assert(!hsm_secret_encryption_key_with_exitcode(passphrase, &encryption_key, &emsg)); |
| 29 | /* Roundtrip */ |
| 30 | assert(encrypt_hsm_secret(&encryption_key, hsm_secret, |
| 31 | &encrypted_secret)); |
| 32 | assert(decrypt_hsm_secret(&encryption_key, &encrypted_secret, |
| 33 | &decrypted_hsm_secret)); |
| 34 | assert(memeq(hsm_secret->data, sizeof(hsm_secret->data), |
| 35 | decrypted_hsm_secret.data, |
| 36 | sizeof(decrypted_hsm_secret.data))); |
| 37 | |
| 38 | tal_free(hsm_secret); |
| 39 | tal_free(passphrase); |
| 40 | } |
| 41 | } |
nothing calls this directly
no test coverage detected