ffi: entropy encoding + backup archive building blocks - #2435
Open
ronaldtse wants to merge 3 commits into
Open
Conversation
| assert_true(archive_len > 0); | ||
|
|
||
| /* Save to a file for re-input. */ | ||
| FILE *f = fopen("backup.archive", "wb"); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2435 +/- ##
==========================================
- Coverage 85.37% 85.11% -0.26%
==========================================
Files 126 127 +1
Lines 22866 23291 +425
==========================================
+ Hits 19521 19825 +304
- Misses 3345 3466 +121 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ronaldtse
force-pushed
the
key-backup-building-blocks
branch
from
August 2, 2026 09:43
2018478 to
458f4c8
Compare
Adds two generic building-block APIs that clients can compose into backup, sync, and escrow workflows. Each is self-contained and parameterised so callers can adapt them to their own formats and storage models; rnp deliberately does not bake in any one workflow. Entropy encoding (rnp_entropy_encode_human_readable and friends): Generates cryptographically random entropy and encodes it in a caller-specified alphabet, split into groups with optional identifiers and optional SHA-256-based checksum. Useful whenever random bytes need to be transcribed by humans (paper backup, manual entry, etc.). The default alphabet is hex; callers can supply their own alphabet (e.g., handwriting-friendly variants) via the params struct. The 'disable_*' fields are bool but follow C convention: false (zero-init default) means "include the feature", true means "omit". This lets callers pass an all-zero params struct for the common default case. Backup archive (rnp_backup_archive_create / _load): Wraps a sequence of secret-key exports in a standard OpenPGP signed-and-encrypted message. The wire format is documented in docs/develop/backup-format.adoc and is just a literal-data packet containing concatenated transferable secret keys, signed by a caller-specified key, then encrypted to a caller-specified public key. The format is RFC 9580-compliant and any OpenPGP library can produce or consume it. Tests: test_ffi_entropy_encoding_roundtrip covers default-alphabet round-trip, custom-alphabet round-trip, order-independent group entry, tampered-checksum rejection, and invalid-params rejection. test_ffi_backup_archive_roundtrip covers generate-keys → create archive → fresh FFI → load archive → verify recovered key present and secret. Wire format docs: docs/develop/backup-format.adoc. This PR does NOT mention any specific application or external proposal. Both building blocks are general-purpose: useful for enterprise key escrow, personal offline backups, multi-device sync, or any other workflow that needs human-transcribable entropy or signed/encrypted key containers.
ronaldtse
force-pushed
the
key-backup-building-blocks
branch
from
August 4, 2026 16:26
458f4c8 to
5ea3f4f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two general-purpose building-block APIs that clients can compose into backup, sync, and escrow workflows. Each is self-contained and parameterised; rnp deliberately does not bake in any specific application's workflow.
What's in this PR
Entropy encoding utility (
rnp_entropy_encode_human_readable,_decode,_validate):disable_*bool fields follow C convention:false(zero-init default) = include feature,true= omit. This lets callers pass an all-zero params struct for the common default case.Backup archive format (
rnp_backup_archive_create,_load):docs/develop/backup-format.adoc.Tests:
test_ffi_entropy_encoding_roundtripcovers default-alphabet round-trip, custom-alphabet round-trip, order-independent group entry, tampered-checksum rejection, invalid-params rejection.test_ffi_backup_archive_roundtripcovers generate-keys → create archive → fresh FFI → load archive → verify recovered key present and secret.Why
These two building blocks come up in many real-world workflows:
Previously each client would re-implement the entropy encoding and the signed+encrypted container pattern from scratch, with attendant correctness risk (checksum bugs, signature-then-encrypt ordering bugs, etc.). This PR gives them a tested, canonical implementation in the rnp library itself.
Architectural decision
rnp is intentionally a crypto library, not a workflow framework. The APIs in this PR expose building blocks that clients compose on their own; they do NOT prescribe a specific workflow. Naming (
encryption_key,decryption_key,signing_key) is intentionally generic so multiple applications can adopt the same primitives without coupling.What's NOT in this PR
Test plan
test_ffi_entropy_encoding_roundtrippasses locally (5 cases covered)test_ffi_backup_archive_roundtrippasses locally (full round-trip with separate FFIs)test_ffi_encrypt_pass,test_ffi_argon2_locked_seckey,test_ffi_encrypt_pk_with_v6_key