@@ -497,7 +497,7 @@ int fsverity_cmd_sign(char *filename, const struct fsverity_hash_alg *hash_alg,
}
if (block_size == 0)
- block_size = get_default_block_size();
+ block_size = fsverity_get_default_block_size();
if (keyfile == NULL) {
status = -EINVAL;
@@ -18,6 +18,12 @@
#include "fsverity.h"
#include "hash_algs.h"
+struct fsverity_command;
+
+static bool parse_block_size_option(const char *arg, u32 *size_ptr);
+static bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr);
+static void usage(const struct fsverity_command *cmd, FILE *fp);
+
enum {
OPT_HASH_ALG,
OPT_BLOCK_SIZE,
@@ -310,7 +316,7 @@ int wrap_cmd_enable(const struct fsverity_command *cmd,
arg.hash_algorithm = FS_VERITY_HASH_ALG_DEFAULT;
if (arg.block_size == 0)
- arg.block_size = get_default_block_size();
+ arg.block_size = fsverity_get_default_block_size();
status = fsverity_cmd_enable(argv[0], &arg);
@@ -437,7 +443,7 @@ static const struct fsverity_command *find_command(const char *name)
return NULL;
}
-bool parse_block_size_option(const char *arg, u32 *size_ptr)
+static bool parse_block_size_option(const char *arg, u32 *size_ptr)
{
char *end;
unsigned long n = strtoul(arg, &end, 10);
@@ -455,7 +461,7 @@ bool parse_block_size_option(const char *arg, u32 *size_ptr)
return true;
}
-bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr)
+static bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr)
{
if (*salt_ptr != NULL) {
error_msg("--salt can only be specified once");
@@ -470,19 +476,6 @@ bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr)
return true;
}
-u32 get_default_block_size(void)
-{
- long n = sysconf(_SC_PAGESIZE);
-
- if (n <= 0 || n >= INT_MAX || !is_power_of_2(n)) {
- fprintf(stderr,
- "Warning: invalid _SC_PAGESIZE (%ld). Assuming 4K blocks.\n",
- n);
- return 4096;
- }
- return n;
-}
-
int main(int argc, char *argv[])
{
const struct fsverity_command *cmd;
@@ -8,8 +8,6 @@
#include "hash_algs.h"
#include "fsverity_uapi.h"
-struct fsverity_command;
-
/*
* Format in which verity file measurements are signed. This is the same as
* 'struct fsverity_digest', except here some magic bytes are prepended to
@@ -24,7 +22,7 @@ struct fsverity_signed_digest {
};
-void usage(const struct fsverity_command *cmd, FILE *fp);
+u32 fsverity_get_default_block_size(void);
int fsverity_cmd_enable(char *filename, struct fsverity_enable_arg *arg);
int fsverity_cmd_measure(char *filename, struct fsverity_digest *d);
@@ -34,8 +32,4 @@ int fsverity_cmd_sign(char *filename, const struct fsverity_hash_alg *hash_alg,
struct fsverity_signed_digest **retdigest,
u8 **sig, u32 *sig_size);
-bool parse_block_size_option(const char *arg, u32 *size_ptr);
-u32 get_default_block_size(void);
-bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr);
-
#endif /* COMMANDS_H */
@@ -213,3 +213,16 @@ void bin2hex(const u8 *bin, size_t bin_len, char *hex)
}
*hex = '\0';
}
+
+u32 fsverity_get_default_block_size(void)
+{
+ long n = sysconf(_SC_PAGESIZE);
+
+ if (n <= 0 || n >= INT_MAX || !is_power_of_2(n)) {
+ fprintf(stderr,
+ "Warning: invalid _SC_PAGESIZE (%ld). Assuming 4K blocks.\n",
+ n);
+ return 4096;
+ }
+ return n;
+}