|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
FNV-1a 64 content hashing over an injected portable filesystem. More...
Go to the source code of this file.
Enumerations | |
| enum | mdl_hash_bound_t : uint64_t { k_hash_max_read_calls = 2000001ULL } |
| Exact regular-file bound accepted by mdl_hash_file. More... | |
Functions | |
| uint64_t | mdl_hash_bytes_seed (const void *data, size_t len, uint64_t seed) |
| Continue an FNV-1a 64 fold over a byte range from a running state. | |
| uint64_t | mdl_hash_bytes (const void *data, size_t len) |
| FNV-1a 64 hash of a byte range. | |
| uint64_t | mdl_hash_str (const char *s) |
| FNV-1a 64 hash of a NUL-terminated string (excluding the NUL). | |
| ra8_err_t | mdl_hash_stream (fw_fs_file_t *file, uint64_t file_size, uint8_t *buffer, uint32_t buffer_bytes, uint64_t *out) |
| Fold an exact regular-file extent into a running FNV state. | |
| ra8_err_t | mdl_hash_file (mdl_storage_t *storage, const char *path, uint64_t *out) |
| FNV-1a 64 hash of a file's full contents. | |
FNV-1a 64 content hashing over an injected portable filesystem.
Provides deterministic buffer and streamed-file hashing with bounded caller-owned storage and no host file objects.
Definition in file mdl_hash.c.
| enum mdl_hash_bound_t : uint64_t |
Exact regular-file bound accepted by mdl_hash_file.
| Enumerator | |
|---|---|
| k_hash_max_read_calls | Short-read + EOF call ceiling. |
Definition at line 17 of file mdl_hash.c.
| uint64_t mdl_hash_bytes | ( | const void * | data, |
| size_t | len ) |
FNV-1a 64 hash of a byte range.
A single-shot fold of data starting from k_mdl_fnv_offset (it delegates to mdl_hash_bytes_seed with that seed). An empty range (len == 0) hashes to the offset basis, and a NULL data with a non-zero len is treated as empty rather than dereferenced.
| [in] | data | First byte of the range, or NULL for an empty range. |
| [in] | len | Number of bytes to fold. |
| k_mdl_fnv_offset | When len is 0 or data is NULL. |
data, when non-NULL, addresses at least len readable bytes. Definition at line 35 of file mdl_hash.c.
References k_mdl_fnv_offset, and mdl_hash_bytes_seed().
Referenced by internal_cache_publish(), mdl_hash_str(), and priv_mdl_cache_read_body().
| uint64_t mdl_hash_bytes_seed | ( | const void * | data, |
| size_t | len, | ||
| uint64_t | seed ) |
Continue an FNV-1a 64 fold over a byte range from a running state.
The streaming primitive: folds data into seed and returns the new running digest, so a large file can be hashed chunk by chunk with no dynamic allocation. Passing k_mdl_fnv_offset as seed for the first chunk makes a chunked hash identical to a single-shot mdl_hash_bytes of the whole range.
| [in] | data | First byte of the chunk, or NULL for an empty chunk. |
| [in] | len | Number of bytes to fold. |
| [in] | seed | Running digest so far (k_mdl_fnv_offset to start fresh). |
data into seed. | seed | When len is 0 or data is NULL (nothing to fold). |
data, when non-NULL, addresses at least len readable bytes. seed is either k_mdl_fnv_offset or a prior result of this function. Definition at line 21 of file mdl_hash.c.
References k_mdl_fnv_prime.
Referenced by internal_build_export_metadata(), internal_cache_payload_identity(), internal_cache_read_record(), internal_copy_payload(), mdl_hash_bytes(), mdl_hash_stream(), mdl_storage_txn_write(), and priv_mdl_export_zip_read().
| ra8_err_t mdl_hash_file | ( | mdl_storage_t * | storage, |
| const char * | path, | ||
| uint64_t * | out ) |
FNV-1a 64 hash of a file's full contents.
Queries path through the injected portable filesystem, rejects non-regular objects before reading, then hashes a regular file up to the implementation's 8.192 GB safety limit through bounded reads and caller-owned scratch. The size is snapshotted before reading; short input, a trailing byte from a concurrent append, or an exhausted read-call ceiling fails rather than publishing a partial-prefix digest. Used to verify a page already on disk still matches the identity recorded in state (a torn file re-hashes to a different value and is refetched) and to record the identity of a freshly fetched page.
| [in,out] | storage | Initialized filesystem binding and file workspace. |
| [in] | path | Canonical portable file path (never NULL). |
| [out] | out | Receives the 64-bit digest on success (never NULL). |
| k_ra8_ok | File read fully and hashed; *out is set. |
| k_ra8_err_invalid_arg | path or out was NULL, or the path was a symlink or non-regular object. |
| k_ra8_err_invalid_size | The regular file exceeded the safety bound. |
| k_ra8_err_not_found | The path or a path component did not exist. |
| k_ra8_err_access_denied | The process lacked permission to open it. |
| k_ra8_fail | Other open/stat/read/close failure. |
storage, path, and out are non-NULL. path directly names a readable regular file for success. Definition at line 103 of file mdl_hash.c.
References fw_fs_stat_t::exists, mdl_storage_t::file_workspace, mdl_storage_t::file_workspace_bytes, mdl_storage_t::fs, fw_fs_close(), fw_fs_open(), fw_fs_stat(), mdl_storage_t::io_buffer, mdl_storage_t::io_buffer_bytes, k_fw_fs_node_file, k_fw_fs_open_read, k_mdl_hash_max_file_bytes, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_not_found, k_ra8_ok, mdl_hash_stream(), fw_fs_t::names, fw_fs_stat_t::size_bytes, fw_fs_t::streams, and fw_fs_stat_t::type.
Referenced by internal_mdl_fetch_try_reuse(), and internal_verify_page_rec().
| uint64_t mdl_hash_str | ( | const char * | s | ) |
FNV-1a 64 hash of a NUL-terminated string (excluding the NUL).
The dedup key for a page's source URL: two runs that scrape the same URL produce the same key, so a page already held is found without re-fetching.
| [in] | s | String to hash, or NULL. |
s's bytes. | k_mdl_fnv_offset | When s is NULL or empty. |
s, when non-NULL, is NUL-terminated. s is not modified.Definition at line 40 of file mdl_hash.c.
References k_mdl_fnv_offset, mdl_hash_bytes(), and strlen().
Referenced by internal_build_export_metadata(), internal_cache_paths(), internal_cache_prepare(), internal_cache_publish(), internal_cache_record_valid(), internal_mdl_fetch_one_page(), internal_mdl_fetch_prepare_page(), internal_mdl_fetch_publish_page(), and internal_mdl_fetch_resolve_not_modified().
| ra8_err_t mdl_hash_stream | ( | fw_fs_file_t * | file, |
| uint64_t | file_size, | ||
| uint8_t * | buffer, | ||
| uint32_t | buffer_bytes, | ||
| uint64_t * | out ) |
Fold an exact regular-file extent into a running FNV state.
Hash exactly one snapshotted extent from an already-open stream.
| [in,out] | file | Open generic file positioned at byte zero. |
| [in] | file_size | Immutable size snapshot obtained from fw_fs_stat. |
| [out] | buffer | Caller-owned read scratch. |
| [in] | buffer_bytes | Nonzero extent of buffer. |
| [out] | out | Digest written only after exact EOF validation. |
file is a valid open regular file and out is non-NULL. file_size is at most k_mdl_hash_max_file_bytes. file through EOF and writes out. out untouched. Definition at line 63 of file mdl_hash.c.
References fw_fs_read(), k_hash_max_read_calls, k_mdl_fnv_offset, k_mdl_hash_max_file_bytes, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_fail, k_ra8_ok, and mdl_hash_bytes_seed().
Referenced by internal_validate_stage(), mdl_hash_file(), and priv_mdl_export_source_verify_close().