Skip to content

eBPF-based security platform

treewide: name the functions that kept the shirudo_ prefix

Daniel Borkmann825746011093
diff --git a/builtin-attest.c b/builtin-attest.c
index dd7d2b22..adb902e9 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -247,7 +247,7 @@ static int cert_digest(const char *path, __u8 out[32])
}
got = read(fd, buf, (size_t)st.st_size);
close(fd);
- if (got == st.st_size && shirudo_sha256(buf, (size_t)got, out))
+ if (got == st.st_size && sha256_calc(buf, (size_t)got, out))
got = -1;
xfree(buf, (size_t)st.st_size);
return got == st.st_size ? 0 : -EIO;
@@ -419,7 +419,7 @@ static int cmd_attest_predict(int argc, const char **argv)
goto out;
}
printf("anchor: %s\n", anchor);
- if (shirudo_sha256(anchor, strlen(anchor), anchor_digest)) {
+ if (sha256_calc(anchor, strlen(anchor), anchor_digest)) {
pr_err("attest predict: cannot hash the anchor");
goto out;
}
diff --git a/builtin-bpm.c b/builtin-bpm.c
index 93abd509..f3ece4cc 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -1595,7 +1595,7 @@ static int tree_fetch_publication(const struct bpm_tree_config *cfg,
if (ret)
return ret;
return bpm_tree_fetch_publication(&c, repository, cfg->reference,
- shirudo_cert_path(), pub,
+ get_cert_path(), pub,
manifest_digest, digest_sz);
}
diff --git a/builtin-init.c b/builtin-init.c
index 6dfde2a6..cfb355e0 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -1006,7 +1006,7 @@ static int boot_restore(bool recorded,
ret = -EPERM;
goto next;
}
- if (shirudo_upatch_apply(path) != 0) {
+ if (upatch_apply(path) != 0) {
pr_err("boot-restore: failed to apply %s",
names[i]->d_name);
ret = -EINVAL;
diff --git a/builtin-status.c b/builtin-status.c
index 48a69e14..dd004222 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -152,7 +152,7 @@ static void gather_assets(struct asset_view *a)
struct stat st;
*a = (struct asset_view){};
- a->cert = access(shirudo_cert_path(), F_OK) == 0;
+ a->cert = access(get_cert_path(), F_OK) == 0;
a->signing_key = access(SIGNING_KEY_PATH, F_OK) == 0;
if (stat(eventlog_path(), &st) == 0) {
a->eventlog = true;
@@ -1003,7 +1003,7 @@ int cmd_status(int argc, const char **argv)
keyring_view_dm_verity(&dmv, &ident);
mode = lsm_attached ? "production" : "inactive";
is_operator = access(SIGNING_KEY_PATH, F_OK) == 0;
- cert_present = access(shirudo_cert_path(), F_OK) == 0;
+ cert_present = access(get_cert_path(), F_OK) == 0;
is_target = cert_present || lsm_attached || keyring_present;
n_ups = scandir(BPFFS_UPATCHES_DIR, &ups, notdot, alphasort);
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 4e1f7525..2dee6e42 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1666,8 +1666,8 @@ static void close_loader_fds(const struct shirudo_loader_ctx *cx,
}
/* Shared by `upatch load` and boot restore: one signature-verified path. */
-static int upatch_apply(const char *path, bool verify_only,
- struct shirudo_op_report *rep)
+static int __upatch_apply(const char *path, bool verify_only,
+ struct shirudo_op_report *rep)
{
struct shirudo_upatch u;
struct shirudo_prog_spec *prog_specs = NULL;
@@ -1860,8 +1860,8 @@ static int upatch_apply(const char *path, bool verify_only,
{
__u8 loader_digest[UPATCH_PAYLOAD_HASH_LEN];
- if (shirudo_sha256(insns, u.hdr.loader_insns_len,
- loader_digest)) {
+ if (sha256_calc(insns, u.hdr.loader_insns_len,
+ loader_digest)) {
pr_err("__loader.map: cannot hash the loader");
rep_fail(rep, "signed_loader_load", "unknown", EIO,
"loader digest failed");
@@ -2056,9 +2056,9 @@ out:
return ret;
}
-int shirudo_upatch_apply(const char *path)
+int upatch_apply(const char *path)
{
- return upatch_apply(path, false, NULL);
+ return __upatch_apply(path, false, NULL);
}
/*
@@ -2705,7 +2705,7 @@ static int cmd_upatch_load(int argc, const char **argv)
goto done;
}
- if (upatch_apply(file, false, &rep) != 0)
+ if (__upatch_apply(file, false, &rep) != 0)
goto done;
if (!have_id) { /* loaded but couldn't read identity */
ret = 0;
@@ -2864,7 +2864,7 @@ static int cmd_upatch_unload(int argc, const char **argv)
goto done;
/* A bad signature fails here, before anything is removed. */
- if (upatch_apply(file, true, &rep) != 0) {
+ if (__upatch_apply(file, true, &rep) != 0) {
pr_err("upatch unload: signature verification failed; refusing");
goto done;
}
diff --git a/testing/fuzz/chain.c b/testing/fuzz/chain.c
index 6a5a8a0b..47ee4648 100644
--- a/testing/fuzz/chain.c
+++ b/testing/fuzz/chain.c
@@ -10,8 +10,8 @@
#include "chain.h"
#include "crypto.h"
-int shirudo_sha256(const void *data, size_t len,
- __u8 out[CHAIN_DIGEST_LEN])
+int sha256_calc(const void *data, size_t len,
+ __u8 out[CHAIN_DIGEST_LEN])
{
return sha256_buffer(data, len, out);
}
diff --git a/testing/helper/test-register.c b/testing/helper/test-register.c
index 952d0502..f1e2c041 100644
--- a/testing/helper/test-register.c
+++ b/testing/helper/test-register.c
@@ -465,7 +465,7 @@ int main(int argc, char **argv)
if (!ret)
ret = chain_anchor(nv.name, anchor, sizeof(anchor));
if (!ret) {
- shirudo_sha256(anchor, strlen(anchor), anchor_digest);
+ sha256_calc(anchor, strlen(anchor), anchor_digest);
ret = tpm_pcr_extend(tpm, pcr, anchor_digest);
}
if (!ret)
diff --git a/testing/unit/chain.c b/testing/unit/chain.c
index c59dc130..087b6c88 100644
--- a/testing/unit/chain.c
+++ b/testing/unit/chain.c
@@ -12,7 +12,7 @@ static void sha256_matches_fips_180_vector(void)
char hex[2 * 32 + 1];
__u8 d[32];
- ASSERT_EQ(shirudo_sha256("abc", 3, d), 0);
+ ASSERT_EQ(sha256_calc("abc", 3, d), 0);
hex_encode(d, sizeof(d), hex);
EXPECT_STREQ(hex, want);
}
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index 9af73c42..42801bac 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -662,14 +662,14 @@ static int cmd_bpm_tree_append(int argc, char **argv)
const char *keys_dir = keys_dir_resolve(keys_dir_arg);
if (!key) {
- if (shirudo_key_path(key_path, sizeof(key_path), keys_dir,
- SIGNING_KEY_FILE))
+ if (format_key_path(key_path, sizeof(key_path), keys_dir,
+ SIGNING_KEY_FILE))
return -EINVAL;
key = key_path;
}
if (!cert) {
- if (shirudo_key_path(cert_path, sizeof(cert_path), keys_dir,
- CERT_FILE))
+ if (format_key_path(cert_path, sizeof(cert_path), keys_dir,
+ CERT_FILE))
return -EINVAL;
cert = cert_path;
}
@@ -895,11 +895,11 @@ int build_bpm_push(int argc, char **argv)
}
if (keys_dir_arg) {
if ((!index_cert &&
- shirudo_key_path(cert_path, sizeof(cert_path),
- keys_dir_arg, CERT_FILE)) ||
+ format_key_path(cert_path, sizeof(cert_path),
+ keys_dir_arg, CERT_FILE)) ||
(!index_key &&
- shirudo_key_path(key_path, sizeof(key_path),
- keys_dir_arg, SIGNING_KEY_FILE)))
+ format_key_path(key_path, sizeof(key_path),
+ keys_dir_arg, SIGNING_KEY_FILE)))
return publish_fail("push", -EINVAL);
if (!index_cert)
index_cert = cert_path;
diff --git a/tools/shirudo-build/image.c b/tools/shirudo-build/image.c
index d35ecab3..4b1b6482 100644
--- a/tools/shirudo-build/image.c
+++ b/tools/shirudo-build/image.c
@@ -40,7 +40,7 @@ static void image_usage(FILE *fp)
"Build and offline verification require veritysetup.\n");
}
-static int build_image(int argc, char **argv)
+static int __build_image(int argc, char **argv)
{
char executable[PATH_MAX], script[PATH_MAX], directory[PATH_MAX];
char **command;
@@ -236,7 +236,7 @@ static int sign_root(const char *input, const char *output, const char *pkey,
return ret;
}
-int shirudo_build_image(int argc, char **argv)
+int build_image(int argc, char **argv)
{
bool explicit_key = false, explicit_cert = false;
char pkey_path[PATH_MAX], cert_path[PATH_MAX];
@@ -247,7 +247,7 @@ int shirudo_build_image(int argc, char **argv)
int i, ret;
if (argc >= 2 && !strcmp(argv[1], "build"))
- return build_image(argc, argv);
+ return __build_image(argc, argv);
if (argc == 2 && !strcmp(argv[1], "--help")) {
image_usage(stdout);
return 0;
diff --git a/tools/shirudo-build/image.h b/tools/shirudo-build/image.h
index 41f3b8fa..dca4f564 100644
--- a/tools/shirudo-build/image.h
+++ b/tools/shirudo-build/image.h
@@ -4,6 +4,6 @@
#ifndef SHIRUDO_BUILD_IMAGE_H
#define SHIRUDO_BUILD_IMAGE_H
-int shirudo_build_image(int argc, char **argv);
+int build_image(int argc, char **argv);
#endif /* SHIRUDO_BUILD_IMAGE_H */
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index c7d51218..b530079d 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -519,15 +519,15 @@ int build_upatch_cli(int argc, char **argv)
keys_dir = keys_dir_resolve(keys_dir);
if (keys_dir) {
if (!pkey_explicit) {
- ret = shirudo_key_path(pkey_buf, sizeof(pkey_buf), keys_dir,
- SIGNING_KEY_FILE);
+ ret = format_key_path(pkey_buf, sizeof(pkey_buf), keys_dir,
+ SIGNING_KEY_FILE);
if (ret)
return 2;
pkey = pkey_buf;
}
if (!cert_explicit) {
- ret = shirudo_key_path(cert_buf, sizeof(cert_buf), keys_dir,
- CERT_FILE);
+ ret = format_key_path(cert_buf, sizeof(cert_buf), keys_dir,
+ CERT_FILE);
if (ret)
return 2;
cert = cert_buf;
diff --git a/tools/shirudo-build/shirudo-build.c b/tools/shirudo-build/shirudo-build.c
index a50d9134..2c83bc8a 100644
--- a/tools/shirudo-build/shirudo-build.c
+++ b/tools/shirudo-build/shirudo-build.c
@@ -212,7 +212,7 @@ int main(int argc, char **argv)
return 1;
if (argc >= 2 && strcmp(argv[1], "image") == 0)
- return shirudo_build_image(argc - 1, argv + 1);
+ return build_image(argc - 1, argv + 1);
if (argc >= 2 && strcmp(argv[1], "upatch") == 0)
return build_upatch_cli(argc - 1, argv + 1);
if (argc >= 2 && strcmp(argv[1], "bpm") == 0)
@@ -267,9 +267,9 @@ int main(int argc, char **argv)
if (keys_dir) {
if (!pkey_explicit) {
- ret = shirudo_key_path(pkey_path, sizeof(pkey_path),
- keys_dir,
- SIGNING_KEY_FILE);
+ ret = format_key_path(pkey_path, sizeof(pkey_path),
+ keys_dir,
+ SIGNING_KEY_FILE);
if (ret) {
pr_err("invalid keys dir %s: %s",
keys_dir, strerror(-ret));
@@ -278,8 +278,8 @@ int main(int argc, char **argv)
pkey = pkey_path;
}
if (!cert_explicit) {
- ret = shirudo_key_path(cert_path, sizeof(cert_path),
- keys_dir, CERT_FILE);
+ ret = format_key_path(cert_path, sizeof(cert_path),
+ keys_dir, CERT_FILE);
if (ret) {
pr_err("invalid keys dir %s: %s",
keys_dir, strerror(-ret));
diff --git a/tools/shirudo-build/vouch.c b/tools/shirudo-build/vouch.c
index 7b9f4b42..60e69cdb 100644
--- a/tools/shirudo-build/vouch.c
+++ b/tools/shirudo-build/vouch.c
@@ -129,17 +129,17 @@ int build_keys_vouch(int argc, char **argv)
keys_dir = keys_dir_resolve(keys_dir_arg);
if (keys_dir) {
if (!pkey_explicit) {
- if (shirudo_key_path(pkey_path, sizeof(pkey_path),
- keys_dir,
- SIGNING_KEY_FILE)) {
+ if (format_key_path(pkey_path, sizeof(pkey_path),
+ keys_dir,
+ SIGNING_KEY_FILE)) {
pr_err("invalid keys dir %s", keys_dir);
return 2;
}
pkey = pkey_path;
}
if (!cert_explicit) {
- if (shirudo_key_path(cert_path, sizeof(cert_path),
- keys_dir, CERT_FILE)) {
+ if (format_key_path(cert_path, sizeof(cert_path),
+ keys_dir, CERT_FILE)) {
pr_err("invalid keys dir %s", keys_dir);
return 2;
}
diff --git a/util/attest.c b/util/attest.c
index b8bc485d..c1a9cf14 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -698,7 +698,7 @@ static int check_signed(struct reporter *rep, const char *what,
say(rep, false, "%s: signature structure unparseable", what);
return -EKEYREJECTED;
}
- shirudo_sha256(attest, *attest_len, digest);
+ sha256_calc(attest, *attest_len, digest);
ret = ecdsa_p256_verify(ak->x, ak->y, digest, r, s);
say(rep, ret == 0, "%s: ECDSA signature by the attestation key", what);
tpm_qualified_name(TPM_RH_ENDORSEMENT, ak_name, qn);
@@ -1176,7 +1176,7 @@ int attest_verify(const char *evidence, size_t len,
bool named = !chain_anchor(p->init.name, anchor,
sizeof(anchor));
- shirudo_sha256(anchor, strlen(anchor), anchor_digest);
+ sha256_calc(anchor, strlen(anchor), anchor_digest);
say(&rep, named && ct_eq(anchor_digest, p->init.anchor_digest,
32),
"anchor: record digest matches the index name");
diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.c
index 383eec57..eaace7a6 100644
--- a/util/bpm_tree_state.c
+++ b/util/bpm_tree_state.c
@@ -668,7 +668,7 @@ int tree_event_replay(__u8 out[32])
}
memcpy(next, chain, 32);
memcpy(next + 32, d, 32);
- ret = shirudo_sha256(next, sizeof(next), chain);
+ ret = sha256_calc(next, sizeof(next), chain);
if (ret)
break;
if (!ct_eq(chain, recorded, 32)) {
diff --git a/util/chain.c b/util/chain.c
index c459851a..37200c37 100644
--- a/util/chain.c
+++ b/util/chain.c
@@ -29,7 +29,7 @@
#include "paths.h"
#include "tpm.h"
-int shirudo_sha256(const void *data, size_t len, __u8 out[32])
+int sha256_calc(const void *data, size_t len, __u8 out[32])
{
int ret = sha256_buffer(data, len, out);
@@ -103,7 +103,7 @@ int chain_init_event(const __u8 cert_sha[32],
}
off += (size_t)w;
}
- ret = shirudo_sha256(listing, listing_len, set_digest);
+ ret = sha256_calc(listing, listing_len, set_digest);
xfree(listing, listing_len + 1);
if (ret)
return ret;
@@ -112,7 +112,7 @@ int chain_init_event(const __u8 cert_sha[32],
memcpy(tag + taglen, cert_sha, 32);
memcpy(tag + taglen + 32, set_digest, 32);
memcpy(tag + taglen + 64, tree_root, 32);
- return shirudo_sha256(tag, taglen + 96, event);
+ return sha256_calc(tag, taglen + 96, event);
}
int chain_upatch_event(const char *tag, const char *name,
@@ -128,7 +128,7 @@ int chain_upatch_event(const char *tag, const char *name,
off += 32;
memcpy(buf + off, name, namelen);
off += namelen;
- return shirudo_sha256(buf, off, event);
+ return sha256_calc(buf, off, event);
}
void chain_key_event(const char *tag, const __u8 cert_sha[32],
@@ -148,7 +148,7 @@ void chain_tree_event(__s64 seq, const __u8 operation_digest[32],
for (i = 0; i < 8; i++)
buf[taglen + i] = (__u8)(s >> (56 - 8 * i));
memcpy(buf + taglen + 8, operation_digest, 32);
- shirudo_sha256(buf, taglen + 40, event);
+ sha256_calc(buf, taglen + 40, event);
}
int chain_fold_checked(__u8 chain[32], const __u8 event[32])
@@ -428,8 +428,8 @@ int chain_init(const __u8 event[32],
goto out;
memcpy(info->name, written, sizeof(written));
info->name_len = sizeof(written);
- ret = shirudo_sha256(info->anchor, strlen(info->anchor),
- info->anchor_digest);
+ ret = sha256_calc(info->anchor, strlen(info->anchor),
+ info->anchor_digest);
if (ret)
goto out;
ret = tpm_pcr_extend(tpm, CHAIN_PCR,
diff --git a/util/chain.h b/util/chain.h
index fb661758..3e62abda 100644
--- a/util/chain.h
+++ b/util/chain.h
@@ -34,8 +34,8 @@
(1u << CHAIN_PHASE_PCR))
#define CHAIN_ANCHOR_MAX 128
-int shirudo_sha256(const void *data, size_t len,
- __u8 out[CHAIN_DIGEST_LEN]);
+int sha256_calc(const void *data, size_t len,
+ __u8 out[CHAIN_DIGEST_LEN]);
void sha256_2(const void *a, size_t a_len,
const void *b, size_t b_len,
diff --git a/util/eventlog.c b/util/eventlog.c
index f8a4a0a7..2d1431df 100644
--- a/util/eventlog.c
+++ b/util/eventlog.c
@@ -371,7 +371,7 @@ static int replay_line(const char *line, size_t len, bool is_init, void *ctx)
memset(chain, 0, 32);
memcpy(cat, chain, 32);
memcpy(cat + 32, digest, 32);
- shirudo_sha256(cat, sizeof(cat), chain);
+ sha256_calc(cat, sizeof(cat), chain);
return 0;
}
diff --git a/util/initrd.c b/util/initrd.c
index b9878f32..19f62514 100644
--- a/util/initrd.c
+++ b/util/initrd.c
@@ -28,7 +28,7 @@ const char *sysroot(void)
return env && *env ? env : "/sysroot";
}
-const char *shirudo_keys_dir(void)
+const char *get_keys_dir(void)
{
if (image_config_root_fd() >= 0)
return RUNTIME_DIR "/keys";
@@ -36,7 +36,7 @@ const char *shirudo_keys_dir(void)
KEYS_DIR;
}
-const char *shirudo_cert_path(void)
+const char *get_cert_path(void)
{
if (image_config_root_fd() >= 0)
return RUNTIME_CERT_PATH;
diff --git a/util/initrd.h b/util/initrd.h
index e41b6149..4fb26282 100644
--- a/util/initrd.h
+++ b/util/initrd.h
@@ -23,7 +23,7 @@ const char *sysroot(void);
* initrd runs, the state tree's otherwise. cert.der is the primary
* certificate in that directory.
*/
-const char *shirudo_keys_dir(void);
-const char *shirudo_cert_path(void);
+const char *get_keys_dir(void);
+const char *get_cert_path(void);
#endif /* SHIRUDO_UTIL_INITRD_H */
diff --git a/util/paths.c b/util/paths.c
index 8266e847..583bbab2 100644
--- a/util/paths.c
+++ b/util/paths.c
@@ -27,8 +27,8 @@ const char *keys_dir_resolve(const char *keys_dir_arg)
return KEYS_DIR;
}
-int shirudo_key_path(char *out, size_t out_sz,
- const char *keys_dir, const char *file)
+int format_key_path(char *out, size_t out_sz,
+ const char *keys_dir, const char *file)
{
const char *dir = keys_dir ? keys_dir : KEYS_DIR;
const char *sep;
@@ -48,12 +48,12 @@ int key_paths(const char *keys_dir,
{
int ret;
- ret = shirudo_key_path(pkey_path, pkey_sz, keys_dir,
- SIGNING_KEY_FILE);
+ ret = format_key_path(pkey_path, pkey_sz, keys_dir,
+ SIGNING_KEY_FILE);
if (ret)
return ret;
- return shirudo_key_path(cert_path, cert_sz, keys_dir,
- CERT_FILE);
+ return format_key_path(cert_path, cert_sz, keys_dir,
+ CERT_FILE);
}
bool path_exists(const char *path)
diff --git a/util/paths.h b/util/paths.h
index 951b5733..6344fce5 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -135,8 +135,8 @@
/* Site config. */
#define CONF_PATH "/etc/shirudo/shirudo.conf"
-int shirudo_key_path(char *out, size_t out_sz,
- const char *keys_dir, const char *file);
+int format_key_path(char *out, size_t out_sz,
+ const char *keys_dir, const char *file);
int key_paths(const char *keys_dir,
char *pkey_path, size_t pkey_sz,
char *cert_path, size_t cert_sz);
diff --git a/util/preflight.c b/util/preflight.c
index 1acd7f90..64bce129 100644
--- a/util/preflight.c
+++ b/util/preflight.c
@@ -179,13 +179,13 @@ static void check_cert(struct shirudo_preflight_result *r)
next_slot(r, SHIRUDO_PRE_CERT_ON_DISK, "cert_on_disk");
struct stat st;
- if (stat(shirudo_cert_path(), &st) == 0 &&
+ if (stat(get_cert_path(), &st) == 0 &&
S_ISREG(st.st_mode) && st.st_size > 0)
pass(c);
else
fail(r, c,
"%s missing or empty (copy the operator's cert)",
- shirudo_cert_path());
+ get_cert_path());
}
/*
@@ -200,7 +200,7 @@ static void check_cert(struct shirudo_preflight_result *r)
*/
static int preflight_keys(struct shirudo_trusted_set *set)
{
- return keys_load(shirudo_keys_dir(), KEYS_REVOKED_DIR,
+ return keys_load(get_keys_dir(), KEYS_REVOKED_DIR,
true, set);
}
diff --git a/util/upatch.h b/util/upatch.h
index 558f9cb7..88d80a4b 100644
--- a/util/upatch.h
+++ b/util/upatch.h
@@ -145,7 +145,7 @@ void prog_specs_free(struct shirudo_prog_spec *specs, __u32 nr_progs);
* The target's upatch lifecycle, which builtin-upatch.c implements for
* init, bpm and keys: load, install, unload.
*/
-int shirudo_upatch_apply(const char *path);
+int upatch_apply(const char *path);
int upatch_install(const char *path);
int upatch_remove(const char *path);