@@ -42,7 +42,7 @@ static bool parse_hash_alg_option(const char *arg, u32 *alg_ptr)
return true;
}
error_msg("unknown hash algorithm: '%s'", arg);
- fputs("Available hash algorithms: ", stderr);
+ fputs("Available hash algorithms:", stderr);
show_all_hash_algs(stderr);
putc('\n', stderr);
@@ -22,9 +22,8 @@ int fsverity_cmd_measure(const struct fsverity_command *cmd,
struct fsverity_digest *d = NULL;
struct filedes file;
char digest_hex[FS_VERITY_MAX_DIGEST_SIZE * 2 + 1];
- const struct fsverity_hash_alg *hash_alg;
char _hash_alg_name[32];
- const char *hash_alg_name;
+ char *hash_alg_name;
int status;
int i;
@@ -48,14 +47,14 @@ int fsverity_cmd_measure(const struct fsverity_command *cmd,
ASSERT(d->digest_size <= FS_VERITY_MAX_DIGEST_SIZE);
bin2hex(d->digest, d->digest_size, digest_hex);
- hash_alg = libfsverity_find_hash_alg_by_num(d->digest_algorithm);
- if (hash_alg) {
- hash_alg_name = hash_alg->name;
- } else {
+ hash_alg_name = libfsverity_hash_name(d->digest_algorithm);
+ if (!hash_alg_name)
sprintf(_hash_alg_name, "ALG_%u", d->digest_algorithm);
- hash_alg_name = _hash_alg_name;
- }
- printf("%s:%s %s\n", hash_alg_name, digest_hex, argv[i]);
+
+ printf("%s:%s %s\n",
+ hash_alg_name ? hash_alg_name :_hash_alg_name,
+ digest_hex, argv[i]);
+ free(hash_alg_name);
}
status = 0;
out:
@@ -87,7 +87,7 @@ int fsverity_cmd_sign(const struct fsverity_command *cmd,
if (!alg_nr) {
error_msg("unknown hash algorithm: '%s'",
optarg);
- fputs("Available hash algorithms: ", stderr);
+ fputs("Available hash algorithms:", stderr);
show_all_hash_algs(stderr);
putc('\n', stderr);
goto out_usage;
@@ -51,14 +51,12 @@ static const struct fsverity_command {
void show_all_hash_algs(FILE *fp)
{
int i = 1;
- const char *sep = "";
- const struct fsverity_hash_alg *alg;
-
- while ((alg = libfsverity_find_hash_alg_by_num(i++))) {
- if (alg && alg->name) {
- fprintf(fp, "%s%s", sep, alg->name);
- sep = ", ";
- }
+ const char *sep = " ";
+ char *alg;
+
+ while ((alg = libfsverity_hash_name(i++))) {
+ fprintf(fp, "%s%s", sep, alg);
+ free(alg);
}
}
@@ -75,7 +73,7 @@ static void usage_all(FILE *fp)
" fsverity --help\n"
" fsverity --version\n"
"\n"
-"Available hash algorithms: ", fp);
+"Available hash algorithms:", fp);
show_all_hash_algs(fp);
putc('\n', fp);
}
@@ -15,6 +15,7 @@
#include "helpers.h"
#include "fsverity_uapi.h"
#include "libfsverity.h"
+#include "libfsverity_private.h"
#include "hash_algs.h"
/* ========== libcrypto (OpenSSL) wrappers ========== */
@@ -56,14 +56,6 @@ struct libfsverity_signature_params {
uint64_t reserved[11];
};
-struct fsverity_hash_alg {
- const char *name;
- int digest_size;
- unsigned int block_size;
- uint16_t hash_num;
- struct hash_ctx *(*create_ctx)(const struct fsverity_hash_alg *alg);
-};
-
/*
* libfsverity_compute_digest - Compute digest of a file
* @fd: open file descriptor of file to compute digest for
@@ -112,17 +104,6 @@ libfsverity_sign_digest(const struct libfsverity_digest *digest,
*/
uint16_t libfsverity_find_hash_alg_by_name(const char *name);
-/*
- * libfsverity_find_hash_alg_by_num - Find hash algorithm by number
- * @name: Number of hash algorithm
- *
- * Returns:
- * struct fsverity_hash_alg success
- * NULL on error
- */
-const struct fsverity_hash_alg *
-libfsverity_find_hash_alg_by_num(unsigned int num);
-
/*
* libfsverity_digest_size - Return size of digest for a given algorithm
* @alg_nr: Valid hash algorithm number
@@ -30,4 +30,23 @@ struct fsverity_descriptor {
uint8_t signature[]; /* optional PKCS#7 signature */
};
+struct fsverity_hash_alg {
+ const char *name;
+ int digest_size;
+ unsigned int block_size;
+ uint16_t hash_num;
+ struct hash_ctx *(*create_ctx)(const struct fsverity_hash_alg *alg);
+};
+
+/*
+ * libfsverity_find_hash_alg_by_num - Find hash algorithm by number
+ * @name: Number of hash algorithm
+ *
+ * Returns:
+ * struct fsverity_hash_alg success
+ * NULL on error
+ */
+const struct fsverity_hash_alg *
+libfsverity_find_hash_alg_by_num(unsigned int num);
+
#endif