This crate implements utilities for working with
fs-verity functionality of the Linux kernel.
This allows you to make a file permanently immutable and have the kernel calculate and store a Merkle tree hash for the file that will be instantly retrievable from that point on. The kernel will also refuse to load any part of the file into memory unless it matches the corresponding parts of the Merkle tree, meaning as long as you trust the kernel the fs-verity measurement returned for a file will always match the data you read from that file. This means that even if the filesystem was tampered with while the system was off, the file contents cannot be changed without also changing or removing the verity hash, or causing reads from the file to fail.
TLDR: It allows you to make a file immutable and allows you to instantly get a reliable hash for that file at any time.
You can think of it as a pure Rust replacement for the main parts of
It consists of two parts:
- An implementation of [
sha2::digest::Digest] which can calculate an
fs-veritymeasurement in userland Rust code. This is useful for e.g. servers and build systems which may not want to (or be able to) enable
fs-verityfor files, but still need to know the digest values so they can be used to create e.g. a signed manifest file containing all the digests.
- On Linux systems, two functions which allow you to enable
fs-verityfor a file, and to fetch the digest for the file from the kernel once it's enabled. This uses the
This was mostly produced as a coding exercise. It works and is pretty clean (well, as much
as is possible under the API constraints I set myself) and thoroughly commented, but it is
currently a bit slower than the C implementation because that uses
code for SHA256, and the SHA256 implementation in RustCrypto is not quite as fast.
One neat aspect of this implementation is that it works in a completely streaming manner, accepting any amount of input in chunks of whatever size.
Functions to enable
Calculates an fs-verity measurement over the input data.
Enum of the supported inner hash algorithms.
Currently the kernel requires the
Maximum size of digests, as described in the Linux kernel documentation.
Linux has a hardcoded limit of 8, see
Maximum size of salts, as described in the Linux kernel documentation
For trait objects of