linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jes Sorensen <jes.sorensen@gmail.com>
To: linux-fscrypt@vger.kernel.org
Cc: kernel-team@fb.com, ebiggers@kernel.org, Jes Sorensen <jsorensen@fb.com>
Subject: [PATCH 3/9] Move fsverity_descriptor definition to libfsverity.h
Date: Thu, 12 Mar 2020 17:47:52 -0400	[thread overview]
Message-ID: <20200312214758.343212-4-Jes.Sorensen@gmail.com> (raw)
In-Reply-To: <20200312214758.343212-1-Jes.Sorensen@gmail.com>

From: Jes Sorensen <jsorensen@fb.com>

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
---
 cmd_sign.c    | 19 +------------------
 libfsverity.h | 26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/cmd_sign.c b/cmd_sign.c
index dcc44f8..1792084 100644
--- a/cmd_sign.c
+++ b/cmd_sign.c
@@ -20,26 +20,9 @@
 #include <unistd.h>
 
 #include "commands.h"
-#include "fsverity_uapi.h"
+#include "libfsverity.h"
 #include "hash_algs.h"
 
-/*
- * Merkle tree properties.  The file measurement is the hash of this structure
- * excluding the signature and with the sig_size field set to 0.
- */
-struct fsverity_descriptor {
-	__u8 version;		/* must be 1 */
-	__u8 hash_algorithm;	/* Merkle tree hash algorithm */
-	__u8 log_blocksize;	/* log2 of size of data and tree blocks */
-	__u8 salt_size;		/* size of salt in bytes; 0 if none */
-	__le32 sig_size;	/* size of signature in bytes; 0 if none */
-	__le64 data_size;	/* size of file the Merkle tree is built over */
-	__u8 root_hash[64];	/* Merkle tree root hash */
-	__u8 salt[32];		/* salt prepended to each hashed block */
-	__u8 __reserved[144];	/* must be 0's */
-	__u8 signature[];	/* optional PKCS#7 signature */
-};
-
 /*
  * Format in which verity file measurements are signed.  This is the same as
  * 'struct fsverity_digest', except here some magic bytes are prepended to
diff --git a/libfsverity.h b/libfsverity.h
index ceebae1..396a6ee 100644
--- a/libfsverity.h
+++ b/libfsverity.h
@@ -13,13 +13,14 @@
 
 #include <stddef.h>
 #include <stdint.h>
+#include <linux/types.h>
 
 #define FS_VERITY_HASH_ALG_SHA256       1
 #define FS_VERITY_HASH_ALG_SHA512       2
 
 struct libfsverity_merkle_tree_params {
 	uint16_t version;
-	uint16_t hash_algorithm;
+	uint16_t hash_algorithm;	/* Matches the digest_algorithm type */
 	uint32_t block_size;
 	uint32_t salt_size;
 	const uint8_t *salt;
@@ -27,6 +28,7 @@ struct libfsverity_merkle_tree_params {
 };
 
 struct libfsverity_digest {
+	char magic[8];			/* must be "FSVerity" */
 	uint16_t digest_algorithm;
 	uint16_t digest_size;
 	uint8_t digest[];
@@ -38,4 +40,26 @@ struct libfsverity_signature_params {
 	uint64_t reserved[11];
 };
 
+/*
+ * Merkle tree properties.  The file measurement is the hash of this structure
+ * excluding the signature and with the sig_size field set to 0.
+ */
+struct fsverity_descriptor {
+	uint8_t version;	/* must be 1 */
+	uint8_t hash_algorithm;	/* Merkle tree hash algorithm */
+	uint8_t log_blocksize;	/* log2 of size of data and tree blocks */
+	uint8_t salt_size;	/* size of salt in bytes; 0 if none */
+	__le32 sig_size;	/* size of signature in bytes; 0 if none */
+	__le64 data_size;	/* size of file the Merkle tree is built over */
+	uint8_t root_hash[64];	/* Merkle tree root hash */
+	uint8_t salt[32];	/* salt prepended to each hashed block */
+	uint8_t __reserved[144];/* must be 0's */
+	uint8_t signature[];	/* optional PKCS#7 signature */
+};
+
+int
+libfsverity_compute_digest(int fd,
+			   const struct libfsverity_merkle_tree_params *params,
+			   struct libfsverity_digest **digest_ret);
+
 #endif
-- 
2.24.1


  parent reply	other threads:[~2020-03-12 21:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 21:47 [PATCH v3 0/9] Split fsverity-utils into a shared library Jes Sorensen
2020-03-12 21:47 ` [PATCH 1/9] Build basic shared library framework Jes Sorensen
2020-03-22  5:23   ` Eric Biggers
2020-03-22  5:33   ` Eric Biggers
2020-04-21 21:00     ` Jes Sorensen
2020-03-12 21:47 ` [PATCH 2/9] Change compute_file_measurement() to take a file descriptor as argument Jes Sorensen
2020-03-12 21:47 ` Jes Sorensen [this message]
2020-03-22  4:57   ` [PATCH 3/9] Move fsverity_descriptor definition to libfsverity.h Eric Biggers
2020-04-21 16:07     ` Jes Sorensen
2020-04-21 16:16       ` Eric Biggers
2020-04-21 16:20         ` Jes Sorensen
2020-03-12 21:47 ` [PATCH 4/9] Move hash algorithm code to shared library Jes Sorensen
2020-03-22  5:38   ` Eric Biggers
2020-04-22 17:57     ` Jes Sorensen
2020-03-12 21:47 ` [PATCH 5/9] Create libfsverity_compute_digest() and adapt cmd_sign to use it Jes Sorensen
2020-03-22  5:40   ` Eric Biggers
2020-03-12 21:47 ` [PATCH 6/9] Introduce libfsverity_sign_digest() Jes Sorensen
2020-03-12 21:47 ` [PATCH 7/9] Validate input arguments to libfsverity_compute_digest() Jes Sorensen
2020-03-12 21:47 ` [PATCH 8/9] Validate input parameters for libfsverity_sign_digest() Jes Sorensen
2020-03-22  5:27   ` Eric Biggers
2020-03-12 21:47 ` [PATCH 9/9] Document API of libfsverity Jes Sorensen
2020-03-22  5:54   ` Eric Biggers
2020-03-22  5:05 ` [PATCH v3 0/9] Split fsverity-utils into a shared library Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200312214758.343212-4-Jes.Sorensen@gmail.com \
    --to=jes.sorensen@gmail.com \
    --cc=ebiggers@kernel.org \
    --cc=jsorensen@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-fscrypt@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).