Skip to content

eBPF-based security platform

util: drop the shirudo_ prefix from the util functions

Daniel Borkmann48686eb341e7
diff --git a/Documentation/tpm.rst b/Documentation/tpm.rst
index a66f6da2..06230e35 100644
--- a/Documentation/tpm.rst
+++ b/Documentation/tpm.rst
@@ -210,7 +210,7 @@ key revocation
each loaded upatch of which then follows as its own unload event.
The register after an event is ``SHA256(register || event)``, starting
-from zeros; ``shirudo_chain_fold()`` and the eventlog replay use the
+from zeros; ``chain_fold()`` and the eventlog replay use the
same fold. Boot restore is exactly one init event however many
upatches it re-applies.
diff --git a/Makefile.shirudo b/Makefile.shirudo
index f9644018..5b8d8e9c 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -560,8 +560,8 @@ testing/helper/test-string: testing/helper/test-string.c util/string.o util/mall
# chain.o's read/extend paths reference util/tpm (libtss2); the tests
# only exercise the pure helpers, but the symbols must still resolve.
-# util/malloc.o brings in x*/shirudo_libc_free that chain.o/tpm.o use.
-# util/config.o resolves shirudo_config_load(), called by tpm.o.
+# util/malloc.o brings in x*/libc_free that chain.o/tpm.o use.
+# util/config.o resolves config_load(), called by tpm.o.
# The register code pulls in the eventlog, which pulls in the seal
# label writer and the JSON codec.
REGISTER_OBJS := util/chain.o util/tpm.o util/tpm_wire.o util/eventlog.o \
diff --git a/builtin-attest.c b/builtin-attest.c
index da4bb815..41535044 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -126,12 +126,12 @@ static int parse_hex(const char *hex, __u8 *out, size_t cap, size_t *len)
if (n == 0 || (n & 1) || n / 2 > cap)
return -EINVAL;
*len = n / 2;
- return shirudo_hex_decode(hex, out, n / 2);
+ return hex_decode(hex, out, n / 2);
}
static int parse_hex32(const char *what, const char *hex, __u8 out[32])
{
- if (strlen(hex) != 64 || shirudo_hex_decode(hex, out, 32)) {
+ if (strlen(hex) != 64 || hex_decode(hex, out, 32)) {
pr_err("attest: %s must be 64 hex characters", what);
return -EINVAL;
}
@@ -144,7 +144,7 @@ static int parse_pcrs(const char *list, __u32 *mask)
*mask = 0;
while (*p) {
- size_t len = shirudo_digits(p, strlen(p));
+ size_t len = digits(p, strlen(p));
__u64 n;
if (parse_u64(p, len, 23, &n))
@@ -162,7 +162,7 @@ static int parse_pcrs(const char *list, __u32 *mask)
/* "<pcr>=<value>": the PCR, below 24, and where its value starts. */
static int parse_pcr_value(const char *arg, __u64 *pcr, const char **value)
{
- size_t len = shirudo_digits(arg, strlen(arg));
+ size_t len = digits(arg, strlen(arg));
if (arg[len] != '=' || parse_u64(arg, len, 23, pcr))
return -EINVAL;
@@ -183,7 +183,7 @@ static int member_add_file(struct members *m, const char *path)
if (m->n >= SHIRUDO_ATTEST_MEMBERS_MAX)
return -E2BIG;
- rc = shirudo_upatch_open(path, &u);
+ rc = upatch_open(path, &u);
if (rc) {
pr_err("attest: open %s: %s", path, strerror(-rc));
return rc;
@@ -191,9 +191,9 @@ static int member_add_file(struct members *m, const char *path)
e = &m->set[m->n++];
memcpy(e->name, u.hdr.name, SHIRUDO_UPATCH_NAME_MAX);
e->name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
- shirudo_hex_encode(u.hdr.payload_sha256,
- SHIRUDO_UPATCH_PAYLOAD_HASH_LEN, e->payload_hex);
- shirudo_upatch_close(&u);
+ hex_encode(u.hdr.payload_sha256,
+ SHIRUDO_UPATCH_PAYLOAD_HASH_LEN, e->payload_hex);
+ upatch_close(&u);
return 0;
}
@@ -212,7 +212,7 @@ static int member_add_spec(struct members *m, const char *spec)
e = &m->set[m->n++];
memcpy(e->name, spec, (size_t)(eq - spec));
e->name[eq - spec] = '\0';
- shirudo_hex_encode(payload, 32, e->payload_hex);
+ hex_encode(payload, 32, e->payload_hex);
return 0;
}
@@ -264,23 +264,23 @@ static int apply_event(const char *spec, __u8 chain[32])
memcpy(name, colon + 1, name_len);
name[name_len] = '\0';
if (kind_len == 4 && !strncmp(spec, "load", 4)) {
- shirudo_chain_upatch_event("shirudo-upatch", name, digest,
- event);
+ chain_upatch_event("shirudo-upatch", name, digest,
+ event);
} else if (kind_len == 6 && !strncmp(spec, "unload", 6)) {
- shirudo_chain_upatch_event("shirudo-unload", name, digest,
- event);
+ chain_upatch_event("shirudo-unload", name, digest,
+ event);
} else if (kind_len == 4 && !strncmp(spec, "tree", 4)) {
__s64 seq;
if (parse_s64(name, strlen(name), 1, INT64_MAX, &seq))
return -EINVAL;
- shirudo_chain_tree_event(seq, digest, event);
+ chain_tree_event(seq, digest, event);
} else if (kind_len == 6 && !strncmp(spec, "revoke", 6)) {
- shirudo_chain_key_event("shirudo-key-revoke", digest, event);
+ chain_key_event("shirudo-key-revoke", digest, event);
} else {
return -EINVAL;
}
- shirudo_chain_fold(chain, event);
+ chain_fold(chain, event);
return 0;
}
@@ -344,8 +344,8 @@ static int cmd_attest_predict(int argc, const char **argv)
goto out;
}
have_bind[slot] = true;
- } else if (shirudo_is_help(a)) {
- shirudo_print_help(&attest_help);
+ } else if (is_help(a)) {
+ print_help(&attest_help);
ret = 0;
goto out;
} else {
@@ -357,15 +357,15 @@ static int cmd_attest_predict(int argc, const char **argv)
pr_err("attest predict: --cert is required");
goto out;
}
- shirudo_keys_anchor_digest(cert_shas, n_certs, cert_sha);
- shirudo_chain_init_event(cert_sha, m.set, m.n, tree_root, set_digest,
- init);
- shirudo_hex_encode(set_digest, 32, hex);
+ keys_anchor_digest(cert_shas, n_certs, cert_sha);
+ chain_init_event(cert_sha, m.set, m.n, tree_root, set_digest,
+ init);
+ hex_encode(set_digest, 32, hex);
printf("set_digest: %s\n", hex);
- shirudo_hex_encode(init, 32, hex);
+ hex_encode(init, 32, hex);
printf("init_event: %s\n", hex);
- shirudo_chain_fold(chain, init);
- shirudo_hex_encode(chain, 32, hex);
+ chain_fold(chain, init);
+ hex_encode(chain, 32, hex);
printf("register_at_boot: %s\n", hex);
for (i = 0; i < n_events; i++) {
if (apply_event(events[i], chain)) {
@@ -374,7 +374,7 @@ static int cmd_attest_predict(int argc, const char **argv)
}
}
if (n_events) {
- shirudo_hex_encode(chain, 32, hex);
+ hex_encode(chain, 32, hex);
printf("register_after_events: %s\n", hex);
}
if (have_bind[0] && have_bind[1]) {
@@ -382,19 +382,19 @@ static int cmd_attest_predict(int argc, const char **argv)
__u8 name[SHIRUDO_TPM_NAME_LEN], anchor_digest[32];
char anchor[SHIRUDO_CHAIN_ANCHOR_MAX];
- shirudo_tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, bind[0], 2,
- branch_written, branch_init,
- policy);
- shirudo_tpm_nv_name(SHIRUDO_NV_INDEX,
- SHIRUDO_TPM_REGISTER_ATTRS |
- SHIRUDO_TPM_NV_WRITTEN, policy, 32, name);
- shirudo_hex_encode(name, sizeof(name), hex);
+ tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, bind[0], 2,
+ branch_written, branch_init,
+ policy);
+ tpm_nv_name(SHIRUDO_NV_INDEX,
+ SHIRUDO_TPM_REGISTER_ATTRS |
+ SHIRUDO_TPM_NV_WRITTEN, policy, 32, name);
+ hex_encode(name, sizeof(name), hex);
printf("register_name: %s\n", hex);
- shirudo_chain_anchor(name, anchor, sizeof(anchor));
+ chain_anchor(name, anchor, sizeof(anchor));
printf("anchor: %s\n", anchor);
shirudo_sha256(anchor, strlen(anchor), anchor_digest);
- shirudo_chain_fold(bind[0], anchor_digest);
- shirudo_hex_encode(bind[0], 32, hex);
+ chain_fold(bind[0], anchor_digest);
+ hex_encode(bind[0], 32, hex);
printf("pcr%u_after_anchor: %s\n", SHIRUDO_CHAIN_PCR, hex);
} else if (have_bind[0] || have_bind[1]) {
pr_err("attest predict: --bind-pcr needs both %u and %u",
@@ -551,8 +551,8 @@ static int cmd_attest_verify(int argc, const char **argv)
x.bind_expect_mask |= 1u << n;
} else if (!strcmp(a, "--require-initrd")) {
x.require_initrd = true;
- } else if (shirudo_is_help(a)) {
- shirudo_print_help(&attest_help);
+ } else if (is_help(a)) {
+ print_help(&attest_help);
ret = 0;
goto out;
} else {
@@ -575,15 +575,15 @@ static int cmd_attest_verify(int argc, const char **argv)
x.nonce = nonce;
x.nonce_len = nonce_len;
if (have_cert) {
- shirudo_keys_anchor_digest(cert_shas, n_certs, cert_sha);
- shirudo_chain_init_event(cert_sha, m.set, m.n, tree_root,
- set_digest, x.init_event);
+ keys_anchor_digest(cert_shas, n_certs, cert_sha);
+ chain_init_event(cert_sha, m.set, m.n, tree_root,
+ set_digest, x.init_event);
x.have_init = true;
}
if (read_evidence(evidence_path, &evidence, &evidence_len))
goto out;
- rc = shirudo_attest_verify(evidence, evidence_len, &x, report,
- SHIRUDO_ATTEST_REPORT_MAX);
+ rc = attest_verify(evidence, evidence_len, &x, report,
+ SHIRUDO_ATTEST_REPORT_MAX);
fputs(report, stdout);
if (rc == -EINVAL) {
pr_err("attest verify: %s is not a shirudo evidence document",
@@ -644,8 +644,8 @@ static int cmd_attest_challenge(int argc, const char **argv)
pol.trust_presented = true;
} else if (!strncmp(a, "--out=", 6)) {
out_path = a + 6;
- } else if (shirudo_is_help(a)) {
- shirudo_print_help(&attest_help);
+ } else if (is_help(a)) {
+ print_help(&attest_help);
ret = 0;
goto out;
} else {
@@ -659,9 +659,9 @@ static int cmd_attest_challenge(int argc, const char **argv)
}
if (read_evidence(evidence_path, &evidence, &evidence_len))
goto out;
- rc = shirudo_attest_challenge_make(evidence, evidence_len, &pol,
- credential, &doc, &len, &cap, report,
- SHIRUDO_ATTEST_REPORT_MAX);
+ rc = attest_challenge_make(evidence, evidence_len, &pol,
+ credential, &doc, &len, &cap, report,
+ SHIRUDO_ATTEST_REPORT_MAX);
fputs(report, stdout);
if (rc == -EINVAL) {
pr_err("attest challenge: %s carries no endorsement key",
@@ -677,8 +677,8 @@ static int cmd_attest_challenge(int argc, const char **argv)
int fd = open(out_path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
0600);
- if (fd < 0 || shirudo_write_all(fd, doc, len) ||
- shirudo_write_all(fd, "\n", 1) || close(fd)) {
+ if (fd < 0 || write_all(fd, doc, len) ||
+ write_all(fd, "\n", 1) || close(fd)) {
pr_err("attest challenge: write %s: %s", out_path,
strerror(errno));
if (fd >= 0)
@@ -687,7 +687,7 @@ static int cmd_attest_challenge(int argc, const char **argv)
goto out;
}
}
- shirudo_hex_encode(credential, sizeof(credential), hex);
+ hex_encode(credential, sizeof(credential), hex);
printf("challenge: %s\ncredential: %s\n", out_path, hex);
ret = 0;
out:
@@ -728,8 +728,8 @@ static int cmd_attest_evidence(int argc, const char **argv)
}
} else if (!strncmp(a, "--out=", 6)) {
out_path = a + 6;
- } else if (shirudo_is_help(a)) {
- shirudo_print_help(&attest_help);
+ } else if (is_help(a)) {
+ print_help(&attest_help);
return 0;
} else {
pr_err("attest: unknown option '%s'", a);
@@ -739,15 +739,15 @@ static int cmd_attest_evidence(int argc, const char **argv)
if (!nonce_len)
pr_warn("attest: no --nonce; the evidence proves no freshness");
if (challenge_path &&
- shirudo_attest_challenge_read(challenge_path, &challenge)) {
+ attest_challenge_read(challenge_path, &challenge)) {
pr_err("attest: %s is not a shirudo credential challenge",
challenge_path);
return 2;
}
- rc = shirudo_attest_evidence(nonce, nonce_len, mask,
- challenge_path ? &challenge : NULL, &doc,
- &len, &cap);
+ rc = attest_evidence(nonce, nonce_len, mask,
+ challenge_path ? &challenge : NULL, &doc,
+ &len, &cap);
if (rc == -ENODEV) {
pr_err("attest: no bound register (tpm_error); run shirudo "
"init first");
@@ -765,8 +765,8 @@ static int cmd_attest_evidence(int argc, const char **argv)
int fd = open(out_path,
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
- if (fd < 0 || shirudo_write_all(fd, doc, len) ||
- shirudo_write_all(fd, "\n", 1) || close(fd)) {
+ if (fd < 0 || write_all(fd, doc, len) ||
+ write_all(fd, "\n", 1) || close(fd)) {
pr_err("attest: write %s: %s", out_path,
strerror(errno));
if (fd >= 0)
@@ -783,21 +783,21 @@ static int cmd_attest_evidence(int argc, const char **argv)
int cmd_attest(int argc, const char **argv)
{
- if (argc >= 2 && shirudo_is_help(argv[1])) {
- shirudo_print_help(&attest_help);
+ if (argc >= 2 && is_help(argv[1])) {
+ print_help(&attest_help);
return 0;
}
- if (argc >= 2 && shirudo_is_list_cmds(argv[1])) {
- shirudo_print_subcmd_list(attest_subcmds,
- ARRAY_SIZE(attest_subcmds));
+ if (argc >= 2 && is_list_cmds(argv[1])) {
+ print_subcmd_list(attest_subcmds,
+ ARRAY_SIZE(attest_subcmds));
return 0;
}
if (argc >= 2 && argv[1][0] != '-') {
const char *sub;
- sub = shirudo_resolve_subcommand("attest", argv[1],
- attest_subcmds,
- ARRAY_SIZE(attest_subcmds));
+ sub = resolve_subcommand("attest", argv[1],
+ attest_subcmds,
+ ARRAY_SIZE(attest_subcmds));
if (!sub)
return 2;
diff --git a/builtin-bpm.c b/builtin-bpm.c
index 96a7694f..b2455372 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -233,14 +233,14 @@ static int copy_file_ex(const char *src, const char *dst, mode_t mode,
close(in);
return exclusive ? -EEXIST : 0;
}
- out = shirudo_seal_open(dst, O_WRONLY | O_CREAT |
- (exclusive ? O_EXCL : O_TRUNC), mode);
+ out = seal_open(dst, O_WRONLY | O_CREAT |
+ (exclusive ? O_EXCL : O_TRUNC), mode);
if (out < 0) {
close(in);
return out;
}
while ((n = read(in, buf, sizeof(buf))) > 0) {
- rc = shirudo_write_all(out, buf, (size_t)n);
+ rc = write_all(out, buf, (size_t)n);
if (rc)
break;
}
@@ -282,15 +282,15 @@ static int load_source(const char *name, struct bpm_source *s)
fp = fopen(path, "r");
if (!fp)
return -errno;
- if (shirudo_check_trusted(fileno(fp), path, false)) {
+ if (check_trusted(fileno(fp), path, false)) {
fclose(fp);
return -EPERM;
}
snprintf(s->name, sizeof(s->name), "%s", name);
while (fgets(line, sizeof(line), fp)) {
- rc = shirudo_bpm_parse_source_line(line,
- s->endpoint, sizeof(s->endpoint),
- s->key_file, sizeof(s->key_file));
+ rc = bpm_parse_source_line(line,
+ s->endpoint, sizeof(s->endpoint),
+ s->key_file, sizeof(s->key_file));
if (rc) {
fclose(fp);
return rc;
@@ -312,17 +312,17 @@ static int save_source(const struct bpm_source *s)
if (snprintf(data, sizeof(data), "endpoint = %s\nkey_file = %s\n",
s->endpoint, s->key_file) >= (int)sizeof(data))
return -E2BIG;
- return shirudo_seal_write_file(path, data, strlen(data), 0644);
+ return seal_write_file(path, data, strlen(data), 0644);
}
static int with_bpm_lock(void)
{
int fd, rc;
- rc = shirudo_seal_mkdir_p(SHIRUDO_LOCKS_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_LOCKS_DIR, 0700);
if (rc)
return rc;
- fd = shirudo_seal_open(SHIRUDO_BPM_LOCK_PATH, O_RDWR | O_CREAT, 0600);
+ fd = seal_open(SHIRUDO_BPM_LOCK_PATH, O_RDWR | O_CREAT, 0600);
if (fd < 0)
return fd;
if (flock(fd, LOCK_EX)) {
@@ -359,24 +359,24 @@ static int sha256_file_hex(const char *path, char *hex, size_t hex_sz)
ssize_t nr;
int fd, rc = -EIO;
- if (hex_sz < 65 || shirudo_sha256_init(&ctx) != 0)
+ if (hex_sz < 65 || sha256_init(&ctx) != 0)
return -EINVAL;
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
- shirudo_sha256_free(&ctx);
+ sha256_free(&ctx);
return -errno;
}
while ((nr = read(fd, buf, sizeof(buf))) > 0) {
- if (shirudo_sha256_update(&ctx, buf, (size_t)nr) != 0)
+ if (sha256_update(&ctx, buf, (size_t)nr) != 0)
goto done;
}
- if (nr < 0 || shirudo_sha256_final(&ctx, digest) != 0)
+ if (nr < 0 || sha256_final(&ctx, digest) != 0)
goto done;
- shirudo_hex_encode(digest, sizeof(digest), hex);
+ hex_encode(digest, sizeof(digest), hex);
rc = 0;
done:
close(fd);
- shirudo_sha256_free(&ctx);
+ sha256_free(&ctx);
return rc;
}
@@ -414,7 +414,7 @@ static int print_package_readme(const char *source)
pr_err("bpm info: package %s does not include README.md", source);
goto out;
}
- rc = shirudo_write_all(STDOUT_FILENO, readme, readme_len);
+ rc = write_all(STDOUT_FILENO, readme, readme_len);
out:
xfree(beefile, beefile_len + 1);
xfree(readme, readme_len + 1);
@@ -429,14 +429,14 @@ static int cert_matches_active(const char *path)
__u8 da[SHIRUDO_CRYPTO_SHA256_LEN], db[SHIRUDO_CRYPTO_SHA256_LEN];
int rc = -EINVAL;
- if (!shirudo_cert_read_file(path, &a) &&
- !shirudo_cert_read_file(SHIRUDO_CERT_PATH, &b) &&
- !shirudo_cert_pubkey_digest(&a, da) &&
- !shirudo_cert_pubkey_digest(&b, db) &&
+ if (!cert_read_file(path, &a) &&
+ !cert_read_file(SHIRUDO_CERT_PATH, &b) &&
+ !cert_pubkey_digest(&a, da) &&
+ !cert_pubkey_digest(&b, db) &&
!memcmp(da, db, sizeof(da)))
rc = 0;
- shirudo_cert_free(&a);
- shirudo_cert_free(&b);
+ cert_free(&a);
+ cert_free(&b);
return rc;
}
@@ -446,10 +446,10 @@ static int key_file_fingerprint(const char *path, char hex[65])
__u8 digest[SHIRUDO_CRYPTO_SHA256_LEN];
int rc;
- rc = shirudo_cert_read_file(path, &cert);
+ rc = cert_read_file(path, &cert);
if (!rc)
- rc = shirudo_cert_pubkey_digest(&cert, digest);
- shirudo_cert_free(&cert);
+ rc = cert_pubkey_digest(&cert, digest);
+ cert_free(&cert);
if (rc)
return rc;
for (size_t i = 0; i < sizeof(digest); i++)
@@ -467,7 +467,7 @@ static int install_key_file(const char *src)
rc = key_file_fingerprint(src, hex);
if (rc)
return rc;
- rc = shirudo_seal_mkdir_p(SHIRUDO_KEYS_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_KEYS_DIR, 0700);
if (rc)
return rc;
active = lstat(SHIRUDO_CERT_PATH, &st) == 0;
@@ -498,7 +498,7 @@ static int install_key_file(const char *src)
return -errno;
return cert_matches_active(src) ? -EPERM : 0;
}
- return shirudo_seal_inherit_path(SHIRUDO_CERT_PATH);
+ return seal_inherit_path(SHIRUDO_CERT_PATH);
}
static int extract_package_cert(const char *archive, char *out, size_t out_sz)
@@ -520,7 +520,7 @@ static int extract_package_cert(const char *archive, char *out, size_t out_sz)
xfree(body, len + 1);
return -errno;
}
- rc = shirudo_write_all(fd, body, len);
+ rc = write_all(fd, body, len);
if (close(fd) && !rc)
rc = -errno;
xfree(body, len + 1);
@@ -658,8 +658,8 @@ static int state_read(struct bpm_state_entry *st, int *n)
struct shirudo_json_field sub[4], root[1];
__s64 unused = 0;
- rc = shirudo_read_file(SHIRUDO_BPM_STATE_PATH, 8u * 1024u * 1024u,
- &body, &len);
+ rc = read_file(SHIRUDO_BPM_STATE_PATH, 8u * 1024u * 1024u,
+ &body, &len);
if (rc == -ENOENT) {
*n = 0;
return 0;
@@ -689,7 +689,7 @@ static int state_read(struct bpm_state_entry *st, int *n)
.dst = &arr, .sub = sub, .n_sub = ARRAY_SIZE(sub),
};
(void)unused;
- rc = shirudo_json_parse((const char *)body, len, root, ARRAY_SIZE(root));
+ rc = json_parse((const char *)body, len, root, ARRAY_SIZE(root));
xfree(body, len + 1);
if (rc || !root[0].seen)
return rc ? rc : -EINVAL;
@@ -703,25 +703,25 @@ static int state_write(const struct bpm_state_entry *st, int n)
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
int rc;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_arr_open(&e, "packages");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_arr_open(&e, "packages");
for (int i = 0; i < n; i++) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", st[i].name);
- shirudo_json_kv_string(&e, "version", st[i].version);
- shirudo_json_kv_string(&e, "source", st[i].source);
- shirudo_json_kv_string(&e, "path", st[i].path);
- shirudo_json_obj_close(&e);
- }
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "name", st[i].name);
+ json_kv_string(&e, "version", st[i].version);
+ json_kv_string(&e, "source", st[i].source);
+ json_kv_string(&e, "path", st[i].path);
+ json_obj_close(&e);
+ }
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err)
return -E2BIG;
- rc = shirudo_seal_mkdir_p(SHIRUDO_BPM_VAR_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_BPM_VAR_DIR, 0700);
if (!rc)
- rc = shirudo_seal_write_file(SHIRUDO_BPM_STATE_PATH, buf, e.len,
- 0600);
+ rc = seal_write_file(SHIRUDO_BPM_STATE_PATH, buf, e.len,
+ 0600);
return rc;
}
@@ -735,7 +735,7 @@ static int load_cached_index(const char *source, struct bpm_index_entry *entries
rc = cache_path(source, path, sizeof(path));
if (rc)
return rc;
- rc = shirudo_read_file(path, 64u * 1024u * 1024u, &body, &len);
+ rc = read_file(path, 64u * 1024u * 1024u, &body, &len);
if (rc)
return rc;
rc = bpm_index_parse(body, len, entries, n);
@@ -827,13 +827,13 @@ static int repo_update_one(const char *name)
rc = -ENAMETOOLONG;
goto out;
}
- rc = shirudo_seal_mkdir_p(dir, 0700);
+ rc = seal_mkdir_p(dir, 0700);
if (rc)
goto out;
rc = cache_path(name, cache, sizeof(cache));
if (rc)
goto out;
- rc = shirudo_seal_write_file(cache, index.data, index.len, 0600);
+ rc = seal_write_file(cache, index.data, index.len, 0600);
out:
bpm_buffer_free(&manifest);
bpm_buffer_free(&index);
@@ -956,7 +956,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
rc = -ENAMETOOLONG;
goto out;
}
- rc = shirudo_seal_mkdir_p(dir, 0700);
+ rc = seal_mkdir_p(dir, 0700);
if (rc)
goto out;
if (snprintf(package_dir, sizeof(package_dir), "%s/%s", dir,
@@ -964,7 +964,7 @@ static int package_install(const struct bpm_source *s, const struct bpm_index_en
rc = -ENAMETOOLONG;
goto out;
}
- rc = shirudo_seal_mkdir_p(SHIRUDO_BPM_STAGING_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_BPM_STAGING_DIR, 0700);
if (rc)
goto out;
if (snprintf(archive, sizeof(archive), "%s/%s-%s.bee",
@@ -1188,7 +1188,7 @@ static int cmd_bpm_config(int argc, const char **argv)
{
const char *op = argc > 1 ? argv[1] : NULL;
- if (!op || shirudo_is_help(op)) {
+ if (!op || is_help(op)) {
fprintf(stderr, "usage: shirudo bpm config register {add|list|remove} ...\n");
return op ? 0 : 2;
}
@@ -1240,16 +1240,16 @@ static int cmd_bpm_config(int argc, const char **argv)
else if (!strcmp(argv[i], "--key-file") && i + 1 < argc)
key = argv[++i];
}
- if (!key || shirudo_cert_read_file(key, &cert) ||
+ if (!key || cert_read_file(key, &cert) ||
!bpm_name_ok(s.name) ||
bpm_oci_parse_endpoint(s.endpoint, &(struct bpm_oci_client){})) {
- shirudo_cert_free(&cert);
+ cert_free(&cert);
pr_err("bpm: register add requires a valid oci:// endpoint and --key-file certificate");
return 2;
}
- shirudo_cert_free(&cert);
- if (shirudo_seal_mkdir_p(SHIRUDO_BPM_REGISTRIES_DIR, 0700) ||
- shirudo_seal_mkdir_p(SHIRUDO_BPM_KEYS_DIR, 0700))
+ cert_free(&cert);
+ if (seal_mkdir_p(SHIRUDO_BPM_REGISTRIES_DIR, 0700) ||
+ seal_mkdir_p(SHIRUDO_BPM_KEYS_DIR, 0700))
return 1;
if (snprintf(managed, sizeof(managed), "%s/%s.der",
SHIRUDO_BPM_KEYS_DIR, s.name) >= (int)sizeof(managed))
@@ -1278,15 +1278,15 @@ static int load_tree_config(struct bpm_tree_config *cfg)
fp = fopen(SHIRUDO_BPM_TREE_ETC_PATH, "r");
if (!fp)
return -errno;
- if (shirudo_check_trusted(fileno(fp), SHIRUDO_BPM_TREE_ETC_PATH, false)) {
+ if (check_trusted(fileno(fp), SHIRUDO_BPM_TREE_ETC_PATH, false)) {
fclose(fp);
return -EPERM;
}
while (fgets(line, sizeof(line), fp)) {
- if (shirudo_bpm_parse_tree_line(line, cfg->endpoint,
- sizeof(cfg->endpoint),
- cfg->reference,
- sizeof(cfg->reference))) {
+ if (bpm_parse_tree_line(line, cfg->endpoint,
+ sizeof(cfg->endpoint),
+ cfg->reference,
+ sizeof(cfg->reference))) {
fclose(fp);
return -EINVAL;
}
@@ -1301,7 +1301,7 @@ static int tree_digest_hex(const char *digest, __u8 out[32])
{
if (!digest || strncmp(digest, "sha256:", 7))
return -EINVAL;
- return shirudo_hex_decode(digest + 7, out, 32);
+ return hex_decode(digest + 7, out, 32);
}
static bool tree_digest_valid(const char *digest)
@@ -1315,7 +1315,7 @@ static bool tree_tpm_available(void)
{
__u8 value[32];
- return !shirudo_chain_read(value);
+ return !chain_read(value);
}
static int tree_fetch_publication(const struct bpm_tree_config *cfg,
@@ -1340,18 +1340,18 @@ static int tree_verify_upatch(const char *path, const char *expected,
struct shirudo_upatch u;
char name[SHIRUDO_UPATCH_NAME_MAX + 1];
char actual[65];
- int rc = shirudo_upatch_open(path, &u);
+ int rc = upatch_open(path, &u);
if (rc)
return rc;
memcpy(name, u.hdr.name, SHIRUDO_UPATCH_NAME_MAX);
name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
- shirudo_hex_encode(u.hdr.payload_sha256, 32, actual);
+ hex_encode(u.hdr.payload_sha256, 32, actual);
if (!bpm_digest_matches(expected, actual) ||
(id && strcmp(name, id)) ||
- shirudo_upatch_is_unload(&u) != unload)
+ upatch_is_unload(&u) != unload)
rc = -EKEYREJECTED;
- shirudo_upatch_close(&u);
+ upatch_close(&u);
return rc;
}
@@ -1420,10 +1420,10 @@ static int tree_pull_artifact(const struct shirudo_tree_operation *op,
rc = -EKEYREJECTED;
if (rc)
goto out;
- rc = shirudo_seal_mkdir_p(SHIRUDO_BPM_TREE_ARTIFACTS_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_BPM_TREE_ARTIFACTS_DIR, 0700);
if (rc)
goto out;
- rc = shirudo_seal_write_file(cache, blob.data, blob.len, 0600);
+ rc = seal_write_file(cache, blob.data, blob.len, 0600);
if (rc)
goto out;
bpm_copy_string(path, path_sz, cache);
@@ -1446,25 +1446,25 @@ static int tree_write_report(const char *path, const struct shirudo_tree_state *
char buf[4096];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_bool(&e, "dry_run", dry_run);
- shirudo_json_kv_int(&e, "selected", selected);
- shirudo_json_kv_int(&e, "skipped", skipped);
- shirudo_json_kv_int(&e, "applied", applied);
- shirudo_json_kv_int(&e, "module_skipped", module_skipped);
- shirudo_json_kv_bool(&e, "tpm_available", tpm_available);
- shirudo_json_kv_int(&e, "last_seq", s->last_seq);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_bool(&e, "dry_run", dry_run);
+ json_kv_int(&e, "selected", selected);
+ json_kv_int(&e, "skipped", skipped);
+ json_kv_int(&e, "applied", applied);
+ json_kv_int(&e, "module_skipped", module_skipped);
+ json_kv_bool(&e, "tpm_available", tpm_available);
+ json_kv_int(&e, "last_seq", s->last_seq);
if (tpm_available)
- shirudo_json_kv_string(&e, "projection_root_tpm",
- s->projection_root_tpm);
+ json_kv_string(&e, "projection_root_tpm",
+ s->projection_root_tpm);
else
- shirudo_json_kv_null(&e, "projection_root_tpm");
- shirudo_json_obj_close(&e);
+ json_kv_null(&e, "projection_root_tpm");
+ json_obj_close(&e);
if (e.err)
return e.err;
if (path)
- return shirudo_seal_write_file(path, buf, e.len, 0600);
+ return seal_write_file(path, buf, e.len, 0600);
printf("%s\n", buf);
return 0;
}
@@ -1474,18 +1474,18 @@ static int tree_write_pending(const struct shirudo_tree_operation *op)
char buf[1024];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_int(&e, "seq", op->seq);
- shirudo_json_kv_string(&e, "id", op->id);
- shirudo_json_kv_string(&e, "operation_digest", op->operation_digest);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_int(&e, "seq", op->seq);
+ json_kv_string(&e, "id", op->id);
+ json_kv_string(&e, "operation_digest", op->operation_digest);
+ json_obj_close(&e);
if (e.err)
return e.err;
- if (shirudo_seal_mkdir_p(SHIRUDO_BPM_TREE_VAR_DIR, 0700))
+ if (seal_mkdir_p(SHIRUDO_BPM_TREE_VAR_DIR, 0700))
return -errno;
- return shirudo_seal_write_file(SHIRUDO_BPM_TREE_PENDING_PATH, buf,
- e.len, 0600);
+ return seal_write_file(SHIRUDO_BPM_TREE_PENDING_PATH, buf,
+ e.len, 0600);
}
static int tree_status_write(const char *id, const char *status)
@@ -1493,22 +1493,22 @@ static int tree_status_write(const char *id, const char *status)
char path[PATH_MAX];
int rc;
- if (!id || !shirudo_upatch_name_valid(id) || !status || !status[0])
+ if (!id || !upatch_name_valid(id) || !status || !status[0])
return -EINVAL;
- rc = shirudo_seal_mkdir_p(SHIRUDO_BPM_TREE_STATUS_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_BPM_TREE_STATUS_DIR, 0700);
if (rc)
return rc;
if (snprintf(path, sizeof(path), "%s/%s",
SHIRUDO_BPM_TREE_STATUS_DIR, id) >= (int)sizeof(path))
return -ENAMETOOLONG;
- return shirudo_seal_write_file(path, status, strlen(status), 0600);
+ return seal_write_file(path, status, strlen(status), 0600);
}
static void tree_status_clear(const char *id)
{
char path[PATH_MAX];
- if (!id || !shirudo_upatch_name_valid(id) ||
+ if (!id || !upatch_name_valid(id) ||
snprintf(path, sizeof(path), "%s/%s",
SHIRUDO_BPM_TREE_STATUS_DIR, id) >= (int)sizeof(path))
return;
@@ -1535,13 +1535,13 @@ static int tree_read_pending(struct bpm_tree_pending *pending)
pending->operation_digest, sizeof(pending->operation_digest),
0, NULL, 0 },
};
- int rc = shirudo_read_file(SHIRUDO_BPM_TREE_PENDING_PATH, 64u * 1024u,
- &body, &len);
+ int rc = read_file(SHIRUDO_BPM_TREE_PENDING_PATH, 64u * 1024u,
+ &body, &len);
if (rc)
return rc;
- rc = shirudo_json_parse((const char *)body, len, fields, ARRAY_SIZE(fields));
+ rc = json_parse((const char *)body, len, fields, ARRAY_SIZE(fields));
if (!rc && (schema != 1 || pending->seq <= 0 ||
- !shirudo_upatch_name_valid(pending->id) ||
+ !upatch_name_valid(pending->id) ||
!tree_digest_valid(pending->operation_digest)))
rc = -EINVAL;
xfree(body, len + 1);
@@ -1562,36 +1562,36 @@ static int tree_measure_operation(const struct shirudo_tree_operation *op,
char digest_hex[65], chain_hex[65];
int rc;
- shirudo_chain_tree_event(op->seq, operation_digest, event);
- rc = shirudo_chain_extend(event, chain);
+ chain_tree_event(op->seq, operation_digest, event);
+ rc = chain_extend(event, chain);
if (rc)
return rc;
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_hex_encode(event, 32, digest_hex);
- shirudo_hex_encode(chain, 32, chain_hex);
+ hex_encode(event, 32, digest_hex);
+ hex_encode(chain, 32, chain_hex);
e = (struct shirudo_json_emit){ .buf = line, .cap = sizeof(line) };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_json_kv_string(&e, "digest", digest_hex);
- shirudo_json_kv_string(&e, "type", "tree_op");
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_obj_open_key(&e, "tree");
- shirudo_json_kv_int(&e, "seq", op->seq);
- shirudo_json_kv_string(&e, "op", op->op);
- shirudo_json_kv_string(&e, "id", op->id);
- shirudo_json_kv_string(&e, "operation_digest", op->operation_digest);
- shirudo_json_obj_close(&e);
- shirudo_json_kv_string(&e, "chain", chain_hex);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ json_kv_string(&e, "digest", digest_hex);
+ json_kv_string(&e, "type", "tree_op");
+ json_kv_string(&e, "boot_id", boot_id);
+ json_obj_open_key(&e, "tree");
+ json_kv_int(&e, "seq", op->seq);
+ json_kv_string(&e, "op", op->op);
+ json_kv_string(&e, "id", op->id);
+ json_kv_string(&e, "operation_digest", op->operation_digest);
+ json_obj_close(&e);
+ json_kv_string(&e, "chain", chain_hex);
+ json_obj_close(&e);
if (e.err)
return e.err;
- return shirudo_eventlog_append(line);
+ return eventlog_append(line);
}
/*
@@ -1628,16 +1628,16 @@ static int tree_recover_pending(const struct shirudo_tree_publication *pub,
return 0;
}
if (tree_digest_hex(pending.operation_digest, digest) ||
- shirudo_hex_decode(state->projection_root, previous, 32))
+ hex_decode(state->projection_root, previous, 32))
return -EINVAL;
- shirudo_sha256_2(previous, sizeof(previous), digest, sizeof(digest), next);
+ sha256_2(previous, sizeof(previous), digest, sizeof(digest), next);
- rc = shirudo_tree_event_replay(replay);
+ rc = tree_event_replay(replay);
if (!rc) {
- if (shirudo_ct_eq(replay, next, sizeof(replay))) {
+ if (ct_eq(replay, next, sizeof(replay))) {
applied = true;
event_present = true;
- } else if (!shirudo_ct_eq(replay, previous, sizeof(replay))) {
+ } else if (!ct_eq(replay, previous, sizeof(replay))) {
return -EKEYREJECTED;
}
} else if (rc != -ENOENT) {
@@ -1647,14 +1647,14 @@ static int tree_recover_pending(const struct shirudo_tree_publication *pub,
if (!applied)
return 0;
if (!event_present) {
- rc = shirudo_tree_event_append(op->seq, op->operation_digest, next);
+ rc = tree_event_append(op->seq, op->operation_digest, next);
if (rc)
return rc;
}
- shirudo_hex_encode(next, sizeof(next), state->projection_root);
- shirudo_hex_encode(next, sizeof(next), state->projection_root_tpm);
+ hex_encode(next, sizeof(next), state->projection_root);
+ hex_encode(next, sizeof(next), state->projection_root_tpm);
state->last_seq = op->seq;
- rc = shirudo_tree_state_write(state);
+ rc = tree_state_write(state);
if (rc)
return rc;
(void)unlink(SHIRUDO_BPM_TREE_PENDING_PATH);
@@ -1666,7 +1666,7 @@ static int tree_validate_operation(const struct shirudo_tree_operation *op)
__u8 digest[32];
char expected_digest[72];
- if (!op || op->seq <= 0 || !shirudo_upatch_name_valid(op->id) ||
+ if (!op || op->seq <= 0 || !upatch_name_valid(op->id) ||
(strcmp(op->op, "add") && strcmp(op->op, "delete")))
return -EINVAL;
if (tree_digest_hex(op->operation_digest, digest) ||
@@ -1674,7 +1674,7 @@ static int tree_validate_operation(const struct shirudo_tree_operation *op)
tree_digest_hex(op->artifact.layer_digest, digest) ||
tree_digest_hex(op->artifact.payload_sha256, digest))
return -EINVAL;
- if (shirudo_tree_operation_digest(op, expected_digest))
+ if (tree_operation_digest(op, expected_digest))
return -EINVAL;
if (strcmp(op->operation_digest, expected_digest))
return -EKEYREJECTED;
@@ -1734,7 +1734,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
bpm_copy_string(report, sizeof(report), argv[i] + 9);
} else if (!strcmp(argv[i], "--report") && i + 1 < argc) {
bpm_copy_string(report, sizeof(report), argv[++i]);
- } else if (shirudo_is_help(argv[i])) {
+ } else if (is_help(argv[i])) {
printf("usage: shirudo bpm tree sync [--dry-run] [--report=<path>]\n");
rc = 0;
goto out;
@@ -1751,7 +1751,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
}
if (rc)
goto out;
- rc = shirudo_tree_state_read(&state);
+ rc = tree_state_read(&state);
if (!rc)
have_state = true;
else if (rc != -ENOENT)
@@ -1844,7 +1844,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
if (op->seq <= state.last_seq)
continue;
- rc = shirudo_tree_selector_matches(&op->selector);
+ rc = tree_selector_matches(&op->selector);
if (rc < 0) {
tree_sync_report_error("selector_evaluate", op, rc);
goto out;
@@ -1900,7 +1900,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
tree_sync_report_error("upatch_install", op, rc);
goto out;
}
- if (shirudo_hex_decode(state.projection_root, previous, 32)) {
+ if (hex_decode(state.projection_root, previous, 32)) {
tree_sync_report_error("projection_root_decode", op, -EINVAL);
rc = -EINVAL;
goto out;
@@ -1910,17 +1910,17 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
tree_sync_report_error("register_extend", op, rc);
goto out;
}
- shirudo_sha256_2(previous, 32, digest, 32, next);
- shirudo_hex_encode(next, 32, state.projection_root);
- shirudo_hex_encode(next, 32, state.projection_root_tpm);
- rc = shirudo_tree_event_append(op->seq, op->operation_digest, next);
+ sha256_2(previous, 32, digest, 32, next);
+ hex_encode(next, 32, state.projection_root);
+ hex_encode(next, 32, state.projection_root_tpm);
+ rc = tree_event_append(op->seq, op->operation_digest, next);
if (rc) {
tree_sync_report_error("tree_event_append", op, rc);
goto out;
}
state.last_seq = op->seq;
applied++;
- rc = shirudo_tree_state_write(&state);
+ rc = tree_state_write(&state);
if (rc) {
tree_sync_report_error("tree_state_commit", op, rc);
goto out;
@@ -1941,7 +1941,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
manifest_digest);
if (!state.tree_id[0])
bpm_copy_string(state.tree_id, sizeof(state.tree_id), pub.tree_id);
- rc = shirudo_tree_state_write(&state);
+ rc = tree_state_write(&state);
if (rc) {
tree_sync_report_error("tree_state_commit_final", NULL, rc);
goto out;
@@ -1952,7 +1952,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
&state, selected, skipped, applied,
module_skipped, dry_run, tpm_available);
out:
- shirudo_tree_publication_free(&pub);
+ tree_publication_free(&pub);
return rc;
}
@@ -2179,26 +2179,26 @@ static int cmd_bpm_key(int argc, const char **argv)
const char *sub, *src;
int rc;
- if (argc < 2 || shirudo_is_help(argv[1])) {
- shirudo_print_help(&bpm_key_help);
+ if (argc < 2 || is_help(argv[1])) {
+ print_help(&bpm_key_help);
return argc < 2 ? 2 : 0;
}
- if (shirudo_is_list_cmds(argv[1])) {
- shirudo_print_subcmd_list(bpm_key_subcmds,
- ARRAY_SIZE(bpm_key_subcmds));
+ if (is_list_cmds(argv[1])) {
+ print_subcmd_list(bpm_key_subcmds,
+ ARRAY_SIZE(bpm_key_subcmds));
return 0;
}
- sub = shirudo_resolve_subcommand("bpm key", argv[1], bpm_key_subcmds,
- ARRAY_SIZE(bpm_key_subcmds));
+ sub = resolve_subcommand("bpm key", argv[1], bpm_key_subcmds,
+ ARRAY_SIZE(bpm_key_subcmds));
if (!sub)
return 2;
- if (argc == 3 && shirudo_is_help(argv[2])) {
- shirudo_print_help(&bpm_key_help);
+ if (argc == 3 && is_help(argv[2])) {
+ print_help(&bpm_key_help);
return 0;
}
if ((!strcmp(sub, "list") && argc != 2) ||
(strcmp(sub, "list") && argc != 3)) {
- shirudo_print_help(&bpm_key_help);
+ print_help(&bpm_key_help);
return 2;
}
if (!strcmp(sub, "list")) {
@@ -2234,16 +2234,16 @@ int cmd_bpm(int argc, const char **argv)
ARRAY_SIZE(bpm_target_subcmds);
const char *sub;
- if (argc < 2 || shirudo_is_help(argv[1])) {
- shirudo_print_help(help);
+ if (argc < 2 || is_help(argv[1])) {
+ print_help(help);
return argc < 2 ? 2 : 0;
}
- if (shirudo_is_list_cmds(argv[1])) {
- shirudo_print_subcmd_list(subcmds, n_subcmds);
+ if (is_list_cmds(argv[1])) {
+ print_subcmd_list(subcmds, n_subcmds);
return 0;
}
- sub = shirudo_resolve_subcommand("shirudo bpm", argv[1], subcmds,
- n_subcmds);
+ sub = resolve_subcommand("shirudo bpm", argv[1], subcmds,
+ n_subcmds);
if (!sub)
return 2;
if (!strcmp(sub, "config"))
@@ -2251,7 +2251,7 @@ int cmd_bpm(int argc, const char **argv)
if (!strcmp(sub, "info")) {
int rc;
- if (argc == 3 && shirudo_is_help(argv[2])) {
+ if (argc == 3 && is_help(argv[2])) {
bpm_info_usage();
return 0;
}
@@ -2264,7 +2264,7 @@ int cmd_bpm(int argc, const char **argv)
rc = print_package_readme(argv[2]);
return bpm_finish(-1, rc, "info");
}
- if (!strcmp(sub, "tree") && (argc < 3 || shirudo_is_help(argv[2]))) {
+ if (!strcmp(sub, "tree") && (argc < 3 || is_help(argv[2]))) {
bpm_tree_usage();
return argc < 3 ? 2 : 0;
}
@@ -2279,7 +2279,7 @@ int cmd_bpm(int argc, const char **argv)
if (!strcmp(sub, "pull")) {
int rc;
- if (argc == 3 && shirudo_is_help(argv[2])) {
+ if (argc == 3 && is_help(argv[2])) {
bpm_pull_usage();
return 0;
}
@@ -2336,7 +2336,7 @@ int cmd_bpm(int argc, const char **argv)
if (argc > 6)
return 2;
- if (argc == 4 && shirudo_is_help(argv[3])) {
+ if (argc == 4 && is_help(argv[3])) {
bpm_tree_usage();
return 0;
}
@@ -2426,7 +2426,7 @@ int cmd_bpm(int argc, const char **argv)
if (argc != 2) {
fprintf(stderr, "usage: shirudo bpm list\n");
- return argc == 3 && shirudo_is_help(argv[2]) ? 0 : 2;
+ return argc == 3 && is_help(argv[2]) ? 0 : 2;
}
state = xcalloc(BPM_MAX_STATE, sizeof(*state));
if (!state)
@@ -2442,7 +2442,7 @@ int cmd_bpm(int argc, const char **argv)
struct bpm_state_entry *state;
int n_state, lock, rc, i;
- if (argc != 3 || shirudo_is_help(argv[2])) {
+ if (argc != 3 || is_help(argv[2])) {
fprintf(stderr, "usage: shirudo bpm uninstall <package>\n");
return argc == 3 ? 0 : 2;
}
diff --git a/builtin-build.c b/builtin-build.c
index e4467921..c017ce15 100644
--- a/builtin-build.c
+++ b/builtin-build.c
@@ -112,8 +112,8 @@ int shirudo_build_exec(const char *label, char **argv)
int cmd_build(int argc, const char **argv)
{
- if (argc >= 2 && shirudo_is_help(argv[1])) {
- shirudo_print_help(&build_help);
+ if (argc >= 2 && is_help(argv[1])) {
+ print_help(&build_help);
return 0;
}
return shirudo_build_exec("build", (char **)argv);
diff --git a/builtin-config.c b/builtin-config.c
index 9ae2b0ee..df19429c 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -43,8 +43,8 @@ int cmd_config(int argc, const char **argv)
int i;
for (i = 1; i < argc; i++) {
- if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&config_help);
+ if (is_help(argv[i])) {
+ print_help(&config_help);
return 0;
}
pr_err("config: unknown option '%s'", argv[i]);
@@ -53,7 +53,7 @@ int cmd_config(int argc, const char **argv)
}
file_present = access(SHIRUDO_CONF_PATH, F_OK) == 0;
- rc = shirudo_config_load(&cfg);
+ rc = config_load(&cfg);
if (rc && rc != -ENOENT) {
pr_err("config: load %s: %s",
SHIRUDO_CONF_PATH, strerror(-rc));
diff --git a/builtin-genkey.c b/builtin-genkey.c
index a194c664..5a2c31c2 100644
--- a/builtin-genkey.c
+++ b/builtin-genkey.c
@@ -53,7 +53,7 @@ static int ensure_keys_dir(const char *keys_dir)
pr_err("keys dir cannot be /");
return -EINVAL;
}
- rc = shirudo_seal_mkdir_p(keys_dir, 0700);
+ rc = seal_mkdir_p(keys_dir, 0700);
if (rc)
pr_err("mkdir %s: %s", keys_dir, strerror(-rc));
return rc;
@@ -64,7 +64,7 @@ static EVP_PKEY *gen_keypair(void)
EVP_PKEY *k = EVP_PKEY_Q_keygen(NULL, NULL, GENKEY_ALG);
if (!k) {
- shirudo_openssl_complain("EVP_PKEY_Q_keygen");
+ openssl_complain("EVP_PKEY_Q_keygen");
if (OPENSSL_version_major() < 3 ||
(OPENSSL_version_major() == 3 &&
OPENSSL_version_minor() < 5))
@@ -82,11 +82,11 @@ static int set_subject_and_issuer(X509 *c)
if (X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8,
(const __u8 *)CERT_CN,
-1, -1, 0) != 1) {
- shirudo_openssl_complain("X509_NAME_add_entry_by_txt");
+ openssl_complain("X509_NAME_add_entry_by_txt");
return -1;
}
if (X509_set_issuer_name(c, name) != 1) {
- shirudo_openssl_complain("X509_set_issuer_name");
+ openssl_complain("X509_set_issuer_name");
return -1;
}
return 0;
@@ -103,13 +103,13 @@ static int add_ext(X509 *c, int nid, const char *value)
ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, value);
if (!ex) {
- shirudo_openssl_complain("X509V3_EXT_conf_nid");
+ openssl_complain("X509V3_EXT_conf_nid");
return -1;
}
rc = X509_add_ext(c, ex, -1);
X509_EXTENSION_free(ex);
if (rc != 1) {
- shirudo_openssl_complain("X509_add_ext");
+ openssl_complain("X509_add_ext");
return -1;
}
return 0;
@@ -118,7 +118,7 @@ static int add_ext(X509 *c, int nid, const char *value)
static int build_serial(X509 *c)
{
if (ASN1_INTEGER_set(X509_get_serialNumber(c), 1) != 1) {
- shirudo_openssl_complain("ASN1_INTEGER_set");
+ openssl_complain("ASN1_INTEGER_set");
return -1;
}
return 0;
@@ -127,12 +127,12 @@ static int build_serial(X509 *c)
static int build_validity(X509 *c)
{
if (!X509_gmtime_adj(X509_getm_notBefore(c), 0)) {
- shirudo_openssl_complain("X509_gmtime_adj notBefore");
+ openssl_complain("X509_gmtime_adj notBefore");
return -1;
}
if (!X509_gmtime_adj(X509_getm_notAfter(c),
VALIDITY_DAYS * 24L * 60L * 60L)) {
- shirudo_openssl_complain("X509_gmtime_adj notAfter");
+ openssl_complain("X509_gmtime_adj notAfter");
return -1;
}
return 0;
@@ -142,7 +142,7 @@ static int build_validity(X509 *c)
static int build_cert(X509 *c, EVP_PKEY *pkey)
{
if (X509_set_version(c, 2) != 1) { /* X.509 v3 */
- shirudo_openssl_complain("X509_set_version");
+ openssl_complain("X509_set_version");
return -1;
}
if (build_serial(c) != 0)
@@ -150,7 +150,7 @@ static int build_cert(X509 *c, EVP_PKEY *pkey)
if (build_validity(c) != 0)
return -1;
if (X509_set_pubkey(c, pkey) != 1) {
- shirudo_openssl_complain("X509_set_pubkey");
+ openssl_complain("X509_set_pubkey");
return -1;
}
if (set_subject_and_issuer(c) != 0)
@@ -166,7 +166,7 @@ static int build_cert(X509 *c, EVP_PKEY *pkey)
return -1;
if (X509_sign(c, pkey, NULL) == 0) {
- shirudo_openssl_complain("X509_sign");
+ openssl_complain("X509_sign");
return -1;
}
return 0;
@@ -193,7 +193,7 @@ static int write_private_pem(EVP_PKEY *pkey, const char *path)
}
fd = -1; /* now owned by fp */
if (PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL) != 1) {
- shirudo_openssl_complain("PEM_write_PrivateKey");
+ openssl_complain("PEM_write_PrivateKey");
goto out;
}
if (fflush(fp) != 0 || fsync(fileno(fp)) != 0) {
@@ -227,11 +227,11 @@ static int write_cert_der(X509 *c, const char *path)
}
bio = BIO_new_fd(fd, BIO_NOCLOSE);
if (!bio) {
- shirudo_openssl_complain("BIO_new_fd");
+ openssl_complain("BIO_new_fd");
goto out;
}
if (i2d_X509_bio(bio, c) != 1) {
- shirudo_openssl_complain("i2d_X509_bio");
+ openssl_complain("i2d_X509_bio");
goto out;
}
if (fsync(fd) != 0) {
@@ -299,8 +299,8 @@ int cmd_genkey(int argc, const char **argv)
keys_dir_arg = argv[++i];
} else if (strncmp(argv[i], "--keys-dir=", 11) == 0) {
keys_dir_arg = argv[i] + 11;
- } else if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&genkey_help);
+ } else if (is_help(argv[i])) {
+ print_help(&genkey_help);
return 0;
} else {
pr_err("genkey: unknown option '%s'", argv[i]);
@@ -309,10 +309,10 @@ int cmd_genkey(int argc, const char **argv)
}
}
- keys_dir = shirudo_keys_dir_resolve(keys_dir_arg);
+ keys_dir = keys_dir_resolve(keys_dir_arg);
- rc = shirudo_key_paths(keys_dir, pkey_path, sizeof(pkey_path),
- cert_path, sizeof(cert_path));
+ rc = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
+ cert_path, sizeof(cert_path));
if (rc) {
pr_err("genkey: invalid keys dir %s: %s",
keys_dir, strerror(-rc));
@@ -330,8 +330,8 @@ int cmd_genkey(int argc, const char **argv)
return 1;
rc = 1;
- if (!force && (shirudo_path_exists(pkey_path) ||
- shirudo_path_exists(cert_path))) {
+ if (!force && (path_exists(pkey_path) ||
+ path_exists(cert_path))) {
pr_err("genkey: %s or %s already exists; pass --force",
pkey_path, cert_path);
return 1;
@@ -342,7 +342,7 @@ int cmd_genkey(int argc, const char **argv)
goto out;
cert = X509_new();
if (!cert) {
- shirudo_openssl_complain("X509_new");
+ openssl_complain("X509_new");
goto out;
}
if (build_cert(cert, pkey) != 0)
diff --git a/builtin-init.c b/builtin-init.c
index f8cf198f..241e5c3f 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -117,7 +117,7 @@ static void keyring_count_asymmetric(key_serial_t serial, const char *type,
static int keyring_asymmetric_count(key_serial_t ring)
{
size_t n = 0;
- int rc = shirudo_keyring_list(ring, keyring_count_asymmetric, &n);
+ int rc = keyring_list(ring, keyring_count_asymmetric, &n);
if (rc)
return rc;
@@ -144,7 +144,7 @@ static void warn_root_keys_differ(const struct shirudo_trusted_set *set)
size_t i;
int rc;
- rc = shirudo_keys_load(SHIRUDO_KEYS_DIR, NULL, true, &root);
+ rc = keys_load(SHIRUDO_KEYS_DIR, NULL, true, &root);
if (rc) {
pr_warn("initrd: the root file system has no certificate "
"under %s (%s); the copies under %s are the anchor",
@@ -176,7 +176,7 @@ static int keyring_holds_set(key_serial_t ring,
rc = read_der(set->certs[i].path, &der, &der_sz);
if (rc)
return rc;
- rc = shirudo_keyring_holds_cert(ring, der, der_sz);
+ rc = keyring_holds_cert(ring, der, der_sz);
xfree(der, der_sz);
if (rc < 0)
return rc;
@@ -212,7 +212,7 @@ static int init_bpf_keyring(key_serial_t ring,
strerror(-rc));
return rc;
}
- key = shirudo_keyring_bpf_add_cert(der, der_sz);
+ key = keyring_bpf_add_cert(der, der_sz);
xfree(der, der_sz);
if (key >= 0) {
pr_info("bpf keyring serial=%d: %s enrolled (key "
@@ -261,7 +261,7 @@ static int init_bpf_keyring(key_serial_t ring,
(int)ring, count, count == 1 ? "" : "s", held, set->n);
return -EKEYREJECTED;
}
- rc = shirudo_keyring_bpf_seal();
+ rc = keyring_bpf_seal();
if (rc) {
pr_err("bpf keyring: certificates enrolled but the keyring "
"could not be sealed: %s", strerror(-rc));
@@ -283,8 +283,8 @@ static int init_keyring(void)
bool frozen;
int rc;
- rc = shirudo_keys_load(shirudo_keys_dir(), SHIRUDO_KEYS_REVOKED_DIR,
- true, &set);
+ rc = keys_load(shirudo_keys_dir(), SHIRUDO_KEYS_REVOKED_DIR,
+ true, &set);
if (rc) {
pr_err("read the keys under %s: %s", shirudo_keys_dir(),
strerror(-rc));
@@ -296,9 +296,9 @@ static int init_keyring(void)
set.n_revoked == 1 ? "" : "s", shirudo_keys_dir());
if (initrd_mode)
warn_root_keys_differ(&set);
- frozen = shirudo_identity_read(&id) == 0;
+ frozen = identity_read(&id) == 0;
- ring = shirudo_keyring_bpf_serial();
+ ring = keyring_bpf_serial();
if (ring > 0) {
rc = init_bpf_keyring(ring, &set);
if (rc == 0 || rc == -EEXIST) {
@@ -352,7 +352,7 @@ static int init_keyring(void)
enrolled.certs[0] = *primary;
enrolled.n = 1;
- ring = shirudo_keyring_find(SHIRUDO_KEYRING_NAME);
+ ring = keyring_find(SHIRUDO_KEYRING_NAME);
if (frozen && id.keyring_type == SHIRUDO_SIG_KEYRING_USER &&
ring != id.keyring_serial) {
pr_err("keyring \"%s\" is %s; the anchor frozen this boot is "
@@ -363,10 +363,10 @@ static int init_keyring(void)
return -EKEYREJECTED;
}
if (ring >= 0) {
- rc = shirudo_keyring_holds_cert(ring, der, der_sz);
+ rc = keyring_holds_cert(ring, der, der_sz);
if (rc > 0) {
xfree(der, der_sz);
- rc = shirudo_keyring_seal(ring);
+ rc = keyring_seal(ring);
if (rc && rc != -EACCES)
pr_warn("keyring \"%s\": could not seal (mutable): %s",
SHIRUDO_KEYRING_NAME, strerror(-rc));
@@ -378,7 +378,7 @@ static int init_keyring(void)
SHIRUDO_KEYRING_NAME, (int)ring,
rc == 0 ? "does not hold the certificate" :
strerror(-rc));
- rc = shirudo_keyring_unlink_from_user(ring);
+ rc = keyring_unlink_from_user(ring);
if (rc) {
pr_err("unlink stale keyring \"%s\": %s",
SHIRUDO_KEYRING_NAME, strerror(-rc));
@@ -392,7 +392,7 @@ static int init_keyring(void)
return ring;
}
- ring = shirudo_keyring_open_or_create(SHIRUDO_KEYRING_NAME);
+ ring = keyring_open_or_create(SHIRUDO_KEYRING_NAME);
if (ring < 0) {
pr_err("open/create keyring \"%s\": %s",
SHIRUDO_KEYRING_NAME, strerror(-ring));
@@ -400,7 +400,7 @@ static int init_keyring(void)
return ring;
}
- key = shirudo_keyring_add_cert(ring, der, der_sz);
+ key = keyring_add_cert(ring, der, der_sz);
xfree(der, der_sz);
if (key < 0) {
pr_err("add cert to keyring: %s", strerror(-key));
@@ -418,7 +418,7 @@ static int init_keyring(void)
* kernel accept BPF they signed. Not fatal if it fails: the LSM
* still enforces; the keyring is just left mutable.
*/
- rc = shirudo_keyring_seal(ring);
+ rc = keyring_seal(ring);
if (rc)
pr_warn("keyring \"%s\": could not seal (mutable): %s",
SHIRUDO_KEYRING_NAME, strerror(-rc));
@@ -456,21 +456,21 @@ static int init_bpffs(void)
{
int rc;
- rc = shirudo_seal_mkdir_p(SHIRUDO_VAR_LIB, 0700);
+ rc = seal_mkdir_p(SHIRUDO_VAR_LIB, 0700);
if (rc) {
pr_err("mkdir %s: %s", SHIRUDO_VAR_LIB, strerror(-rc));
return rc;
}
- rc = shirudo_seal_mkdir_p(SHIRUDO_RUN_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_RUN_DIR, 0700);
if (rc) {
pr_err("mkdir %s: %s", SHIRUDO_RUN_DIR, strerror(-rc));
return rc;
}
/* So that the init record left here is sealed from its creation. */
- rc = shirudo_seal_label(SHIRUDO_RUN_DIR);
+ rc = seal_label(SHIRUDO_RUN_DIR);
if (rc)
pr_warn("seal: label %s: %s", SHIRUDO_RUN_DIR, strerror(-rc));
- rc = shirudo_seal_mkdir_p(SHIRUDO_BPFFS_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_BPFFS_DIR, 0700);
if (rc) {
pr_err("mkdir %s: %s",
SHIRUDO_BPFFS_DIR, strerror(-rc));
@@ -523,8 +523,8 @@ static bool binaries_differ(const char *a, const char *b)
fb = open(b, O_RDONLY | O_CLOEXEC);
if (fa < 0 || fb < 0)
goto out;
- if (shirudo_elf_build_id_fd(fa, ida, &lena) == 0 && lena &&
- shirudo_elf_build_id_fd(fb, idb, &lenb) == 0 && lenb) {
+ if (elf_build_id_fd(fa, ida, &lena) == 0 && lena &&
+ elf_build_id_fd(fb, idb, &lenb) == 0 && lenb) {
differ = lena != lenb || memcmp(ida, idb, lena) != 0;
goto out;
}
@@ -578,7 +578,7 @@ static int identity_executables(struct shirudo_identity *id)
return -errno;
}
self[n] = '\0';
- if (snprintf(root_exe, sizeof(root_exe), "%s%s", shirudo_sysroot(),
+ if (snprintf(root_exe, sizeof(root_exe), "%s%s", sysroot(),
self) >= (int)sizeof(root_exe))
return -ENAMETOOLONG;
if (stat(root_exe, &st) != 0) {
@@ -648,7 +648,7 @@ static const struct {
static int attach_seal(struct bpf_object **obj_out, struct bpf_link **links,
int identity_fd, int tamper_fd)
{
- const struct shirudo_embedded_bpf *blob = shirudo_seal_blob();
+ const struct shirudo_embedded_bpf *blob = seal_blob();
struct bpf_object *obj;
struct bpf_map *m;
int err, i;
@@ -763,7 +763,7 @@ static int init_lsm(bool attach_filesystem_seal)
};
struct bpf_link *prctl_links[ARRAY_SIZE(prctl_hooks)] = {};
struct bpf_link *mount_links[ARRAY_SIZE(mount_hooks)] = {};
- const struct shirudo_embedded_bpf *blob = shirudo_bpf2_blob();
+ const struct shirudo_embedded_bpf *blob = bpf2_blob();
struct bpf_program *p_bpf, *p_bpf_map, *p_unlink, *p_setx, *p_rmx;
struct bpf_program *p_pload, *p_rename;
struct bpf_object *obj = NULL, *seal_obj = NULL;
@@ -835,10 +835,10 @@ static int init_lsm(bool attach_filesystem_seal)
* serial the kernel records for a load that names it as keyring_id.
*/
if (bpf_keyring_mode) {
- keyring = shirudo_keyring_bpf_serial();
+ keyring = keyring_bpf_serial();
id.keyring_type = SHIRUDO_SIG_KEYRING_BPF;
} else {
- keyring = shirudo_keyring_find(SHIRUDO_KEYRING_NAME);
+ keyring = keyring_find(SHIRUDO_KEYRING_NAME);
id.keyring_type = SHIRUDO_SIG_KEYRING_USER;
}
if (keyring < 0) {
@@ -855,7 +855,7 @@ static int init_lsm(bool attach_filesystem_seal)
* keyring itself, what no task but shirudo may write, unlink,
* revoke or invalidate for the rest of the boot.
*/
- err = shirudo_keyring_list(keyring, collect_asymmetric, &keys);
+ err = keyring_list(keyring, collect_asymmetric, &keys);
if (err) {
pr_err("list the anchor keyring %d: %s", (int)keyring,
strerror(-err));
@@ -1092,7 +1092,7 @@ static int boot_restore(struct shirudo_measured_upatch **out_set, size_t *out_n)
*out_set = NULL;
*out_n = 0;
- n = scandir(SHIRUDO_UPATCHES_DIR, &names, shirudo_upatch_select,
+ n = scandir(SHIRUDO_UPATCHES_DIR, &names, upatch_select,
alphasort);
if (n < 0) {
if (errno == ENOENT)
@@ -1102,15 +1102,15 @@ static int boot_restore(struct shirudo_measured_upatch **out_set, size_t *out_n)
return -errno;
}
if (n == 0) {
- shirudo_libc_free(names);
+ libc_free(names);
return 0;
}
set = xcalloc((size_t)n, sizeof(*set));
if (!set) {
for (i = 0; i < n; i++)
- shirudo_libc_free(names[i]);
- shirudo_libc_free(names);
+ libc_free(names[i]);
+ libc_free(names);
return -ENOMEM;
}
@@ -1132,20 +1132,20 @@ static int boot_restore(struct shirudo_measured_upatch **out_set, size_t *out_n)
rc = -ENAMETOOLONG;
goto next;
}
- if (shirudo_upatch_open(path, &u) == 0) {
+ if (upatch_open(path, &u) == 0) {
memcpy(set[cnt].name, u.hdr.name,
SHIRUDO_UPATCH_NAME_MAX);
set[cnt].name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
- shirudo_hex_encode(u.hdr.payload_sha256,
- SHIRUDO_UPATCH_PAYLOAD_HASH_LEN,
- set[cnt].payload_hex);
- shirudo_upatch_close(&u);
+ hex_encode(u.hdr.payload_sha256,
+ SHIRUDO_UPATCH_PAYLOAD_HASH_LEN,
+ set[cnt].payload_hex);
+ upatch_close(&u);
}
- fd = shirudo_upatch_open_first_link(set[cnt].name);
+ fd = upatch_open_first_link(set[cnt].name);
if (fd >= 0) {
close(fd);
- shirudo_upatch_payload_sha256(set[cnt].name, pinned_hex,
- sizeof(pinned_hex));
+ upatch_payload_sha256(set[cnt].name, pinned_hex,
+ sizeof(pinned_hex));
if (strcmp(pinned_hex, set[cnt].payload_hex) != 0) {
pr_err("boot-restore: %s is loaded with a "
"payload other than the archived one "
@@ -1166,9 +1166,9 @@ static int boot_restore(struct shirudo_measured_upatch **out_set, size_t *out_n)
}
cnt++;
next:
- shirudo_libc_free(names[i]);
+ libc_free(names[i]);
}
- shirudo_libc_free(names);
+ libc_free(names);
if (rc) {
xfree(set, (size_t)n * sizeof(*set));
@@ -1200,57 +1200,57 @@ static int append_init_event(const struct shirudo_measured_upatch *set,
char ts[32], boot_id[64], nv_index[16];
size_t i;
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_hex_encode(cert_sha, 32, cert_hex);
- shirudo_hex_encode(set_digest, 32, set_hex);
- shirudo_hex_encode(tree_root, 32, tree_hex);
- shirudo_hex_encode(init_digest, 32, digest_hex);
- shirudo_hex_encode(info->pcr_before, 32, pcr_hex);
- shirudo_hex_encode(info->phase_before, 32, phase_hex);
- shirudo_hex_encode(info->name, SHIRUDO_TPM_NAME_LEN, name_hex);
- shirudo_hex_encode(info->anchor_digest, 32, anchor_hex);
- shirudo_hex_encode(info->value, 32, chain_hex);
-
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_json_kv_string(&e, "digest", digest_hex);
- shirudo_json_kv_string(&e, "type", "init");
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_kv_int(&e, "tpm_reset_count", info->reset_count);
- shirudo_json_kv_string(&e, "cert_sha256", cert_hex);
- shirudo_json_arr_open(&e, "certs");
+ hex_encode(cert_sha, 32, cert_hex);
+ hex_encode(set_digest, 32, set_hex);
+ hex_encode(tree_root, 32, tree_hex);
+ hex_encode(init_digest, 32, digest_hex);
+ hex_encode(info->pcr_before, 32, pcr_hex);
+ hex_encode(info->phase_before, 32, phase_hex);
+ hex_encode(info->name, SHIRUDO_TPM_NAME_LEN, name_hex);
+ hex_encode(info->anchor_digest, 32, anchor_hex);
+ hex_encode(info->value, 32, chain_hex);
+
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ json_kv_string(&e, "digest", digest_hex);
+ json_kv_string(&e, "type", "init");
+ json_kv_string(&e, "boot_id", boot_id);
+ json_kv_int(&e, "tpm_reset_count", info->reset_count);
+ json_kv_string(&e, "cert_sha256", cert_hex);
+ json_arr_open(&e, "certs");
for (i = 0; i < enrolled.n; i++) {
char sha_hex[HEXLEN(32)];
- shirudo_hex_encode(enrolled.certs[i].sha256, 32, sha_hex);
- shirudo_json_str(&e, sha_hex);
+ hex_encode(enrolled.certs[i].sha256, 32, sha_hex);
+ json_str(&e, sha_hex);
}
- shirudo_json_arr_close(&e);
- shirudo_json_kv_string(&e, "set_digest", set_hex);
- shirudo_json_kv_string(&e, "tree_root", tree_hex);
- shirudo_json_arr_open(&e, "set");
+ json_arr_close(&e);
+ json_kv_string(&e, "set_digest", set_hex);
+ json_kv_string(&e, "tree_root", tree_hex);
+ json_arr_open(&e, "set");
for (i = 0; i < n; i++) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", set[i].name);
- shirudo_json_kv_string(&e, "payload_sha256", set[i].payload_hex);
- shirudo_json_obj_close(&e);
- }
- shirudo_json_arr_close(&e);
- shirudo_json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
- shirudo_json_kv_string(&e, "pcr_before", pcr_hex);
- shirudo_json_kv_int(&e, "phase_pcr", SHIRUDO_CHAIN_PHASE_PCR);
- shirudo_json_kv_string(&e, "phase_before", phase_hex);
- shirudo_json_kv_string(&e, "bound_in", info->initrd ? "initrd" : "root");
- shirudo_json_kv_string(&e, "nv_name", name_hex);
- shirudo_json_kv_string(&e, "anchor", info->anchor);
- shirudo_json_kv_string(&e, "anchor_digest", anchor_hex);
- shirudo_json_kv_string(&e, "chain", chain_hex);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "name", set[i].name);
+ json_kv_string(&e, "payload_sha256", set[i].payload_hex);
+ json_obj_close(&e);
+ }
+ json_arr_close(&e);
+ json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
+ json_kv_string(&e, "pcr_before", pcr_hex);
+ json_kv_int(&e, "phase_pcr", SHIRUDO_CHAIN_PHASE_PCR);
+ json_kv_string(&e, "phase_before", phase_hex);
+ json_kv_string(&e, "bound_in", info->initrd ? "initrd" : "root");
+ json_kv_string(&e, "nv_name", name_hex);
+ json_kv_string(&e, "anchor", info->anchor);
+ json_kv_string(&e, "anchor_digest", anchor_hex);
+ json_kv_string(&e, "chain", chain_hex);
+ json_obj_close(&e);
if (e.err) {
pr_err("eventlog: init entry encode failed: %s",
@@ -1261,9 +1261,9 @@ static int append_init_event(const struct shirudo_measured_upatch *set,
* From the initrd the record waits under /run for the root file
* system's init: the eventlog is on a root that is read-only here.
*/
- return shirudo_eventlog_append_to(initrd_mode ?
- shirudo_eventlog_pending_path() :
- shirudo_eventlog_path(), buf);
+ return eventlog_append_to(initrd_mode ?
+ eventlog_pending_path() :
+ eventlog_path(), buf);
}
static bool phase_unmeasured(const __u8 pcr[32])
@@ -1282,8 +1282,8 @@ static void tree_root_at_boot(__u8 out[32])
struct shirudo_tree_state s = {};
memset(out, 0, 32);
- if (shirudo_tree_state_read(&s) == 0 &&
- shirudo_hex_decode(s.projection_root, out, 32) != 0)
+ if (tree_state_read(&s) == 0 &&
+ hex_decode(s.projection_root, out, 32) != 0)
memset(out, 0, 32);
}
@@ -1308,14 +1308,14 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
__u64 max_bytes;
bool full;
- shirudo_config_load(&cfg);
+ config_load(&cfg);
max_bytes = cfg.eventlog_max_bytes;
- full = shirudo_eventlog_would_exceed(max_bytes);
+ full = eventlog_would_exceed(max_bytes);
explicit_bzero(&cfg, sizeof(cfg)); /* scrub tpm_owner_auth */
if (full) {
pr_err("eventlog %s would exceed eventlog.max_bytes=%llu; "
"refusing chain extend (eventlog_full)",
- shirudo_eventlog_path(), max_bytes);
+ eventlog_path(), max_bytes);
return -ENOSPC;
}
}
@@ -1324,7 +1324,7 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
pr_err("chain: no certificate enrolled");
return -ENOENT;
}
- shirudo_keys_set_digest(&enrolled, cert_sha);
+ keys_set_digest(&enrolled, cert_sha);
/*
* init_event = SHA256("shirudo-init\0" || cert_sha256 || set_digest
@@ -1332,10 +1332,10 @@ static int chain_extend_init(struct shirudo_measured_upatch *set, size_t n)
* predictor shares (util/attest.c).
*/
tree_root_at_boot(tree_root);
- shirudo_chain_init_event(cert_sha, set, n, tree_root, set_digest,
- init_digest);
+ chain_init_event(cert_sha, set, n, tree_root, set_digest,
+ init_digest);
- rc = shirudo_chain_init(init_digest, &info);
+ rc = chain_init(init_digest, &info);
if (rc == -ENODEV) {
pr_err("tpm: not usable; shirudo requires a TPM 2.0 "
"(tpm_error)");
@@ -1429,16 +1429,16 @@ static int initrd_enter(void)
struct stat st;
int rc;
- if (snprintf(src, sizeof(src), "%s%s", shirudo_sysroot(),
+ if (snprintf(src, sizeof(src), "%s%s", sysroot(),
SHIRUDO_VAR_LIB) >= (int)sizeof(src))
return -ENAMETOOLONG;
if (stat(src, &st) != 0 || !S_ISDIR(st.st_mode)) {
pr_err("initrd: %s is not a directory; the root file system "
"must be mounted at %s with /var on it or mounted "
- "there (x-initrd.mount)", src, shirudo_sysroot());
+ "there (x-initrd.mount)", src, sysroot());
return -ENOENT;
}
- rc = shirudo_seal_mkdir_p(SHIRUDO_VAR_LIB, 0700);
+ rc = seal_mkdir_p(SHIRUDO_VAR_LIB, 0700);
if (rc) {
pr_err("initrd: mkdir %s: %s", SHIRUDO_VAR_LIB, strerror(-rc));
return rc;
@@ -1492,14 +1492,14 @@ static int run_init(bool no_seal)
pr_info("initrd: labels and the eventlog are left to the root "
"file system's init");
} else {
- rc = shirudo_seal_label_tree();
+ rc = seal_label_tree();
if (rc)
pr_warn("init: seal label-walk incomplete: %s "
"(some files may be unsealed)", strerror(-rc));
- rc = shirudo_eventlog_adopt_pending();
+ rc = eventlog_adopt_pending();
if (rc) {
pr_err("init: the initrd's record in %s could not be "
- "adopted: %s", shirudo_eventlog_pending_path(),
+ "adopted: %s", eventlog_pending_path(),
strerror(-rc));
return rc;
}
@@ -1547,8 +1547,8 @@ int cmd_init(int argc, const char **argv)
check_only = true;
} else if (strcmp(a, "--no-seal") == 0) {
no_seal = true;
- } else if (shirudo_is_help(a)) {
- shirudo_print_help(&init_help);
+ } else if (is_help(a)) {
+ print_help(&init_help);
return 0;
} else {
pr_err("init: unknown option '%s'", a);
@@ -1557,8 +1557,8 @@ int cmd_init(int argc, const char **argv)
}
}
- initrd_mode = shirudo_in_initrd();
- shirudo_preflight_run(&res);
+ initrd_mode = in_initrd();
+ preflight_run(&res);
print_preflight(&res);
if (res.n_failed > 0) {
diff --git a/builtin-keys.c b/builtin-keys.c
index 2e0f9da0..d14f3439 100644
--- a/builtin-keys.c
+++ b/builtin-keys.c
@@ -55,20 +55,20 @@ static X509 *read_cert_der(const char *path)
pr_err("open %s: %s", path, strerror(errno));
return NULL;
}
- if (shirudo_check_trusted(fd, path, false)) {
+ if (check_trusted(fd, path, false)) {
close(fd);
return NULL;
}
bio = BIO_new_fd(fd, BIO_CLOSE);
if (!bio) {
close(fd);
- shirudo_openssl_complain("BIO_new_fd");
+ openssl_complain("BIO_new_fd");
return NULL;
}
c = d2i_X509_bio(bio, NULL);
BIO_free(bio);
if (!c)
- shirudo_openssl_complain("d2i_X509_bio");
+ openssl_complain("d2i_X509_bio");
return c;
}
@@ -85,7 +85,7 @@ static EVP_PKEY *read_priv_pem(const char *path)
k = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
fclose(fp);
if (!k)
- shirudo_openssl_complain("PEM_read_PrivateKey");
+ openssl_complain("PEM_read_PrivateKey");
return k;
}
@@ -135,7 +135,7 @@ static int compute_cert_fpr(X509 *c, __u8 fpr[SHA256_DIGEST_LENGTH])
__u32 n = SHA256_DIGEST_LENGTH;
if (X509_digest(c, EVP_sha256(), fpr, &n) != 1) {
- shirudo_openssl_complain("X509_digest");
+ openssl_complain("X509_digest");
return -1;
}
return 0;
@@ -152,12 +152,12 @@ static int compute_spki_fpr(EVP_PKEY *pkey,
der_len = i2d_PUBKEY(pkey, &der);
if (der_len <= 0) {
- shirudo_openssl_complain("i2d_PUBKEY");
+ openssl_complain("i2d_PUBKEY");
return -1;
}
if (EVP_Digest(der, (size_t)der_len, fpr, &n,
EVP_sha256(), NULL) != 1) {
- shirudo_openssl_complain("EVP_Digest");
+ openssl_complain("EVP_Digest");
goto out;
}
rc = 0;
@@ -239,7 +239,7 @@ static int dump_signing_key(const char *pkey_path,
EVP_PKEY *priv;
int rc = 0;
- if (!shirudo_path_exists(pkey_path)) {
+ if (!path_exists(pkey_path)) {
printf("Signing key (%s):\n", pkey_path);
printf(" %-22s %s\n", "Present:",
"no (target host -- private key lives on the operator)");
@@ -341,7 +341,7 @@ static int keys_list_keyring(key_serial_t ring, const char *label)
printf("Keyring (%s):\n", label);
printf(" %-22s %d\n", "Serial:", (int)ring);
- if (shirudo_identity_read(&id) == 0) {
+ if (identity_read(&id) == 0) {
const char *match = id.keyring_serial == ring ?
"matches" : "MISMATCH";
@@ -355,7 +355,7 @@ static int keys_list_keyring(key_serial_t ring, const char *label)
"(none this boot)");
}
- rc = shirudo_keyring_list(ring, collect_key, &c);
+ rc = keyring_list(ring, collect_key, &c);
if (rc) {
pr_err("keyring list: %s", strerror(-rc));
goto out;
@@ -474,13 +474,13 @@ static int check_cert_algorithm(const __u8 *der, size_t der_sz,
char name[64] = {};
int rc;
- rc = shirudo_cert_read_der(der, der_sz, &cert);
+ rc = cert_read_der(der, der_sz, &cert);
if (rc) {
pr_err("keys add: %s is not a certificate", what);
return rc;
}
- rc = shirudo_cert_key_algorithm(&cert, name, sizeof(name));
- shirudo_cert_free(&cert);
+ rc = cert_key_algorithm(&cert, name, sizeof(name));
+ cert_free(&cert);
if (rc || strcmp(name, "ML-DSA-87")) {
pr_err("keys add: %s is %s; shirudo accepts only ML-DSA-87",
what, rc ? "of an unknown algorithm" : name);
@@ -504,10 +504,10 @@ static int check_voucher_live(const struct shirudo_trusted_set *set,
int rc = 0;
size_t i;
- if (shirudo_identity_read(&id) ||
+ if (identity_read(&id) ||
id.keyring_type != SHIRUDO_SIG_KEYRING_BPF)
return 0;
- ring = shirudo_keyring_bpf_serial();
+ ring = keyring_bpf_serial();
if (ring <= 0)
return 0;
for (i = 0; i < set->n; i++) {
@@ -516,10 +516,10 @@ static int check_voucher_live(const struct shirudo_trusted_set *set,
}
if (i == set->n)
return -ENOKEY;
- rc = shirudo_keys_read_der(set->certs[i].path, &der, &der_sz);
+ rc = keys_read_der(set->certs[i].path, &der, &der_sz);
if (rc)
return rc;
- rc = shirudo_keyring_holds_cert(ring, der, der_sz);
+ rc = keyring_holds_cert(ring, der, der_sz);
xfree(der, der_sz);
if (rc < 0)
return rc;
@@ -549,8 +549,8 @@ static int keys_add(int argc, const char **argv)
keys_dir_arg = argv[++a];
} else if (!strncmp(argv[a], "--keys-dir=", 11)) {
keys_dir_arg = argv[a] + 11;
- } else if (shirudo_is_help(argv[a])) {
- shirudo_print_help(&keys_add_help);
+ } else if (is_help(argv[a])) {
+ print_help(&keys_add_help);
return 0;
} else if (argv[a][0] == '-') {
pr_err("keys add: unknown option '%s'", argv[a]);
@@ -563,22 +563,22 @@ static int keys_add(int argc, const char **argv)
}
}
if (!cert || !vouch_path) {
- shirudo_print_help(&keys_add_help);
+ print_help(&keys_add_help);
return 2;
}
- keys_dir = shirudo_keys_dir_resolve(keys_dir_arg);
+ keys_dir = keys_dir_resolve(keys_dir_arg);
if (snprintf(revoked, sizeof(revoked), "%s/revoked", keys_dir) >=
(int)sizeof(revoked)) {
pr_err("keys add: keys directory path too long");
return 2;
}
- rc = shirudo_keys_read_der(cert, &der, &der_sz);
+ rc = keys_read_der(cert, &der, &der_sz);
if (rc) {
pr_err("keys add: read %s: %s", cert, strerror(-rc));
return 1;
}
- rc = shirudo_keys_digest_der(der, der_sz, sha256, fp);
+ rc = keys_digest_der(der, der_sz, sha256, fp);
if (rc) {
pr_err("keys add: %s is not a certificate", cert);
goto out;
@@ -586,32 +586,32 @@ static int keys_add(int argc, const char **argv)
rc = check_cert_algorithm(der, der_sz, cert);
if (rc)
goto out;
- shirudo_hex_encode(fp, 32, fp_hex);
+ hex_encode(fp, 32, fp_hex);
- rc = shirudo_keys_load(keys_dir, NULL, true, &set);
+ rc = keys_load(keys_dir, NULL, true, &set);
if (rc) {
pr_err("keys add: no trusted set under %s: %s (install the "
"primary certificate first)", keys_dir, strerror(-rc));
goto out;
}
- if (shirudo_keys_is_revoked(revoked, fp)) {
+ if (keys_is_revoked(revoked, fp)) {
pr_err("keys add: %s was revoked on this target", fp_hex);
rc = -EKEYREVOKED;
goto out;
}
- rc = shirudo_keys_read_der(vouch_path, &sig, &sig_sz);
+ rc = keys_read_der(vouch_path, &sig, &sig_sz);
if (rc) {
pr_err("keys add: read %s: %s", vouch_path, strerror(-rc));
goto out;
}
- rc = shirudo_keys_verify_vouch(&set, der, der_sz, sig, sig_sz, by);
+ rc = keys_verify_vouch(&set, der, der_sz, sig, sig_sz, by);
if (rc) {
pr_err("keys add: %s does not vouch for %s under any of the "
"%zu trusted certificate%s", vouch_path, fp_hex, set.n,
set.n == 1 ? "" : "s");
goto out;
}
- shirudo_hex_encode(by, 32, by_hex);
+ hex_encode(by, 32, by_hex);
if (!strcmp(keys_dir, SHIRUDO_KEYS_DIR)) {
rc = check_voucher_live(&set, by);
if (rc) {
@@ -637,8 +637,8 @@ static int keys_add(int argc, const char **argv)
rc = -E2BIG;
goto out;
}
- rc = shirudo_keys_install(keys_dir, der, der_sz, sig, sig_sz, out,
- sizeof(out));
+ rc = keys_install(keys_dir, der, der_sz, sig, sig_sz, out,
+ sizeof(out));
if (rc) {
pr_err("keys add: install under %s/trusted: %s", keys_dir,
strerror(-rc));
@@ -685,30 +685,30 @@ static int append_key_event(const char *type, const char *fp_hex,
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
char ts[32], boot_id[64], nv_index[16], digest_hex[65];
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_hex_encode(event, 32, digest_hex);
-
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_json_kv_string(&e, "digest", digest_hex);
- shirudo_json_kv_string(&e, "type", type);
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_obj_open_key(&e, "key");
- shirudo_json_kv_string(&e, "fingerprint", fp_hex);
- shirudo_json_kv_string(&e, "cert_sha256", sha_hex);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ hex_encode(event, 32, digest_hex);
+
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ json_kv_string(&e, "digest", digest_hex);
+ json_kv_string(&e, "type", type);
+ json_kv_string(&e, "boot_id", boot_id);
+ json_obj_open_key(&e, "key");
+ json_kv_string(&e, "fingerprint", fp_hex);
+ json_kv_string(&e, "cert_sha256", sha_hex);
+ json_obj_close(&e);
+ json_obj_close(&e);
if (e.err) {
pr_err("eventlog: %s entry encode failed: %s", type,
strerror(-e.err));
return e.err;
}
- return shirudo_eventlog_append(buf);
+ return eventlog_append(buf);
}
/*
@@ -724,8 +724,8 @@ static int measure_revoke(const struct shirudo_trusted_cert *c,
char sha_hex[65], chain_hex[65];
int rc;
- shirudo_chain_key_event("shirudo-key-revoke", c->sha256, event);
- rc = shirudo_chain_extend(event, chain);
+ chain_key_event("shirudo-key-revoke", c->sha256, event);
+ rc = chain_extend(event, chain);
if (rc) {
pr_err("keys revoke: register %s (category: %s); the key is "
"revoked but the revocation is NOT measured; operator "
@@ -736,14 +736,14 @@ static int measure_revoke(const struct shirudo_trusted_cert *c,
rc == -EACCES ? "tampered" : "tpm_error");
return rc;
}
- shirudo_hex_encode(c->sha256, 32, sha_hex);
+ hex_encode(c->sha256, 32, sha_hex);
rc = append_key_event("key_revoke", fp_hex, sha_hex, event);
if (rc) {
pr_err("keys revoke: eventlog append failed after extend -- "
"chain/log desync; operator must reconcile");
return rc;
}
- shirudo_hex_encode(chain, 32, chain_hex);
+ hex_encode(chain, 32, chain_hex);
pr_audit("key revoke measured: fingerprint=%s chain=%s", fp_hex,
chain_hex);
return 0;
@@ -763,12 +763,12 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
int n, i, rc = 0, purged = 0;
*unloaded = 0;
- if (shirudo_cert_read_der(der, der_sz, &cert))
+ if (cert_read_der(der, der_sz, &cert))
return -EINVAL;
- n = scandir(SHIRUDO_UPATCHES_DIR, &names, shirudo_upatch_select,
+ n = scandir(SHIRUDO_UPATCHES_DIR, &names, upatch_select,
alphasort);
if (n < 0) {
- shirudo_cert_free(&cert);
+ cert_free(&cert);
return errno == ENOENT ? 0 : -errno;
}
for (i = 0; i < n; i++) {
@@ -780,13 +780,13 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
if (snprintf(path, sizeof(path), "%s/%s", SHIRUDO_UPATCHES_DIR,
names[i]->d_name) >= (int)sizeof(path))
continue;
- if (shirudo_upatch_open(path, &u))
+ if (upatch_open(path, &u))
continue;
- signed_by = shirudo_cms_signed_by(shirudo_upatch_signature(&u),
- u.hdr.signature_len, &cert);
+ signed_by = cms_signed_by(upatch_signature(&u),
+ u.hdr.signature_len, &cert);
memcpy(name, u.hdr.name, SHIRUDO_UPATCH_NAME_MAX);
name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
- shirudo_upatch_close(&u);
+ upatch_close(&u);
if (signed_by != 1)
continue;
prc = shirudo_upatch_purge(name, "key_revoke");
@@ -802,9 +802,9 @@ static int purge_signed_by(const __u8 *der, size_t der_sz,
*unloaded += prc;
}
for (i = 0; i < n; i++)
- shirudo_libc_free(names[i]);
- shirudo_libc_free(names);
- shirudo_cert_free(&cert);
+ libc_free(names[i]);
+ libc_free(names);
+ cert_free(&cert);
return rc ? rc : purged;
}
@@ -815,10 +815,10 @@ static int promote(const struct shirudo_trusted_cert *c)
__u8 *der = NULL;
int rc;
- rc = shirudo_keys_read_der(c->path, &der, &der_sz);
+ rc = keys_read_der(c->path, &der, &der_sz);
if (rc)
return rc;
- rc = shirudo_keys_write_file(SHIRUDO_CERT_PATH, der, der_sz);
+ rc = keys_write_file(SHIRUDO_CERT_PATH, der, der_sz);
xfree(der, der_sz);
if (rc)
return rc;
@@ -861,7 +861,7 @@ static int revoke_logged(const char *line, size_t len, void *ctx)
ARRAY_SIZE(key) },
};
- if (!shirudo_json_parse(line, len, f, ARRAY_SIZE(f)) &&
+ if (!json_parse(line, len, f, ARRAY_SIZE(f)) &&
!strcmp(type, "key_revoke") && !strcmp(fp, r->fp_hex))
r->found = true;
return 0;
@@ -882,7 +882,7 @@ static bool revoke_unmeasured(const char *marker, const char *fp_hex)
return true;
if (st.st_mtime < time(NULL) - up.tv_sec)
return false;
- return shirudo_eventlog_boot_lines(revoke_logged, &r) || !r.found;
+ return eventlog_boot_lines(revoke_logged, &r) || !r.found;
}
/* The certificate a revoked marker holds, as a member it once was. */
@@ -893,16 +893,16 @@ static int revoked_cert(const __u8 fp[32], const char *marker,
char trusted[PATH_MAX];
int rc;
- rc = shirudo_keys_read_der(marker, der, der_sz);
+ rc = keys_read_der(marker, der, der_sz);
if (rc)
return rc;
memset(c, 0, sizeof(*c));
- rc = shirudo_keys_digest_der(*der, *der_sz, c->sha256, c->fingerprint);
+ rc = keys_digest_der(*der, *der_sz, c->sha256, c->fingerprint);
if (!rc && memcmp(c->fingerprint, fp, 32))
rc = -EKEYREJECTED;
if (!rc)
- rc = shirudo_keys_path_for(SHIRUDO_KEYS_DIR "/trusted", fp,
- ".der", trusted, sizeof(trusted));
+ rc = keys_path_for(SHIRUDO_KEYS_DIR "/trusted", fp,
+ ".der", trusted, sizeof(trusted));
if (rc) {
xfree(*der, *der_sz);
*der = NULL;
@@ -935,8 +935,8 @@ static int keys_revoke(int argc, const char **argv)
promote_arg = argv[++a];
} else if (!strncmp(argv[a], "--promote=", 10)) {
promote_arg = argv[a] + 10;
- } else if (shirudo_is_help(argv[a])) {
- shirudo_print_help(&keys_revoke_help);
+ } else if (is_help(argv[a])) {
+ print_help(&keys_revoke_help);
return 0;
} else if (argv[a][0] == '-') {
pr_err("keys revoke: unknown option '%s'", argv[a]);
@@ -950,44 +950,44 @@ static int keys_revoke(int argc, const char **argv)
}
}
if (!fp_arg) {
- shirudo_print_help(&keys_revoke_help);
+ print_help(&keys_revoke_help);
return 2;
}
- if (strlen(fp_arg) != 64 || shirudo_hex_decode(fp_arg, fp, 32)) {
+ if (strlen(fp_arg) != 64 || hex_decode(fp_arg, fp, 32)) {
pr_err("keys revoke: a fingerprint is 64 hex digits (see "
"`shirudo keys`)");
return 2;
}
if (promote_arg && (strlen(promote_arg) != 64 ||
- shirudo_hex_decode(promote_arg, promote_fp, 32))) {
+ hex_decode(promote_arg, promote_fp, 32))) {
pr_err("keys revoke: --promote takes a fingerprint");
return 2;
}
- shirudo_hex_encode(fp, 32, fp_hex);
+ hex_encode(fp, 32, fp_hex);
/*
* Only the bpf keyring can lose one key and keep the others; the
* staging keyring holds the primary alone and the rotation guide
* is the way out of it.
*/
- if (shirudo_identity_read(&id) ||
+ if (identity_read(&id) ||
id.keyring_type != SHIRUDO_SIG_KEYRING_BPF) {
pr_err("keys revoke: the certificates are not enrolled in the "
"bpf keyring this boot; rotate the key instead");
return 1;
}
- ring = shirudo_keyring_bpf_serial();
+ ring = keyring_bpf_serial();
if (ring <= 0) {
pr_err("keys revoke: no bpf keyring: %s", strerror(-ring));
return 1;
}
- rc = shirudo_keys_load(SHIRUDO_KEYS_DIR, NULL, true, &set);
+ rc = keys_load(SHIRUDO_KEYS_DIR, NULL, true, &set);
if (rc) {
pr_err("keys revoke: read the trusted set: %s", strerror(-rc));
return 1;
}
victim = set_find(&set, fp);
- if (!victim && !shirudo_keys_is_revoked(SHIRUDO_KEYS_REVOKED_DIR, fp)) {
+ if (!victim && !keys_is_revoked(SHIRUDO_KEYS_REVOKED_DIR, fp)) {
pr_err("keys revoke: %s is not a trusted certificate", fp_hex);
return 1;
}
@@ -996,8 +996,8 @@ static int keys_revoke(int argc, const char **argv)
* Revoked before: a run that failed after the marker left
* the unlink, the measurement or the purge to this one.
*/
- rc = shirudo_keys_path_for(SHIRUDO_KEYS_REVOKED_DIR, fp,
- ".der", revoked, sizeof(revoked));
+ rc = keys_path_for(SHIRUDO_KEYS_REVOKED_DIR, fp,
+ ".der", revoked, sizeof(revoked));
if (!rc)
rc = revoked_cert(fp, revoked, &gone, &der, &der_sz);
if (rc) {
@@ -1026,23 +1026,23 @@ static int keys_revoke(int argc, const char **argv)
return 1;
}
}
- rc = shirudo_keys_read_der(victim->path, &der, &der_sz);
+ rc = keys_read_der(victim->path, &der, &der_sz);
if (rc) {
pr_err("keys revoke: read %s: %s", victim->path, strerror(-rc));
return 1;
}
/* The marker first: whatever happens next, no boot enrols it again. */
- rc = shirudo_seal_mkdir_p(SHIRUDO_KEYS_REVOKED_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_KEYS_REVOKED_DIR, 0700);
if (rc) {
pr_err("keys revoke: mkdir %s: %s", SHIRUDO_KEYS_REVOKED_DIR,
strerror(-rc));
goto out;
}
- rc = shirudo_keys_path_for(SHIRUDO_KEYS_REVOKED_DIR, fp, ".der",
- revoked, sizeof(revoked));
+ rc = keys_path_for(SHIRUDO_KEYS_REVOKED_DIR, fp, ".der",
+ revoked, sizeof(revoked));
if (!rc)
- rc = shirudo_keys_write_file(revoked, der, der_sz);
+ rc = keys_write_file(revoked, der, der_sz);
if (rc) {
pr_err("keys revoke: write %s: %s", revoked, strerror(-rc));
goto out;
@@ -1057,7 +1057,7 @@ static int keys_revoke(int argc, const char **argv)
finish:
/* The kernel: from this moment nothing it signed verifies. */
- key = shirudo_keyring_find_cert(ring, der, der_sz);
+ key = keyring_find_cert(ring, der, der_sz);
if (key == -ENOKEY) {
pr_warn("keys revoke: %s is not in the bpf keyring this boot",
fp_hex);
@@ -1067,7 +1067,7 @@ finish:
rc = key;
goto out;
} else {
- rc = shirudo_keyring_unlink_key(ring, key);
+ rc = keyring_unlink_key(ring, key);
if (rc) {
pr_err("keys revoke: unlink key %d from the bpf "
"keyring %d: %s; the key is marked revoked and "
@@ -1124,8 +1124,8 @@ static int keys_vouch(int argc, const char **argv)
size_t sz;
int rc;
- if (argc >= 2 && shirudo_is_help(argv[1])) {
- shirudo_print_help(&keys_vouch_help);
+ if (argc >= 2 && is_help(argv[1])) {
+ print_help(&keys_vouch_help);
return 0;
}
sz = ((size_t)argc + 3) * sizeof(*helper_argv);
@@ -1147,10 +1147,10 @@ int cmd_keys(int argc, const char **argv)
{
const char *sub;
- if (argc < 2 || argv[1][0] == '-' || shirudo_is_help(argv[1]))
+ if (argc < 2 || argv[1][0] == '-' || is_help(argv[1]))
return keys_show(argc, argv);
- sub = shirudo_resolve_subcommand("shirudo keys", argv[1], keys_subcmds,
- ARRAY_SIZE(keys_subcmds));
+ sub = resolve_subcommand("shirudo keys", argv[1], keys_subcmds,
+ ARRAY_SIZE(keys_subcmds));
if (!sub)
return 2;
if (!strcmp(sub, "add"))
@@ -1178,12 +1178,12 @@ static int keys_show(int argc, const char **argv)
keys_dir_arg = argv[++i];
} else if (strncmp(argv[i], "--keys-dir=", 11) == 0) {
keys_dir_arg = argv[i] + 11;
- } else if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&keys_help);
+ } else if (is_help(argv[i])) {
+ print_help(&keys_help);
return 0;
- } else if (shirudo_is_list_cmds(argv[i])) {
- shirudo_print_subcmd_list(keys_subcmds,
- ARRAY_SIZE(keys_subcmds));
+ } else if (is_list_cmds(argv[i])) {
+ print_subcmd_list(keys_subcmds,
+ ARRAY_SIZE(keys_subcmds));
return 0;
} else {
pr_err("keys: unknown option '%s'", argv[i]);
@@ -1192,10 +1192,10 @@ static int keys_show(int argc, const char **argv)
}
}
- keys_dir = shirudo_keys_dir_resolve(keys_dir_arg);
+ keys_dir = keys_dir_resolve(keys_dir_arg);
- rc = shirudo_key_paths(keys_dir, pkey_path, sizeof(pkey_path),
- cert_path, sizeof(cert_path));
+ rc = key_paths(keys_dir, pkey_path, sizeof(pkey_path),
+ cert_path, sizeof(cert_path));
if (rc) {
pr_err("keys: invalid keys dir %s: %s",
keys_dir, strerror(-rc));
@@ -1208,13 +1208,13 @@ static int keys_show(int argc, const char **argv)
* rather than picking one mode: the on-disk cert + signing key,
* then the kernel keyring once `shirudo init` has populated one.
*/
- if (shirudo_path_exists(cert_path)) {
+ if (path_exists(cert_path)) {
if (keys_dump_disk_material(cert_path, pkey_path))
rc = 1;
shown = true;
}
- if (shirudo_keys_load(keys_dir, NULL, true, &set) == 0 &&
+ if (keys_load(keys_dir, NULL, true, &set) == 0 &&
(set.n > 1 || set.n_revoked || set.n_unvouched)) {
size_t i;
@@ -1224,22 +1224,22 @@ static int keys_show(int argc, const char **argv)
for (i = 0; i < set.n; i++) {
char fp[65], sha[65];
- shirudo_hex_encode(set.certs[i].fingerprint, 32, fp);
- shirudo_hex_encode(set.certs[i].sha256, 32, sha);
+ hex_encode(set.certs[i].fingerprint, 32, fp);
+ hex_encode(set.certs[i].sha256, 32, sha);
printf(" %s%s\n sha256 %s\n", fp,
set.certs[i].primary ? " (primary)" : "", sha);
if (set.certs[i].primary)
continue;
- shirudo_hex_encode(set.certs[i].voucher, 32, fp);
+ hex_encode(set.certs[i].voucher, 32, fp);
printf(" vouched by %s\n", fp);
}
shown = true;
}
/* The live anchor: the bpf keyring, or the staged one below. */
- if (shirudo_identity_read(&id) == 0 &&
+ if (identity_read(&id) == 0 &&
id.keyring_type == SHIRUDO_SIG_KEYRING_BPF) {
- ring = shirudo_keyring_bpf_serial();
+ ring = keyring_bpf_serial();
if (ring > 0) {
if (shown)
printf("\n");
@@ -1249,7 +1249,7 @@ static int keys_show(int argc, const char **argv)
}
}
- ring = shirudo_keyring_find(SHIRUDO_KEYRING_NAME);
+ ring = keyring_find(SHIRUDO_KEYRING_NAME);
if (ring >= 0) {
if (shown)
printf("\n");
diff --git a/builtin-status.c b/builtin-status.c
index 8ca9de45..503cc5bf 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -71,10 +71,10 @@ static int count_eventlog(long *entries, long *bytes)
ssize_t n;
int fd;
- if (stat(shirudo_eventlog_path(), &st) != 0)
+ if (stat(eventlog_path(), &st) != 0)
return -errno;
*bytes = (long)st.st_size;
- fd = open(shirudo_eventlog_path(), O_RDONLY | O_CLOEXEC);
+ fd = open(eventlog_path(), O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -errno;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
@@ -115,9 +115,9 @@ static int count_dir(const char *dir, bool upatch_only)
if (!upatch_only ||
(len > 7 && strcmp(nm + len - 7, ".upatch") == 0))
count++;
- shirudo_libc_free(list[i]);
+ libc_free(list[i]);
}
- shirudo_libc_free(list);
+ libc_free(list);
return count;
}
@@ -150,7 +150,7 @@ static void gather_assets(struct asset_view *a)
*a = (struct asset_view){};
a->cert = access(SHIRUDO_CERT_PATH, F_OK) == 0;
a->signing_key = access(SHIRUDO_SIGNING_KEY_PATH, F_OK) == 0;
- if (stat(shirudo_eventlog_path(), &st) == 0) {
+ if (stat(eventlog_path(), &st) == 0) {
a->eventlog = true;
a->eventlog_bytes = (long)st.st_size;
}
@@ -193,7 +193,7 @@ static int parse_event_line(const char *line, size_t len, struct ev_proj *ev)
};
*ev = (struct ev_proj){};
- return shirudo_json_parse(line, len, f, ARRAY_SIZE(f));
+ return json_parse(line, len, f, ARRAY_SIZE(f));
}
static void emit_eventlog_events(struct shirudo_json_emit *e)
@@ -201,38 +201,38 @@ static void emit_eventlog_events(struct shirudo_json_emit *e)
char *save, *line, *buf;
size_t len;
- shirudo_json_arr_open(e, "events");
- if (shirudo_read_file(shirudo_eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
- &buf, &len) != 0) {
- shirudo_json_arr_close(e);
+ json_arr_open(e, "events");
+ if (read_file(eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
+ &buf, &len) != 0) {
+ json_arr_close(e);
return;
}
for (line = strtok_r(buf, "\n", &save); line;
line = strtok_r(NULL, "\n", &save)) {
struct ev_proj ev;
- shirudo_json_obj_open(e);
+ json_obj_open(e);
if (parse_event_line(line, strlen(line), &ev) != 0) {
- shirudo_json_kv_string(e, "type", "unparseable");
- shirudo_json_obj_close(e);
+ json_kv_string(e, "type", "unparseable");
+ json_obj_close(e);
continue;
}
- shirudo_json_kv_string(e, "ts", ev.ts);
- shirudo_json_kv_string(e, "type", ev.type);
- shirudo_json_kv_string(e, "digest", ev.digest);
+ json_kv_string(e, "ts", ev.ts);
+ json_kv_string(e, "type", ev.type);
+ json_kv_string(e, "digest", ev.digest);
if (ev.set_digest[0])
- shirudo_json_kv_string(e, "set_digest", ev.set_digest);
+ json_kv_string(e, "set_digest", ev.set_digest);
if (ev.up_name[0]) {
- shirudo_json_obj_open_key(e, "upatch");
- shirudo_json_kv_string(e, "name", ev.up_name);
- shirudo_json_kv_string(e, "payload_sha256",
- ev.up_payload);
- shirudo_json_obj_close(e);
+ json_obj_open_key(e, "upatch");
+ json_kv_string(e, "name", ev.up_name);
+ json_kv_string(e, "payload_sha256",
+ ev.up_payload);
+ json_obj_close(e);
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
xfree(buf, len + 1);
- shirudo_json_arr_close(e);
+ json_arr_close(e);
}
static void event_detail(const struct ev_proj *ev, char *out, size_t cap)
@@ -251,8 +251,8 @@ static void print_eventlog_table(void)
char *save, *line, *buf;
size_t len;
- if (shirudo_read_file(shirudo_eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
- &buf, &len) != 0)
+ if (read_file(eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
+ &buf, &len) != 0)
return;
printf("\nEventlog (audit trail):\n");
printf(" %-20s %-13s %-13s %s\n", "TIME", "TYPE", "DIGEST",
@@ -290,13 +290,13 @@ static void print_system_human(const struct shirudo_sysinfo *si)
if (si->mem_total_kb > 0) {
char tot[16], used[16];
- shirudo_human_size((__u64)si->mem_total_kb * 1024,
- tot, sizeof(tot));
+ human_size((__u64)si->mem_total_kb * 1024,
+ tot, sizeof(tot));
if (si->mem_avail_kb >= 0 &&
si->mem_avail_kb <= si->mem_total_kb) {
- shirudo_human_size((__u64)(si->mem_total_kb -
- si->mem_avail_kb) * 1024,
- used, sizeof(used));
+ human_size((__u64)(si->mem_total_kb -
+ si->mem_avail_kb) * 1024,
+ used, sizeof(used));
printf(" %-16s %s/%s\n", "Memory:", used, tot);
} else {
printf(" %-16s %s\n", "Memory:", tot);
@@ -305,10 +305,10 @@ static void print_system_human(const struct shirudo_sysinfo *si)
if (si->disk_total_kb > 0) {
char tot[16], used[16];
- shirudo_human_size((__u64)si->disk_total_kb * 1024,
- tot, sizeof(tot));
- shirudo_human_size((__u64)si->disk_used_kb * 1024,
- used, sizeof(used));
+ human_size((__u64)si->disk_total_kb * 1024,
+ tot, sizeof(tot));
+ human_size((__u64)si->disk_used_kb * 1024,
+ used, sizeof(used));
printf(" %-16s %s/%s\n", "Disk:", used, tot);
}
if (si->uptime_sec >= 0)
@@ -334,9 +334,9 @@ static void print_kernel_config_entry(void *ctx, const char *key,
static void print_kernel_config_human(const struct shirudo_sysinfo *si)
{
printf(" Kernel Config:\n");
- if (shirudo_sysinfo_kernel_config_foreach(si->kernel_release,
- print_kernel_config_entry,
- NULL) < 0)
+ if (sysinfo_kernel_config_foreach(si->kernel_release,
+ print_kernel_config_entry,
+ NULL) < 0)
printf(" (unavailable)\n");
}
@@ -403,24 +403,24 @@ static size_t build_upatches_table(struct dirent **ups, int n_ups,
size_t nm = 0;
const char *name = ups[i]->d_name;
- if (shirudo_upatch_name_from_bpffs(raw_name, sizeof(raw_name),
- ups[i]->d_name) == 0)
+ if (upatch_name_from_bpffs(raw_name, sizeof(raw_name),
+ ups[i]->d_name) == 0)
name = raw_name;
snprintf(r->name, sizeof(r->name), "%.*s",
(int)(sizeof(r->name) - 1), name);
- shirudo_upatch_resolve_location(vbtf, name,
- r->location,
- sizeof(r->location));
- shirudo_upatch_loaded_at(name, r->loaded_at,
- sizeof(r->loaded_at));
- shirudo_upatch_payload_sha256(name,
- r->payload_sha256,
- sizeof(r->payload_sha256));
- shirudo_upatch_maps_list_one(name, &list, &nm);
+ upatch_resolve_location(vbtf, name,
+ r->location,
+ sizeof(r->location));
+ upatch_loaded_at(name, r->loaded_at,
+ sizeof(r->loaded_at));
+ upatch_payload_sha256(name,
+ r->payload_sha256,
+ sizeof(r->payload_sha256));
+ upatch_maps_list_one(name, &list, &nm);
r->n_maps = (__u32)nm;
- shirudo_map_summary_free(list, nm);
- r->age_sec = shirudo_upatch_age_sec(r->loaded_at);
+ map_summary_free(list, nm);
+ r->age_sec = upatch_age_sec(r->loaded_at);
}
if (vbtf)
btf__free(vbtf);
@@ -539,7 +539,7 @@ int cmd_status(int argc, const char **argv)
char phase_before_hex[2 * SHIRUDO_CHAIN_DIGEST_LEN + 1] = "";
char chain_hex[2 * SHIRUDO_CHAIN_DIGEST_LEN + 1] = "";
char name_hex[2 * SHIRUDO_TPM_NAME_LEN + 1] = "";
- struct shirudo_chain_status cst = {};
+ struct chain_status cst = {};
char nv_index[16];
char *json_buf = NULL;
size_t json_cap = 0;
@@ -578,8 +578,8 @@ int cmd_status(int argc, const char **argv)
include_modules = true;
} else if (strcmp(argv[i], "--show-full") == 0) {
show_full = true;
- } else if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&status_help);
+ } else if (is_help(argv[i])) {
+ print_help(&status_help);
return 0;
} else {
fprintf(stderr, "status: unknown option '%s'\n", argv[i]);
@@ -589,7 +589,7 @@ int cmd_status(int argc, const char **argv)
}
json = json_stdout || otel;
if (otel) {
- int rc = shirudo_config_load(&otel_cfg);
+ int rc = config_load(&otel_cfg);
if (rc) {
pr_err("status: load OTEL configuration: %s", strerror(-rc));
@@ -622,7 +622,7 @@ int cmd_status(int argc, const char **argv)
include_modules = true;
}
if (include_system)
- shirudo_sysinfo_gather(&sysi);
+ sysinfo_gather(&sysi);
fd = bpf_obj_get(SHIRUDO_LSM_LINK_PIN);
lsm_attached = fd >= 0;
@@ -632,19 +632,19 @@ int cmd_status(int argc, const char **argv)
* The anchor init froze is the kernel's record; the live keyring
* of that kind is what a load would name, and the two must agree.
*/
- if (shirudo_identity_read(&ident) == 0) {
+ if (identity_read(&ident) == 0) {
keyring_pinned = ident.keyring_serial;
if (ident.keyring_type == SHIRUDO_SIG_KEYRING_BPF) {
- keyring_serial = shirudo_keyring_bpf_serial();
+ keyring_serial = keyring_bpf_serial();
keyring_mode = "bpf";
} else {
keyring_serial =
- shirudo_keyring_find(SHIRUDO_KEYRING_NAME);
+ keyring_find(SHIRUDO_KEYRING_NAME);
keyring_mode = "user";
}
} else {
keyring_pinned = -ENOENT;
- keyring_serial = shirudo_keyring_find(SHIRUDO_KEYRING_NAME);
+ keyring_serial = keyring_find(SHIRUDO_KEYRING_NAME);
keyring_mode = keyring_serial >= 0 ? "user" : "none";
}
keyring_present = keyring_serial >= 0;
@@ -653,13 +653,13 @@ int cmd_status(int argc, const char **argv)
* and how many keys the bpf keyring holds right now: the two part
* when a certificate was added or revoked since the boot.
*/
- certs_rc = shirudo_keys_load(SHIRUDO_KEYS_DIR, NULL,
- !strcmp(keyring_mode, "bpf"), &certs);
+ certs_rc = keys_load(SHIRUDO_KEYS_DIR, NULL,
+ !strcmp(keyring_mode, "bpf"), &certs);
if (!strcmp(keyring_mode, "bpf") && keyring_present) {
size_t n = 0;
- if (shirudo_keyring_list(keyring_serial, count_asymmetric,
- &n) == 0)
+ if (keyring_list(keyring_serial, count_asymmetric,
+ &n) == 0)
certs_enrolled = (int)n;
}
/*
@@ -678,25 +678,25 @@ int cmd_status(int argc, const char **argv)
n_ups = 0;
gather_assets(&assets);
- tamper_rc = shirudo_tamper_read(&tamper);
+ tamper_rc = tamper_read(&tamper);
{
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- chain_rc = shirudo_chain_status(&cst);
+ chain_rc = chain_status(&cst);
if (chain_rc == 0 && !(cst.defined && cst.written))
chain_rc = -ENODEV;
if (chain_rc == 0) {
- shirudo_hex_encode(cst.value, sizeof(cst.value),
- chain_hex);
- shirudo_hex_encode(cst.name, cst.name_len, name_hex);
+ hex_encode(cst.value, sizeof(cst.value),
+ chain_hex);
+ hex_encode(cst.name, cst.name_len, name_hex);
}
if (cst.logged) {
- shirudo_hex_encode(cst.init.pcr_before,
- sizeof(cst.init.pcr_before),
- pcr_before_hex);
- shirudo_hex_encode(cst.init.phase_before,
- sizeof(cst.init.phase_before),
- phase_before_hex);
+ hex_encode(cst.init.pcr_before,
+ sizeof(cst.init.pcr_before),
+ pcr_before_hex);
+ hex_encode(cst.init.phase_before,
+ sizeof(cst.init.phase_before),
+ phase_before_hex);
}
ev_rc = count_eventlog(&ev_entries, &ev_bytes);
@@ -710,9 +710,9 @@ int cmd_status(int argc, const char **argv)
__u8 replay[SHIRUDO_CHAIN_DIGEST_LEN];
match = cst.anchored && !cst.rebound &&
- shirudo_eventlog_replay(replay) == 0 &&
- shirudo_ct_eq(cst.value, replay,
- sizeof(replay));
+ eventlog_replay(replay) == 0 &&
+ ct_eq(cst.value, replay,
+ sizeof(replay));
}
}
@@ -744,11 +744,11 @@ int cmd_status(int argc, const char **argv)
}
e = (struct shirudo_json_emit){ .buf = json_buf, .cap = json_cap };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "version_id", shirudo_version_id);
- shirudo_json_kv_bool(&e, "is_target", is_target);
- shirudo_json_kv_bool(&e, "is_operator", is_operator);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "version_id", shirudo_version_id);
+ json_kv_bool(&e, "is_target", is_target);
+ json_kv_bool(&e, "is_operator", is_operator);
{
struct shirudo_conditions_input cin;
struct shirudo_condition conds[SHIRUDO_CONDITIONS_MAX];
@@ -765,184 +765,184 @@ int cmd_status(int argc, const char **argv)
chain_rc == 0,
match == 1, match >= 0,
nv_index);
- otel_status = shirudo_status_verdict(&cin);
- shirudo_json_kv_string(&e, "status",
- otel_status);
- nc = shirudo_conditions(&cin, conds,
- ARRAY_SIZE(conds));
- shirudo_json_arr_open(&e, "conditions");
+ otel_status = status_verdict(&cin);
+ json_kv_string(&e, "status",
+ otel_status);
+ nc = conditions(&cin, conds,
+ ARRAY_SIZE(conds));
+ json_arr_open(&e, "conditions");
for (ci = 0; ci < nc; ci++) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "type",
- conds[ci].type);
- shirudo_json_kv_string(&e, "status",
- conds[ci].status);
- shirudo_json_kv_string(&e, "detail",
- conds[ci].detail);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "type",
+ conds[ci].type);
+ json_kv_string(&e, "status",
+ conds[ci].status);
+ json_kv_string(&e, "detail",
+ conds[ci].detail);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
+ json_arr_close(&e);
}
- shirudo_json_kv_bool(&e, "lsm_attached", lsm_attached);
- shirudo_json_kv_string(&e, "mode", mode);
- shirudo_json_kv_string(&e, "keyring_mode", keyring_mode);
- shirudo_json_kv_bool(&e, "keyring_present", keyring_present);
+ json_kv_bool(&e, "lsm_attached", lsm_attached);
+ json_kv_string(&e, "mode", mode);
+ json_kv_string(&e, "keyring_mode", keyring_mode);
+ json_kv_bool(&e, "keyring_present", keyring_present);
if (keyring_present)
- shirudo_json_kv_int(&e, "keyring_serial",
- keyring_serial);
+ json_kv_int(&e, "keyring_serial",
+ keyring_serial);
else
- shirudo_json_kv_null(&e, "keyring_serial");
+ json_kv_null(&e, "keyring_serial");
if (keyring_pinned >= 1)
- shirudo_json_kv_int(&e, "keyring_serial_pinned",
- keyring_pinned);
+ json_kv_int(&e, "keyring_serial_pinned",
+ keyring_pinned);
else
- shirudo_json_kv_null(&e, "keyring_serial_pinned");
+ json_kv_null(&e, "keyring_serial_pinned");
if (keyring_present && keyring_pinned >= 1)
- shirudo_json_kv_bool(&e, "keyring_serial_matches",
- keyring_serial == keyring_pinned);
+ json_kv_bool(&e, "keyring_serial_matches",
+ keyring_serial == keyring_pinned);
else
- shirudo_json_kv_null(&e, "keyring_serial_matches");
- shirudo_json_kv_bool(&e, "cert_present", cert_present);
- shirudo_json_arr_open(&e, "certs");
+ json_kv_null(&e, "keyring_serial_matches");
+ json_kv_bool(&e, "cert_present", cert_present);
+ json_arr_open(&e, "certs");
for (i = 0; certs_rc == 0 && i < (int)certs.n; i++) {
char sha_hex[65], fp_hex[65];
- shirudo_hex_encode(certs.certs[i].sha256, 32, sha_hex);
- shirudo_hex_encode(certs.certs[i].fingerprint, 32,
- fp_hex);
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "sha256", sha_hex);
- shirudo_json_kv_string(&e, "fingerprint", fp_hex);
- shirudo_json_kv_bool(&e, "primary",
- certs.certs[i].primary);
- shirudo_json_obj_close(&e);
+ hex_encode(certs.certs[i].sha256, 32, sha_hex);
+ hex_encode(certs.certs[i].fingerprint, 32,
+ fp_hex);
+ json_obj_open(&e);
+ json_kv_string(&e, "sha256", sha_hex);
+ json_kv_string(&e, "fingerprint", fp_hex);
+ json_kv_bool(&e, "primary",
+ certs.certs[i].primary);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
- shirudo_json_kv_int(&e, "certs_revoked",
- certs_rc == 0 ? (int)certs.n_revoked : 0);
- shirudo_json_kv_int(&e, "certs_unvouched",
- certs_rc == 0 ? (int)certs.n_unvouched : 0);
+ json_arr_close(&e);
+ json_kv_int(&e, "certs_revoked",
+ certs_rc == 0 ? (int)certs.n_revoked : 0);
+ json_kv_int(&e, "certs_unvouched",
+ certs_rc == 0 ? (int)certs.n_unvouched : 0);
if (certs_enrolled >= 0)
- shirudo_json_kv_int(&e, "certs_enrolled",
- certs_enrolled);
+ json_kv_int(&e, "certs_enrolled",
+ certs_enrolled);
else
- shirudo_json_kv_null(&e, "certs_enrolled");
- shirudo_json_kv_bool(&e, "signing_key_present", is_operator);
+ json_kv_null(&e, "certs_enrolled");
+ json_kv_bool(&e, "signing_key_present", is_operator);
{
struct shirudo_upatch_table_row *rows = NULL;
size_t n_rows = build_upatches_table(ups, n_ups, &rows);
- shirudo_upatch_table_emit_json(&e, rows, n_rows);
+ upatch_table_emit_json(&e, rows, n_rows);
xfree(rows, n_rows * sizeof(*rows));
}
- shirudo_json_obj_open_key(&e, "assets");
- shirudo_json_kv_string(&e, "root", SHIRUDO_VAR_LIB);
- shirudo_json_kv_bool(&e, "cert", assets.cert);
- shirudo_json_kv_bool(&e, "signing_key", assets.signing_key);
- shirudo_json_kv_bool(&e, "eventlog", assets.eventlog);
- shirudo_json_kv_int(&e, "eventlog_bytes", assets.eventlog_bytes);
+ json_obj_open_key(&e, "assets");
+ json_kv_string(&e, "root", SHIRUDO_VAR_LIB);
+ json_kv_bool(&e, "cert", assets.cert);
+ json_kv_bool(&e, "signing_key", assets.signing_key);
+ json_kv_bool(&e, "eventlog", assets.eventlog);
+ json_kv_int(&e, "eventlog_bytes", assets.eventlog_bytes);
if (assets.n_upatches >= 0)
- shirudo_json_kv_int(&e, "upatches", assets.n_upatches);
+ json_kv_int(&e, "upatches", assets.n_upatches);
else
- shirudo_json_kv_null(&e, "upatches");
+ json_kv_null(&e, "upatches");
if (assets.n_incoming >= 0)
- shirudo_json_kv_int(&e, "incoming", assets.n_incoming);
+ json_kv_int(&e, "incoming", assets.n_incoming);
else
- shirudo_json_kv_null(&e, "incoming");
- shirudo_json_kv_bool(&e, "bpffs_mounted", assets.bpffs_mounted);
- shirudo_json_obj_close(&e);
+ json_kv_null(&e, "incoming");
+ json_kv_bool(&e, "bpffs_mounted", assets.bpffs_mounted);
+ json_obj_close(&e);
/*
* What the guards refused this boot, every counter by name
* so a collector's keys stay the same from one record to
* the next; null until init has pinned the map.
*/
if (tamper_rc == 0) {
- shirudo_json_obj_open_key(&e, "tamper_attempts");
- shirudo_json_kv_int(&e, "total", (__s64)tamper.total);
- shirudo_json_obj_open_key(&e, "counters");
+ json_obj_open_key(&e, "tamper_attempts");
+ json_kv_int(&e, "total", (__s64)tamper.total);
+ json_obj_open_key(&e, "counters");
for (i = 0; i < SHIRUDO_TAMPER_MAX; i++)
- shirudo_json_kv_int(&e, shirudo_tamper_name(i),
- (__s64)tamper.count[i]);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_kv_int(&e, tamper_name(i),
+ (__s64)tamper.count[i]);
+ json_obj_close(&e);
+ json_obj_close(&e);
} else {
- shirudo_json_kv_null(&e, "tamper_attempts");
+ json_kv_null(&e, "tamper_attempts");
}
if (include_system)
- shirudo_sysinfo_emit_json(&e, &sysi);
+ sysinfo_emit_json(&e, &sysi);
{
- shirudo_json_obj_open_key(&e, "tpm");
- shirudo_json_kv_string(&e, "nv_index", nv_index);
+ json_obj_open_key(&e, "tpm");
+ json_kv_string(&e, "nv_index", nv_index);
if (chain_rc == 0)
- shirudo_json_kv_string(&e, "chain", chain_hex);
+ json_kv_string(&e, "chain", chain_hex);
else
- shirudo_json_kv_null(&e, "chain");
+ json_kv_null(&e, "chain");
if (chain_rc == 0)
- shirudo_json_kv_string(&e, "nv_name", name_hex);
+ json_kv_string(&e, "nv_name", name_hex);
else
- shirudo_json_kv_null(&e, "nv_name");
- shirudo_json_kv_bool(&e, "register_bound",
- chain_rc == 0);
- shirudo_json_kv_bool(&e, "register_anchored",
- cst.anchored);
- shirudo_json_kv_int(&e, "init_records",
- cst.logged ? (int)cst.init.records :
- 0);
- shirudo_json_kv_bool(&e, "register_rebound",
- cst.rebound);
- shirudo_json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
- shirudo_json_kv_int(&e, "phase_pcr",
- SHIRUDO_CHAIN_PHASE_PCR);
+ json_kv_null(&e, "nv_name");
+ json_kv_bool(&e, "register_bound",
+ chain_rc == 0);
+ json_kv_bool(&e, "register_anchored",
+ cst.anchored);
+ json_kv_int(&e, "init_records",
+ cst.logged ? (int)cst.init.records :
+ 0);
+ json_kv_bool(&e, "register_rebound",
+ cst.rebound);
+ json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
+ json_kv_int(&e, "phase_pcr",
+ SHIRUDO_CHAIN_PHASE_PCR);
if (cst.logged) {
- shirudo_json_kv_string(&e, "pcr_before",
- pcr_before_hex);
- shirudo_json_kv_string(&e, "phase_before",
- phase_before_hex);
- shirudo_json_kv_string(&e, "bound_in",
- cst.init.initrd ?
- "initrd" : "root");
+ json_kv_string(&e, "pcr_before",
+ pcr_before_hex);
+ json_kv_string(&e, "phase_before",
+ phase_before_hex);
+ json_kv_string(&e, "bound_in",
+ cst.init.initrd ?
+ "initrd" : "root");
} else {
- shirudo_json_kv_null(&e, "pcr_before");
- shirudo_json_kv_null(&e, "phase_before");
- shirudo_json_kv_null(&e, "bound_in");
+ json_kv_null(&e, "pcr_before");
+ json_kv_null(&e, "phase_before");
+ json_kv_null(&e, "bound_in");
}
if (match < 0)
- shirudo_json_kv_null(&e, "chain_matches_eventlog");
+ json_kv_null(&e, "chain_matches_eventlog");
else
- shirudo_json_kv_bool(&e, "chain_matches_eventlog",
- match);
- shirudo_json_obj_open_key(&e, "eventlog");
- shirudo_json_kv_bool(&e, "present", ev_rc == 0);
- shirudo_json_kv_int(&e, "entries",
- ev_rc == 0 ? ev_entries : 0);
- shirudo_json_kv_int(&e, "bytes", ev_rc == 0 ? ev_bytes : 0);
+ json_kv_bool(&e, "chain_matches_eventlog",
+ match);
+ json_obj_open_key(&e, "eventlog");
+ json_kv_bool(&e, "present", ev_rc == 0);
+ json_kv_int(&e, "entries",
+ ev_rc == 0 ? ev_entries : 0);
+ json_kv_int(&e, "bytes", ev_rc == 0 ? ev_bytes : 0);
if (include_eventlog)
emit_eventlog_events(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_tree_emit_status(&e);
+ json_obj_close(&e);
+ json_obj_close(&e);
+ tree_emit_status(&e);
}
if (include_kernel_log) {
size_t bytes = (size_t)kernel_log_lines *
sizeof(struct shirudo_kmsg_record);
struct shirudo_kmsg_record *recs = xmalloc(bytes);
- int nr = recs ? shirudo_kmsg_tail(recs, kernel_log_lines)
+ int nr = recs ? kmsg_tail(recs, kernel_log_lines)
: -ENOMEM;
int j;
- shirudo_json_arr_open(&e, "kernel_log");
+ json_arr_open(&e, "kernel_log");
for (j = 0; j < nr; j++) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "ts", recs[j].ts);
- shirudo_json_kv_string(&e, "msg", recs[j].msg);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "ts", recs[j].ts);
+ json_kv_string(&e, "msg", recs[j].msg);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
+ json_arr_close(&e);
xfree(recs, bytes);
}
if (include_modules) {
struct shirudo_kmod_set ks = {};
- int mrc = shirudo_kmodules_read(&ks);
+ int mrc = kmodules_read(&ks);
struct timespec rt = {}, bt = {};
__s64 boot_sec = 0;
char boot_iso[32] = "";
@@ -951,12 +951,12 @@ int cmd_status(int argc, const char **argv)
if (clock_gettime(CLOCK_REALTIME, &rt) == 0 &&
clock_gettime(CLOCK_BOOTTIME, &bt) == 0) {
boot_sec = (__s64)rt.tv_sec - bt.tv_sec;
- shirudo_iso8601((time_t)boot_sec, boot_iso,
- sizeof(boot_iso));
+ iso8601((time_t)boot_sec, boot_iso,
+ sizeof(boot_iso));
}
- shirudo_json_kv_string(&e, "boot_at",
- boot_iso[0] ? boot_iso : "");
- shirudo_json_arr_open(&e, "modules");
+ json_kv_string(&e, "boot_at",
+ boot_iso[0] ? boot_iso : "");
+ json_arr_open(&e, "modules");
if (mrc == 0) {
for (mi = 0; mi < ks.n; mi++) {
const struct shirudo_kmod *m =
@@ -966,40 +966,40 @@ int cmd_status(int argc, const char **argv)
__u16 di;
if (at > 0)
- shirudo_iso8601(at, iso,
- sizeof(iso));
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name",
- m->name);
- shirudo_json_kv_int(&e, "size",
- (__s64)m->size);
- shirudo_json_kv_int(&e, "refcount",
- m->refcount);
- shirudo_json_kv_string(&e, "loaded_at",
- iso);
+ iso8601(at, iso,
+ sizeof(iso));
+ json_obj_open(&e);
+ json_kv_string(&e, "name",
+ m->name);
+ json_kv_int(&e, "size",
+ (__s64)m->size);
+ json_kv_int(&e, "refcount",
+ m->refcount);
+ json_kv_string(&e, "loaded_at",
+ iso);
if (boot_sec > 0 &&
m->loaded_at_sec >= boot_sec)
- shirudo_json_kv_int(&e,
- "since_boot_sec",
- m->loaded_at_sec - boot_sec);
+ json_kv_int(&e,
+ "since_boot_sec",
+ m->loaded_at_sec - boot_sec);
else
- shirudo_json_kv_null(&e,
- "since_boot_sec");
- shirudo_json_arr_open(&e, "deps");
+ json_kv_null(&e,
+ "since_boot_sec");
+ json_arr_open(&e, "deps");
for (di = 0; di < m->n_deps; di++) {
size_t dk = ks.deps[m->deps_off
+ di];
- shirudo_json_str(&e,
- ks.mods[dk].name);
+ json_str(&e,
+ ks.mods[dk].name);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
}
}
- shirudo_json_arr_close(&e);
- shirudo_kmodules_free(&ks);
+ json_arr_close(&e);
+ kmodules_free(&ks);
}
- shirudo_json_obj_close(&e);
+ json_obj_close(&e);
if (e.err) {
fprintf(stderr, "status: json encode failed: %s\n",
@@ -1014,15 +1014,15 @@ int cmd_status(int argc, const char **argv)
severity_number = status_otel_severity(otel_status,
&severity_text);
- rc = shirudo_otel_send_log_json(&otel_opts,
- "shirudo.keepalive",
- "shirudo.keepalive",
- severity_number,
- severity_text,
- otel_status,
- shirudo_version_id,
- refused, json_buf,
- strlen(json_buf));
+ rc = otel_send_log_json(&otel_opts,
+ "shirudo.keepalive",
+ "shirudo.keepalive",
+ severity_number,
+ severity_text,
+ otel_status,
+ shirudo_version_id,
+ refused, json_buf,
+ strlen(json_buf));
if (rc) {
pr_err("status: OTEL export failed: %s",
strerror(-rc));
@@ -1053,9 +1053,9 @@ int cmd_status(int argc, const char **argv)
chain_rc == 0,
match == 1, match >= 0,
nv_index);
- verdict = shirudo_status_verdict(&cin);
- shirudo_status_reason(&cin, reason, sizeof(reason));
- nc = shirudo_conditions(&cin, conds, ARRAY_SIZE(conds));
+ verdict = status_verdict(&cin);
+ status_reason(&cin, reason, sizeof(reason));
+ nc = conditions(&cin, conds, ARRAY_SIZE(conds));
n_rows = build_upatches_table(ups, n_ups, &rows);
(void)gethostname(hostname, sizeof(hostname));
hostname[sizeof(hostname) - 1] = '\0';
@@ -1077,7 +1077,7 @@ int cmd_status(int argc, const char **argv)
printf("Version-ID: %s\n", shirudo_version_id);
printf("\n");
- shirudo_conditions_print(conds, nc);
+ conditions_print(conds, nc);
printf("\nTamper attempts (refused this boot):\n");
if (tamper_rc == -ENOENT)
@@ -1090,9 +1090,9 @@ int cmd_status(int argc, const char **argv)
for (i = 0; tamper_rc == 0 && i < SHIRUDO_TAMPER_MAX; i++) {
if (tamper.count[i])
printf(" %-20s %6llu %s\n",
- shirudo_tamper_name(i),
+ tamper_name(i),
(__u64)tamper.count[i],
- shirudo_tamper_meaning(i));
+ tamper_meaning(i));
}
printf("\nKeyring (%s):\n", SHIRUDO_KEYRING_NAME);
@@ -1123,8 +1123,8 @@ int cmd_status(int argc, const char **argv)
for (i = 0; i < (int)certs.n; i++) {
char fp_hex[65];
- shirudo_hex_encode(certs.certs[i].fingerprint,
- 32, fp_hex);
+ hex_encode(certs.certs[i].fingerprint,
+ 32, fp_hex);
printf(" %s%s\n", fp_hex,
certs.certs[i].primary ? " (primary)" :
"");
@@ -1136,7 +1136,7 @@ int cmd_status(int argc, const char **argv)
print_kernel_config_human(&sysi);
}
- shirudo_upatch_table_print(rows, n_rows);
+ upatch_table_print(rows, n_rows);
xfree(rows, n_rows * sizeof(*rows));
rows = NULL;
@@ -1175,7 +1175,7 @@ int cmd_status(int argc, const char **argv)
match ? "matches" : "MISMATCH (tamper?)");
if (ev_rc == 0)
printf(" %-18s %s (%ld entries, %ld bytes)\n",
- "Eventlog:", shirudo_eventlog_path(),
+ "Eventlog:", eventlog_path(),
ev_entries, ev_bytes);
else
printf(" %-18s absent\n", "Eventlog:");
@@ -1213,7 +1213,7 @@ int cmd_status(int argc, const char **argv)
size_t bytes = (size_t)kernel_log_lines *
sizeof(struct shirudo_kmsg_record);
struct shirudo_kmsg_record *recs = xmalloc(bytes);
- int nr = recs ? shirudo_kmsg_tail(recs, kernel_log_lines)
+ int nr = recs ? kmsg_tail(recs, kernel_log_lines)
: -ENOMEM;
int j;
@@ -1230,7 +1230,7 @@ int cmd_status(int argc, const char **argv)
}
if (include_modules) {
struct shirudo_kmod_set ks = {};
- int mrc = shirudo_kmodules_read(&ks);
+ int mrc = kmodules_read(&ks);
struct timespec rt = {}, bt = {};
__s64 boot_sec = 0;
size_t last = 10;
@@ -1247,25 +1247,25 @@ int cmd_status(int argc, const char **argv)
printf("\nLoaded modules (total %zu, "
"last %zu loads, newest first):\n",
ks.n, shown);
- shirudo_kmodules_print_recent(&ks, last,
- boot_sec);
+ kmodules_print_recent(&ks, last,
+ boot_sec);
if (!show_full) {
printf(" (Use --show-full to show "
"all loaded modules in a "
"dependency tree)\n");
} else {
printf("\nDependency tree:\n");
- shirudo_kmodules_print_tree(&ks);
+ kmodules_print_tree(&ks);
}
}
- shirudo_kmodules_free(&ks);
+ kmodules_free(&ks);
}
}
out:
for (i = 0; i < n_ups; i++)
- shirudo_libc_free(ups[i]);
- shirudo_libc_free(ups);
+ libc_free(ups[i]);
+ libc_free(ups);
if (json_buf)
xfree(json_buf, json_cap);
return ret;
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 01542e88..d82b9daa 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -109,7 +109,7 @@ static const char *cat_from_load_errno(int e)
static const char *flag_str(const struct shirudo_upatch *u)
{
- return shirudo_upatch_is_unload(u) ? "UNLOAD-directive" : "LOAD";
+ return upatch_is_unload(u) ? "UNLOAD-directive" : "LOAD";
}
static const char *decoder_language_str(__u32 language)
@@ -134,7 +134,7 @@ static int print_sha256_hex(const __u8 hash[32])
{
char hex[65];
- shirudo_hex_encode(hash, 32, hex);
+ hex_encode(hash, 32, hex);
return fputs(hex, stdout) < 0 ? -1 : 0;
}
@@ -285,8 +285,8 @@ static int cmd_upatch_info(int argc, const char **argv)
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--json") == 0) {
json = true;
- } else if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&upatch_info_help);
+ } else if (is_help(argv[i])) {
+ print_help(&upatch_info_help);
return 0;
} else if (argv[i][0] == '-') {
fprintf(stderr, "upatch info: unknown option '%s'\n",
@@ -301,11 +301,11 @@ static int cmd_upatch_info(int argc, const char **argv)
}
}
if (!path) {
- shirudo_print_help(&upatch_info_help);
+ print_help(&upatch_info_help);
return 2;
}
- rc = shirudo_upatch_open(path, &u);
+ rc = upatch_open(path, &u);
if (rc != 0) {
pr_err("upatch info: %s: %s", path, strerror(-rc));
return 1;
@@ -324,48 +324,48 @@ static int cmd_upatch_info(int argc, const char **argv)
goto out;
e.buf = buf;
e.cap = cap;
- shirudo_hex_encode(u.hdr.payload_sha256, 32, payload_hex);
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "path", path);
- shirudo_json_kv_string(&e, "name", name);
- shirudo_json_kv_string(&e, "type",
- shirudo_upatch_is_unload(&u) ? "unload"
+ hex_encode(u.hdr.payload_sha256, 32, payload_hex);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "path", path);
+ json_kv_string(&e, "name", name);
+ json_kv_string(&e, "type",
+ upatch_is_unload(&u) ? "unload"
: "load");
- shirudo_json_kv_string(&e, "payload_type",
- shirudo_upatch_type_str(&u));
- shirudo_json_kv_int(&e, "version", u.hdr.version);
- shirudo_json_kv_string(&e, "payload_sha256", payload_hex);
- shirudo_json_kv_int(&e, "loader_insns_len",
- u.hdr.loader_insns_len);
- shirudo_json_kv_int(&e, "signature_len", u.hdr.signature_len);
- shirudo_json_kv_int(&e, "metadata_len", u.hdr.metadata_len);
- shirudo_json_kv_int(&e, "data_len", u.hdr.data_len);
- shirudo_json_kv_int(&e, "log_buf_sz", u.hdr.log_buf_sz);
- shirudo_json_kv_int(&e, "file_size", (__s64)u.map_size);
- shirudo_json_arr_open(&e, "decoders");
+ json_kv_string(&e, "payload_type",
+ upatch_type_str(&u));
+ json_kv_int(&e, "version", u.hdr.version);
+ json_kv_string(&e, "payload_sha256", payload_hex);
+ json_kv_int(&e, "loader_insns_len",
+ u.hdr.loader_insns_len);
+ json_kv_int(&e, "signature_len", u.hdr.signature_len);
+ json_kv_int(&e, "metadata_len", u.hdr.metadata_len);
+ json_kv_int(&e, "data_len", u.hdr.data_len);
+ json_kv_int(&e, "log_buf_sz", u.hdr.log_buf_sz);
+ json_kv_int(&e, "file_size", (__s64)u.map_size);
+ json_arr_open(&e, "decoders");
for (__u32 j = 0; j < u.nr_decoders; j++) {
- struct shirudo_upatch_decoder_view d;
+ struct upatch_decoder_view d;
- if (shirudo_upatch_decoder_view(&u, j, &d))
+ if (upatch_decoder_view(&u, j, &d))
continue;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "language",
- decoder_language_str(d.language));
- shirudo_json_kv_int(&e, "api_version", d.api_version);
- shirudo_json_kv_string(&e, "input_format",
- decoder_input_str(d.input_format));
- shirudo_json_kv_string(&e, "export_signal",
- decoder_signal_str(d.export_signal));
- shirudo_json_kv_string(&e, "upatch", d.upatch);
- shirudo_json_kv_string(&e, "map", d.map);
- shirudo_json_kv_string(&e, "source_file", d.source_name);
- shirudo_json_kv_string(&e, "entrypoint", d.entrypoint);
- shirudo_json_kv_int(&e, "source_len", d.source_len);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "language",
+ decoder_language_str(d.language));
+ json_kv_int(&e, "api_version", d.api_version);
+ json_kv_string(&e, "input_format",
+ decoder_input_str(d.input_format));
+ json_kv_string(&e, "export_signal",
+ decoder_signal_str(d.export_signal));
+ json_kv_string(&e, "upatch", d.upatch);
+ json_kv_string(&e, "map", d.map);
+ json_kv_string(&e, "source_file", d.source_name);
+ json_kv_string(&e, "entrypoint", d.entrypoint);
+ json_kv_int(&e, "source_len", d.source_len);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err)
fprintf(stderr, "upatch info: json encode failed: %s\n",
strerror(-e.err));
@@ -379,7 +379,7 @@ static int cmd_upatch_info(int argc, const char **argv)
printf("File: %s\n", path);
printf("Name: %s\n", name);
printf("Type: %s\n", flag_str(&u));
- printf("Payload type: %s\n", shirudo_upatch_type_str(&u));
+ printf("Payload type: %s\n", upatch_type_str(&u));
printf("Version: %u\n", u.hdr.version);
printf("Payload SHA256: ");
print_sha256_hex(u.hdr.payload_sha256);
@@ -406,13 +406,13 @@ static int cmd_upatch_info(int argc, const char **argv)
printf(" %-22s %u bytes\n", "Length:", u.hdr.signature_len);
printf("\nDecoders:\n");
- if (!shirudo_upatch_has_decoders(&u)) {
+ if (!upatch_has_decoders(&u)) {
printf(" (none)\n");
} else {
for (__u32 j = 0; j < u.nr_decoders; j++) {
- struct shirudo_upatch_decoder_view d;
+ struct upatch_decoder_view d;
- if (shirudo_upatch_decoder_view(&u, j, &d))
+ if (upatch_decoder_view(&u, j, &d))
continue;
printf(" %-22s %s/%s\n", "Target:", d.upatch, d.map);
printf(" %-20s %s (api=%u)\n", "Language:",
@@ -427,7 +427,7 @@ static int cmd_upatch_info(int argc, const char **argv)
}
ret = 0;
out:
- shirudo_upatch_close(&u);
+ upatch_close(&u);
return ret;
}
@@ -445,14 +445,14 @@ static bool upatch_is_loaded(const char *name)
struct stat st;
int fd;
- fd = shirudo_upatch_open_first_link(name);
+ fd = upatch_open_first_link(name);
if (fd < 0)
goto test_pin;
close(fd);
return true;
test_pin:
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return false;
if (snprintf(pin, sizeof(pin), "%s/%s/test",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >= (int)sizeof(pin))
@@ -476,8 +476,8 @@ static int cmd_upatch_list(int argc, const char **argv)
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--json") == 0) {
json = true;
- } else if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&upatch_list_help);
+ } else if (is_help(argv[i])) {
+ print_help(&upatch_list_help);
return 0;
} else {
fprintf(stderr, "upatch list: unknown option '%s'\n",
@@ -502,9 +502,9 @@ static int cmd_upatch_list(int argc, const char **argv)
}
e.buf = jbuf;
e.cap = 65536;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_arr_open(&e, "upatches");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_arr_open(&e, "upatches");
} else {
printf("upatches (%s):\n", SHIRUDO_UPATCHES_DIR);
if (np == 0)
@@ -525,7 +525,7 @@ static int cmd_upatch_list(int argc, const char **argv)
SHIRUDO_UPATCHES_DIR,
persisted[i]->d_name) >= sizeof(path))
continue;
- if (shirudo_upatch_open(path, &u) != 0) {
+ if (upatch_open(path, &u) != 0) {
if (!json)
printf(" %-6s %-6s %-18s %s\n", "?", "?",
"(unreadable)", persisted[i]->d_name);
@@ -533,21 +533,21 @@ static int cmd_upatch_list(int argc, const char **argv)
}
memcpy(name, u.hdr.name, sizeof(u.hdr.name));
name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
- shirudo_hex_encode(u.hdr.payload_sha256, 32, payload_hex);
- type = shirudo_upatch_is_unload(&u) ? "unload" : "load";
- payload_type = shirudo_upatch_type_str(&u);
+ hex_encode(u.hdr.payload_sha256, 32, payload_hex);
+ type = upatch_is_unload(&u) ? "unload" : "load";
+ payload_type = upatch_type_str(&u);
loaded = upatch_is_loaded(name);
- shirudo_upatch_close(&u);
+ upatch_close(&u);
if (json) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", name);
- shirudo_json_kv_string(&e, "type", type);
- shirudo_json_kv_string(&e, "payload_type", payload_type);
- shirudo_json_kv_bool(&e, "loaded", loaded);
- shirudo_json_kv_bool(&e, "persisted", 1);
- shirudo_json_kv_string(&e, "payload_sha256", payload_hex);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "name", name);
+ json_kv_string(&e, "type", type);
+ json_kv_string(&e, "payload_type", payload_type);
+ json_kv_bool(&e, "loaded", loaded);
+ json_kv_bool(&e, "persisted", 1);
+ json_kv_string(&e, "payload_sha256", payload_hex);
+ json_obj_close(&e);
} else {
char shown[19];
@@ -566,7 +566,7 @@ static int cmd_upatch_list(int argc, const char **argv)
if (strcmp(nm, ".") == 0 || strcmp(nm, "..") == 0)
continue;
- if (shirudo_upatch_name_from_bpffs(raw_name, sizeof(raw_name), nm))
+ if (upatch_name_from_bpffs(raw_name, sizeof(raw_name), nm))
continue;
if ((size_t)snprintf(persist, sizeof(persist), "%s/%s.upatch",
SHIRUDO_UPATCHES_DIR, raw_name) >= sizeof(persist))
@@ -575,13 +575,13 @@ static int cmd_upatch_list(int argc, const char **argv)
continue;
if (json) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", raw_name);
- shirudo_json_kv_null(&e, "type");
- shirudo_json_kv_bool(&e, "loaded", 1);
- shirudo_json_kv_bool(&e, "persisted", 0);
- shirudo_json_kv_null(&e, "payload_sha256");
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "name", raw_name);
+ json_kv_null(&e, "type");
+ json_kv_bool(&e, "loaded", 1);
+ json_kv_bool(&e, "persisted", 0);
+ json_kv_null(&e, "payload_sha256");
+ json_obj_close(&e);
} else {
printf(" %-6s %-6s %-18s %s (orphan: no persisted "
".upatch, will not survive reboot)\n",
@@ -590,8 +590,8 @@ static int cmd_upatch_list(int argc, const char **argv)
}
if (json) {
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
fprintf(stderr, "upatch list: json encode failed: %s\n",
strerror(-e.err));
@@ -603,11 +603,11 @@ static int cmd_upatch_list(int argc, const char **argv)
out:
for (i = 0; i < np; i++)
- shirudo_libc_free(persisted[i]);
- shirudo_libc_free(persisted);
+ libc_free(persisted[i]);
+ libc_free(persisted);
for (j = 0; j < na; j++)
- shirudo_libc_free(active[j]);
- shirudo_libc_free(active);
+ libc_free(active[j]);
+ libc_free(active);
if (jbuf)
xfree(jbuf, 65536);
return rc;
@@ -1055,7 +1055,7 @@ static int prepare_uprobe_targets(struct shirudo_prog_spec *specs,
return -ERANGE;
}
}
- rc = shirudo_elf_build_id_fd(fd, build_id, &build_id_len);
+ rc = elf_build_id_fd(fd, build_id, &build_id_len);
if (rc) {
close(fd);
return rc == -EACCES || rc == -EPERM ? rc : -ESTALE;
@@ -1198,7 +1198,7 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
pr_warn("upatch carries no programs to attach");
return 0;
}
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return -ENAMETOOLONG;
rc = mkdir_if_absent(SHIRUDO_BPFFS_UPATCHES_DIR, 0700, NULL);
@@ -1313,8 +1313,8 @@ static int attach_and_pin_progs(const struct shirudo_loader_ctx *cx,
__u32 retval = 0;
/* A zero context is the load-time arena initialization call. */
- rc = shirudo_prog_test_run(test_fd, init_ctx, sizeof(init_ctx),
- &retval);
+ rc = prog_test_run(test_fd, init_ctx, sizeof(init_ctx),
+ &retval);
if (rc || (__s32)retval < 0) {
pr_err("initialize test-run arena: %s",
rc ? strerror(-rc) : strerror(-(__s32)retval));
@@ -1360,7 +1360,7 @@ static int pin_upatch_maps(const struct shirudo_loader_ctx *cx,
if (nr_maps == 0)
return 0;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return 0;
if (snprintf(dir, sizeof(dir), "%s/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >=
@@ -1426,7 +1426,7 @@ static void set_pin_payload(const char *name, const __u8 payload[32])
char dir[PATH_MAX];
char bpffs_name[SHIRUDO_UPATCH_BPFFS_NAME_MAX + 1];
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return;
if (snprintf(dir, sizeof(dir), "%s/%s", SHIRUDO_BPFFS_UPATCHES_DIR,
bpffs_name) >= (int)sizeof(dir))
@@ -1443,7 +1443,7 @@ static int get_pin_payload(const char *name, __u8 out[32])
char bpffs_name[SHIRUDO_UPATCH_BPFFS_NAME_MAX + 1];
ssize_t n;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return -ENAMETOOLONG;
if (snprintf(dir, sizeof(dir), "%s/%s", SHIRUDO_BPFFS_UPATCHES_DIR,
bpffs_name) >= (int)sizeof(dir))
@@ -1470,7 +1470,7 @@ static int trust_anchor_keyring(key_serial_t *keyring,
key_serial_t ring;
int rc;
- rc = shirudo_identity_read(&id);
+ rc = identity_read(&id);
if (rc) {
pr_err("no trust anchor frozen this boot: %s (run `shirudo "
"init`)", strerror(-rc));
@@ -1479,7 +1479,7 @@ static int trust_anchor_keyring(key_serial_t *keyring,
return -1;
}
if (id.keyring_type == SHIRUDO_SIG_KEYRING_BPF) {
- ring = shirudo_keyring_bpf_serial();
+ ring = keyring_bpf_serial();
if (ring != id.keyring_serial) {
pr_err("the kernel's bpf keyring (%d) is not the one "
"init sealed (%d)", (int)ring,
@@ -1491,7 +1491,7 @@ static int trust_anchor_keyring(key_serial_t *keyring,
*keyring = KEY_SPEC_BPF_KEYRING;
return 0;
}
- ring = shirudo_keyring_find(SHIRUDO_KEYRING_NAME);
+ ring = keyring_find(SHIRUDO_KEYRING_NAME);
if (ring < 0) {
pr_err("keyring \"%s\" not found: %s; the anchor frozen this "
"boot was serial %d", SHIRUDO_KEYRING_NAME,
@@ -1558,7 +1558,7 @@ static int upatch_apply(const char *path, bool verify_only,
}
vlog[0] = '\0';
- rc = shirudo_upatch_open(path, &u);
+ rc = upatch_open(path, &u);
if (rc) {
pr_err("open %s: %s", path, strerror(-rc));
rep_fail(rep, "parse", "parser_rejected", -rc,
@@ -1572,7 +1572,7 @@ static int upatch_apply(const char *path, bool verify_only,
* gate) -- so it deliberately accepts an UNLOAD directive and
* stops before TEST_RUN/attach.
*/
- if (!verify_only && shirudo_upatch_is_unload(&u)) {
+ if (!verify_only && upatch_is_unload(&u)) {
pr_err("upatch load: %s is an UNLOAD directive; "
"use `shirudo upatch unload`", path);
rep_fail(rep, "parse", "parser_rejected", 0,
@@ -1594,9 +1594,9 @@ static int upatch_apply(const char *path, bool verify_only,
goto out;
}
- insns = shirudo_upatch_loader(&u);
- sig = shirudo_upatch_signature(&u);
- data = shirudo_upatch_data(&u);
+ insns = upatch_loader(&u);
+ sig = upatch_signature(&u);
+ data = upatch_data(&u);
insn_cnt = u.hdr.loader_insns_len / sizeof(struct bpf_insn);
/* bpf_obj_name_cpy() takes alphanumerics, '_' and '.' alone. */
@@ -1639,10 +1639,10 @@ static int upatch_apply(const char *path, bool verify_only,
{
__u8 content_digest[SHIRUDO_UPATCH_PAYLOAD_HASH_LEN];
- shirudo_sha256_2(insns, u.hdr.loader_insns_len,
- data, u.hdr.data_len, content_digest);
- if (!shirudo_ct_eq(content_digest, u.hdr.payload_sha256,
- sizeof(content_digest))) {
+ sha256_2(insns, u.hdr.loader_insns_len,
+ data, u.hdr.data_len, content_digest);
+ if (!ct_eq(content_digest, u.hdr.payload_sha256,
+ sizeof(content_digest))) {
pr_err("upatch: payload_sha256 does not match signed "
"content (insns || data); refusing");
rep_fail(rep, "parse", "parser_rejected", 0,
@@ -1659,9 +1659,9 @@ static int upatch_apply(const char *path, bool verify_only,
* through link creation to prevent pathname replacement races.
*/
if (!verify_only) {
- rc = shirudo_prog_specs_parse(shirudo_upatch_metadata(&u),
- u.hdr.metadata_len,
- u.hdr.nr_progs, &prog_specs);
+ rc = prog_specs_parse(upatch_metadata(&u),
+ u.hdr.metadata_len,
+ u.hdr.nr_progs, &prog_specs);
if (rc) {
pr_err("upatch program metadata rejected: %s",
strerror(-rc));
@@ -1750,7 +1750,7 @@ static int upatch_apply(const char *path, bool verify_only,
fprintf(stderr, "loader verifier log:\n%s\n", vlog);
rep_fail(rep, "signed_loader_load", cat_from_load_errno(e), e,
"BPF_PROG_LOAD of signed loader failed");
- shirudo_report_set_log(rep, vlog);
+ report_set_log(rep, vlog);
rc = 1;
goto out;
}
@@ -1799,14 +1799,14 @@ static int upatch_apply(const char *path, bool verify_only,
cx->log_size = SHIRUDO_VERIFIER_LOG_MAX;
cx->log_buf = ptr_to_u64(vlog);
- rc = shirudo_prog_test_run(prog_fd, cx, (__u32)ctx_sz, &retval);
+ rc = prog_test_run(prog_fd, cx, (__u32)ctx_sz, &retval);
if (rc) {
pr_err("BPF_PROG_TEST_RUN: %s", strerror(errno));
if (vlog[0])
fprintf(stderr, "loader runtime log:\n%s\n", vlog);
rep_fail(rep, "payload_load", "verifier_rejected", errno,
"BPF_PROG_TEST_RUN failed");
- shirudo_report_set_log(rep, vlog);
+ report_set_log(rep, vlog);
rc = 1;
goto out;
}
@@ -1818,7 +1818,7 @@ static int upatch_apply(const char *path, bool verify_only,
-(__s32)retval, "inner loader returned error");
if (rep)
rep->loader_return = (__s32)retval;
- shirudo_report_set_log(rep, vlog);
+ report_set_log(rep, vlog);
rc = 1;
goto out;
}
@@ -1863,7 +1863,7 @@ static int upatch_apply(const char *path, bool verify_only,
rep->loader_return = (__s32)retval;
rc = 0;
out:
- shirudo_prog_specs_free(prog_specs, u.hdr.nr_progs);
+ prog_specs_free(prog_specs, u.hdr.nr_progs);
xfree(vlog, SHIRUDO_VERIFIER_LOG_MAX);
if (cx)
close_loader_fds(cx, u.hdr.nr_maps, u.hdr.nr_progs);
@@ -1872,7 +1872,7 @@ out:
close(prog_fd);
if (map_fd >= 0)
close(map_fd);
- shirudo_upatch_close(&u);
+ upatch_close(&u);
return rc;
}
@@ -1895,7 +1895,7 @@ static int upatch_preflight(const char *expect_chain,
key_serial_t keyring;
int fd, rc;
- rc = shirudo_kernel_abi_check(abi_detail, sizeof(abi_detail));
+ rc = kernel_abi_check(abi_detail, sizeof(abi_detail));
if (rc) {
pr_err("upatch: pre-flight refused (category: "
"kernel_abi_unsupported, message: %s)", abi_detail);
@@ -1919,12 +1919,12 @@ static int upatch_preflight(const char *expect_chain,
if (!expect_chain)
return 0;
- if (shirudo_hex_decode(expect_chain, want, sizeof(want))) {
+ if (hex_decode(expect_chain, want, sizeof(want))) {
pr_err("upatch load: --expect-chain must be %d hex chars",
2 * SHIRUDO_CHAIN_DIGEST_LEN);
return -1;
}
- rc = shirudo_chain_read(have);
+ rc = chain_read(have);
if (rc == -ENODEV) {
pr_err("upatch load: pre-flight refused (category: tampered, "
"message: chain_drift) -- register unreadable, cannot "
@@ -1935,8 +1935,8 @@ static int upatch_preflight(const char *expect_chain,
pr_err("upatch load: chain read failed: %s", strerror(-rc));
return -1;
}
- if (!shirudo_ct_eq(want, have, sizeof(want))) {
- shirudo_hex_encode(have, sizeof(have), have_hex);
+ if (!ct_eq(want, have, sizeof(want))) {
+ hex_encode(have, sizeof(have), have_hex);
pr_err("upatch load: pre-flight refused (category: tampered, "
"message: chain_drift) -- live chain %s != expected; "
"re-status and re-issue with the refreshed value",
@@ -1954,11 +1954,11 @@ static int eventlog_room(struct shirudo_op_report *rep, const char *op)
{
struct shirudo_config cfg;
- shirudo_config_load(&cfg);
- if (shirudo_eventlog_would_exceed(cfg.eventlog_max_bytes)) {
+ config_load(&cfg);
+ if (eventlog_would_exceed(cfg.eventlog_max_bytes)) {
pr_err("upatch %s: eventlog %s would exceed "
"eventlog.max_bytes=%llu; refusing -- no load, no extend",
- op, shirudo_eventlog_path(), cfg.eventlog_max_bytes);
+ op, eventlog_path(), cfg.eventlog_max_bytes);
rep_fail(rep, "pre_flight", "eventlog_full", ENOSPC,
"eventlog would exceed eventlog.max_bytes");
return -1;
@@ -1995,34 +1995,34 @@ static int append_upatch_event(const char *type, const char *name,
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
char ts[32], boot_id[64], nv_index[16], payload_hex[65], digest_hex[65];
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_hex_encode(payload, 32, payload_hex);
- shirudo_hex_encode(event, 32, digest_hex);
-
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_json_kv_string(&e, "digest", digest_hex);
- shirudo_json_kv_string(&e, "type", type);
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_obj_open_key(&e, "upatch");
- shirudo_json_kv_string(&e, "name", name);
- shirudo_json_kv_string(&e, "payload_sha256", payload_hex);
- shirudo_json_obj_close(&e);
+ hex_encode(payload, 32, payload_hex);
+ hex_encode(event, 32, digest_hex);
+
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ json_kv_string(&e, "digest", digest_hex);
+ json_kv_string(&e, "type", type);
+ json_kv_string(&e, "boot_id", boot_id);
+ json_obj_open_key(&e, "upatch");
+ json_kv_string(&e, "name", name);
+ json_kv_string(&e, "payload_sha256", payload_hex);
+ json_obj_close(&e);
if (reason)
- shirudo_json_kv_string(&e, "reason", reason);
- shirudo_json_obj_close(&e);
+ json_kv_string(&e, "reason", reason);
+ json_obj_close(&e);
if (e.err) {
pr_err("eventlog: %s entry encode failed: %s", type,
strerror(-e.err));
return e.err;
}
- return shirudo_eventlog_append(buf);
+ return eventlog_append(buf);
}
/*
@@ -2041,9 +2041,9 @@ static int upatch_chain_event(const char *tag, const char *type,
if (out_chain)
out_chain[0] = '\0';
- shirudo_chain_upatch_event(tag, name, payload, event);
+ chain_upatch_event(tag, name, payload, event);
- rc = shirudo_chain_extend(event, chain);
+ rc = chain_extend(event, chain);
if (rc == -ENODEV) {
pr_err("upatch %s: TPM/register unavailable (category: "
"tpm_error) -- op done but NOT measured; shirudo "
@@ -2068,7 +2068,7 @@ static int upatch_chain_event(const char *tag, const char *type,
"chain/log desync; operator must reconcile", op);
return rc;
}
- shirudo_hex_encode(chain, 32, chain_hex);
+ hex_encode(chain, 32, chain_hex);
if (out_chain)
memcpy(out_chain, chain_hex, sizeof(chain_hex));
pr_info("upatch %s: chain extended, value=%s", op, chain_hex);
@@ -2132,12 +2132,12 @@ static int append_json_record(const char *path, const char *json, size_t len)
goto out_unlock;
}
if (last != '\n')
- rc = shirudo_write_all(fd, "\n", 1);
+ rc = write_all(fd, "\n", 1);
}
if (!rc)
- rc = shirudo_write_all(fd, json, len);
+ rc = write_all(fd, json, len);
if (!rc)
- rc = shirudo_write_all(fd, "\n", 1);
+ rc = write_all(fd, "\n", 1);
if (!rc && fsync(fd) != 0)
rc = -errno;
if (rc && ftruncate(fd, original_size) != 0)
@@ -2155,9 +2155,9 @@ static int print_json_record(const char *json, size_t len)
{
int rc;
- rc = shirudo_write_all(STDOUT_FILENO, json, len);
+ rc = write_all(STDOUT_FILENO, json, len);
if (!rc)
- rc = shirudo_write_all(STDOUT_FILENO, "\n", 1);
+ rc = write_all(STDOUT_FILENO, "\n", 1);
return rc;
}
@@ -2177,14 +2177,14 @@ static int copy_file_atomic(const char *src, const char *dst)
in = open(src, O_RDONLY | O_CLOEXEC);
if (in < 0)
return -errno;
- out = shirudo_seal_open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW,
- 0644);
+ out = seal_open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW,
+ 0644);
if (out < 0) {
close(in);
return out;
}
while ((r = read(in, buf, sizeof(buf))) > 0) {
- rc = shirudo_write_all(out, buf, (size_t)r);
+ rc = write_all(out, buf, (size_t)r);
if (rc)
break;
}
@@ -2219,7 +2219,7 @@ static int persist_upatch(const char *src, const char *name)
struct stat ss, ds;
int rc;
- rc = shirudo_seal_mkdir_p(SHIRUDO_UPATCHES_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_UPATCHES_DIR, 0700);
if (rc) {
pr_err("mkdir %s: %s", SHIRUDO_UPATCHES_DIR, strerror(-rc));
return rc;
@@ -2275,7 +2275,7 @@ static int parse_op_args(int argc, const char **argv, const char *verb,
}
}
if (!*file) {
- shirudo_print_help(help);
+ print_help(help);
return 2;
}
return 0;
@@ -2316,7 +2316,7 @@ static int remove_pin_dir(const char *name)
struct stat st;
int rc;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return -ENAMETOOLONG;
if (snprintf(dir, sizeof(dir), "%s/%s", SHIRUDO_BPFFS_UPATCHES_DIR,
bpffs_name) >= (int)sizeof(dir))
@@ -2354,15 +2354,15 @@ static int stage_upatch(const char *src, char *staged, size_t sz)
size_t len = 0;
int rc;
- rc = shirudo_read_file(src, SHIRUDO_UPATCH_FILE_MAX, &buf, &len);
+ rc = read_file(src, SHIRUDO_UPATCH_FILE_MAX, &buf, &len);
if (rc)
return rc;
- rc = shirudo_seal_mkdir_p(SHIRUDO_INCOMING_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_INCOMING_DIR, 0700);
if (!rc && snprintf(staged, sz, "%s/load-%d.upatch",
SHIRUDO_INCOMING_DIR, (int)getpid()) >= (int)sz)
rc = -ENAMETOOLONG;
if (!rc)
- rc = shirudo_seal_write_file(staged, buf, len, 0600);
+ rc = seal_write_file(staged, buf, len, 0600);
xfree(buf, len + 1);
if (rc)
staged[0] = '\0';
@@ -2381,8 +2381,8 @@ static int cmd_upatch_load(int argc, const char **argv)
int rc, ret = 1;
for (int i = 1; i < argc; i++) {
- if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&upatch_load_help);
+ if (is_help(argv[i])) {
+ print_help(&upatch_load_help);
return 0;
}
}
@@ -2405,7 +2405,7 @@ static int cmd_upatch_load(int argc, const char **argv)
}
file = staged;
- rc = shirudo_upatch_open(file, &u);
+ rc = upatch_open(file, &u);
if (rc) {
pr_err("open %s: %s", file, strerror(-rc));
rep_fail(&rep, "parse", "parser_rejected", -rc,
@@ -2415,9 +2415,9 @@ static int cmd_upatch_load(int argc, const char **argv)
memcpy(name, u.hdr.name, SHIRUDO_UPATCH_NAME_MAX);
name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
memcpy(payload, u.hdr.payload_sha256, sizeof(payload));
- shirudo_hex_encode(payload, sizeof(payload), rep.payload_hex);
+ hex_encode(payload, sizeof(payload), rep.payload_hex);
rep.name = name;
- shirudo_upatch_close(&u);
+ upatch_close(&u);
have_id = true;
if (no_precheck) {
@@ -2477,8 +2477,8 @@ done:
if (staged[0])
unlink(staged);
if (report)
- shirudo_report_emit(report, &rep);
- shirudo_report_free(&rep);
+ report_emit(report, &rep);
+ report_free(&rep);
return ret;
}
@@ -2494,8 +2494,8 @@ static int cmd_upatch_unload(int argc, const char **argv)
int rc, ret = 1;
for (int i = 1; i < argc; i++) {
- if (shirudo_is_help(argv[i])) {
- shirudo_print_help(&upatch_unload_help);
+ if (is_help(argv[i])) {
+ print_help(&upatch_unload_help);
return 0;
}
}
@@ -2509,31 +2509,31 @@ static int cmd_upatch_unload(int argc, const char **argv)
if (version_gate(expect_version_id, no_version_check, &rep, "unload") != 0)
goto done;
- rc = shirudo_upatch_open(file, &u);
+ rc = upatch_open(file, &u);
if (rc) {
pr_err("open %s: %s", file, strerror(-rc));
rep_fail(&rep, "parse", "parser_rejected", -rc,
"cannot open .upatch");
goto done;
}
- if (!shirudo_upatch_is_unload(&u)) {
+ if (!upatch_is_unload(&u)) {
pr_err("upatch unload: %s is a LOAD upatch; use "
"`shirudo upatch load`", file);
rep_fail(&rep, "parse", "parser_rejected", 0,
"is a LOAD upatch");
- shirudo_upatch_close(&u);
+ upatch_close(&u);
goto done;
}
memcpy(name, u.hdr.name, SHIRUDO_UPATCH_NAME_MAX);
name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
if (u.hdr.metadata_len == sizeof(payload))
- memcpy(payload, shirudo_upatch_metadata(&u), sizeof(payload));
+ memcpy(payload, upatch_metadata(&u), sizeof(payload));
else
pr_warn("upatch unload: directive carries no payload metadata; "
"chain event uses zeros");
- shirudo_upatch_close(&u);
+ upatch_close(&u);
rep.name = name;
- shirudo_hex_encode(payload, sizeof(payload), rep.payload_hex);
+ hex_encode(payload, sizeof(payload), rep.payload_hex);
if (!safe_upatch_name(name)) {
pr_err("upatch unload: refusing unsafe upatch name '%s'", name);
@@ -2582,7 +2582,7 @@ static int cmd_upatch_unload(int argc, const char **argv)
} else {
xrc = get_pin_payload(name, live);
if (xrc == 0) {
- if (!shirudo_ct_eq(live, payload, sizeof(payload))) {
+ if (!ct_eq(live, payload, sizeof(payload))) {
pr_err("upatch unload: payload_mismatch -- the "
"upatch loaded under '%s' is not what the "
"directive expects; refusing", name);
@@ -2650,8 +2650,8 @@ done:
rep.err ? strerror(rep.err) : "none",
rep.message[0] ? rep.message : "(none)");
if (report)
- shirudo_report_emit(report, &rep);
- shirudo_report_free(&rep);
+ report_emit(report, &rep);
+ report_free(&rep);
return ret;
}
@@ -2668,11 +2668,11 @@ int shirudo_upatch_purge(const char *name, const char *reason)
if (snprintf(persisted, sizeof(persisted), "%s/%s.upatch",
SHIRUDO_UPATCHES_DIR, name) >= (int)sizeof(persisted))
return -ENAMETOOLONG;
- rc = shirudo_upatch_open(persisted, &u);
+ rc = upatch_open(persisted, &u);
if (rc)
return rc;
memcpy(payload, u.hdr.payload_sha256, sizeof(payload));
- shirudo_upatch_close(&u);
+ upatch_close(&u);
rc = remove_pin_dir(name);
if (rc && rc != -ENOENT) {
@@ -2801,25 +2801,25 @@ static void emit_line_info_json(struct shirudo_json_emit *e,
{
__u32 i = 0;
- shirudo_json_arr_open(e, "files");
+ json_arr_open(e, "files");
while (i < k) {
const char *path = ents[i].file;
__u32 j;
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "path", path);
- shirudo_json_arr_open(e, "lines");
+ json_obj_open(e);
+ json_kv_string(e, "path", path);
+ json_arr_open(e, "lines");
for (j = i; j < k && strcmp(ents[j].file, path) == 0; j++) {
- shirudo_json_obj_open(e);
- shirudo_json_kv_int(e, "line", ents[j].line);
- shirudo_json_kv_string(e, "src", ents[j].src);
- shirudo_json_obj_close(e);
+ json_obj_open(e);
+ json_kv_int(e, "line", ents[j].line);
+ json_kv_string(e, "src", ents[j].src);
+ json_obj_close(e);
}
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
i = j;
}
- shirudo_json_arr_close(e);
+ json_arr_close(e);
}
static int append_one_map_json(const char *path,
@@ -2829,7 +2829,7 @@ static int append_one_map_json(const char *path,
size_t decoded_len = 0;
int rc;
- rc = shirudo_upatch_decode_map_json(v, &decoded, &decoded_len);
+ rc = upatch_decode_map_json(v, &decoded, &decoded_len);
if (rc == 0) {
while (decoded_len && (decoded[decoded_len - 1] == '\n' ||
decoded[decoded_len - 1] == '\r'))
@@ -2851,13 +2851,13 @@ static int export_one_map(const char *upatch, const char *map,
SHIRUDO_MAP_ENTRIES_DEFAULT;
int rc, ret = 0;
- rc = shirudo_upatch_maps_read_flags(upatch, map, cap,
- peek ? SHIRUDO_MAP_READ_PEEK : 0,
- &v);
+ rc = upatch_maps_read_flags(upatch, map, cap,
+ peek ? SHIRUDO_MAP_READ_PEEK : 0,
+ &v);
if (rc) {
pr_err("upatch map: read %s/%s: %s", upatch, map,
strerror(-rc));
- shirudo_map_view_free(&v);
+ map_view_free(&v);
return 1;
}
if (json_output) {
@@ -2875,10 +2875,10 @@ static int export_one_map(const char *upatch, const char *map,
if (otel) {
__u32 decoder_signal;
- rc = shirudo_upatch_decode_map_signal(&v, &decoder_signal);
+ rc = upatch_decode_map_signal(&v, &decoder_signal);
if (!rc)
- rc = shirudo_upatch_maps_otel_send_decoded(&v, decoder_signal,
- otel_opts);
+ rc = upatch_maps_otel_send_decoded(&v, decoder_signal,
+ otel_opts);
if (rc) {
pr_err("upatch map: OTLP export %s/%s: %s", upatch, map,
strerror(-rc));
@@ -2886,11 +2886,11 @@ static int export_one_map(const char *upatch, const char *map,
}
}
if (print_detail) {
- shirudo_upatch_maps_print_detail(&v);
+ upatch_maps_print_detail(&v);
if (ferror(stdout))
ret = 1;
}
- shirudo_map_view_free(&v);
+ map_view_free(&v);
return ret;
}
@@ -2912,8 +2912,8 @@ static int cmd_upatch_map(int argc, const char **argv)
for (i = 1; i < argc; i++) {
const char *a = argv[i];
- if (shirudo_is_help(a)) {
- shirudo_print_help(&upatch_map_help);
+ if (is_help(a)) {
+ print_help(&upatch_map_help);
return 0;
}
if (strcmp(a, "--all") == 0) {
@@ -2955,7 +2955,7 @@ static int cmd_upatch_map(int argc, const char **argv)
otel_opts.endpoint = a + 16;
} else if (strncmp(a, "--tenant-id=", 12) == 0) {
if (otel_opts.tenant_id ||
- !shirudo_tenant_id_valid(a + 12)) {
+ !tenant_id_valid(a + 12)) {
fprintf(stderr, "upatch map: invalid or duplicate "
"--tenant-id; expected 1..128 characters using "
"A-Z, a-z, 0-9, '.', '_', or '-'\n");
@@ -3004,7 +3004,7 @@ static int cmd_upatch_map(int argc, const char **argv)
}
}
if (all) {
- int rc = shirudo_config_load(&export_cfg);
+ int rc = config_load(&export_cfg);
if (rc) {
pr_err("upatch map: load export configuration: %s",
@@ -3075,7 +3075,7 @@ static int cmd_upatch_map(int argc, const char **argv)
if (all) {
size_t k;
- shirudo_upatch_maps_list_all(&list, &n);
+ upatch_maps_list_all(&list, &n);
for (k = 0; k < n; k++) {
if (export_one_map(list[k].upatch, list[k].name,
json_output, json_path, otel,
@@ -3083,7 +3083,7 @@ static int cmd_upatch_map(int argc, const char **argv)
!json_output && !otel) != 0)
ret = 1;
}
- shirudo_map_summary_free(list, n);
+ map_summary_free(list, n);
return ret;
}
@@ -3092,9 +3092,9 @@ static int cmd_upatch_map(int argc, const char **argv)
pr_err("upatch map: invalid upatch name '%s'", upatch);
return 2;
}
- shirudo_upatch_maps_list_one(upatch, &list, &n);
+ upatch_maps_list_one(upatch, &list, &n);
} else {
- shirudo_upatch_maps_list_all(&list, &n);
+ upatch_maps_list_all(&list, &n);
}
if (json_output) {
@@ -3105,29 +3105,29 @@ static int cmd_upatch_map(int argc, const char **argv)
buf = xmalloc(cap);
if (!buf) {
- shirudo_map_summary_free(list, n);
+ map_summary_free(list, n);
return 1;
}
e.buf = buf;
e.cap = cap;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_arr_open(&e, "maps");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_arr_open(&e, "maps");
for (k = 0; k < n; k++) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "upatch", list[k].upatch);
- shirudo_json_kv_string(&e, "name", list[k].name);
- shirudo_json_kv_string(&e, "type",
- list[k].type_name);
- shirudo_json_kv_int(&e, "max_entries",
- list[k].max_entries);
+ json_obj_open(&e);
+ json_kv_string(&e, "upatch", list[k].upatch);
+ json_kv_string(&e, "name", list[k].name);
+ json_kv_string(&e, "type",
+ list[k].type_name);
+ json_kv_int(&e, "max_entries",
+ list[k].max_entries);
if (list[k].n_cpus > 1)
- shirudo_json_kv_int(&e, "n_cpus",
- list[k].n_cpus);
- shirudo_json_obj_close(&e);
+ json_kv_int(&e, "n_cpus",
+ list[k].n_cpus);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
ret = 1;
} else {
@@ -3145,9 +3145,9 @@ static int cmd_upatch_map(int argc, const char **argv)
}
xfree(buf, cap);
} else {
- shirudo_upatch_maps_print_summary(list, n);
+ upatch_maps_print_summary(list, n);
}
- shirudo_map_summary_free(list, n);
+ map_summary_free(list, n);
return ret;
}
@@ -3194,7 +3194,7 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
c->payload[0] = '\0';
c->prog_id = 0;
- link_fd = shirudo_upatch_open_first_link(want);
+ link_fd = upatch_open_first_link(want);
if (link_fd < 0)
return link_fd;
len = sizeof(linfo);
@@ -3207,12 +3207,12 @@ static int upatch_get_collect(const char *want, struct upatch_get_ctx *c)
if (linfo.prog_id == 0)
return -EINVAL;
c->prog_id = linfo.prog_id;
- shirudo_upatch_loaded_at(want, c->loaded_at, sizeof(c->loaded_at));
- shirudo_upatch_payload_sha256(want, c->payload, sizeof(c->payload));
+ upatch_loaded_at(want, c->loaded_at, sizeof(c->loaded_at));
+ upatch_payload_sha256(want, c->payload, sizeof(c->payload));
vbtf = btf__load_vmlinux_btf();
- shirudo_upatch_resolve_location(vbtf, want, c->location,
- sizeof(c->location));
+ upatch_resolve_location(vbtf, want, c->location,
+ sizeof(c->location));
if (vbtf)
btf__free(vbtf);
@@ -3270,24 +3270,24 @@ static void age_from_ts(const char *ts, char *out, size_t cap)
return;
if (!strptime(ts, "%Y-%m-%dT%H:%M:%SZ", &tm))
return;
- shirudo_format_duration((long)(time(NULL) - timegm(&tm)), out, cap);
+ format_duration((long)(time(NULL) - timegm(&tm)), out, cap);
}
static void render_one_map_text(const char *upatch, const char *map,
__u32 cap)
{
struct shirudo_map_view v = {};
- int rc = shirudo_upatch_maps_read_flags(upatch, map, cap,
- SHIRUDO_MAP_READ_PEEK, &v);
+ int rc = upatch_maps_read_flags(upatch, map, cap,
+ SHIRUDO_MAP_READ_PEEK, &v);
printf("\n== Map: %s ==\n", map);
if (rc != 0) {
printf(" (read failed: %s)\n", strerror(-rc));
- shirudo_map_view_free(&v);
+ map_view_free(&v);
return;
}
- shirudo_upatch_maps_print_detail(&v);
- shirudo_map_view_free(&v);
+ upatch_maps_print_detail(&v);
+ map_view_free(&v);
}
static void render_get_text(const struct upatch_get_ctx *c,
@@ -3346,46 +3346,46 @@ static int render_get_json(const struct upatch_get_ctx *c,
age_from_ts(c->loaded_at, age, sizeof(age));
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_obj_open_key(&e, "upatch");
- shirudo_json_kv_string(&e, "name", c->upatch);
- shirudo_json_kv_string(&e, "location", c->location);
- shirudo_json_kv_int(&e, "prog_id", c->prog_id);
- shirudo_json_kv_string(&e, "loaded_at", c->loaded_at);
- shirudo_json_kv_string(&e, "age", age);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_obj_open_key(&e, "upatch");
+ json_kv_string(&e, "name", c->upatch);
+ json_kv_string(&e, "location", c->location);
+ json_kv_int(&e, "prog_id", c->prog_id);
+ json_kv_string(&e, "loaded_at", c->loaded_at);
+ json_kv_string(&e, "age", age);
if (c->payload[0])
- shirudo_json_kv_string(&e, "payload_sha256", c->payload);
+ json_kv_string(&e, "payload_sha256", c->payload);
else
- shirudo_json_kv_null(&e, "payload_sha256");
- shirudo_json_obj_open_key(&e, "source");
+ json_kv_null(&e, "payload_sha256");
+ json_obj_open_key(&e, "source");
emit_line_info_json(&e, c->ents, c->n_ents);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "maps");
+ json_obj_close(&e);
+ json_arr_open(&e, "maps");
for (k = 0; k < nm; k++) {
struct shirudo_map_view v = {};
int rc;
- rc = shirudo_upatch_maps_read_flags(c->upatch, maps[k].name,
- map_cap,
- SHIRUDO_MAP_READ_PEEK, &v);
+ rc = upatch_maps_read_flags(c->upatch, maps[k].name,
+ map_cap,
+ SHIRUDO_MAP_READ_PEEK, &v);
if (rc != 0) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", maps[k].name);
- shirudo_json_kv_string(&e, "type",
- maps[k].type_name);
- shirudo_json_kv_int(&e, "max_entries",
- maps[k].max_entries);
- shirudo_json_kv_string(&e, "error", strerror(-rc));
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "name", maps[k].name);
+ json_kv_string(&e, "type",
+ maps[k].type_name);
+ json_kv_int(&e, "max_entries",
+ maps[k].max_entries);
+ json_kv_string(&e, "error", strerror(-rc));
+ json_obj_close(&e);
} else {
- shirudo_upatch_maps_emit_json_object(&e, &v);
+ upatch_maps_emit_json_object(&e, &v);
}
- shirudo_map_view_free(&v);
+ map_view_free(&v);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e); /* upatch */
- shirudo_json_obj_close(&e); /* root */
+ json_arr_close(&e);
+ json_obj_close(&e); /* upatch */
+ json_obj_close(&e); /* root */
if (e.err) {
fprintf(stderr, "upatch get: json encode failed: %s\n",
strerror(-e.err));
@@ -3410,8 +3410,8 @@ static int cmd_upatch_get(int argc, const char **argv)
for (i = 1; i < argc; i++) {
const char *a = argv[i];
- if (shirudo_is_help(a)) {
- shirudo_print_help(&upatch_get_help);
+ if (is_help(a)) {
+ print_help(&upatch_get_help);
return 0;
}
if (strcmp(a, "--json") == 0) {
@@ -3430,7 +3430,7 @@ static int cmd_upatch_get(int argc, const char **argv)
}
}
if (!want) {
- shirudo_print_help(&upatch_get_help);
+ print_help(&upatch_get_help);
return 2;
}
if (!safe_upatch_name(want)) {
@@ -3444,7 +3444,7 @@ static int cmd_upatch_get(int argc, const char **argv)
upatch_get_ctx_free(&ctx);
return 1;
}
- shirudo_upatch_maps_list_one(want, &maps, &nm);
+ upatch_maps_list_one(want, &maps, &nm);
map_cap = show_full ? 0 : SHIRUDO_MAP_ENTRIES_DEFAULT;
if (json)
@@ -3452,7 +3452,7 @@ static int cmd_upatch_get(int argc, const char **argv)
else
render_get_text(&ctx, maps, nm, map_cap), rc = 0;
- shirudo_map_summary_free(maps, nm);
+ map_summary_free(maps, nm);
upatch_get_ctx_free(&ctx);
return rc;
}
@@ -3484,18 +3484,18 @@ int cmd_upatch(int argc, const char **argv)
{
const char *canonical;
- if (argc < 2 || shirudo_is_help(argv[1])) {
- shirudo_print_help(&upatch_help);
+ if (argc < 2 || is_help(argv[1])) {
+ print_help(&upatch_help);
return argc < 2 ? 2 : 0;
}
- if (shirudo_is_list_cmds(argv[1])) {
- shirudo_print_subcmd_list(upatch_subcmds,
- ARRAY_SIZE(upatch_subcmds));
+ if (is_list_cmds(argv[1])) {
+ print_subcmd_list(upatch_subcmds,
+ ARRAY_SIZE(upatch_subcmds));
return 0;
}
- canonical = shirudo_resolve_subcommand("shirudo upatch", argv[1],
- upatch_subcmds,
- ARRAY_SIZE(upatch_subcmds));
+ canonical = resolve_subcommand("shirudo upatch", argv[1],
+ upatch_subcmds,
+ ARRAY_SIZE(upatch_subcmds));
if (!canonical)
return 2;
if (strcmp(canonical, "info") == 0)
diff --git a/builtin-version.c b/builtin-version.c
index dd8467ae..aa198827 100644
--- a/builtin-version.c
+++ b/builtin-version.c
@@ -33,8 +33,8 @@ static const struct shirudo_help version_help = {
int cmd_version(int argc, const char **argv)
{
- if (argc >= 2 && shirudo_is_help(argv[1])) {
- shirudo_print_help(&version_help);
+ if (argc >= 2 && is_help(argv[1])) {
+ print_help(&version_help);
return 0;
}
if (argc >= 2 && strcmp(argv[1], "--version-id") == 0) {
diff --git a/include/shirudo/string.h b/include/shirudo/string.h
index 8e84a907..3b9df441 100644
--- a/include/shirudo/string.h
+++ b/include/shirudo/string.h
@@ -13,7 +13,7 @@
#include <shirudo/misc.h>
/* How many of the len bytes at s, from the first, are decimal digits. */
-size_t shirudo_digits(const char *s, size_t len);
+size_t digits(const char *s, size_t len);
/*
* The number the len bytes at s spell, decimal for u64 and s64 and
diff --git a/shirudo.c b/shirudo.c
index 80a4be4f..d4e9df5b 100644
--- a/shirudo.c
+++ b/shirudo.c
@@ -106,29 +106,29 @@ int main(int argc, const char **argv)
size_t matches[ARRAY_SIZE(commands)];
size_t i, n_match;
- shirudo_harden_stdio();
- shirudo_log_init();
- shirudo_harden_self();
+ harden_stdio();
+ log_init();
+ harden_self();
if (argc < 2) {
cmd_help(0, NULL);
return 1;
}
- if (shirudo_is_list_cmds(argv[1])) {
+ if (is_list_cmds(argv[1])) {
for (i = 0; i < commands_n; i++)
printf("%s\n", commands[i].name);
return 0;
}
/* With the rest of argv, so `--help --list-cmds` still lists. */
- if (shirudo_is_help(argv[1]))
+ if (is_help(argv[1]))
return cmd_help(argc - 1, argv + 1);
for (i = 0; i < commands_n; i++)
names[i] = commands[i].name;
/* Tolerant matching is the Levenshtein pass below. */
- n_match = shirudo_resolve(argv[1], names, commands_n,
- matches, ARRAY_SIZE(matches));
+ n_match = resolve(argv[1], names, commands_n,
+ matches, ARRAY_SIZE(matches));
if (n_match == 1) {
c = &commands[matches[0]];
} else if (n_match > 1) {
@@ -156,8 +156,8 @@ int main(int argc, const char **argv)
if (max_dist > 3)
max_dist = 3;
- n = shirudo_suggest(argv[1], names, commands_n, max_dist,
- sugg, ARRAY_SIZE(sugg));
+ n = suggest(argv[1], names, commands_n, max_dist,
+ sugg, ARRAY_SIZE(sugg));
if (n) {
fprintf(stderr, "\nDid you mean one of:\n");
for (i = 0; i < n; i++)
diff --git a/testing/fuzz/chain.c b/testing/fuzz/chain.c
index 8cb79312..4a483a2c 100644
--- a/testing/fuzz/chain.c
+++ b/testing/fuzz/chain.c
@@ -13,10 +13,10 @@
void shirudo_sha256(const void *data, size_t len,
__u8 out[SHIRUDO_CHAIN_DIGEST_LEN])
{
- shirudo_sha256_buffer(data, len, out);
+ sha256_buffer(data, len, out);
}
-int shirudo_ct_eq(const void *a, const void *b, size_t n)
+int ct_eq(const void *a, const void *b, size_t n)
{
return !memcmp(a, b, n);
}
diff --git a/testing/fuzz/fuzz-attest.c b/testing/fuzz/fuzz-attest.c
index 06b2c9fd..2435a2d9 100644
--- a/testing/fuzz/fuzz-attest.c
+++ b/testing/fuzz/fuzz-attest.c
@@ -33,16 +33,16 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
char *out;
int fd;
- shirudo_attest_verify((const char *)data, size, &expect, report,
- sizeof(report));
- if (!shirudo_attest_challenge_make((const char *)data, size, &pol,
- credential, &out, &out_len, &cap,
- report, sizeof(report)))
+ attest_verify((const char *)data, size, &expect, report,
+ sizeof(report));
+ if (!attest_challenge_make((const char *)data, size, &pol,
+ credential, &out, &out_len, &cap,
+ report, sizeof(report)))
xfree(out, cap);
fd = fuzz_file(data, size, path, sizeof(path));
if (fd < 0)
return 0;
- shirudo_attest_challenge_read(path, &challenge);
+ attest_challenge_read(path, &challenge);
close(fd);
return 0;
}
diff --git a/testing/fuzz/fuzz-cms.c b/testing/fuzz/fuzz-cms.c
index f45e3969..a383f334 100644
--- a/testing/fuzz/fuzz-cms.c
+++ b/testing/fuzz/fuzz-cms.c
@@ -14,7 +14,7 @@
int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
{
- struct shirudo_cert_pubkey pub;
+ struct cert_pubkey pub;
struct shirudo_cert cert = {};
size_t der_len, sig_len, n;
const __u8 *der, *sig;
@@ -30,18 +30,18 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
sig = der + der_len;
sig_len = size - 2 - der_len;
- shirudo_keys_digest_der(der, der_len, sha, fp);
- if (!shirudo_cert_read_der(der, der_len, &cert)) {
- shirudo_cert_pubkey(&cert, &pub);
- shirudo_verify_detached(der, der_len, sig, sig_len, &cert);
- shirudo_cms_signed_by(sig, sig_len, &cert);
- shirudo_cert_free(&cert);
+ keys_digest_der(der, der_len, sha, fp);
+ if (!cert_read_der(der, der_len, &cert)) {
+ cert_pubkey(&cert, &pub);
+ verify_detached(der, der_len, sig, sig_len, &cert);
+ cms_signed_by(sig, sig_len, &cert);
+ cert_free(&cert);
}
raw = xmalloc(sig_len + 1);
if (raw) {
- shirudo_base64_decode((const char *)sig, sig_len, raw,
- sig_len + 1, &n);
+ base64_decode((const char *)sig, sig_len, raw,
+ sig_len + 1, &n);
xfree(raw, sig_len + 1);
}
return 0;
diff --git a/testing/fuzz/fuzz-config.c b/testing/fuzz/fuzz-config.c
index 81c2592b..937576a9 100644
--- a/testing/fuzz/fuzz-config.c
+++ b/testing/fuzz/fuzz-config.c
@@ -24,15 +24,15 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
fd = fuzz_file(data, size, path, sizeof(path));
if (fd < 0)
return 0;
- shirudo_config_load_path(&cfg, path);
+ config_load_path(&cfg, path);
/* Read as load_source() and load_tree_config() read their files. */
fp = fopen(path, "r");
while (fp && fgets(line, sizeof(line), fp)) {
memcpy(copy, line, sizeof(line));
- shirudo_bpm_parse_source_line(copy, endpoint, sizeof(endpoint),
- key_file, sizeof(key_file));
- shirudo_bpm_parse_tree_line(line, endpoint, sizeof(endpoint),
- reference, sizeof(reference));
+ bpm_parse_source_line(copy, endpoint, sizeof(endpoint),
+ key_file, sizeof(key_file));
+ bpm_parse_tree_line(line, endpoint, sizeof(endpoint),
+ reference, sizeof(reference));
}
if (fp)
fclose(fp);
diff --git a/testing/fuzz/fuzz-decoder.c b/testing/fuzz/fuzz-decoder.c
index ccdb72f6..b02609bc 100644
--- a/testing/fuzz/fuzz-decoder.c
+++ b/testing/fuzz/fuzz-decoder.c
@@ -27,7 +27,7 @@ static const char * const sources[] = {
"../fixtures/decoders/counters.lua",
};
-static struct shirudo_upatch_decoder_view views[ARRAY_SIZE(sources)];
+static struct upatch_decoder_view views[ARRAY_SIZE(sources)];
/* The decoders sit beside the target in the tree, wherever it runs from. */
int LLVMFuzzerInitialize(int *argc, char ***argv)
@@ -40,7 +40,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
for (size_t i = 0; i < ARRAY_SIZE(sources); i++) {
snprintf(path, sizeof(path), "%s/%s", dirname(self), sources[i]);
snprintf(self, sizeof(self), "%s", (*argv)[0]);
- if (shirudo_read_file(path, 1 << 20, &src, &len))
+ if (read_file(path, 1 << 20, &src, &len))
abort();
views[i].source = src;
views[i].source_len = (__u32)len;
@@ -55,7 +55,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
{
struct shirudo_map_entry entries[32];
- struct shirudo_upatch_decoder_view *d;
+ struct upatch_decoder_view *d;
struct shirudo_serial_page page = {};
struct shirudo_map_view v = {
.type_name = "array",
diff --git a/testing/fuzz/fuzz-elf.c b/testing/fuzz/fuzz-elf.c
index 086cbf00..e796cf42 100644
--- a/testing/fuzz/fuzz-elf.c
+++ b/testing/fuzz/fuzz-elf.c
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * shirudo_elf_build_id_fd() on the binary a uprobe target names, which
+ * elf_build_id_fd() on the binary a uprobe target names, which
* the unsigned program metadata of a upatch chooses.
*/
@@ -20,7 +20,7 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
if (fd < 0)
return 0;
len = sizeof(build_id);
- shirudo_elf_build_id_fd(fd, build_id, &len);
+ elf_build_id_fd(fd, build_id, &len);
close(fd);
return 0;
}
diff --git a/testing/fuzz/fuzz-eventlog.c b/testing/fuzz/fuzz-eventlog.c
index 00bb492c..5e6d59b5 100644
--- a/testing/fuzz/fuzz-eventlog.c
+++ b/testing/fuzz/fuzz-eventlog.c
@@ -25,7 +25,7 @@ static int on_line(const char *line, size_t len, void *ctx)
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
- shirudo_eventlog_boot_id(boot, sizeof(boot));
+ eventlog_boot_id(boot, sizeof(boot));
if (strlen(boot) != sizeof(seed_boot) - 1)
abort();
setenv("SHIRUDO_EVENTLOG_PENDING_PATH", "/nonexistent/eventlog", 1);
@@ -57,9 +57,9 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
if (fd < 0)
return 0;
setenv("SHIRUDO_EVENTLOG_PATH", path, 1);
- shirudo_eventlog_replay(root);
- shirudo_eventlog_boot_init(&init);
- shirudo_eventlog_boot_lines(on_line, &seen);
+ eventlog_replay(root);
+ eventlog_boot_init(&init);
+ eventlog_boot_lines(on_line, &seen);
close(fd);
return 0;
}
diff --git a/testing/fuzz/fuzz-json.c b/testing/fuzz/fuzz-json.c
index a16da1ba..1e7f7f63 100644
--- a/testing/fuzz/fuzz-json.c
+++ b/testing/fuzz/fuzz-json.c
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * shirudo_json_parse() over a schema with every field type.
+ * json_parse() over a schema with every field type.
*/
#include "fuzz.h"
@@ -37,6 +37,6 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
{ "a", SHIRUDO_JSON_T_ARRAY, &arr, 0, 0, elem, ARRAY_SIZE(elem) },
};
- shirudo_json_parse((const char *)data, size, root, ARRAY_SIZE(root));
+ json_parse((const char *)data, size, root, ARRAY_SIZE(root));
return 0;
}
diff --git a/testing/fuzz/fuzz-kernel.c b/testing/fuzz/fuzz-kernel.c
index 8591e9c7..8f5d63ed 100644
--- a/testing/fuzz/fuzz-kernel.c
+++ b/testing/fuzz/fuzz-kernel.c
@@ -33,10 +33,10 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
return 0;
memcpy(text, data, size);
text[size] = '\0';
- if (!shirudo_kmodules_parse(text, &set))
- shirudo_kmodules_free(&set);
+ if (!kmodules_parse(text, &set))
+ kmodules_free(&set);
xfree(text, size + 1);
- shirudo_kernel_build_id_from_notes(data, size, build_id);
+ kernel_build_id_from_notes(data, size, build_id);
return 0;
}
diff --git a/testing/fuzz/fuzz-otel.c b/testing/fuzz/fuzz-otel.c
index b604b33a..6dae1e90 100644
--- a/testing/fuzz/fuzz-otel.c
+++ b/testing/fuzz/fuzz-otel.c
@@ -16,48 +16,48 @@ const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 id)
return NULL;
}
-bool shirudo_upatch_map_is_percpu(__u32 type)
+bool upatch_map_is_percpu(__u32 type)
{
return false;
}
-int shirudo_upatch_decode_map_json(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_json(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return -EOPNOTSUPP;
}
-int shirudo_upatch_decode_map_json_limit(const struct shirudo_map_view *v,
- size_t max_bytes,
- char **out, size_t *out_len)
+int upatch_decode_map_json_limit(const struct shirudo_map_view *v,
+ size_t max_bytes,
+ char **out, size_t *out_len)
{
return -EOPNOTSUPP;
}
-int shirudo_upatch_decode_map_otel(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_otel(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return -EOPNOTSUPP;
}
-int shirudo_upatch_decode_map_file_json(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_file_json(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return -EOPNOTSUPP;
}
-int shirudo_upatch_decode_map_file_json_limit(const char *path,
- const struct shirudo_map_view *v,
- size_t max_bytes, char **out,
- size_t *out_len)
+int upatch_decode_map_file_json_limit(const char *path,
+ const struct shirudo_map_view *v,
+ size_t max_bytes, char **out,
+ size_t *out_len)
{
return -EOPNOTSUPP;
}
-int shirudo_upatch_decode_map_file_otel(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_file_otel(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return -EOPNOTSUPP;
}
@@ -98,7 +98,7 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
e.buf = xmalloc(cap);
if (e.buf) {
e.cap = cap;
- shirudo_json_obj_open(&e);
+ json_obj_open(&e);
json_anyvalue_from_document(&e, body, size, false);
xfree(e.buf, cap);
}
diff --git a/testing/fuzz/fuzz-prog-metadata.c b/testing/fuzz/fuzz-prog-metadata.c
index c6010f71..c22463dd 100644
--- a/testing/fuzz/fuzz-prog-metadata.c
+++ b/testing/fuzz/fuzz-prog-metadata.c
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * shirudo_prog_specs_parse() on a load upatch's program metadata, which
+ * prog_specs_parse() on a load upatch's program metadata, which
* the loader signature does not cover.
*/
@@ -26,7 +26,7 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
memcpy(&md, data, sizeof(md));
nr_progs = le32toh(md.nr_progs);
}
- if (!shirudo_prog_specs_parse(data, (__u32)size, nr_progs, &specs))
- shirudo_prog_specs_free(specs, nr_progs);
+ if (!prog_specs_parse(data, (__u32)size, nr_progs, &specs))
+ prog_specs_free(specs, nr_progs);
return 0;
}
diff --git a/testing/fuzz/fuzz-tpm-wire.c b/testing/fuzz/fuzz-tpm-wire.c
index 15509668..0ad5d0dd 100644
--- a/testing/fuzz/fuzz-tpm-wire.c
+++ b/testing/fuzz/fuzz-tpm-wire.c
@@ -16,10 +16,10 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
struct shirudo_tpm_public pub;
struct shirudo_tpm_attest at;
- shirudo_tpm_public_parse(data, size, &pub);
- shirudo_tpm_ecc_public_parse(data, size, &ecc);
- shirudo_tpm_object_name(data, size, name);
- shirudo_tpm_ecdsa_signature_parse(data, size, r, s);
- shirudo_tpm_attest_parse(data, size, &at);
+ tpm_public_parse(data, size, &pub);
+ tpm_ecc_public_parse(data, size, &ecc);
+ tpm_object_name(data, size, name);
+ tpm_ecdsa_signature_parse(data, size, r, s);
+ tpm_attest_parse(data, size, &at);
return 0;
}
diff --git a/testing/fuzz/fuzz-tree-state.c b/testing/fuzz/fuzz-tree-state.c
index 12809103..abcc0631 100644
--- a/testing/fuzz/fuzz-tree-state.c
+++ b/testing/fuzz/fuzz-tree-state.c
@@ -27,8 +27,8 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
fd = fuzz_file(data, size, fuzz_path, sizeof(fuzz_path));
if (fd < 0)
return 0;
- shirudo_tree_state_read(&state);
- shirudo_tree_event_replay(root);
+ tree_state_read(&state);
+ tree_event_replay(root);
close(fd);
return 0;
}
diff --git a/testing/fuzz/fuzz-tree.c b/testing/fuzz/fuzz-tree.c
index a350cd3a..66cf1f80 100644
--- a/testing/fuzz/fuzz-tree.c
+++ b/testing/fuzz/fuzz-tree.c
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * shirudo_tree_parse() on an upatch tree publication, the canonical
+ * tree_parse() on an upatch tree publication, the canonical
* digest of every operation it accepts and the publication emitted again.
*/
@@ -16,12 +16,12 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
char digest[72], *out;
size_t len;
- if (shirudo_tree_parse((const char *)data, size, &pub))
+ if (tree_parse((const char *)data, size, &pub))
return 0;
for (int i = 0; i < pub.n_operations; i++)
- shirudo_tree_operation_digest(&pub.operations[i], digest);
- if (!shirudo_tree_emit_publication(&pub, &out, &len))
+ tree_operation_digest(&pub.operations[i], digest);
+ if (!tree_emit_publication(&pub, &out, &len))
xfree(out, len);
- shirudo_tree_publication_free(&pub);
+ tree_publication_free(&pub);
return 0;
}
diff --git a/testing/fuzz/fuzz-upatch.c b/testing/fuzz/fuzz-upatch.c
index 7761dd7f..526617a6 100644
--- a/testing/fuzz/fuzz-upatch.c
+++ b/testing/fuzz/fuzz-upatch.c
@@ -2,7 +2,7 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * shirudo_upatch_open() on a .upatch container, and its decoder table.
+ * upatch_open() on a .upatch container, and its decoder table.
*/
#include "fuzz.h"
@@ -18,19 +18,19 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
fd = fuzz_file(data, size, path, sizeof(path));
if (fd < 0)
return 0;
- if (!shirudo_upatch_open(path, &u)) {
- if (!shirudo_prog_specs_parse(shirudo_upatch_metadata(&u),
- u.hdr.metadata_len,
- u.hdr.nr_progs, &specs))
- shirudo_prog_specs_free(specs, u.hdr.nr_progs);
- shirudo_upatch_is_unload(&u);
- if (shirudo_upatch_has_decoders(&u)) {
- struct shirudo_upatch_decoder_view d;
+ if (!upatch_open(path, &u)) {
+ if (!prog_specs_parse(upatch_metadata(&u),
+ u.hdr.metadata_len,
+ u.hdr.nr_progs, &specs))
+ prog_specs_free(specs, u.hdr.nr_progs);
+ upatch_is_unload(&u);
+ if (upatch_has_decoders(&u)) {
+ struct upatch_decoder_view d;
- for (__u32 i = 0; !shirudo_upatch_decoder_view(&u, i, &d); i++)
+ for (__u32 i = 0; !upatch_decoder_view(&u, i, &d); i++)
;
}
- shirudo_upatch_close(&u);
+ upatch_close(&u);
}
close(fd);
return 0;
diff --git a/testing/fuzz/log.c b/testing/fuzz/log.c
index a8d94661..dde57238 100644
--- a/testing/fuzz/log.c
+++ b/testing/fuzz/log.c
@@ -10,7 +10,7 @@
#include "log.h"
-void shirudo_log_init(void)
+void log_init(void)
{
}
diff --git a/testing/helper/test-bpm-source.c b/testing/helper/test-bpm-source.c
index aee78dfc..89247918 100644
--- a/testing/helper/test-bpm-source.c
+++ b/testing/helper/test-bpm-source.c
@@ -23,12 +23,12 @@ int main(void)
char reference[80] = {};
char endpoint[512] = {};
- if (shirudo_bpm_parse_source_line(endpoint_line, endpoint,
- sizeof(endpoint), key_file,
- sizeof(key_file)) ||
- shirudo_bpm_parse_source_line(key_file_line, endpoint,
- sizeof(endpoint), key_file,
- sizeof(key_file)))
+ if (bpm_parse_source_line(endpoint_line, endpoint,
+ sizeof(endpoint), key_file,
+ sizeof(key_file)) ||
+ bpm_parse_source_line(key_file_line, endpoint,
+ sizeof(endpoint), key_file,
+ sizeof(key_file)))
return 1;
if (strcmp(endpoint, "oci://registry.test:5443") ||
strcmp(key_file, "/etc/shirudo/bpm/keys/jbrust.pem"))
@@ -36,15 +36,15 @@ int main(void)
printf("endpoint=%s\nkey_file=%s\n", endpoint, key_file);
- if (shirudo_bpm_parse_tree_line(tree_endpoint_line, endpoint,
- sizeof(endpoint), reference,
- sizeof(reference)) ||
- shirudo_bpm_parse_tree_line(reference_line, endpoint,
- sizeof(endpoint), reference,
- sizeof(reference)) ||
- shirudo_bpm_parse_tree_line(unbalanced_line, endpoint,
- sizeof(endpoint), reference,
- sizeof(reference)) != -EINVAL)
+ if (bpm_parse_tree_line(tree_endpoint_line, endpoint,
+ sizeof(endpoint), reference,
+ sizeof(reference)) ||
+ bpm_parse_tree_line(reference_line, endpoint,
+ sizeof(endpoint), reference,
+ sizeof(reference)) ||
+ bpm_parse_tree_line(unbalanced_line, endpoint,
+ sizeof(endpoint), reference,
+ sizeof(reference)) != -EINVAL)
return 1;
printf("tree endpoint=%s\ntree reference=%s\n", endpoint, reference);
return 0;
diff --git a/testing/helper/test-chain.c b/testing/helper/test-chain.c
index 254cdb40..23a3f53f 100644
--- a/testing/helper/test-chain.c
+++ b/testing/helper/test-chain.c
@@ -19,7 +19,7 @@ static void puthex(const __u8 *b, size_t n)
{
char h[2 * 64 + 1];
- shirudo_hex_encode(b, n, h);
+ hex_encode(b, n, h);
printf("%s\n", h);
}
@@ -42,7 +42,7 @@ int main(int argc, char **argv)
if (n > sizeof(buf))
return 2;
- rc = shirudo_hex_decode(argv[2], buf, n);
+ rc = hex_decode(argv[2], buf, n);
printf("rc=%d\n", rc);
if (rc == 0)
puthex(buf, n);
@@ -54,10 +54,10 @@ int main(int argc, char **argv)
if (na != nb || na > sizeof(a))
return 2;
- if (shirudo_hex_decode(argv[2], a, na) ||
- shirudo_hex_decode(argv[3], b, nb))
+ if (hex_decode(argv[2], a, na) ||
+ hex_decode(argv[3], b, nb))
return 2;
- printf("%d\n", shirudo_ct_eq(a, b, na));
+ printf("%d\n", ct_eq(a, b, na));
return 0;
}
return 2;
diff --git a/testing/helper/test-config.c b/testing/helper/test-config.c
index e9431344..041741fd 100644
--- a/testing/helper/test-config.c
+++ b/testing/helper/test-config.c
@@ -23,7 +23,7 @@ static int write_config(const char *path, const char *contents)
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
if (fd < 0)
return -errno;
- rc = shirudo_write_all(fd, contents, strlen(contents));
+ rc = write_all(fd, contents, strlen(contents));
if (rc) {
close(fd);
return rc;
@@ -36,7 +36,7 @@ static int check_defaults(const char *path)
struct shirudo_config cfg;
unlink(path);
- if (shirudo_config_load_path(&cfg, path) != 0)
+ if (config_load_path(&cfg, path) != 0)
return 1;
return !cfg.map_export_valid || cfg.map_export_json_path[0] ||
cfg.map_export_tenant_id[0] ||
@@ -62,7 +62,7 @@ static int check_valid(const char *path)
struct shirudo_config cfg;
if (write_config(path, input) != 0 ||
- shirudo_config_load_path(&cfg, path) != 0)
+ config_load_path(&cfg, path) != 0)
return 1;
return !cfg.map_export_valid ||
strcmp(cfg.map_export_json_path,
@@ -82,7 +82,7 @@ static int check_invalid(const char *path, const char *input)
struct shirudo_config cfg;
return write_config(path, input) != 0 ||
- shirudo_config_load_path(&cfg, path) != 0 ||
+ config_load_path(&cfg, path) != 0 ||
cfg.map_export_valid;
}
@@ -95,7 +95,7 @@ static int check_max_bytes(const char *path, const char *value,
snprintf(input, sizeof(input), "eventlog.max_bytes = %s\n", value);
return write_config(path, input) != 0 ||
- shirudo_config_load_path(&cfg, path) != 0 ||
+ config_load_path(&cfg, path) != 0 ||
cfg.eventlog_max_bytes != expected;
}
diff --git a/testing/helper/test-eventlog.c b/testing/helper/test-eventlog.c
index 97926ed3..1db46c56 100644
--- a/testing/helper/test-eventlog.c
+++ b/testing/helper/test-eventlog.c
@@ -31,33 +31,33 @@ static int append_init(const char *path, const char *bound_in,
char name_hex[2 * SHIRUDO_TPM_NAME_LEN + 1];
__u8 zero[SHIRUDO_TPM_NAME_LEN] = {};
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_hex_encode(zero, 32, hex);
- shirudo_hex_encode(zero, SHIRUDO_TPM_NAME_LEN, name_hex);
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_json_kv_string(&e, "digest", hex);
- shirudo_json_kv_string(&e, "type", "init");
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_kv_int(&e, "tpm_reset_count", reset_count);
- shirudo_json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
- shirudo_json_kv_string(&e, "pcr_before", hex);
- shirudo_json_kv_int(&e, "phase_pcr", SHIRUDO_CHAIN_PHASE_PCR);
- shirudo_json_kv_string(&e, "phase_before", hex);
- shirudo_json_kv_string(&e, "bound_in", bound_in);
- shirudo_json_kv_string(&e, "nv_name", name_hex);
- shirudo_json_kv_string(&e, "anchor", "shirudo-anchor:test");
- shirudo_json_kv_string(&e, "anchor_digest", hex);
- shirudo_json_kv_string(&e, "chain", hex);
- shirudo_json_obj_close(&e);
+ hex_encode(zero, 32, hex);
+ hex_encode(zero, SHIRUDO_TPM_NAME_LEN, name_hex);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ json_kv_string(&e, "digest", hex);
+ json_kv_string(&e, "type", "init");
+ json_kv_string(&e, "boot_id", boot_id);
+ json_kv_int(&e, "tpm_reset_count", reset_count);
+ json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
+ json_kv_string(&e, "pcr_before", hex);
+ json_kv_int(&e, "phase_pcr", SHIRUDO_CHAIN_PHASE_PCR);
+ json_kv_string(&e, "phase_before", hex);
+ json_kv_string(&e, "bound_in", bound_in);
+ json_kv_string(&e, "nv_name", name_hex);
+ json_kv_string(&e, "anchor", "shirudo-anchor:test");
+ json_kv_string(&e, "anchor_digest", hex);
+ json_kv_string(&e, "chain", hex);
+ json_obj_close(&e);
if (e.err)
return e.err;
- return shirudo_eventlog_append_to(path, buf);
+ return eventlog_append_to(path, buf);
}
static int count_lines(const char *line, size_t len, void *ctx)
@@ -79,8 +79,8 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "init") == 0 && (argc == 4 || argc == 5)) {
const char *path = strcmp(argv[2], "pending") == 0 ?
- shirudo_eventlog_pending_path() :
- shirudo_eventlog_path();
+ eventlog_pending_path() :
+ eventlog_path();
__u32 reset = 1;
int rc;
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "boot-init") == 0) {
struct shirudo_eventlog_init rec;
- int rc = shirudo_eventlog_boot_init(&rec);
+ int rc = eventlog_boot_init(&rec);
printf("rc=%d\n", rc);
if (rc)
@@ -105,16 +105,16 @@ int main(int argc, char **argv)
}
if (strcmp(argv[1], "lines") == 0) {
__u32 n = 0;
- int rc = shirudo_eventlog_boot_lines(count_lines, &n);
+ int rc = eventlog_boot_lines(count_lines, &n);
printf("rc=%d\nlines=%u\n", rc, n);
return rc ? 1 : 0;
}
if (strcmp(argv[1], "adopt") == 0) {
- int rc = shirudo_eventlog_adopt_pending();
+ int rc = eventlog_adopt_pending();
printf("rc=%d\npending=%s\n", rc,
- access(shirudo_eventlog_pending_path(), F_OK) == 0 ?
+ access(eventlog_pending_path(), F_OK) == 0 ?
"present" : "absent");
return rc ? 1 : 0;
}
diff --git a/testing/helper/test-exec-churn.c b/testing/helper/test-exec-churn.c
index d8db73a6..d058185f 100644
--- a/testing/helper/test-exec-churn.c
+++ b/testing/helper/test-exec-churn.c
@@ -69,7 +69,7 @@ static int worker(__u64 deadline, int fd)
completed++;
}
- if (shirudo_write_all(fd, &completed, sizeof(completed)))
+ if (write_all(fd, &completed, sizeof(completed)))
return 1;
return 0;
}
diff --git a/testing/helper/test-json-parser.c b/testing/helper/test-json-parser.c
index 0d92d4e7..d1547667 100644
--- a/testing/helper/test-json-parser.c
+++ b/testing/helper/test-json-parser.c
@@ -69,7 +69,7 @@ int main(void)
{ NULL, 0, NULL, 0, 0, NULL, 0 },
};
size_t n = fread(buf, 1, sizeof(buf), stdin);
- int rc = shirudo_json_parse(buf, n, f, ARRAY_SIZE(f));
+ int rc = json_parse(buf, n, f, ARRAY_SIZE(f));
printf("rc=%d\n", rc);
if (rc == 0) {
diff --git a/testing/helper/test-kernel-abi.c b/testing/helper/test-kernel-abi.c
index 902f9ef2..47910342 100644
--- a/testing/helper/test-kernel-abi.c
+++ b/testing/helper/test-kernel-abi.c
@@ -146,7 +146,7 @@ static int check(enum fixture fixture, int want_ok, const char *want_detail)
fprintf(stderr, "cannot construct fixture %d\n", fixture);
return 1;
}
- rc = shirudo_kernel_abi_validate_btf(btf, detail, sizeof(detail));
+ rc = kernel_abi_validate_btf(btf, detail, sizeof(detail));
btf__free(btf);
if ((rc == 0) != want_ok) {
fprintf(stderr, "fixture %d: rc=%d detail=%s\n",
diff --git a/testing/helper/test-kernel-build-id.c b/testing/helper/test-kernel-build-id.c
index c56f5908..924cc7db 100644
--- a/testing/helper/test-kernel-build-id.c
+++ b/testing/helper/test-kernel-build-id.c
@@ -25,19 +25,19 @@ int main(void)
__u8 malformed[sizeof(notes)];
char build_id[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX];
- if (shirudo_kernel_build_id_from_notes(notes, sizeof(notes), build_id) ||
+ if (kernel_build_id_from_notes(notes, sizeof(notes), build_id) ||
strcmp(build_id, "01234567")) {
fprintf(stderr, "failed to parse GNU build-id note: %s\n", build_id);
return 1;
}
- if (shirudo_kernel_build_id_from_notes(notes, 0, build_id) != -ENOENT) {
+ if (kernel_build_id_from_notes(notes, 0, build_id) != -ENOENT) {
fprintf(stderr, "empty notes should return -ENOENT\n");
return 1;
}
memcpy(malformed, notes, sizeof(notes));
put_u32(malformed, UINT32_MAX);
- if (shirudo_kernel_build_id_from_notes(malformed, sizeof(malformed),
- build_id) != -EINVAL) {
+ if (kernel_build_id_from_notes(malformed, sizeof(malformed),
+ build_id) != -EINVAL) {
fprintf(stderr, "malformed notes should return -EINVAL\n");
return 1;
}
diff --git a/testing/helper/test-kernel-release.c b/testing/helper/test-kernel-release.c
index 624c25c8..84686b9c 100644
--- a/testing/helper/test-kernel-release.c
+++ b/testing/helper/test-kernel-release.c
@@ -28,8 +28,8 @@ int main(void)
for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
int matches;
- matches = shirudo_kernel_release_prefix_matches(cases[i].release,
- cases[i].prefix);
+ matches = kernel_release_prefix_matches(cases[i].release,
+ cases[i].prefix);
if (matches != cases[i].matches) {
fprintf(stderr, "case %zu: unexpected match result %d\n",
diff --git a/testing/helper/test-keys.c b/testing/helper/test-keys.c
index ffebc176..bdca412b 100644
--- a/testing/helper/test-keys.c
+++ b/testing/helper/test-keys.c
@@ -23,7 +23,7 @@ static void puthex(const __u8 *b, size_t n)
{
char h[65];
- shirudo_hex_encode(b, n, h);
+ hex_encode(b, n, h);
puts(h);
}
@@ -44,23 +44,23 @@ int main(int argc, char **argv)
struct shirudo_cert cert = {};
struct shirudo_upatch u;
- if (argc < 4 || shirudo_upatch_open(argv[2], &u)) {
+ if (argc < 4 || upatch_open(argv[2], &u)) {
fprintf(stderr, "usage: signer <upatch> <cert.der>\n");
return 2;
}
- if (shirudo_cert_read_file(argv[3], &cert)) {
- shirudo_upatch_close(&u);
+ if (cert_read_file(argv[3], &cert)) {
+ upatch_close(&u);
return 2;
}
- rc = shirudo_cms_signed_by(shirudo_upatch_signature(&u),
- u.hdr.signature_len, &cert);
- shirudo_cert_free(&cert);
- shirudo_upatch_close(&u);
+ rc = cms_signed_by(upatch_signature(&u),
+ u.hdr.signature_len, &cert);
+ cert_free(&cert);
+ upatch_close(&u);
printf("%s\n", rc == 1 ? "yes" : rc == 0 ? "no" : "error");
return rc < 0 ? 1 : 0;
}
- rc = shirudo_keys_load(argv[2], NULL,
- argc < 4 || strcmp(argv[3], "primary"), &set);
+ rc = keys_load(argv[2], NULL,
+ argc < 4 || strcmp(argv[3], "primary"), &set);
if (!strcmp(argv[1], "reject"))
return rc == -EINVAL ? 0 : 1;
if (rc) {
@@ -73,8 +73,8 @@ int main(int argc, char **argv)
for (i = 0; i < set.n; i++) {
char sha[65], fp[65];
- shirudo_hex_encode(set.certs[i].sha256, 32, sha);
- shirudo_hex_encode(set.certs[i].fingerprint, 32, fp);
+ hex_encode(set.certs[i].sha256, 32, sha);
+ hex_encode(set.certs[i].fingerprint, 32, fp);
printf("%s %s %s %s\n", sha, fp,
set.certs[i].primary ? "primary" : "trusted",
set.certs[i].path);
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
return 0;
}
if (strcmp(argv[1], "digest") == 0) {
- shirudo_keys_set_digest(&set, digest);
+ keys_set_digest(&set, digest);
puthex(digest, 32);
return 0;
}
diff --git a/testing/helper/test-otel-map.c b/testing/helper/test-otel-map.c
index 8e41d46c..61df26dd 100644
--- a/testing/helper/test-otel-map.c
+++ b/testing/helper/test-otel-map.c
@@ -137,7 +137,7 @@ static int make_decoder(bool metric, bool counter, bool snapshot,
trailer.decoder_len = htole32(decoder_len);
memcpy(file + data_off + decoder_len, &trailer, sizeof(trailer));
- rc = shirudo_write_all(fd, file, file_len);
+ rc = write_all(fd, file, file_len);
if (close(fd) != 0 && rc == 0)
rc = -errno;
xfree(file, file_len);
@@ -214,8 +214,8 @@ static int print_classification(__u32 type, bool is_signed, bool with_btf,
if (rc)
return 1;
f.view.serialized = serialized;
- rc = shirudo_upatch_maps_otel_classify(&f.view, &signal, reason,
- sizeof(reason));
+ rc = upatch_maps_otel_classify(&f.view, &signal, reason,
+ sizeof(reason));
if (!rc)
printf("%s:%s\n", signal == SHIRUDO_OTEL_METRIC ?
"metric" : "log", reason);
@@ -245,13 +245,13 @@ static int print_payload(bool metric, bool counter, bool with_location)
rc = make_decoder(metric, counter, false, decoder_path,
sizeof(decoder_path));
if (!rc && metric)
- rc = shirudo_upatch_maps_otel_build_metric_file(decoder_path,
- &f.view, &opts,
- &buf, &len);
+ rc = upatch_maps_otel_build_metric_file(decoder_path,
+ &f.view, &opts,
+ &buf, &len);
else if (!rc)
- rc = shirudo_upatch_maps_otel_build_log_file(decoder_path,
- &f.view, &buf,
- &len);
+ rc = upatch_maps_otel_build_log_file(decoder_path,
+ &f.view, &buf,
+ &len);
if (!rc && buf)
fwrite(buf, 1, len, stdout);
if (buf)
@@ -272,9 +272,9 @@ static int print_local_json(void)
return 1;
e.buf = buf;
e.cap = sizeof(buf);
- shirudo_json_obj_open(&e);
- shirudo_upatch_maps_emit_json_fields(&e, &f.view);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ upatch_maps_emit_json_fields(&e, &f.view);
+ json_obj_close(&e);
if (!e.err)
printf("%s", buf);
fixture_destroy(&f);
@@ -298,8 +298,8 @@ static int send_log(const char *url, __u32 retries, bool insecure)
rc = make_decoder(false, false, false, decoder_path,
sizeof(decoder_path));
if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_FORCE_LOG, &opts);
+ rc = upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_FORCE_LOG, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
@@ -318,8 +318,8 @@ static int send_auto(const char *base, bool is_signed)
rc = make_decoder(!is_signed, !is_signed, false, decoder_path,
sizeof(decoder_path));
if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_AUTO, &opts);
+ rc = upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_AUTO, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
@@ -343,8 +343,8 @@ static int send_metric(const char *url)
rc = make_decoder(true, false, false, decoder_path,
sizeof(decoder_path));
if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_FORCE_METRIC, &opts);
+ rc = upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_FORCE_METRIC, &opts);
if (decoder_path[0])
unlink(decoder_path);
fixture_destroy(&f);
@@ -420,8 +420,8 @@ static int send_s3(const char *endpoint, __u32 retries, bool large)
rc = make_decoder(false, false, true, decoder_path,
sizeof(decoder_path));
if (!rc)
- rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,
- SHIRUDO_OTEL_S3, &opts);
+ rc = upatch_maps_otel_send_file(decoder_path, &f.view,
+ SHIRUDO_OTEL_S3, &opts);
if (decoder_path[0])
unlink(decoder_path);
large_serialized_destroy(&f);
@@ -441,25 +441,25 @@ static int tenant_validation(void)
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))
return 1;
opts.tenant_id = "bad tenant";
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
failed += rc != -EINVAL;
opts.tenant_id = NULL;
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS",
"X-Tenant-ID=bad%20tenant", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
failed += rc != -EINVAL;
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS",
"X-Tenant-ID=one,x-tenant-id=two", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
failed += rc != -EINVAL;
opts.tenant_id = "tenant-cli-1234";
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS",
"X-Tenant-ID=ignored%20invalid", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
failed += rc == -EINVAL;
unsetenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS");
fixture_destroy(&f);
@@ -480,28 +480,28 @@ static int s3_validation(void)
setenv("AWS_ENDPOINT_URL_S3", "http://127.0.0.1:1", 1);
unsetenv("AWS_ACCESS_KEY_ID");
unsetenv("AWS_SECRET_ACCESS_KEY");
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
if (rc != -EACCES)
goto fail;
setenv("AWS_ACCESS_KEY_ID", "test", 1);
setenv("AWS_SECRET_ACCESS_KEY", "secret", 1);
opts.s3_uri = "s3://BAD_BUCKET/prefix";
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
if (rc != -EINVAL)
goto fail;
opts.s3_uri = "s3://test-bucket/prefix";
f.view.truncated = true;
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
f.view.truncated = false;
if (rc != -E2BIG)
goto fail;
f.view.skipped = true;
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
f.view.skipped = false;
if (rc != -EOPNOTSUPP)
goto fail;
setenv("AWS_ENDPOINT_URL_S3", "http://storage.example", 1);
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_S3, &opts);
if (rc != -EPERM)
goto fail;
fixture_destroy(&f);
@@ -522,8 +522,8 @@ static int security_check(void)
if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))
return 1;
- rc = shirudo_upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
- &opts);
+ rc = upatch_maps_otel_send(&f.view, SHIRUDO_OTEL_FORCE_LOG,
+ &opts);
fixture_destroy(&f);
return rc != -EPERM;
}
diff --git a/testing/helper/test-register.c b/testing/helper/test-register.c
index 4d4152ef..ee8d8f12 100644
--- a/testing/helper/test-register.c
+++ b/testing/helper/test-register.c
@@ -30,7 +30,7 @@ static void puthex(const __u8 *b, size_t n)
if (n > 1024)
return;
- shirudo_hex_encode(b, n, h);
+ hex_encode(b, n, h);
printf("%s\n", h);
}
@@ -41,37 +41,37 @@ static int append_init(const __u8 event[32],
char buf[4096], ts[32], boot_id[64], nv_index[16], hex[256];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_hex_encode(event, 32, hex);
- shirudo_json_kv_string(&e, "digest", hex);
- shirudo_json_kv_string(&e, "type", "init");
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_kv_int(&e, "tpm_reset_count", info->reset_count);
- shirudo_json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
- shirudo_hex_encode(info->pcr_before, 32, hex);
- shirudo_json_kv_string(&e, "pcr_before", hex);
- shirudo_json_kv_int(&e, "phase_pcr", SHIRUDO_CHAIN_PHASE_PCR);
- shirudo_hex_encode(info->phase_before, 32, hex);
- shirudo_json_kv_string(&e, "phase_before", hex);
- shirudo_json_kv_string(&e, "bound_in", info->initrd ? "initrd" : "root");
- shirudo_hex_encode(info->name, info->name_len, hex);
- shirudo_json_kv_string(&e, "nv_name", hex);
- shirudo_json_kv_string(&e, "anchor", info->anchor);
- shirudo_hex_encode(info->anchor_digest, 32, hex);
- shirudo_json_kv_string(&e, "anchor_digest", hex);
- shirudo_hex_encode(info->value, 32, hex);
- shirudo_json_kv_string(&e, "chain", hex);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ hex_encode(event, 32, hex);
+ json_kv_string(&e, "digest", hex);
+ json_kv_string(&e, "type", "init");
+ json_kv_string(&e, "boot_id", boot_id);
+ json_kv_int(&e, "tpm_reset_count", info->reset_count);
+ json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
+ hex_encode(info->pcr_before, 32, hex);
+ json_kv_string(&e, "pcr_before", hex);
+ json_kv_int(&e, "phase_pcr", SHIRUDO_CHAIN_PHASE_PCR);
+ hex_encode(info->phase_before, 32, hex);
+ json_kv_string(&e, "phase_before", hex);
+ json_kv_string(&e, "bound_in", info->initrd ? "initrd" : "root");
+ hex_encode(info->name, info->name_len, hex);
+ json_kv_string(&e, "nv_name", hex);
+ json_kv_string(&e, "anchor", info->anchor);
+ hex_encode(info->anchor_digest, 32, hex);
+ json_kv_string(&e, "anchor_digest", hex);
+ hex_encode(info->value, 32, hex);
+ json_kv_string(&e, "chain", hex);
+ json_obj_close(&e);
if (e.err)
return e.err;
- return shirudo_eventlog_append(buf);
+ return eventlog_append(buf);
}
static int append_event(const char *type, const char *name,
@@ -80,27 +80,27 @@ static int append_event(const char *type, const char *name,
char buf[4096], ts[32], boot_id[64], nv_index[16], hex[65];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 2);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "alg", "sha256");
- shirudo_hex_encode(event, 32, hex);
- shirudo_json_kv_string(&e, "digest", hex);
- shirudo_json_kv_string(&e, "type", type);
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_obj_open_key(&e, "upatch");
- shirudo_json_kv_string(&e, "name", name);
- shirudo_json_obj_close(&e);
- shirudo_hex_encode(chain, 32, hex);
- shirudo_json_kv_string(&e, "chain", hex);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 2);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "alg", "sha256");
+ hex_encode(event, 32, hex);
+ json_kv_string(&e, "digest", hex);
+ json_kv_string(&e, "type", type);
+ json_kv_string(&e, "boot_id", boot_id);
+ json_obj_open_key(&e, "upatch");
+ json_kv_string(&e, "name", name);
+ json_obj_close(&e);
+ hex_encode(chain, 32, hex);
+ json_kv_string(&e, "chain", hex);
+ json_obj_close(&e);
if (e.err)
return e.err;
- return shirudo_eventlog_append(buf);
+ return eventlog_append(buf);
}
int main(int argc, char **argv)
@@ -114,9 +114,9 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "init") == 0 && argc == 3) {
struct shirudo_chain_init_info info;
- if (shirudo_hex_decode(argv[2], event, 32))
+ if (hex_decode(argv[2], event, 32))
return 2;
- rc = shirudo_chain_init(event, &info);
+ rc = chain_init(event, &info);
printf("rc=%d\n", rc);
if (rc)
return 1;
@@ -139,11 +139,11 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "load") == 0 && argc == 4) {
__u8 payload[32];
- if (shirudo_hex_decode(argv[3], payload, 32))
+ if (hex_decode(argv[3], payload, 32))
return 2;
- shirudo_chain_upatch_event("shirudo-upatch", argv[2], payload,
- event);
- rc = shirudo_chain_extend(event, chain);
+ chain_upatch_event("shirudo-upatch", argv[2], payload,
+ event);
+ rc = chain_extend(event, chain);
printf("rc=%d\n", rc);
if (rc)
return 1;
@@ -153,9 +153,9 @@ int main(int argc, char **argv)
1 : 0;
}
if (strcmp(argv[1], "extend-raw") == 0 && argc == 3) {
- if (shirudo_hex_decode(argv[2], event, 32))
+ if (hex_decode(argv[2], event, 32))
return 2;
- rc = shirudo_chain_extend(event, chain);
+ rc = chain_extend(event, chain);
printf("rc=%d\n", rc);
if (rc)
return 1;
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
return 0;
}
if (strcmp(argv[1], "read") == 0) {
- rc = shirudo_chain_read(chain);
+ rc = chain_read(chain);
printf("rc=%d\n", rc);
if (rc)
return 1;
@@ -173,9 +173,9 @@ int main(int argc, char **argv)
return 0;
}
if (strcmp(argv[1], "status") == 0) {
- struct shirudo_chain_status st;
+ struct chain_status st;
- rc = shirudo_chain_status(&st);
+ rc = chain_status(&st);
printf("rc=%d\n", rc);
printf("tpm=%d defined=%d written=%d logged=%d anchored=%d\n",
st.tpm, st.defined, st.written, st.logged, st.anchored);
@@ -191,10 +191,10 @@ int main(int argc, char **argv)
struct shirudo_tpm *tpm = NULL;
__u8 d[32];
- if (shirudo_hex_decode(argv[3], d, 32) || shirudo_tpm_open(&tpm))
+ if (hex_decode(argv[3], d, 32) || tpm_open(&tpm))
return 2;
- rc = shirudo_tpm_pcr_extend(tpm, (__u32)atoi(argv[2]), d);
- shirudo_tpm_close(tpm);
+ rc = tpm_pcr_extend(tpm, (__u32)atoi(argv[2]), d);
+ tpm_close(tpm);
printf("rc=%d\n", rc);
return rc ? 1 : 0;
}
@@ -202,10 +202,10 @@ int main(int argc, char **argv)
struct shirudo_tpm *tpm = NULL;
__u8 v[32];
- if (shirudo_tpm_open(&tpm))
+ if (tpm_open(&tpm))
return 1;
- rc = shirudo_tpm_pcr_read(tpm, (__u32)atoi(argv[2]), v);
- shirudo_tpm_close(tpm);
+ rc = tpm_pcr_read(tpm, (__u32)atoi(argv[2]), v);
+ tpm_close(tpm);
if (rc)
return 1;
puthex(v, 32);
@@ -219,38 +219,38 @@ int main(int argc, char **argv)
struct shirudo_tpm_key ek = { .handle = 0 };
struct shirudo_tpm *tpm = NULL;
- if (shirudo_tpm_open(&tpm))
+ if (tpm_open(&tpm))
return 1;
- rc = shirudo_tpm_ek_create(tpm, strcmp(argv[2], "rsa") == 0,
- &ek);
+ rc = tpm_ek_create(tpm, strcmp(argv[2], "rsa") == 0,
+ &ek);
if (!rc) {
printf("public=");
puthex(ek.public, ek.public_len);
printf("name=");
puthex(ek.name, ek.name_len);
- shirudo_tpm_key_flush(tpm, &ek);
+ tpm_key_flush(tpm, &ek);
}
- shirudo_tpm_close(tpm);
+ tpm_close(tpm);
printf("rc=%d\n", rc);
return rc ? 1 : 0;
}
/* The attack: recreate the index with the same public area. */
if (strcmp(argv[1], "recreate") == 0) {
- struct shirudo_tpm_nv_info nv;
+ struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
- if (shirudo_tpm_open(&tpm))
+ if (tpm_open(&tpm))
return 1;
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (!rc && nv.defined)
- rc = shirudo_tpm_nv_undefine(tpm, SHIRUDO_NV_INDEX,
- NULL, 0);
+ rc = tpm_nv_undefine(tpm, SHIRUDO_NV_INDEX,
+ NULL, 0);
if (!rc)
- rc = shirudo_tpm_nv_define(tpm, SHIRUDO_NV_INDEX,
- nv.policy, NULL, 0);
+ rc = tpm_nv_define(tpm, SHIRUDO_NV_INDEX,
+ nv.policy, NULL, 0);
if (!rc)
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
- shirudo_tpm_close(tpm);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ tpm_close(tpm);
printf("rc=%d\n", rc);
if (rc)
return 1;
@@ -265,21 +265,21 @@ int main(int argc, char **argv)
struct shirudo_tpm *tpm = NULL;
__u8 values[64];
- if (shirudo_hex_decode(argv[2], event, 32) ||
- shirudo_eventlog_boot_init(&rec))
+ if (hex_decode(argv[2], event, 32) ||
+ eventlog_boot_init(&rec))
return 2;
memcpy(values, rec.pcr_before, 32);
memcpy(values + 32, rec.phase_before, 32);
- shirudo_tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, values, 2,
- branch_written, branch_init,
- policy);
- if (shirudo_tpm_open(&tpm))
+ tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, values, 2,
+ branch_written, branch_init,
+ policy);
+ if (tpm_open(&tpm))
return 1;
- rc = shirudo_tpm_nv_extend_first(tpm, SHIRUDO_NV_INDEX,
- SHIRUDO_CHAIN_PCR_MASK,
- branch_written, branch_init,
- event);
- shirudo_tpm_close(tpm);
+ rc = tpm_nv_extend_first(tpm, SHIRUDO_NV_INDEX,
+ SHIRUDO_CHAIN_PCR_MASK,
+ branch_written, branch_init,
+ event);
+ tpm_close(tpm);
printf("rc=%d\n", rc);
return rc ? 1 : 0;
}
@@ -290,17 +290,17 @@ int main(int argc, char **argv)
char *doc;
if (nonce_len > sizeof(nonce) ||
- shirudo_hex_decode(argv[2], nonce, nonce_len))
+ hex_decode(argv[2], nonce, nonce_len))
return 2;
if (argc == 4 &&
- shirudo_attest_challenge_read(argv[3], &challenge)) {
+ attest_challenge_read(argv[3], &challenge)) {
fprintf(stderr, "evidence: bad challenge\n");
return 2;
}
- rc = shirudo_attest_evidence(nonce, nonce_len,
- SHIRUDO_ATTEST_PCR_DEFAULT,
- argc == 4 ? &challenge : NULL,
- &doc, &len, &cap);
+ rc = attest_evidence(nonce, nonce_len,
+ SHIRUDO_ATTEST_PCR_DEFAULT,
+ argc == 4 ? &challenge : NULL,
+ &doc, &len, &cap);
if (rc) {
fprintf(stderr, "evidence: %s\n", strerror(-rc));
return 1;
diff --git a/testing/helper/test-seal.c b/testing/helper/test-seal.c
index 0cea8e9a..eb5d6ed7 100644
--- a/testing/helper/test-seal.c
+++ b/testing/helper/test-seal.c
@@ -21,10 +21,10 @@ static int append(const char *path, const char *text)
{
int fd, rc;
- fd = shirudo_seal_open(path, O_WRONLY | O_CREAT | O_APPEND, 0600);
+ fd = seal_open(path, O_WRONLY | O_CREAT | O_APPEND, 0600);
if (fd < 0)
return fd;
- rc = shirudo_write_all(fd, text, strlen(text));
+ rc = write_all(fd, text, strlen(text));
if (close(fd) && !rc)
rc = -errno;
return rc;
@@ -59,16 +59,16 @@ int main(int argc, char **argv)
return 0;
}
if (strcmp(argv[1], "label") == 0) {
- rc = shirudo_seal_label(argv[2]);
+ rc = seal_label(argv[2]);
} else if (strcmp(argv[1], "mkdir") == 0) {
- rc = shirudo_seal_mkdir_p(argv[2], 0700);
+ rc = seal_mkdir_p(argv[2], 0700);
} else if (strcmp(argv[1], "open") == 0 && argc == 4) {
rc = append(argv[2], argv[3]);
} else if (strcmp(argv[1], "write") == 0 && argc == 4) {
- rc = shirudo_seal_write_file(argv[2], argv[3], strlen(argv[3]),
- 0600);
+ rc = seal_write_file(argv[2], argv[3], strlen(argv[3]),
+ 0600);
} else if (strcmp(argv[1], "inherit") == 0) {
- rc = shirudo_seal_inherit_path(argv[2]);
+ rc = seal_inherit_path(argv[2]);
} else {
fprintf(stderr, "unknown subcommand\n");
return 2;
diff --git a/testing/helper/test-string.c b/testing/helper/test-string.c
index 2b9fb514..787546a1 100644
--- a/testing/helper/test-string.c
+++ b/testing/helper/test-string.c
@@ -53,7 +53,7 @@ int main(int argc, char **argv)
int rc;
if (!strcmp(op, "digits") && argc == 3) {
- printf("n=%zu\n", shirudo_digits(argv[2], strlen(argv[2])));
+ printf("n=%zu\n", digits(argv[2], strlen(argv[2])));
return 0;
}
if ((!strcmp(op, "u64") || !strcmp(op, "x64")) &&
diff --git a/testing/helper/test-tpm-wire.c b/testing/helper/test-tpm-wire.c
index b0496a1a..cffb5a35 100644
--- a/testing/helper/test-tpm-wire.c
+++ b/testing/helper/test-tpm-wire.c
@@ -21,7 +21,7 @@ static void puthex(const __u8 *b, size_t n)
if (n > 2048)
return;
- shirudo_hex_encode(b, n, h);
+ hex_encode(b, n, h);
printf("%s\n", h);
}
@@ -32,7 +32,7 @@ static int gethex(const char *hex, __u8 *out, size_t cap, size_t *len)
if (n & 1 || n / 2 > cap)
return -1;
*len = n / 2;
- return shirudo_hex_decode(hex, out, n / 2);
+ return hex_decode(hex, out, n / 2);
}
int main(int argc, char **argv)
@@ -43,37 +43,37 @@ int main(int argc, char **argv)
if (argc < 2)
return 2;
if (strcmp(argv[1], "nv-written") == 0 && argc == 4) {
- if (shirudo_hex_decode(argv[2], a, 32))
+ if (hex_decode(argv[2], a, 32))
return 2;
- shirudo_tpm_policy_nv_written(a, atoi(argv[3]) != 0, out);
+ tpm_policy_nv_written(a, atoi(argv[3]) != 0, out);
puthex(out, 32);
return 0;
}
if (strcmp(argv[1], "pcr") == 0 && argc == 5) {
- if (shirudo_hex_decode(argv[2], a, 32) ||
- shirudo_hex_decode(argv[4], b, 32))
+ if (hex_decode(argv[2], a, 32) ||
+ hex_decode(argv[4], b, 32))
return 2;
- shirudo_tpm_policy_pcr(a, (__u32)strtoul(argv[3], NULL, 0),
- b, out);
+ tpm_policy_pcr(a, (__u32)strtoul(argv[3], NULL, 0),
+ b, out);
puthex(out, 32);
return 0;
}
if (strcmp(argv[1], "or") == 0 && argc == 4) {
- if (shirudo_hex_decode(argv[2], a, 32) ||
- shirudo_hex_decode(argv[3], b, 32))
+ if (hex_decode(argv[2], a, 32) ||
+ hex_decode(argv[3], b, 32))
return 2;
- shirudo_tpm_policy_or(a, b, out);
+ tpm_policy_or(a, b, out);
puthex(out, 32);
return 0;
}
if (strcmp(argv[1], "register-policy") == 0 && argc == 5) {
__u8 w[32], i[32], p[32], values[64];
- if (shirudo_hex_decode(argv[3], values, 32) ||
- shirudo_hex_decode(argv[4], values + 32, 32))
+ if (hex_decode(argv[3], values, 32) ||
+ hex_decode(argv[4], values + 32, 32))
return 2;
- shirudo_tpm_register_policy((__u32)strtoul(argv[2], NULL, 0),
- values, 2, w, i, p);
+ tpm_register_policy((__u32)strtoul(argv[2], NULL, 0),
+ values, 2, w, i, p);
puthex(w, 32);
puthex(i, 32);
puthex(p, 32);
@@ -82,11 +82,11 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "nv-name") == 0 && argc == 5) {
__u8 name[SHIRUDO_TPM_NAME_LEN];
- if (shirudo_hex_decode(argv[4], a, 32))
+ if (hex_decode(argv[4], a, 32))
return 2;
- shirudo_tpm_nv_name((__u32)strtoul(argv[2], NULL, 0),
- (__u32)strtoul(argv[3], NULL, 0), a, 32,
- name);
+ tpm_nv_name((__u32)strtoul(argv[2], NULL, 0),
+ (__u32)strtoul(argv[3], NULL, 0), a, 32,
+ name);
puthex(name, sizeof(name));
return 0;
}
@@ -94,7 +94,7 @@ int main(int argc, char **argv)
__u8 name[SHIRUDO_TPM_NAME_LEN];
if (gethex(argv[2], buf, sizeof(buf), &len) ||
- shirudo_tpm_object_name(buf, len, name))
+ tpm_object_name(buf, len, name))
return 1;
puthex(name, sizeof(name));
return 0;
@@ -105,7 +105,7 @@ int main(int argc, char **argv)
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = shirudo_tpm_ecc_public_parse(buf, len, &pub);
+ rc = tpm_ecc_public_parse(buf, len, &pub);
printf("rc=%d\n", rc);
if (rc)
return 0;
@@ -123,7 +123,7 @@ int main(int argc, char **argv)
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = shirudo_tpm_public_parse(buf, len, &pub);
+ rc = tpm_public_parse(buf, len, &pub);
printf("rc=%d\n", rc);
if (rc)
return 0;
@@ -133,8 +133,8 @@ int main(int argc, char **argv)
pub.sym_alg, pub.sym_bits, pub.sym_mode, pub.scheme,
pub.scheme_hash, pub.curve, pub.rsa_bits,
pub.rsa_exponent, pub.n_len);
- rc = shirudo_tpm_public_marshal(&pub, again, sizeof(again),
- &again_len);
+ rc = tpm_public_marshal(&pub, again, sizeof(again),
+ &again_len);
printf("marshal_rc=%d same=%d\n", rc,
rc == 0 && again_len == len && !memcmp(again, buf, len));
return 0;
@@ -147,8 +147,8 @@ int main(int argc, char **argv)
gethex(strcmp(argv[4], "-") ? argv[4] : "", ctx, sizeof(ctx),
&ctx_len) || res_len > sizeof(res))
return 2;
- if (shirudo_tpm_kdfa(key, key_len, argv[3], ctx, ctx_len, NULL, 0,
- res, res_len))
+ if (tpm_kdfa(key, key_len, argv[3], ctx, ctx_len, NULL, 0,
+ res, res_len))
return 1;
puthex(res, res_len);
return 0;
@@ -161,7 +161,7 @@ int main(int argc, char **argv)
gethex(argv[4], u, sizeof(u), &u_len) ||
gethex(argv[5], v, sizeof(v), &v_len))
return 2;
- shirudo_tpm_kdfe(z, argv[3], u, u_len, v, v_len, res);
+ tpm_kdfe(z, argv[3], u, u_len, v, v_len, res);
puthex(res, 32);
return 0;
}
@@ -179,7 +179,7 @@ int main(int argc, char **argv)
n != SHIRUDO_TPM_NAME_LEN ||
gethex(argv[4], cred, sizeof(cred), &n) || n != 32)
return 2;
- if (shirudo_tpm_credential_protect(seed, name, cred, blob))
+ if (tpm_credential_protect(seed, name, cred, blob))
return 1;
puthex(blob, sizeof(blob));
return 0;
@@ -190,7 +190,7 @@ int main(int argc, char **argv)
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = shirudo_tpm_ecdsa_signature_parse(buf, len, r, s);
+ rc = tpm_ecdsa_signature_parse(buf, len, r, s);
printf("rc=%d\n", rc);
if (rc)
return 0;
@@ -204,7 +204,7 @@ int main(int argc, char **argv)
if (gethex(argv[2], buf, sizeof(buf), &len))
return 2;
- rc = shirudo_tpm_attest_parse(buf, len, &at);
+ rc = tpm_attest_parse(buf, len, &at);
printf("rc=%d\n", rc);
if (rc)
return 0;
diff --git a/testing/helper/test-upatch-decode.c b/testing/helper/test-upatch-decode.c
index 8d8ac2b2..0b923b18 100644
--- a/testing/helper/test-upatch-decode.c
+++ b/testing/helper/test-upatch-decode.c
@@ -38,11 +38,11 @@ int main(int argc, char **argv)
else if (strcmp(argv[1], "loop") == 0)
view.serial_bytes_total = 999;
if (strcmp(argv[1], "otel") == 0)
- rc = shirudo_upatch_decode_map_file_otel(argv[2], &view,
- &out, &out_len);
+ rc = upatch_decode_map_file_otel(argv[2], &view,
+ &out, &out_len);
else
- rc = shirudo_upatch_decode_map_file_json(argv[2], &view,
- &out, &out_len);
+ rc = upatch_decode_map_file_json(argv[2], &view,
+ &out, &out_len);
if (rc) {
fprintf(stderr, "decode: %d\n", rc);
return 1;
diff --git a/testing/helper/test-upatch-map-types.c b/testing/helper/test-upatch-map-types.c
index c1bea690..0d63e14b 100644
--- a/testing/helper/test-upatch-map-types.c
+++ b/testing/helper/test-upatch-map-types.c
@@ -19,21 +19,21 @@ int main(int argc, char **argv)
return 2;
if (strcmp(argv[1], "arena-name") == 0) {
- puts(shirudo_map_type_name(BPF_MAP_TYPE_ARENA));
+ puts(map_type_name(BPF_MAP_TYPE_ARENA));
return 0;
}
if (strcmp(argv[1], "arena-skip") == 0) {
- s = shirudo_map_skip_reason(BPF_MAP_TYPE_ARENA);
+ s = map_skip_reason(BPF_MAP_TYPE_ARENA);
puts(s ? s : "");
return 0;
}
if (strcmp(argv[1], "array-skip") == 0) {
- s = shirudo_map_skip_reason(BPF_MAP_TYPE_ARRAY);
+ s = map_skip_reason(BPF_MAP_TYPE_ARRAY);
puts(s ? s : "");
return 0;
}
if (strcmp(argv[1], "ringbuf-name") == 0) {
- puts(shirudo_map_type_name(BPF_MAP_TYPE_RINGBUF));
+ puts(map_type_name(BPF_MAP_TYPE_RINGBUF));
return 0;
}
return 2;
diff --git a/testing/helper/test-upatch-prog-metadata.c b/testing/helper/test-upatch-prog-metadata.c
index fc48ccda..6b96fa4f 100644
--- a/testing/helper/test-upatch-prog-metadata.c
+++ b/testing/helper/test-upatch-prog-metadata.c
@@ -32,7 +32,7 @@ static int expect_attach(const struct shirudo_upatch *u, __u32 kind,
return fail("unexpected metadata prog count");
if (u->hdr.metadata_len != sizeof(md) + sizeof(prog))
return fail("unexpected metadata length");
- raw = shirudo_upatch_metadata(u);
+ raw = upatch_metadata(u);
if (!raw)
return fail("missing metadata");
memcpy(&md, raw, sizeof(md));
@@ -73,7 +73,7 @@ static int expect_serializer(const struct shirudo_upatch *u)
return fail("unexpected map/prog counts");
if (u->hdr.metadata_len != sizeof(md) + sizeof(progs))
return fail("unexpected metadata length");
- raw = shirudo_upatch_metadata(u);
+ raw = upatch_metadata(u);
if (!raw)
return fail("missing metadata");
memcpy(&md, raw, sizeof(md));
@@ -110,7 +110,7 @@ static int expect_uprobe_multi(const struct shirudo_upatch *u,
if (u->hdr.nr_progs != 1)
return fail("unexpected metadata prog count");
- raw = shirudo_upatch_metadata(u);
+ raw = upatch_metadata(u);
if (!raw || u->hdr.metadata_len < sizeof(md) + sizeof(prog) +
sizeof(targets) + sizeof(record))
return fail("missing uprobe metadata");
@@ -172,7 +172,7 @@ int main(int argc, char **argv)
if (argc >= 3)
mode = argv[2];
- rc = shirudo_upatch_open(argv[1], &u);
+ rc = upatch_open(argv[1], &u);
if (rc)
return fail("open upatch failed");
@@ -209,7 +209,7 @@ int main(int argc, char **argv)
rc = fail("unknown metadata check mode");
}
- shirudo_upatch_close(&u);
+ upatch_close(&u);
if (rc)
return rc;
puts("ok");
diff --git a/testing/helper/test-upatch-serializer-pages.c b/testing/helper/test-upatch-serializer-pages.c
index cd1e69f5..f284c64a 100644
--- a/testing/helper/test-upatch-serializer-pages.c
+++ b/testing/helper/test-upatch-serializer-pages.c
@@ -50,11 +50,11 @@ static int check_abi_and_nonce(void)
sizeof(struct shirudo_serial_chunk) != 4096 ||
SHIRUDO_SERIAL_CHUNK_PAYLOAD != 4032)
return fail("serializer v3 ABI layout mismatch");
- if (shirudo_serial_chunk_validate(&chunk, 1, 2, 3, 10, 11, 0x12345678) != 0)
+ if (serial_chunk_validate(&chunk, 1, 2, 3, 10, 11, 0x12345678) != 0)
return fail("valid serializer nonce rejected");
- if (shirudo_serial_chunk_validate(&chunk, 1, 2, 3, 10, 11, 0x87654321) != -EBADMSG)
+ if (serial_chunk_validate(&chunk, 1, 2, 3, 10, 11, 0x87654321) != -EBADMSG)
return fail("serializer nonce mismatch accepted");
- if (shirudo_serializer_new_invocation_id(&generated) != 0 || generated == 0)
+ if (serializer_new_invocation_id(&generated) != 0 || generated == 0)
return fail("serializer invocation ID generation failed");
return 0;
}
@@ -67,24 +67,24 @@ static int check_map_locks(void)
if (!mkdtemp(dir))
return fail("mkdtemp failed");
- first = shirudo_serializer_lock_acquire_at(dir, 101);
+ first = serializer_lock_acquire_at(dir, 101);
if (first < 0) {
fail("first serializer lock failed");
goto out;
}
- busy = shirudo_serializer_lock_acquire_at(dir, 101);
+ busy = serializer_lock_acquire_at(dir, 101);
if (busy != -EBUSY) {
fail("contended serializer lock did not return EBUSY");
goto out;
}
- other = shirudo_serializer_lock_acquire_at(dir, 202);
+ other = serializer_lock_acquire_at(dir, 202);
if (other < 0) {
fail("independent serializer map lock failed");
goto out;
}
close(first);
first = -1;
- again = shirudo_serializer_lock_acquire_at(dir, 101);
+ again = serializer_lock_acquire_at(dir, 101);
if (again < 0) {
fail("released serializer lock could not be reacquired");
goto out;
@@ -151,7 +151,7 @@ int main(void)
e.buf = buf;
e.cap = sizeof(buf);
- shirudo_upatch_maps_emit_json_object(&e, &v);
+ upatch_maps_emit_json_object(&e, &v);
if (e.err)
return fail("json emit failed");
@@ -180,14 +180,14 @@ int main(void)
return fail("old chunk field still emitted");
e = (struct shirudo_json_emit){ .buf = doc, .cap = sizeof(doc) };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "upatch", "exec-uid-arena");
- shirudo_json_kv_string(&e, "map", "tree_arena");
- shirudo_json_obj_open_key(&e, "data");
- shirudo_upatch_maps_emit_json_fields(&e, &v);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "upatch", "exec-uid-arena");
+ json_kv_string(&e, "map", "tree_arena");
+ json_obj_open_key(&e, "data");
+ upatch_maps_emit_json_fields(&e, &v);
+ json_obj_close(&e);
+ json_obj_close(&e);
if (e.err)
return fail("wrapped json emit failed");
if (has(doc, "\"data\":{{"))
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index 2d599233..be8dcbe2 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -561,7 +561,7 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)
return -EINVAL;
if (!u->tree.present)
continue;
- if (!u->tree.id[0] || !shirudo_upatch_name_valid(u->tree.id))
+ if (!u->tree.id[0] || !upatch_name_valid(u->tree.id))
return -EINVAL;
if (!u->tree.load_artifact[0])
build_copy(u->tree.load_artifact, sizeof(u->tree.load_artifact),
@@ -843,19 +843,19 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
unlink(object);
if (rc)
return rc < 0 ? rc : -EIO;
- if (shirudo_upatch_open(load, &parsed))
+ if (upatch_open(load, &parsed))
return -EINVAL;
- if (shirudo_upatch_is_unload(&parsed) || !parsed.hdr.name[0]) {
- shirudo_upatch_close(&parsed);
+ if (upatch_is_unload(&parsed) || !parsed.hdr.name[0]) {
+ upatch_close(&parsed);
return -EINVAL;
}
build_copy(u->name, sizeof(u->name), parsed.hdr.name);
- shirudo_hex_encode(parsed.hdr.payload_sha256,
- SHIRUDO_CRYPTO_SHA256_LEN,
- u->payload_sha256);
+ hex_encode(parsed.hdr.payload_sha256,
+ SHIRUDO_CRYPTO_SHA256_LEN,
+ u->payload_sha256);
memcpy(payload, parsed.hdr.payload_sha256, sizeof(payload));
- build_copy(u->type, sizeof(u->type), shirudo_upatch_type_str(&parsed));
- shirudo_upatch_close(&parsed);
+ build_copy(u->type, sizeof(u->type), upatch_type_str(&parsed));
+ upatch_close(&parsed);
rc = shirudo_build_package_unload(u->name, payload, unload, pkey,
cert);
if (rc)
@@ -877,7 +877,7 @@ static int build_environment(const struct bpm_build_spec *spec,
ssize_t self_len;
if (!body || uname(&un) ||
- shirudo_iso8601(now, timestamp, sizeof(timestamp))) {
+ iso8601(now, timestamp, sizeof(timestamp))) {
if (body)
xfree(body, BPM_BUILD_MAX_JSON);
return -EIO;
@@ -885,41 +885,41 @@ static int build_environment(const struct bpm_build_spec *spec,
self_len = readlink("/proc/self/exe", self, sizeof(self) - 1);
if (self_len > 0)
self[self_len] = '\0';
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "format_version", 1);
- shirudo_json_kv_string(&e, "builder", "bpm build");
- shirudo_json_kv_string(&e, "created_at", timestamp);
- shirudo_json_obj_open_key(&e, "package");
- shirudo_json_kv_string(&e, "name", spec->name);
- shirudo_json_kv_string(&e, "version", version);
- shirudo_json_obj_close(&e);
- shirudo_json_kv_string(&e, "os", un.sysname);
- shirudo_json_kv_string(&e, "arch", un.machine);
- shirudo_json_kv_string(&e, "bpm_version", shirudo_version);
- shirudo_json_obj_open_key(&e, "shirudo");
- shirudo_json_kv_string(&e, "path", self);
- shirudo_json_kv_string(&e, "version", shirudo_version);
- shirudo_json_kv_string(&e, "spki_sha256_fingerprint", fingerprint);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "upatches");
+ json_obj_open(&e);
+ json_kv_int(&e, "format_version", 1);
+ json_kv_string(&e, "builder", "bpm build");
+ json_kv_string(&e, "created_at", timestamp);
+ json_obj_open_key(&e, "package");
+ json_kv_string(&e, "name", spec->name);
+ json_kv_string(&e, "version", version);
+ json_obj_close(&e);
+ json_kv_string(&e, "os", un.sysname);
+ json_kv_string(&e, "arch", un.machine);
+ json_kv_string(&e, "bpm_version", shirudo_version);
+ json_obj_open_key(&e, "shirudo");
+ json_kv_string(&e, "path", self);
+ json_kv_string(&e, "version", shirudo_version);
+ json_kv_string(&e, "spki_sha256_fingerprint", fingerprint);
+ json_obj_close(&e);
+ json_arr_open(&e, "upatches");
for (size_t i = 0; i < spec->n_upatches; i++) {
const struct bpm_build_upatch *u = &spec->upatches[i];
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "source", u->source);
- shirudo_json_kv_string(&e, "type", u->type);
- shirudo_json_kv_string(&e, "load_target", u->load_target);
- shirudo_json_kv_string(&e, "load_output", strrchr(u->load_target, '/') ?
- strrchr(u->load_target, '/') + 1 : u->load_target);
- shirudo_json_kv_string(&e, "unload_target", u->unload_target);
- shirudo_json_kv_string(&e, "unload_output", strrchr(u->unload_target, '/') ?
- strrchr(u->unload_target, '/') + 1 : u->unload_target);
- shirudo_json_kv_string(&e, "upatch_name", u->name);
- shirudo_json_kv_string(&e, "payload_sha256", u->payload_sha256);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "source", u->source);
+ json_kv_string(&e, "type", u->type);
+ json_kv_string(&e, "load_target", u->load_target);
+ json_kv_string(&e, "load_output", strrchr(u->load_target, '/') ?
+ strrchr(u->load_target, '/') + 1 : u->load_target);
+ json_kv_string(&e, "unload_target", u->unload_target);
+ json_kv_string(&e, "unload_output", strrchr(u->unload_target, '/') ?
+ strrchr(u->unload_target, '/') + 1 : u->unload_target);
+ json_kv_string(&e, "upatch_name", u->name);
+ json_kv_string(&e, "payload_sha256", u->payload_sha256);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
xfree(body, BPM_BUILD_MAX_JSON);
return e.err;
@@ -1097,7 +1097,7 @@ static const char *build_resolve_keys_dir(const char *arg, char *out, size_t cap
const char *home = getenv("HOME");
if (!arg || !*arg)
- arg = shirudo_keys_dir_resolve(NULL);
+ arg = keys_dir_resolve(NULL);
if (arg[0] == '~' && (!arg[1] || arg[1] == '/')) {
if (!home || snprintf(out, cap, "%s%s", home, arg + 1) >= (int)cap)
return NULL;
@@ -1172,8 +1172,8 @@ static int shirudo_build_bpm_build(int argc, char **argv)
pr_err("bpm build: keys directory %s is not usable", keys_dir);
return -ENOENT;
}
- rc = shirudo_key_paths(keys_abs, pkey, sizeof(pkey), cert_path,
- sizeof(cert_path));
+ rc = key_paths(keys_abs, pkey, sizeof(pkey), cert_path,
+ sizeof(cert_path));
if (rc)
return rc;
if (shirudo_build_check_keys(pkey, cert_path))
@@ -1209,14 +1209,14 @@ static int shirudo_build_bpm_build(int argc, char **argv)
pr_err("bpm build: %s is not a valid Beefile", resolved_file);
goto out;
}
- if (shirudo_cert_read_file(cert_path, &cert)) {
+ if (cert_read_file(cert_path, &cert)) {
rc = -ENOENT;
goto out;
}
- rc = shirudo_cert_pubkey_digest(&cert, digest);
+ rc = cert_pubkey_digest(&cert, digest);
if (rc)
goto out_cert;
- shirudo_hex_encode(digest, sizeof(digest), fingerprint);
+ hex_encode(digest, sizeof(digest), fingerprint);
/*
* Compile in the package directory so ./vmlinux.h and the vendored
* headers resolve the way they do for `shirudo build` run there.
@@ -1233,7 +1233,7 @@ static int shirudo_build_bpm_build(int argc, char **argv)
rc = build_archive(spec, version, cert_path, fingerprint, out_dir);
build_stage_close(spec);
out_cert:
- shirudo_cert_free(&cert);
+ cert_free(&cert);
out:
if (body)
xfree(body, body_len + 1);
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index fbaaf561..3e5eab1c 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -76,7 +76,7 @@ static int sign_detached(const void *payload, size_t len,
io.signature = xmalloc(io.signature_sz);
if (!io.signature)
return -ENOMEM;
- rc = shirudo_cms_sign(&io, key, cert);
+ rc = cms_sign(&io, key, cert);
if (rc) {
xfree(io.signature, BPM_SIGN_MAX);
return rc;
@@ -235,7 +235,7 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
bpm_copy_string(entry->signer, sizeof(entry->signer), info->signer);
qsort(entries, (size_t)n, sizeof(*entries), index_entry_compare);
- if (shirudo_iso8601(now, timestamp, sizeof(timestamp))) {
+ if (iso8601(now, timestamp, sizeof(timestamp))) {
rc = -EIO;
goto out;
}
@@ -246,23 +246,23 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
goto out;
}
e = (struct shirudo_json_emit){ .buf = body, .cap = cap };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "generated_at", timestamp);
- shirudo_json_arr_open(&e, "packages");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "generated_at", timestamp);
+ json_arr_open(&e, "packages");
for (int i = 0; i < n; i++) {
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", entries[i].name);
- shirudo_json_kv_string(&e, "version", entries[i].version);
- shirudo_json_kv_string(&e, "repository", entries[i].repository);
- shirudo_json_kv_string(&e, "manifest_digest", entries[i].manifest_digest);
- shirudo_json_kv_string(&e, "package_digest", entries[i].package_digest);
- shirudo_json_kv_int(&e, "package_size", entries[i].package_size);
- shirudo_json_kv_string(&e, "signer_fingerprint", entries[i].signer);
- shirudo_json_obj_close(&e);
- }
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_string(&e, "name", entries[i].name);
+ json_kv_string(&e, "version", entries[i].version);
+ json_kv_string(&e, "repository", entries[i].repository);
+ json_kv_string(&e, "manifest_digest", entries[i].manifest_digest);
+ json_kv_string(&e, "package_digest", entries[i].package_digest);
+ json_kv_int(&e, "package_size", entries[i].package_size);
+ json_kv_string(&e, "signer_fingerprint", entries[i].signer);
+ json_obj_close(&e);
+ }
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
rc = e.err;
goto out;
@@ -289,16 +289,16 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
goto out;
}
e = (struct shirudo_json_emit){ .buf = manifest, .cap = BPM_MANIFEST_CAP };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schemaVersion", 2);
- shirudo_json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
- shirudo_json_kv_string(&e, "artifactType", BPM_INDEX_ARTIFACT);
+ json_obj_open(&e);
+ json_kv_int(&e, "schemaVersion", 2);
+ json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
+ json_kv_string(&e, "artifactType", BPM_INDEX_ARTIFACT);
bpm_oci_emit_descriptor(&e, "config", &config, NULL);
- shirudo_json_arr_open(&e, "layers");
+ json_arr_open(&e, "layers");
bpm_oci_emit_descriptor(&e, NULL, &payload_layer, NULL);
bpm_oci_emit_descriptor(&e, NULL, &sig_layer, NULL);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
rc = e.err;
goto out;
@@ -344,8 +344,8 @@ static int push_package(const char *package_path, const char *raw_repository,
return -errno;
if (!S_ISREG(st.st_mode))
return -EINVAL;
- rc = shirudo_read_file(package_path, BPM_MAX_HTTP_BODY, &archive,
- &archive_len);
+ rc = read_file(package_path, BPM_MAX_HTTP_BODY, &archive,
+ &archive_len);
if (rc)
return rc;
rc = bpm_pkg_load_info(package_path, &info);
@@ -379,20 +379,20 @@ static int push_package(const char *package_path, const char *raw_repository,
}
e.buf = manifest_body;
e.cap = BPM_MANIFEST_CAP;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schemaVersion", 2);
- shirudo_json_kv_string(&e, "mediaType", "application/vnd.oci.image.manifest.v1+json");
+ json_obj_open(&e);
+ json_kv_int(&e, "schemaVersion", 2);
+ json_kv_string(&e, "mediaType", "application/vnd.oci.image.manifest.v1+json");
bpm_oci_emit_descriptor(&e, "config", &config, NULL);
- shirudo_json_arr_open(&e, "layers");
+ json_arr_open(&e, "layers");
bpm_oci_emit_descriptor(&e, NULL, &layer, package_title);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_open_key(&e, "annotations");
- shirudo_json_kv_string(&e, "dev.shirudo.bpm.package.name", info.name);
- shirudo_json_kv_string(&e, "dev.shirudo.bpm.package.version", info.version);
- shirudo_json_kv_string(&e, "org.opencontainers.image.title", info.name);
- shirudo_json_kv_string(&e, "org.opencontainers.image.version", info.version);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_open_key(&e, "annotations");
+ json_kv_string(&e, "dev.shirudo.bpm.package.name", info.name);
+ json_kv_string(&e, "dev.shirudo.bpm.package.version", info.version);
+ json_kv_string(&e, "org.opencontainers.image.title", info.name);
+ json_kv_string(&e, "org.opencontainers.image.version", info.version);
+ json_obj_close(&e);
+ json_obj_close(&e);
if (e.err) {
xfree(manifest_body, BPM_MANIFEST_CAP);
rc = e.err;
@@ -439,20 +439,20 @@ static int push_package(const char *package_path, const char *raw_repository,
goto out;
}
e = (struct shirudo_json_emit){ .buf = key_manifest_body, .cap = BPM_MANIFEST_CAP };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schemaVersion", 2);
- shirudo_json_kv_string(&e, "mediaType", "application/vnd.oci.image.manifest.v1+json");
- shirudo_json_kv_string(&e, "artifactType", BPM_PUBLIC_KEY_ARTIFACT);
+ json_obj_open(&e);
+ json_kv_int(&e, "schemaVersion", 2);
+ json_kv_string(&e, "mediaType", "application/vnd.oci.image.manifest.v1+json");
+ json_kv_string(&e, "artifactType", BPM_PUBLIC_KEY_ARTIFACT);
bpm_oci_emit_descriptor(&e, "config", &key_config, NULL);
- shirudo_json_arr_open(&e, "layers");
+ json_arr_open(&e, "layers");
bpm_oci_emit_descriptor(&e, NULL, &key_layer, NULL);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_open_key(&e, "subject");
- shirudo_json_kv_string(&e, "mediaType", subject.media);
- shirudo_json_kv_string(&e, "digest", subject.digest);
- shirudo_json_kv_int(&e, "size", subject.size);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_open_key(&e, "subject");
+ json_kv_string(&e, "mediaType", subject.media);
+ json_kv_string(&e, "digest", subject.digest);
+ json_kv_int(&e, "size", subject.size);
+ json_obj_close(&e);
+ json_obj_close(&e);
if (e.err) {
rc = e.err;
goto out;
@@ -547,10 +547,10 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
fd = mkstemp(temporary);
if (fd < 0)
return -errno;
- rc = shirudo_write_all(fd, body, len);
+ rc = write_all(fd, body, len);
close(fd);
if (!rc)
- rc = shirudo_upatch_open(temporary, &u);
+ rc = upatch_open(temporary, &u);
unlink(temporary);
if (rc) {
pr_err("bpm tree append: %s is not a valid upatch", id);
@@ -558,10 +558,10 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
}
memcpy(name, u.hdr.name, SHIRUDO_UPATCH_NAME_MAX);
name[SHIRUDO_UPATCH_NAME_MAX] = '\0';
- shirudo_hex_encode(u.hdr.payload_sha256, 32, hex);
- if (strcmp(name, id) || shirudo_upatch_is_unload(&u) != unload)
+ hex_encode(u.hdr.payload_sha256, 32, hex);
+ if (strcmp(name, id) || upatch_is_unload(&u) != unload)
rc = -EKEYREJECTED;
- shirudo_upatch_close(&u);
+ upatch_close(&u);
if (rc) {
pr_err("bpm tree append: the %s artifact for %s is a %s directive named %s",
unload ? "unload" : "load", id,
@@ -585,18 +585,18 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
if (!manifest)
return -ENOMEM;
e = (struct shirudo_json_emit){ .buf = manifest, .cap = BPM_MANIFEST_CAP };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schemaVersion", 2);
- shirudo_json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
- shirudo_json_kv_string(&e, "artifactType", BPM_UPATCH_MEDIA);
+ json_obj_open(&e);
+ json_kv_int(&e, "schemaVersion", 2);
+ json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
+ json_kv_string(&e, "artifactType", BPM_UPATCH_MEDIA);
bpm_oci_emit_descriptor(&e, "config", &config, NULL);
- shirudo_json_arr_open(&e, "layers");
+ json_arr_open(&e, "layers");
bpm_oci_emit_descriptor(&e, NULL, &layer, NULL);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_open_key(&e, "annotations");
- shirudo_json_kv_string(&e, "org.opencontainers.image.title", title);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_open_key(&e, "annotations");
+ json_kv_string(&e, "org.opencontainers.image.title", title);
+ json_obj_close(&e);
+ json_obj_close(&e);
rc = e.err;
if (!rc)
rc = bpm_oci_put_manifest(c, repository, tag,
@@ -685,7 +685,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
}
unload = !strcmp(operation, "delete");
if (!key || !cert) {
- const char *keys_dir = shirudo_keys_dir_resolve(keys_dir_arg);
+ const char *keys_dir = keys_dir_resolve(keys_dir_arg);
if (!key) {
if (shirudo_key_path(key_path, sizeof(key_path), keys_dir,
@@ -787,9 +787,9 @@ static int cmd_bpm_tree_append(int argc, char **argv)
xfree(body, body_len + 1);
if (rc)
goto out;
- rc = shirudo_tree_operation_digest(op, op->operation_digest);
+ rc = tree_operation_digest(op, op->operation_digest);
if (!rc)
- rc = shirudo_tree_publication_append(&pub, op);
+ rc = tree_publication_append(&pub, op);
if (rc)
goto out;
pub.head_seq = op->seq;
@@ -800,7 +800,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
rc = -ENOENT;
goto out;
}
- rc = shirudo_tree_emit_publication(&pub, &payload, &payload_len);
+ rc = tree_emit_publication(&pub, &payload, &payload_len);
if (rc)
goto out;
rc = sign_detached(payload, payload_len, key, cert, &sig, &sig_len);
@@ -825,16 +825,16 @@ static int cmd_bpm_tree_append(int argc, char **argv)
goto out;
}
e = (struct shirudo_json_emit){ .buf = manifest, .cap = BPM_MANIFEST_CAP };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schemaVersion", 2);
- shirudo_json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
- shirudo_json_kv_string(&e, "artifactType", BPM_TREE_ARTIFACT);
+ json_obj_open(&e);
+ json_kv_int(&e, "schemaVersion", 2);
+ json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
+ json_kv_string(&e, "artifactType", BPM_TREE_ARTIFACT);
bpm_oci_emit_descriptor(&e, "config", &config, NULL);
- shirudo_json_arr_open(&e, "layers");
+ json_arr_open(&e, "layers");
bpm_oci_emit_descriptor(&e, NULL, &payload_layer, NULL);
bpm_oci_emit_descriptor(&e, NULL, &sig_layer, NULL);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
rc = e.err;
if (!rc)
rc = bpm_oci_put_manifest(&c, repository, reference,
@@ -851,7 +851,7 @@ out:
xfree(payload, payload_len);
if (op)
xfree(op, sizeof(*op));
- shirudo_tree_publication_free(&pub);
+ tree_publication_free(&pub);
bpm_build_spec_free(spec);
if (beefile)
xfree(beefile, len + 1);
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index df967f32..ca62f741 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -462,8 +462,8 @@ static int decoder_set_add(struct decoder_set *set,
pr_err("decoder source path '%s' is invalid", manifest->source);
return err;
}
- err = shirudo_read_file(path, 16u * 1024u * 1024u, &source,
- &source_len);
+ err = read_file(path, 16u * 1024u * 1024u, &source,
+ &source_len);
if (!err && !source_len)
err = -EINVAL;
if (err) {
@@ -889,8 +889,8 @@ static int build_prog_metadata(struct bpf_object *obj, __u32 nr_progs,
}
ut->prog_idx = i;
nr_uprobe_targets++;
- err = shirudo_elf_target_resolve(ut->path,
- md->progs[i].target, &ut->elf);
+ err = elf_target_resolve(ut->path,
+ md->progs[i].target, &ut->elf);
if (err) {
if (err == -ENOENT)
pr_err("uprobe.multi pattern '%s' matched no functions in %s (or the ELF has no GNU build ID)",
@@ -988,7 +988,7 @@ static int build_prog_metadata(struct bpf_object *obj, __u32 nr_progs,
xfree(seen_maps, (size_t)nr_progs * sizeof(*seen_maps));
for (i = 0; i < nr_uprobe_targets; i++) {
xstrfree(uprobe_targets[i].path);
- shirudo_elf_target_free(&uprobe_targets[i].elf);
+ elf_target_free(&uprobe_targets[i].elf);
}
xfree(uprobe_targets, (size_t)nr_progs * sizeof(*uprobe_targets));
return 0;
@@ -997,7 +997,7 @@ err_free:
xfree(seen_maps, (size_t)nr_progs * sizeof(*seen_maps));
for (i = 0; i < nr_uprobe_targets; i++) {
xstrfree(uprobe_targets[i].path);
- shirudo_elf_target_free(&uprobe_targets[i].elf);
+ elf_target_free(&uprobe_targets[i].elf);
}
xfree(uprobe_targets, (size_t)nr_progs * sizeof(*uprobe_targets));
xfree(md, md_alloc_len);
@@ -1167,9 +1167,9 @@ static int finalize_object(struct bpf_object *obj, const char *out_path,
sio.data_sz = signed_data_len;
sio.signature = sig_buf;
sio.signature_sz = SHIRUDO_MAX_SIG_SIZE;
- err = shirudo_cms_sign(&sio, pkey_path, cert_path);
+ err = cms_sign(&sio, pkey_path, cert_path);
if (err) {
- pr_err("shirudo_cms_sign: %d", err);
+ pr_err("cms_sign: %d", err);
goto out;
}
@@ -1194,15 +1194,15 @@ static int finalize_object(struct bpf_object *obj, const char *out_path,
pr_err("open %s: %s", out_path, strerror(errno));
goto out;
}
- err = shirudo_write_all(fd, &hdr, sizeof(hdr));
+ err = write_all(fd, &hdr, sizeof(hdr));
if (!err)
- err = shirudo_write_all(fd, opts.insns, opts.insns_sz);
+ err = write_all(fd, opts.insns, opts.insns_sz);
if (!err)
- err = shirudo_write_all(fd, sig_buf, sio.signature_sz);
+ err = write_all(fd, sig_buf, sio.signature_sz);
if (!err && data_len)
- err = shirudo_write_all(fd, signed_data, data_len);
+ err = write_all(fd, signed_data, data_len);
if (!err && write_meta_len)
- err = shirudo_write_all(fd, write_meta, write_meta_len);
+ err = write_all(fd, write_meta, write_meta_len);
if (!err && fsync(fd) != 0)
err = -errno;
close(fd);
@@ -1279,7 +1279,7 @@ int shirudo_build_package_unload(const char *upatch_name,
const char *pkey_path,
const char *cert_path)
{
- const struct shirudo_embedded_bpf *blob = shirudo_unload_blob();
+ const struct shirudo_embedded_bpf *blob = unload_blob();
struct shirudo_unload_params params = {};
struct bpf_object *obj;
struct bpf_map *rodata;
diff --git a/tools/shirudo-build/shirudo-build.c b/tools/shirudo-build/shirudo-build.c
index 98452ca6..925f369f 100644
--- a/tools/shirudo-build/shirudo-build.c
+++ b/tools/shirudo-build/shirudo-build.c
@@ -165,7 +165,7 @@ static int compile_to_temp(const char *source, const char *vmlinux_h,
int shirudo_build_check_keys(const char *pkey, const char *cert)
{
- int fd = shirudo_open_signing_key(pkey);
+ int fd = open_signing_key(pkey);
if (fd < 0) {
if (fd != -EPERM)
@@ -211,9 +211,9 @@ int main(int argc, char **argv)
int rc;
int i;
- shirudo_harden_stdio();
- shirudo_log_init();
- shirudo_harden_self();
+ harden_stdio();
+ log_init();
+ harden_self();
if (argc >= 2 && strcmp(argv[1], "bpm") == 0)
return shirudo_build_bpm(argc - 1, argv + 1);
@@ -263,7 +263,7 @@ int main(int argc, char **argv)
}
}
- keys_dir = shirudo_keys_dir_resolve(keys_dir_arg);
+ keys_dir = keys_dir_resolve(keys_dir_arg);
if (keys_dir) {
if (!pkey_explicit) {
@@ -298,8 +298,8 @@ int main(int argc, char **argv)
return 2;
}
if (payload_sha256_hex) {
- if (shirudo_hex_decode(payload_sha256_hex,
- payload_sha256, 32)) {
+ if (hex_decode(payload_sha256_hex,
+ payload_sha256, 32)) {
pr_err("--payload-sha256 must be 64 hex chars");
return 2;
}
@@ -317,10 +317,10 @@ int main(int argc, char **argv)
snprintf(archive, sizeof(archive), "%s/%s.upatch",
SHIRUDO_UPATCHES_DIR, unload_name);
- if (shirudo_upatch_open(archive, &u) == 0) {
+ if (upatch_open(archive, &u) == 0) {
memcpy(payload_sha256, u.hdr.payload_sha256,
sizeof(payload_sha256));
- shirudo_upatch_close(&u);
+ upatch_close(&u);
pr_info("--payload-sha256 derived from archive %s",
archive);
} else {
diff --git a/tools/shirudo-build/vouch.c b/tools/shirudo-build/vouch.c
index 34ed8b6c..ef59ea42 100644
--- a/tools/shirudo-build/vouch.c
+++ b/tools/shirudo-build/vouch.c
@@ -46,13 +46,13 @@ static int cert_algorithm_ok(const __u8 *der, size_t der_sz,
char name[64] = {};
int rc;
- rc = shirudo_cert_read_der(der, der_sz, &cert);
+ rc = cert_read_der(der, der_sz, &cert);
if (rc) {
pr_err("%s is not a certificate", what);
return rc;
}
- rc = shirudo_cert_key_algorithm(&cert, name, sizeof(name));
- shirudo_cert_free(&cert);
+ rc = cert_key_algorithm(&cert, name, sizeof(name));
+ cert_free(&cert);
if (rc || strcmp(name, "ML-DSA-87")) {
pr_err("%s is %s; shirudo accepts only ML-DSA-87", what,
rc ? "of an unknown algorithm" : name);
@@ -68,7 +68,7 @@ static int write_file(const char *path, const void *data, size_t len)
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0)
return -errno;
- rc = shirudo_write_all(fd, data, len);
+ rc = write_all(fd, data, len);
if (close(fd) && !rc)
rc = -errno;
if (rc)
@@ -125,7 +125,7 @@ int shirudo_build_keys_vouch(int argc, char **argv)
usage(stderr);
return 2;
}
- keys_dir = shirudo_keys_dir_resolve(keys_dir_arg);
+ keys_dir = keys_dir_resolve(keys_dir_arg);
if (keys_dir) {
if (!pkey_explicit) {
if (shirudo_key_path(pkey_path, sizeof(pkey_path),
@@ -156,12 +156,12 @@ int shirudo_build_keys_vouch(int argc, char **argv)
output = out_path;
}
- rc = shirudo_keys_read_der(input, &der, &der_sz);
+ rc = keys_read_der(input, &der, &der_sz);
if (rc) {
pr_err("keys vouch: read %s: %s", input, strerror(-rc));
return 1;
}
- rc = shirudo_keys_digest_der(der, der_sz, sha, fp);
+ rc = keys_digest_der(der, der_sz, sha, fp);
if (rc) {
pr_err("keys vouch: %s is not a certificate", input);
goto out;
@@ -169,25 +169,25 @@ int shirudo_build_keys_vouch(int argc, char **argv)
rc = cert_algorithm_ok(der, der_sz, input);
if (rc)
goto out;
- rc = shirudo_keys_read_der(cert, &own, &own_sz);
+ rc = keys_read_der(cert, &own, &own_sz);
if (rc) {
pr_err("keys vouch: read %s: %s", cert, strerror(-rc));
goto out;
}
- rc = shirudo_keys_digest_der(own, own_sz, sha, own_fp);
+ rc = keys_digest_der(own, own_sz, sha, own_fp);
if (rc) {
pr_err("keys vouch: %s is not a certificate", cert);
goto out;
}
- shirudo_hex_encode(fp, 32, fp_hex);
- shirudo_hex_encode(own_fp, 32, own_hex);
+ hex_encode(fp, 32, fp_hex);
+ hex_encode(own_fp, 32, own_hex);
if (!memcmp(fp, own_fp, 32)) {
pr_err("keys vouch: %s holds the signing key itself; a key "
"cannot vouch for its own certificate", input);
rc = -EINVAL;
goto out;
}
- rc = shirudo_keys_vouch_payload(der, der_sz, &payload, &payload_sz);
+ rc = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
if (rc)
goto out;
io.insns = payload;
@@ -198,7 +198,7 @@ int shirudo_build_keys_vouch(int argc, char **argv)
rc = -ENOMEM;
goto out;
}
- rc = shirudo_cms_sign(&io, pkey, cert);
+ rc = cms_sign(&io, pkey, cert);
if (rc) {
pr_err("keys vouch: sign: %s", strerror(-rc));
goto out;
diff --git a/util/attest.c b/util/attest.c
index 5f7e929c..875fd743 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -84,7 +84,7 @@ static int read_file_base64(const char *path, char **out, size_t *out_cap)
}
cap = 4 * ((len + 2) / 3) + 1;
*out = xmalloc(cap);
- rc = *out ? shirudo_base64_encode(raw, len, *out, cap) : -ENOMEM;
+ rc = *out ? base64_encode(raw, len, *out, cap) : -ENOMEM;
xfree(raw, LOG_MAX_BYTES + 1);
if (rc) {
xfree(*out, cap);
@@ -97,7 +97,7 @@ static int read_file_base64(const char *path, char **out, size_t *out_cap)
static int emit_line(const char *line, size_t len, void *ctx)
{
- shirudo_json_raw(ctx, line, len);
+ json_raw(ctx, line, len);
return 0;
}
@@ -110,8 +110,8 @@ static void emit_hex(struct shirudo_json_emit *e, const char *key,
e->err = -E2BIG;
return;
}
- shirudo_hex_encode(data, len, hex);
- shirudo_json_kv_string(e, key, hex);
+ hex_encode(data, len, hex);
+ json_kv_string(e, key, hex);
}
/* A quote is accepted only when it covers the PCR values read beside it. */
@@ -123,32 +123,32 @@ static bool quote_covers(const struct shirudo_tpm_attestation *quote,
__u8 digest[32];
__u32 i;
- if (shirudo_tpm_attest_parse(quote->attest, quote->attest_len, &a) ||
+ if (tpm_attest_parse(quote->attest, quote->attest_len, &a) ||
a.type != SHIRUDO_TPM_ST_ATTEST_QUOTE || a.pcr_mask != mask)
return false;
- if (shirudo_sha256_init(&ctx) != 0)
+ if (sha256_init(&ctx) != 0)
return false;
for (i = 0; i < 24; i++) {
if ((mask & (1u << i)) &&
- shirudo_sha256_update(&ctx, values[i], 32) != 0) {
- shirudo_sha256_free(&ctx);
+ sha256_update(&ctx, values[i], 32) != 0) {
+ sha256_free(&ctx);
return false;
}
}
- if (shirudo_sha256_final(&ctx, digest) != 0)
+ if (sha256_final(&ctx, digest) != 0)
return false;
- return shirudo_ct_eq(digest, a.pcr_digest, 32);
+ return ct_eq(digest, a.pcr_digest, 32);
}
-int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
- __u32 pcr_mask,
- const struct shirudo_attest_challenge *challenge,
- char **out, size_t *len, size_t *cap)
+int attest_evidence(const __u8 *nonce, size_t nonce_len,
+ __u32 pcr_mask,
+ const struct shirudo_attest_challenge *challenge,
+ char **out, size_t *len, size_t *cap)
{
struct shirudo_tpm_key ak = { .handle = 0 }, ek = { .handle = 0 };
struct shirudo_tpm_key ak_copy = {}, ek_copy = {};
struct shirudo_tpm_attestation quote = {}, certify = {};
- struct shirudo_tpm_nv_info nv;
+ struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
struct shirudo_json_emit e;
__u8 values[24][32] = {};
@@ -169,10 +169,10 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
(pcr_mask & ~0x00FFFFFFu))
return -EINVAL;
- rc = shirudo_tpm_open(&tpm);
+ rc = tpm_open(&tpm);
if (rc)
return -ENODEV;
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
if (!nv.defined || !nv.written) {
@@ -181,22 +181,22 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = -ENODEV;
goto out;
}
- rc = shirudo_tpm_nv_read(tpm, SHIRUDO_NV_INDEX, reg);
+ rc = tpm_nv_read(tpm, SHIRUDO_NV_INDEX, reg);
if (rc)
goto out;
- rc = shirudo_tpm_ak_create(tpm, &ak);
+ rc = tpm_ak_create(tpm, &ak);
if (rc)
goto out;
for (attempt = 0; attempt < QUOTE_ATTEMPTS; attempt++) {
for (i = 0; i < 24; i++) {
if (!(pcr_mask & (1u << i)))
continue;
- rc = shirudo_tpm_pcr_read(tpm, i, values[i]);
+ rc = tpm_pcr_read(tpm, i, values[i]);
if (rc)
goto out;
}
- rc = shirudo_tpm_quote(tpm, &ak, nonce, nonce_len, pcr_mask,
- &quote);
+ rc = tpm_quote(tpm, &ak, nonce, nonce_len, pcr_mask,
+ &quote);
if (rc)
goto out;
if (quote_covers(&quote, pcr_mask, values))
@@ -207,8 +207,8 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = -EAGAIN;
goto out;
}
- rc = shirudo_tpm_nv_certify(tpm, &ak, SHIRUDO_NV_INDEX, nonce,
- nonce_len, &certify);
+ rc = tpm_nv_certify(tpm, &ak, SHIRUDO_NV_INDEX, nonce,
+ nonce_len, &certify);
if (rc)
goto out;
ek_cert = xmalloc(EK_CERT_MAX);
@@ -216,12 +216,12 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = -ENOMEM;
goto out;
}
- if (shirudo_tpm_ek_certificate(tpm, ek_cert, EK_CERT_MAX, &ek_cert_len,
- &ek_cert_rsa) == 0) {
+ if (tpm_ek_certificate(tpm, ek_cert, EK_CERT_MAX, &ek_cert_len,
+ &ek_cert_rsa) == 0) {
ek_b64_cap = 4 * ((ek_cert_len + 2) / 3) + 1;
ek_b64 = xmalloc(ek_b64_cap);
- if (!ek_b64 || shirudo_base64_encode(ek_cert, ek_cert_len, ek_b64,
- ek_b64_cap)) {
+ if (!ek_b64 || base64_encode(ek_cert, ek_cert_len, ek_b64,
+ ek_b64_cap)) {
xfree(ek_b64, ek_b64_cap);
ek_b64 = NULL;
ek_b64_cap = 0;
@@ -233,7 +233,7 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
* ECC key, which the operator pins by name.
*/
ek_rsa = challenge ? challenge->ek_rsa : ek_cert_rsa;
- rc = shirudo_tpm_ek_create(tpm, ek_rsa, &ek);
+ rc = tpm_ek_create(tpm, ek_rsa, &ek);
if (rc)
goto out;
if (challenge) {
@@ -244,13 +244,13 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = -EKEYREJECTED;
goto out;
}
- rc = shirudo_tpm_activate_credential(tpm, &ak, &ek,
- challenge->blob,
- challenge->blob_len,
- challenge->secret,
- challenge->secret_len,
- cred, sizeof(cred),
- &cred_len);
+ rc = tpm_activate_credential(tpm, &ak, &ek,
+ challenge->blob,
+ challenge->blob_len,
+ challenge->secret,
+ challenge->secret_len,
+ cred, sizeof(cred),
+ &cred_len);
if (rc) {
pr_err("attest: the TPM refused the challenge: not "
"made for this attestation key under this "
@@ -261,15 +261,15 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
/* The keys are flushed before the file work; keep their public parts. */
memcpy(&ak_copy, &ak, sizeof(ak_copy));
memcpy(&ek_copy, &ek, sizeof(ek_copy));
- shirudo_tpm_key_flush(tpm, &ek);
- shirudo_tpm_key_flush(tpm, &ak);
- shirudo_tpm_close(tpm);
+ tpm_key_flush(tpm, &ek);
+ tpm_key_flush(tpm, &ak);
+ tpm_close(tpm);
tpm = NULL;
read_file_base64(FIRMWARE_LOG_PATH, &fw, &fw_cap);
read_file_base64(SYSTEMD_LOG_PATH, &sd, &sd_cap);
need = 64 * 1024 + fw_cap + sd_cap + ek_b64_cap;
- if (stat(shirudo_eventlog_path(), &st) == 0 && st.st_size > 0)
+ if (stat(eventlog_path(), &st) == 0 && st.st_size > 0)
need += 2 * (size_t)st.st_size;
if (need > SHIRUDO_JSON_MAX_BYTES)
need = SHIRUDO_JSON_MAX_BYTES;
@@ -280,77 +280,77 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
}
*cap = need;
- shirudo_eventlog_timestamp(ts, sizeof(ts));
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_timestamp(ts, sizeof(ts));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
- shirudo_hex_encode(nonce, nonce_len, nonce_hex);
+ hex_encode(nonce, nonce_len, nonce_hex);
e = (struct shirudo_json_emit){ .buf = *out, .cap = need };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "kind", "shirudo-attestation");
- shirudo_json_kv_string(&e, "version_id", shirudo_version_id);
- shirudo_json_kv_string(&e, "ts", ts);
- shirudo_json_kv_string(&e, "boot_id", boot_id);
- shirudo_json_kv_string(&e, "nonce", nonce_hex);
- shirudo_json_kv_string(&e, "pcr_bank", "sha256");
- shirudo_json_kv_int(&e, "pcr_mask", pcr_mask);
- shirudo_json_arr_open(&e, "pcrs");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "kind", "shirudo-attestation");
+ json_kv_string(&e, "version_id", shirudo_version_id);
+ json_kv_string(&e, "ts", ts);
+ json_kv_string(&e, "boot_id", boot_id);
+ json_kv_string(&e, "nonce", nonce_hex);
+ json_kv_string(&e, "pcr_bank", "sha256");
+ json_kv_int(&e, "pcr_mask", pcr_mask);
+ json_arr_open(&e, "pcrs");
for (i = 0; i < 24; i++) {
if (!(pcr_mask & (1u << i)))
continue;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "index", i);
+ json_obj_open(&e);
+ json_kv_int(&e, "index", i);
emit_hex(&e, "value", values[i], 32);
- shirudo_json_obj_close(&e);
+ json_obj_close(&e);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_open_key(&e, "ak");
+ json_arr_close(&e);
+ json_obj_open_key(&e, "ak");
emit_hex(&e, "public", ak_copy.public, ak_copy.public_len);
emit_hex(&e, "name", ak_copy.name, ak_copy.name_len);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_open_key(&e, "ek");
- shirudo_json_kv_string(&e, "type", ek_rsa ? "rsa" : "ecc");
+ json_obj_close(&e);
+ json_obj_open_key(&e, "ek");
+ json_kv_string(&e, "type", ek_rsa ? "rsa" : "ecc");
emit_hex(&e, "public", ek_copy.public, ek_copy.public_len);
emit_hex(&e, "name", ek_copy.name, ek_copy.name_len);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_open_key(&e, "quote");
+ json_obj_close(&e);
+ json_obj_open_key(&e, "quote");
emit_hex(&e, "attest", quote.attest, quote.attest_len);
emit_hex(&e, "signature", quote.signature, quote.signature_len);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_open_key(&e, "register");
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
+ json_obj_close(&e);
+ json_obj_open_key(&e, "register");
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_int(&e, "pcr", SHIRUDO_CHAIN_PCR);
emit_hex(&e, "name", nv.name, nv.name_len);
emit_hex(&e, "value", reg, sizeof(reg));
emit_hex(&e, "attest", certify.attest, certify.attest_len);
emit_hex(&e, "signature", certify.signature, certify.signature_len);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "eventlog");
- shirudo_eventlog_boot_lines(emit_line, &e);
- shirudo_json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_open(&e, "eventlog");
+ eventlog_boot_lines(emit_line, &e);
+ json_arr_close(&e);
if (cred_len) {
- shirudo_json_obj_open_key(&e, "credential");
+ json_obj_open_key(&e, "credential");
emit_hex(&e, "value", cred, cred_len);
- shirudo_json_obj_close(&e);
+ json_obj_close(&e);
} else {
- shirudo_json_kv_null(&e, "credential");
+ json_kv_null(&e, "credential");
}
if (ek_b64)
- shirudo_json_kv_string(&e, "ek_certificate", ek_b64);
+ json_kv_string(&e, "ek_certificate", ek_b64);
else
- shirudo_json_kv_null(&e, "ek_certificate");
- shirudo_json_obj_open_key(&e, "logs");
+ json_kv_null(&e, "ek_certificate");
+ json_obj_open_key(&e, "logs");
if (fw)
- shirudo_json_kv_string(&e, "firmware", fw);
+ json_kv_string(&e, "firmware", fw);
else
- shirudo_json_kv_null(&e, "firmware");
+ json_kv_null(&e, "firmware");
if (sd)
- shirudo_json_kv_string(&e, "systemd", sd);
+ json_kv_string(&e, "systemd", sd);
else
- shirudo_json_kv_null(&e, "systemd");
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_kv_null(&e, "systemd");
+ json_obj_close(&e);
+ json_obj_close(&e);
if (e.err) {
rc = e.err;
goto out;
@@ -360,9 +360,9 @@ int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = 0;
out:
if (tpm) {
- shirudo_tpm_key_flush(tpm, &ek);
- shirudo_tpm_key_flush(tpm, &ak);
- shirudo_tpm_close(tpm);
+ tpm_key_flush(tpm, &ek);
+ tpm_key_flush(tpm, &ak);
+ tpm_close(tpm);
}
xfree(ek_cert, ek_cert ? EK_CERT_MAX : 0);
xfree(ek_b64, ek_b64_cap);
@@ -454,7 +454,7 @@ static int on_pcr(void *ctx)
struct parse *p = ctx;
if (p->pcr_index < 0 || p->pcr_index >= 24 ||
- shirudo_hex_decode(p->pcr_value_hex, p->pcrs[p->pcr_index], 32))
+ hex_decode(p->pcr_value_hex, p->pcrs[p->pcr_index], 32))
return -EINVAL;
p->pcr_have |= 1u << p->pcr_index;
return 0;
@@ -470,7 +470,7 @@ static int on_record(void *ctx)
r = &p->recs[p->n_recs];
memset(r, 0, sizeof(*r));
snprintf(r->type, sizeof(r->type), "%s", p->type);
- if (shirudo_hex_decode(p->digest_hex, r->digest, 32))
+ if (hex_decode(p->digest_hex, r->digest, 32))
return -EINVAL;
if (!strcmp(p->type, "init")) {
struct init_record *in = &p->init;
@@ -482,14 +482,14 @@ static int on_record(void *ctx)
p->rec_phase_pcr <= p->rec_pcr || p->rec_phase_pcr >= 24 ||
p->rec_reset > UINT32_MAX ||
strlen(p->nv_name_hex) != 2 * SHIRUDO_TPM_NAME_LEN ||
- shirudo_hex_decode(p->pcr_before_hex, in->pcr_before, 32) ||
- shirudo_hex_decode(p->phase_before_hex, in->phase_before,
- 32) ||
- shirudo_hex_decode(p->nv_name_hex, in->name,
- SHIRUDO_TPM_NAME_LEN) ||
- shirudo_hex_decode(p->anchor_digest_hex, in->anchor_digest,
- 32) ||
- shirudo_hex_decode(p->chain_hex, in->chain, 32))
+ hex_decode(p->pcr_before_hex, in->pcr_before, 32) ||
+ hex_decode(p->phase_before_hex, in->phase_before,
+ 32) ||
+ hex_decode(p->nv_name_hex, in->name,
+ SHIRUDO_TPM_NAME_LEN) ||
+ hex_decode(p->anchor_digest_hex, in->anchor_digest,
+ 32) ||
+ hex_decode(p->chain_hex, in->chain, 32))
return -EINVAL;
memcpy(in->digest, r->digest, 32);
in->pcr = (__u32)p->rec_pcr;
@@ -606,7 +606,7 @@ static int hex_bytes(const char *hex, __u8 *out, size_t cap, size_t *len)
if (n & 1 || n / 2 > cap)
return -EINVAL;
*len = n / 2;
- return shirudo_hex_decode(hex, out, n / 2);
+ return hex_decode(hex, out, n / 2);
}
static int check_signed(struct reporter *rep, const char *what,
@@ -625,30 +625,30 @@ static int check_signed(struct reporter *rep, const char *what,
if (hex_bytes(attest_hex, attest, attest_cap, attest_len) ||
hex_bytes(sig_hex, sig, sizeof(sig), &sig_len))
return -EINVAL;
- if (shirudo_tpm_attest_parse(attest, *attest_len, parsed)) {
+ if (tpm_attest_parse(attest, *attest_len, parsed)) {
say(rep, false, "%s: attestation structure unparseable", what);
return -EKEYREJECTED;
}
- if (shirudo_tpm_ecdsa_signature_parse(sig, sig_len, r, s)) {
+ if (tpm_ecdsa_signature_parse(sig, sig_len, r, s)) {
say(rep, false, "%s: signature structure unparseable", what);
return -EKEYREJECTED;
}
shirudo_sha256(attest, *attest_len, digest);
- rc = shirudo_ecdsa_p256_verify(ak->x, ak->y, digest, r, s);
+ rc = ecdsa_p256_verify(ak->x, ak->y, digest, r, s);
say(rep, rc == 0, "%s: ECDSA signature by the attestation key", what);
- shirudo_tpm_qualified_name(SHIRUDO_TPM_RH_ENDORSEMENT, ak_name, qn);
+ tpm_qualified_name(SHIRUDO_TPM_RH_ENDORSEMENT, ak_name, qn);
say(rep, parsed->signer_len == SHIRUDO_TPM_NAME_LEN &&
- shirudo_ct_eq(parsed->signer, qn, SHIRUDO_TPM_NAME_LEN),
+ ct_eq(parsed->signer, qn, SHIRUDO_TPM_NAME_LEN),
"%s: signed by the key as an endorsement primary", what);
say(rep, parsed->extra_len == nonce_len &&
- (nonce_len == 0 || shirudo_ct_eq(parsed->extra, nonce, nonce_len)),
+ (nonce_len == 0 || ct_eq(parsed->extra, nonce, nonce_len)),
"%s: carries the nonce", what);
return 0;
}
-int shirudo_attest_verify(const char *evidence, size_t len,
- const struct shirudo_attest_expect *expect,
- char *report, size_t report_cap)
+int attest_verify(const char *evidence, size_t len,
+ const struct shirudo_attest_expect *expect,
+ char *report, size_t report_cap)
{
struct reporter rep = { .buf = report, .cap = report_cap };
struct shirudo_tpm_attest quote = {}, certify = {};
@@ -803,7 +803,7 @@ int shirudo_attest_verify(const char *evidence, size_t len,
cred_sub, ARRAY_SIZE(cred_sub) },
};
- rc = shirudo_json_parse(evidence, len, top, ARRAY_SIZE(top));
+ rc = json_parse(evidence, len, top, ARRAY_SIZE(top));
if (rc || !top[0].seen || !top[1].seen || !top[2].seen ||
!top[3].seen || !top[4].seen || !top[5].seen ||
!top[6].seen) {
@@ -821,7 +821,7 @@ int shirudo_attest_verify(const char *evidence, size_t len,
}
say(&rep, expect->nonce_len == nonce_len &&
(nonce_len == 0 ||
- shirudo_ct_eq(nonce, expect->nonce, nonce_len)),
+ ct_eq(nonce, expect->nonce, nonce_len)),
"nonce matches the request");
if (hex_bytes(p->ak_public_hex, ak_public, sizeof(ak_public),
@@ -831,7 +831,7 @@ int shirudo_attest_verify(const char *evidence, size_t len,
rc = -EINVAL;
goto out;
}
- if (shirudo_tpm_ecc_public_parse(ak_public, ak_public_len, &ak_pub)) {
+ if (tpm_ecc_public_parse(ak_public, ak_public_len, &ak_pub)) {
say(&rep, false, "attestation key: public area is not a "
"P-256 ECDSA key");
rc = -EKEYREJECTED;
@@ -842,13 +842,13 @@ int shirudo_attest_verify(const char *evidence, size_t len,
{
__u8 computed[SHIRUDO_TPM_NAME_LEN];
- shirudo_tpm_object_name(ak_public, ak_public_len, computed);
- say(&rep, shirudo_ct_eq(computed, ak_name, sizeof(computed)),
+ tpm_object_name(ak_public, ak_public_len, computed);
+ say(&rep, ct_eq(computed, ak_name, sizeof(computed)),
"attestation key: name matches its public area");
}
if (expect->have_ak_name)
- say(&rep, shirudo_ct_eq(ak_name, expect->ak_name,
- SHIRUDO_TPM_NAME_LEN),
+ say(&rep, ct_eq(ak_name, expect->ak_name,
+ SHIRUDO_TPM_NAME_LEN),
"attestation key: the pinned key");
else
note(&rep, "attestation key not pinned: name %s",
@@ -868,15 +868,15 @@ int shirudo_attest_verify(const char *evidence, size_t len,
rc = -EINVAL;
goto out;
}
- parsed = shirudo_tpm_public_parse(ek_public, ek_public_len,
- &ek_pub) == 0;
- shirudo_tpm_object_name(ek_public, ek_public_len, computed);
- say(&rep, parsed && shirudo_ct_eq(computed, ek_name,
- SHIRUDO_TPM_NAME_LEN),
+ parsed = tpm_public_parse(ek_public, ek_public_len,
+ &ek_pub) == 0;
+ tpm_object_name(ek_public, ek_public_len, computed);
+ say(&rep, parsed && ct_eq(computed, ek_name,
+ SHIRUDO_TPM_NAME_LEN),
"endorsement key: name matches its public area");
say(&rep, parsed && ek_pub.attrs == SHIRUDO_TPM_EK_ATTRS &&
ek_pub.policy_len == 32 &&
- shirudo_ct_eq(ek_pub.policy, shirudo_tpm_ek_policy, 32),
+ ct_eq(ek_pub.policy, shirudo_tpm_ek_policy, 32),
"endorsement key: TCG default template under the "
"endorsement policy");
} else {
@@ -889,7 +889,7 @@ int shirudo_attest_verify(const char *evidence, size_t len,
say(&rep, have_ek &&
!hex_bytes(p->ek_name_hex, ek_name, sizeof(ek_name), &n) &&
n == SHIRUDO_TPM_NAME_LEN &&
- shirudo_ct_eq(ek_name, expect->ek_name, SHIRUDO_TPM_NAME_LEN),
+ ct_eq(ek_name, expect->ek_name, SHIRUDO_TPM_NAME_LEN),
"endorsement key: the pinned key");
}
if (have_cred && hex_bytes(p->cred_hex, cred, sizeof(cred), &cred_len)) {
@@ -898,8 +898,8 @@ int shirudo_attest_verify(const char *evidence, size_t len,
}
if (expect->have_credential)
say(&rep, have_cred && cred_len == SHIRUDO_TPM_CREDENTIAL_LEN &&
- shirudo_ct_eq(cred, expect->credential,
- SHIRUDO_TPM_CREDENTIAL_LEN),
+ ct_eq(cred, expect->credential,
+ SHIRUDO_TPM_CREDENTIAL_LEN),
"attestation key: activated the credential made for it "
"under the endorsement key");
else if (have_cred)
@@ -923,16 +923,16 @@ int shirudo_attest_verify(const char *evidence, size_t len,
say(&rep, complete,
"quote: covers the PCRs the document lists");
- if (complete && shirudo_sha256_init(&ctx) == 0) {
+ if (complete && sha256_init(&ctx) == 0) {
for (bit = 0; bit < 24; bit++) {
if (quote.pcr_mask & (1u << bit))
- shirudo_sha256_update(&ctx,
- p->pcrs[bit], 32);
+ sha256_update(&ctx,
+ p->pcrs[bit], 32);
}
- shirudo_sha256_final(&ctx, digest);
+ sha256_final(&ctx, digest);
}
vouched = complete &&
- shirudo_ct_eq(digest, quote.pcr_digest, 32);
+ ct_eq(digest, quote.pcr_digest, 32);
say(&rep, vouched,
"quote: PCR digest matches the listed values");
if (!vouched)
@@ -960,12 +960,12 @@ int shirudo_attest_verify(const char *evidence, size_t len,
if (rc == 0) {
say(&rep, certify.type == SHIRUDO_TPM_ST_ATTEST_NV &&
certify.index_name_len == SHIRUDO_TPM_NAME_LEN &&
- shirudo_ct_eq(certify.index_name, reg_name,
- SHIRUDO_TPM_NAME_LEN),
+ ct_eq(certify.index_name, reg_name,
+ SHIRUDO_TPM_NAME_LEN),
"register: certification names the listed index");
say(&rep, certify.type == SHIRUDO_TPM_ST_ATTEST_NV &&
certify.offset == 0 && certify.nv_len == 32 &&
- shirudo_ct_eq(certify.nv_data, reg_value, 32),
+ ct_eq(certify.nv_data, reg_value, 32),
"register: certified contents match the listed value");
}
if (qrc == 0 && crc == 0)
@@ -986,15 +986,15 @@ int shirudo_attest_verify(const char *evidence, size_t len,
}
memcpy(bind, p->init.pcr_before, 32);
memcpy(bind + 32, p->init.phase_before, 32);
- shirudo_tpm_register_policy((1u << p->init.pcr) |
- (1u << p->init.phase_pcr), bind, 2,
- branch_written, branch_init, policy);
- shirudo_tpm_nv_name(reg_index,
- SHIRUDO_TPM_REGISTER_ATTRS | SHIRUDO_TPM_NV_WRITTEN,
- policy, 32, expected_name);
+ tpm_register_policy((1u << p->init.pcr) |
+ (1u << p->init.phase_pcr), bind, 2,
+ branch_written, branch_init, policy);
+ tpm_nv_name(reg_index,
+ SHIRUDO_TPM_REGISTER_ATTRS | SHIRUDO_TPM_NV_WRITTEN,
+ policy, 32, expected_name);
say(&rep, (__u32)p->reg_pcr == p->init.pcr &&
- shirudo_ct_eq(expected_name, reg_name, SHIRUDO_TPM_NAME_LEN) &&
- shirudo_ct_eq(expected_name, p->init.name, SHIRUDO_TPM_NAME_LEN),
+ ct_eq(expected_name, reg_name, SHIRUDO_TPM_NAME_LEN) &&
+ ct_eq(expected_name, p->init.name, SHIRUDO_TPM_NAME_LEN),
"register: public area is bound to PCRs %u and %u as recorded",
p->init.pcr, p->init.phase_pcr);
for (bit = 0; bit < 24; bit++) {
@@ -1004,8 +1004,8 @@ int shirudo_attest_verify(const char *evidence, size_t len,
continue;
held = bit == p->init.pcr ? p->init.pcr_before :
bit == p->init.phase_pcr ? p->init.phase_before : NULL;
- say(&rep, held && shirudo_ct_eq(held, expect->bind_values[bit],
- 32),
+ say(&rep, held && ct_eq(held, expect->bind_values[bit],
+ 32),
"binding: PCR %u held the expected value", bit);
}
if (expect->require_initrd)
@@ -1029,27 +1029,27 @@ int shirudo_attest_verify(const char *evidence, size_t len,
"count");
for (i = 0; i < p->n_recs; i++) {
- shirudo_chain_fold(chain, p->recs[i].digest);
+ chain_fold(chain, p->recs[i].digest);
if (i)
runtime++;
}
- say(&rep, shirudo_ct_eq(chain, reg_value, 32),
+ say(&rep, ct_eq(chain, reg_value, 32),
"eventlog: %zu record%s replay to the certified value", p->n_recs,
p->n_recs == 1 ? "" : "s");
{
char anchor[SHIRUDO_CHAIN_ANCHOR_MAX];
- shirudo_chain_anchor(p->init.name, anchor, sizeof(anchor));
+ chain_anchor(p->init.name, anchor, sizeof(anchor));
shirudo_sha256(anchor, strlen(anchor), anchor_digest);
- say(&rep, shirudo_ct_eq(anchor_digest, p->init.anchor_digest,
- 32),
+ say(&rep, ct_eq(anchor_digest, p->init.anchor_digest,
+ 32),
"anchor: record digest matches the index name");
memcpy(pcr_expected, p->init.pcr_before, 32);
- shirudo_chain_fold(pcr_expected, anchor_digest);
+ chain_fold(pcr_expected, anchor_digest);
if (p->pcr_have & (1u << p->init.pcr)) {
- bool exact = shirudo_ct_eq(pcr_expected,
- p->pcrs[p->init.pcr], 32);
+ bool exact = ct_eq(pcr_expected,
+ p->pcrs[p->init.pcr], 32);
if (exact || expect->strict_anchor)
say(&rep, exact, "anchor: PCR %u equals the "
@@ -1066,18 +1066,18 @@ int shirudo_attest_verify(const char *evidence, size_t len,
}
if (expect->have_init)
- say(&rep, shirudo_ct_eq(p->init.digest, expect->init_event, 32),
+ say(&rep, ct_eq(p->init.digest, expect->init_event, 32),
"state: init event covers the expected certificate, set "
"and tree root");
if (expect->have_chain) {
- say(&rep, shirudo_ct_eq(reg_value, expect->chain, 32),
+ say(&rep, ct_eq(reg_value, expect->chain, 32),
"state: register equals the expected value");
} else if (expect->have_init) {
__u8 predicted[32] = {};
- shirudo_chain_fold(predicted, expect->init_event);
+ chain_fold(predicted, expect->init_event);
if (runtime == 0)
- say(&rep, shirudo_ct_eq(reg_value, predicted, 32),
+ say(&rep, ct_eq(reg_value, predicted, 32),
"state: register equals the value predicted for "
"the set at boot");
else
@@ -1095,7 +1095,7 @@ int shirudo_attest_verify(const char *evidence, size_t len,
if (!(expect->pcr_expect_mask & (1u << bit)))
continue;
say(&rep, (p->pcr_have & (1u << bit)) &&
- shirudo_ct_eq(p->pcrs[bit], expect->pcrs[bit], 32),
+ ct_eq(p->pcrs[bit], expect->pcrs[bit], 32),
"PCR %u matches the expected value", bit);
}
rc = rep.failed ? -EKEYREJECTED : 0;
@@ -1105,8 +1105,8 @@ out:
return rc;
}
-int shirudo_attest_challenge_read(const char *path,
- struct shirudo_attest_challenge *out)
+int attest_challenge_read(const char *path,
+ struct shirudo_attest_challenge *out)
{
char blob_hex[2 * SHIRUDO_TPM_ID_OBJECT_LEN + 1], secret_hex[2 * 256 + 1];
char ak_hex[2 * SHIRUDO_TPM_NAME_LEN + 1], kind[32], type[8];
@@ -1136,10 +1136,10 @@ int shirudo_attest_challenge_read(const char *path,
ak_hex[0] = '\0';
blob_hex[0] = '\0';
secret_hex[0] = '\0';
- rc = shirudo_read_file(path, SHIRUDO_ATTEST_CHALLENGE_MAX, &doc, &len);
+ rc = read_file(path, SHIRUDO_ATTEST_CHALLENGE_MAX, &doc, &len);
if (rc)
return rc;
- rc = shirudo_json_parse(doc, len, top, ARRAY_SIZE(top));
+ rc = json_parse(doc, len, top, ARRAY_SIZE(top));
xfree(doc, len + 1);
if (rc || !top[0].seen || strcmp(kind, "shirudo-credential") ||
!ek_sub[0].seen || !top[2].seen || !top[3].seen || !top[4].seen)
@@ -1159,24 +1159,24 @@ int shirudo_attest_challenge_read(const char *path,
}
/* The certificate's key must be the endorsement key of the evidence. */
-static bool cert_describes(const struct shirudo_cert_pubkey *key,
+static bool cert_describes(const struct cert_pubkey *key,
const struct shirudo_tpm_public *pub)
{
if (key->rsa != (pub->type == SHIRUDO_TPM_ALG_RSA))
return false;
if (key->rsa)
return key->n_len == pub->n_len &&
- shirudo_ct_eq(key->n, pub->n, pub->n_len) &&
+ ct_eq(key->n, pub->n, pub->n_len) &&
key->e == (pub->rsa_exponent ? pub->rsa_exponent : 65537);
- return shirudo_ct_eq(key->x, pub->x, 32) &&
- shirudo_ct_eq(key->y, pub->y, 32);
+ return ct_eq(key->x, pub->x, 32) &&
+ ct_eq(key->y, pub->y, 32);
}
-int shirudo_attest_challenge_make(const char *evidence, size_t len,
- const struct shirudo_attest_challenge_policy *pol,
- __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
- char **out, size_t *out_len, size_t *cap,
- char *report, size_t report_cap)
+int attest_challenge_make(const char *evidence, size_t len,
+ const struct shirudo_attest_challenge_policy *pol,
+ __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
+ char **out, size_t *out_len, size_t *cap,
+ char *report, size_t report_cap)
{
const char *ek_ca = pol->ek_ca;
bool vouched = pol->ek_name || pol->trust_presented;
@@ -1188,7 +1188,7 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
__u8 ek_public[SHIRUDO_TPM_PUBLIC_MAX], computed[SHIRUDO_TPM_NAME_LEN];
__u8 seed[32], z[32], eph_x[32], eph_y[32], secret[256];
__u8 blob[SHIRUDO_TPM_ID_OBJECT_LEN], *der = NULL;
- struct shirudo_cert_pubkey cert_key;
+ struct cert_pubkey cert_key;
struct shirudo_tpm_public pub;
struct shirudo_cert cert = {};
struct shirudo_json_emit e;
@@ -1230,7 +1230,7 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
ek_type[0] = '\0';
ek_public_hex[0] = '\0';
ek_name_hex[0] = '\0';
- if (shirudo_json_parse(evidence, len, top, ARRAY_SIZE(top)) ||
+ if (json_parse(evidence, len, top, ARRAY_SIZE(top)) ||
!ak_sub[0].seen || !ek_sub[0].seen || !ek_sub[1].seen ||
!ek_sub[2].seen ||
hex_bytes(ak_hex, ak_name, sizeof(ak_name), &ak_len) ||
@@ -1246,8 +1246,8 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
rsa = false;
else
goto out;
- if (shirudo_tpm_public_parse(ek_public, ek_public_len, &pub) ||
- (pub.type == SHIRUDO_TPM_ALG_RSA) != rsa)
+ if (tpm_public_parse(ek_public, ek_public_len, &pub) ||
+ pub.type != (rsa ? SHIRUDO_TPM_ALG_RSA : SHIRUDO_TPM_ALG_ECC))
goto out;
/*
@@ -1255,20 +1255,20 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
* operator enrolled, not for whatever the document names.
*/
if (pol->ak_name)
- say(&rep, shirudo_ct_eq(ak_name, pol->ak_name,
- SHIRUDO_TPM_NAME_LEN),
+ say(&rep, ct_eq(ak_name, pol->ak_name,
+ SHIRUDO_TPM_NAME_LEN),
"attestation key: the pinned key");
if (pol->ek_name)
- say(&rep, shirudo_ct_eq(ek_name, pol->ek_name,
- SHIRUDO_TPM_NAME_LEN),
+ say(&rep, ct_eq(ek_name, pol->ek_name,
+ SHIRUDO_TPM_NAME_LEN),
"endorsement key: the pinned key");
/* The key must be an endorsement key, not any decryption key. */
- shirudo_tpm_object_name(ek_public, ek_public_len, computed);
- say(&rep, shirudo_ct_eq(computed, ek_name, SHIRUDO_TPM_NAME_LEN),
+ tpm_object_name(ek_public, ek_public_len, computed);
+ say(&rep, ct_eq(computed, ek_name, SHIRUDO_TPM_NAME_LEN),
"endorsement key: name matches its public area");
say(&rep, pub.attrs == SHIRUDO_TPM_EK_ATTRS && pub.policy_len == 32 &&
- shirudo_ct_eq(pub.policy, shirudo_tpm_ek_policy, 32),
+ ct_eq(pub.policy, shirudo_tpm_ek_policy, 32),
"endorsement key: TCG default template under the endorsement "
"policy");
if (top[2].seen) {
@@ -1277,10 +1277,10 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
rc = -ENOMEM;
goto out;
}
- if (shirudo_base64_decode(cert_b64, strlen(cert_b64), der,
- EK_CERT_MAX, &der_len) ||
- shirudo_cert_read_der(der, der_len, &cert) ||
- shirudo_cert_pubkey(&cert, &cert_key)) {
+ if (base64_decode(cert_b64, strlen(cert_b64), der,
+ EK_CERT_MAX, &der_len) ||
+ cert_read_der(der, der_len, &cert) ||
+ cert_pubkey(&cert, &cert_key)) {
say(&rep, false, "endorsement certificate: parseable "
"with a P-256 or RSA-2048 key");
} else {
@@ -1288,8 +1288,8 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
"endorsement certificate: describes the "
"endorsement key");
if (ek_ca) {
- int vrc = shirudo_cert_verify_chain(&cert, ek_ca,
- &reason);
+ int vrc = cert_verify_chain(&cert, ek_ca,
+ &reason);
if (vrc == -EINVAL)
say(&rep, false, "endorsement "
@@ -1330,15 +1330,15 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
goto out;
if (rsa) {
if (getrandom(seed, sizeof(seed), 0) != (ssize_t)sizeof(seed) ||
- shirudo_rsa_oaep_encrypt(pub.n, pub.n_len, pub.rsa_exponent,
- "IDENTITY", sizeof("IDENTITY"),
- seed, sizeof(seed), secret,
- sizeof(secret), &secret_len))
+ rsa_oaep_encrypt(pub.n, pub.n_len, pub.rsa_exponent,
+ "IDENTITY", sizeof("IDENTITY"),
+ seed, sizeof(seed), secret,
+ sizeof(secret), &secret_len))
goto out;
} else {
- if (shirudo_ecdh_p256_ephemeral(pub.x, pub.y, eph_x, eph_y, z))
+ if (ecdh_p256_ephemeral(pub.x, pub.y, eph_x, eph_y, z))
goto out;
- shirudo_tpm_kdfe(z, "IDENTITY", eph_x, 32, pub.x, 32, seed);
+ tpm_kdfe(z, "IDENTITY", eph_x, 32, pub.x, 32, seed);
secret[0] = 0;
secret[1] = 32;
memcpy(secret + 2, eph_x, 32);
@@ -1347,7 +1347,7 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
memcpy(secret + 36, eph_y, 32);
secret_len = 68;
}
- if (shirudo_tpm_credential_protect(seed, ak_name, credential, blob))
+ if (tpm_credential_protect(seed, ak_name, credential, blob))
goto out;
*cap = 4096;
@@ -1357,19 +1357,19 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
goto out;
}
e = (struct shirudo_json_emit){ .buf = *out, .cap = *cap };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "kind", "shirudo-credential");
- shirudo_json_obj_open_key(&e, "ek");
- shirudo_json_kv_string(&e, "type", rsa ? "rsa" : "ecc");
- shirudo_json_kv_string(&e, "name", ek_name_hex);
- shirudo_json_obj_close(&e);
- shirudo_json_kv_string(&e, "ak_name", ak_hex);
- shirudo_hex_encode(blob, sizeof(blob), hex);
- shirudo_json_kv_string(&e, "credential_blob", hex);
- shirudo_hex_encode(secret, secret_len, hex);
- shirudo_json_kv_string(&e, "secret", hex);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "kind", "shirudo-credential");
+ json_obj_open_key(&e, "ek");
+ json_kv_string(&e, "type", rsa ? "rsa" : "ecc");
+ json_kv_string(&e, "name", ek_name_hex);
+ json_obj_close(&e);
+ json_kv_string(&e, "ak_name", ak_hex);
+ hex_encode(blob, sizeof(blob), hex);
+ json_kv_string(&e, "credential_blob", hex);
+ hex_encode(secret, secret_len, hex);
+ json_kv_string(&e, "secret", hex);
+ json_obj_close(&e);
if (e.err) {
rc = e.err;
goto out;
@@ -1380,7 +1380,7 @@ int shirudo_attest_challenge_make(const char *evidence, size_t len,
out:
explicit_bzero(seed, sizeof(seed));
explicit_bzero(z, sizeof(z));
- shirudo_cert_free(&cert);
+ cert_free(&cert);
xfree(der, der ? EK_CERT_MAX : 0);
xfree(cert_b64, EK_CERT_B64_MAX);
if (rc) {
diff --git a/util/attest.h b/util/attest.h
index 36f94c1c..bc71dc1b 100644
--- a/util/attest.h
+++ b/util/attest.h
@@ -40,17 +40,17 @@ struct shirudo_attest_challenge {
#define SHIRUDO_ATTEST_CHALLENGE_MAX (16 * 1024)
-int shirudo_attest_challenge_read(const char *path,
- struct shirudo_attest_challenge *out);
+int attest_challenge_read(const char *path,
+ struct shirudo_attest_challenge *out);
/*
* Target side. The buffer is xmalloc'd to *cap and NUL-terminated;
* -EKEYREJECTED when the TPM refuses the challenge.
*/
-int shirudo_attest_evidence(const __u8 *nonce, size_t nonce_len,
- __u32 pcr_mask,
- const struct shirudo_attest_challenge *challenge,
- char **out, size_t *len, size_t *cap);
+int attest_evidence(const __u8 *nonce, size_t nonce_len,
+ __u32 pcr_mask,
+ const struct shirudo_attest_challenge *challenge,
+ char **out, size_t *len, size_t *cap);
/*
* Operator side. The credential the target has to recover is handed
@@ -64,11 +64,11 @@ struct shirudo_attest_challenge_policy {
bool trust_presented; /* accept an unvouched endorsement key */
};
-int shirudo_attest_challenge_make(const char *evidence, size_t len,
- const struct shirudo_attest_challenge_policy *pol,
- __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
- char **out, size_t *out_len, size_t *cap,
- char *report, size_t report_cap);
+int attest_challenge_make(const char *evidence, size_t len,
+ const struct shirudo_attest_challenge_policy *pol,
+ __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
+ char **out, size_t *out_len, size_t *cap,
+ char *report, size_t report_cap);
struct shirudo_attest_expect {
const __u8 *nonce;
@@ -96,8 +96,8 @@ struct shirudo_attest_expect {
* Operator side: 0 when every check passed, -EKEYREJECTED when one
* failed, -EINVAL when the document is malformed.
*/
-int shirudo_attest_verify(const char *evidence, size_t len,
- const struct shirudo_attest_expect *expect,
- char *report, size_t report_cap);
+int attest_verify(const char *evidence, size_t len,
+ const struct shirudo_attest_expect *expect,
+ char *report, size_t report_cap);
#endif /* SHIRUDO_ATTEST_H */
diff --git a/util/bpm_oci.c b/util/bpm_oci.c
index 9b710326..011a5e39 100644
--- a/util/bpm_oci.c
+++ b/util/bpm_oci.c
@@ -283,7 +283,7 @@ static int load_registry_auth(const char *registry, struct bpm_oci_client *c)
return -ENAMETOOLONG;
authfile = path;
}
- rc = shirudo_read_file(authfile, 4u * 1024u * 1024u, &body, &body_len);
+ rc = read_file(authfile, 4u * 1024u * 1024u, &body, &body_len);
if (rc)
return rc == -ENOENT ? 0 : rc;
/*
@@ -353,11 +353,11 @@ int bpm_oci_parse_endpoint(const char *endpoint, struct bpm_oci_client *c)
if (strlen(ca_file) >= sizeof(c->ca_file))
return -ENAMETOOLONG;
bpm_copy_string(c->ca_file, sizeof(c->ca_file), ca_file);
- if (shirudo_cert_read_file(c->ca_file, &ca) != 0) {
+ if (cert_read_file(c->ca_file, &ca) != 0) {
pr_err("bpm OCI: BPM_OCI_CA_FILE is not a readable certificate");
return -EINVAL;
}
- shirudo_cert_free(&ca);
+ cert_free(&ca);
}
if (c->ca_file[0]) {
struct stat st;
@@ -445,7 +445,7 @@ static int curl_once_ex(struct bpm_oci_client *c, const char *method,
}
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
- if (shirudo_tls_curl_policy(curl, &c->tls_ca)) {
+ if (tls_curl_policy(curl, &c->tls_ca)) {
pr_err("bpm OCI request %s: cannot apply TLS policy", url);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
@@ -477,7 +477,7 @@ static int curl_once_ex(struct bpm_oci_client *c, const char *method,
file->overflow = true;
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
- shirudo_tls_ca_cleanup(&c->tls_ca);
+ tls_ca_cleanup(&c->tls_ca);
return status < 0 ? -EHOSTUNREACH : 0;
}
@@ -625,7 +625,7 @@ static int get_bearer_token(struct bpm_oci_client *c, const char *challenge)
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &r);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
- if (shirudo_tls_curl_policy(curl, &c->tls_ca)) {
+ if (tls_curl_policy(curl, &c->tls_ca)) {
rc = -EINVAL;
goto out;
}
@@ -648,7 +648,7 @@ out:
curl_free(esc_scope);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
- shirudo_tls_ca_cleanup(&c->tls_ca);
+ tls_ca_cleanup(&c->tls_ca);
bpm_buffer_free(&r.body);
return rc;
}
@@ -880,7 +880,7 @@ int bpm_oci_parse_manifest(const __u8 *body, size_t len,
.dst = &arr, .sub = sub, .n_sub = ARRAY_SIZE(sub) };
root[2] = (struct shirudo_json_field){ .key = "annotations", .type = SHIRUDO_JSON_T_OBJECT,
.sub = manifest_annotations, .n_sub = ARRAY_SIZE(manifest_annotations) };
- if (shirudo_json_parse((const char *)body, len, root, ARRAY_SIZE(root)) ||
+ if (json_parse((const char *)body, len, root, ARRAY_SIZE(root)) ||
!root[0].seen || schema != 2 || !root[1].seen)
return -EINVAL;
*n_layers = sink.n;
@@ -1054,7 +1054,7 @@ int bpm_sha256_hex(const void *data, size_t len,
{
__u8 digest[SHIRUDO_CRYPTO_SHA256_LEN];
- if (hex_sz < 65 || shirudo_sha256_buffer(data, len, digest) != 0)
+ if (hex_sz < 65 || sha256_buffer(data, len, digest) != 0)
return -EINVAL;
for (__u32 i = 0; i < sizeof(digest); i++)
snprintf(hex + i * 2, 3, "%02x", digest[i]);
@@ -1158,18 +1158,18 @@ void bpm_oci_emit_descriptor(struct shirudo_json_emit *e, const char *key,
const struct bpm_descriptor *d, const char *title)
{
if (key)
- shirudo_json_obj_open_key(e, key);
+ json_obj_open_key(e, key);
else
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "mediaType", d->media);
- shirudo_json_kv_string(e, "digest", d->digest);
- shirudo_json_kv_int(e, "size", d->size);
+ json_obj_open(e);
+ json_kv_string(e, "mediaType", d->media);
+ json_kv_string(e, "digest", d->digest);
+ json_kv_int(e, "size", d->size);
if (title) {
- shirudo_json_obj_open_key(e, "annotations");
- shirudo_json_kv_string(e, "org.opencontainers.image.title", title);
- shirudo_json_obj_close(e);
+ json_obj_open_key(e, "annotations");
+ json_kv_string(e, "org.opencontainers.image.title", title);
+ json_obj_close(e);
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
int bpm_oci_put_manifest(struct bpm_oci_client *c, const char *repository,
diff --git a/util/bpm_package.c b/util/bpm_package.c
index e0327b99..28b694c8 100644
--- a/util/bpm_package.c
+++ b/util/bpm_package.c
@@ -101,7 +101,7 @@ int bpm_index_parse(const __u8 *body, size_t len,
.key = "packages", .type = SHIRUDO_JSON_T_ARRAY,
.dst = &arr, .sub = sub, .n_sub = ARRAY_SIZE(sub),
};
- if (shirudo_json_parse((const char *)body, len, root, ARRAY_SIZE(root)) ||
+ if (json_parse((const char *)body, len, root, ARRAY_SIZE(root)) ||
schema != 1 || !root[1].seen)
return -EINVAL;
*n_entries = sink.n;
@@ -158,8 +158,8 @@ int bpm_semver_compare(const char *a, const char *b)
const char *pa = a, *pb = b;
for (int part = 0; part < 3; part++) {
- size_t na = shirudo_digits(pa, strlen(pa));
- size_t nb = shirudo_digits(pb, strlen(pb));
+ size_t na = digits(pa, strlen(pa));
+ size_t nb = digits(pb, strlen(pb));
__u64 va, vb;
if (parse_u64(pa, na, UINT64_MAX, &va) ||
@@ -184,9 +184,9 @@ int bpm_verify_cms(const __u8 *payload, size_t payload_len,
struct shirudo_cert cert = {};
int rc = -EINVAL;
- if (!shirudo_cert_read_file(cert_path, &cert))
- rc = shirudo_verify_detached(payload, payload_len, sig, sig_len, &cert);
- shirudo_cert_free(&cert);
+ if (!cert_read_file(cert_path, &cert))
+ rc = verify_detached(payload, payload_len, sig, sig_len, &cert);
+ cert_free(&cert);
return rc;
}
@@ -420,7 +420,7 @@ int bpm_pkg_extract(const char *archive, const char *dest)
if (!gz)
return -EINVAL;
- rc = shirudo_seal_mkdir_p(dest, 0700);
+ rc = seal_mkdir_p(dest, 0700);
if (rc) {
gzclose(gz);
return rc;
@@ -481,7 +481,7 @@ int bpm_pkg_extract(const char *archive, const char *dest)
break;
}
if (type == '5') {
- rc = shirudo_seal_mkdir_p(path, 0700);
+ rc = seal_mkdir_p(path, 0700);
if (rc)
break;
} else if (type == '0') {
@@ -492,7 +492,7 @@ int bpm_pkg_extract(const char *archive, const char *dest)
slash = strrchr(parent, '/');
if (slash) {
*slash = 0;
- rc = shirudo_seal_mkdir_p(parent, 0700);
+ rc = seal_mkdir_p(parent, 0700);
if (rc)
break;
}
@@ -584,8 +584,8 @@ int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info)
&environment_len, 4u * 1024u * 1024u);
if (rc)
return rc;
- if (shirudo_json_parse((const char *)environment, environment_len,
- root, ARRAY_SIZE(root)) ||
+ if (json_parse((const char *)environment, environment_len,
+ root, ARRAY_SIZE(root)) ||
!root[0].seen || !parsed.name[0] || !parsed.version[0] ||
!bpm_package_name_ok(parsed.name) || !bpm_version_ok(parsed.version)) {
rc = -EINVAL;
@@ -705,7 +705,7 @@ int bpm_tree_fetch_publication(struct bpm_oci_client *c,
rc = -EKEYREJECTED;
goto out;
}
- rc = shirudo_tree_parse((const char *)payload.data, payload.len, pub);
+ rc = tree_parse((const char *)payload.data, payload.len, pub);
out:
if (layers)
xfree(layers, BPM_MAX_ENTRIES * sizeof(*layers));
diff --git a/util/bpm_source_config.c b/util/bpm_source_config.c
index 0358fccc..c098cf76 100644
--- a/util/bpm_source_config.c
+++ b/util/bpm_source_config.c
@@ -12,9 +12,9 @@
#include "bpm_source_config.h"
-int shirudo_bpm_parse_source_line(char *line,
- char *endpoint, size_t endpoint_sz,
- char *key_file, size_t key_file_sz)
+int bpm_parse_source_line(char *line,
+ char *endpoint, size_t endpoint_sz,
+ char *key_file, size_t key_file_sz)
{
char *eq, *key, *key_end, *val;
@@ -57,9 +57,9 @@ static char *trim(char *s)
return s;
}
-int shirudo_bpm_parse_tree_line(char *line,
- char *endpoint, size_t endpoint_sz,
- char *reference, size_t reference_sz)
+int bpm_parse_tree_line(char *line,
+ char *endpoint, size_t endpoint_sz,
+ char *reference, size_t reference_sz)
{
char *eq = strchr(line, '=');
char *key, *value;
diff --git a/util/bpm_source_config.h b/util/bpm_source_config.h
index 52fc0c64..1bc0352f 100644
--- a/util/bpm_source_config.h
+++ b/util/bpm_source_config.h
@@ -8,12 +8,12 @@
#include <stddef.h>
-int shirudo_bpm_parse_source_line(char *line,
- char *endpoint, size_t endpoint_sz,
- char *key_file, size_t key_file_sz);
+int bpm_parse_source_line(char *line,
+ char *endpoint, size_t endpoint_sz,
+ char *key_file, size_t key_file_sz);
/* A line of upatch-tree.conf: endpoint and reference, either quoted. */
-int shirudo_bpm_parse_tree_line(char *line,
- char *endpoint, size_t endpoint_sz,
- char *reference, size_t reference_sz);
+int bpm_parse_tree_line(char *line,
+ char *endpoint, size_t endpoint_sz,
+ char *reference, size_t reference_sz);
#endif /* SHIRUDO_BPM_SOURCE_CONFIG_H */
diff --git a/util/bpm_tree.c b/util/bpm_tree.c
index 098adfe9..f713ce84 100644
--- a/util/bpm_tree.c
+++ b/util/bpm_tree.c
@@ -171,7 +171,7 @@ static int tp_int(struct tree_parser *p, __s64 *out)
tp_ws(p);
len = (size_t)(p->end - p->p);
neg = len && *p->p == '-';
- n = neg + shirudo_digits(p->p + neg, len - neg);
+ n = neg + digits(p->p + neg, len - neg);
if (parse_s64(p->p, n, INT64_MIN, INT64_MAX, out))
return -EINVAL;
p->p += n;
@@ -380,7 +380,7 @@ static int tp_operation(struct tree_parser *p, struct shirudo_tree_operation *o)
}
}
-void shirudo_tree_publication_free(struct shirudo_tree_publication *pub)
+void tree_publication_free(struct shirudo_tree_publication *pub)
{
if (!pub)
return;
@@ -411,8 +411,8 @@ static int tree_operations_reserve(struct shirudo_tree_publication *pub)
return 0;
}
-int shirudo_tree_publication_append(struct shirudo_tree_publication *pub,
- const struct shirudo_tree_operation *op)
+int tree_publication_append(struct shirudo_tree_publication *pub,
+ const struct shirudo_tree_operation *op)
{
int rc;
@@ -451,8 +451,8 @@ static int tp_seq_object(struct tree_parser *p, char *key, size_t cap,
}
}
-int shirudo_tree_parse(const char *body, size_t len,
- struct shirudo_tree_publication *out)
+int tree_parse(const char *body, size_t len,
+ struct shirudo_tree_publication *out)
{
struct tree_parser p;
char key[SHIRUDO_TREE_STRING_MAX];
@@ -584,7 +584,7 @@ int shirudo_tree_parse(const char *body, size_t len,
}
return 0;
fail:
- shirudo_tree_publication_free(out);
+ tree_publication_free(out);
return rc;
}
@@ -620,58 +620,58 @@ static int tree_emit_selector(struct shirudo_json_emit *e,
qsort(labels, (size_t)s->n_labels, sizeof(labels[0]),
tree_selector_kv_compare);
- shirudo_json_obj_open_key(e, "selector");
+ json_obj_open_key(e, "selector");
if (s->n_architecture) {
- shirudo_json_arr_open(e, "architecture");
+ json_arr_open(e, "architecture");
for (int i = 0; i < s->n_architecture; i++)
- shirudo_json_str(e, s->architecture[i]);
- shirudo_json_arr_close(e);
+ json_str(e, s->architecture[i]);
+ json_arr_close(e);
}
if (s->n_kconfig) {
- shirudo_json_obj_open_key(e, "kconfig");
+ json_obj_open_key(e, "kconfig");
for (int i = 0; i < s->n_kconfig; i++) {
- shirudo_json_arr_open(e, kconfig[i]->key);
+ json_arr_open(e, kconfig[i]->key);
for (int j = 0; j < kconfig[i]->n_values; j++)
- shirudo_json_str(e, kconfig[i]->values[j]);
- shirudo_json_arr_close(e);
+ json_str(e, kconfig[i]->values[j]);
+ json_arr_close(e);
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
if (s->n_kernel_build_id) {
- shirudo_json_arr_open(e, "kernel_build_id");
+ json_arr_open(e, "kernel_build_id");
for (int i = 0; i < s->n_kernel_build_id; i++)
- shirudo_json_str(e, s->kernel_build_id[i]);
- shirudo_json_arr_close(e);
+ json_str(e, s->kernel_build_id[i]);
+ json_arr_close(e);
}
if (s->n_kernel_release_prefix) {
- shirudo_json_arr_open(e, "kernel_release_prefix");
+ json_arr_open(e, "kernel_release_prefix");
for (int i = 0; i < s->n_kernel_release_prefix; i++)
- shirudo_json_str(e, s->kernel_release_prefix[i]);
- shirudo_json_arr_close(e);
+ json_str(e, s->kernel_release_prefix[i]);
+ json_arr_close(e);
}
if (s->n_labels) {
- shirudo_json_obj_open_key(e, "labels");
+ json_obj_open_key(e, "labels");
for (int i = 0; i < s->n_labels; i++) {
- shirudo_json_arr_open(e, labels[i]->key);
+ json_arr_open(e, labels[i]->key);
for (int j = 0; j < labels[i]->n_values; j++)
- shirudo_json_str(e, labels[i]->values[j]);
- shirudo_json_arr_close(e);
+ json_str(e, labels[i]->values[j]);
+ json_arr_close(e);
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
return 0;
}
static void tree_emit_artifact(struct shirudo_json_emit *e,
const struct shirudo_tree_artifact *a)
{
- shirudo_json_obj_open_key(e, "artifact");
- shirudo_json_kv_string(e, "repository", a->repository);
- shirudo_json_kv_string(e, "manifest_digest", a->manifest_digest);
- shirudo_json_kv_string(e, "layer_digest", a->layer_digest);
- shirudo_json_kv_string(e, "payload_sha256", a->payload_sha256);
- shirudo_json_obj_close(e);
+ json_obj_open_key(e, "artifact");
+ json_kv_string(e, "repository", a->repository);
+ json_kv_string(e, "manifest_digest", a->manifest_digest);
+ json_kv_string(e, "layer_digest", a->layer_digest);
+ json_kv_string(e, "payload_sha256", a->payload_sha256);
+ json_obj_close(e);
}
static int tree_emit_operation(struct shirudo_json_emit *e,
@@ -680,17 +680,17 @@ static int tree_emit_operation(struct shirudo_json_emit *e,
{
int rc;
- shirudo_json_obj_open(e);
- shirudo_json_kv_int(e, "seq", op->seq);
- shirudo_json_kv_string(e, "op", op->op);
- shirudo_json_kv_string(e, "id", op->id);
+ json_obj_open(e);
+ json_kv_int(e, "seq", op->seq);
+ json_kv_string(e, "op", op->op);
+ json_kv_string(e, "id", op->id);
rc = tree_emit_selector(e, &op->selector);
if (rc)
return rc;
tree_emit_artifact(e, &op->artifact);
if (with_digest)
- shirudo_json_kv_string(e, "operation_digest", op->operation_digest);
- shirudo_json_obj_close(e);
+ json_kv_string(e, "operation_digest", op->operation_digest);
+ json_obj_close(e);
return e->err;
}
@@ -698,8 +698,8 @@ static int tree_emit_operation(struct shirudo_json_emit *e,
* The operation digest covers the canonical operation without the digest
* field itself: seq, op, id, selector and artifact.
*/
-int shirudo_tree_operation_digest(const struct shirudo_tree_operation *op,
- char out[72])
+int tree_operation_digest(const struct shirudo_tree_operation *op,
+ char out[72])
{
size_t body_cap = 1024u * 1024u;
struct shirudo_json_emit e;
@@ -712,10 +712,10 @@ int shirudo_tree_operation_digest(const struct shirudo_tree_operation *op,
return -ENOMEM;
e = (struct shirudo_json_emit){ .buf = body, .cap = body_cap };
rc = tree_emit_operation(&e, op, false);
- if (!rc && shirudo_sha256_buffer(body, e.len, digest))
+ if (!rc && sha256_buffer(body, e.len, digest))
rc = -EIO;
if (!rc) {
- shirudo_hex_encode(digest, sizeof(digest), hex);
+ hex_encode(digest, sizeof(digest), hex);
memcpy(out, "sha256:", 7);
memcpy(out + 7, hex, sizeof(hex));
}
@@ -766,8 +766,8 @@ static size_t tree_operation_bound(const struct shirudo_tree_operation *op)
* schema, tree_id, generation, parent_manifest_digest (when any), base,
* operations, head.
*/
-int shirudo_tree_emit_publication(const struct shirudo_tree_publication *pub,
- char **out, size_t *out_len)
+int tree_emit_publication(const struct shirudo_tree_publication *pub,
+ char **out, size_t *out_len)
{
struct shirudo_json_emit e;
size_t cap = 4096;
@@ -780,24 +780,24 @@ int shirudo_tree_emit_publication(const struct shirudo_tree_publication *pub,
if (!body)
return -ENOMEM;
e = (struct shirudo_json_emit){ .buf = body, .cap = cap };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", pub->schema);
- shirudo_json_kv_string(&e, "tree_id", pub->tree_id);
- shirudo_json_kv_int(&e, "generation", pub->generation);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", pub->schema);
+ json_kv_string(&e, "tree_id", pub->tree_id);
+ json_kv_int(&e, "generation", pub->generation);
if (pub->parent_manifest_digest[0])
- shirudo_json_kv_string(&e, "parent_manifest_digest",
- pub->parent_manifest_digest);
- shirudo_json_obj_open_key(&e, "base");
- shirudo_json_kv_int(&e, "seq", pub->base_seq);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "operations");
+ json_kv_string(&e, "parent_manifest_digest",
+ pub->parent_manifest_digest);
+ json_obj_open_key(&e, "base");
+ json_kv_int(&e, "seq", pub->base_seq);
+ json_obj_close(&e);
+ json_arr_open(&e, "operations");
for (int i = 0; !rc && i < pub->n_operations; i++)
rc = tree_emit_operation(&e, &pub->operations[i], true);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_open_key(&e, "head");
- shirudo_json_kv_int(&e, "seq", pub->head_seq);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_open_key(&e, "head");
+ json_kv_int(&e, "seq", pub->head_seq);
+ json_obj_close(&e);
+ json_obj_close(&e);
if (!rc)
rc = e.err;
if (rc) {
diff --git a/util/bpm_tree.h b/util/bpm_tree.h
index 5f507dd5..a4427652 100644
--- a/util/bpm_tree.h
+++ b/util/bpm_tree.h
@@ -82,11 +82,11 @@ struct shirudo_tree_state {
char manifest_digest[128];
};
-int shirudo_tree_parse(const char *body, size_t len,
- struct shirudo_tree_publication *out);
-int shirudo_tree_publication_append(struct shirudo_tree_publication *pub,
- const struct shirudo_tree_operation *op);
-void shirudo_tree_publication_free(struct shirudo_tree_publication *pub);
+int tree_parse(const char *body, size_t len,
+ struct shirudo_tree_publication *out);
+int tree_publication_append(struct shirudo_tree_publication *pub,
+ const struct shirudo_tree_operation *op);
+void tree_publication_free(struct shirudo_tree_publication *pub);
/*
* Canonical forms shared by publisher and target: the operation digest
@@ -94,24 +94,24 @@ void shirudo_tree_publication_free(struct shirudo_tree_publication *pub);
* the publication document. The emitted document is xmalloc'd; release
* it with xfree(out, out_len).
*/
-int shirudo_tree_operation_digest(const struct shirudo_tree_operation *op,
- char out[72]);
-int shirudo_tree_emit_publication(const struct shirudo_tree_publication *pub,
- char **out, size_t *out_len);
+int tree_operation_digest(const struct shirudo_tree_operation *op,
+ char out[72]);
+int tree_emit_publication(const struct shirudo_tree_publication *pub,
+ char **out, size_t *out_len);
/*
* Evaluate a publication selector against the running node. An empty
* selector is an unconstrained wildcard and matches every node. 1 on a
* match, 0 without one, -errno when the node's labels cannot be read.
*/
-int shirudo_tree_selector_matches(const struct shirudo_tree_selector *selector);
+int tree_selector_matches(const struct shirudo_tree_selector *selector);
-int shirudo_tree_state_read(struct shirudo_tree_state *out);
-int shirudo_tree_state_write(const struct shirudo_tree_state *state);
-int shirudo_tree_event_append(__s64 seq, const char *operation_digest,
- const __u8 projection_root[32]);
-int shirudo_tree_event_replay(__u8 out[32]);
+int tree_state_read(struct shirudo_tree_state *out);
+int tree_state_write(const struct shirudo_tree_state *state);
+int tree_event_append(__s64 seq, const char *operation_digest,
+ const __u8 projection_root[32]);
+int tree_event_replay(__u8 out[32]);
-void shirudo_tree_emit_status(struct shirudo_json_emit *e);
+void tree_emit_status(struct shirudo_json_emit *e);
#endif /* SHIRUDO_BPM_TREE_H */
diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.c
index f9e9f5be..e088f721 100644
--- a/util/bpm_tree_state.c
+++ b/util/bpm_tree_state.c
@@ -303,7 +303,7 @@ static int read_selector_config_file(const char *path,
return rc;
}
-int shirudo_tree_selector_matches(const struct shirudo_tree_selector *s)
+int tree_selector_matches(const struct shirudo_tree_selector *s)
{
struct utsname u;
struct shirudo_tree_kv labels[SHIRUDO_TREE_MAX_LABELS];
@@ -330,8 +330,8 @@ int shirudo_tree_selector_matches(const struct shirudo_tree_selector *s)
if (s->n_kernel_release_prefix) {
matched = false;
for (int i = 0; i < s->n_kernel_release_prefix; i++) {
- if (shirudo_kernel_release_prefix_matches(u.release,
- s->kernel_release_prefix[i])) {
+ if (kernel_release_prefix_matches(u.release,
+ s->kernel_release_prefix[i])) {
matched = true;
break;
}
@@ -346,7 +346,7 @@ int shirudo_tree_selector_matches(const struct shirudo_tree_selector *s)
* A selector carrying a build ID is deliberately fail-closed
* when the running kernel does not publish a GNU build ID.
*/
- if (shirudo_kernel_build_id_read(build_id))
+ if (kernel_build_id_read(build_id))
return 0;
matched = false;
for (int i = 0; i < s->n_kernel_build_id; i++) {
@@ -443,10 +443,10 @@ static bool hex32_valid(const char *hex)
{
__u8 raw[32];
- return !shirudo_hex_decode(hex, raw, sizeof(raw));
+ return !hex_decode(hex, raw, sizeof(raw));
}
-int shirudo_tree_state_read(struct shirudo_tree_state *out)
+int tree_state_read(struct shirudo_tree_state *out)
{
__u8 *body;
size_t len;
@@ -470,7 +470,7 @@ int shirudo_tree_state_read(struct shirudo_tree_state *out)
rc = tree_read_file(SHIRUDO_BPM_TREE_STATE_PATH, &body, &len);
if (rc)
return rc;
- rc = shirudo_json_parse((const char *)body, len, f, ARRAY_SIZE(f));
+ rc = json_parse((const char *)body, len, f, ARRAY_SIZE(f));
if (!rc && (schema != 1 || !f[1].seen || !f[3].seen || !f[4].seen))
rc = -EINVAL;
if (!rc && !f[5].seen) {
@@ -504,35 +504,35 @@ static int tree_atomic_write(const char *path, const void *data, size_t len)
return -EINVAL;
memcpy(dir, path, slash - path);
dir[slash - path] = '\0';
- rc = shirudo_seal_mkdir_p(dir, 0700);
+ rc = seal_mkdir_p(dir, 0700);
if (rc) {
pr_err("tree state mkdir %s: %s", dir, strerror(-rc));
return rc;
}
- return shirudo_seal_write_file(path, data, len, 0600);
+ return seal_write_file(path, data, len, 0600);
}
-int shirudo_tree_state_write(const struct shirudo_tree_state *s)
+int tree_state_write(const struct shirudo_tree_state *s)
{
char buf[4096];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "tree_id", s->tree_id);
- shirudo_json_kv_int(&e, "generation", s->generation);
- shirudo_json_kv_int(&e, "last_seq", s->last_seq);
- shirudo_json_kv_string(&e, "projection_root", s->projection_root);
- shirudo_json_kv_string(&e, "projection_root_tpm", s->projection_root_tpm);
- shirudo_json_kv_string(&e, "manifest_digest", s->manifest_digest);
- shirudo_json_obj_close(&e);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "tree_id", s->tree_id);
+ json_kv_int(&e, "generation", s->generation);
+ json_kv_int(&e, "last_seq", s->last_seq);
+ json_kv_string(&e, "projection_root", s->projection_root);
+ json_kv_string(&e, "projection_root_tpm", s->projection_root_tpm);
+ json_kv_string(&e, "manifest_digest", s->manifest_digest);
+ json_obj_close(&e);
if (e.err)
return e.err;
return tree_atomic_write(SHIRUDO_BPM_TREE_STATE_PATH, buf, e.len);
}
-int shirudo_tree_event_append(__s64 seq, const char *operation_digest,
- const __u8 projection_root[32])
+int tree_event_append(__s64 seq, const char *operation_digest,
+ const __u8 projection_root[32])
{
char buf[1024], root[65];
struct shirudo_json_emit e = { .buf = buf, .cap = sizeof(buf) };
@@ -542,20 +542,20 @@ int shirudo_tree_event_append(__s64 seq, const char *operation_digest,
if (!operation_digest || strncmp(operation_digest, "sha256:", 7) ||
!hex32_valid(operation_digest + 7))
return -EINVAL;
- shirudo_hex_encode(projection_root, 32, root);
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_int(&e, "seq", seq);
- shirudo_json_kv_string(&e, "digest", operation_digest);
- shirudo_json_kv_string(&e, "projection_root", root);
- shirudo_json_obj_close(&e);
+ hex_encode(projection_root, 32, root);
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_int(&e, "seq", seq);
+ json_kv_string(&e, "digest", operation_digest);
+ json_kv_string(&e, "projection_root", root);
+ json_obj_close(&e);
if (e.err)
return e.err;
- rc = shirudo_seal_mkdir_p(SHIRUDO_BPM_TREE_VAR_DIR, 0700);
+ rc = seal_mkdir_p(SHIRUDO_BPM_TREE_VAR_DIR, 0700);
if (rc)
return rc;
- fd = shirudo_seal_open(SHIRUDO_BPM_TREE_EVENTLOG_PATH,
- O_WRONLY | O_CREAT | O_APPEND, 0600);
+ fd = seal_open(SHIRUDO_BPM_TREE_EVENTLOG_PATH,
+ O_WRONLY | O_CREAT | O_APPEND, 0600);
if (fd < 0)
return fd;
/* A partial line would fail every later replay; roll it back. */
@@ -569,9 +569,9 @@ int shirudo_tree_event_append(__s64 seq, const char *operation_digest,
rc = -errno;
goto out;
}
- rc = shirudo_write_all(fd, buf, e.len);
+ rc = write_all(fd, buf, e.len);
if (!rc)
- rc = shirudo_write_all(fd, "\n", 1);
+ rc = write_all(fd, "\n", 1);
if (!rc && fsync(fd))
rc = -errno;
if (rc && ftruncate(fd, st.st_size))
@@ -583,7 +583,7 @@ out:
return rc;
}
-int shirudo_tree_event_replay(__u8 out[32])
+int tree_event_replay(__u8 out[32])
{
__u8 *body;
size_t len;
@@ -608,23 +608,23 @@ int shirudo_tree_event_replay(__u8 out[32])
};
__u8 d[32], next[64], recorded[32];
- rc = shirudo_json_parse(line, strlen(line), f, ARRAY_SIZE(f));
+ rc = json_parse(line, strlen(line), f, ARRAY_SIZE(f));
if (rc || !f[0].seen || !f[1].seen || !f[2].seen ||
seq <= previous_seq || strlen(projection) != 64 ||
- shirudo_hex_decode(projection, recorded, 32)) {
+ hex_decode(projection, recorded, 32)) {
rc = -EINVAL;
break;
}
previous_seq = seq;
if (strncmp(digest, "sha256:", 7) ||
- shirudo_hex_decode(digest + 7, d, sizeof(d))) {
+ hex_decode(digest + 7, d, sizeof(d))) {
rc = -EINVAL;
break;
}
memcpy(next, chain, 32);
memcpy(next + 32, d, 32);
shirudo_sha256(next, sizeof(next), chain);
- if (!shirudo_ct_eq(chain, recorded, 32)) {
+ if (!ct_eq(chain, recorded, 32)) {
rc = -EINVAL;
break;
}
@@ -635,36 +635,36 @@ int shirudo_tree_event_replay(__u8 out[32])
return rc;
}
-void shirudo_tree_emit_status(struct shirudo_json_emit *e)
+void tree_emit_status(struct shirudo_json_emit *e)
{
struct shirudo_tree_state s = {};
__u8 live[32], replay[32];
char hex[65];
bool configured = access(SHIRUDO_BPM_TREE_ETC_PATH, R_OK) == 0;
- shirudo_json_obj_open_key(e, "upatch_tree");
- shirudo_json_kv_bool(e, "configured", configured);
- shirudo_json_kv_bool(e, "pending", access(SHIRUDO_BPM_TREE_PENDING_PATH,
- R_OK) == 0);
- if (shirudo_tree_state_read(&s) == 0) {
- shirudo_json_kv_string(e, "tree_id", s.tree_id);
- shirudo_json_kv_int(e, "generation", s.generation);
- shirudo_json_kv_int(e, "last_seq", s.last_seq);
- shirudo_json_kv_string(e, "projection_root", s.projection_root);
- shirudo_json_kv_string(e, "manifest_digest", s.manifest_digest);
+ json_obj_open_key(e, "upatch_tree");
+ json_kv_bool(e, "configured", configured);
+ json_kv_bool(e, "pending", access(SHIRUDO_BPM_TREE_PENDING_PATH,
+ R_OK) == 0);
+ if (tree_state_read(&s) == 0) {
+ json_kv_string(e, "tree_id", s.tree_id);
+ json_kv_int(e, "generation", s.generation);
+ json_kv_int(e, "last_seq", s.last_seq);
+ json_kv_string(e, "projection_root", s.projection_root);
+ json_kv_string(e, "manifest_digest", s.manifest_digest);
} else {
- shirudo_json_kv_null(e, "state");
+ json_kv_null(e, "state");
}
- if (shirudo_tree_event_replay(replay) == 0) {
- shirudo_hex_encode(replay, 32, hex);
- shirudo_json_kv_string(e, "eventlog_projection_root", hex);
- shirudo_json_kv_bool(e, "eventlog_matches_state",
- shirudo_hex_decode(s.projection_root, live,
- 32) == 0 &&
- shirudo_ct_eq(live, replay, 32));
+ if (tree_event_replay(replay) == 0) {
+ hex_encode(replay, 32, hex);
+ json_kv_string(e, "eventlog_projection_root", hex);
+ json_kv_bool(e, "eventlog_matches_state",
+ hex_decode(s.projection_root, live,
+ 32) == 0 &&
+ ct_eq(live, replay, 32));
} else {
- shirudo_json_kv_null(e, "eventlog_projection_root");
- shirudo_json_kv_null(e, "eventlog_matches_state");
+ json_kv_null(e, "eventlog_projection_root");
+ json_kv_null(e, "eventlog_matches_state");
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
diff --git a/util/chain.c b/util/chain.c
index e8322806..a3ef0b36 100644
--- a/util/chain.c
+++ b/util/chain.c
@@ -28,28 +28,28 @@
void shirudo_sha256(const void *data, size_t len, __u8 out[32])
{
- if (shirudo_sha256_buffer(data, len, out) != 0)
+ if (sha256_buffer(data, len, out) != 0)
memset(out, 0, 32);
}
-void shirudo_sha256_2(const void *a, size_t a_len,
- const void *b, size_t b_len, __u8 out[32])
+void sha256_2(const void *a, size_t a_len,
+ const void *b, size_t b_len, __u8 out[32])
{
struct shirudo_sha256_ctx ctx;
- if (shirudo_sha256_init(&ctx) != 0) {
+ if (sha256_init(&ctx) != 0) {
memset(out, 0, 32);
return;
}
- if (shirudo_sha256_update(&ctx, a, a_len) != 0 ||
- (b_len && shirudo_sha256_update(&ctx, b, b_len) != 0) ||
- shirudo_sha256_final(&ctx, out) != 0) {
+ if (sha256_update(&ctx, a, a_len) != 0 ||
+ (b_len && sha256_update(&ctx, b, b_len) != 0) ||
+ sha256_final(&ctx, out) != 0) {
memset(out, 0, 32);
- shirudo_sha256_free(&ctx);
+ sha256_free(&ctx);
}
}
-int shirudo_ct_eq(const void *a, const void *b, size_t n)
+int ct_eq(const void *a, const void *b, size_t n)
{
const __u8 *pa = a, *pb = b;
__u8 diff = 0;
@@ -66,10 +66,10 @@ static int member_cmp(const void *a, const void *b)
((const struct shirudo_measured_upatch *)b)->name);
}
-void shirudo_chain_init_event(const __u8 cert_sha[32],
- struct shirudo_measured_upatch *set, size_t n,
- const __u8 tree_root[32],
- __u8 set_digest[32], __u8 event[32])
+void chain_init_event(const __u8 cert_sha[32],
+ struct shirudo_measured_upatch *set, size_t n,
+ const __u8 tree_root[32],
+ __u8 set_digest[32], __u8 event[32])
{
__u8 tag[sizeof("shirudo-init") + 96];
size_t taglen = sizeof("shirudo-init"), listing_len = 0, off = 0, i;
@@ -101,8 +101,8 @@ void shirudo_chain_init_event(const __u8 cert_sha[32],
shirudo_sha256(tag, taglen + 96, event);
}
-void shirudo_chain_upatch_event(const char *tag, const char *name,
- const __u8 payload[32], __u8 event[32])
+void chain_upatch_event(const char *tag, const char *name,
+ const __u8 payload[32], __u8 event[32])
{
__u8 buf[sizeof("shirudo-unload") + 32 + SHIRUDO_UPATCH_NAME_MAX];
size_t taglen = strlen(tag) + 1, off = 0;
@@ -117,14 +117,14 @@ void shirudo_chain_upatch_event(const char *tag, const char *name,
shirudo_sha256(buf, off, event);
}
-void shirudo_chain_key_event(const char *tag, const __u8 cert_sha[32],
- __u8 event[32])
+void chain_key_event(const char *tag, const __u8 cert_sha[32],
+ __u8 event[32])
{
- shirudo_sha256_2(tag, strlen(tag) + 1, cert_sha, 32, event);
+ sha256_2(tag, strlen(tag) + 1, cert_sha, 32, event);
}
-void shirudo_chain_tree_event(__s64 seq, const __u8 operation_digest[32],
- __u8 event[32])
+void chain_tree_event(__s64 seq, const __u8 operation_digest[32],
+ __u8 event[32])
{
__u8 buf[sizeof("shirudo-tree") + 8 + 32];
size_t taglen = sizeof("shirudo-tree"), i;
@@ -137,7 +137,7 @@ void shirudo_chain_tree_event(__s64 seq, const __u8 operation_digest[32],
shirudo_sha256(buf, taglen + 40, event);
}
-void shirudo_chain_fold(__u8 chain[32], const __u8 event[32])
+void chain_fold(__u8 chain[32], const __u8 event[32])
{
__u8 cat[64];
@@ -146,12 +146,12 @@ void shirudo_chain_fold(__u8 chain[32], const __u8 event[32])
shirudo_sha256(cat, sizeof(cat), chain);
}
-void shirudo_chain_anchor(const __u8 name[SHIRUDO_TPM_NAME_LEN],
- char *out, size_t cap)
+void chain_anchor(const __u8 name[SHIRUDO_TPM_NAME_LEN],
+ char *out, size_t cap)
{
char hex[2 * SHIRUDO_TPM_NAME_LEN + 1];
- shirudo_hex_encode(name, SHIRUDO_TPM_NAME_LEN, hex);
+ hex_encode(name, SHIRUDO_TPM_NAME_LEN, hex);
snprintf(out, cap, "nvpcr-init:%s:0x%x:%s", SHIRUDO_CHAIN_NAME,
SHIRUDO_NV_INDEX, hex);
}
@@ -182,20 +182,20 @@ static void register_expectation(const __u8 pcr_before[32],
__u8 values[64];
bind_values(pcr_before, phase_before, values);
- shirudo_tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, values, 2,
- branch_written, branch_init, policy);
- shirudo_tpm_nv_name(SHIRUDO_NV_INDEX, SHIRUDO_TPM_REGISTER_ATTRS,
- policy, SHIRUDO_TPM_NV_DIGEST_LEN, name_unwritten);
- shirudo_tpm_nv_name(SHIRUDO_NV_INDEX,
- SHIRUDO_TPM_REGISTER_ATTRS | SHIRUDO_TPM_NV_WRITTEN,
- policy, SHIRUDO_TPM_NV_DIGEST_LEN, name_written);
+ tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, values, 2,
+ branch_written, branch_init, policy);
+ tpm_nv_name(SHIRUDO_NV_INDEX, SHIRUDO_TPM_REGISTER_ATTRS,
+ policy, SHIRUDO_TPM_NV_DIGEST_LEN, name_unwritten);
+ tpm_nv_name(SHIRUDO_NV_INDEX,
+ SHIRUDO_TPM_REGISTER_ATTRS | SHIRUDO_TPM_NV_WRITTEN,
+ policy, SHIRUDO_TPM_NV_DIGEST_LEN, name_written);
}
-static bool name_equals(const struct shirudo_tpm_nv_info *info,
+static bool name_equals(const struct tpm_nv_info *info,
const __u8 name[SHIRUDO_TPM_NAME_LEN])
{
return info->name_len == SHIRUDO_TPM_NAME_LEN &&
- shirudo_ct_eq(info->name, name, SHIRUDO_TPM_NAME_LEN);
+ ct_eq(info->name, name, SHIRUDO_TPM_NAME_LEN);
}
static int register_define(struct shirudo_tpm *tpm, bool defined,
@@ -204,40 +204,40 @@ static int register_define(struct shirudo_tpm *tpm, bool defined,
struct shirudo_config cfg = {};
int rc;
- shirudo_config_load(&cfg);
+ config_load(&cfg);
if (defined) {
- rc = shirudo_tpm_nv_undefine(tpm, SHIRUDO_NV_INDEX,
- cfg.tpm_owner_auth,
- cfg.tpm_owner_auth_len);
+ rc = tpm_nv_undefine(tpm, SHIRUDO_NV_INDEX,
+ cfg.tpm_owner_auth,
+ cfg.tpm_owner_auth_len);
if (rc)
goto out;
}
- rc = shirudo_tpm_nv_define(tpm, SHIRUDO_NV_INDEX, policy,
- cfg.tpm_owner_auth, cfg.tpm_owner_auth_len);
+ rc = tpm_nv_define(tpm, SHIRUDO_NV_INDEX, policy,
+ cfg.tpm_owner_auth, cfg.tpm_owner_auth_len);
out:
explicit_bzero(&cfg, sizeof(cfg));
return rc;
}
-int shirudo_chain_init(const __u8 event[32],
- struct shirudo_chain_init_info *info)
+int chain_init(const __u8 event[32],
+ struct shirudo_chain_init_info *info)
{
__u8 unwritten[SHIRUDO_TPM_NAME_LEN], written[SHIRUDO_TPM_NAME_LEN];
__u8 branch_written[32], branch_init[32], policy[32];
struct shirudo_eventlog_init rec;
- struct shirudo_tpm_nv_info nv;
+ struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
bool recorded;
int rc;
memset(info, 0, sizeof(*info));
- rc = shirudo_tpm_open(&tpm);
+ rc = tpm_open(&tpm);
if (rc)
return -ENODEV;
- rc = shirudo_tpm_reset_count(tpm, &info->reset_count);
+ rc = tpm_reset_count(tpm, &info->reset_count);
if (rc)
goto out;
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
@@ -252,10 +252,10 @@ int shirudo_chain_init(const __u8 event[32],
* PCR keeps the record of both bindings. A log that cannot be
* read may hold the record, so it is refused as well.
*/
- rc = shirudo_eventlog_boot_init(&rec);
+ rc = eventlog_boot_init(&rec);
if (rc && rc != -ENOENT) {
pr_err("tpm: eventlog %s unreadable: %s; not binding register "
- "0x%08x", shirudo_eventlog_path(), strerror(-rc),
+ "0x%08x", eventlog_path(), strerror(-rc),
SHIRUDO_NV_INDEX);
goto out;
}
@@ -263,8 +263,8 @@ int shirudo_chain_init(const __u8 event[32],
rec.reset_count == info->reset_count);
if (recorded) {
if (nv.defined && nv.written && name_equals(&nv, rec.name)) {
- rc = shirudo_tpm_nv_read(tpm, SHIRUDO_NV_INDEX,
- info->value);
+ rc = tpm_nv_read(tpm, SHIRUDO_NV_INDEX,
+ info->value);
if (rc)
goto out;
memcpy(info->name, nv.name, nv.name_len);
@@ -272,8 +272,8 @@ int shirudo_chain_init(const __u8 event[32],
memcpy(info->pcr_before, rec.pcr_before, 32);
memcpy(info->phase_before, rec.phase_before, 32);
memcpy(info->anchor_digest, rec.anchor_digest, 32);
- shirudo_chain_anchor(info->name, info->anchor,
- sizeof(info->anchor));
+ chain_anchor(info->name, info->anchor,
+ sizeof(info->anchor));
info->initrd = rec.initrd;
info->reused = true;
goto out;
@@ -289,13 +289,13 @@ int shirudo_chain_init(const __u8 event[32],
pr_warn("tpm: register 0x%08x written this boot without a "
"record; rebinding it", SHIRUDO_NV_INDEX);
- rc = shirudo_tpm_pcr_read(tpm, SHIRUDO_CHAIN_PCR, info->pcr_before);
+ rc = tpm_pcr_read(tpm, SHIRUDO_CHAIN_PCR, info->pcr_before);
if (!rc)
- rc = shirudo_tpm_pcr_read(tpm, SHIRUDO_CHAIN_PHASE_PCR,
- info->phase_before);
+ rc = tpm_pcr_read(tpm, SHIRUDO_CHAIN_PHASE_PCR,
+ info->phase_before);
if (rc)
goto out;
- info->initrd = shirudo_in_initrd();
+ info->initrd = in_initrd();
register_expectation(info->pcr_before, info->phase_before,
branch_written, branch_init, policy, unwritten,
written);
@@ -304,7 +304,7 @@ int shirudo_chain_init(const __u8 event[32],
rc = register_define(tpm, nv.defined, policy);
if (rc)
goto out;
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
if (!nv.defined || !name_equals(&nv, unwritten)) {
@@ -315,48 +315,48 @@ int shirudo_chain_init(const __u8 event[32],
}
}
- rc = shirudo_tpm_nv_extend_first(tpm, SHIRUDO_NV_INDEX,
- SHIRUDO_CHAIN_PCR_MASK, branch_written,
- branch_init, event);
+ rc = tpm_nv_extend_first(tpm, SHIRUDO_NV_INDEX,
+ SHIRUDO_CHAIN_PCR_MASK, branch_written,
+ branch_init, event);
if (rc)
goto out;
memcpy(info->name, written, sizeof(written));
info->name_len = sizeof(written);
- shirudo_chain_anchor(info->name, info->anchor, sizeof(info->anchor));
+ chain_anchor(info->name, info->anchor, sizeof(info->anchor));
shirudo_sha256(info->anchor, strlen(info->anchor), info->anchor_digest);
- rc = shirudo_tpm_pcr_extend(tpm, SHIRUDO_CHAIN_PCR,
- info->anchor_digest);
+ rc = tpm_pcr_extend(tpm, SHIRUDO_CHAIN_PCR,
+ info->anchor_digest);
if (rc) {
pr_err("tpm: register written but PCR %u not anchored; "
"the init branch stays open until reboot",
SHIRUDO_CHAIN_PCR);
goto out;
}
- rc = shirudo_tpm_nv_read(tpm, SHIRUDO_NV_INDEX, info->value);
+ rc = tpm_nv_read(tpm, SHIRUDO_NV_INDEX, info->value);
out:
- shirudo_tpm_close(tpm);
+ tpm_close(tpm);
return rc;
}
-int shirudo_chain_extend(const __u8 event[32], __u8 out_chain[32])
+int chain_extend(const __u8 event[32], __u8 out_chain[32])
{
__u8 branch_written[32], branch_init[32], policy[32], values[64];
struct shirudo_eventlog_init rec;
- struct shirudo_tpm_nv_info nv;
+ struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
int rc;
- rc = shirudo_eventlog_boot_init(&rec);
+ rc = eventlog_boot_init(&rec);
if (rc)
return -ENODEV; /* no register this boot */
bind_values(rec.pcr_before, rec.phase_before, values);
- shirudo_tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, values, 2,
- branch_written, branch_init, policy);
+ tpm_register_policy(SHIRUDO_CHAIN_PCR_MASK, values, 2,
+ branch_written, branch_init, policy);
- rc = shirudo_tpm_open(&tpm);
+ rc = tpm_open(&tpm);
if (rc)
return -ENODEV;
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
if (!nv.defined || !nv.written) {
@@ -369,51 +369,51 @@ int shirudo_chain_extend(const __u8 event[32], __u8 out_chain[32])
rc = -EACCES;
goto out;
}
- rc = shirudo_tpm_nv_extend(tpm, SHIRUDO_NV_INDEX, branch_written,
- branch_init, event);
+ rc = tpm_nv_extend(tpm, SHIRUDO_NV_INDEX, branch_written,
+ branch_init, event);
if (rc) {
rc = -EIO;
goto out;
}
if (out_chain)
- rc = shirudo_tpm_nv_read(tpm, SHIRUDO_NV_INDEX, out_chain) ?
+ rc = tpm_nv_read(tpm, SHIRUDO_NV_INDEX, out_chain) ?
-EIO : 0;
out:
- shirudo_tpm_close(tpm);
+ tpm_close(tpm);
return rc;
}
-int shirudo_chain_read(__u8 out[32])
+int chain_read(__u8 out[32])
{
struct shirudo_tpm *tpm = NULL;
int rc;
- rc = shirudo_tpm_open(&tpm);
+ rc = tpm_open(&tpm);
if (rc)
return -ENODEV;
- rc = shirudo_tpm_nv_read(tpm, SHIRUDO_NV_INDEX, out);
- shirudo_tpm_close(tpm);
+ rc = tpm_nv_read(tpm, SHIRUDO_NV_INDEX, out);
+ tpm_close(tpm);
return rc ? -ENODEV : 0;
}
-int shirudo_chain_status(struct shirudo_chain_status *st)
+int chain_status(struct chain_status *st)
{
- struct shirudo_tpm_nv_info nv;
+ struct tpm_nv_info nv;
struct shirudo_tpm *tpm = NULL;
__u32 reset_count = 0;
int rc;
memset(st, 0, sizeof(*st));
- st->logged = shirudo_eventlog_boot_init(&st->init) == 0;
+ st->logged = eventlog_boot_init(&st->init) == 0;
st->rebound = st->logged && st->init.records_epoch > 1;
- rc = shirudo_tpm_open(&tpm);
+ rc = tpm_open(&tpm);
if (rc)
return -ENODEV;
st->tpm = true;
- rc = shirudo_tpm_reset_count(tpm, &reset_count);
+ rc = tpm_reset_count(tpm, &reset_count);
if (rc)
goto out;
- rc = shirudo_tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
+ rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
st->defined = nv.defined;
@@ -421,12 +421,12 @@ int shirudo_chain_status(struct shirudo_chain_status *st)
memcpy(st->name, nv.name, nv.name_len);
st->name_len = nv.name_len;
if (nv.defined && nv.written)
- rc = shirudo_tpm_nv_read(tpm, SHIRUDO_NV_INDEX, st->value);
+ rc = tpm_nv_read(tpm, SHIRUDO_NV_INDEX, st->value);
st->anchored = nv.defined && nv.written && st->logged &&
name_equals(&nv, st->init.name) &&
(!st->init.have_reset_count ||
st->init.reset_count == reset_count);
out:
- shirudo_tpm_close(tpm);
+ tpm_close(tpm);
return rc;
}
diff --git a/util/chain.h b/util/chain.h
index e1c8e844..b16ece1d 100644
--- a/util/chain.h
+++ b/util/chain.h
@@ -37,12 +37,12 @@
void shirudo_sha256(const void *data, size_t len,
__u8 out[SHIRUDO_CHAIN_DIGEST_LEN]);
-void shirudo_sha256_2(const void *a, size_t a_len,
- const void *b, size_t b_len,
- __u8 out[SHIRUDO_CHAIN_DIGEST_LEN]);
+void sha256_2(const void *a, size_t a_len,
+ const void *b, size_t b_len,
+ __u8 out[SHIRUDO_CHAIN_DIGEST_LEN]);
/* Constant time; 1 when equal. */
-int shirudo_ct_eq(const void *a, const void *b, size_t n);
+int ct_eq(const void *a, const void *b, size_t n);
struct shirudo_measured_upatch {
char name[SHIRUDO_UPATCH_NAME_MAX + 1];
@@ -53,22 +53,22 @@ struct shirudo_measured_upatch {
* The event digests every measuring path and the predictor share.
* The set is sorted by name before hashing.
*/
-void shirudo_chain_init_event(const __u8 cert_sha[32],
- struct shirudo_measured_upatch *set, size_t n,
- const __u8 tree_root[32],
- __u8 set_digest[32], __u8 event[32]);
+void chain_init_event(const __u8 cert_sha[32],
+ struct shirudo_measured_upatch *set, size_t n,
+ const __u8 tree_root[32],
+ __u8 set_digest[32], __u8 event[32]);
/* SHA256(tag || NUL || cert_sha256), tag "shirudo-key-revoke". */
-void shirudo_chain_key_event(const char *tag, const __u8 cert_sha[32],
- __u8 event[32]);
-void shirudo_chain_upatch_event(const char *tag, const char *name,
- const __u8 payload[32], __u8 event[32]);
-void shirudo_chain_tree_event(__s64 seq, const __u8 operation_digest[32],
- __u8 event[32]);
-void shirudo_chain_fold(__u8 chain[32], const __u8 event[32]);
+void chain_key_event(const char *tag, const __u8 cert_sha[32],
+ __u8 event[32]);
+void chain_upatch_event(const char *tag, const char *name,
+ const __u8 payload[32], __u8 event[32]);
+void chain_tree_event(__s64 seq, const __u8 operation_digest[32],
+ __u8 event[32]);
+void chain_fold(__u8 chain[32], const __u8 event[32]);
/* The PCR record anchoring a register name: nvpcr-init:shirudo:0x..:<name>. */
-void shirudo_chain_anchor(const __u8 name[SHIRUDO_TPM_NAME_LEN],
- char *out, size_t cap);
+void chain_anchor(const __u8 name[SHIRUDO_TPM_NAME_LEN],
+ char *out, size_t cap);
struct shirudo_chain_init_info {
bool reused; /* written and on record */
@@ -91,8 +91,8 @@ struct shirudo_chain_init_info {
* when the owner hierarchy refuses, -EPROTO when the TPM's name is not
* the computed one.
*/
-int shirudo_chain_init(const __u8 event[SHIRUDO_CHAIN_DIGEST_LEN],
- struct shirudo_chain_init_info *info);
+int chain_init(const __u8 event[SHIRUDO_CHAIN_DIGEST_LEN],
+ struct shirudo_chain_init_info *info);
/*
* Extend this boot's register by one event through the written
@@ -100,13 +100,13 @@ int shirudo_chain_init(const __u8 event[SHIRUDO_CHAIN_DIGEST_LEN],
* init record, index unwritten), -EACCES when the index on the TPM is
* not the one init recorded (recreated), -EIO on a TPM failure.
*/
-int shirudo_chain_extend(const __u8 event[SHIRUDO_CHAIN_DIGEST_LEN],
- __u8 out_chain[SHIRUDO_CHAIN_DIGEST_LEN]);
+int chain_extend(const __u8 event[SHIRUDO_CHAIN_DIGEST_LEN],
+ __u8 out_chain[SHIRUDO_CHAIN_DIGEST_LEN]);
/* The live value; -ENODEV when no register is written this boot. */
-int shirudo_chain_read(__u8 out[SHIRUDO_CHAIN_DIGEST_LEN]);
+int chain_read(__u8 out[SHIRUDO_CHAIN_DIGEST_LEN]);
-struct shirudo_chain_status {
+struct chain_status {
bool tpm; /* a TPM answered */
bool defined;
bool written;
@@ -119,6 +119,6 @@ struct shirudo_chain_status {
struct shirudo_eventlog_init init;
};
-int shirudo_chain_status(struct shirudo_chain_status *st);
+int chain_status(struct chain_status *st);
#endif /* SHIRUDO_CHAIN_H */
diff --git a/util/conditions.c b/util/conditions.c
index b8463e97..426c66c3 100644
--- a/util/conditions.c
+++ b/util/conditions.c
@@ -12,8 +12,8 @@
#include "conditions.h"
-size_t shirudo_conditions(const struct shirudo_conditions_input *in,
- struct shirudo_condition *c, size_t cap)
+size_t conditions(const struct shirudo_conditions_input *in,
+ struct shirudo_condition *c, size_t cap)
{
size_t n = 0;
@@ -91,7 +91,7 @@ size_t shirudo_conditions(const struct shirudo_conditions_input *in,
return n;
}
-void shirudo_conditions_print(const struct shirudo_condition *c, size_t n)
+void conditions_print(const struct shirudo_condition *c, size_t n)
{
size_t i;
@@ -102,7 +102,7 @@ void shirudo_conditions_print(const struct shirudo_condition *c, size_t n)
c[i].detail);
}
-const char *shirudo_status_verdict(const struct shirudo_conditions_input *in)
+const char *status_verdict(const struct shirudo_conditions_input *in)
{
if (!in->reachable)
return "unreachable";
@@ -120,10 +120,10 @@ const char *shirudo_status_verdict(const struct shirudo_conditions_input *in)
return "ok";
}
-void shirudo_status_reason(const struct shirudo_conditions_input *in,
- char *buf, size_t cap)
+void status_reason(const struct shirudo_conditions_input *in,
+ char *buf, size_t cap)
{
- const char *v = shirudo_status_verdict(in);
+ const char *v = status_verdict(in);
buf[0] = '\0';
if (strcmp(v, "unreachable") == 0) {
diff --git a/util/conditions.h b/util/conditions.h
index 25f90f15..a0d42501 100644
--- a/util/conditions.h
+++ b/util/conditions.h
@@ -49,10 +49,10 @@ struct shirudo_condition {
*/
#define SHIRUDO_CONDITIONS_MAX 4
-size_t shirudo_conditions(const struct shirudo_conditions_input *in,
- struct shirudo_condition *out, size_t cap);
+size_t conditions(const struct shirudo_conditions_input *in,
+ struct shirudo_condition *out, size_t cap);
-void shirudo_conditions_print(const struct shirudo_condition *c, size_t n);
+void conditions_print(const struct shirudo_condition *c, size_t n);
/*
* Single-word aggregate verdict (severity worst -> best):
@@ -60,9 +60,9 @@ void shirudo_conditions_print(const struct shirudo_condition *c, size_t n);
* init-pending -> degraded -> ok
* Used by the `Status:` line in `shirudo status` and its JSON output.
*/
-const char *shirudo_status_verdict(const struct shirudo_conditions_input *in);
+const char *status_verdict(const struct shirudo_conditions_input *in);
-void shirudo_status_reason(const struct shirudo_conditions_input *in,
- char *buf, size_t cap);
+void status_reason(const struct shirudo_conditions_input *in,
+ char *buf, size_t cap);
#endif /* SHIRUDO_CONDITIONS_H */
diff --git a/util/config.c b/util/config.c
index 80814e1b..6a4fa1c5 100644
--- a/util/config.c
+++ b/util/config.c
@@ -93,8 +93,8 @@ static void set_owner_auth(struct shirudo_config *cfg, const char *val)
}
/* An ignored value must leave the one set before intact. */
for (i = 0; i < hl / 2; i++) {
- int hi = shirudo_hex_nibble(h[2 * i]);
- int lo = shirudo_hex_nibble(h[2 * i + 1]);
+ int hi = hex_nibble(h[2 * i]);
+ int lo = hex_nibble(h[2 * i + 1]);
if (hi < 0 || lo < 0) {
pr_warn("config: tpm.owner_auth: bad hex "
@@ -119,7 +119,7 @@ static void set_owner_auth(struct shirudo_config *cfg, const char *val)
cfg->tpm_owner_auth_len = l;
}
-int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
+int config_load_path(struct shirudo_config *cfg, const char *path)
{
char line[SHIRUDO_MAP_EXPORT_PATH_MAX + 128];
int rc = 0;
@@ -133,7 +133,7 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
if (!f) {
if (errno != ENOENT)
rc = -errno; /* still apply env override below */
- } else if (shirudo_check_trusted(fileno(f), path, false)) {
+ } else if (check_trusted(fileno(f), path, false)) {
fclose(f);
return -EPERM;
} else {
@@ -190,7 +190,7 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
sizeof(cfg->map_export_otel_endpoint), val))
map_export_bad(cfg, key, val, "value too long");
} else if (strcmp(key, "map_export.tenant_id") == 0) {
- if (val[0] && !shirudo_tenant_id_valid(val))
+ if (val[0] && !tenant_id_valid(val))
map_export_bad(cfg, key, val,
"expected 1..128 characters from "
"A-Z, a-z, 0-9, '.', '_', '-'");
@@ -239,7 +239,7 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
rc = -EIO;
/* The TPM owner's authorization is for no other user's eyes. */
if (cfg->tpm_owner_auth_len &&
- shirudo_check_trusted(fileno(f), path, true)) {
+ check_trusted(fileno(f), path, true)) {
explicit_bzero(cfg->tpm_owner_auth,
sizeof(cfg->tpm_owner_auth));
cfg->tpm_owner_auth_len = 0;
@@ -257,12 +257,12 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
return rc;
}
-int shirudo_config_load(struct shirudo_config *cfg)
+int config_load(struct shirudo_config *cfg)
{
const char *env;
int rc;
- rc = shirudo_config_load_path(cfg, SHIRUDO_CONF_PATH);
+ rc = config_load_path(cfg, SHIRUDO_CONF_PATH);
if (rc && rc != -ENOENT)
return rc;
diff --git a/util/config.h b/util/config.h
index 4ed47d87..974ca8e7 100644
--- a/util/config.h
+++ b/util/config.h
@@ -49,9 +49,9 @@ struct shirudo_config {
};
/* A missing file is not an error. */
-int shirudo_config_load(struct shirudo_config *cfg);
+int config_load(struct shirudo_config *cfg);
-/* Testable path-specific loader; unlike shirudo_config_load(), no env. */
-int shirudo_config_load_path(struct shirudo_config *cfg, const char *path);
+/* Testable path-specific loader; unlike config_load(), no env. */
+int config_load_path(struct shirudo_config *cfg, const char *path);
#endif /* SHIRUDO_CONFIG_H */
diff --git a/util/crypto.h b/util/crypto.h
index a16b6895..7d4aa1ea 100644
--- a/util/crypto.h
+++ b/util/crypto.h
@@ -23,50 +23,50 @@ struct shirudo_sha256_ctx {
void *impl;
};
-int shirudo_sha256_init(struct shirudo_sha256_ctx *ctx);
-int shirudo_sha256_update(struct shirudo_sha256_ctx *ctx,
- const void *data, size_t len);
-int shirudo_sha256_final(struct shirudo_sha256_ctx *ctx,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
-void shirudo_sha256_free(struct shirudo_sha256_ctx *ctx);
-int shirudo_sha256_buffer(const void *data, size_t len,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
-int shirudo_base64_encode(const __u8 *data, size_t len,
- char *out, size_t out_sz);
+int sha256_init(struct shirudo_sha256_ctx *ctx);
+int sha256_update(struct shirudo_sha256_ctx *ctx,
+ const void *data, size_t len);
+int sha256_final(struct shirudo_sha256_ctx *ctx,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
+void sha256_free(struct shirudo_sha256_ctx *ctx);
+int sha256_buffer(const void *data, size_t len,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
+int base64_encode(const __u8 *data, size_t len,
+ char *out, size_t out_sz);
/* 0 when valid, -EKEYREJECTED when not. */
-int shirudo_ecdsa_p256_verify(const __u8 x[32], const __u8 y[32],
- const __u8 digest[SHIRUDO_CRYPTO_SHA256_LEN],
- const __u8 r[32], const __u8 s[32]);
+int ecdsa_p256_verify(const __u8 x[32], const __u8 y[32],
+ const __u8 digest[SHIRUDO_CRYPTO_SHA256_LEN],
+ const __u8 r[32], const __u8 s[32]);
struct shirudo_cert {
void *impl;
};
-int shirudo_cert_read_file(const char *path, struct shirudo_cert *cert);
-void shirudo_cert_free(struct shirudo_cert *cert);
-int shirudo_cert_pubkey_digest(const struct shirudo_cert *cert,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
+int cert_read_file(const char *path, struct shirudo_cert *cert);
+void cert_free(struct shirudo_cert *cert);
+int cert_pubkey_digest(const struct shirudo_cert *cert,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
/* The provider's name for the cert's public key, e.g. "ML-DSA-87". */
-int shirudo_cert_key_algorithm(const struct shirudo_cert *cert,
- char *out, size_t out_sz);
-int shirudo_verify_detached(const __u8 *payload, size_t payload_len,
- const __u8 *signature, size_t signature_len,
- const struct shirudo_cert *cert);
+int cert_key_algorithm(const struct shirudo_cert *cert,
+ char *out, size_t out_sz);
+int verify_detached(const __u8 *payload, size_t payload_len,
+ const __u8 *signature, size_t signature_len,
+ const struct shirudo_cert *cert);
/*
* Whether a signer of the CMS blob names this certificate, by key id
* or by issuer and serial: 1 when one does, 0 when none, -EINVAL when
* the blob does not parse. Says nothing about the signature's validity.
*/
-int shirudo_cms_signed_by(const __u8 *signature, size_t signature_len,
- const struct shirudo_cert *cert);
+int cms_signed_by(const __u8 *signature, size_t signature_len,
+ const struct shirudo_cert *cert);
struct shirudo_tls_ca {
const char *path;
void *impl;
};
-void shirudo_tls_ca_cleanup(struct shirudo_tls_ca *ca);
+void tls_ca_cleanup(struct shirudo_tls_ca *ca);
/*
* shirudo's TLS policy for every libcurl handle it opens: TLS 1.3 only
@@ -76,40 +76,40 @@ void shirudo_tls_ca_cleanup(struct shirudo_tls_ca *ca);
* trust anchor fed to the SSL_CTX callback. Returns 0 or a negative
* errno; callers must not connect when it fails.
*/
-int shirudo_tls_curl_policy(CURL *curl, struct shirudo_tls_ca *ca);
+int tls_curl_policy(CURL *curl, struct shirudo_tls_ca *ca);
-int shirudo_hmac_sha256(const __u8 *key, size_t key_len,
- const void *data, size_t len,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
+int hmac_sha256(const __u8 *key, size_t key_len,
+ const void *data, size_t len,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN]);
/* AES-128 in CFB mode with a zero IV and no padding. */
-int shirudo_aes128_cfb_encrypt(const __u8 key[16], const __u8 *in,
- size_t len, __u8 *out);
+int aes128_cfb_encrypt(const __u8 key[16], const __u8 *in,
+ size_t len, __u8 *out);
/*
* RSA-OAEP with SHA-256, MGF1-SHA-256 and the given label to the
* modulus n with the public exponent e (0 for 65537).
*/
-int shirudo_rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
- const void *label, size_t label_len,
- const __u8 *in, size_t in_len,
- __u8 *out, size_t cap, size_t *out_len);
+int rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
+ const void *label, size_t label_len,
+ const __u8 *in, size_t in_len,
+ __u8 *out, size_t cap, size_t *out_len);
/*
* One ephemeral P-256 ECDH against the point (x, y): the ephemeral
* public point and the shared secret's x coordinate.
*/
-int shirudo_ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
- __u8 eph_x[32], __u8 eph_y[32],
- __u8 z[32]);
+int ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
+ __u8 eph_x[32], __u8 eph_y[32],
+ __u8 z[32]);
-int shirudo_base64_decode(const char *in, size_t in_len, __u8 *out,
- size_t cap, size_t *out_len);
+int base64_decode(const char *in, size_t in_len, __u8 *out,
+ size_t cap, size_t *out_len);
-int shirudo_cert_read_der(const __u8 *der, size_t len,
- struct shirudo_cert *cert);
+int cert_read_der(const __u8 *der, size_t len,
+ struct shirudo_cert *cert);
-struct shirudo_cert_pubkey {
+struct cert_pubkey {
bool rsa;
__u8 n[512];
size_t n_len;
@@ -118,18 +118,18 @@ struct shirudo_cert_pubkey {
__u8 y[32];
};
-int shirudo_cert_pubkey(const struct shirudo_cert *cert,
- struct shirudo_cert_pubkey *out);
+int cert_pubkey(const struct shirudo_cert *cert,
+ struct cert_pubkey *out);
/*
* Chain the certificate to the PEM bundle of trusted issuers at path.
* -EKEYREJECTED when it does not chain, with *reason set to libcrypto's
* static explanation; -EINVAL when the bundle cannot be loaded.
*/
-int shirudo_cert_verify_chain(const struct shirudo_cert *cert,
- const char *bundle_path, const char **reason);
+int cert_verify_chain(const struct shirudo_cert *cert,
+ const char *bundle_path, const char **reason);
/* Log libcrypto's last error under where. */
-void shirudo_openssl_complain(const char *where);
+void openssl_complain(const char *where);
#endif /* SHIRUDO_CRYPTO_H */
diff --git a/util/crypto_openssl.c b/util/crypto_openssl.c
index 248e8257..b060dcd9 100644
--- a/util/crypto_openssl.c
+++ b/util/crypto_openssl.c
@@ -41,7 +41,7 @@ static X509 *read_x509(const char *path)
if (fd < 0)
return NULL;
- if (shirudo_check_trusted(fd, path, false)) {
+ if (check_trusted(fd, path, false)) {
close(fd);
return NULL;
}
@@ -63,7 +63,7 @@ static X509 *read_x509(const char *path)
return cert;
}
-int shirudo_sha256_init(struct shirudo_sha256_ctx *ctx)
+int sha256_init(struct shirudo_sha256_ctx *ctx)
{
EVP_MD_CTX *md;
@@ -79,16 +79,16 @@ int shirudo_sha256_init(struct shirudo_sha256_ctx *ctx)
return 0;
}
-int shirudo_sha256_update(struct shirudo_sha256_ctx *ctx,
- const void *data, size_t len)
+int sha256_update(struct shirudo_sha256_ctx *ctx,
+ const void *data, size_t len)
{
if (!ctx || !ctx->impl || (len && !data))
return -EINVAL;
return EVP_DigestUpdate(ctx->impl, data, len) == 1 ? 0 : -EIO;
}
-int shirudo_sha256_final(struct shirudo_sha256_ctx *ctx,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN])
+int sha256_final(struct shirudo_sha256_ctx *ctx,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN])
{
__u32 len = 0;
int rc;
@@ -101,7 +101,7 @@ int shirudo_sha256_final(struct shirudo_sha256_ctx *ctx,
return rc;
}
-void shirudo_sha256_free(struct shirudo_sha256_ctx *ctx)
+void sha256_free(struct shirudo_sha256_ctx *ctx)
{
if (!ctx)
return;
@@ -109,24 +109,24 @@ void shirudo_sha256_free(struct shirudo_sha256_ctx *ctx)
ctx->impl = NULL;
}
-int shirudo_sha256_buffer(const void *data, size_t len,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN])
+int sha256_buffer(const void *data, size_t len,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN])
{
struct shirudo_sha256_ctx ctx;
int rc;
- rc = shirudo_sha256_init(&ctx);
+ rc = sha256_init(&ctx);
if (!rc)
- rc = shirudo_sha256_update(&ctx, data, len);
+ rc = sha256_update(&ctx, data, len);
if (!rc)
- rc = shirudo_sha256_final(&ctx, out);
+ rc = sha256_final(&ctx, out);
else
- shirudo_sha256_free(&ctx);
+ sha256_free(&ctx);
return rc;
}
-int shirudo_base64_encode(const __u8 *data, size_t len,
- char *out, size_t out_sz)
+int base64_encode(const __u8 *data, size_t len,
+ char *out, size_t out_sz)
{
size_t need = 4 * ((len + 2) / 3) + 1;
@@ -138,9 +138,9 @@ int shirudo_base64_encode(const __u8 *data, size_t len,
return 0;
}
-int shirudo_ecdsa_p256_verify(const __u8 x[32], const __u8 y[32],
- const __u8 digest[32],
- const __u8 r[32], const __u8 s[32])
+int ecdsa_p256_verify(const __u8 x[32], const __u8 y[32],
+ const __u8 digest[32],
+ const __u8 r[32], const __u8 s[32])
{
__u8 point[65], *der = NULL;
EVP_PKEY_CTX *kctx = NULL, *vctx = NULL;
@@ -192,7 +192,7 @@ out:
return rc;
}
-int shirudo_cert_read_file(const char *path, struct shirudo_cert *cert)
+int cert_read_file(const char *path, struct shirudo_cert *cert)
{
if (!path || !cert)
return -EINVAL;
@@ -200,7 +200,7 @@ int shirudo_cert_read_file(const char *path, struct shirudo_cert *cert)
return cert->impl ? 0 : -EINVAL;
}
-void shirudo_cert_free(struct shirudo_cert *cert)
+void cert_free(struct shirudo_cert *cert)
{
if (!cert)
return;
@@ -214,8 +214,8 @@ void shirudo_cert_free(struct shirudo_cert *cert)
* X.509 parser accepts, including ML-DSA keys libcrypto cannot otherwise
* marshal as a bare EVP_PKEY on older releases.
*/
-int shirudo_cert_pubkey_digest(const struct shirudo_cert *cert,
- __u8 out[SHIRUDO_CRYPTO_SHA256_LEN])
+int cert_pubkey_digest(const struct shirudo_cert *cert,
+ __u8 out[SHIRUDO_CRYPTO_SHA256_LEN])
{
__u8 *der = NULL, *p;
int der_len, encoded_len, rc = -EINVAL;
@@ -246,8 +246,8 @@ out:
return rc;
}
-int shirudo_cert_key_algorithm(const struct shirudo_cert *cert,
- char *out, size_t out_sz)
+int cert_key_algorithm(const struct shirudo_cert *cert,
+ char *out, size_t out_sz)
{
const char *name;
EVP_PKEY *pub;
@@ -267,9 +267,9 @@ int shirudo_cert_key_algorithm(const struct shirudo_cert *cert,
* with signedAttrs and SHA-512 or bare on OpenSSL 4, and an RSA one
* verify through one call; ML-DSA needs libcrypto >= 3.5.
*/
-int shirudo_verify_detached(const __u8 *payload, size_t payload_len,
- const __u8 *signature, size_t signature_len,
- const struct shirudo_cert *cert)
+int verify_detached(const __u8 *payload, size_t payload_len,
+ const __u8 *signature, size_t signature_len,
+ const struct shirudo_cert *cert)
{
BIO *sig = NULL, *data = NULL, *out = NULL;
CMS_ContentInfo *cms = NULL;
@@ -307,8 +307,8 @@ done:
return rc;
}
-int shirudo_cms_signed_by(const __u8 *signature, size_t signature_len,
- const struct shirudo_cert *cert)
+int cms_signed_by(const __u8 *signature, size_t signature_len,
+ const struct shirudo_cert *cert)
{
STACK_OF(CMS_SignerInfo) *sis;
CMS_ContentInfo *cms = NULL;
@@ -340,8 +340,8 @@ done:
return rc;
}
-int shirudo_hmac_sha256(const __u8 *key, size_t key_len,
- const void *data, size_t len, __u8 out[32])
+int hmac_sha256(const __u8 *key, size_t key_len,
+ const void *data, size_t len, __u8 out[32])
{
EVP_MAC_CTX *ctx = NULL;
OSSL_PARAM params[2];
@@ -365,8 +365,8 @@ int shirudo_hmac_sha256(const __u8 *key, size_t key_len,
return rc;
}
-int shirudo_aes128_cfb_encrypt(const __u8 key[16], const __u8 *in,
- size_t len, __u8 *out)
+int aes128_cfb_encrypt(const __u8 key[16], const __u8 *in,
+ size_t len, __u8 *out)
{
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
int n = 0, fin = 0, rc = -EIO;
@@ -385,10 +385,10 @@ out:
return rc;
}
-int shirudo_rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
- const void *label, size_t label_len,
- const __u8 *in, size_t in_len,
- __u8 *out, size_t cap, size_t *out_len)
+int rsa_oaep_encrypt(const __u8 *n, size_t n_len, __u32 e,
+ const void *label, size_t label_len,
+ const __u8 *in, size_t in_len,
+ __u8 *out, size_t cap, size_t *out_len)
{
EVP_PKEY_CTX *kctx = NULL, *ectx = NULL;
BIGNUM *bn = NULL, *be = NULL;
@@ -442,9 +442,9 @@ out:
return rc;
}
-int shirudo_ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
- __u8 eph_x[32], __u8 eph_y[32],
- __u8 z[32])
+int ecdh_p256_ephemeral(const __u8 x[32], const __u8 y[32],
+ __u8 eph_x[32], __u8 eph_y[32],
+ __u8 z[32])
{
EVP_PKEY_CTX *kctx = NULL, *dctx = NULL;
EVP_PKEY *eph = NULL, *peer = NULL;
@@ -490,8 +490,8 @@ out:
return rc;
}
-int shirudo_base64_decode(const char *in, size_t in_len, __u8 *out,
- size_t cap, size_t *out_len)
+int base64_decode(const char *in, size_t in_len, __u8 *out,
+ size_t cap, size_t *out_len)
{
EVP_ENCODE_CTX *ctx = EVP_ENCODE_CTX_new();
int n = 0, fin = 0, rc = -EINVAL;
@@ -510,8 +510,8 @@ out:
return rc;
}
-int shirudo_cert_read_der(const __u8 *der, size_t len,
- struct shirudo_cert *cert)
+int cert_read_der(const __u8 *der, size_t len,
+ struct shirudo_cert *cert)
{
const __u8 *p = der;
@@ -521,8 +521,8 @@ int shirudo_cert_read_der(const __u8 *der, size_t len,
return cert->impl ? 0 : -EINVAL;
}
-int shirudo_cert_pubkey(const struct shirudo_cert *cert,
- struct shirudo_cert_pubkey *out)
+int cert_pubkey(const struct shirudo_cert *cert,
+ struct cert_pubkey *out)
{
BIGNUM *a = NULL, *b = NULL;
char group[32] = "";
@@ -562,8 +562,8 @@ out:
return rc;
}
-int shirudo_cert_verify_chain(const struct shirudo_cert *cert,
- const char *bundle_path, const char **reason)
+int cert_verify_chain(const struct shirudo_cert *cert,
+ const char *bundle_path, const char **reason)
{
X509_STORE_CTX *ctx = NULL;
X509_STORE *store;
@@ -596,7 +596,7 @@ out:
return rc;
}
-void shirudo_openssl_complain(const char *where)
+void openssl_complain(const char *where)
{
char buf[256];
diff --git a/util/elf_target.c b/util/elf_target.c
index 36b27182..dbb01e50 100644
--- a/util/elf_target.c
+++ b/util/elf_target.c
@@ -120,9 +120,9 @@ static int elf_build_id(Elf *elf,
return -ENOENT;
}
-int shirudo_elf_build_id_fd(int fd,
- __u8 build_id[SHIRUDO_UPATCH_BUILD_ID_MAX],
- __u32 *build_id_len)
+int elf_build_id_fd(int fd,
+ __u8 build_id[SHIRUDO_UPATCH_BUILD_ID_MAX],
+ __u32 *build_id_len)
{
Elf *elf;
int err;
@@ -143,8 +143,8 @@ int shirudo_elf_build_id_fd(int fd,
return err;
}
-int shirudo_elf_target_resolve(const char *path, const char *pattern,
- struct shirudo_elf_target *out)
+int elf_target_resolve(const char *path, const char *pattern,
+ struct shirudo_elf_target *out)
{
Elf *elf = NULL;
unsigned long *resolved_offsets = NULL;
@@ -195,7 +195,7 @@ int shirudo_elf_target_resolve(const char *path, const char *pattern,
for (i = 0; i < nr_resolved; i++)
out->offsets[i] = resolved_offsets[i];
out->nr_offsets = (__u32)nr_resolved;
- shirudo_libc_free(resolved_offsets);
+ libc_free(resolved_offsets);
resolved_offsets = NULL;
qsort(out->offsets, out->nr_offsets, sizeof(*out->offsets), u64_cmp);
@@ -210,13 +210,13 @@ out:
elf_end(elf);
if (fd >= 0)
close(fd);
- shirudo_libc_free(resolved_offsets);
+ libc_free(resolved_offsets);
if (err)
- shirudo_elf_target_free(out);
+ elf_target_free(out);
return err;
}
-void shirudo_elf_target_free(struct shirudo_elf_target *target)
+void elf_target_free(struct shirudo_elf_target *target)
{
if (!target)
return;
diff --git a/util/elf_target.h b/util/elf_target.h
index e31f75ad..f44609e4 100644
--- a/util/elf_target.h
+++ b/util/elf_target.h
@@ -16,13 +16,13 @@ struct shirudo_elf_target {
__u32 nr_offsets;
};
-int shirudo_elf_target_resolve(const char *path, const char *pattern,
- struct shirudo_elf_target *out);
+int elf_target_resolve(const char *path, const char *pattern,
+ struct shirudo_elf_target *out);
-int shirudo_elf_build_id_fd(int fd,
- __u8 build_id[SHIRUDO_UPATCH_BUILD_ID_MAX],
- __u32 *build_id_len);
+int elf_build_id_fd(int fd,
+ __u8 build_id[SHIRUDO_UPATCH_BUILD_ID_MAX],
+ __u32 *build_id_len);
-void shirudo_elf_target_free(struct shirudo_elf_target *target);
+void elf_target_free(struct shirudo_elf_target *target);
#endif /* SHIRUDO_ELF_TARGET_H */
diff --git a/util/eventlog.c b/util/eventlog.c
index 9184346e..27716001 100644
--- a/util/eventlog.c
+++ b/util/eventlog.c
@@ -28,14 +28,14 @@
#include "paths.h"
#include "seal.h"
-const char *shirudo_eventlog_path(void)
+const char *eventlog_path(void)
{
const char *env = getenv("SHIRUDO_EVENTLOG_PATH");
return env && *env ? env : SHIRUDO_EVENTLOG_PATH;
}
-const char *shirudo_eventlog_pending_path(void)
+const char *eventlog_pending_path(void)
{
const char *env = getenv("SHIRUDO_EVENTLOG_PENDING_PATH");
@@ -49,14 +49,14 @@ static int adopt_pending(void);
* log: a line appended ahead of it would drop out of every replay, so
* the record is adopted first.
*/
-int shirudo_eventlog_append(const char *json_line)
+int eventlog_append(const char *json_line)
{
int rc;
rc = adopt_pending();
if (rc)
return rc;
- return shirudo_eventlog_append_to(shirudo_eventlog_path(), json_line);
+ return eventlog_append_to(eventlog_path(), json_line);
}
/*
@@ -64,13 +64,13 @@ int shirudo_eventlog_append(const char *json_line)
* of the log failing on it, so a failed append is rolled back under the
* lock that keeps appenders from interleaving.
*/
-int shirudo_eventlog_append_to(const char *path, const char *json_line)
+int eventlog_append_to(const char *path, const char *json_line)
{
size_t len = strlen(json_line);
struct stat st;
int fd, rc;
- fd = shirudo_seal_open(path, O_WRONLY | O_CREAT | O_APPEND, 0600);
+ fd = seal_open(path, O_WRONLY | O_CREAT | O_APPEND, 0600);
if (fd < 0) {
pr_err("eventlog: open %s: %s", path, strerror(-fd));
return fd;
@@ -86,9 +86,9 @@ int shirudo_eventlog_append_to(const char *path, const char *json_line)
goto out;
}
- rc = shirudo_write_all(fd, json_line, len);
+ rc = write_all(fd, json_line, len);
if (!rc && (len == 0 || json_line[len - 1] != '\n'))
- rc = shirudo_write_all(fd, "\n", 1);
+ rc = write_all(fd, "\n", 1);
if (!rc && fsync(fd) != 0)
rc = -errno;
if (rc && ftruncate(fd, st.st_size) != 0)
@@ -104,14 +104,14 @@ out:
return 0;
}
-int shirudo_eventlog_would_exceed(__u64 max_bytes)
+int eventlog_would_exceed(__u64 max_bytes)
{
struct stat st;
__u64 cur = 0;
if (max_bytes == 0)
return 0; /* unlimited */
- if (stat(shirudo_eventlog_path(), &st) == 0)
+ if (stat(eventlog_path(), &st) == 0)
cur = (__u64)st.st_size;
return cur + SHIRUDO_EVENTLOG_LINE_MAX > max_bytes;
}
@@ -122,13 +122,13 @@ static int read_log(char **out, size_t *out_len)
char *base = NULL, *pending = NULL, *buf;
int rc, rc_pending;
- rc = shirudo_read_file(shirudo_eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
- &base, &base_len);
+ rc = read_file(eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
+ &base, &base_len);
if (rc && rc != -ENOENT)
return rc;
- rc_pending = shirudo_read_file(shirudo_eventlog_pending_path(),
- SHIRUDO_JSON_MAX_BYTES, &pending,
- &pending_len);
+ rc_pending = read_file(eventlog_pending_path(),
+ SHIRUDO_JSON_MAX_BYTES, &pending,
+ &pending_len);
if (rc_pending && rc_pending != -ENOENT) {
xfree(base, base_len + 1);
return rc_pending;
@@ -181,7 +181,7 @@ static int walk_lines(char *buf, int (*cb)(const char *line, size_t len,
char *line, *save;
int rc = 0;
- shirudo_eventlog_boot_id(boot_id, sizeof(boot_id));
+ eventlog_boot_id(boot_id, sizeof(boot_id));
for (line = strtok_r(buf, "\n", &save); line && !rc;
line = strtok_r(NULL, "\n", &save)) {
struct shirudo_json_field f[] = {
@@ -194,7 +194,7 @@ static int walk_lines(char *buf, int (*cb)(const char *line, size_t len,
line_boot[0] = '\0';
type[0] = '\0';
- if (shirudo_json_parse(line, strlen(line), f, 2)) {
+ if (json_parse(line, strlen(line), f, 2)) {
rc = -EINVAL;
break;
}
@@ -250,8 +250,8 @@ static int log_holds(const char *line, size_t len)
size_t blen = 0;
int rc;
- rc = shirudo_read_file(shirudo_eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
- &buf, &blen);
+ rc = read_file(eventlog_path(), SHIRUDO_JSON_MAX_BYTES,
+ &buf, &blen);
if (rc == -ENOENT)
return 0;
if (rc)
@@ -265,12 +265,12 @@ static int log_holds(const char *line, size_t len)
static int adopt_pending(void)
{
- const char *pending = shirudo_eventlog_pending_path();
+ const char *pending = eventlog_pending_path();
char *buf = NULL, *line, *save;
size_t len = 0;
int rc;
- rc = shirudo_read_file(pending, SHIRUDO_JSON_MAX_BYTES, &buf, &len);
+ rc = read_file(pending, SHIRUDO_JSON_MAX_BYTES, &buf, &len);
if (rc == -ENOENT)
return 0;
if (rc)
@@ -285,8 +285,8 @@ static int adopt_pending(void)
continue;
}
if (!rc)
- rc = shirudo_eventlog_append_to(shirudo_eventlog_path(),
- line);
+ rc = eventlog_append_to(eventlog_path(),
+ line);
}
xfree(buf, len + 1);
if (rc)
@@ -296,7 +296,7 @@ static int adopt_pending(void)
return 0;
}
-int shirudo_eventlog_adopt_pending(void)
+int eventlog_adopt_pending(void)
{
return adopt_pending();
}
@@ -311,8 +311,8 @@ static int replay_line(const char *line, size_t len, bool is_init, void *ctx)
__u8 digest[32], cat[64];
__u8 *chain = ctx;
- if (shirudo_json_parse(line, len, f, 1) || !f[0].seen ||
- shirudo_hex_decode(digest_hex, digest, sizeof(digest)))
+ if (json_parse(line, len, f, 1) || !f[0].seen ||
+ hex_decode(digest_hex, digest, sizeof(digest)))
return -EINVAL;
if (is_init)
memset(chain, 0, 32);
@@ -322,7 +322,7 @@ static int replay_line(const char *line, size_t len, bool is_init, void *ctx)
return 0;
}
-int shirudo_eventlog_replay(__u8 out[32])
+int eventlog_replay(__u8 out[32])
{
__u8 chain[32] = {};
int rc;
@@ -359,14 +359,14 @@ static int init_line(const char *line, size_t len, bool is_init, void *ctx)
if (!is_init)
return 0;
bound_in[0] = '\0';
- if (shirudo_json_parse(line, len, f, 7) || !f[0].seen || !f[1].seen ||
+ if (json_parse(line, len, f, 7) || !f[0].seen || !f[1].seen ||
!f[2].seen || !f[3].seen || !f[5].seen || pcr < 0 || pcr >= 24 ||
(f[4].seen && (reset_count < 0 || reset_count > UINT32_MAX)) ||
strlen(name) != 2 * SHIRUDO_TPM_NAME_LEN ||
- shirudo_hex_decode(pcr_before, out->pcr_before, 32) ||
- shirudo_hex_decode(phase_before, out->phase_before, 32) ||
- shirudo_hex_decode(name, out->name, SHIRUDO_TPM_NAME_LEN) ||
- shirudo_hex_decode(anchor, out->anchor_digest, 32))
+ hex_decode(pcr_before, out->pcr_before, 32) ||
+ hex_decode(phase_before, out->phase_before, 32) ||
+ hex_decode(name, out->name, SHIRUDO_TPM_NAME_LEN) ||
+ hex_decode(anchor, out->anchor_digest, 32))
return -EINVAL;
out->initrd = f[6].seen && !strcmp(bound_in, "initrd");
/*
@@ -389,7 +389,7 @@ static int init_line(const char *line, size_t len, bool is_init, void *ctx)
return 0;
}
-int shirudo_eventlog_boot_init(struct shirudo_eventlog_init *out)
+int eventlog_boot_init(struct shirudo_eventlog_init *out)
{
memset(out, 0, sizeof(*out));
return walk_boot(init_line, out);
@@ -407,20 +407,20 @@ static int lines_line(const char *line, size_t len, bool is_init, void *ctx)
return l->cb(line, len, l->ctx);
}
-int shirudo_eventlog_boot_lines(int (*cb)(const char *line, size_t len,
- void *ctx), void *ctx)
+int eventlog_boot_lines(int (*cb)(const char *line, size_t len,
+ void *ctx), void *ctx)
{
struct lines_ctx l = { cb, ctx };
return walk_boot(lines_line, &l);
}
-void shirudo_eventlog_timestamp(char *out, size_t cap)
+void eventlog_timestamp(char *out, size_t cap)
{
- shirudo_iso8601(time(NULL), out, cap);
+ iso8601(time(NULL), out, cap);
}
-void shirudo_eventlog_boot_id(char *out, size_t cap)
+void eventlog_boot_id(char *out, size_t cap)
{
ssize_t n;
int fd;
diff --git a/util/eventlog.h b/util/eventlog.h
index dced5338..163f7042 100644
--- a/util/eventlog.h
+++ b/util/eventlog.h
@@ -22,7 +22,7 @@
#define SHIRUDO_EVENTLOG_LINE_MAX 4096
/* The on-disk path; SHIRUDO_EVENTLOG_PATH in the environment overrides it. */
-const char *shirudo_eventlog_path(void);
+const char *eventlog_path(void);
/*
* Where an init run from the initrd leaves its record until the root
@@ -30,20 +30,20 @@ const char *shirudo_eventlog_path(void);
* environment overrides it. Every reader below sees a pending record
* as part of this boot's log.
*/
-const char *shirudo_eventlog_pending_path(void);
+const char *eventlog_pending_path(void);
-int shirudo_eventlog_append(const char *json_line);
-int shirudo_eventlog_append_to(const char *path, const char *json_line);
+int eventlog_append(const char *json_line);
+int eventlog_append_to(const char *path, const char *json_line);
/* 0 when nothing was pending. */
-int shirudo_eventlog_adopt_pending(void);
+int eventlog_adopt_pending(void);
/*
* Replay this boot's records, from its last "init" record on, the way
* the register accumulates them. -ENOENT when this boot has no init
* record, -EINVAL on a malformed line.
*/
-int shirudo_eventlog_replay(__u8 out[SHIRUDO_TPM_DIGEST_LEN]);
+int eventlog_replay(__u8 out[SHIRUDO_TPM_DIGEST_LEN]);
/*
* What the last init record of this boot says about the register, and
@@ -64,10 +64,10 @@ struct shirudo_eventlog_init {
__u32 records_epoch; /* for this reset count */
};
-int shirudo_eventlog_boot_init(struct shirudo_eventlog_init *out);
+int eventlog_boot_init(struct shirudo_eventlog_init *out);
-int shirudo_eventlog_boot_lines(int (*cb)(const char *line, size_t len,
- void *ctx), void *ctx);
+int eventlog_boot_lines(int (*cb)(const char *line, size_t len,
+ void *ctx), void *ctx);
/*
* 1 if appending one more event would push the eventlog past max_bytes;
@@ -75,9 +75,9 @@ int shirudo_eventlog_boot_lines(int (*cb)(const char *line, size_t len,
* must stay in lockstep, so a caller refuses the whole operation (no
* PROG_LOAD, no extend, no append) when this returns 1.
*/
-int shirudo_eventlog_would_exceed(__u64 max_bytes);
+int eventlog_would_exceed(__u64 max_bytes);
-void shirudo_eventlog_timestamp(char *out, size_t cap); /* ISO-8601 UTC */
-void shirudo_eventlog_boot_id(char *out, size_t cap); /* /proc boot_id */
+void eventlog_timestamp(char *out, size_t cap); /* ISO-8601 UTC */
+void eventlog_boot_id(char *out, size_t cap); /* /proc boot_id */
#endif /* SHIRUDO_EVENTLOG_H */
diff --git a/util/format.c b/util/format.c
index 58efda88..f0285965 100644
--- a/util/format.c
+++ b/util/format.c
@@ -11,7 +11,7 @@
#include "format.h"
-void shirudo_human_size(__u64 bytes, char *out, size_t out_cap)
+void human_size(__u64 bytes, char *out, size_t out_cap)
{
double v = (double)bytes;
const char *suf = "B";
diff --git a/util/format.h b/util/format.h
index 06edc0d8..2a968484 100644
--- a/util/format.h
+++ b/util/format.h
@@ -17,6 +17,6 @@
* picked so the rendered value stays within four significant digits
* regardless of magnitude (16K / 1.8M / 5.57G / 1.23G / 124G).
*/
-void shirudo_human_size(__u64 bytes, char *out, size_t out_cap);
+void human_size(__u64 bytes, char *out, size_t out_cap);
#endif /* SHIRUDO_UTIL_FORMAT_H */
diff --git a/util/harden.c b/util/harden.c
index e2c7a76b..aa4e0168 100644
--- a/util/harden.c
+++ b/util/harden.c
@@ -19,7 +19,7 @@
* that number to the next file it opens, and what it prints lands in
* that file: point each closed one at /dev/null before anything opens.
*/
-void shirudo_harden_stdio(void)
+void harden_stdio(void)
{
int fd;
@@ -32,7 +32,7 @@ void shirudo_harden_stdio(void)
}
}
-void shirudo_harden_self(void)
+void harden_self(void)
{
struct rlimit no_core = { 0, 0 };
diff --git a/util/harden.h b/util/harden.h
index 860949f5..60aaf922 100644
--- a/util/harden.h
+++ b/util/harden.h
@@ -10,7 +10,7 @@
#include <stddef.h>
-void shirudo_harden_stdio(void);
-void shirudo_harden_self(void);
+void harden_stdio(void);
+void harden_self(void);
#endif /* SHIRUDO_HARDEN_H */
diff --git a/util/help.c b/util/help.c
index 1f719eea..9c743cc4 100644
--- a/util/help.c
+++ b/util/help.c
@@ -57,20 +57,20 @@ static void wrap_print(const char *text, size_t indent, size_t avail)
fputc('\n', stderr);
}
-int shirudo_is_help(const char *arg)
+int is_help(const char *arg)
{
return arg && (strcmp(arg, "help") == 0 ||
strcmp(arg, "--help") == 0 ||
strcmp(arg, "-h") == 0);
}
-int shirudo_is_list_cmds(const char *arg)
+int is_list_cmds(const char *arg)
{
return arg && strcmp(arg, "--list-cmds") == 0;
}
-void shirudo_print_subcmd_list(const struct shirudo_help_item *items,
- size_t n_items)
+void print_subcmd_list(const struct shirudo_help_item *items,
+ size_t n_items)
{
size_t i;
@@ -78,7 +78,7 @@ void shirudo_print_subcmd_list(const struct shirudo_help_item *items,
printf("%s\n", items[i].name);
}
-void shirudo_print_help(const struct shirudo_help *h)
+void print_help(const struct shirudo_help *h)
{
size_t i, j;
@@ -142,8 +142,8 @@ shirudo_help_unknown_subcommand(const char *cmd_label, const char *bad,
for (i = 0; i < n_subcmds && n_names < SHIRUDO_SUBCMD_MAX; i++)
names[n_names++] = subcmds[i].name;
- n = shirudo_suggest(bad, names, n_names, max_dist, sugg,
- ARRAY_SIZE(sugg));
+ n = suggest(bad, names, n_names, max_dist, sugg,
+ ARRAY_SIZE(sugg));
if (n) {
fprintf(stderr, "\nDid you mean one of:\n");
for (i = 0; i < n; i++)
@@ -151,10 +151,10 @@ shirudo_help_unknown_subcommand(const char *cmd_label, const char *bad,
}
}
-const char *shirudo_resolve_subcommand(const char *cmd_label,
- const char *input,
- const struct shirudo_help_item *subcmds,
- size_t n_subcmds)
+const char *resolve_subcommand(const char *cmd_label,
+ const char *input,
+ const struct shirudo_help_item *subcmds,
+ size_t n_subcmds)
{
const char *names[SHIRUDO_SUBCMD_MAX];
size_t matches[SHIRUDO_SUBCMD_MAX];
@@ -168,8 +168,8 @@ const char *shirudo_resolve_subcommand(const char *cmd_label,
for (i = 0; i < n_subcmds && n_names < ARRAY_SIZE(names); i++)
names[n_names++] = subcmds[i].name;
- n = shirudo_resolve(input, names, n_names, matches,
- ARRAY_SIZE(matches));
+ n = resolve(input, names, n_names, matches,
+ ARRAY_SIZE(matches));
if (n == 1)
return names[matches[0]];
if (n == 0) {
diff --git a/util/help.h b/util/help.h
index e6c9c796..2bc7f5af 100644
--- a/util/help.h
+++ b/util/help.h
@@ -29,23 +29,23 @@ struct shirudo_help {
const char *footer;
};
-int shirudo_is_help(const char *arg);
+int is_help(const char *arg);
-int shirudo_is_list_cmds(const char *arg);
+int is_list_cmds(const char *arg);
-void shirudo_print_help(const struct shirudo_help *h);
+void print_help(const struct shirudo_help *h);
/* What bash completion reads through --list-cmds. */
-void shirudo_print_subcmd_list(const struct shirudo_help_item *items,
- size_t n_items);
+void print_subcmd_list(const struct shirudo_help_item *items,
+ size_t n_items);
/*
* NULL on failure with stderr already written: a did-you-mean block,
* or the ambiguous matches.
*/
-const char *shirudo_resolve_subcommand(const char *cmd_label,
- const char *input,
- const struct shirudo_help_item *subcmds,
- size_t n_subcmds);
+const char *resolve_subcommand(const char *cmd_label,
+ const char *input,
+ const struct shirudo_help_item *subcmds,
+ size_t n_subcmds);
#endif /* SHIRUDO_HELP_H */
diff --git a/util/hex.c b/util/hex.c
index 7271bd72..27898501 100644
--- a/util/hex.c
+++ b/util/hex.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "malloc.h"
-void shirudo_hex_encode(const __u8 *in, size_t n, char *out)
+void hex_encode(const __u8 *in, size_t n, char *out)
{
static const char d[] = "0123456789abcdef";
size_t i;
@@ -21,16 +21,16 @@ void shirudo_hex_encode(const __u8 *in, size_t n, char *out)
out[2 * n] = '\0';
}
-char *shirudo_hex_alloc(const void *in, size_t n)
+char *hex_alloc(const void *in, size_t n)
{
char *out = xmalloc(2 * n + 1);
if (out)
- shirudo_hex_encode(in, n, out);
+ hex_encode(in, n, out);
return out;
}
-int shirudo_hex_nibble(int c)
+int hex_nibble(int c)
{
if (c >= '0' && c <= '9')
return c - '0';
@@ -41,15 +41,15 @@ int shirudo_hex_nibble(int c)
return -1;
}
-int shirudo_hex_decode(const char *hex, __u8 *out, size_t n)
+int hex_decode(const char *hex, __u8 *out, size_t n)
{
size_t i;
if (strlen(hex) != 2 * n)
return -EINVAL;
for (i = 0; i < n; i++) {
- int hi = shirudo_hex_nibble(hex[2 * i]);
- int lo = shirudo_hex_nibble(hex[2 * i + 1]);
+ int hi = hex_nibble(hex[2 * i]);
+ int lo = hex_nibble(hex[2 * i + 1]);
if (hi < 0 || lo < 0)
return -EINVAL;
diff --git a/util/hex.h b/util/hex.h
index e188548b..c87fb559 100644
--- a/util/hex.h
+++ b/util/hex.h
@@ -13,14 +13,14 @@
#include <shirudo/misc.h>
/* out needs 2 * n + 1 bytes. */
-void shirudo_hex_encode(const __u8 *in, size_t n, char *out);
+void hex_encode(const __u8 *in, size_t n, char *out);
/* The same, xmalloc'd to 2 * n + 1 bytes. */
-char *shirudo_hex_alloc(const void *in, size_t n);
+char *hex_alloc(const void *in, size_t n);
/* The value of one hex digit, -1 for any other byte. */
-int shirudo_hex_nibble(int c);
+int hex_nibble(int c);
/* Exactly 2 * n hex digits, either case. 0 or -EINVAL. */
-int shirudo_hex_decode(const char *hex, __u8 *out, size_t n);
+int hex_decode(const char *hex, __u8 *out, size_t n);
#endif /* SHIRUDO_HEX_H */
diff --git a/util/identity.c b/util/identity.c
index b0e2db8d..b3b2ebe0 100644
--- a/util/identity.c
+++ b/util/identity.c
@@ -18,7 +18,7 @@
#include "identity.h"
#include "paths.h"
-int shirudo_identity_read(struct shirudo_identity *out)
+int identity_read(struct shirudo_identity *out)
{
struct bpf_map_info info = {};
__u32 len = sizeof(info);
diff --git a/util/identity.h b/util/identity.h
index 2e6e3dff..cf0fe4f9 100644
--- a/util/identity.h
+++ b/util/identity.h
@@ -42,6 +42,6 @@ struct shirudo_identity {
* The identity map init populated, froze and pinned this boot. -ENOENT
* when init has not run, another -errno when the pin cannot be read.
*/
-int shirudo_identity_read(struct shirudo_identity *out);
+int identity_read(struct shirudo_identity *out);
#endif /* SHIRUDO_UTIL_IDENTITY_H */
diff --git a/util/initrd.c b/util/initrd.c
index 86e8d049..985747dc 100644
--- a/util/initrd.c
+++ b/util/initrd.c
@@ -12,14 +12,14 @@
#include "initrd.h"
#include "paths.h"
-bool shirudo_in_initrd(void)
+bool in_initrd(void)
{
const char *env = getenv("SHIRUDO_INITRD_RELEASE");
return access(env && *env ? env : "/etc/initrd-release", F_OK) == 0;
}
-const char *shirudo_sysroot(void)
+const char *sysroot(void)
{
const char *env = getenv("SHIRUDO_SYSROOT");
@@ -28,12 +28,12 @@ const char *shirudo_sysroot(void)
const char *shirudo_keys_dir(void)
{
- return shirudo_in_initrd() ? SHIRUDO_INITRD_KEYS_DIR :
+ return in_initrd() ? SHIRUDO_INITRD_KEYS_DIR :
SHIRUDO_KEYS_DIR;
}
const char *shirudo_cert_path(void)
{
- return shirudo_in_initrd() ? SHIRUDO_INITRD_CERT_PATH :
+ return in_initrd() ? SHIRUDO_INITRD_CERT_PATH :
SHIRUDO_CERT_PATH;
}
diff --git a/util/initrd.h b/util/initrd.h
index 526264e7..e41b6149 100644
--- a/util/initrd.h
+++ b/util/initrd.h
@@ -14,9 +14,9 @@
* The initrd marks itself with /etc/initrd-release; tests point
* SHIRUDO_INITRD_RELEASE elsewhere.
*/
-bool shirudo_in_initrd(void);
+bool in_initrd(void);
-const char *shirudo_sysroot(void);
+const char *sysroot(void);
/*
* The keys init enrols: the initrd's own, measured copies while the
diff --git a/util/io.c b/util/io.c
index 035b92a5..b660d9ea 100644
--- a/util/io.c
+++ b/util/io.c
@@ -17,7 +17,7 @@
#include "malloc.h"
#include "paths.h"
-int shirudo_write_all(int fd, const void *buf, size_t len)
+int write_all(int fd, const void *buf, size_t len)
{
const __u8 *p = buf;
@@ -37,7 +37,7 @@ int shirudo_write_all(int fd, const void *buf, size_t len)
return 0;
}
-int shirudo_read_file(const char *path, size_t max, void *out, size_t *len)
+int read_file(const char *path, size_t max, void *out, size_t *len)
{
struct stat st;
char *buf, *p;
@@ -55,7 +55,7 @@ int shirudo_read_file(const char *path, size_t max, void *out, size_t *len)
rc = -EINVAL;
goto out;
}
- rc = shirudo_check_trusted(fd, path, false);
+ rc = check_trusted(fd, path, false);
if (rc)
goto out;
if ((uintmax_t)st.st_size > max) {
@@ -100,7 +100,7 @@ static bool trusted_owner(uid_t uid)
return uid == 0 || uid == geteuid();
}
-int shirudo_check_trusted(int fd, const char *path, bool secret)
+int check_trusted(int fd, const char *path, bool secret)
{
char real[PATH_MAX], *slash;
struct stat st;
diff --git a/util/io.h b/util/io.h
index 2deb9fb7..6ab6cd28 100644
--- a/util/io.h
+++ b/util/io.h
@@ -7,14 +7,14 @@
#include <stdbool.h>
#include <stddef.h>
-int shirudo_write_all(int fd, const void *buf, size_t len);
+int write_all(int fd, const void *buf, size_t len);
/*
* A regular file of at most max bytes, into *out xmalloc'd to *len + 1
* bytes and NUL-terminated; out is the address of a char or unsigned
* char pointer.
*/
-int shirudo_read_file(const char *path, size_t max, void *out, size_t *len);
+int read_file(const char *path, size_t max, void *out, size_t *len);
/*
* Whether the file open on fd at path may steer what shirudo trusts.
@@ -25,6 +25,6 @@ int shirudo_read_file(const char *path, size_t max, void *out, size_t *len);
* root's guards its files the same way. A path elsewhere, where a test
* points shirudo, is the caller's to vouch for. 0, or -EPERM logged.
*/
-int shirudo_check_trusted(int fd, const char *path, bool secret);
+int check_trusted(int fd, const char *path, bool secret);
#endif /* SHIRUDO_IO_H */
diff --git a/util/json.c b/util/json.c
index 743f770d..4268a94a 100644
--- a/util/json.c
+++ b/util/json.c
@@ -124,14 +124,14 @@ static void leave(struct shirudo_json_emit *e)
e->depth--;
}
-void shirudo_json_obj_open(struct shirudo_json_emit *e)
+void json_obj_open(struct shirudo_json_emit *e)
{
sep(e);
put(e, '{');
enter(e);
}
-void shirudo_json_obj_open_key(struct shirudo_json_emit *e, const char *key)
+void json_obj_open_key(struct shirudo_json_emit *e, const char *key)
{
sep(e);
put_string(e, key);
@@ -140,13 +140,13 @@ void shirudo_json_obj_open_key(struct shirudo_json_emit *e, const char *key)
enter(e);
}
-void shirudo_json_obj_close(struct shirudo_json_emit *e)
+void json_obj_close(struct shirudo_json_emit *e)
{
put(e, '}');
leave(e);
}
-void shirudo_json_arr_open(struct shirudo_json_emit *e, const char *key)
+void json_arr_open(struct shirudo_json_emit *e, const char *key)
{
sep(e);
put_string(e, key);
@@ -155,14 +155,14 @@ void shirudo_json_arr_open(struct shirudo_json_emit *e, const char *key)
enter(e);
}
-void shirudo_json_arr_close(struct shirudo_json_emit *e)
+void json_arr_close(struct shirudo_json_emit *e)
{
put(e, ']');
leave(e);
}
-void shirudo_json_kv_string(struct shirudo_json_emit *e,
- const char *key, const char *val)
+void json_kv_string(struct shirudo_json_emit *e,
+ const char *key, const char *val)
{
sep(e);
put_string(e, key);
@@ -170,8 +170,8 @@ void shirudo_json_kv_string(struct shirudo_json_emit *e,
put_string(e, val);
}
-void shirudo_json_kv_int(struct shirudo_json_emit *e,
- const char *key, __s64 val)
+void json_kv_int(struct shirudo_json_emit *e,
+ const char *key, __s64 val)
{
char num[24];
@@ -182,7 +182,7 @@ void shirudo_json_kv_int(struct shirudo_json_emit *e,
put_raw(e, num);
}
-void shirudo_json_kv_bool(struct shirudo_json_emit *e, const char *key, int val)
+void json_kv_bool(struct shirudo_json_emit *e, const char *key, int val)
{
sep(e);
put_string(e, key);
@@ -190,7 +190,7 @@ void shirudo_json_kv_bool(struct shirudo_json_emit *e, const char *key, int val)
put_raw(e, val ? "true" : "false");
}
-void shirudo_json_kv_null(struct shirudo_json_emit *e, const char *key)
+void json_kv_null(struct shirudo_json_emit *e, const char *key)
{
sep(e);
put_string(e, key);
@@ -198,8 +198,8 @@ void shirudo_json_kv_null(struct shirudo_json_emit *e, const char *key)
put_raw(e, "null");
}
-void shirudo_json_kv_raw(struct shirudo_json_emit *e, const char *key,
- const char *value, size_t value_len)
+void json_kv_raw(struct shirudo_json_emit *e, const char *key,
+ const char *value, size_t value_len)
{
size_t i;
@@ -210,14 +210,14 @@ void shirudo_json_kv_raw(struct shirudo_json_emit *e, const char *key,
put(e, value[i]);
}
-void shirudo_json_str(struct shirudo_json_emit *e, const char *val)
+void json_str(struct shirudo_json_emit *e, const char *val)
{
sep(e);
put_string(e, val);
}
-void shirudo_json_raw(struct shirudo_json_emit *e, const char *value,
- size_t value_len)
+void json_raw(struct shirudo_json_emit *e, const char *value,
+ size_t value_len)
{
size_t i;
@@ -251,7 +251,7 @@ static int hex4(const char *s)
int v = 0, i;
for (i = 0; i < 4; i++) {
- int n = shirudo_hex_nibble(s[i]);
+ int n = hex_nibble(s[i]);
if (n < 0)
return -1;
@@ -561,7 +561,7 @@ static int lit(struct pctx *c, const char *s)
static int skip_digits(struct pctx *c)
{
- size_t n = shirudo_digits(c->p, (size_t)(c->end - c->p));
+ size_t n = digits(c->p, (size_t)(c->end - c->p));
c->p += n;
return n ? 0 : -EINVAL;
@@ -689,8 +689,8 @@ static int parse_value(struct pctx *c, struct shirudo_json_field *f)
}
}
-int shirudo_json_parse(const char *data, size_t len,
- struct shirudo_json_field *fields, size_t n_fields)
+int json_parse(const char *data, size_t len,
+ struct shirudo_json_field *fields, size_t n_fields)
{
struct pctx c = {
.p = data, .end = data + len,
diff --git a/util/json.h b/util/json.h
index 748b3420..21e60585 100644
--- a/util/json.h
+++ b/util/json.h
@@ -36,24 +36,24 @@ struct shirudo_json_emit {
* latches and later calls are no-ops: check it once after the final
* close.
*/
-void shirudo_json_obj_open(struct shirudo_json_emit *e);
-void shirudo_json_obj_open_key(struct shirudo_json_emit *e, const char *key);
-void shirudo_json_obj_close(struct shirudo_json_emit *e);
-void shirudo_json_arr_open(struct shirudo_json_emit *e, const char *key);
-void shirudo_json_arr_close(struct shirudo_json_emit *e);
-void shirudo_json_kv_string(struct shirudo_json_emit *e,
- const char *key, const char *val);
-void shirudo_json_kv_int(struct shirudo_json_emit *e,
- const char *key, __s64 val);
-void shirudo_json_kv_bool(struct shirudo_json_emit *e,
- const char *key, int val);
-void shirudo_json_kv_null(struct shirudo_json_emit *e, const char *key);
+void json_obj_open(struct shirudo_json_emit *e);
+void json_obj_open_key(struct shirudo_json_emit *e, const char *key);
+void json_obj_close(struct shirudo_json_emit *e);
+void json_arr_open(struct shirudo_json_emit *e, const char *key);
+void json_arr_close(struct shirudo_json_emit *e);
+void json_kv_string(struct shirudo_json_emit *e,
+ const char *key, const char *val);
+void json_kv_int(struct shirudo_json_emit *e,
+ const char *key, __s64 val);
+void json_kv_bool(struct shirudo_json_emit *e,
+ const char *key, int val);
+void json_kv_null(struct shirudo_json_emit *e, const char *key);
/* Insert an internally-generated, already-valid JSON value verbatim. */
-void shirudo_json_kv_raw(struct shirudo_json_emit *e, const char *key,
- const char *value, size_t value_len);
-void shirudo_json_str(struct shirudo_json_emit *e, const char *val);
-void shirudo_json_raw(struct shirudo_json_emit *e, const char *value,
- size_t value_len);
+void json_kv_raw(struct shirudo_json_emit *e, const char *key,
+ const char *value, size_t value_len);
+void json_str(struct shirudo_json_emit *e, const char *val);
+void json_raw(struct shirudo_json_emit *e, const char *value,
+ size_t value_len);
/*
* Not a generic deserialiser: declared keys are dispatched, everything
@@ -92,7 +92,7 @@ struct shirudo_json_field {
* -EINVAL on malformed input or a type mismatch, -E2BIG on a bounds
* violation, -ENOSPC when a string exceeds its dst_cap.
*/
-int shirudo_json_parse(const char *data, size_t len,
- struct shirudo_json_field *fields, size_t n_fields);
+int json_parse(const char *data, size_t len,
+ struct shirudo_json_field *fields, size_t n_fields);
#endif /* SHIRUDO_JSON_H */
diff --git a/util/kernel_abi.c b/util/kernel_abi.c
index 50a08913..de669f39 100644
--- a/util/kernel_abi.c
+++ b/util/kernel_abi.c
@@ -95,8 +95,8 @@ static bool is_byte_int(const struct btf_type *t)
btf_int_offset(t) == 0 && btf_int_bits(t) == 8;
}
-int shirudo_kernel_abi_validate_btf(const struct btf *btf,
- char *detail, size_t detail_sz)
+int kernel_abi_validate_btf(const struct btf *btf,
+ char *detail, size_t detail_sz)
{
const struct btf_member *sha, *excl_prog_sha, *sig;
const struct btf_member *keyring_serial, *keyring_type, *verdict;
@@ -192,7 +192,7 @@ int shirudo_kernel_abi_validate_btf(const struct btf *btf,
return 0;
}
-int shirudo_kernel_abi_check(char *detail, size_t detail_sz)
+int kernel_abi_check(char *detail, size_t detail_sz)
{
struct btf *btf;
long err;
@@ -207,7 +207,7 @@ int shirudo_kernel_abi_check(char *detail, size_t detail_sz)
"cannot read target kernel BTF: %s; boot a Shirudo-patched kernel",
strerror((int)-err));
- rc = shirudo_kernel_abi_validate_btf(btf, detail, detail_sz);
+ rc = kernel_abi_validate_btf(btf, detail, detail_sz);
btf__free(btf);
return rc;
}
diff --git a/util/kernel_abi.h b/util/kernel_abi.h
index c2ee9bd9..8f2bdd65 100644
--- a/util/kernel_abi.h
+++ b/util/kernel_abi.h
@@ -19,9 +19,9 @@ struct btf;
* structural contract can be tested with synthetic BTF without depending on
* the kernel running the test.
*/
-int shirudo_kernel_abi_validate_btf(const struct btf *btf,
- char *detail, size_t detail_sz);
+int kernel_abi_validate_btf(const struct btf *btf,
+ char *detail, size_t detail_sz);
-int shirudo_kernel_abi_check(char *detail, size_t detail_sz);
+int kernel_abi_check(char *detail, size_t detail_sz);
#endif /* SHIRUDO_KERNEL_ABI_H */
diff --git a/util/kernel_build_id.c b/util/kernel_build_id.c
index 384119c9..a123f7ca 100644
--- a/util/kernel_build_id.c
+++ b/util/kernel_build_id.c
@@ -27,8 +27,8 @@ static int read_u32(const __u8 *p, size_t remaining, __u32 *out)
return 0;
}
-int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,
- char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
+int kernel_build_id_from_notes(const void *notes, size_t notes_len,
+ char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
{
const __u8 *p = notes;
@@ -65,7 +65,7 @@ int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,
return -ENOENT;
}
-int shirudo_kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
+int kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
{
__u8 notes[KERNEL_NOTES_MAX];
size_t len = 0;
@@ -88,7 +88,7 @@ int shirudo_kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
len += (size_t)n;
}
rc = len == sizeof(notes) ? -E2BIG :
- shirudo_kernel_build_id_from_notes(notes, len, out);
+ kernel_build_id_from_notes(notes, len, out);
out:
close(fd);
return rc;
diff --git a/util/kernel_build_id.h b/util/kernel_build_id.h
index 7c066878..ba1160ce 100644
--- a/util/kernel_build_id.h
+++ b/util/kernel_build_id.h
@@ -10,9 +10,9 @@
#define SHIRUDO_KERNEL_BUILD_ID_STRING_MAX \
(SHIRUDO_KERNEL_BUILD_ID_MAX * 2u + 1u)
-int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,
- char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
+int kernel_build_id_from_notes(const void *notes, size_t notes_len,
+ char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
-int shirudo_kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
+int kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
#endif /* SHIRUDO_KERNEL_BUILD_ID_H */
diff --git a/util/kernel_release.c b/util/kernel_release.c
index fe316e3f..8684b212 100644
--- a/util/kernel_release.c
+++ b/util/kernel_release.c
@@ -5,8 +5,8 @@
#include "kernel_release.h"
-bool shirudo_kernel_release_prefix_matches(const char *release,
- const char *prefix)
+bool kernel_release_prefix_matches(const char *release,
+ const char *prefix)
{
size_t len;
diff --git a/util/kernel_release.h b/util/kernel_release.h
index 88676f6d..8a428afa 100644
--- a/util/kernel_release.h
+++ b/util/kernel_release.h
@@ -6,7 +6,7 @@
#include <stdbool.h>
-bool shirudo_kernel_release_prefix_matches(const char *release,
- const char *prefix);
+bool kernel_release_prefix_matches(const char *release,
+ const char *prefix);
#endif /* SHIRUDO_KERNEL_RELEASE_H */
diff --git a/util/keyring.c b/util/keyring.c
index 3df4b65b..e1e6cf7e 100644
--- a/util/keyring.c
+++ b/util/keyring.c
@@ -58,7 +58,7 @@ static long sys_keyctl(int cmd, long a, long b, long c, long d)
return syscall(__NR_keyctl, cmd, a, b, c, d);
}
-key_serial_t shirudo_keyring_find(const char *name)
+key_serial_t keyring_find(const char *name)
{
long ret = sys_keyctl(KEYCTL_SEARCH, KEY_SPEC_USER_KEYRING,
(long)"keyring", (long)name, 0);
@@ -67,7 +67,7 @@ key_serial_t shirudo_keyring_find(const char *name)
return (key_serial_t)ret;
}
-static int shirudo_keyring_make_mutable(key_serial_t keyring)
+static int keyring_make_mutable(key_serial_t keyring)
{
/*
* A named keyring linked only from @u is not necessarily possessed by
@@ -84,9 +84,9 @@ static int shirudo_keyring_make_mutable(key_serial_t keyring)
return 0;
}
-key_serial_t shirudo_keyring_open_or_create(const char *name)
+key_serial_t keyring_open_or_create(const char *name)
{
- key_serial_t s = shirudo_keyring_find(name);
+ key_serial_t s = keyring_find(name);
long ret;
int rc;
@@ -98,7 +98,7 @@ key_serial_t shirudo_keyring_open_or_create(const char *name)
if (ret < 0)
return (key_serial_t)-errno;
- rc = shirudo_keyring_make_mutable((key_serial_t)ret);
+ rc = keyring_make_mutable((key_serial_t)ret);
if (rc)
return (key_serial_t)rc;
@@ -108,15 +108,15 @@ key_serial_t shirudo_keyring_open_or_create(const char *name)
return (key_serial_t)ret;
}
-int shirudo_keyring_unlink_from_user(key_serial_t keyring)
+int keyring_unlink_from_user(key_serial_t keyring)
{
if (sys_keyctl(KEYCTL_UNLINK, keyring, KEY_SPEC_USER_KEYRING, 0, 0) < 0)
return -errno;
return 0;
}
-key_serial_t shirudo_keyring_add_cert(key_serial_t keyring,
- const void *cert, size_t cert_len)
+key_serial_t keyring_add_cert(key_serial_t keyring,
+ const void *cert, size_t cert_len)
{
long ret = sys_add_key("asymmetric", NULL, cert, cert_len, keyring);
@@ -125,7 +125,7 @@ key_serial_t shirudo_keyring_add_cert(key_serial_t keyring,
return (key_serial_t)ret;
}
-int shirudo_keyring_seal(key_serial_t keyring)
+int keyring_seal(key_serial_t keyring)
{
/*
* Possessor + user keep view/read/search (so any root process can
@@ -172,8 +172,8 @@ static void split_describe(char *desc, const char **type,
*description = p;
}
-int shirudo_keyring_list(key_serial_t keyring,
- shirudo_keyring_cb cb, void *ud)
+int keyring_list(key_serial_t keyring,
+ shirudo_keyring_cb cb, void *ud)
{
key_serial_t *serials = NULL;
size_t cap = 64 * sizeof(*serials);
@@ -246,8 +246,8 @@ static void holds_cert_cb(key_serial_t serial, const char *type,
}
}
-int shirudo_keyring_holds_cert(key_serial_t keyring,
- const __u8 *der, size_t der_len)
+int keyring_holds_cert(key_serial_t keyring,
+ const __u8 *der, size_t der_len)
{
struct holds_cert_ctx ctx = {};
const char *type, *description;
@@ -268,15 +268,15 @@ int shirudo_keyring_holds_cert(key_serial_t keyring,
return -ERANGE;
memcpy(ctx.want, description, strlen(description) + 1);
- rc = shirudo_keyring_list(keyring, holds_cert_cb, &ctx);
+ rc = keyring_list(keyring, holds_cert_cb, &ctx);
if (rc)
return rc;
return ctx.found ? 1 : 0;
}
-key_serial_t shirudo_keyring_find_cert(key_serial_t keyring,
- const __u8 *der,
- size_t der_len)
+key_serial_t keyring_find_cert(key_serial_t keyring,
+ const __u8 *der,
+ size_t der_len)
{
struct holds_cert_ctx ctx = {};
const char *type, *description;
@@ -296,20 +296,20 @@ key_serial_t shirudo_keyring_find_cert(key_serial_t keyring,
if (strlen(description) >= sizeof(ctx.want))
return -ERANGE;
memcpy(ctx.want, description, strlen(description) + 1);
- rc = shirudo_keyring_list(keyring, holds_cert_cb, &ctx);
+ rc = keyring_list(keyring, holds_cert_cb, &ctx);
if (rc)
return rc;
return ctx.found ? ctx.serial : -ENOKEY;
}
-int shirudo_keyring_unlink_key(key_serial_t keyring, key_serial_t key)
+int keyring_unlink_key(key_serial_t keyring, key_serial_t key)
{
if (sys_keyctl(KEYCTL_UNLINK, key, keyring, 0, 0) < 0)
return -errno;
return 0;
}
-key_serial_t shirudo_keyring_bpf_serial(void)
+key_serial_t keyring_bpf_serial(void)
{
long ret = sys_keyctl(KEYCTL_GET_KEYRING_ID, KEY_SPEC_BPF_KEYRING, 0, 0,
0);
@@ -317,8 +317,8 @@ key_serial_t shirudo_keyring_bpf_serial(void)
return ret < 0 ? -errno : (key_serial_t)ret;
}
-key_serial_t shirudo_keyring_bpf_add_cert(const __u8 *cert,
- size_t cert_len)
+key_serial_t keyring_bpf_add_cert(const __u8 *cert,
+ size_t cert_len)
{
long ret = sys_add_key("asymmetric", NULL, cert, cert_len,
KEY_SPEC_BPF_KEYRING);
@@ -326,7 +326,7 @@ key_serial_t shirudo_keyring_bpf_add_cert(const __u8 *cert,
return ret < 0 ? -errno : (key_serial_t)ret;
}
-int shirudo_keyring_bpf_seal(void)
+int keyring_bpf_seal(void)
{
/* No restriction type: the keyring rejects every further link. */
if (sys_keyctl(KEYCTL_RESTRICT_KEYRING, KEY_SPEC_BPF_KEYRING, 0, 0, 0) < 0)
diff --git a/util/keyring.h b/util/keyring.h
index 19ef1483..6931a33c 100644
--- a/util/keyring.h
+++ b/util/keyring.h
@@ -20,20 +20,20 @@ typedef void (*shirudo_keyring_cb)(key_serial_t serial,
void *ud);
/* -ENOKEY if absent. */
-key_serial_t shirudo_keyring_find(const char *name);
+key_serial_t keyring_find(const char *name);
/*
* As above, but adds the keyring to @u if absent.
*/
-key_serial_t shirudo_keyring_open_or_create(const char *name);
+key_serial_t keyring_open_or_create(const char *name);
/*
* Unlink a keyring from @u so init can replace an incomplete stale keyring.
*/
-int shirudo_keyring_unlink_from_user(key_serial_t keyring);
+int keyring_unlink_from_user(key_serial_t keyring);
-key_serial_t shirudo_keyring_add_cert(key_serial_t keyring,
- const void *cert, size_t cert_len);
+key_serial_t keyring_add_cert(key_serial_t keyring,
+ const void *cert, size_t cert_len);
/*
* Freeze a keyring for the rest of the boot: drop write/link/setattr
@@ -42,7 +42,7 @@ key_serial_t shirudo_keyring_add_cert(key_serial_t keyring,
* one-way change. The kernel can still find the cert at BPF_PROG_LOAD.
* Returns 0 or -errno.
*/
-int shirudo_keyring_seal(key_serial_t keyring);
+int keyring_seal(key_serial_t keyring);
/*
* Whether <keyring> holds the certificate <der>: 1 when one of its
@@ -52,19 +52,19 @@ int shirudo_keyring_seal(key_serial_t keyring);
* the certificate gets on the thread keyring and those of the keys in
* <keyring>; no key material leaves the kernel.
*/
-int shirudo_keyring_holds_cert(key_serial_t keyring,
- const __u8 *der, size_t der_len);
+int keyring_holds_cert(key_serial_t keyring,
+ const __u8 *der, size_t der_len);
/* The serial of <keyring>'s key for the certificate, -ENOKEY, -errno. */
-key_serial_t shirudo_keyring_find_cert(key_serial_t keyring,
- const __u8 *der,
- size_t der_len);
+key_serial_t keyring_find_cert(key_serial_t keyring,
+ const __u8 *der,
+ size_t der_len);
/* Unlink <key> from <keyring>; sealing does not stop this, the LSM may. */
-int shirudo_keyring_unlink_key(key_serial_t keyring, key_serial_t key);
+int keyring_unlink_key(key_serial_t keyring, key_serial_t key);
-int shirudo_keyring_list(key_serial_t keyring,
- shirudo_keyring_cb cb, void *ud);
+int keyring_list(key_serial_t keyring,
+ shirudo_keyring_cb cb, void *ud);
/*
* The kernel's bpf keyring, the trust anchor a signed loader names with
@@ -78,11 +78,11 @@ int shirudo_keyring_list(key_serial_t keyring,
#endif
/* Its serial, or -errno on a kernel without one. */
-key_serial_t shirudo_keyring_bpf_serial(void);
+key_serial_t keyring_bpf_serial(void);
/* Enrol a DER certificate; -EPERM once the keyring is sealed. */
-key_serial_t shirudo_keyring_bpf_add_cert(const __u8 *cert,
- size_t cert_len);
+key_serial_t keyring_bpf_add_cert(const __u8 *cert,
+ size_t cert_len);
/* Seal it for the rest of the boot: no key can be linked afterwards. */
-int shirudo_keyring_bpf_seal(void);
+int keyring_bpf_seal(void);
#endif /* SHIRUDO_KEYRING_H */
diff --git a/util/keys.c b/util/keys.c
index 58b29001..507c68ce 100644
--- a/util/keys.c
+++ b/util/keys.c
@@ -36,8 +36,8 @@ struct keys_candidate {
bool done;
};
-int shirudo_keys_read_der(const char *path, __u8 **out,
- size_t *out_sz)
+int keys_read_der(const char *path, __u8 **out,
+ size_t *out_sz)
{
struct stat st;
__u8 *buf;
@@ -58,7 +58,7 @@ int shirudo_keys_read_der(const char *path, __u8 **out,
close(fd);
return -EINVAL;
}
- if (shirudo_check_trusted(fd, path, false)) {
+ if (check_trusted(fd, path, false)) {
close(fd);
return -EPERM;
}
@@ -78,62 +78,62 @@ int shirudo_keys_read_der(const char *path, __u8 **out,
return 0;
}
-int shirudo_keys_digest_der(const __u8 *der, size_t der_sz,
- __u8 sha256[32], __u8 fingerprint[32])
+int keys_digest_der(const __u8 *der, size_t der_sz,
+ __u8 sha256[32], __u8 fingerprint[32])
{
struct shirudo_cert cert = {};
int rc;
- rc = shirudo_sha256_buffer(der, der_sz, sha256);
+ rc = sha256_buffer(der, der_sz, sha256);
if (rc)
return rc;
- rc = shirudo_cert_read_der(der, der_sz, &cert);
+ rc = cert_read_der(der, der_sz, &cert);
if (rc)
return rc;
- rc = shirudo_cert_pubkey_digest(&cert, fingerprint);
- shirudo_cert_free(&cert);
+ rc = cert_pubkey_digest(&cert, fingerprint);
+ cert_free(&cert);
return rc;
}
-static int shirudo_keys_digest_file(const char *path, __u8 sha256[32],
- __u8 fingerprint[32])
+static int keys_digest_file(const char *path, __u8 sha256[32],
+ __u8 fingerprint[32])
{
size_t der_sz = 0;
__u8 *der = NULL;
int rc;
- rc = shirudo_keys_read_der(path, &der, &der_sz);
+ rc = keys_read_der(path, &der, &der_sz);
if (rc)
return rc;
- rc = shirudo_keys_digest_der(der, der_sz, sha256, fingerprint);
+ rc = keys_digest_der(der, der_sz, sha256, fingerprint);
xfree(der, der_sz);
return rc;
}
-int shirudo_keys_path_for(const char *dir, const __u8 fingerprint[32],
- const char *suffix, char *out, size_t cap)
+int keys_path_for(const char *dir, const __u8 fingerprint[32],
+ const char *suffix, char *out, size_t cap)
{
char hex[65];
- shirudo_hex_encode(fingerprint, 32, hex);
+ hex_encode(fingerprint, 32, hex);
if ((size_t)snprintf(out, cap, "%s/%s%s", dir, hex, suffix) >= cap)
return -ENAMETOOLONG;
return 0;
}
-bool shirudo_keys_is_revoked(const char *revoked_dir,
- const __u8 fingerprint[32])
+bool keys_is_revoked(const char *revoked_dir,
+ const __u8 fingerprint[32])
{
char path[PATH_MAX];
- if (shirudo_keys_path_for(revoked_dir, fingerprint, ".der", path,
- sizeof(path)))
+ if (keys_path_for(revoked_dir, fingerprint, ".der", path,
+ sizeof(path)))
return false;
return access(path, F_OK) == 0;
}
-int shirudo_keys_vouch_payload(const __u8 *der, size_t der_sz,
- __u8 **out, size_t *out_sz)
+int keys_vouch_payload(const __u8 *der, size_t der_sz,
+ __u8 **out, size_t *out_sz)
{
size_t n = sizeof(SHIRUDO_KEYS_VOUCH_PREFIX) + der_sz;
__u8 *buf = xmalloc(n);
@@ -148,30 +148,30 @@ int shirudo_keys_vouch_payload(const __u8 *der, size_t der_sz,
return 0;
}
-int shirudo_keys_verify_vouch(const struct shirudo_trusted_set *set,
- const __u8 *der, size_t der_sz,
- const __u8 *sig, size_t sig_sz,
- __u8 voucher[32])
+int keys_verify_vouch(const struct shirudo_trusted_set *set,
+ const __u8 *der, size_t der_sz,
+ const __u8 *sig, size_t sig_sz,
+ __u8 voucher[32])
{
size_t payload_sz = 0, i;
__u8 *payload = NULL;
int rc;
- rc = shirudo_keys_vouch_payload(der, der_sz, &payload, &payload_sz);
+ rc = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
if (rc)
return rc;
rc = -EKEYREJECTED;
for (i = 0; i < set->n && rc; i++) {
struct shirudo_cert cert = {};
- if (shirudo_cert_read_file(set->certs[i].path, &cert))
+ if (cert_read_file(set->certs[i].path, &cert))
continue;
- if (shirudo_verify_detached(payload, payload_sz, sig, sig_sz,
- &cert) == 0) {
+ if (verify_detached(payload, payload_sz, sig, sig_sz,
+ &cert) == 0) {
memcpy(voucher, set->certs[i].fingerprint, 32);
rc = 0;
}
- shirudo_cert_free(&cert);
+ cert_free(&cert);
}
xfree(payload, payload_sz);
return rc;
@@ -234,8 +234,8 @@ static size_t count_der(const char *dir)
if (n < 0)
return 0;
for (i = 0; i < n; i++)
- shirudo_libc_free(names[i]);
- shirudo_libc_free(names);
+ libc_free(names[i]);
+ libc_free(names);
return (size_t)n;
}
@@ -275,10 +275,10 @@ static int admit_vouched(struct shirudo_trusted_set *set,
continue;
}
if (vouch_path_for(c->path, vouch, sizeof(vouch)) ||
- shirudo_keys_read_der(vouch, &sig, &sig_sz))
+ keys_read_der(vouch, &sig, &sig_sz))
continue;
- rc = shirudo_keys_verify_vouch(set, c->der, c->der_sz,
- sig, sig_sz, voucher);
+ rc = keys_verify_vouch(set, c->der, c->der_sz,
+ sig, sig_sz, voucher);
xfree(sig, sig_sz);
if (rc)
continue;
@@ -338,17 +338,17 @@ static int scan_trusted(const char *keys_dir, const char *revoked_dir,
rc = -ENAMETOOLONG;
break;
}
- rc = shirudo_keys_read_der(c->path, &c->der, &c->der_sz);
+ rc = keys_read_der(c->path, &c->der, &c->der_sz);
if (rc)
break;
- rc = shirudo_keys_digest_der(c->der, c->der_sz, c->sha256,
- c->fingerprint);
+ rc = keys_digest_der(c->der, c->der_sz, c->sha256,
+ c->fingerprint);
if (rc) {
xfree(c->der, c->der_sz);
c->der = NULL;
break;
}
- if (shirudo_keys_is_revoked(revoked_dir, c->fingerprint)) {
+ if (keys_is_revoked(revoked_dir, c->fingerprint)) {
xfree(c->der, c->der_sz);
c->der = NULL;
continue;
@@ -356,13 +356,13 @@ static int scan_trusted(const char *keys_dir, const char *revoked_dir,
(*n_cand)++;
}
for (i = 0; i < n; i++)
- shirudo_libc_free(names[i]);
- shirudo_libc_free(names);
+ libc_free(names[i]);
+ libc_free(names);
return rc;
}
-int shirudo_keys_load(const char *keys_dir, const char *revoked_dir,
- bool with_trusted, struct shirudo_trusted_set *set)
+int keys_load(const char *keys_dir, const char *revoked_dir,
+ bool with_trusted, struct shirudo_trusted_set *set)
{
struct keys_candidate *cand = NULL;
__u8 sha256[32], fingerprint[32];
@@ -381,10 +381,10 @@ int shirudo_keys_load(const char *keys_dir, const char *revoked_dir,
if (snprintf(path, sizeof(path), "%s/%s", keys_dir,
SHIRUDO_CERT_FILE) >= (int)sizeof(path))
return -ENAMETOOLONG;
- rc = shirudo_keys_digest_file(path, sha256, fingerprint);
+ rc = keys_digest_file(path, sha256, fingerprint);
if (rc)
return rc;
- if (!shirudo_keys_is_revoked(revoked_dir, fingerprint))
+ if (!keys_is_revoked(revoked_dir, fingerprint))
set_add(set, path, sha256, fingerprint, NULL);
set->n_revoked = count_der(revoked_dir);
if (!with_trusted)
@@ -409,8 +409,8 @@ static int digest_cmp(const void *a, const void *b)
return memcmp(a, b, 32);
}
-void shirudo_keys_anchor_digest(const __u8 sha256[][32], size_t n,
- __u8 out[32])
+void keys_anchor_digest(const __u8 sha256[][32], size_t n,
+ __u8 out[32])
{
__u8 sorted[SHIRUDO_KEYS_MAX][32];
size_t i;
@@ -426,53 +426,53 @@ void shirudo_keys_anchor_digest(const __u8 sha256[][32], size_t n,
for (i = 0; i < n; i++)
memcpy(sorted[i], sha256[i], 32);
qsort(sorted, n, 32, digest_cmp);
- shirudo_sha256_buffer(sorted, n * 32, out);
+ sha256_buffer(sorted, n * 32, out);
}
-void shirudo_keys_set_digest(const struct shirudo_trusted_set *set,
- __u8 out[32])
+void keys_set_digest(const struct shirudo_trusted_set *set,
+ __u8 out[32])
{
__u8 sha[SHIRUDO_KEYS_MAX][32];
size_t i;
for (i = 0; i < set->n; i++)
memcpy(sha[i], set->certs[i].sha256, 32);
- shirudo_keys_anchor_digest(sha, set->n, out);
+ keys_anchor_digest(sha, set->n, out);
}
-int shirudo_keys_write_file(const char *path, const void *data, size_t len)
+int keys_write_file(const char *path, const void *data, size_t len)
{
- return shirudo_seal_write_file(path, data, len, 0644);
+ return seal_write_file(path, data, len, 0644);
}
-int shirudo_keys_install(const char *keys_dir, const __u8 *der,
- size_t der_sz, const __u8 *sig,
- size_t sig_sz, char *out, size_t cap)
+int keys_install(const char *keys_dir, const __u8 *der,
+ size_t der_sz, const __u8 *sig,
+ size_t sig_sz, char *out, size_t cap)
{
__u8 sha256[32], fingerprint[32];
char vouch[PATH_MAX];
char dir[PATH_MAX];
int rc;
- rc = shirudo_keys_digest_der(der, der_sz, sha256, fingerprint);
+ rc = keys_digest_der(der, der_sz, sha256, fingerprint);
if (rc)
return rc;
if (snprintf(dir, sizeof(dir), "%s/trusted", keys_dir) >=
(int)sizeof(dir))
return -ENAMETOOLONG;
- rc = shirudo_seal_mkdir_p(dir, 0700);
+ rc = seal_mkdir_p(dir, 0700);
if (rc)
return rc;
- rc = shirudo_keys_path_for(dir, fingerprint, ".der", out, cap);
+ rc = keys_path_for(dir, fingerprint, ".der", out, cap);
if (!rc)
- rc = shirudo_keys_path_for(dir, fingerprint, ".vouch", vouch,
- sizeof(vouch));
+ rc = keys_path_for(dir, fingerprint, ".vouch", vouch,
+ sizeof(vouch));
if (rc)
return rc;
- rc = shirudo_keys_write_file(vouch, sig, sig_sz);
+ rc = keys_write_file(vouch, sig, sig_sz);
if (rc)
return rc;
- rc = shirudo_keys_write_file(out, der, der_sz);
+ rc = keys_write_file(out, der, der_sz);
if (rc)
unlink(vouch);
return rc;
diff --git a/util/keys.h b/util/keys.h
index 2f88782e..2877ab43 100644
--- a/util/keys.h
+++ b/util/keys.h
@@ -52,56 +52,56 @@ struct shirudo_trusted_set {
* the keys directory, leaving out the keys revoked_dir names; NULL
* means revoked/ beside them. -ENOENT when there is no cert.der.
*/
-int shirudo_keys_load(const char *keys_dir, const char *revoked_dir,
- bool with_trusted, struct shirudo_trusted_set *set);
+int keys_load(const char *keys_dir, const char *revoked_dir,
+ bool with_trusted, struct shirudo_trusted_set *set);
/* A whole file of at most SHIRUDO_KEYS_DER_MAX bytes, xmalloc'd. */
-int shirudo_keys_read_der(const char *path, __u8 **out,
- size_t *out_sz);
+int keys_read_der(const char *path, __u8 **out,
+ size_t *out_sz);
-int shirudo_keys_digest_der(const __u8 *der, size_t der_sz,
- __u8 sha256[32], __u8 fingerprint[32]);
+int keys_digest_der(const __u8 *der, size_t der_sz,
+ __u8 sha256[32], __u8 fingerprint[32]);
/*
* The digest the init event covers: the one certificate's digest, or
* the SHA-256 over the sorted digests of several. The same function
* serves the operator predicting a register for a set.
*/
-void shirudo_keys_anchor_digest(const __u8 sha256[][32], size_t n,
- __u8 out[32]);
-void shirudo_keys_set_digest(const struct shirudo_trusted_set *set,
- __u8 out[32]);
+void keys_anchor_digest(const __u8 sha256[][32], size_t n,
+ __u8 out[32]);
+void keys_set_digest(const struct shirudo_trusted_set *set,
+ __u8 out[32]);
-bool shirudo_keys_is_revoked(const char *revoked_dir,
- const __u8 fingerprint[32]);
+bool keys_is_revoked(const char *revoked_dir,
+ const __u8 fingerprint[32]);
/* <dir>/<fingerprint hex><suffix>, the name a certificate has in a set. */
-int shirudo_keys_path_for(const char *dir, const __u8 fingerprint[32],
- const char *suffix, char *out, size_t cap);
+int keys_path_for(const char *dir, const __u8 fingerprint[32],
+ const char *suffix, char *out, size_t cap);
/* The bytes a vouch signs: the prefix and the certificate, xmalloc'd. */
-int shirudo_keys_vouch_payload(const __u8 *der, size_t der_sz,
- __u8 **out, size_t *out_sz);
+int keys_vouch_payload(const __u8 *der, size_t der_sz,
+ __u8 **out, size_t *out_sz);
/*
* Whether a member of the set signed the vouch for this certificate:
* 0 with the member's fingerprint in voucher, -EKEYREJECTED when none
* did.
*/
-int shirudo_keys_verify_vouch(const struct shirudo_trusted_set *set,
- const __u8 *der, size_t der_sz,
- const __u8 *sig, size_t sig_sz,
- __u8 voucher[32]);
+int keys_verify_vouch(const struct shirudo_trusted_set *set,
+ const __u8 *der, size_t der_sz,
+ const __u8 *sig, size_t sig_sz,
+ __u8 voucher[32]);
-int shirudo_keys_write_file(const char *path, const void *data, size_t len);
+int keys_write_file(const char *path, const void *data, size_t len);
/*
* Write the certificate and its vouch under <keys_dir>/trusted, named
* by fingerprint, the vouch first so a visible certificate always has
* one. out gets the certificate's path.
*/
-int shirudo_keys_install(const char *keys_dir, const __u8 *der,
- size_t der_sz, const __u8 *sig,
- size_t sig_sz, char *out, size_t cap);
+int keys_install(const char *keys_dir, const __u8 *der,
+ size_t der_sz, const __u8 *sig,
+ size_t sig_sz, char *out, size_t cap);
#endif /* SHIRUDO_UTIL_KEYS_H */
diff --git a/util/kmodules.c b/util/kmodules.c
index 787390a2..4a4824ec 100644
--- a/util/kmodules.c
+++ b/util/kmodules.c
@@ -93,7 +93,7 @@ static int kmod_find(const struct shirudo_kmod_set *set, const char *name)
return -1;
}
-int shirudo_kmodules_parse(char *buf, struct shirudo_kmod_set *set)
+int kmodules_parse(char *buf, struct shirudo_kmod_set *set)
{
size_t mod_cap = 64, deps_cap = 256, edge_cap = 256, n_edges = 0;
struct edge { __u16 user, dep; } *edges = NULL;
@@ -258,7 +258,7 @@ out:
return rc;
}
-int shirudo_kmodules_read(struct shirudo_kmod_set *set)
+int kmodules_read(struct shirudo_kmod_set *set)
{
size_t buf_cap = 0, i;
char *buf = NULL;
@@ -268,7 +268,7 @@ int shirudo_kmodules_read(struct shirudo_kmod_set *set)
rc = slurp(&buf, &buf_cap);
if (rc)
return rc;
- rc = shirudo_kmodules_parse(buf, set);
+ rc = kmodules_parse(buf, set);
xfree(buf, buf_cap);
if (rc)
return rc;
@@ -294,7 +294,7 @@ int shirudo_kmodules_read(struct shirudo_kmod_set *set)
return 0;
}
-void shirudo_kmodules_free(struct shirudo_kmod_set *set)
+void kmodules_free(struct shirudo_kmod_set *set)
{
xfree(set->mods, set->n * sizeof(*set->mods));
xfree(set->deps, set->n_deps * sizeof(*set->deps));
@@ -310,7 +310,7 @@ static void print_subtree(const struct shirudo_kmod_set *set, size_t i,
char size_s[16];
char child_prefix[256];
- shirudo_human_size(m->size, size_s, sizeof(size_s));
+ human_size(m->size, size_s, sizeof(size_s));
if (already) {
printf("%s%s%s (shared)\n", prefix, branch, m->name);
@@ -332,7 +332,7 @@ static void print_subtree(const struct shirudo_kmod_set *set, size_t i,
}
}
-void shirudo_kmodules_print_tree(const struct shirudo_kmod_set *set)
+void kmodules_print_tree(const struct shirudo_kmod_set *set)
{
__u8 *used_by;
__u8 *seen;
@@ -413,8 +413,8 @@ static int recent_cmp(const void *a, const void *b)
return strcmp(mx->name, my->name);
}
-void shirudo_kmodules_print_recent(const struct shirudo_kmod_set *set,
- size_t last_n, __s64 boot_sec)
+void kmodules_print_recent(const struct shirudo_kmod_set *set,
+ size_t last_n, __s64 boot_sec)
{
struct recent_idx *all;
size_t take, i;
@@ -440,12 +440,12 @@ void shirudo_kmodules_print_recent(const struct shirudo_kmod_set *set,
char ts[32], size_s[16], age[24];
if (m->loaded_at_sec <= 0 ||
- shirudo_iso8601((time_t)m->loaded_at_sec, ts, sizeof(ts)))
+ iso8601((time_t)m->loaded_at_sec, ts, sizeof(ts)))
snprintf(ts, sizeof(ts), "?");
- shirudo_human_size(m->size, size_s, sizeof(size_s));
+ human_size(m->size, size_s, sizeof(size_s));
if (boot_sec > 0 && m->loaded_at_sec >= boot_sec)
- shirudo_format_duration((long)(m->loaded_at_sec - boot_sec),
- age, sizeof(age));
+ format_duration((long)(m->loaded_at_sec - boot_sec),
+ age, sizeof(age));
else
snprintf(age, sizeof(age), "?");
diff --git a/util/kmodules.h b/util/kmodules.h
index c1357f1b..3e10703e 100644
--- a/util/kmodules.h
+++ b/util/kmodules.h
@@ -37,18 +37,18 @@ struct shirudo_kmod_set {
size_t n_deps;
};
-int shirudo_kmodules_read(struct shirudo_kmod_set *set);
+int kmodules_read(struct shirudo_kmod_set *set);
/* The text of /proc/modules, modified in place, into set. */
-int shirudo_kmodules_parse(char *buf, struct shirudo_kmod_set *set);
-void shirudo_kmodules_free(struct shirudo_kmod_set *set);
+int kmodules_parse(char *buf, struct shirudo_kmod_set *set);
+void kmodules_free(struct shirudo_kmod_set *set);
-void shirudo_kmodules_print_tree(const struct shirudo_kmod_set *set);
+void kmodules_print_tree(const struct shirudo_kmod_set *set);
/*
* boot_sec is the wallclock instant of boot: the since-boot column is
* elapsed from boot, not time ago.
*/
-void shirudo_kmodules_print_recent(const struct shirudo_kmod_set *set,
- size_t last_n, __s64 boot_sec);
+void kmodules_print_recent(const struct shirudo_kmod_set *set,
+ size_t last_n, __s64 boot_sec);
#endif /* SHIRUDO_UTIL_KMODULES_H */
diff --git a/util/kmsg.c b/util/kmsg.c
index b59d1939..b10e43b4 100644
--- a/util/kmsg.c
+++ b/util/kmsg.c
@@ -125,11 +125,11 @@ static void monotonic_to_iso(__u64 mono_us,
rec.tv_sec++;
}
- if (shirudo_iso8601(rec.tv_sec, out, out_cap))
+ if (iso8601(rec.tv_sec, out, out_cap))
snprintf(out, out_cap, "?");
}
-int shirudo_kmsg_tail(struct shirudo_kmsg_record *out, size_t cap)
+int kmsg_tail(struct shirudo_kmsg_record *out, size_t cap)
{
struct timespec rt_at_open, mt_at_open;
char buf[KMSG_READ_BUF];
diff --git a/util/kmsg.h b/util/kmsg.h
index 675a7ca6..72441b6f 100644
--- a/util/kmsg.h
+++ b/util/kmsg.h
@@ -22,6 +22,6 @@ struct shirudo_kmsg_record {
* Records the ring buffer has dropped are skipped: EPIPE restarts the
* read.
*/
-int shirudo_kmsg_tail(struct shirudo_kmsg_record *out, size_t cap);
+int kmsg_tail(struct shirudo_kmsg_record *out, size_t cap);
#endif /* SHIRUDO_UTIL_KMSG_H */
diff --git a/util/loader.c b/util/loader.c
index a9bd94d4..eaa41e5f 100644
--- a/util/loader.c
+++ b/util/loader.c
@@ -50,7 +50,7 @@ static const struct shirudo_embedded_bpf unload = {
.data = shirudo_unload_bpf_o,
};
-const struct shirudo_embedded_bpf *shirudo_bpf2_blob(void)
+const struct shirudo_embedded_bpf *bpf2_blob(void)
{
static struct shirudo_embedded_bpf b;
@@ -59,7 +59,7 @@ const struct shirudo_embedded_bpf *shirudo_bpf2_blob(void)
return &b;
}
-const struct shirudo_embedded_bpf *shirudo_seal_blob(void)
+const struct shirudo_embedded_bpf *seal_blob(void)
{
static struct shirudo_embedded_bpf b;
@@ -68,7 +68,7 @@ const struct shirudo_embedded_bpf *shirudo_seal_blob(void)
return &b;
}
-const struct shirudo_embedded_bpf *shirudo_unload_blob(void)
+const struct shirudo_embedded_bpf *unload_blob(void)
{
static struct shirudo_embedded_bpf b;
diff --git a/util/loader.h b/util/loader.h
index 3f05f323..50e9559d 100644
--- a/util/loader.h
+++ b/util/loader.h
@@ -16,8 +16,8 @@ struct shirudo_embedded_bpf {
size_t size;
};
-const struct shirudo_embedded_bpf *shirudo_bpf2_blob(void);
-const struct shirudo_embedded_bpf *shirudo_seal_blob(void);
-const struct shirudo_embedded_bpf *shirudo_unload_blob(void);
+const struct shirudo_embedded_bpf *bpf2_blob(void);
+const struct shirudo_embedded_bpf *seal_blob(void);
+const struct shirudo_embedded_bpf *unload_blob(void);
#endif /* SHIRUDO_LOADER_H */
diff --git a/util/log.c b/util/log.c
index 55478a6e..6edaea16 100644
--- a/util/log.c
+++ b/util/log.c
@@ -15,7 +15,7 @@
#define LOG_MSG_MAX 8192
-void shirudo_log_init(void)
+void log_init(void)
{
openlog("shirudo", LOG_PID | LOG_NDELAY, LOG_AUTHPRIV);
}
diff --git a/util/log.h b/util/log.h
index d3c38fc5..9b7b8cca 100644
--- a/util/log.h
+++ b/util/log.h
@@ -10,7 +10,7 @@
#include <stdarg.h>
-void shirudo_log_init(void);
+void log_init(void);
void pr_err(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
diff --git a/util/malloc.c b/util/malloc.c
index 24090ae2..3b30a688 100644
--- a/util/malloc.c
+++ b/util/malloc.c
@@ -103,7 +103,7 @@ void xstrfree(char *s)
free(s);
}
-void shirudo_libc_free(void *p)
+void libc_free(void *p)
{
free(p);
}
diff --git a/util/malloc.h b/util/malloc.h
index 2e9f83ed..b619ecc4 100644
--- a/util/malloc.h
+++ b/util/malloc.h
@@ -52,7 +52,7 @@ void xstrfree(char *s);
* The one path for memory libc allocated, as scandir, getline and
* realpath do; free() itself is poisoned below.
*/
-void shirudo_libc_free(void *p);
+void libc_free(void *p);
/*
* The poison sits at the end so that the system declarations pulled in
diff --git a/util/paths.c b/util/paths.c
index 1941ee43..da0c3d32 100644
--- a/util/paths.c
+++ b/util/paths.c
@@ -13,7 +13,7 @@
#include "paths.h"
-const char *shirudo_keys_dir_resolve(const char *keys_dir_arg)
+const char *keys_dir_resolve(const char *keys_dir_arg)
{
const char *env;
@@ -42,9 +42,9 @@ int shirudo_key_path(char *out, size_t out_sz,
return 0;
}
-int shirudo_key_paths(const char *keys_dir,
- char *pkey_path, size_t pkey_sz,
- char *cert_path, size_t cert_sz)
+int key_paths(const char *keys_dir,
+ char *pkey_path, size_t pkey_sz,
+ char *cert_path, size_t cert_sz)
{
int rc;
@@ -56,7 +56,7 @@ int shirudo_key_paths(const char *keys_dir,
SHIRUDO_CERT_FILE);
}
-bool shirudo_path_exists(const char *path)
+bool path_exists(const char *path)
{
struct stat st;
diff --git a/util/paths.h b/util/paths.h
index 89ea21a2..5e59e6d6 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -118,10 +118,10 @@
int shirudo_key_path(char *out, size_t out_sz,
const char *keys_dir, const char *file);
-int shirudo_key_paths(const char *keys_dir,
- char *pkey_path, size_t pkey_sz,
- char *cert_path, size_t cert_sz);
-const char *shirudo_keys_dir_resolve(const char *keys_dir_arg);
+int key_paths(const char *keys_dir,
+ char *pkey_path, size_t pkey_sz,
+ char *cert_path, size_t cert_sz);
+const char *keys_dir_resolve(const char *keys_dir_arg);
/*
* bpffs reserves dots in path components, which upatch names may
@@ -129,8 +129,8 @@ const char *shirudo_keys_dir_resolve(const char *keys_dir_arg);
* raw name collides. The raw name stays the identity in the format and
* the eventlog.
*/
-static inline int shirudo_upatch_bpffs_name(char *out, size_t out_sz,
- const char *name)
+static inline int upatch_bpffs_name(char *out, size_t out_sz,
+ const char *name)
{
size_t i, j, len;
@@ -151,8 +151,8 @@ static inline int shirudo_upatch_bpffs_name(char *out, size_t out_sz,
return 0;
}
-static inline int shirudo_upatch_name_from_bpffs(char *out, size_t out_sz,
- const char *name)
+static inline int upatch_name_from_bpffs(char *out, size_t out_sz,
+ const char *name)
{
size_t i, j;
@@ -175,6 +175,6 @@ static inline int shirudo_upatch_name_from_bpffs(char *out, size_t out_sz,
return 0;
}
-bool shirudo_path_exists(const char *path);
+bool path_exists(const char *path);
#endif /* SHIRUDO_PATHS_H */
diff --git a/util/preflight.c b/util/preflight.c
index 3444ef01..552b0b93 100644
--- a/util/preflight.c
+++ b/util/preflight.c
@@ -163,7 +163,7 @@ static void check_signed_loader_abi(struct shirudo_preflight_result *r)
next_slot(r, SHIRUDO_PRE_SIGNED_LOADER_ABI,
"signed_loader_kernel_abi");
- if (shirudo_kernel_abi_check(c->detail, sizeof(c->detail)) == 0) {
+ if (kernel_abi_check(c->detail, sizeof(c->detail)) == 0) {
pass(c);
} else {
c->ok = false;
@@ -234,8 +234,8 @@ static int read_cert(const char *path, __u8 **out, size_t *out_sz)
*/
static int preflight_keys(struct shirudo_trusted_set *set)
{
- return shirudo_keys_load(shirudo_keys_dir(), SHIRUDO_KEYS_REVOKED_DIR,
- true, set);
+ return keys_load(shirudo_keys_dir(), SHIRUDO_KEYS_REVOKED_DIR,
+ true, set);
}
static void check_cert_algorithm(struct shirudo_preflight_result *r)
@@ -256,12 +256,12 @@ static void check_cert_algorithm(struct shirudo_preflight_result *r)
char name[64];
int rc;
- if (shirudo_cert_read_file(set.certs[i].path, &cert)) {
+ if (cert_read_file(set.certs[i].path, &cert)) {
fail(r, c, "%s: cannot parse", set.certs[i].path);
return;
}
- rc = shirudo_cert_key_algorithm(&cert, name, sizeof(name));
- shirudo_cert_free(&cert);
+ rc = cert_key_algorithm(&cert, name, sizeof(name));
+ cert_free(&cert);
if (rc) {
fail(r, c, "%s: cannot determine public-key algorithm",
set.certs[i].path);
@@ -363,8 +363,8 @@ static void check_embedded_loader(struct shirudo_preflight_result *r)
{
struct shirudo_preflight_check *c =
next_slot(r, SHIRUDO_PRE_EMBEDDED_LOADER, "embedded_loader");
- const struct shirudo_embedded_bpf *bpf2 = shirudo_bpf2_blob();
- const struct shirudo_embedded_bpf *seal = shirudo_seal_blob();
+ const struct shirudo_embedded_bpf *bpf2 = bpf2_blob();
+ const struct shirudo_embedded_bpf *seal = seal_blob();
size_t bpf2_sz = bpf2 ? bpf2->size : 0;
size_t seal_sz = seal ? seal->size : 0;
@@ -389,7 +389,7 @@ static void check_tpm(struct shirudo_preflight_result *r)
*/
{
struct shirudo_config cfg = {};
- bool override = shirudo_config_load(&cfg) == 0 && cfg.tpm_tcti[0];
+ bool override = config_load(&cfg) == 0 && cfg.tpm_tcti[0];
if (override) {
pass(c);
@@ -413,7 +413,7 @@ static void check_tpm(struct shirudo_preflight_result *r)
strerror(errno));
}
-void shirudo_preflight_run(struct shirudo_preflight_result *out)
+void preflight_run(struct shirudo_preflight_result *out)
{
memset(out, 0, sizeof(*out));
check_root(out);
diff --git a/util/preflight.h b/util/preflight.h
index 81343da6..725d6b0a 100644
--- a/util/preflight.h
+++ b/util/preflight.h
@@ -44,6 +44,6 @@ struct shirudo_preflight_result {
* or a classical certificate. Nothing is printed; the caller presents
* the outcome.
*/
-void shirudo_preflight_run(struct shirudo_preflight_result *out);
+void preflight_run(struct shirudo_preflight_result *out);
#endif /* SHIRUDO_PREFLIGHT_H */
diff --git a/util/report.c b/util/report.c
index 68f1eb81..bb450455 100644
--- a/util/report.c
+++ b/util/report.c
@@ -17,7 +17,7 @@
#include "paths.h"
#include "report.h"
-int shirudo_report_emit(const char *path, const struct shirudo_op_report *r)
+int report_emit(const char *path, const struct shirudo_op_report *r)
{
struct shirudo_json_emit e;
struct utsname uts;
@@ -38,45 +38,45 @@ int shirudo_report_emit(const char *path, const struct shirudo_op_report *r)
snprintf(nv_index, sizeof(nv_index), "0x%08X", SHIRUDO_NV_INDEX);
errname = r->err ? strerrorname_np(r->err) : NULL;
- shirudo_json_obj_open(&e);
- shirudo_json_kv_int(&e, "schema", 1);
- shirudo_json_kv_string(&e, "result", r->ok ? "ok" : "failed");
- shirudo_json_kv_string(&e, "op", r->op ? r->op : "");
- shirudo_json_kv_string(&e, "phase", r->phase ? r->phase : "done");
+ json_obj_open(&e);
+ json_kv_int(&e, "schema", 1);
+ json_kv_string(&e, "result", r->ok ? "ok" : "failed");
+ json_kv_string(&e, "op", r->op ? r->op : "");
+ json_kv_string(&e, "phase", r->phase ? r->phase : "done");
if (r->err)
- shirudo_json_kv_int(&e, "errno", r->err);
+ json_kv_int(&e, "errno", r->err);
else
- shirudo_json_kv_null(&e, "errno");
+ json_kv_null(&e, "errno");
if (errname)
- shirudo_json_kv_string(&e, "errno_name", errname);
+ json_kv_string(&e, "errno_name", errname);
else
- shirudo_json_kv_null(&e, "errno_name");
- shirudo_json_kv_string(&e, "category", r->category ? r->category
+ json_kv_null(&e, "errno_name");
+ json_kv_string(&e, "category", r->category ? r->category
: (r->ok ? "ok" : "unknown"));
- shirudo_json_kv_string(&e, "message", r->message);
- shirudo_json_kv_string(&e, "verifier_log", vlog);
- shirudo_json_kv_int(&e, "loader_return", r->loader_return);
+ json_kv_string(&e, "message", r->message);
+ json_kv_string(&e, "verifier_log", vlog);
+ json_kv_int(&e, "loader_return", r->loader_return);
- shirudo_json_obj_open_key(&e, "upatch");
- shirudo_json_kv_string(&e, "path", r->path ? r->path : "");
- shirudo_json_kv_string(&e, "name", r->name ? r->name : "");
- shirudo_json_kv_string(&e, "payload_sha256", r->payload_hex);
- shirudo_json_obj_close(&e);
+ json_obj_open_key(&e, "upatch");
+ json_kv_string(&e, "path", r->path ? r->path : "");
+ json_kv_string(&e, "name", r->name ? r->name : "");
+ json_kv_string(&e, "payload_sha256", r->payload_hex);
+ json_obj_close(&e);
- shirudo_json_obj_open_key(&e, "kernel");
- shirudo_json_kv_string(&e, "release",
- uname(&uts) == 0 ? uts.release : "");
- shirudo_json_obj_close(&e);
+ json_obj_open_key(&e, "kernel");
+ json_kv_string(&e, "release",
+ uname(&uts) == 0 ? uts.release : "");
+ json_obj_close(&e);
if (r->ok && r->tpm_present) {
- shirudo_json_obj_open_key(&e, "tpm");
- shirudo_json_kv_string(&e, "nv_index", nv_index);
- shirudo_json_kv_string(&e, "chain_after", r->chain_after);
- shirudo_json_obj_close(&e);
+ json_obj_open_key(&e, "tpm");
+ json_kv_string(&e, "nv_index", nv_index);
+ json_kv_string(&e, "chain_after", r->chain_after);
+ json_obj_close(&e);
} else {
- shirudo_json_kv_null(&e, "tpm");
+ json_kv_null(&e, "tpm");
}
- shirudo_json_obj_close(&e);
+ json_obj_close(&e);
if (e.err) {
pr_err("report: encode failed: %s", strerror(-e.err));
@@ -105,7 +105,7 @@ int shirudo_report_emit(const char *path, const struct shirudo_op_report *r)
return rc;
}
-void shirudo_report_set_log(struct shirudo_op_report *r, const char *log)
+void report_set_log(struct shirudo_op_report *r, const char *log)
{
if (!r)
return;
@@ -120,7 +120,7 @@ void shirudo_report_set_log(struct shirudo_op_report *r, const char *log)
r->verifier_log = xstrndup(log, SHIRUDO_VERIFIER_LOG_MAX);
}
-void shirudo_report_free(struct shirudo_op_report *r)
+void report_free(struct shirudo_op_report *r)
{
xstrfree(r->verifier_log);
r->verifier_log = NULL;
diff --git a/util/report.h b/util/report.h
index 43054d33..51289ba0 100644
--- a/util/report.h
+++ b/util/report.h
@@ -40,9 +40,9 @@ struct shirudo_op_report {
char chain_after[65];
};
-int shirudo_report_emit(const char *path, const struct shirudo_op_report *r);
+int report_emit(const char *path, const struct shirudo_op_report *r);
-void shirudo_report_set_log(struct shirudo_op_report *r, const char *log);
-void shirudo_report_free(struct shirudo_op_report *r);
+void report_set_log(struct shirudo_op_report *r, const char *log);
+void report_free(struct shirudo_op_report *r);
#endif /* SHIRUDO_REPORT_H */
diff --git a/util/seal.c b/util/seal.c
index b7f26b38..6e50dc9b 100644
--- a/util/seal.c
+++ b/util/seal.c
@@ -24,7 +24,7 @@
#define SEAL_LABEL_LEN (sizeof(SHIRUDO_SEAL_LABEL) - 1)
-int shirudo_seal_label(const char *path)
+int seal_label(const char *path)
{
if (lsetxattr(path, SHIRUDO_XATTR_NAME, SHIRUDO_SEAL_LABEL,
sizeof(SHIRUDO_SEAL_LABEL) - 1, 0) != 0)
@@ -52,12 +52,12 @@ static int seal_label_cb(const char *path, const struct stat *sb,
*/
if (sb->st_dev != seal_root_dev)
return 0;
- if (shirudo_seal_label(path) != 0)
+ if (seal_label(path) != 0)
pr_warn("seal: label %s: %s", path, strerror(errno));
return 0; /* best-effort: keep walking */
}
-int shirudo_seal_label_tree(void)
+int seal_label_tree(void)
{
char self[PATH_MAX];
struct stat st;
@@ -67,7 +67,7 @@ int shirudo_seal_label_tree(void)
n = readlink("/proc/self/exe", self, sizeof(self) - 1);
if (n > 0) {
self[n] = '\0';
- if (shirudo_seal_label(self) != 0)
+ if (seal_label(self) != 0)
pr_warn("seal: label %s: %s", self, strerror(errno));
}
@@ -132,7 +132,7 @@ static int seal_open_parent(const char *path, const char **name)
return fd;
}
-int shirudo_seal_inherit(int dfd, int fd)
+int seal_inherit(int dfd, int fd)
{
char parent[SEAL_LABEL_LEN], own[SEAL_LABEL_LEN];
ssize_t plen, olen;
@@ -150,7 +150,7 @@ int shirudo_seal_inherit(int dfd, int fd)
return 0;
}
-int shirudo_seal_inherit_path(const char *path)
+int seal_inherit_path(const char *path)
{
char parent[SEAL_LABEL_LEN], own[SEAL_LABEL_LEN];
ssize_t plen, olen;
@@ -174,7 +174,7 @@ int shirudo_seal_inherit_path(const char *path)
return 0;
}
-int shirudo_seal_open(const char *path, int flags, mode_t mode)
+int seal_open(const char *path, int flags, mode_t mode)
{
const char *name;
int dfd, fd, rc;
@@ -188,7 +188,7 @@ int shirudo_seal_open(const char *path, int flags, mode_t mode)
close(dfd);
return rc;
}
- rc = shirudo_seal_inherit(dfd, fd);
+ rc = seal_inherit(dfd, fd);
close(dfd);
if (rc) {
close(fd);
@@ -197,7 +197,7 @@ int shirudo_seal_open(const char *path, int flags, mode_t mode)
return fd;
}
-int shirudo_seal_mkdir_p(const char *path, mode_t mode)
+int seal_mkdir_p(const char *path, mode_t mode)
{
char buf[PATH_MAX], *comp, *save;
int dfd, nfd, rc = 0;
@@ -222,7 +222,7 @@ int shirudo_seal_mkdir_p(const char *path, mode_t mode)
break;
}
if (created)
- rc = shirudo_seal_inherit(dfd, nfd);
+ rc = seal_inherit(dfd, nfd);
close(dfd);
dfd = nfd;
if (rc)
@@ -232,8 +232,8 @@ int shirudo_seal_mkdir_p(const char *path, mode_t mode)
return rc;
}
-int shirudo_seal_write_file(const char *path, const void *data, size_t len,
- mode_t mode)
+int seal_write_file(const char *path, const void *data, size_t len,
+ mode_t mode)
{
char tmp[NAME_MAX + 1];
const char *name;
@@ -253,9 +253,9 @@ int shirudo_seal_write_file(const char *path, const void *data, size_t len,
close(dfd);
return rc;
}
- rc = shirudo_seal_inherit(dfd, fd);
+ rc = seal_inherit(dfd, fd);
if (!rc)
- rc = shirudo_write_all(fd, data, len);
+ rc = write_all(fd, data, len);
if (!rc && fsync(fd))
rc = -errno;
if (close(fd) && !rc)
diff --git a/util/seal.h b/util/seal.h
index 039ac7b2..ab2c7a54 100644
--- a/util/seal.h
+++ b/util/seal.h
@@ -20,13 +20,13 @@
"94442b45cfcdc59aabc2a91364ed2ae129418e05a5c1985231b9c032e673f469"
/* A symlink's own inode, not its target's. Idempotent. */
-int shirudo_seal_label(const char *path);
+int seal_label(const char *path);
/*
* Before the seal attaches, so the bulk setxattr is not gated; best
* effort per entry.
*/
-int shirudo_seal_label_tree(void);
+int seal_label_tree(void);
/*
* Creating under a sealed directory. The directory decides: an inode
@@ -40,18 +40,18 @@ int shirudo_seal_label_tree(void);
* failure, a sealed inode that could not be labelled included.
*/
-int shirudo_seal_open(const char *path, int flags, mode_t mode);
+int seal_open(const char *path, int flags, mode_t mode);
/* mkdir -p, every directory created labelled as its parent is. */
-int shirudo_seal_mkdir_p(const char *path, mode_t mode);
+int seal_mkdir_p(const char *path, mode_t mode);
-int shirudo_seal_write_file(const char *path, const void *data, size_t len,
- mode_t mode);
+int seal_write_file(const char *path, const void *data, size_t len,
+ mode_t mode);
/* Give the inode behind fd the label of its directory, open as dfd. */
-int shirudo_seal_inherit(int dfd, int fd);
+int seal_inherit(int dfd, int fd);
/* The same by path, without following a symlink. */
-int shirudo_seal_inherit_path(const char *path);
+int seal_inherit_path(const char *path);
#endif /* SHIRUDO_SEAL_H */
diff --git a/util/serializer.c b/util/serializer.c
index 54ffae95..b25b48a6 100644
--- a/util/serializer.c
+++ b/util/serializer.c
@@ -15,7 +15,7 @@
#include "seal.h"
#include "serializer.h"
-int shirudo_serializer_lock_acquire_at(const char *dir, __u32 map_id)
+int serializer_lock_acquire_at(const char *dir, __u32 map_id)
{
char name[64];
struct stat st;
@@ -23,7 +23,7 @@ int shirudo_serializer_lock_acquire_at(const char *dir, __u32 map_id)
if (!dir || !dir[0] || map_id == 0)
return -EINVAL;
- rc = shirudo_seal_mkdir_p(dir, 0700);
+ rc = seal_mkdir_p(dir, 0700);
if (rc)
return rc;
dir_fd = open(dir, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
@@ -40,7 +40,7 @@ int shirudo_serializer_lock_acquire_at(const char *dir, __u32 map_id)
close(dir_fd);
return rc;
}
- rc = shirudo_seal_inherit(dir_fd, fd);
+ rc = seal_inherit(dir_fd, fd);
close(dir_fd);
if (rc) {
close(fd);
@@ -64,12 +64,12 @@ int shirudo_serializer_lock_acquire_at(const char *dir, __u32 map_id)
return fd;
}
-int shirudo_serializer_lock_acquire(__u32 map_id)
+int serializer_lock_acquire(__u32 map_id)
{
- return shirudo_serializer_lock_acquire_at(SHIRUDO_LOCKS_DIR, map_id);
+ return serializer_lock_acquire_at(SHIRUDO_LOCKS_DIR, map_id);
}
-int shirudo_serializer_new_invocation_id(__u64 *out)
+int serializer_new_invocation_id(__u64 *out)
{
__u64 id;
__u8 *p = (__u8 *)&id;
@@ -96,13 +96,13 @@ int shirudo_serializer_new_invocation_id(__u64 *out)
return 0;
}
-int shirudo_serial_chunk_validate(const struct shirudo_serial_chunk *c,
- __u32 want_index,
- __u32 total_chunks,
- __u32 page_index,
- __u64 cursor,
- __u64 next_cursor,
- __u64 invocation_id)
+int serial_chunk_validate(const struct shirudo_serial_chunk *c,
+ __u32 want_index,
+ __u32 total_chunks,
+ __u32 page_index,
+ __u64 cursor,
+ __u64 next_cursor,
+ __u64 invocation_id)
{
if (!c || invocation_id == 0)
return -EINVAL;
diff --git a/util/serializer.h b/util/serializer.h
index 6a002832..fc7a64b0 100644
--- a/util/serializer.h
+++ b/util/serializer.h
@@ -8,16 +8,16 @@
#include "bpf/lib/shirudo_serializer.h"
-int shirudo_serializer_lock_acquire(__u32 map_id);
-int shirudo_serializer_lock_acquire_at(const char *dir, __u32 map_id);
-int shirudo_serializer_new_invocation_id(__u64 *out);
+int serializer_lock_acquire(__u32 map_id);
+int serializer_lock_acquire_at(const char *dir, __u32 map_id);
+int serializer_new_invocation_id(__u64 *out);
-int shirudo_serial_chunk_validate(const struct shirudo_serial_chunk *chunk,
- __u32 want_index,
- __u32 total_chunks,
- __u32 page_index,
- __u64 cursor,
- __u64 next_cursor,
- __u64 invocation_id);
+int serial_chunk_validate(const struct shirudo_serial_chunk *chunk,
+ __u32 want_index,
+ __u32 total_chunks,
+ __u32 page_index,
+ __u64 cursor,
+ __u64 next_cursor,
+ __u64 invocation_id);
#endif /* SHIRUDO_UTIL_SERIALIZER_H */
diff --git a/util/sign.c b/util/sign.c
index 4a00b467..77037630 100644
--- a/util/sign.c
+++ b/util/sign.c
@@ -68,7 +68,7 @@ static void display_openssl_errors(void)
display_openssl_errors(); \
} while (0)
-int shirudo_open_signing_key(const char *pkey_path)
+int open_signing_key(const char *pkey_path)
{
struct stat st;
int fd, rc;
@@ -108,7 +108,7 @@ static EVP_PKEY *read_private_key(const char *pkey_path)
BIO *b;
int fd;
- fd = shirudo_open_signing_key(pkey_path);
+ fd = open_signing_key(pkey_path);
if (fd < 0)
return NULL;
b = BIO_new_fd(fd, BIO_CLOSE);
@@ -159,8 +159,8 @@ static bool pkey_is_mldsa(const EVP_PKEY *pkey)
return name && strncasecmp(name, "ML-DSA", 6) == 0;
}
-int shirudo_cms_sign(struct shirudo_sign_io *io,
- const char *pkey_path, const char *cert_path)
+int cms_sign(struct shirudo_sign_io *io,
+ const char *pkey_path, const char *cert_path)
{
unsigned int signer_flags = CMS_NOCERTS | CMS_BINARY | CMS_NOSMIMECAP |
#ifdef CMS_NO_SIGNING_TIME
diff --git a/util/sign.h b/util/sign.h
index de37ebf8..9b9a2553 100644
--- a/util/sign.h
+++ b/util/sign.h
@@ -36,13 +36,13 @@ struct shirudo_sign_io {
* -ENOSPC when the signature buffer is too small, -EINVAL on a parse
* failure, -EIO on an OpenSSL failure.
*/
-int shirudo_cms_sign(struct shirudo_sign_io *io,
- const char *pkey_path, const char *cert_path);
+int cms_sign(struct shirudo_sign_io *io,
+ const char *pkey_path, const char *cert_path);
/*
* Opens the private key and checks, on that descriptor, that it is a
* regular file of mode 0600. The descriptor, or -errno logged.
*/
-int shirudo_open_signing_key(const char *pkey_path);
+int open_signing_key(const char *pkey_path);
#endif /* SHIRUDO_SIGN_H */
diff --git a/util/similar.c b/util/similar.c
index e6fae60c..8a1975cf 100644
--- a/util/similar.c
+++ b/util/similar.c
@@ -9,7 +9,7 @@
#include "similar.h"
-static int shirudo_edit_distance(const char *s, const char *t, int max)
+static int edit_distance(const char *s, const char *t, int max)
{
int prev[SHIRUDO_SIMILAR_MAX_LEN + 1];
int curr[SHIRUDO_SIMILAR_MAX_LEN + 1];
@@ -64,10 +64,10 @@ static int shirudo_edit_distance(const char *s, const char *t, int max)
return prev[n];
}
-size_t shirudo_suggest(const char *name,
- const char *const *commands, size_t n_commands,
- int max_dist,
- struct shirudo_suggestion *out, size_t cap)
+size_t suggest(const char *name,
+ const char *const *commands, size_t n_commands,
+ int max_dist,
+ struct shirudo_suggestion *out, size_t cap)
{
size_t n_out = 0;
size_t i;
@@ -76,7 +76,7 @@ size_t shirudo_suggest(const char *name,
return 0;
for (i = 0; i < n_commands; i++) {
- int d = shirudo_edit_distance(name, commands[i], max_dist);
+ int d = edit_distance(name, commands[i], max_dist);
size_t pos;
if (d > max_dist)
@@ -102,9 +102,9 @@ size_t shirudo_suggest(const char *name,
return n_out;
}
-size_t shirudo_resolve(const char *input,
- const char *const *candidates, size_t n,
- size_t *matches, size_t cap)
+size_t resolve(const char *input,
+ const char *const *candidates, size_t n,
+ size_t *matches, size_t cap)
{
size_t i, m = 0, len = strlen(input);
diff --git a/util/similar.h b/util/similar.h
index 6a3e664f..e09ecc5d 100644
--- a/util/similar.h
+++ b/util/similar.h
@@ -22,18 +22,18 @@ struct shirudo_suggestion {
int dist;
};
-size_t shirudo_suggest(const char *name,
- const char *const *commands, size_t n_commands,
- int max_dist,
- struct shirudo_suggestion *out, size_t cap);
+size_t suggest(const char *name,
+ const char *const *commands, size_t n_commands,
+ int max_dist,
+ struct shirudo_suggestion *out, size_t cap);
/*
* Three tiers, the first that hits wins: exact, input a prefix of a
* candidate, candidate a prefix of input. The count tells unique from
* none from ambiguous.
*/
-size_t shirudo_resolve(const char *input,
- const char *const *candidates, size_t n,
- size_t *matches, size_t cap);
+size_t resolve(const char *input,
+ const char *const *candidates, size_t n,
+ size_t *matches, size_t cap);
#endif /* SHIRUDO_SIMILAR_H */
diff --git a/util/string.c b/util/string.c
index 80a434bf..664861f4 100644
--- a/util/string.c
+++ b/util/string.c
@@ -11,7 +11,7 @@
#include <shirudo/string.h>
-size_t shirudo_digits(const char *s, size_t len)
+size_t digits(const char *s, size_t len)
{
size_t n = 0;
diff --git a/util/sysinfo.c b/util/sysinfo.c
index e9efbf10..d328894c 100644
--- a/util/sysinfo.c
+++ b/util/sysinfo.c
@@ -168,9 +168,9 @@ static void kernel_config_entries_free(struct kernel_config_entry *entries,
xfree(entries, n * sizeof(*entries));
}
-int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
- shirudo_kernel_config_cb cb,
- void *ctx)
+int sysinfo_kernel_config_foreach(const char *kernel_release,
+ shirudo_kernel_config_cb cb,
+ void *ctx)
{
char path[PATH_MAX];
char line[8192];
@@ -259,20 +259,20 @@ int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
static void emit_kernel_config_entry(void *ctx, const char *key,
const char *value)
{
- shirudo_json_kv_string(ctx, key, value);
+ json_kv_string(ctx, key, value);
}
static void emit_kernel_config(struct shirudo_json_emit *e,
const char *kernel_release)
{
- shirudo_json_obj_open_key(e, "kernel_config");
- shirudo_sysinfo_kernel_config_foreach(kernel_release,
- emit_kernel_config_entry, e);
+ json_obj_open_key(e, "kernel_config");
+ sysinfo_kernel_config_foreach(kernel_release,
+ emit_kernel_config_entry, e);
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
-void shirudo_sysinfo_gather(struct shirudo_sysinfo *si)
+void sysinfo_gather(struct shirudo_sysinfo *si)
{
struct utsname u;
@@ -304,7 +304,7 @@ void shirudo_sysinfo_gather(struct shirudo_sysinfo *si)
sizeof(si->machine_id));
read_first_line("/proc/sys/kernel/random/boot_id", si->boot_id,
sizeof(si->boot_id));
- (void)shirudo_kernel_build_id_read(si->kernel_build_id);
+ (void)kernel_build_id_read(si->kernel_build_id);
si->nproc = sysconf(_SC_NPROCESSORS_ONLN);
read_mem(&si->mem_total_kb, &si->mem_avail_kb);
@@ -312,24 +312,24 @@ void shirudo_sysinfo_gather(struct shirudo_sysinfo *si)
si->uptime_sec = read_uptime_sec();
}
-void shirudo_sysinfo_emit_json(struct shirudo_json_emit *e,
- const struct shirudo_sysinfo *si)
+void sysinfo_emit_json(struct shirudo_json_emit *e,
+ const struct shirudo_sysinfo *si)
{
- shirudo_json_obj_open_key(e, "system");
- shirudo_json_kv_string(e, "hostname", si->hostname);
- shirudo_json_kv_string(e, "os", si->os_pretty);
- shirudo_json_kv_string(e, "kernel_release", si->kernel_release);
- shirudo_json_kv_string(e, "kernel_version", si->kernel_version);
- shirudo_json_kv_string(e, "kernel_build_id", si->kernel_build_id);
+ json_obj_open_key(e, "system");
+ json_kv_string(e, "hostname", si->hostname);
+ json_kv_string(e, "os", si->os_pretty);
+ json_kv_string(e, "kernel_release", si->kernel_release);
+ json_kv_string(e, "kernel_version", si->kernel_version);
+ json_kv_string(e, "kernel_build_id", si->kernel_build_id);
emit_kernel_config(e, si->kernel_release);
- shirudo_json_kv_string(e, "architecture", si->machine);
- shirudo_json_kv_string(e, "machine_id", si->machine_id);
- shirudo_json_kv_string(e, "boot_id", si->boot_id);
- shirudo_json_kv_int(e, "nproc", si->nproc);
- shirudo_json_kv_int(e, "mem_total_kb", si->mem_total_kb);
- shirudo_json_kv_int(e, "mem_avail_kb", si->mem_avail_kb);
- shirudo_json_kv_int(e, "disk_total_kb", si->disk_total_kb);
- shirudo_json_kv_int(e, "disk_used_kb", si->disk_used_kb);
- shirudo_json_kv_int(e, "uptime_seconds", si->uptime_sec);
- shirudo_json_obj_close(e);
+ json_kv_string(e, "architecture", si->machine);
+ json_kv_string(e, "machine_id", si->machine_id);
+ json_kv_string(e, "boot_id", si->boot_id);
+ json_kv_int(e, "nproc", si->nproc);
+ json_kv_int(e, "mem_total_kb", si->mem_total_kb);
+ json_kv_int(e, "mem_avail_kb", si->mem_avail_kb);
+ json_kv_int(e, "disk_total_kb", si->disk_total_kb);
+ json_kv_int(e, "disk_used_kb", si->disk_used_kb);
+ json_kv_int(e, "uptime_seconds", si->uptime_sec);
+ json_obj_close(e);
}
diff --git a/util/sysinfo.h b/util/sysinfo.h
index c5a8b48a..132f9f97 100644
--- a/util/sysinfo.h
+++ b/util/sysinfo.h
@@ -29,18 +29,18 @@ struct shirudo_sysinfo {
};
/* Fill *si; missing values become "" (strings) or -1 (numbers). */
-void shirudo_sysinfo_gather(struct shirudo_sysinfo *si);
+void sysinfo_gather(struct shirudo_sysinfo *si);
struct shirudo_json_emit;
typedef void (*shirudo_kernel_config_cb)(void *ctx, const char *key,
const char *value);
-int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
- shirudo_kernel_config_cb cb,
- void *ctx);
+int sysinfo_kernel_config_foreach(const char *kernel_release,
+ shirudo_kernel_config_cb cb,
+ void *ctx);
-void shirudo_sysinfo_emit_json(struct shirudo_json_emit *e,
- const struct shirudo_sysinfo *si);
+void sysinfo_emit_json(struct shirudo_json_emit *e,
+ const struct shirudo_sysinfo *si);
#endif /* SHIRUDO_SYSINFO_H */
diff --git a/util/tamper.c b/util/tamper.c
index 2ae65ab4..1ebd433e 100644
--- a/util/tamper.c
+++ b/util/tamper.c
@@ -78,21 +78,21 @@ static const struct {
"perf event bound to a shirudo task" },
};
-const char *shirudo_tamper_name(enum shirudo_tamper_point point)
+const char *tamper_name(enum shirudo_tamper_point point)
{
if (point >= SHIRUDO_TAMPER_MAX || !tamper_points[point].name)
return "?";
return tamper_points[point].name;
}
-const char *shirudo_tamper_meaning(enum shirudo_tamper_point point)
+const char *tamper_meaning(enum shirudo_tamper_point point)
{
if (point >= SHIRUDO_TAMPER_MAX || !tamper_points[point].meaning)
return "?";
return tamper_points[point].meaning;
}
-int shirudo_tamper_read(struct shirudo_tamper_counts *out)
+int tamper_read(struct shirudo_tamper_counts *out)
{
struct bpf_map_info info = {};
__u32 len = sizeof(info);
diff --git a/util/tamper.h b/util/tamper.h
index 7dd30c36..e13fef38 100644
--- a/util/tamper.h
+++ b/util/tamper.h
@@ -16,14 +16,14 @@ struct shirudo_tamper_counts {
__u64 total;
};
-const char *shirudo_tamper_name(enum shirudo_tamper_point point);
-const char *shirudo_tamper_meaning(enum shirudo_tamper_point point);
+const char *tamper_name(enum shirudo_tamper_point point);
+const char *tamper_meaning(enum shirudo_tamper_point point);
/*
* The counters the LSM has kept this boot. -ENOENT when init has not
* run, -EPROTO when the pinned map is not the shape this binary knows,
* another -errno when the pin cannot be read.
*/
-int shirudo_tamper_read(struct shirudo_tamper_counts *out);
+int tamper_read(struct shirudo_tamper_counts *out);
#endif /* SHIRUDO_UTIL_TAMPER_H */
diff --git a/util/tenant_id.h b/util/tenant_id.h
index a7cdcd93..d7b8a2d3 100644
--- a/util/tenant_id.h
+++ b/util/tenant_id.h
@@ -11,7 +11,7 @@
#define SHIRUDO_TENANT_ID_MAX 128
-static inline bool shirudo_tenant_id_valid(const char *id)
+static inline bool tenant_id_valid(const char *id)
{
size_t i;
diff --git a/util/timefmt.c b/util/timefmt.c
index 002d8bb9..0e5f31df 100644
--- a/util/timefmt.c
+++ b/util/timefmt.c
@@ -10,7 +10,7 @@
#include "timefmt.h"
-void shirudo_format_duration(long seconds, char *buf, size_t cap)
+void format_duration(long seconds, char *buf, size_t cap)
{
if (seconds < 0)
snprintf(buf, cap, "?");
@@ -24,7 +24,7 @@ void shirudo_format_duration(long seconds, char *buf, size_t cap)
snprintf(buf, cap, "%ldd", seconds / 86400);
}
-int shirudo_iso8601(time_t t, char *out, size_t cap)
+int iso8601(time_t t, char *out, size_t cap)
{
struct tm tm;
diff --git a/util/timefmt.h b/util/timefmt.h
index 0dc5d8f2..9f86cc23 100644
--- a/util/timefmt.h
+++ b/util/timefmt.h
@@ -12,9 +12,9 @@
#include <time.h>
/* A negative seconds writes "?"; cap must hold the worst-case %ldd. */
-void shirudo_format_duration(long seconds, char *buf, size_t cap);
+void format_duration(long seconds, char *buf, size_t cap);
/* UTC to the second; "" and -EINVAL when t cannot be rendered. */
-int shirudo_iso8601(time_t t, char *out, size_t cap);
+int iso8601(time_t t, char *out, size_t cap);
#endif /* SHIRUDO_TIMEFMT_H */
diff --git a/util/tls_openssl.c b/util/tls_openssl.c
index e44dff0e..4c9d8e7c 100644
--- a/util/tls_openssl.c
+++ b/util/tls_openssl.c
@@ -26,7 +26,7 @@
*/
#define SHIRUDO_TLS_GROUPS "*X25519MLKEM768:SecP256r1MLKEM768"
-void shirudo_tls_ca_cleanup(struct shirudo_tls_ca *ca)
+void tls_ca_cleanup(struct shirudo_tls_ca *ca)
{
if (ca)
ca->impl = NULL;
@@ -52,7 +52,7 @@ static CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr)
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return CURLE_SSL_CACERT_BADFILE;
- if (shirudo_check_trusted(fd, path, false)) {
+ if (check_trusted(fd, path, false)) {
close(fd);
return CURLE_SSL_CACERT_BADFILE;
}
@@ -71,7 +71,7 @@ static CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr)
return CURLE_OK;
}
-int shirudo_tls_curl_policy(CURL *curl, struct shirudo_tls_ca *ca)
+int tls_curl_policy(CURL *curl, struct shirudo_tls_ca *ca)
{
if (!curl)
return -EINVAL;
diff --git a/util/tpm.c b/util/tpm.c
index b13c6220..34680edf 100644
--- a/util/tpm.c
+++ b/util/tpm.c
@@ -30,7 +30,7 @@ struct shirudo_tpm {
ESYS_CONTEXT *esys;
};
-int shirudo_tpm_open(struct shirudo_tpm **out)
+int tpm_open(struct shirudo_tpm **out)
{
struct shirudo_config cfg = {};
struct shirudo_tpm *t;
@@ -55,7 +55,7 @@ int shirudo_tpm_open(struct shirudo_tpm **out)
* since evidence is signed by the key the operator pinned.
*/
tcti = getenv("SHIRUDO_TPM_TCTI");
- if ((!tcti || !*tcti) && shirudo_config_load(&cfg) == 0 &&
+ if ((!tcti || !*tcti) && config_load(&cfg) == 0 &&
cfg.tpm_tcti[0])
tcti = cfg.tpm_tcti;
if (!tcti || !*tcti)
@@ -81,7 +81,7 @@ int shirudo_tpm_open(struct shirudo_tpm **out)
return 0;
}
-void shirudo_tpm_close(struct shirudo_tpm *t)
+void tpm_close(struct shirudo_tpm *t)
{
if (!t)
return;
@@ -119,8 +119,8 @@ static void pcr_selection(__u32 mask, TPML_PCR_SELECTION *sel)
sel->pcrSelections[0].pcrSelect[2] = (__u8)(mask >> 16);
}
-int shirudo_tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,
- __u8 out[32])
+int tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,
+ __u8 out[32])
{
TPML_PCR_SELECTION sel;
TPML_DIGEST *values = NULL;
@@ -146,8 +146,8 @@ int shirudo_tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,
return 0;
}
-int shirudo_tpm_pcr_extend(struct shirudo_tpm *t, __u32 pcr,
- const __u8 digest[32])
+int tpm_pcr_extend(struct shirudo_tpm *t, __u32 pcr,
+ const __u8 digest[32])
{
TPML_DIGEST_VALUES dv = { .count = 1 };
TSS2_RC rc;
@@ -165,7 +165,7 @@ int shirudo_tpm_pcr_extend(struct shirudo_tpm *t, __u32 pcr,
return 0;
}
-int shirudo_tpm_reset_count(struct shirudo_tpm *t, __u32 *out)
+int tpm_reset_count(struct shirudo_tpm *t, __u32 *out)
{
TPMS_TIME_INFO *info = NULL;
TSS2_RC rc;
@@ -197,8 +197,8 @@ static int nv_handle(struct shirudo_tpm *t, __u32 index, ESYS_TR *out)
return 0;
}
-int shirudo_tpm_nv_info(struct shirudo_tpm *t, __u32 index,
- struct shirudo_tpm_nv_info *info)
+int tpm_nv_info(struct shirudo_tpm *t, __u32 index,
+ struct tpm_nv_info *info)
{
TPM2B_NV_PUBLIC *pub = NULL;
TPM2B_NAME *name = NULL;
@@ -276,9 +276,9 @@ static int owner_auth_error(const char *op, __u32 index, TSS2_RC rc)
return -EIO;
}
-int shirudo_tpm_nv_define(struct shirudo_tpm *t, __u32 index,
- const __u8 policy[32],
- const void *owner_auth, size_t owner_auth_len)
+int tpm_nv_define(struct shirudo_tpm *t, __u32 index,
+ const __u8 policy[32],
+ const void *owner_auth, size_t owner_auth_len)
{
TPM2B_NV_PUBLIC pub = {};
TPM2B_AUTH nv_auth = {};
@@ -305,8 +305,8 @@ int shirudo_tpm_nv_define(struct shirudo_tpm *t, __u32 index,
return 0;
}
-int shirudo_tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
- const void *owner_auth, size_t owner_auth_len)
+int tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
+ const void *owner_auth, size_t owner_auth_len)
{
ESYS_TR nv;
TSS2_RC rc;
@@ -327,7 +327,7 @@ int shirudo_tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
return 0;
}
-int shirudo_tpm_nv_read(struct shirudo_tpm *t, __u32 index, __u8 out[32])
+int tpm_nv_read(struct shirudo_tpm *t, __u32 index, __u8 out[32])
{
TPM2B_MAX_NV_BUFFER *data = NULL;
ESYS_TR nv;
@@ -431,7 +431,7 @@ static int policy_session_register(struct shirudo_tpm *t, bool init,
}
rc = Esys_PolicyGetDigest(t->esys, *session, ESYS_TR_NONE,
ESYS_TR_NONE, ESYS_TR_NONE, &digest);
- shirudo_tpm_policy_or(branch_written, branch_init, expected);
+ tpm_policy_or(branch_written, branch_init, expected);
if (rc != TSS2_RC_SUCCESS || digest->size != 32 ||
memcmp(digest->buffer, expected, 32) != 0) {
pr_err("tpm: register policy digest does not match the "
@@ -468,11 +468,11 @@ static int nv_extend_session(struct shirudo_tpm *t, __u32 index,
return 0;
}
-int shirudo_tpm_nv_extend_first(struct shirudo_tpm *t, __u32 index,
- __u32 pcr_mask,
- const __u8 branch_written[32],
- const __u8 branch_init[32],
- const __u8 event[32])
+int tpm_nv_extend_first(struct shirudo_tpm *t, __u32 index,
+ __u32 pcr_mask,
+ const __u8 branch_written[32],
+ const __u8 branch_init[32],
+ const __u8 event[32])
{
ESYS_TR session = ESYS_TR_NONE;
int err;
@@ -486,10 +486,10 @@ int shirudo_tpm_nv_extend_first(struct shirudo_tpm *t, __u32 index,
return err;
}
-int shirudo_tpm_nv_extend(struct shirudo_tpm *t, __u32 index,
- const __u8 branch_written[32],
- const __u8 branch_init[32],
- const __u8 event[32])
+int tpm_nv_extend(struct shirudo_tpm *t, __u32 index,
+ const __u8 branch_written[32],
+ const __u8 branch_init[32],
+ const __u8 event[32])
{
ESYS_TR session = ESYS_TR_NONE;
int err;
@@ -551,7 +551,7 @@ static int public_from_tss(const TPMT_PUBLIC *p, __u8 *out, size_t cap,
} else {
return -EPROTONOSUPPORT;
}
- return shirudo_tpm_public_marshal(&pub, out, cap, len);
+ return tpm_public_marshal(&pub, out, cap, len);
}
static int marshal_signature(const TPMT_SIGNATURE *sig, __u8 *out,
@@ -612,8 +612,8 @@ static int endorsement_primary(struct shirudo_tpm *t,
sizeof(key->public), &key->public_len);
Esys_Free(out_pub);
if (!err)
- err = shirudo_tpm_object_name(key->public, key->public_len,
- computed);
+ err = tpm_object_name(key->public, key->public_len,
+ computed);
if (!err) {
rc = Esys_TR_GetName(t->esys, handle, &name);
if (rc != TSS2_RC_SUCCESS || name->size != sizeof(computed) ||
@@ -628,11 +628,11 @@ static int endorsement_primary(struct shirudo_tpm *t,
Esys_Free(name);
}
if (err)
- shirudo_tpm_key_flush(t, key);
+ tpm_key_flush(t, key);
return err;
}
-int shirudo_tpm_ak_create(struct shirudo_tpm *t, struct shirudo_tpm_key *ak)
+int tpm_ak_create(struct shirudo_tpm *t, struct shirudo_tpm_key *ak)
{
TPM2B_PUBLIC in_pub = {};
@@ -652,8 +652,8 @@ int shirudo_tpm_ak_create(struct shirudo_tpm *t, struct shirudo_tpm_key *ak)
return endorsement_primary(t, &in_pub, "attestation key", ak);
}
-int shirudo_tpm_ek_create(struct shirudo_tpm *t, bool rsa,
- struct shirudo_tpm_key *ek)
+int tpm_ek_create(struct shirudo_tpm *t, bool rsa,
+ struct shirudo_tpm_key *ek)
{
TPM2B_PUBLIC in_pub = {};
TPMT_PUBLIC *pub = &in_pub.publicArea;
@@ -688,7 +688,7 @@ int shirudo_tpm_ek_create(struct shirudo_tpm *t, bool rsa,
return endorsement_primary(t, &in_pub, "endorsement key", ek);
}
-void shirudo_tpm_key_flush(struct shirudo_tpm *t, struct shirudo_tpm_key *key)
+void tpm_key_flush(struct shirudo_tpm *t, struct shirudo_tpm_key *key)
{
if (key->handle != ESYS_TR_NONE && key->handle != 0)
Esys_FlushContext(t->esys, key->handle);
@@ -708,9 +708,9 @@ static int attestation_copy(const TPM2B_ATTEST *attest,
&out->signature_len);
}
-int shirudo_tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
- const __u8 *nonce, size_t nonce_len, __u32 pcr_mask,
- struct shirudo_tpm_attestation *out)
+int tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
+ const __u8 *nonce, size_t nonce_len, __u32 pcr_mask,
+ struct shirudo_tpm_attestation *out)
{
TPMT_SIG_SCHEME scheme = { .scheme = TPM2_ALG_NULL };
TPMT_SIGNATURE *sig = NULL;
@@ -737,10 +737,10 @@ int shirudo_tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
return err;
}
-int shirudo_tpm_nv_certify(struct shirudo_tpm *t,
- const struct shirudo_tpm_key *ak, __u32 index,
- const __u8 *nonce, size_t nonce_len,
- struct shirudo_tpm_attestation *out)
+int tpm_nv_certify(struct shirudo_tpm *t,
+ const struct shirudo_tpm_key *ak, __u32 index,
+ const __u8 *nonce, size_t nonce_len,
+ struct shirudo_tpm_attestation *out)
{
TPMT_SIG_SCHEME scheme = { .scheme = TPM2_ALG_NULL };
TPMT_SIGNATURE *sig = NULL;
@@ -772,12 +772,12 @@ int shirudo_tpm_nv_certify(struct shirudo_tpm *t,
return err;
}
-int shirudo_tpm_activate_credential(struct shirudo_tpm *t,
- const struct shirudo_tpm_key *ak,
- const struct shirudo_tpm_key *ek,
- const __u8 *blob, size_t blob_len,
- const __u8 *secret, size_t secret_len,
- __u8 *out, size_t cap, size_t *out_len)
+int tpm_activate_credential(struct shirudo_tpm *t,
+ const struct shirudo_tpm_key *ak,
+ const struct shirudo_tpm_key *ek,
+ const __u8 *blob, size_t blob_len,
+ const __u8 *secret, size_t secret_len,
+ __u8 *out, size_t cap, size_t *out_len)
{
TPM2B_ENCRYPTED_SECRET sec = {};
TPM2B_DIGEST *cert_info = NULL;
@@ -874,8 +874,8 @@ static int nv_read_all(struct shirudo_tpm *t, __u32 index, __u8 *out,
return 0;
}
-int shirudo_tpm_ek_certificate(struct shirudo_tpm *t, __u8 *out,
- size_t cap, size_t *len, bool *rsa)
+int tpm_ek_certificate(struct shirudo_tpm *t, __u8 *out,
+ size_t cap, size_t *len, bool *rsa)
{
int err;
diff --git a/util/tpm.h b/util/tpm.h
index c66a2fe4..08c08fd4 100644
--- a/util/tpm.h
+++ b/util/tpm.h
@@ -22,21 +22,21 @@
struct shirudo_tpm;
-int shirudo_tpm_open(struct shirudo_tpm **out);
-void shirudo_tpm_close(struct shirudo_tpm *t);
+int tpm_open(struct shirudo_tpm **out);
+void tpm_close(struct shirudo_tpm *t);
-int shirudo_tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,
- __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
-int shirudo_tpm_pcr_extend(struct shirudo_tpm *t, __u32 pcr,
- const __u8 digest[SHIRUDO_TPM_DIGEST_LEN]);
+int tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,
+ __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
+int tpm_pcr_extend(struct shirudo_tpm *t, __u32 pcr,
+ const __u8 digest[SHIRUDO_TPM_DIGEST_LEN]);
/*
* The TPM's reset count, a new value at every TPM reset: the identity
* of the period a clear-on-reset index lives through.
*/
-int shirudo_tpm_reset_count(struct shirudo_tpm *t, __u32 *out);
+int tpm_reset_count(struct shirudo_tpm *t, __u32 *out);
-struct shirudo_tpm_nv_info {
+struct tpm_nv_info {
bool defined;
bool written;
__u32 attrs;
@@ -56,25 +56,25 @@ struct shirudo_tpm_nv_info {
* only satisfies while the anchoring PCR still holds the value the
* policy was computed from, every later one the written branch.
*/
-int shirudo_tpm_nv_info(struct shirudo_tpm *t, __u32 index,
- struct shirudo_tpm_nv_info *info);
-int shirudo_tpm_nv_define(struct shirudo_tpm *t, __u32 index,
- const __u8 policy[SHIRUDO_TPM_DIGEST_LEN],
- const void *owner_auth, size_t owner_auth_len);
-int shirudo_tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
- const void *owner_auth, size_t owner_auth_len);
+int tpm_nv_info(struct shirudo_tpm *t, __u32 index,
+ struct tpm_nv_info *info);
+int tpm_nv_define(struct shirudo_tpm *t, __u32 index,
+ const __u8 policy[SHIRUDO_TPM_DIGEST_LEN],
+ const void *owner_auth, size_t owner_auth_len);
+int tpm_nv_undefine(struct shirudo_tpm *t, __u32 index,
+ const void *owner_auth, size_t owner_auth_len);
/* -ENOENT: not defined; -ENODATA: defined but not written this boot. */
-int shirudo_tpm_nv_read(struct shirudo_tpm *t, __u32 index,
- __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
-int shirudo_tpm_nv_extend_first(struct shirudo_tpm *t, __u32 index,
- __u32 pcr_mask,
- const __u8 branch_written[32],
- const __u8 branch_init[32],
- const __u8 event[32]);
-int shirudo_tpm_nv_extend(struct shirudo_tpm *t, __u32 index,
- const __u8 branch_written[32],
- const __u8 branch_init[32],
- const __u8 event[32]);
+int tpm_nv_read(struct shirudo_tpm *t, __u32 index,
+ __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
+int tpm_nv_extend_first(struct shirudo_tpm *t, __u32 index,
+ __u32 pcr_mask,
+ const __u8 branch_written[32],
+ const __u8 branch_init[32],
+ const __u8 event[32]);
+int tpm_nv_extend(struct shirudo_tpm *t, __u32 index,
+ const __u8 branch_written[32],
+ const __u8 branch_init[32],
+ const __u8 event[32]);
/*
* The attestation key: a restricted P-256 ECDSA primary under the
@@ -96,14 +96,14 @@ struct shirudo_tpm_attestation {
size_t signature_len;
};
-int shirudo_tpm_ak_create(struct shirudo_tpm *t, struct shirudo_tpm_key *ak);
+int tpm_ak_create(struct shirudo_tpm *t, struct shirudo_tpm_key *ak);
/*
* The endorsement key from the TCG default template of the given
* type, the key the TPM's endorsement certificate describes.
*/
-int shirudo_tpm_ek_create(struct shirudo_tpm *t, bool rsa,
- struct shirudo_tpm_key *ek);
+int tpm_ek_create(struct shirudo_tpm *t, bool rsa,
+ struct shirudo_tpm_key *ek);
/*
* TPM2_ActivateCredential: recover the credential an operator
@@ -111,26 +111,26 @@ int shirudo_tpm_ek_create(struct shirudo_tpm *t, bool rsa,
* -EKEYREJECTED when the TPM refuses it, as it does for a blob made
* for another key or another TPM.
*/
-int shirudo_tpm_activate_credential(struct shirudo_tpm *t,
- const struct shirudo_tpm_key *ak,
- const struct shirudo_tpm_key *ek,
- const __u8 *blob, size_t blob_len,
- const __u8 *secret, size_t secret_len,
- __u8 *out, size_t cap, size_t *out_len);
-void shirudo_tpm_key_flush(struct shirudo_tpm *t, struct shirudo_tpm_key *key);
-int shirudo_tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
- const __u8 *nonce, size_t nonce_len, __u32 pcr_mask,
- struct shirudo_tpm_attestation *out);
-int shirudo_tpm_nv_certify(struct shirudo_tpm *t,
- const struct shirudo_tpm_key *ak, __u32 index,
- const __u8 *nonce, size_t nonce_len,
- struct shirudo_tpm_attestation *out);
+int tpm_activate_credential(struct shirudo_tpm *t,
+ const struct shirudo_tpm_key *ak,
+ const struct shirudo_tpm_key *ek,
+ const __u8 *blob, size_t blob_len,
+ const __u8 *secret, size_t secret_len,
+ __u8 *out, size_t cap, size_t *out_len);
+void tpm_key_flush(struct shirudo_tpm *t, struct shirudo_tpm_key *key);
+int tpm_quote(struct shirudo_tpm *t, const struct shirudo_tpm_key *ak,
+ const __u8 *nonce, size_t nonce_len, __u32 pcr_mask,
+ struct shirudo_tpm_attestation *out);
+int tpm_nv_certify(struct shirudo_tpm *t,
+ const struct shirudo_tpm_key *ak, __u32 index,
+ const __u8 *nonce, size_t nonce_len,
+ struct shirudo_tpm_attestation *out);
/*
* The endorsement key certificate from its TCG NV index, the ECC one
* first; *rsa tells which key it describes. -ENOENT if none.
*/
-int shirudo_tpm_ek_certificate(struct shirudo_tpm *t, __u8 *out,
- size_t cap, size_t *len, bool *rsa);
+int tpm_ek_certificate(struct shirudo_tpm *t, __u8 *out,
+ size_t cap, size_t *len, bool *rsa);
#endif /* SHIRUDO_TPM_H */
diff --git a/util/tpm_wire.c b/util/tpm_wire.c
index 5ae9de02..27179909 100644
--- a/util/tpm_wire.c
+++ b/util/tpm_wire.c
@@ -96,22 +96,22 @@ static void policy_hash(const __u8 prev[32], __u32 cc,
__u8 cc_be[4];
tpm_put32(cc_be, cc);
- if (shirudo_sha256_init(&ctx) != 0) {
+ if (sha256_init(&ctx) != 0) {
memset(out, 0, 32);
return;
}
- if (shirudo_sha256_update(&ctx, prev, 32) != 0 ||
- shirudo_sha256_update(&ctx, cc_be, sizeof(cc_be)) != 0 ||
- (a_len && shirudo_sha256_update(&ctx, a, a_len) != 0) ||
- (b_len && shirudo_sha256_update(&ctx, b, b_len) != 0) ||
- shirudo_sha256_final(&ctx, out) != 0) {
+ if (sha256_update(&ctx, prev, 32) != 0 ||
+ sha256_update(&ctx, cc_be, sizeof(cc_be)) != 0 ||
+ (a_len && sha256_update(&ctx, a, a_len) != 0) ||
+ (b_len && sha256_update(&ctx, b, b_len) != 0) ||
+ sha256_final(&ctx, out) != 0) {
memset(out, 0, 32);
- shirudo_sha256_free(&ctx);
+ sha256_free(&ctx);
}
}
-void shirudo_tpm_policy_nv_written(const __u8 prev[32], bool written,
- __u8 out[32])
+void tpm_policy_nv_written(const __u8 prev[32], bool written,
+ __u8 out[32])
{
__u8 set = written ? 1 : 0;
@@ -130,8 +130,8 @@ shirudo_tpm_pcr_selection(__u32 pcr_mask,
out[9] = (__u8)(pcr_mask >> 16);
}
-void shirudo_tpm_policy_pcr(const __u8 prev[32], __u32 pcr_mask,
- const __u8 pcr_digest[32], __u8 out[32])
+void tpm_policy_pcr(const __u8 prev[32], __u32 pcr_mask,
+ const __u8 pcr_digest[32], __u8 out[32])
{
__u8 sel[SHIRUDO_TPM_PCR_SELECTION_LEN];
@@ -140,32 +140,32 @@ void shirudo_tpm_policy_pcr(const __u8 prev[32], __u32 pcr_mask,
out);
}
-void shirudo_tpm_policy_or(const __u8 a[32], const __u8 b[32],
- __u8 out[32])
+void tpm_policy_or(const __u8 a[32], const __u8 b[32],
+ __u8 out[32])
{
static const __u8 zero[32];
policy_hash(zero, TPM_CC_POLICY_OR, a, 32, b, 32, out);
}
-void shirudo_tpm_register_policy(__u32 pcr_mask,
- const __u8 *pcr_values, size_t n_values,
- __u8 branch_written[32],
- __u8 branch_init[32], __u8 policy[32])
+void tpm_register_policy(__u32 pcr_mask,
+ const __u8 *pcr_values, size_t n_values,
+ __u8 branch_written[32],
+ __u8 branch_init[32], __u8 policy[32])
{
static const __u8 zero[32];
__u8 pcr_digest[32], unwritten[32];
- shirudo_tpm_policy_nv_written(zero, true, branch_written);
- shirudo_tpm_policy_nv_written(zero, false, unwritten);
- shirudo_sha256_buffer(pcr_values, 32 * n_values, pcr_digest);
- shirudo_tpm_policy_pcr(unwritten, pcr_mask, pcr_digest, branch_init);
- shirudo_tpm_policy_or(branch_written, branch_init, policy);
+ tpm_policy_nv_written(zero, true, branch_written);
+ tpm_policy_nv_written(zero, false, unwritten);
+ sha256_buffer(pcr_values, 32 * n_values, pcr_digest);
+ tpm_policy_pcr(unwritten, pcr_mask, pcr_digest, branch_init);
+ tpm_policy_or(branch_written, branch_init, policy);
}
-void shirudo_tpm_nv_name(__u32 index, __u32 attrs,
- const __u8 policy[32], __u16 data_size,
- __u8 name[SHIRUDO_TPM_NAME_LEN])
+void tpm_nv_name(__u32 index, __u32 attrs,
+ const __u8 policy[32], __u16 data_size,
+ __u8 name[SHIRUDO_TPM_NAME_LEN])
{
__u8 pub[4 + 2 + 4 + 2 + 32 + 2];
@@ -176,11 +176,11 @@ void shirudo_tpm_nv_name(__u32 index, __u32 attrs,
memcpy(pub + 12, policy, 32);
tpm_put16(pub + 44, data_size);
tpm_put16(name, SHIRUDO_TPM_ALG_SHA256);
- shirudo_sha256_buffer(pub, sizeof(pub), name + 2);
+ sha256_buffer(pub, sizeof(pub), name + 2);
}
-int shirudo_tpm_object_name(const __u8 *public, size_t len,
- __u8 name[SHIRUDO_TPM_NAME_LEN])
+int tpm_object_name(const __u8 *public, size_t len,
+ __u8 name[SHIRUDO_TPM_NAME_LEN])
{
struct reader r = { public, len };
__u16 type, alg;
@@ -189,20 +189,20 @@ int shirudo_tpm_object_name(const __u8 *public, size_t len,
alg != SHIRUDO_TPM_ALG_SHA256)
return -EINVAL;
tpm_put16(name, SHIRUDO_TPM_ALG_SHA256);
- shirudo_sha256_buffer(public, len, name + 2);
+ sha256_buffer(public, len, name + 2);
return 0;
}
-void shirudo_tpm_qualified_name(__u32 hierarchy,
- const __u8 name[SHIRUDO_TPM_NAME_LEN],
- __u8 out[SHIRUDO_TPM_NAME_LEN])
+void tpm_qualified_name(__u32 hierarchy,
+ const __u8 name[SHIRUDO_TPM_NAME_LEN],
+ __u8 out[SHIRUDO_TPM_NAME_LEN])
{
__u8 buf[4 + SHIRUDO_TPM_NAME_LEN];
tpm_put32(buf, hierarchy);
memcpy(buf + 4, name, SHIRUDO_TPM_NAME_LEN);
tpm_put16(out, SHIRUDO_TPM_ALG_SHA256);
- shirudo_sha256_buffer(buf, sizeof(buf), out + 2);
+ sha256_buffer(buf, sizeof(buf), out + 2);
}
const __u8 shirudo_tpm_ek_policy[32] = {
@@ -211,8 +211,8 @@ const __u8 shirudo_tpm_ek_policy[32] = {
0x0b, 0x64, 0xf2, 0xa1, 0xda, 0x1b, 0x33, 0x14, 0x69, 0xaa,
};
-int shirudo_tpm_public_parse(const __u8 *buf, size_t len,
- struct shirudo_tpm_public *out)
+int tpm_public_parse(const __u8 *buf, size_t len,
+ struct shirudo_tpm_public *out)
{
struct reader r = { buf, len };
const __u8 *policy, *n;
@@ -263,8 +263,8 @@ int shirudo_tpm_public_parse(const __u8 *buf, size_t len,
return 0;
}
-int shirudo_tpm_public_marshal(const struct shirudo_tpm_public *pub,
- __u8 *out, size_t cap, size_t *len)
+int tpm_public_marshal(const struct shirudo_tpm_public *pub,
+ __u8 *out, size_t cap, size_t *len)
{
size_t need = 2 + 2 + 4 + 2 + pub->policy_len + 2 + 2, off = 0;
@@ -318,14 +318,14 @@ int shirudo_tpm_public_marshal(const struct shirudo_tpm_public *pub,
return 0;
}
-int shirudo_tpm_ecc_public_parse(const __u8 *buf, size_t len,
- struct shirudo_tpm_ecc_public *out)
+int tpm_ecc_public_parse(const __u8 *buf, size_t len,
+ struct shirudo_tpm_ecc_public *out)
{
struct shirudo_tpm_public pub;
int rc;
memset(out, 0, sizeof(*out));
- rc = shirudo_tpm_public_parse(buf, len, &pub);
+ rc = tpm_public_parse(buf, len, &pub);
if (rc)
return rc;
if (pub.type != SHIRUDO_TPM_ALG_ECC ||
@@ -341,10 +341,10 @@ int shirudo_tpm_ecc_public_parse(const __u8 *buf, size_t len,
return 0;
}
-int shirudo_tpm_kdfa(const __u8 *key, size_t key_len, const char *label,
- const __u8 *ctx_u, size_t u_len,
- const __u8 *ctx_v, size_t v_len,
- __u8 *out, size_t out_len)
+int tpm_kdfa(const __u8 *key, size_t key_len, const char *label,
+ const __u8 *ctx_u, size_t u_len,
+ const __u8 *ctx_v, size_t v_len,
+ __u8 *out, size_t out_len)
{
__u8 buf[4 + 64 + 1 + 2 * SHIRUDO_TPM_NAME_LEN + 4], block[32];
size_t label_len = strlen(label), done = 0, off, n;
@@ -367,7 +367,7 @@ int shirudo_tpm_kdfa(const __u8 *key, size_t key_len, const char *label,
off += v_len;
tpm_put32(buf + off, (__u32)(out_len * 8));
off += 4;
- if (shirudo_hmac_sha256(key, key_len, buf, off, block))
+ if (hmac_sha256(key, key_len, buf, off, block))
return -EIO;
n = out_len - done < 32 ? out_len - done : 32;
memcpy(out + done, block, n);
@@ -377,9 +377,9 @@ int shirudo_tpm_kdfa(const __u8 *key, size_t key_len, const char *label,
return 0;
}
-void shirudo_tpm_kdfe(const __u8 z[32], const char *label,
- const __u8 *party_u, size_t u_len,
- const __u8 *party_v, size_t v_len, __u8 out[32])
+void tpm_kdfe(const __u8 z[32], const char *label,
+ const __u8 *party_u, size_t u_len,
+ const __u8 *party_v, size_t v_len, __u8 out[32])
{
__u8 buf[4 + 32 + 64 + 1 + 2 * 64];
size_t label_len = strlen(label), off = 4;
@@ -400,33 +400,33 @@ void shirudo_tpm_kdfe(const __u8 z[32], const char *label,
if (v_len)
memcpy(buf + off, party_v, v_len);
off += v_len;
- shirudo_sha256_buffer(buf, off, out);
+ sha256_buffer(buf, off, out);
explicit_bzero(buf, sizeof(buf));
}
-int shirudo_tpm_credential_protect(const __u8 seed[32],
- const __u8 name[SHIRUDO_TPM_NAME_LEN],
- const __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
- __u8 out[SHIRUDO_TPM_ID_OBJECT_LEN])
+int tpm_credential_protect(const __u8 seed[32],
+ const __u8 name[SHIRUDO_TPM_NAME_LEN],
+ const __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
+ __u8 out[SHIRUDO_TPM_ID_OBJECT_LEN])
{
__u8 plain[2 + SHIRUDO_TPM_CREDENTIAL_LEN], enc[sizeof(plain)];
__u8 mac_in[sizeof(enc) + SHIRUDO_TPM_NAME_LEN], mac[32];
__u8 sym_key[16], hmac_key[32];
int rc = -EIO;
- if (shirudo_tpm_kdfa(seed, 32, "STORAGE", name, SHIRUDO_TPM_NAME_LEN,
- NULL, 0, sym_key, sizeof(sym_key)))
+ if (tpm_kdfa(seed, 32, "STORAGE", name, SHIRUDO_TPM_NAME_LEN,
+ NULL, 0, sym_key, sizeof(sym_key)))
goto out;
tpm_put16(plain, SHIRUDO_TPM_CREDENTIAL_LEN);
memcpy(plain + 2, credential, SHIRUDO_TPM_CREDENTIAL_LEN);
- if (shirudo_aes128_cfb_encrypt(sym_key, plain, sizeof(plain), enc) ||
- shirudo_tpm_kdfa(seed, 32, "INTEGRITY", NULL, 0, NULL, 0, hmac_key,
- sizeof(hmac_key)))
+ if (aes128_cfb_encrypt(sym_key, plain, sizeof(plain), enc) ||
+ tpm_kdfa(seed, 32, "INTEGRITY", NULL, 0, NULL, 0, hmac_key,
+ sizeof(hmac_key)))
goto out;
memcpy(mac_in, enc, sizeof(enc));
memcpy(mac_in + sizeof(enc), name, SHIRUDO_TPM_NAME_LEN);
- if (shirudo_hmac_sha256(hmac_key, sizeof(hmac_key), mac_in,
- sizeof(mac_in), mac))
+ if (hmac_sha256(hmac_key, sizeof(hmac_key), mac_in,
+ sizeof(mac_in), mac))
goto out;
tpm_put16(out, 32);
memcpy(out + 2, mac, 32);
@@ -439,8 +439,8 @@ out:
return rc;
}
-int shirudo_tpm_ecdsa_signature_parse(const __u8 *buf, size_t len,
- __u8 r_out[32], __u8 s_out[32])
+int tpm_ecdsa_signature_parse(const __u8 *buf, size_t len,
+ __u8 r_out[32], __u8 s_out[32])
{
struct reader r = { buf, len };
__u16 alg, hash;
@@ -465,8 +465,8 @@ static int get_name(struct reader *r, __u8 *name, size_t *name_len)
return 0;
}
-int shirudo_tpm_attest_parse(const __u8 *buf, size_t len,
- struct shirudo_tpm_attest *out)
+int tpm_attest_parse(const __u8 *buf, size_t len,
+ struct shirudo_tpm_attest *out)
{
struct reader r = { buf, len };
__u32 magic;
diff --git a/util/tpm_wire.h b/util/tpm_wire.h
index 0a581111..aa7c6c51 100644
--- a/util/tpm_wire.h
+++ b/util/tpm_wire.h
@@ -63,16 +63,16 @@ static inline size_t tpm_put2b(__u8 *p, const __u8 *data, size_t len)
#define SHIRUDO_TPM_REGISTER_ATTRS 0x0E060048u
#define SHIRUDO_TPM_NV_WRITTEN 0x20000000u
-void shirudo_tpm_policy_nv_written(const __u8 prev[SHIRUDO_TPM_DIGEST_LEN],
- bool written,
- __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
-void shirudo_tpm_policy_pcr(const __u8 prev[SHIRUDO_TPM_DIGEST_LEN],
- __u32 pcr_mask,
- const __u8 pcr_digest[SHIRUDO_TPM_DIGEST_LEN],
- __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
-void shirudo_tpm_policy_or(const __u8 a[SHIRUDO_TPM_DIGEST_LEN],
- const __u8 b[SHIRUDO_TPM_DIGEST_LEN],
+void tpm_policy_nv_written(const __u8 prev[SHIRUDO_TPM_DIGEST_LEN],
+ bool written,
__u8 out[SHIRUDO_TPM_DIGEST_LEN]);
+void tpm_policy_pcr(const __u8 prev[SHIRUDO_TPM_DIGEST_LEN],
+ __u32 pcr_mask,
+ const __u8 pcr_digest[SHIRUDO_TPM_DIGEST_LEN],
+ __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
+void tpm_policy_or(const __u8 a[SHIRUDO_TPM_DIGEST_LEN],
+ const __u8 b[SHIRUDO_TPM_DIGEST_LEN],
+ __u8 out[SHIRUDO_TPM_DIGEST_LEN]);
/*
* The register's write policy from the values the binding PCRs held
@@ -80,29 +80,29 @@ void shirudo_tpm_policy_or(const __u8 a[SHIRUDO_TPM_DIGEST_LEN],
* PolicyNvWritten(NO) + PolicyPCR(mask, SHA-256(values))). The two
* branch digests are what a session has to present to PolicyOR.
*/
-void shirudo_tpm_register_policy(__u32 pcr_mask,
- const __u8 *pcr_values, size_t n_values,
- __u8 branch_written[32],
- __u8 branch_init[32],
- __u8 policy[32]);
+void tpm_register_policy(__u32 pcr_mask,
+ const __u8 *pcr_values, size_t n_values,
+ __u8 branch_written[32],
+ __u8 branch_init[32],
+ __u8 policy[32]);
/* Name of an NV index: nameAlg || SHA-256(TPMS_NV_PUBLIC). */
-void shirudo_tpm_nv_name(__u32 index, __u32 attrs,
- const __u8 policy[SHIRUDO_TPM_DIGEST_LEN],
- __u16 data_size,
- __u8 name[SHIRUDO_TPM_NAME_LEN]);
+void tpm_nv_name(__u32 index, __u32 attrs,
+ const __u8 policy[SHIRUDO_TPM_DIGEST_LEN],
+ __u16 data_size,
+ __u8 name[SHIRUDO_TPM_NAME_LEN]);
-int shirudo_tpm_object_name(const __u8 *public, size_t len,
- __u8 name[SHIRUDO_TPM_NAME_LEN]);
+int tpm_object_name(const __u8 *public, size_t len,
+ __u8 name[SHIRUDO_TPM_NAME_LEN]);
/*
* Qualified name of a primary object: nameAlg || SHA-256(hierarchy
* handle || name). Attestations carry the signer's qualified name.
*/
#define SHIRUDO_TPM_RH_ENDORSEMENT 0x4000000Bu
-void shirudo_tpm_qualified_name(__u32 hierarchy,
- const __u8 name[SHIRUDO_TPM_NAME_LEN],
- __u8 out[SHIRUDO_TPM_NAME_LEN]);
+void tpm_qualified_name(__u32 hierarchy,
+ const __u8 name[SHIRUDO_TPM_NAME_LEN],
+ __u8 out[SHIRUDO_TPM_NAME_LEN]);
/*
* The TCG default endorsement key templates: a restricted decryption
@@ -137,10 +137,10 @@ struct shirudo_tpm_public {
__u8 n[256];
};
-int shirudo_tpm_public_parse(const __u8 *buf, size_t len,
- struct shirudo_tpm_public *out);
-int shirudo_tpm_public_marshal(const struct shirudo_tpm_public *pub,
- __u8 *out, size_t cap, size_t *len);
+int tpm_public_parse(const __u8 *buf, size_t len,
+ struct shirudo_tpm_public *out);
+int tpm_public_marshal(const struct shirudo_tpm_public *pub,
+ __u8 *out, size_t cap, size_t *len);
struct shirudo_tpm_ecc_public {
__u32 attrs;
@@ -151,21 +151,21 @@ struct shirudo_tpm_ecc_public {
__u8 y[32];
};
-int shirudo_tpm_ecc_public_parse(const __u8 *buf, size_t len,
- struct shirudo_tpm_ecc_public *out);
+int tpm_ecc_public_parse(const __u8 *buf, size_t len,
+ struct shirudo_tpm_ecc_public *out);
/*
* The key derivations of TPM 2.0 Part 1 with SHA-256: KDFa (SP800-108
* in counter mode) and KDFe (SP800-56A one-step). Labels are given
* without their terminating NUL, which the derivation adds.
*/
-int shirudo_tpm_kdfa(const __u8 *key, size_t key_len, const char *label,
- const __u8 *ctx_u, size_t u_len,
- const __u8 *ctx_v, size_t v_len,
- __u8 *out, size_t out_len);
-void shirudo_tpm_kdfe(const __u8 z[32], const char *label,
- const __u8 *party_u, size_t u_len,
- const __u8 *party_v, size_t v_len, __u8 out[32]);
+int tpm_kdfa(const __u8 *key, size_t key_len, const char *label,
+ const __u8 *ctx_u, size_t u_len,
+ const __u8 *ctx_v, size_t v_len,
+ __u8 *out, size_t out_len);
+void tpm_kdfe(const __u8 z[32], const char *label,
+ const __u8 *party_u, size_t u_len,
+ const __u8 *party_v, size_t v_len, __u8 out[32]);
/*
* Credential protection (Part 1, 24.4): from a seed shared with the
@@ -176,13 +176,13 @@ void shirudo_tpm_kdfe(const __u8 z[32], const char *label,
*/
#define SHIRUDO_TPM_CREDENTIAL_LEN 32
#define SHIRUDO_TPM_ID_OBJECT_LEN (2 + 32 + 2 + SHIRUDO_TPM_CREDENTIAL_LEN)
-int shirudo_tpm_credential_protect(const __u8 seed[32],
- const __u8 name[SHIRUDO_TPM_NAME_LEN],
- const __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
- __u8 out[SHIRUDO_TPM_ID_OBJECT_LEN]);
+int tpm_credential_protect(const __u8 seed[32],
+ const __u8 name[SHIRUDO_TPM_NAME_LEN],
+ const __u8 credential[SHIRUDO_TPM_CREDENTIAL_LEN],
+ __u8 out[SHIRUDO_TPM_ID_OBJECT_LEN]);
-int shirudo_tpm_ecdsa_signature_parse(const __u8 *buf, size_t len,
- __u8 r[32], __u8 s[32]);
+int tpm_ecdsa_signature_parse(const __u8 *buf, size_t len,
+ __u8 r[32], __u8 s[32]);
struct shirudo_tpm_attest {
__u16 type;
@@ -211,7 +211,7 @@ struct shirudo_tpm_attest {
* single SHA-256 PCR bank is accepted in a quote. Pointers into the
* input stay valid as long as buf does.
*/
-int shirudo_tpm_attest_parse(const __u8 *buf, size_t len,
- struct shirudo_tpm_attest *out);
+int tpm_attest_parse(const __u8 *buf, size_t len,
+ struct shirudo_tpm_attest *out);
#endif /* SHIRUDO_TPM_WIRE_H */
diff --git a/util/upatch.c b/util/upatch.c
index ac68a68c..1de98826 100644
--- a/util/upatch.c
+++ b/util/upatch.c
@@ -193,7 +193,7 @@ static void parse_decoders(struct shirudo_upatch *u)
u->nr_decoders = nr_decoders;
}
-int shirudo_upatch_open(const char *path, struct shirudo_upatch *out)
+int upatch_open(const char *path, struct shirudo_upatch *out)
{
struct stat st;
void *m;
@@ -230,19 +230,19 @@ int shirudo_upatch_open(const char *path, struct shirudo_upatch *out)
rc = parse_header(out->map, out->map_size, &out->hdr);
if (rc != 0) {
- shirudo_upatch_close(out);
+ upatch_close(out);
return rc;
}
rc = validate_bounds(&out->hdr, out->map_size);
if (rc != 0) {
- shirudo_upatch_close(out);
+ upatch_close(out);
return rc;
}
parse_decoders(out);
return 0;
}
-void shirudo_upatch_close(struct shirudo_upatch *u)
+void upatch_close(struct shirudo_upatch *u)
{
if (u->map) {
munmap((void *)u->map, u->map_size);
@@ -254,51 +254,51 @@ void shirudo_upatch_close(struct shirudo_upatch *u)
}
}
-const void *shirudo_upatch_loader(const struct shirudo_upatch *u)
+const void *upatch_loader(const struct shirudo_upatch *u)
{
if (!u->map)
return NULL;
return u->map + u->hdr.loader_insns_off;
}
-const void *shirudo_upatch_signature(const struct shirudo_upatch *u)
+const void *upatch_signature(const struct shirudo_upatch *u)
{
if (!u->map)
return NULL;
return u->map + u->hdr.signature_off;
}
-const void *shirudo_upatch_metadata(const struct shirudo_upatch *u)
+const void *upatch_metadata(const struct shirudo_upatch *u)
{
if (!u->map || u->hdr.metadata_len == 0)
return NULL;
return u->map + u->hdr.metadata_off;
}
-const void *shirudo_upatch_data(const struct shirudo_upatch *u)
+const void *upatch_data(const struct shirudo_upatch *u)
{
if (!u->map || u->hdr.data_len == 0)
return NULL;
return u->map + u->hdr.data_off;
}
-bool shirudo_upatch_is_unload(const struct shirudo_upatch *u)
+bool upatch_is_unload(const struct shirudo_upatch *u)
{
return (u->hdr.flags & SHIRUDO_DIRECTIVE_UNLOAD) != 0;
}
-const char *shirudo_upatch_type_str(const struct shirudo_upatch *u)
+const char *upatch_type_str(const struct shirudo_upatch *u)
{
return "bpf";
}
-bool shirudo_upatch_has_decoders(const struct shirudo_upatch *u)
+bool upatch_has_decoders(const struct shirudo_upatch *u)
{
return u->map && u->decoder_blob && u->nr_decoders > 0;
}
-int shirudo_upatch_decoder_view(const struct shirudo_upatch *u, __u32 idx,
- struct shirudo_upatch_decoder_view *out)
+int upatch_decoder_view(const struct shirudo_upatch *u, __u32 idx,
+ struct upatch_decoder_view *out)
{
struct shirudo_upatch_decoder_entry d;
const __u8 *bp;
@@ -306,7 +306,7 @@ int shirudo_upatch_decoder_view(const struct shirudo_upatch *u, __u32 idx,
if (!out)
return -EINVAL;
memset(out, 0, sizeof(*out));
- if (!shirudo_upatch_has_decoders(u) || idx >= u->nr_decoders)
+ if (!upatch_has_decoders(u) || idx >= u->nr_decoders)
return -ENOENT;
bp = (const __u8 *)u->decoder_blob;
@@ -325,7 +325,7 @@ int shirudo_upatch_decoder_view(const struct shirudo_upatch *u, __u32 idx,
return 0;
}
-bool shirudo_upatch_name_valid(const char *name)
+bool upatch_name_valid(const char *name)
{
size_t i;
@@ -342,14 +342,14 @@ bool shirudo_upatch_name_valid(const char *name)
return true;
}
-int shirudo_upatch_select(const struct dirent *e)
+int upatch_select(const struct dirent *e)
{
size_t n = strlen(e->d_name);
return n > 7 && strcmp(e->d_name + n - 7, ".upatch") == 0;
}
-void shirudo_prog_specs_free(struct shirudo_prog_spec *specs, __u32 nr_progs)
+void prog_specs_free(struct shirudo_prog_spec *specs, __u32 nr_progs)
{
__u32 i;
@@ -366,8 +366,8 @@ void shirudo_prog_specs_free(struct shirudo_prog_spec *specs, __u32 nr_progs)
xfree(specs, (size_t)nr_progs * sizeof(*specs));
}
-int shirudo_prog_specs_parse(const void *metadata, __u32 metadata_len,
- __u32 nr_progs, struct shirudo_prog_spec **out)
+int prog_specs_parse(const void *metadata, __u32 metadata_len,
+ __u32 nr_progs, struct shirudo_prog_spec **out)
{
struct shirudo_upatch_prog_metadata md;
struct shirudo_prog_spec *specs = NULL;
@@ -578,6 +578,6 @@ int shirudo_prog_specs_parse(const void *metadata, __u32 metadata_len,
*out = specs;
return 0;
out:
- shirudo_prog_specs_free(specs, nr_progs);
+ prog_specs_free(specs, nr_progs);
return rc;
}
diff --git a/util/upatch.h b/util/upatch.h
index f917bacb..eb05f9db 100644
--- a/util/upatch.h
+++ b/util/upatch.h
@@ -27,7 +27,7 @@ struct shirudo_upatch {
__u32 nr_decoders;
};
-struct shirudo_upatch_decoder_view {
+struct upatch_decoder_view {
__u32 language;
__u32 api_version;
__u32 input_format;
@@ -44,34 +44,34 @@ struct shirudo_upatch_decoder_view {
* Returns 0 on success, -errno on failure. Logs nothing -- caller
* decides whether to emit user-facing diagnostics.
*/
-int shirudo_upatch_open(const char *path, struct shirudo_upatch *out);
-void shirudo_upatch_close(struct shirudo_upatch *u);
+int upatch_open(const char *path, struct shirudo_upatch *out);
+void upatch_close(struct shirudo_upatch *u);
/*
* Section accessors. Pointers reference the mmap; valid only until
- * shirudo_upatch_close().
+ * upatch_close().
*/
-const void *shirudo_upatch_loader(const struct shirudo_upatch *u);
-const void *shirudo_upatch_signature(const struct shirudo_upatch *u);
-const void *shirudo_upatch_metadata(const struct shirudo_upatch *u);
-const void *shirudo_upatch_data(const struct shirudo_upatch *u);
+const void *upatch_loader(const struct shirudo_upatch *u);
+const void *upatch_signature(const struct shirudo_upatch *u);
+const void *upatch_metadata(const struct shirudo_upatch *u);
+const void *upatch_data(const struct shirudo_upatch *u);
-bool shirudo_upatch_is_unload(const struct shirudo_upatch *u);
-const char *shirudo_upatch_type_str(const struct shirudo_upatch *u);
+bool upatch_is_unload(const struct shirudo_upatch *u);
+const char *upatch_type_str(const struct shirudo_upatch *u);
-bool shirudo_upatch_has_decoders(const struct shirudo_upatch *u);
-int shirudo_upatch_decoder_view(const struct shirudo_upatch *u, __u32 idx,
- struct shirudo_upatch_decoder_view *out);
+bool upatch_has_decoders(const struct shirudo_upatch *u);
+int upatch_decoder_view(const struct shirudo_upatch *u, __u32 idx,
+ struct upatch_decoder_view *out);
/*
* Validate an externally-provided upatch name: non-empty, doesn't
* start with '.', and matches [A-Za-z0-9._-]+. Rejects anything that
* could escape the bpffs / on-disk path namespace.
*/
-bool shirudo_upatch_name_valid(const char *name);
+bool upatch_name_valid(const char *name);
/* A scandir() filter for the archived .upatch files. */
-int shirudo_upatch_select(const struct dirent *e);
+int upatch_select(const struct dirent *e);
struct shirudo_prog_spec {
__u32 role;
@@ -92,10 +92,10 @@ struct shirudo_prog_spec {
/*
* The program metadata of a load upatch, which the loader signature does
* not cover: parsed strictly into one spec per program, target_fd -1.
- * 0 or -errno; free with shirudo_prog_specs_free().
+ * 0 or -errno; free with prog_specs_free().
*/
-int shirudo_prog_specs_parse(const void *metadata, __u32 metadata_len,
- __u32 nr_progs, struct shirudo_prog_spec **out);
-void shirudo_prog_specs_free(struct shirudo_prog_spec *specs, __u32 nr_progs);
+int prog_specs_parse(const void *metadata, __u32 metadata_len,
+ __u32 nr_progs, struct shirudo_prog_spec **out);
+void prog_specs_free(struct shirudo_prog_spec *specs, __u32 nr_progs);
#endif /* SHIRUDO_UTIL_UPATCH_H */
diff --git a/util/upatch_decode.c b/util/upatch_decode.c
index 93809f15..17fdc3a9 100644
--- a/util/upatch_decode.c
+++ b/util/upatch_decode.c
@@ -14,8 +14,8 @@
#ifndef SHIRUDO_HAVE_LUAJIT
-int shirudo_upatch_decode_map_json(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_json(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
if (!v || !out || !out_len)
return -EINVAL;
@@ -24,44 +24,44 @@ int shirudo_upatch_decode_map_json(const struct shirudo_map_view *v,
return -EOPNOTSUPP;
}
-int shirudo_upatch_decode_map_json_limit(const struct shirudo_map_view *v,
- size_t max_bytes,
- char **out, size_t *out_len)
+int upatch_decode_map_json_limit(const struct shirudo_map_view *v,
+ size_t max_bytes,
+ char **out, size_t *out_len)
{
(void)max_bytes;
- return shirudo_upatch_decode_map_json(v, out, out_len);
+ return upatch_decode_map_json(v, out, out_len);
}
-int shirudo_upatch_decode_map_otel(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_otel(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
- return shirudo_upatch_decode_map_json(v, out, out_len);
+ return upatch_decode_map_json(v, out, out_len);
}
-int shirudo_upatch_decode_map_file_json(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_file_json(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
(void)path;
- return shirudo_upatch_decode_map_json(v, out, out_len);
+ return upatch_decode_map_json(v, out, out_len);
}
-int shirudo_upatch_decode_map_file_json_limit(const char *path,
- const struct shirudo_map_view *v,
- size_t max_bytes, char **out,
- size_t *out_len)
+int upatch_decode_map_file_json_limit(const char *path,
+ const struct shirudo_map_view *v,
+ size_t max_bytes, char **out,
+ size_t *out_len)
{
(void)path;
(void)max_bytes;
- return shirudo_upatch_decode_map_json(v, out, out_len);
+ return upatch_decode_map_json(v, out, out_len);
}
-int shirudo_upatch_decode_map_file_otel(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_file_otel(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
(void)path;
- return shirudo_upatch_decode_map_json(v, out, out_len);
+ return upatch_decode_map_json(v, out, out_len);
}
#else /* SHIRUDO_HAVE_LUAJIT */
@@ -581,14 +581,14 @@ static int hex_decode_push(lua_State *L, const char *hex, size_t len,
i++;
if (i >= len)
break;
- hi = shirudo_hex_nibble((__u8)hex[i++]);
+ hi = hex_nibble((__u8)hex[i++]);
while (i < len && isspace((__u8)hex[i]))
i++;
if (i >= len) {
lua_pop(L, 1);
return -EINVAL;
}
- lo = shirudo_hex_nibble((__u8)hex[i++]);
+ lo = hex_nibble((__u8)hex[i++]);
if (hi < 0 || lo < 0) {
lua_pop(L, 1);
return -EINVAL;
@@ -876,8 +876,8 @@ static int lua_shirudo_hex_u64(lua_State *L)
}
for (i = 7; i >= 0; i--) {
const char *p = hex + (size_t)off * 2 + (size_t)i * 2;
- int hi = shirudo_hex_nibble(p[0]);
- int lo = shirudo_hex_nibble(p[1]);
+ int hi = hex_nibble(p[0]);
+ int lo = hex_nibble(p[1]);
if (hi < 0 || lo < 0) {
lua_push_u64_string(L, 0);
@@ -1072,8 +1072,8 @@ static void lua_push_map_input(lua_State *L, const struct shirudo_map_view *v)
for (i = 0; i < v->n_entries; i++) {
const struct shirudo_map_entry *entry = &v->entries[i];
size_t value_bytes = (size_t)v->value_stride * v->n_cpus;
- char *key_hex = shirudo_hex_alloc(entry->key, v->key_size);
- char *value_hex = shirudo_hex_alloc(entry->value, value_bytes);
+ char *key_hex = hex_alloc(entry->key, v->key_size);
+ char *value_hex = hex_alloc(entry->value, value_bytes);
if (!key_hex || !value_hex) {
xfree(key_hex, (size_t)v->key_size * 2 + 1);
@@ -1094,7 +1094,7 @@ static void lua_push_map_input(lua_State *L, const struct shirudo_map_view *v)
lua_newtable(L);
for (p = 0; p < v->n_serial_pages; p++) {
const struct shirudo_serial_page *page = &v->serial_pages[p];
- char *hex = shirudo_hex_alloc(page->data, page->bytes);
+ char *hex = hex_alloc(page->data, page->bytes);
if (!hex)
luaL_error(L, "decoder page data is too large");
@@ -1162,7 +1162,7 @@ static const char *lua_error_message(lua_State *L)
return message ? message : "unknown Lua error";
}
-static int run_lua_decoder(const struct shirudo_upatch_decoder_view *d,
+static int run_lua_decoder(const struct upatch_decoder_view *d,
const struct shirudo_map_view *v,
bool otel, size_t max_bytes,
char **out, size_t *out_len)
@@ -1243,7 +1243,7 @@ out_close:
return rc;
}
-static int decoder_matches(const struct shirudo_upatch_decoder_view *d,
+static int decoder_matches(const struct upatch_decoder_view *d,
const struct shirudo_map_view *v)
{
if (d->language != SHIRUDO_UPATCH_DECODER_LANG_LUA ||
@@ -1271,54 +1271,54 @@ static int decode_map_file(const char *path, const struct shirudo_map_view *v,
return -EINVAL;
*out = NULL;
*out_len = 0;
- if (!shirudo_upatch_name_valid(v->upatch))
+ if (!upatch_name_valid(v->upatch))
return -EINVAL;
- rc = shirudo_upatch_open(path, &u);
+ rc = upatch_open(path, &u);
if (rc)
return rc == -ENOENT ? -ENOENT : rc;
rc = -ENOENT;
for (i = 0; i < u.nr_decoders; i++) {
- struct shirudo_upatch_decoder_view d;
+ struct upatch_decoder_view d;
- if (shirudo_upatch_decoder_view(&u, i, &d))
+ if (upatch_decoder_view(&u, i, &d))
continue;
if (!decoder_matches(&d, v))
continue;
rc = run_lua_decoder(&d, v, otel, max_bytes, out, out_len);
break;
}
- shirudo_upatch_close(&u);
+ upatch_close(&u);
return rc;
}
-int shirudo_upatch_decode_map_signal(const struct shirudo_map_view *v,
- __u32 *signal_out)
+int upatch_decode_map_signal(const struct shirudo_map_view *v,
+ __u32 *signal_out)
{
struct shirudo_upatch u;
char path[PATH_MAX];
__u32 i;
int rc;
- if (!v || !signal_out || !shirudo_upatch_name_valid(v->upatch))
+ if (!v || !signal_out || !upatch_name_valid(v->upatch))
return -EINVAL;
if (snprintf(path, sizeof(path), "%s/%s.upatch", SHIRUDO_UPATCHES_DIR,
v->upatch) >= (int)sizeof(path))
return -ENAMETOOLONG;
- rc = shirudo_upatch_open(path, &u);
+ rc = upatch_open(path, &u);
if (rc)
return rc == -ENOENT ? -ENOENT : rc;
rc = -ENOENT;
for (i = 0; i < u.nr_decoders; i++) {
- struct shirudo_upatch_decoder_view d;
+ struct upatch_decoder_view d;
- if (shirudo_upatch_decoder_view(&u, i, &d) ||
+ if (upatch_decoder_view(&u, i, &d) ||
!decoder_matches(&d, v))
continue;
*signal_out = d.export_signal;
rc = 0;
break;
}
- shirudo_upatch_close(&u);
+ upatch_close(&u);
return rc;
}
@@ -1335,51 +1335,51 @@ static int decode_map(const struct shirudo_map_view *v, bool otel,
return decode_map_file(path, v, otel, max_bytes, out, out_len);
}
-int shirudo_upatch_decode_map_json(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_json(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
- return shirudo_upatch_decode_map_json_limit(v,
- SHIRUDO_JSON_MAX_BYTES,
- out, out_len);
+ return upatch_decode_map_json_limit(v,
+ SHIRUDO_JSON_MAX_BYTES,
+ out, out_len);
}
-int shirudo_upatch_decode_map_json_limit(const struct shirudo_map_view *v,
- size_t max_bytes,
- char **out, size_t *out_len)
+int upatch_decode_map_json_limit(const struct shirudo_map_view *v,
+ size_t max_bytes,
+ char **out, size_t *out_len)
{
if (!max_bytes)
return -EINVAL;
return decode_map(v, false, max_bytes, out, out_len);
}
-int shirudo_upatch_decode_map_otel(const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_otel(const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return decode_map(v, true, SHIRUDO_JSON_MAX_BYTES, out, out_len);
}
-int shirudo_upatch_decode_map_file_json(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_file_json(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
- return shirudo_upatch_decode_map_file_json_limit(path, v,
- SHIRUDO_JSON_MAX_BYTES,
- out, out_len);
+ return upatch_decode_map_file_json_limit(path, v,
+ SHIRUDO_JSON_MAX_BYTES,
+ out, out_len);
}
-int shirudo_upatch_decode_map_file_json_limit(const char *path,
- const struct shirudo_map_view *v,
- size_t max_bytes, char **out,
- size_t *out_len)
+int upatch_decode_map_file_json_limit(const char *path,
+ const struct shirudo_map_view *v,
+ size_t max_bytes, char **out,
+ size_t *out_len)
{
if (!max_bytes)
return -EINVAL;
return decode_map_file(path, v, false, max_bytes, out, out_len);
}
-int shirudo_upatch_decode_map_file_otel(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_decode_map_file_otel(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
return decode_map_file(path, v, true, SHIRUDO_JSON_MAX_BYTES,
out, out_len);
diff --git a/util/upatch_decode.h b/util/upatch_decode.h
index cccfb4f9..7aeb4ea7 100644
--- a/util/upatch_decode.h
+++ b/util/upatch_decode.h
@@ -19,30 +19,30 @@ struct shirudo_map_view;
* xmalloc'd; -ENOENT without a usable decoder, which an export treats
* as failing the map.
*/
-int shirudo_upatch_decode_map_json(const struct shirudo_map_view *v,
- char **out, size_t *out_len);
+int upatch_decode_map_json(const struct shirudo_map_view *v,
+ char **out, size_t *out_len);
/* Variant for consumers such as S3 archival with a larger output budget. */
-int shirudo_upatch_decode_map_json_limit(const struct shirudo_map_view *v,
- size_t max_bytes,
- char **out, size_t *out_len);
+int upatch_decode_map_json_limit(const struct shirudo_map_view *v,
+ size_t max_bytes,
+ char **out, size_t *out_len);
-int shirudo_upatch_decode_map_otel(const struct shirudo_map_view *v,
- char **out, size_t *out_len);
+int upatch_decode_map_otel(const struct shirudo_map_view *v,
+ char **out, size_t *out_len);
/* Explicit-artifact variants used by offline consumers and tests. */
-int shirudo_upatch_decode_map_file_json(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len);
-int shirudo_upatch_decode_map_file_json_limit(const char *path,
- const struct shirudo_map_view *v,
- size_t max_bytes, char **out,
- size_t *out_len);
-int shirudo_upatch_decode_map_file_otel(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len);
-
-int shirudo_upatch_decode_map_signal(const struct shirudo_map_view *v,
- __u32 *signal_out);
+int upatch_decode_map_file_json(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len);
+int upatch_decode_map_file_json_limit(const char *path,
+ const struct shirudo_map_view *v,
+ size_t max_bytes, char **out,
+ size_t *out_len);
+int upatch_decode_map_file_otel(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len);
+
+int upatch_decode_map_signal(const struct shirudo_map_view *v,
+ __u32 *signal_out);
#endif /* SHIRUDO_UTIL_UPATCH_DECODE_H */
diff --git a/util/upatch_map_types.h b/util/upatch_map_types.h
index 581b61ee..244dc0f6 100644
--- a/util/upatch_map_types.h
+++ b/util/upatch_map_types.h
@@ -13,7 +13,7 @@
#include <shirudo/misc.h>
-static inline const char *shirudo_map_type_name(__u32 type)
+static inline const char *map_type_name(__u32 type)
{
switch (type) {
case BPF_MAP_TYPE_ARRAY:
@@ -43,7 +43,7 @@ static inline const char *shirudo_map_type_name(__u32 type)
}
}
-static inline const char *shirudo_map_skip_reason(__u32 type)
+static inline const char *map_skip_reason(__u32 type)
{
switch (type) {
case BPF_MAP_TYPE_RINGBUF:
diff --git a/util/upatch_maps.c b/util/upatch_maps.c
index 6fc669a6..f6016a84 100644
--- a/util/upatch_maps.c
+++ b/util/upatch_maps.c
@@ -52,8 +52,8 @@ static void resolve_map_location(struct shirudo_map_view *v)
vbtf = btf__load_vmlinux_btf();
if (libbpf_get_error(vbtf))
vbtf = NULL;
- (void)shirudo_upatch_resolve_location(vbtf, v->upatch,
- v->location, sizeof(v->location));
+ (void)upatch_resolve_location(vbtf, v->upatch,
+ v->location, sizeof(v->location));
if (vbtf)
btf__free(vbtf);
}
@@ -63,7 +63,7 @@ static void resolve_map_location(struct shirudo_map_view *v)
#define SHIRUDO_SERIAL_MAX_TOTAL_BYTES \
((__u64)SHIRUDO_SERIAL_MAX_PAGES * SHIRUDO_SERIAL_MAX_BYTES)
-bool shirudo_upatch_map_is_percpu(__u32 type)
+bool upatch_map_is_percpu(__u32 type)
{
return type == BPF_MAP_TYPE_PERCPU_ARRAY ||
type == BPF_MAP_TYPE_PERCPU_HASH ||
@@ -72,12 +72,12 @@ bool shirudo_upatch_map_is_percpu(__u32 type)
static __u32 map_value_stride(__u32 type, __u32 value_size)
{
- if (!shirudo_upatch_map_is_percpu(type))
+ if (!upatch_map_is_percpu(type))
return value_size;
return (value_size + 7U) & ~7U;
}
-__u32 shirudo_upatch_map_value_stride(const struct shirudo_map_view *v)
+__u32 upatch_map_value_stride(const struct shirudo_map_view *v)
{
return v->value_stride ? v->value_stride : v->value_size;
}
@@ -684,9 +684,9 @@ static char *format_value(const void *value, __u32 value_size,
}
}
-char *shirudo_upatch_map_format_percpu_sum(const struct shirudo_map_view *v,
- const void *values_per_cpu,
- const char *btf_type)
+char *upatch_map_format_percpu_sum(const struct shirudo_map_view *v,
+ const void *values_per_cpu,
+ const char *btf_type)
{
if (v->value_size == 1 || v->value_size == 2 ||
v->value_size == 4 || v->value_size == 8) {
@@ -709,7 +709,7 @@ char *shirudo_upatch_map_format_percpu_sum(const struct shirudo_map_view *v,
__u64 one = 0;
memcpy(&one, (const char *)values_per_cpu +
- (size_t)i * shirudo_upatch_map_value_stride(v),
+ (size_t)i * upatch_map_value_stride(v),
v->value_size);
/* A negative per-CPU count must not add as 2^n - 1. */
if (is_signed && bits < 64 &&
@@ -732,7 +732,7 @@ static int open_map_pin(const char *upatch, const char *map_name,
__u32 info_len = sizeof(*info_out);
int fd;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
return -ENAMETOOLONG;
if ((size_t)snprintf(path, sizeof(path), "%s/%s/maps/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name, map_name)
@@ -765,7 +765,7 @@ static int open_serializer_pin(const char *upatch, const char *map_name)
char bpffs_name[SHIRUDO_UPATCH_BPFFS_NAME_MAX + 1];
int fd;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
return -ENAMETOOLONG;
if ((size_t)snprintf(path, sizeof(path), "%s/%s/serializers/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name, map_name) >=
@@ -777,8 +777,8 @@ static int open_serializer_pin(const char *upatch, const char *map_name)
return fd;
}
-int shirudo_prog_test_run(int prog_fd, void *ctx, __u32 ctx_sz,
- __u32 *retval)
+int prog_test_run(int prog_fd, void *ctx, __u32 ctx_sz,
+ __u32 *retval)
{
union bpf_attr attr = {};
long ret;
@@ -902,9 +902,9 @@ static int read_serial_page(int serial_fd,
rc = -errno;
goto out_data;
}
- rc = shirudo_serial_chunk_validate(chunk, key, total_chunks,
- page_index, cursor,
- next_cursor, invocation_id);
+ rc = serial_chunk_validate(chunk, key, total_chunks,
+ page_index, cursor,
+ next_cursor, invocation_id);
if (rc)
goto out_data;
if (chunk->status != 0) {
@@ -973,13 +973,13 @@ static int try_read_serialized(const char *upatch, const char *map,
* the kernel map ID so every process sharing this exact output map
* contends, while unrelated upatches remain independent.
*/
- lock_fd = shirudo_serializer_lock_acquire(serial_info.id);
+ lock_fd = serializer_lock_acquire(serial_info.id);
if (lock_fd < 0) {
rc = lock_fd;
lock_fd = -1;
goto out;
}
- rc = shirudo_serializer_new_invocation_id(&invocation_id);
+ rc = serializer_new_invocation_id(&invocation_id);
if (rc)
goto out;
@@ -1003,7 +1003,7 @@ static int try_read_serialized(const char *upatch, const char *map,
ctx.cursor = cursor;
ctx.invocation_id = invocation_id;
- rc = shirudo_prog_test_run(prog_fd, &ctx, sizeof(ctx), &retval);
+ rc = prog_test_run(prog_fd, &ctx, sizeof(ctx), &retval);
if (rc)
goto out;
if ((__s32)retval < 0) {
@@ -1082,16 +1082,16 @@ out:
static int read_entries(int fd, struct shirudo_map_view *v,
__u32 cap)
{
- size_t value_count = shirudo_upatch_map_is_percpu(v->type) ?
+ size_t value_count = upatch_map_is_percpu(v->type) ?
v->n_cpus : 1;
size_t value_alloc;
__u32 i;
int err;
- if (shirudo_upatch_map_value_stride(v) != 0 &&
- value_count > SIZE_MAX / shirudo_upatch_map_value_stride(v))
+ if (upatch_map_value_stride(v) != 0 &&
+ value_count > SIZE_MAX / upatch_map_value_stride(v))
return -EOVERFLOW;
- value_alloc = (size_t)shirudo_upatch_map_value_stride(v) * value_count;
+ value_alloc = (size_t)upatch_map_value_stride(v) * value_count;
v->entries = NULL;
v->n_entries = 0;
@@ -1196,7 +1196,7 @@ static int read_entries(int fd, struct shirudo_map_view *v,
return -EOPNOTSUPP;
}
-void shirudo_map_view_free(struct shirudo_map_view *v)
+void map_view_free(struct shirudo_map_view *v)
{
size_t value_alloc;
__u32 i;
@@ -1204,8 +1204,8 @@ void shirudo_map_view_free(struct shirudo_map_view *v)
if (!v)
return;
if (v->entries) {
- value_alloc = (size_t)shirudo_upatch_map_value_stride(v) *
- (shirudo_upatch_map_is_percpu(v->type) ?
+ value_alloc = (size_t)upatch_map_value_stride(v) *
+ (upatch_map_is_percpu(v->type) ?
v->n_cpus : 1);
for (i = 0; i < v->n_entries; i++) {
xfree(v->entries[i].key, v->key_size);
@@ -1231,17 +1231,17 @@ void shirudo_map_view_free(struct shirudo_map_view *v)
}
}
-int shirudo_upatch_maps_read(const char *upatch, const char *map,
- __u32 max_entries_cap,
- struct shirudo_map_view *out)
+int upatch_maps_read(const char *upatch, const char *map,
+ __u32 max_entries_cap,
+ struct shirudo_map_view *out)
{
- return shirudo_upatch_maps_read_flags(upatch, map, max_entries_cap, 0,
- out);
+ return upatch_maps_read_flags(upatch, map, max_entries_cap, 0,
+ out);
}
-int shirudo_upatch_maps_read_flags(const char *upatch, const char *map,
- __u32 max_entries_cap, __u32 flags,
- struct shirudo_map_view *out)
+int upatch_maps_read_flags(const char *upatch, const char *map,
+ __u32 max_entries_cap, __u32 flags,
+ struct shirudo_map_view *out)
{
struct bpf_map_info info = {};
char upatch_dir[PATH_MAX];
@@ -1258,15 +1258,15 @@ int shirudo_upatch_maps_read_flags(const char *upatch, const char *map,
if (rc)
return rc;
out->type = info.type;
- out->type_name = shirudo_map_type_name(info.type);
+ out->type_name = map_type_name(info.type);
out->key_size = info.key_size;
out->value_size = info.value_size;
out->value_stride = map_value_stride(info.type, info.value_size);
out->max_entries = info.max_entries;
- out->n_cpus = shirudo_upatch_map_is_percpu(info.type) ?
+ out->n_cpus = upatch_map_is_percpu(info.type) ?
(__u32)nproc_possible() : 1;
resolve_map_location(out);
- if (!shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch) &&
+ if (!upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch) &&
(size_t)snprintf(upatch_dir, sizeof(upatch_dir), "%s/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) <
sizeof(upatch_dir) && stat(upatch_dir, &upatch_st) == 0)
@@ -1284,9 +1284,9 @@ int shirudo_upatch_maps_read_flags(const char *upatch, const char *map,
return 0;
}
- if (shirudo_map_skip_reason(info.type)) {
+ if (map_skip_reason(info.type)) {
out->skipped = true;
- out->skipped_reason = shirudo_map_skip_reason(info.type);
+ out->skipped_reason = map_skip_reason(info.type);
close(fd);
return 0;
}
@@ -1343,7 +1343,7 @@ static void scan_upatch_maps(const char *upatch,
struct dirent *e;
DIR *d;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
return;
if ((size_t)snprintf(dir, sizeof(dir), "%s/%s/maps",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >=
@@ -1369,18 +1369,18 @@ static void scan_upatch_maps(const char *upatch,
snprintf(one.name, sizeof(one.name), "%.*s",
(int)(sizeof(one.name) - 1), e->d_name);
one.type = info.type;
- one.type_name = shirudo_map_type_name(info.type);
+ one.type_name = map_type_name(info.type);
one.max_entries = info.max_entries;
- one.n_cpus = shirudo_upatch_map_is_percpu(info.type) ?
+ one.n_cpus = upatch_map_is_percpu(info.type) ?
(__u32)nproc_possible() : 1;
summary_append(list, n, cap, &one);
}
closedir(d);
}
-int shirudo_upatch_maps_list_one(const char *upatch,
- struct shirudo_map_summary **out,
- size_t *n_out)
+int upatch_maps_list_one(const char *upatch,
+ struct shirudo_map_summary **out,
+ size_t *n_out)
{
struct shirudo_map_summary *list = NULL;
size_t n = 0, cap = 0;
@@ -1391,8 +1391,8 @@ int shirudo_upatch_maps_list_one(const char *upatch,
return 0;
}
-int shirudo_upatch_maps_list_all(struct shirudo_map_summary **out,
- size_t *n_out)
+int upatch_maps_list_all(struct shirudo_map_summary **out,
+ size_t *n_out)
{
struct shirudo_map_summary *list = NULL;
size_t n = 0, cap = 0;
@@ -1410,8 +1410,8 @@ int shirudo_upatch_maps_list_all(struct shirudo_map_summary **out,
if (e->d_name[0] == '.')
continue;
- if (shirudo_upatch_name_from_bpffs(raw_name, sizeof(raw_name),
- e->d_name))
+ if (upatch_name_from_bpffs(raw_name, sizeof(raw_name),
+ e->d_name))
continue;
scan_upatch_maps(raw_name, &list, &n, &cap);
}
@@ -1421,14 +1421,14 @@ int shirudo_upatch_maps_list_all(struct shirudo_map_summary **out,
return 0;
}
-void shirudo_map_summary_free(struct shirudo_map_summary *list, size_t n)
+void map_summary_free(struct shirudo_map_summary *list, size_t n)
{
if (list)
xfree(list, n * sizeof(*list));
}
-void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,
- size_t n)
+void upatch_maps_print_summary(const struct shirudo_map_summary *list,
+ size_t n)
{
size_t i;
@@ -1447,10 +1447,10 @@ void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,
}
}
-char *shirudo_upatch_map_format_cell(const struct shirudo_map_view *v,
- __u32 type_id, const void *bytes,
- __u32 bytes_size,
- const char *btf_name)
+char *upatch_map_format_cell(const struct shirudo_map_view *v,
+ __u32 type_id, const void *bytes,
+ __u32 bytes_size,
+ const char *btf_name)
{
char *s = NULL;
@@ -1495,13 +1495,13 @@ static void print_serialized_hex(const __u8 *data, __u32 len)
}
}
-void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v)
+void upatch_maps_print_detail(const struct shirudo_map_view *v)
{
__u32 i;
printf("upatch: %s\n", v->upatch);
printf("Map: %s\n", v->name);
- if (shirudo_upatch_map_is_percpu(v->type))
+ if (upatch_map_is_percpu(v->type))
printf("Type: %s (%u CPUs)\n",
v->type_name, v->n_cpus);
else
@@ -1565,25 +1565,25 @@ void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v)
const struct shirudo_map_entry *en = &v->entries[i];
char *key_s;
- key_s = shirudo_upatch_map_format_cell(v, v->key_type_id,
- en->key, v->key_size,
- v->btf_key_type);
- if (shirudo_upatch_map_is_percpu(v->type)) {
+ key_s = upatch_map_format_cell(v, v->key_type_id,
+ en->key, v->key_size,
+ v->btf_key_type);
+ if (upatch_map_is_percpu(v->type)) {
char *sum_s;
int j;
- sum_s = shirudo_upatch_map_format_percpu_sum(v, en->value,
- v->btf_value_type);
+ sum_s = upatch_map_format_percpu_sum(v, en->value,
+ v->btf_value_type);
printf(" key=%s: sum=%s\n", key_s ? key_s : "?",
sum_s ? sum_s : "?");
for (j = 0; j < (int)v->n_cpus; j++) {
const char *p = (const char *)en->value +
- (size_t)j * shirudo_upatch_map_value_stride(v);
+ (size_t)j * upatch_map_value_stride(v);
char *one;
- one = shirudo_upatch_map_format_cell(v, v->value_type_id,
- p, v->value_size,
- v->btf_value_type);
+ one = upatch_map_format_cell(v, v->value_type_id,
+ p, v->value_size,
+ v->btf_value_type);
if (j % 4 == 0)
printf(" ");
printf("cpu%d=%-7s ", j, one ? one : "?");
@@ -1597,9 +1597,9 @@ void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v)
} else {
char *val_s;
- val_s = shirudo_upatch_map_format_cell(v, v->value_type_id,
- en->value, v->value_size,
- v->btf_value_type);
+ val_s = upatch_map_format_cell(v, v->value_type_id,
+ en->value, v->value_size,
+ v->btf_value_type);
printf(" key = %s\n -> %s\n", key_s ? key_s : "?",
val_s ? val_s : "?");
xstrfree(val_s);
@@ -1608,131 +1608,131 @@ void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v)
}
}
-void shirudo_upatch_maps_emit_json_fields(struct shirudo_json_emit *e,
- const struct shirudo_map_view *v)
+void upatch_maps_emit_json_fields(struct shirudo_json_emit *e,
+ const struct shirudo_map_view *v)
{
__u32 i, j;
if (!v)
return;
- shirudo_json_kv_string(e, "name", v->name);
- shirudo_json_kv_string(e, "type", v->type_name);
- shirudo_json_kv_int(e, "max_entries", v->max_entries);
- shirudo_json_kv_int(e, "n_entries", v->n_entries);
- if (shirudo_upatch_map_is_percpu(v->type))
- shirudo_json_kv_int(e, "n_cpus", v->n_cpus);
+ json_kv_string(e, "name", v->name);
+ json_kv_string(e, "type", v->type_name);
+ json_kv_int(e, "max_entries", v->max_entries);
+ json_kv_int(e, "n_entries", v->n_entries);
+ if (upatch_map_is_percpu(v->type))
+ json_kv_int(e, "n_cpus", v->n_cpus);
if (v->serialized) {
__u32 p;
- shirudo_json_kv_bool(e, "serialized", true);
- shirudo_json_kv_int(e, "serialized_pages",
- v->n_serial_pages);
- shirudo_json_kv_int(e, "serialized_bytes",
- v->serial_bytes_total);
- shirudo_json_arr_open(e, "pages");
+ json_kv_bool(e, "serialized", true);
+ json_kv_int(e, "serialized_pages",
+ v->n_serial_pages);
+ json_kv_int(e, "serialized_bytes",
+ v->serial_bytes_total);
+ json_arr_open(e, "pages");
for (p = 0; p < v->n_serial_pages; p++) {
const struct shirudo_serial_page *page =
&v->serial_pages[p];
- char *hex = shirudo_hex_alloc(page->data,
- page->bytes);
-
- shirudo_json_obj_open(e);
- shirudo_json_kv_int(e, "page_index",
- page->page_index);
- shirudo_json_kv_int(e, "cursor", page->cursor);
- shirudo_json_kv_int(e, "next_cursor",
- page->next_cursor);
- shirudo_json_kv_bool(e, "done", page->done);
- shirudo_json_kv_int(e, "flags", page->flags);
- shirudo_json_kv_int(e, "chunks", page->chunks);
- shirudo_json_kv_int(e, "bytes", page->bytes);
- shirudo_json_kv_string(e, "data_hex",
- hex ? hex : "");
+ char *hex = hex_alloc(page->data,
+ page->bytes);
+
+ json_obj_open(e);
+ json_kv_int(e, "page_index",
+ page->page_index);
+ json_kv_int(e, "cursor", page->cursor);
+ json_kv_int(e, "next_cursor",
+ page->next_cursor);
+ json_kv_bool(e, "done", page->done);
+ json_kv_int(e, "flags", page->flags);
+ json_kv_int(e, "chunks", page->chunks);
+ json_kv_int(e, "bytes", page->bytes);
+ json_kv_string(e, "data_hex",
+ hex ? hex : "");
xfree(hex, (size_t)page->bytes * 2 + 1);
- shirudo_json_obj_close(e);
+ json_obj_close(e);
}
- shirudo_json_arr_close(e);
+ json_arr_close(e);
return;
}
- shirudo_json_kv_bool(e, "serialized", false);
+ json_kv_bool(e, "serialized", false);
if (v->skipped) {
- shirudo_json_kv_string(e, "skipped",
- v->skipped_reason ?
- v->skipped_reason : "");
+ json_kv_string(e, "skipped",
+ v->skipped_reason ?
+ v->skipped_reason : "");
return;
}
- shirudo_json_kv_bool(e, "truncated", v->truncated);
+ json_kv_bool(e, "truncated", v->truncated);
if (v->truncated)
- shirudo_json_kv_int(e, "n_truncated_at", v->n_truncated_at);
+ json_kv_int(e, "n_truncated_at", v->n_truncated_at);
if (v->btf_key_type[0] || v->btf_value_type[0]) {
- shirudo_json_obj_open_key(e, "btf");
- shirudo_json_kv_string(e, "key_type",
- v->btf_key_type[0] ? v->btf_key_type
+ json_obj_open_key(e, "btf");
+ json_kv_string(e, "key_type",
+ v->btf_key_type[0] ? v->btf_key_type
: "");
- shirudo_json_kv_string(e, "value_type",
- v->btf_value_type[0] ?
- v->btf_value_type : "");
+ json_kv_string(e, "value_type",
+ v->btf_value_type[0] ?
+ v->btf_value_type : "");
if (v->key_type_def[0])
- shirudo_json_kv_string(e, "key_type_def",
- v->key_type_def);
+ json_kv_string(e, "key_type_def",
+ v->key_type_def);
if (v->value_type_def[0])
- shirudo_json_kv_string(e, "value_type_def",
- v->value_type_def);
- shirudo_json_obj_close(e);
+ json_kv_string(e, "value_type_def",
+ v->value_type_def);
+ json_obj_close(e);
}
- shirudo_json_arr_open(e, "entries");
+ json_arr_open(e, "entries");
for (i = 0; i < v->n_entries; i++) {
const struct shirudo_map_entry *en = &v->entries[i];
char *key_s;
- key_s = shirudo_upatch_map_format_cell(v, v->key_type_id,
- en->key, v->key_size,
- v->btf_key_type);
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "key", key_s ? key_s : "");
- if (shirudo_upatch_map_is_percpu(v->type)) {
+ key_s = upatch_map_format_cell(v, v->key_type_id,
+ en->key, v->key_size,
+ v->btf_key_type);
+ json_obj_open(e);
+ json_kv_string(e, "key", key_s ? key_s : "");
+ if (upatch_map_is_percpu(v->type)) {
char *sum_s;
- sum_s = shirudo_upatch_map_format_percpu_sum(v, en->value,
- v->btf_value_type);
- shirudo_json_arr_open(e, "values_per_cpu");
+ sum_s = upatch_map_format_percpu_sum(v, en->value,
+ v->btf_value_type);
+ json_arr_open(e, "values_per_cpu");
for (j = 0; j < v->n_cpus; j++) {
const char *p = (const char *)en->value +
- (size_t)j * shirudo_upatch_map_value_stride(v);
+ (size_t)j * upatch_map_value_stride(v);
char *one;
- one = shirudo_upatch_map_format_cell(v, v->value_type_id,
- p, v->value_size,
- v->btf_value_type);
- shirudo_json_str(e, one ? one : "");
+ one = upatch_map_format_cell(v, v->value_type_id,
+ p, v->value_size,
+ v->btf_value_type);
+ json_str(e, one ? one : "");
xstrfree(one);
}
- shirudo_json_arr_close(e);
- shirudo_json_kv_string(e, "sum",
- sum_s ? sum_s : "");
+ json_arr_close(e);
+ json_kv_string(e, "sum",
+ sum_s ? sum_s : "");
xstrfree(sum_s);
} else {
char *val_s;
- val_s = shirudo_upatch_map_format_cell(v, v->value_type_id,
- en->value, v->value_size,
- v->btf_value_type);
- shirudo_json_kv_string(e, "value",
- val_s ? val_s : "");
+ val_s = upatch_map_format_cell(v, v->value_type_id,
+ en->value, v->value_size,
+ v->btf_value_type);
+ json_kv_string(e, "value",
+ val_s ? val_s : "");
xstrfree(val_s);
}
- shirudo_json_obj_close(e);
+ json_obj_close(e);
xstrfree(key_s);
}
- shirudo_json_arr_close(e);
+ json_arr_close(e);
}
-void shirudo_upatch_maps_emit_json_object(struct shirudo_json_emit *e,
- const struct shirudo_map_view *v)
+void upatch_maps_emit_json_object(struct shirudo_json_emit *e,
+ const struct shirudo_map_view *v)
{
if (!v)
return;
- shirudo_json_obj_open(e);
- shirudo_upatch_maps_emit_json_fields(e, v);
- shirudo_json_obj_close(e);
+ json_obj_open(e);
+ upatch_maps_emit_json_fields(e, v);
+ json_obj_close(e);
}
diff --git a/util/upatch_maps.h b/util/upatch_maps.h
index 58d75f55..c16f3c57 100644
--- a/util/upatch_maps.h
+++ b/util/upatch_maps.h
@@ -82,7 +82,7 @@ struct shirudo_map_view {
struct shirudo_map_entry *entries; /* n_entries long */
};
-void shirudo_map_view_free(struct shirudo_map_view *v);
+void map_view_free(struct shirudo_map_view *v);
/* Name, type and max_entries alone, without reading entries. */
struct shirudo_map_summary {
@@ -94,21 +94,21 @@ struct shirudo_map_summary {
__u32 n_cpus;
};
-int shirudo_upatch_maps_list_all(struct shirudo_map_summary **out,
- size_t *n_out);
-int shirudo_upatch_maps_list_one(const char *upatch,
- struct shirudo_map_summary **out,
- size_t *n_out);
-void shirudo_map_summary_free(struct shirudo_map_summary *list, size_t n);
+int upatch_maps_list_all(struct shirudo_map_summary **out,
+ size_t *n_out);
+int upatch_maps_list_one(const char *upatch,
+ struct shirudo_map_summary **out,
+ size_t *n_out);
+void map_summary_free(struct shirudo_map_summary *list, size_t n);
/*
* Read one map's contents. <max_entries_cap> bounds the number of
* (key, value) pairs returned; SHIRUDO_MAP_ENTRIES_DEFAULT for the
* default, 0 for unlimited (--show-full). Returns 0/-errno.
*/
-int shirudo_upatch_maps_read(const char *upatch, const char *map,
- __u32 max_entries_cap,
- struct shirudo_map_view *out);
+int upatch_maps_read(const char *upatch, const char *map,
+ __u32 max_entries_cap,
+ struct shirudo_map_view *out);
/*
* Serializer-backed maps are drained by a read, as the map-export timer
@@ -117,31 +117,31 @@ int shirudo_upatch_maps_read(const char *upatch, const char *map,
*/
#define SHIRUDO_MAP_READ_PEEK (1u << 0)
-int shirudo_upatch_maps_read_flags(const char *upatch, const char *map,
- __u32 max_entries_cap, __u32 flags,
- struct shirudo_map_view *out);
+int upatch_maps_read_flags(const char *upatch, const char *map,
+ __u32 max_entries_cap, __u32 flags,
+ struct shirudo_map_view *out);
-void shirudo_upatch_maps_print_summary(const struct shirudo_map_summary *list,
- size_t n);
-void shirudo_upatch_maps_print_detail(const struct shirudo_map_view *v);
+void upatch_maps_print_summary(const struct shirudo_map_summary *list,
+ size_t n);
+void upatch_maps_print_detail(const struct shirudo_map_view *v);
/* NULL v emits nothing. The shape is part of the status report. */
-void shirudo_upatch_maps_emit_json_fields(struct shirudo_json_emit *e,
- const struct shirudo_map_view *v);
-void shirudo_upatch_maps_emit_json_object(struct shirudo_json_emit *e,
- const struct shirudo_map_view *v);
-
-bool shirudo_upatch_map_is_percpu(__u32 type);
-__u32 shirudo_upatch_map_value_stride(const struct shirudo_map_view *v);
-char *shirudo_upatch_map_format_cell(const struct shirudo_map_view *v,
- __u32 type_id, const void *value,
- __u32 value_size,
- const char *btf_type);
-char *shirudo_upatch_map_format_percpu_sum(const struct shirudo_map_view *v,
- const void *values_per_cpu,
- const char *btf_type);
-
-int shirudo_prog_test_run(int prog_fd, void *ctx, __u32 ctx_sz,
- __u32 *retval);
+void upatch_maps_emit_json_fields(struct shirudo_json_emit *e,
+ const struct shirudo_map_view *v);
+void upatch_maps_emit_json_object(struct shirudo_json_emit *e,
+ const struct shirudo_map_view *v);
+
+bool upatch_map_is_percpu(__u32 type);
+__u32 upatch_map_value_stride(const struct shirudo_map_view *v);
+char *upatch_map_format_cell(const struct shirudo_map_view *v,
+ __u32 type_id, const void *value,
+ __u32 value_size,
+ const char *btf_type);
+char *upatch_map_format_percpu_sum(const struct shirudo_map_view *v,
+ const void *values_per_cpu,
+ const char *btf_type);
+
+int prog_test_run(int prog_fd, void *ctx, __u32 ctx_sz,
+ __u32 *retval);
#endif /* SHIRUDO_UTIL_UPATCH_MAPS_H */
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index a2bae90d..d1e7fe6a 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -146,9 +146,9 @@ static int metric_type_from_view(const struct shirudo_map_view *v,
return 0;
}
-int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
- enum shirudo_otel_signal *signal,
- char *reason, size_t reason_sz)
+int upatch_maps_otel_classify(const struct shirudo_map_view *v,
+ enum shirudo_otel_signal *signal,
+ char *reason, size_t reason_sz)
{
struct metric_type mt;
int rc;
@@ -164,7 +164,7 @@ int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
snprintf(reason, reason_sz, "map type is not generically readable");
return 0;
}
- if (!shirudo_upatch_map_is_percpu(v->type)) {
+ if (!upatch_map_is_percpu(v->type)) {
snprintf(reason, reason_sz, "map is not per-CPU");
return 0;
}
@@ -186,12 +186,12 @@ int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
static void otlp_kv_string(struct shirudo_json_emit *e, const char *key,
const char *value)
{
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "key", key);
- shirudo_json_obj_open_key(e, "value");
- shirudo_json_kv_string(e, "stringValue", value ? value : "");
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_obj_open(e);
+ json_kv_string(e, "key", key);
+ json_obj_open_key(e, "value");
+ json_kv_string(e, "stringValue", value ? value : "");
+ json_obj_close(e);
+ json_obj_close(e);
}
static void otlp_kv_int(struct shirudo_json_emit *e, const char *key,
@@ -200,78 +200,78 @@ static void otlp_kv_int(struct shirudo_json_emit *e, const char *key,
char num[32];
snprintf(num, sizeof(num), "%lld", value);
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "key", key);
- shirudo_json_obj_open_key(e, "value");
- shirudo_json_kv_string(e, "intValue", num);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_obj_open(e);
+ json_kv_string(e, "key", key);
+ json_obj_open_key(e, "value");
+ json_kv_string(e, "intValue", num);
+ json_obj_close(e);
+ json_obj_close(e);
}
static void otlp_kv_bool(struct shirudo_json_emit *e, const char *key,
bool value)
{
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "key", key);
- shirudo_json_obj_open_key(e, "value");
- shirudo_json_kv_bool(e, "boolValue", value);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_obj_open(e);
+ json_kv_string(e, "key", key);
+ json_obj_open_key(e, "value");
+ json_kv_bool(e, "boolValue", value);
+ json_obj_close(e);
+ json_obj_close(e);
}
static void otlp_kvlist_begin(struct shirudo_json_emit *e, const char *key)
{
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "key", key);
- shirudo_json_obj_open_key(e, "value");
- shirudo_json_obj_open_key(e, "kvlistValue");
- shirudo_json_arr_open(e, "values");
+ json_obj_open(e);
+ json_kv_string(e, "key", key);
+ json_obj_open_key(e, "value");
+ json_obj_open_key(e, "kvlistValue");
+ json_arr_open(e, "values");
}
static void otlp_kvlist_end(struct shirudo_json_emit *e)
{
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
+ json_obj_close(e);
+ json_obj_close(e);
}
static void otlp_array_begin(struct shirudo_json_emit *e, const char *key)
{
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "key", key);
- shirudo_json_obj_open_key(e, "value");
- shirudo_json_obj_open_key(e, "arrayValue");
- shirudo_json_arr_open(e, "values");
+ json_obj_open(e);
+ json_kv_string(e, "key", key);
+ json_obj_open_key(e, "value");
+ json_obj_open_key(e, "arrayValue");
+ json_arr_open(e, "values");
}
static void otlp_array_end(struct shirudo_json_emit *e)
{
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
+ json_obj_close(e);
+ json_obj_close(e);
}
static void otlp_array_string(struct shirudo_json_emit *e, const char *value)
{
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "stringValue", value ? value : "");
- shirudo_json_obj_close(e);
+ json_obj_open(e);
+ json_kv_string(e, "stringValue", value ? value : "");
+ json_obj_close(e);
}
static void otlp_array_kvlist_begin(struct shirudo_json_emit *e)
{
- shirudo_json_obj_open(e);
- shirudo_json_obj_open_key(e, "kvlistValue");
- shirudo_json_arr_open(e, "values");
+ json_obj_open(e);
+ json_obj_open_key(e, "kvlistValue");
+ json_arr_open(e, "values");
}
static void otlp_array_kvlist_end(struct shirudo_json_emit *e)
{
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
+ json_obj_close(e);
}
/*
@@ -388,9 +388,9 @@ static int json_anyvalue_number(struct json_anyvalue_ctx *c,
memcpy(number, start, len);
number[len] = '\0';
if (fraction)
- shirudo_json_kv_string(e, "doubleValue", number);
+ json_kv_string(e, "doubleValue", number);
else
- shirudo_json_kv_string(e, "intValue", number);
+ json_kv_string(e, "intValue", number);
return 0;
}
@@ -411,16 +411,16 @@ static int json_anyvalue_object(struct json_anyvalue_ctx *c,
}
c->p++;
if (wrap)
- shirudo_json_obj_open(e);
- shirudo_json_obj_open_key(e, "kvlistValue");
- shirudo_json_arr_open(e, "values");
+ json_obj_open(e);
+ json_obj_open_key(e, "kvlistValue");
+ json_arr_open(e, "values");
json_anyvalue_skip_ws(c);
if (c->p < c->end && *c->p == '}') {
c->p++;
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
if (wrap)
- shirudo_json_obj_close(e);
+ json_obj_close(e);
c->depth--;
return 0;
}
@@ -437,12 +437,12 @@ static int json_anyvalue_object(struct json_anyvalue_ctx *c,
break;
}
json_anyvalue_skip_ws(c);
- shirudo_json_obj_open(e);
- shirudo_json_kv_raw(e, "key", key, key_len);
- shirudo_json_obj_open_key(e, "value");
+ json_obj_open(e);
+ json_kv_raw(e, "key", key, key_len);
+ json_obj_open_key(e, "value");
rc = json_anyvalue_emit_contents(c, e);
- shirudo_json_obj_close(e);
- shirudo_json_obj_close(e);
+ json_obj_close(e);
+ json_obj_close(e);
if (rc)
break;
json_anyvalue_skip_ws(c);
@@ -461,10 +461,10 @@ static int json_anyvalue_object(struct json_anyvalue_ctx *c,
}
json_anyvalue_skip_ws(c);
}
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
if (wrap)
- shirudo_json_obj_close(e);
+ json_obj_close(e);
c->depth--;
return rc;
}
@@ -480,9 +480,9 @@ static int json_anyvalue_array(struct json_anyvalue_ctx *c,
}
c->p++;
if (wrap)
- shirudo_json_obj_open(e);
- shirudo_json_obj_open_key(e, "arrayValue");
- shirudo_json_arr_open(e, "values");
+ json_obj_open(e);
+ json_obj_open_key(e, "arrayValue");
+ json_arr_open(e, "values");
json_anyvalue_skip_ws(c);
if (c->p < c->end && *c->p == ']') {
c->p++;
@@ -507,10 +507,10 @@ static int json_anyvalue_array(struct json_anyvalue_ctx *c,
}
}
}
- shirudo_json_arr_close(e);
- shirudo_json_obj_close(e);
+ json_arr_close(e);
+ json_obj_close(e);
if (wrap)
- shirudo_json_obj_close(e);
+ json_obj_close(e);
c->depth--;
return rc;
}
@@ -534,19 +534,19 @@ static int json_anyvalue_emit_contents(struct json_anyvalue_ctx *c,
rc = json_anyvalue_string(c, &start, &len);
if (rc)
return rc;
- shirudo_json_kv_raw(e, "stringValue", start, len);
+ json_kv_raw(e, "stringValue", start, len);
return 0;
case 't':
rc = json_anyvalue_literal(c, "true");
if (rc)
return rc;
- shirudo_json_kv_bool(e, "boolValue", true);
+ json_kv_bool(e, "boolValue", true);
return 0;
case 'f':
rc = json_anyvalue_literal(c, "false");
if (rc)
return rc;
- shirudo_json_kv_bool(e, "boolValue", false);
+ json_kv_bool(e, "boolValue", false);
return 0;
case 'n':
rc = json_anyvalue_literal(c, "null");
@@ -564,9 +564,9 @@ static int json_anyvalue_emit(struct json_anyvalue_ctx *c,
{
int rc;
- shirudo_json_obj_open(e);
+ json_obj_open(e);
rc = json_anyvalue_emit_contents(c, e);
- shirudo_json_obj_close(e);
+ json_obj_close(e);
return rc;
}
@@ -596,11 +596,11 @@ static void emit_resource_attributes(struct shirudo_json_emit *e)
if (gethostname(hostname, sizeof(hostname)) != 0)
snprintf(hostname, sizeof(hostname), "unknown");
hostname[sizeof(hostname) - 1] = '\0';
- shirudo_json_arr_open(e, "attributes");
+ json_arr_open(e, "attributes");
otlp_kv_string(e, "service.name", "shirudo");
otlp_kv_string(e, "service.version", shirudo_version);
otlp_kv_string(e, "host.name", hostname);
- shirudo_json_arr_close(e);
+ json_arr_close(e);
}
static __u64 realtime_ns(void)
@@ -626,7 +626,7 @@ static __attribute__((unused)) void emit_log_map_data(struct shirudo_json_emit *
otlp_kv_string(e, "type", v->type_name);
otlp_kv_int(e, "max_entries", v->max_entries);
otlp_kv_int(e, "n_entries", v->n_entries);
- if (shirudo_upatch_map_is_percpu(v->type))
+ if (upatch_map_is_percpu(v->type))
otlp_kv_int(e, "n_cpus", v->n_cpus);
if (v->serialized) {
__u32 p;
@@ -638,8 +638,8 @@ static __attribute__((unused)) void emit_log_map_data(struct shirudo_json_emit *
otlp_array_begin(e, "pages");
for (p = 0; p < v->n_serial_pages; p++) {
const struct shirudo_serial_page *page = &v->serial_pages[p];
- char *hex = shirudo_hex_alloc(page->data,
- page->bytes);
+ char *hex = hex_alloc(page->data,
+ page->bytes);
otlp_array_kvlist_begin(e);
otlp_kv_int(e, "page_index", page->page_index);
@@ -680,25 +680,25 @@ static __attribute__((unused)) void emit_log_map_data(struct shirudo_json_emit *
const struct shirudo_map_entry *en = &v->entries[i];
char *key;
- key = shirudo_upatch_map_format_cell(v, v->key_type_id,
- en->key, v->key_size,
- v->btf_key_type);
+ key = upatch_map_format_cell(v, v->key_type_id,
+ en->key, v->key_size,
+ v->btf_key_type);
otlp_array_kvlist_begin(e);
otlp_kv_string(e, "key", key ?: "");
- if (shirudo_upatch_map_is_percpu(v->type)) {
+ if (upatch_map_is_percpu(v->type)) {
char *sum;
- sum = shirudo_upatch_map_format_percpu_sum(v, en->value,
- v->btf_value_type);
+ sum = upatch_map_format_percpu_sum(v, en->value,
+ v->btf_value_type);
otlp_array_begin(e, "values_per_cpu");
for (j = 0; j < v->n_cpus; j++) {
const char *p = (const char *)en->value +
- (size_t)j * shirudo_upatch_map_value_stride(v);
+ (size_t)j * upatch_map_value_stride(v);
char *one;
- one = shirudo_upatch_map_format_cell(v, v->value_type_id,
- p, v->value_size,
- v->btf_value_type);
+ one = upatch_map_format_cell(v, v->value_type_id,
+ p, v->value_size,
+ v->btf_value_type);
otlp_array_string(e, one ?: "");
xstrfree(one);
}
@@ -708,9 +708,9 @@ static __attribute__((unused)) void emit_log_map_data(struct shirudo_json_emit *
} else {
char *value;
- value = shirudo_upatch_map_format_cell(v, v->value_type_id,
- en->value, v->value_size,
- v->btf_value_type);
+ value = upatch_map_format_cell(v, v->value_type_id,
+ en->value, v->value_size,
+ v->btf_value_type);
otlp_kv_string(e, "value", value ?: "");
xstrfree(value);
}
@@ -740,40 +740,40 @@ static int build_log_payload(const char *path,
e.cap = SHIRUDO_JSON_MAX_BYTES;
u64_decimal(realtime_ns(), now);
- shirudo_json_obj_open(&e);
- shirudo_json_arr_open(&e, "resourceLogs");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "resource");
+ json_obj_open(&e);
+ json_arr_open(&e, "resourceLogs");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "resource");
emit_resource_attributes(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "scopeLogs");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "scope");
- shirudo_json_kv_string(&e, "name", "shirudo.upatch.maps");
- shirudo_json_kv_string(&e, "version", shirudo_version);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "logRecords");
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "timeUnixNano", now);
- shirudo_json_kv_string(&e, "observedTimeUnixNano", now);
- shirudo_json_kv_int(&e, "severityNumber", 9);
- shirudo_json_kv_string(&e, "severityText", "INFO");
- shirudo_json_kv_string(&e, "eventName", "shirudo.bpf.map.snapshot");
- decode_rc = path ? shirudo_upatch_decode_map_file_otel(path, v,
- &decoded, &decoded_len) :
- shirudo_upatch_decode_map_otel(v, &decoded, &decoded_len);
+ json_obj_close(&e);
+ json_arr_open(&e, "scopeLogs");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "scope");
+ json_kv_string(&e, "name", "shirudo.upatch.maps");
+ json_kv_string(&e, "version", shirudo_version);
+ json_obj_close(&e);
+ json_arr_open(&e, "logRecords");
+ json_obj_open(&e);
+ json_kv_string(&e, "timeUnixNano", now);
+ json_kv_string(&e, "observedTimeUnixNano", now);
+ json_kv_int(&e, "severityNumber", 9);
+ json_kv_string(&e, "severityText", "INFO");
+ json_kv_string(&e, "eventName", "shirudo.bpf.map.snapshot");
+ decode_rc = path ? upatch_decode_map_file_otel(path, v,
+ &decoded, &decoded_len) :
+ upatch_decode_map_otel(v, &decoded, &decoded_len);
if (!decode_rc && record_max && decoded_len > record_max) {
xfree(decoded, decoded_len + 1);
decode_rc = -E2BIG;
}
if (decode_rc == 0) {
- shirudo_json_kv_raw(&e, "body", decoded, decoded_len);
+ json_kv_raw(&e, "body", decoded, decoded_len);
} else {
xfree(buf, SHIRUDO_JSON_MAX_BYTES);
return decode_rc;
}
xfree(decoded, decoded_len + 1);
- shirudo_json_arr_open(&e, "attributes");
+ json_arr_open(&e, "attributes");
otlp_kv_string(&e, "shirudo.upatch.name", v->upatch);
otlp_kv_string(&e, "shirudo.upatch.location", v->location);
otlp_kv_string(&e, "shirudo.map.name", v->name);
@@ -783,14 +783,14 @@ static int build_log_payload(const char *path,
otlp_kv_int(&e, "shirudo.map.n_cpus", v->n_cpus);
otlp_kv_bool(&e, "shirudo.map.serialized", v->serialized);
otlp_kv_bool(&e, "shirudo.map.truncated", v->truncated);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
xfree(buf, SHIRUDO_JSON_MAX_BYTES);
@@ -801,9 +801,9 @@ static int build_log_payload(const char *path,
return 0;
}
-int shirudo_upatch_maps_otel_build_log_file(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len)
+int upatch_maps_otel_build_log_file(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len)
{
if (!path)
return -EINVAL;
@@ -845,12 +845,12 @@ static int entry_metric_value(const struct shirudo_map_view *v,
const struct shirudo_map_entry *en,
const struct metric_type *mt, __s64 *out)
{
- __u32 count = shirudo_upatch_map_is_percpu(v->type) ?
+ __u32 count = upatch_map_is_percpu(v->type) ?
v->n_cpus : 1;
__int128 signed_sum = 0;
unsigned __int128 unsigned_sum = 0;
- __u32 stride = shirudo_upatch_map_value_stride(v);
+ __u32 stride = upatch_map_value_stride(v);
__u32 i;
for (i = 0; i < count; i++) {
@@ -931,7 +931,7 @@ static int map_start_ns(const struct shirudo_map_view *v, __u64 *out)
*out = v->lifetime_start_ns;
return 0;
}
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), v->upatch))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), v->upatch))
return -ENAMETOOLONG;
if ((size_t)snprintf(path, sizeof(path), "%s/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >=
@@ -1000,34 +1000,34 @@ static __attribute__((unused)) int build_metric_payload(const struct otel_state
e.buf = buf;
e.cap = SHIRUDO_JSON_MAX_BYTES;
- shirudo_json_obj_open(&e);
- shirudo_json_arr_open(&e, "resourceMetrics");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "resource");
+ json_obj_open(&e);
+ json_arr_open(&e, "resourceMetrics");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "resource");
emit_resource_attributes(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "scopeMetrics");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "scope");
- shirudo_json_kv_string(&e, "name", "shirudo.upatch.maps");
- shirudo_json_kv_string(&e, "version", shirudo_version);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "metrics");
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "name", name);
+ json_obj_close(&e);
+ json_arr_open(&e, "scopeMetrics");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "scope");
+ json_kv_string(&e, "name", "shirudo.upatch.maps");
+ json_kv_string(&e, "version", shirudo_version);
+ json_obj_close(&e);
+ json_arr_open(&e, "metrics");
+ json_obj_open(&e);
+ json_kv_string(&e, "name", name);
if (st->opts.metric_description && st->opts.metric_description[0])
- shirudo_json_kv_string(&e, "description",
- st->opts.metric_description);
- shirudo_json_kv_string(&e, "unit",
- st->opts.metric_unit ?: "1");
- shirudo_json_obj_open_key(&e,
- st->opts.metric_kind == SHIRUDO_OTEL_METRIC_COUNTER ?
- "sum" : "gauge");
+ json_kv_string(&e, "description",
+ st->opts.metric_description);
+ json_kv_string(&e, "unit",
+ st->opts.metric_unit ?: "1");
+ json_obj_open_key(&e,
+ st->opts.metric_kind == SHIRUDO_OTEL_METRIC_COUNTER ?
+ "sum" : "gauge");
if (st->opts.metric_kind == SHIRUDO_OTEL_METRIC_COUNTER) {
- shirudo_json_kv_int(&e, "aggregationTemporality", 2);
- shirudo_json_kv_bool(&e, "isMonotonic", true);
+ json_kv_int(&e, "aggregationTemporality", 2);
+ json_kv_bool(&e, "isMonotonic", true);
}
- shirudo_json_arr_open(&e, "dataPoints");
+ json_arr_open(&e, "dataPoints");
for (i = 0; i < v->n_entries; i++) {
const struct shirudo_map_entry *en = &v->entries[i];
char value[32];
@@ -1040,32 +1040,32 @@ static __attribute__((unused)) int build_metric_payload(const struct otel_state
return rc;
}
snprintf(value, sizeof(value), "%lld", point);
- key = shirudo_upatch_map_format_cell(v, v->key_type_id,
- en->key, v->key_size, v->btf_key_type);
- shirudo_json_obj_open(&e);
+ key = upatch_map_format_cell(v, v->key_type_id,
+ en->key, v->key_size, v->btf_key_type);
+ json_obj_open(&e);
if (st->opts.metric_kind == SHIRUDO_OTEL_METRIC_COUNTER)
- shirudo_json_kv_string(&e, "startTimeUnixNano", start);
- shirudo_json_kv_string(&e, "timeUnixNano", now);
- shirudo_json_kv_string(&e, "asInt", value);
- shirudo_json_arr_open(&e, "attributes");
+ json_kv_string(&e, "startTimeUnixNano", start);
+ json_kv_string(&e, "timeUnixNano", now);
+ json_kv_string(&e, "asInt", value);
+ json_arr_open(&e, "attributes");
otlp_kv_string(&e, "shirudo.map.key", key ?: "");
otlp_kv_string(&e, "shirudo.upatch.name", v->upatch);
otlp_kv_string(&e, "shirudo.upatch.location", v->location);
otlp_kv_string(&e, "shirudo.map.name", v->name);
otlp_kv_string(&e, "shirudo.map.type", v->type_name);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
xstrfree(key);
}
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
xfree(buf, SHIRUDO_JSON_MAX_BYTES);
@@ -1087,9 +1087,9 @@ static int build_metric_decoded_payload(const char *path,
int rc;
(void)opts;
- rc = path ? shirudo_upatch_decode_map_file_json(path, v,
- &decoded, &decoded_len) :
- shirudo_upatch_decode_map_json(v, &decoded, &decoded_len);
+ rc = path ? upatch_decode_map_file_json(path, v,
+ &decoded, &decoded_len) :
+ upatch_decode_map_json(v, &decoded, &decoded_len);
if (rc)
return rc;
decoded_buf = decoded;
@@ -1109,24 +1109,24 @@ static int build_metric_decoded_payload(const char *path,
}
e.buf = buf;
e.cap = SHIRUDO_JSON_MAX_BYTES;
- shirudo_json_obj_open(&e);
- shirudo_json_arr_open(&e, "resourceMetrics");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "resource");
+ json_obj_open(&e);
+ json_arr_open(&e, "resourceMetrics");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "resource");
emit_resource_attributes(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "scopeMetrics");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "scope");
- shirudo_json_kv_string(&e, "name", "shirudo.upatch.maps");
- shirudo_json_kv_string(&e, "version", shirudo_version);
- shirudo_json_obj_close(&e);
- shirudo_json_kv_raw(&e, "metrics", decoded, decoded_len);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_obj_close(&e);
+ json_arr_open(&e, "scopeMetrics");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "scope");
+ json_kv_string(&e, "name", "shirudo.upatch.maps");
+ json_kv_string(&e, "version", shirudo_version);
+ json_obj_close(&e);
+ json_kv_raw(&e, "metrics", decoded, decoded_len);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
xfree(buf, SHIRUDO_JSON_MAX_BYTES);
xfree(decoded_buf, decoded_alloc_len + 1);
@@ -1291,10 +1291,10 @@ shirudo_upatch_maps_otel_build_metric(const struct shirudo_map_view *v,
return build_metric_decoded_payload(NULL, v, opts, out, out_len);
}
-int shirudo_upatch_maps_otel_build_metric_file(const char *path,
- const struct shirudo_map_view *v,
- const struct shirudo_otel_opts *opts,
- char **out, size_t *out_len)
+int upatch_maps_otel_build_metric_file(const char *path,
+ const struct shirudo_map_view *v,
+ const struct shirudo_otel_opts *opts,
+ char **out, size_t *out_len)
{
if (!path)
return -EINVAL;
@@ -1347,8 +1347,8 @@ static int percent_decode(char *s)
if (!src[1] || !src[2])
return -EINVAL;
- hi = shirudo_hex_nibble(src[1]);
- lo = shirudo_hex_nibble(src[2]);
+ hi = hex_nibble(src[1]);
+ lo = hex_nibble(src[2]);
if (hi < 0 || lo < 0)
return -EINVAL;
*dst++ = (char)((hi << 4) | lo);
@@ -1406,7 +1406,7 @@ static int add_configured_headers(struct otel_state *st, const char *input)
if (tenant) {
if (st->opts.tenant_id)
continue;
- if (tenant_seen || !shirudo_tenant_id_valid(value)) {
+ if (tenant_seen || !tenant_id_valid(value)) {
rc = -EINVAL;
break;
}
@@ -1470,7 +1470,7 @@ static int configure_state(struct otel_state *st, const char *spec,
rc = add_configured_headers(st, headers);
if (rc || !st->opts.tenant_id)
return rc;
- if (!shirudo_tenant_id_valid(st->opts.tenant_id))
+ if (!tenant_id_valid(st->opts.tenant_id))
return -EINVAL;
{
char line[sizeof("X-Tenant-ID: ") + SHIRUDO_TENANT_ID_MAX];
@@ -1605,11 +1605,11 @@ static int check_partial_success(enum shirudo_otel_signal signal,
if (len == 0)
return 0;
- rc = shirudo_json_parse(body, len, root, ARRAY_SIZE(root));
+ rc = json_parse(body, len, root, ARRAY_SIZE(root));
if (rc) {
partial[0] = (struct shirudo_json_field){
count, SHIRUDO_JSON_T_INT, &rejected, 0, 0, NULL, 0 };
- if (shirudo_json_parse(body, len, root, ARRAY_SIZE(root)))
+ if (json_parse(body, len, root, ARRAY_SIZE(root)))
return -EBADMSG;
} else if (partial[0].seen) {
char *end;
@@ -1625,7 +1625,7 @@ static int check_partial_success(enum shirudo_otel_signal signal,
partial[0] = (struct shirudo_json_field){
"errorMessage", SHIRUDO_JSON_T_STRING, error,
sizeof(error), 0, NULL, 0 };
- if (shirudo_json_parse(body, len, root, ARRAY_SIZE(root)))
+ if (json_parse(body, len, root, ARRAY_SIZE(root)))
error[0] = '\0';
pr_err("otel: Collector partially rejected %lld %s%s%s",
rejected, signal == SHIRUDO_OTEL_LOG ? "log record(s)" :
@@ -1709,7 +1709,7 @@ static int otel_post(struct otel_state *st, const char *json, size_t json_len)
st->insecure_tls ? 0L : 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST,
st->insecure_tls ? 0L : 2L);
- if (shirudo_tls_curl_policy(curl, NULL)) {
+ if (tls_curl_policy(curl, NULL)) {
curl_easy_cleanup(curl);
rc = -EINVAL;
break;
@@ -1805,8 +1805,8 @@ static int otel_open_common(const char *spec, const struct shirudo_map_view *v,
if (!v || !state)
return -EINVAL;
if (automatic) {
- rc = shirudo_upatch_maps_otel_classify(v, &signal,
- reason, sizeof(reason));
+ rc = upatch_maps_otel_classify(v, &signal,
+ reason, sizeof(reason));
if (rc)
return rc;
fprintf(stderr, "otel: selected %s for %s map %s: %s\n",
@@ -1837,9 +1837,9 @@ static int otel_emit(void *state, const struct shirudo_map_view *v)
st->opts.log_record_max_bytes,
&payload, &len);
else if (st->decoder_path)
- rc = shirudo_upatch_maps_otel_build_metric_file(st->decoder_path, v,
- &st->opts,
- &payload, &len);
+ rc = upatch_maps_otel_build_metric_file(st->decoder_path, v,
+ &st->opts,
+ &payload, &len);
else
rc = shirudo_upatch_maps_otel_build_metric(v, &st->opts,
&payload, &len);
@@ -1903,47 +1903,47 @@ static int build_generic_log_payload(const char *scope_name,
e.cap = cap;
u64_decimal(realtime_ns(), now);
- shirudo_json_obj_open(&e);
- shirudo_json_arr_open(&e, "resourceLogs");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "resource");
+ json_obj_open(&e);
+ json_arr_open(&e, "resourceLogs");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "resource");
emit_resource_attributes(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "scopeLogs");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "scope");
- shirudo_json_kv_string(&e, "name", scope_name);
- shirudo_json_kv_string(&e, "version", shirudo_version);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "logRecords");
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "timeUnixNano", now);
- shirudo_json_kv_string(&e, "observedTimeUnixNano", now);
- shirudo_json_kv_int(&e, "severityNumber", severity_number);
- shirudo_json_kv_string(&e, "severityText", severity_text);
- shirudo_json_kv_string(&e, "eventName", event_name);
- shirudo_json_obj_open_key(&e, "body");
+ json_obj_close(&e);
+ json_arr_open(&e, "scopeLogs");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "scope");
+ json_kv_string(&e, "name", scope_name);
+ json_kv_string(&e, "version", shirudo_version);
+ json_obj_close(&e);
+ json_arr_open(&e, "logRecords");
+ json_obj_open(&e);
+ json_kv_string(&e, "timeUnixNano", now);
+ json_kv_string(&e, "observedTimeUnixNano", now);
+ json_kv_int(&e, "severityNumber", severity_number);
+ json_kv_string(&e, "severityText", severity_text);
+ json_kv_string(&e, "eventName", event_name);
+ json_obj_open_key(&e, "body");
rc = json_anyvalue_from_document(&e, body_json, body_len, false);
- shirudo_json_obj_close(&e);
+ json_obj_close(&e);
if (rc) {
xfree(buf, cap);
return rc;
}
- shirudo_json_arr_open(&e, "attributes");
+ json_arr_open(&e, "attributes");
if (status)
otlp_kv_string(&e, "shirudo.status", status);
if (version_id)
otlp_kv_string(&e, "shirudo.version_id", version_id);
if (tamper_attempts >= 0)
otlp_kv_int(&e, "shirudo.tamper_attempts", tamper_attempts);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err) {
xfree(buf, cap);
return e.err;
@@ -1954,15 +1954,15 @@ static int build_generic_log_payload(const char *scope_name,
return 0;
}
-int shirudo_otel_send_log_json(const struct shirudo_otel_opts *opts,
- const char *scope_name,
- const char *event_name,
- int severity_number,
- const char *severity_text,
- const char *status,
- const char *version_id,
- __s64 tamper_attempts,
- const char *body_json, size_t body_len)
+int otel_send_log_json(const struct shirudo_otel_opts *opts,
+ const char *scope_name,
+ const char *event_name,
+ int severity_number,
+ const char *severity_text,
+ const char *status,
+ const char *version_id,
+ __s64 tamper_attempts,
+ const char *body_json, size_t body_len)
{
char *payload = NULL;
void *state = NULL;
@@ -2044,7 +2044,7 @@ static int snapshot_write_compressed(struct snapshot_writer *w,
return -EOVERFLOW;
if (len && fwrite(data, 1, len, w->file) != len)
return -EIO;
- if (len && shirudo_sha256_update(&w->md, data, len) != 0)
+ if (len && sha256_update(&w->md, data, len) != 0)
return -EIO;
w->object_bytes += len;
return 0;
@@ -2056,7 +2056,7 @@ static int snapshot_writer_init(struct snapshot_writer *w, FILE *file)
memset(w, 0, sizeof(*w));
w->file = file;
- if (shirudo_sha256_init(&w->md) != 0)
+ if (sha256_init(&w->md) != 0)
return -EIO;
zr = deflateInit2(&w->z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16,
8, Z_DEFAULT_STRATEGY);
@@ -2075,7 +2075,7 @@ static void snapshot_writer_abort(struct snapshot_writer *w)
{
if (w->deflate_ready)
deflateEnd(&w->z);
- shirudo_sha256_free(&w->md);
+ sha256_free(&w->md);
w->deflate_ready = false;
}
@@ -2134,7 +2134,7 @@ static int snapshot_writer_finish(struct snapshot_writer *w,
if (deflateEnd(&w->z) != Z_OK)
return -EIO;
w->deflate_ready = false;
- if (shirudo_sha256_final(&w->md, snapshot->sha256) != 0)
+ if (sha256_final(&w->md, snapshot->sha256) != 0)
return -EIO;
if (fflush(w->file) != 0 || fseeko(w->file, 0, SEEK_SET) != 0)
return -EIO;
@@ -2143,9 +2143,9 @@ static int snapshot_writer_finish(struct snapshot_writer *w,
for (size_t i = 0; i < sizeof(snapshot->sha256); i++)
snprintf(snapshot->sha256_hex + i * 2, 3, "%02x",
snapshot->sha256[i]);
- if (shirudo_base64_encode(snapshot->sha256, sizeof(snapshot->sha256),
- snapshot->sha256_b64,
- sizeof(snapshot->sha256_b64)) != 0)
+ if (base64_encode(snapshot->sha256, sizeof(snapshot->sha256),
+ snapshot->sha256_b64,
+ sizeof(snapshot->sha256_b64)) != 0)
return -EIO;
snapshot->sha256_b64[44] = '\0';
return 0;
@@ -2163,15 +2163,15 @@ static int build_s3_snapshot(const char *decoder_path,
memset(snapshot, 0, sizeof(*snapshot));
/* S3 stores exactly the canonical value returned by the signed decoder. */
if (decoder_path)
- rc = shirudo_upatch_decode_map_file_json_limit(decoder_path, v,
- S3_DECODER_JSON_MAX_BYTES,
- &decoded,
- &decoded_len);
+ rc = upatch_decode_map_file_json_limit(decoder_path, v,
+ S3_DECODER_JSON_MAX_BYTES,
+ &decoded,
+ &decoded_len);
else
- rc = shirudo_upatch_decode_map_json_limit(v,
- S3_DECODER_JSON_MAX_BYTES,
- &decoded,
- &decoded_len);
+ rc = upatch_decode_map_json_limit(v,
+ S3_DECODER_JSON_MAX_BYTES,
+ &decoded,
+ &decoded_len);
if (rc)
return rc;
rc = snapshot_temp_file(&snapshot->file);
@@ -2558,7 +2558,7 @@ static int s3_put(struct otel_s3_state *st,
st->insecure_tls ? 0L : 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST,
st->insecure_tls ? 0L : 2L);
- if (shirudo_tls_curl_policy(curl, NULL)) {
+ if (tls_curl_policy(curl, NULL)) {
curl_easy_cleanup(curl);
rc = -EINVAL;
break;
@@ -2611,30 +2611,30 @@ static int build_s3_reference(const struct shirudo_map_view *v,
u64_decimal(realtime_ns(), now);
snprintf(description, sizeof(description),
"BPF map snapshot stored in S3: %s", uri);
- shirudo_json_obj_open(&e);
- shirudo_json_arr_open(&e, "resourceLogs");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "resource");
+ json_obj_open(&e);
+ json_arr_open(&e, "resourceLogs");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "resource");
emit_resource_attributes(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "scopeLogs");
- shirudo_json_obj_open(&e);
- shirudo_json_obj_open_key(&e, "scope");
- shirudo_json_kv_string(&e, "name", "shirudo.upatch.maps");
- shirudo_json_kv_string(&e, "version", shirudo_version);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "logRecords");
- shirudo_json_obj_open(&e);
- shirudo_json_kv_string(&e, "timeUnixNano", now);
- shirudo_json_kv_string(&e, "observedTimeUnixNano", now);
- shirudo_json_kv_int(&e, "severityNumber", 9);
- shirudo_json_kv_string(&e, "severityText", "INFO");
- shirudo_json_kv_string(&e, "eventName",
- "shirudo.bpf.map.snapshot.reference");
- shirudo_json_obj_open_key(&e, "body");
- shirudo_json_kv_string(&e, "stringValue", description);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_open(&e, "attributes");
+ json_obj_close(&e);
+ json_arr_open(&e, "scopeLogs");
+ json_obj_open(&e);
+ json_obj_open_key(&e, "scope");
+ json_kv_string(&e, "name", "shirudo.upatch.maps");
+ json_kv_string(&e, "version", shirudo_version);
+ json_obj_close(&e);
+ json_arr_open(&e, "logRecords");
+ json_obj_open(&e);
+ json_kv_string(&e, "timeUnixNano", now);
+ json_kv_string(&e, "observedTimeUnixNano", now);
+ json_kv_int(&e, "severityNumber", 9);
+ json_kv_string(&e, "severityText", "INFO");
+ json_kv_string(&e, "eventName",
+ "shirudo.bpf.map.snapshot.reference");
+ json_obj_open_key(&e, "body");
+ json_kv_string(&e, "stringValue", description);
+ json_obj_close(&e);
+ json_arr_open(&e, "attributes");
otlp_kv_string(&e, "shirudo.upatch.name", v->upatch);
otlp_kv_string(&e, "shirudo.upatch.location", v->location);
otlp_kv_string(&e, "shirudo.map.name", v->name);
@@ -2656,14 +2656,14 @@ static int build_s3_reference(const struct shirudo_map_view *v,
(__s64)snapshot->json_bytes);
otlp_kv_string(&e, "shirudo.map.snapshot.sha256",
snapshot->sha256_hex);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
- shirudo_json_arr_close(&e);
- shirudo_json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ json_arr_close(&e);
+ json_obj_close(&e);
if (e.err || e.depth) {
if (!e.err)
e.err = -EBADMSG;
@@ -2776,10 +2776,10 @@ static int otel_s3_close(void *state)
return 0;
}
-int shirudo_upatch_maps_otel_send_file(const char *decoder_path,
- const struct shirudo_map_view *v,
- enum shirudo_otel_mode mode,
- const struct shirudo_otel_opts *opts)
+int upatch_maps_otel_send_file(const char *decoder_path,
+ const struct shirudo_map_view *v,
+ enum shirudo_otel_mode mode,
+ const struct shirudo_otel_opts *opts)
{
const char *endpoint = opts ? opts->endpoint : NULL;
bool automatic = mode == SHIRUDO_OTEL_AUTO;
@@ -2814,28 +2814,28 @@ int shirudo_upatch_maps_otel_send_file(const char *decoder_path,
return rc ? rc : close_rc;
}
-int shirudo_upatch_maps_otel_send(const struct shirudo_map_view *v,
- enum shirudo_otel_mode mode,
- const struct shirudo_otel_opts *opts)
+int upatch_maps_otel_send(const struct shirudo_map_view *v,
+ enum shirudo_otel_mode mode,
+ const struct shirudo_otel_opts *opts)
{
- return shirudo_upatch_maps_otel_send_file(NULL, v, mode, opts);
+ return upatch_maps_otel_send_file(NULL, v, mode, opts);
}
-int shirudo_upatch_maps_otel_send_decoded(const struct shirudo_map_view *v,
- enum shirudo_otel_signal signal,
- const struct shirudo_otel_opts *opts)
+int upatch_maps_otel_send_decoded(const struct shirudo_map_view *v,
+ enum shirudo_otel_signal signal,
+ const struct shirudo_otel_opts *opts)
{
int rc;
if (signal == SHIRUDO_OTEL_LOG)
- rc = shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_LOG,
- opts);
+ rc = upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_LOG,
+ opts);
else if (signal == SHIRUDO_OTEL_METRIC)
- rc = shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_METRIC,
- opts);
+ rc = upatch_maps_otel_send(v, SHIRUDO_OTEL_FORCE_METRIC,
+ opts);
else
return -EINVAL;
if (rc == -E2BIG && opts && opts->s3_uri)
- return shirudo_upatch_maps_otel_send(v, SHIRUDO_OTEL_S3, opts);
+ return upatch_maps_otel_send(v, SHIRUDO_OTEL_S3, opts);
return rc;
}
diff --git a/util/upatch_maps_otel.h b/util/upatch_maps_otel.h
index 9c2810f9..eab172f1 100644
--- a/util/upatch_maps_otel.h
+++ b/util/upatch_maps_otel.h
@@ -44,42 +44,42 @@ struct shirudo_otel_opts {
const char *metric_description;
};
-int shirudo_upatch_maps_otel_classify(const struct shirudo_map_view *v,
- enum shirudo_otel_signal *signal,
- char *reason, size_t reason_sz);
-int shirudo_upatch_maps_otel_build_log_file(const char *path,
- const struct shirudo_map_view *v,
- char **out, size_t *out_len);
-int shirudo_upatch_maps_otel_build_metric_file(const char *path,
- const struct shirudo_map_view *v,
- const struct shirudo_otel_opts *opts,
- char **out, size_t *out_len);
-int shirudo_upatch_maps_otel_send(const struct shirudo_map_view *v,
- enum shirudo_otel_mode mode,
- const struct shirudo_otel_opts *opts);
-int shirudo_upatch_maps_otel_send_file(const char *path,
+int upatch_maps_otel_classify(const struct shirudo_map_view *v,
+ enum shirudo_otel_signal *signal,
+ char *reason, size_t reason_sz);
+int upatch_maps_otel_build_log_file(const char *path,
+ const struct shirudo_map_view *v,
+ char **out, size_t *out_len);
+int upatch_maps_otel_build_metric_file(const char *path,
const struct shirudo_map_view *v,
- enum shirudo_otel_mode mode,
- const struct shirudo_otel_opts *opts);
+ const struct shirudo_otel_opts *opts,
+ char **out, size_t *out_len);
+int upatch_maps_otel_send(const struct shirudo_map_view *v,
+ enum shirudo_otel_mode mode,
+ const struct shirudo_otel_opts *opts);
+int upatch_maps_otel_send_file(const char *path,
+ const struct shirudo_map_view *v,
+ enum shirudo_otel_mode mode,
+ const struct shirudo_otel_opts *opts);
/* Export using the matching decoder's signed, static signal selection. */
-int shirudo_upatch_maps_otel_send_decoded(const struct shirudo_map_view *v,
- enum shirudo_otel_signal signal,
- const struct shirudo_otel_opts *opts);
+int upatch_maps_otel_send_decoded(const struct shirudo_map_view *v,
+ enum shirudo_otel_signal signal,
+ const struct shirudo_otel_opts *opts);
/*
* Send an already-built JSON object as the structured body of one OTLP
* log. A tamper_attempts of 0 or more rides along as an attribute; a
* negative one leaves it out.
*/
-int shirudo_otel_send_log_json(const struct shirudo_otel_opts *opts,
- const char *scope_name,
- const char *event_name,
- int severity_number,
- const char *severity_text,
- const char *status,
- const char *version_id,
- __s64 tamper_attempts,
- const char *body_json, size_t body_len);
+int otel_send_log_json(const struct shirudo_otel_opts *opts,
+ const char *scope_name,
+ const char *event_name,
+ int severity_number,
+ const char *severity_text,
+ const char *status,
+ const char *version_id,
+ __s64 tamper_attempts,
+ const char *body_json, size_t body_len);
#endif /* SHIRUDO_UTIL_UPATCH_MAPS_OTEL_H */
diff --git a/util/upatch_resolve.c b/util/upatch_resolve.c
index 909e4783..9074db40 100644
--- a/util/upatch_resolve.c
+++ b/util/upatch_resolve.c
@@ -38,13 +38,13 @@
#define NF_IP6_PRI_RAW_BEFORE_DEFRAG (-450)
#endif
-int shirudo_upatch_open_first_link(const char *name)
+int upatch_open_first_link(const char *name)
{
char pin[PATH_MAX];
char bpffs_name[SHIRUDO_UPATCH_BPFFS_NAME_MAX + 1];
int fd, first_errno;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return -ENAMETOOLONG;
if ((size_t)snprintf(pin, sizeof(pin), "%s/%s/link",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >= sizeof(pin))
@@ -88,8 +88,8 @@ static const char *loc_prefix(__u32 prog_type, __u32 attach_type)
return NULL;
}
-int shirudo_upatch_resolve_location(struct btf *vbtf, const char *name,
- char *out, size_t cap)
+int upatch_resolve_location(struct btf *vbtf, const char *name,
+ char *out, size_t cap)
{
struct bpf_link_info linfo = {};
struct bpf_prog_info info = {};
@@ -100,7 +100,7 @@ int shirudo_upatch_resolve_location(struct btf *vbtf, const char *name,
__u32 len;
out[0] = '\0';
- link_fd = shirudo_upatch_open_first_link(name);
+ link_fd = upatch_open_first_link(name);
if (link_fd < 0)
return link_fd;
len = sizeof(linfo);
@@ -189,24 +189,24 @@ int shirudo_upatch_resolve_location(struct btf *vbtf, const char *name,
return 0;
}
-void shirudo_upatch_loaded_at(const char *name, char *out, size_t cap)
+void upatch_loaded_at(const char *name, char *out, size_t cap)
{
char dir[PATH_MAX];
char bpffs_name[SHIRUDO_UPATCH_BPFFS_NAME_MAX + 1];
struct stat st;
out[0] = '\0';
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return;
if ((size_t)snprintf(dir, sizeof(dir), "%s/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >= sizeof(dir))
return;
if (stat(dir, &st) != 0)
return;
- shirudo_iso8601(st.st_ctim.tv_sec, out, cap);
+ iso8601(st.st_ctim.tv_sec, out, cap);
}
-void shirudo_upatch_payload_sha256(const char *name, char *out, size_t cap)
+void upatch_payload_sha256(const char *name, char *out, size_t cap)
{
char dir[PATH_MAX];
char bpffs_name[SHIRUDO_UPATCH_BPFFS_NAME_MAX + 1];
@@ -216,7 +216,7 @@ void shirudo_upatch_payload_sha256(const char *name, char *out, size_t cap)
out[0] = '\0';
if (cap < 65)
return;
- if (shirudo_upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
return;
if ((size_t)snprintf(dir, sizeof(dir), "%s/%s",
SHIRUDO_BPFFS_UPATCHES_DIR, bpffs_name) >= sizeof(dir))
@@ -224,5 +224,5 @@ void shirudo_upatch_payload_sha256(const char *name, char *out, size_t cap)
n = getxattr(dir, SHIRUDO_XATTR_PAYLOAD, raw, sizeof(raw));
if (n != (ssize_t)sizeof(raw))
return;
- shirudo_hex_encode(raw, sizeof(raw), out);
+ hex_encode(raw, sizeof(raw), out);
}
diff --git a/util/upatch_resolve.h b/util/upatch_resolve.h
index 142b15fc..7994176d 100644
--- a/util/upatch_resolve.h
+++ b/util/upatch_resolve.h
@@ -19,15 +19,15 @@ struct btf;
* "link"; multi-program upatches use "link_0", "link_1", ...
* Returns a link fd on success, negative errno on failure.
*/
-int shirudo_upatch_open_first_link(const char *name);
+int upatch_open_first_link(const char *name);
/* vbtf may be NULL; the location then degrades to the bare prefix. */
-int shirudo_upatch_resolve_location(struct btf *vbtf, const char *name,
- char *out, size_t cap);
+int upatch_resolve_location(struct btf *vbtf, const char *name,
+ char *out, size_t cap);
-void shirudo_upatch_loaded_at(const char *name, char *out, size_t cap);
+void upatch_loaded_at(const char *name, char *out, size_t cap);
/* Empty on any failure. */
-void shirudo_upatch_payload_sha256(const char *name, char *out, size_t cap);
+void upatch_payload_sha256(const char *name, char *out, size_t cap);
#endif /* SHIRUDO_UTIL_UPATCH_RESOLVE_H */
diff --git a/util/upatch_table.c b/util/upatch_table.c
index aff7d26c..14a69c6a 100644
--- a/util/upatch_table.c
+++ b/util/upatch_table.c
@@ -15,7 +15,7 @@
#include "timefmt.h"
#include "upatch_table.h"
-__s64 shirudo_upatch_age_sec(const char *ts)
+__s64 upatch_age_sec(const char *ts)
{
struct tm tm = {};
@@ -26,8 +26,8 @@ __s64 shirudo_upatch_age_sec(const char *ts)
return (__s64)(time(NULL) - timegm(&tm));
}
-void shirudo_upatch_table_print(const struct shirudo_upatch_table_row *rows,
- size_t n)
+void upatch_table_print(const struct shirudo_upatch_table_row *rows,
+ size_t n)
{
size_t i;
@@ -41,41 +41,41 @@ void shirudo_upatch_table_print(const struct shirudo_upatch_table_row *rows,
char age[16] = "?";
if (r->age_sec >= 0)
- shirudo_format_duration((long)r->age_sec,
- age, sizeof(age));
+ format_duration((long)r->age_sec,
+ age, sizeof(age));
printf(" %-24s %-28s %5u %-28s %s\n", r->name,
r->location[0] ? r->location : "-",
r->n_maps, r->status[0] ? r->status : "success", age);
}
}
-void shirudo_upatch_table_emit_json(struct shirudo_json_emit *e,
- const struct shirudo_upatch_table_row *rows,
- size_t n)
+void upatch_table_emit_json(struct shirudo_json_emit *e,
+ const struct shirudo_upatch_table_row *rows,
+ size_t n)
{
size_t i;
- shirudo_json_arr_open(e, "upatches_loaded");
+ json_arr_open(e, "upatches_loaded");
for (i = 0; i < n; i++) {
const struct shirudo_upatch_table_row *r = &rows[i];
- shirudo_json_obj_open(e);
- shirudo_json_kv_string(e, "name", r->name);
- shirudo_json_kv_string(e, "location", r->location);
- shirudo_json_kv_string(e, "status",
- r->status[0] ? r->status : "success");
- shirudo_json_kv_int(e, "n_maps", (__s64)r->n_maps);
- shirudo_json_kv_string(e, "loaded_at", r->loaded_at);
+ json_obj_open(e);
+ json_kv_string(e, "name", r->name);
+ json_kv_string(e, "location", r->location);
+ json_kv_string(e, "status",
+ r->status[0] ? r->status : "success");
+ json_kv_int(e, "n_maps", (__s64)r->n_maps);
+ json_kv_string(e, "loaded_at", r->loaded_at);
if (r->age_sec >= 0)
- shirudo_json_kv_int(e, "age_sec", r->age_sec);
+ json_kv_int(e, "age_sec", r->age_sec);
else
- shirudo_json_kv_null(e, "age_sec");
+ json_kv_null(e, "age_sec");
if (r->payload_sha256[0])
- shirudo_json_kv_string(e, "payload_sha256",
- r->payload_sha256);
+ json_kv_string(e, "payload_sha256",
+ r->payload_sha256);
else
- shirudo_json_kv_null(e, "payload_sha256");
- shirudo_json_obj_close(e);
+ json_kv_null(e, "payload_sha256");
+ json_obj_close(e);
}
- shirudo_json_arr_close(e);
+ json_arr_close(e);
}
diff --git a/util/upatch_table.h b/util/upatch_table.h
index 556a0853..b96b525c 100644
--- a/util/upatch_table.h
+++ b/util/upatch_table.h
@@ -26,13 +26,13 @@ struct shirudo_upatch_table_row {
char payload_sha256[65]; /* "" if unavailable; JSON only */
};
-void shirudo_upatch_table_print(const struct shirudo_upatch_table_row *rows,
- size_t n);
+void upatch_table_print(const struct shirudo_upatch_table_row *rows,
+ size_t n);
-void shirudo_upatch_table_emit_json(struct shirudo_json_emit *e,
- const struct shirudo_upatch_table_row *rows,
- size_t n);
+void upatch_table_emit_json(struct shirudo_json_emit *e,
+ const struct shirudo_upatch_table_row *rows,
+ size_t n);
-__s64 shirudo_upatch_age_sec(const char *ts);
+__s64 upatch_age_sec(const char *ts);
#endif /* SHIRUDO_UTIL_UPATCH_TABLE_H */