-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add secret and evaluation key serialization #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d334b4
feat: add secret and evaluation key serialization
cedoor 9a1a7ae
feat: add Params::test aligned with Poulpy bdd_arithmetic test_suite
cedoor 228259a
test: adjust integration tests and add serialize_keys example
cedoor 8df0ba4
docs: drop test-fixture framing from serialize_keys example
cedoor 0079527
style: format code with rustfmt
cedoor 073e1ff
feat(keys): seeds, lattice-only SK, and EvaluationKey blob API
cedoor 12eee75
feat: add versioned ciphertext serialize/deserialize
cedoor a315de7
style: format code with rustfmt
cedoor ca4d552
chore(deps): bump poulpy and adapt to prepare-path regression
cedoor f1ceace
style: format code with rustfmt
cedoor b4e8486
fix: wire Poulpy AVX feature for x86_64 CI and portable all-features
cedoor 06082fb
fix(ciphertext): embed GLWE layout in serialized blobs
cedoor 35a53a3
fix(security): redact KeygenSeeds in Debug output
cedoor 8d71cc2
style: format code with rustfmt
cedoor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| //! Write the standard-form [`squid::EvaluationKey`] blob from one OS-random keygen. | ||
| //! | ||
| //! Secret key material is not written: Poulpy no longer exposes binary I/O for | ||
| //! LWE/GLWE secrets ([poulpy#147](https://github.com/poulpy-fhe/poulpy/pull/147)); | ||
| //! persist seeds or handle secrets at the app level if you need portability. | ||
| //! | ||
| //! Output: `params_test_evaluation_key.bin` under `--output-dir`. | ||
| //! | ||
| //! ```sh | ||
| //! cargo run --example serialize_keys -- --output-dir ./out | ||
| //! ``` | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| use squid::{Context, Params}; | ||
|
|
||
| const EVALUATION_KEY_FILE: &str = "params_test_evaluation_key.bin"; | ||
|
|
||
| struct Args { | ||
| output_dir: PathBuf, | ||
| } | ||
|
|
||
| fn print_usage() { | ||
| eprintln!( | ||
| "\ | ||
| Usage: serialize_keys --output-dir <DIR> | ||
|
|
||
| Write the standard-form evaluation key blob from one OS-random keygen (Params::test()). | ||
|
|
||
| File written (fixed name): | ||
| {EVALUATION_KEY_FILE} | ||
|
|
||
| Options: | ||
| -o, --output-dir <DIR> Directory to write the file into | ||
| -h, --help Show this help | ||
| " | ||
| ); | ||
| } | ||
|
|
||
| fn parse_args() -> Result<Option<Args>, String> { | ||
| let mut args = std::env::args().skip(1); | ||
| let mut output_dir: Option<PathBuf> = None; | ||
|
|
||
| while let Some(arg) = args.next() { | ||
| match arg.as_str() { | ||
| "-h" | "--help" => return Ok(None), | ||
| "-o" | "--output-dir" => { | ||
| let path = args | ||
| .next() | ||
| .ok_or_else(|| "--output-dir requires a directory".to_string())?; | ||
| output_dir = Some(PathBuf::from(path)); | ||
| } | ||
| other => return Err(format!("unknown argument: {other}")), | ||
| } | ||
| } | ||
|
|
||
| Ok(Some(Args { | ||
| output_dir: output_dir | ||
| .ok_or_else(|| "missing --output-dir <DIR> (or -o <DIR>)".to_string())?, | ||
| })) | ||
| } | ||
|
|
||
| fn main() -> std::io::Result<()> { | ||
| let args = match parse_args() { | ||
| Ok(None) => { | ||
| print_usage(); | ||
| return Ok(()); | ||
| } | ||
| Ok(Some(a)) => a, | ||
| Err(e) => { | ||
| eprintln!("Error: {e}"); | ||
| print_usage(); | ||
| std::process::exit(1); | ||
| } | ||
| }; | ||
|
|
||
| std::fs::create_dir_all(&args.output_dir)?; | ||
|
|
||
| let evaluation_key = args.output_dir.join(EVALUATION_KEY_FILE); | ||
|
|
||
| let params = Params::test(); | ||
| let mut ctx = Context::new(params); | ||
| let (_sk, ek) = ctx.keygen(); | ||
|
|
||
| let ek_blob = ctx | ||
| .serialize_evaluation_key(&ek) | ||
| .expect("serialize evaluation key"); | ||
|
|
||
| std::fs::write(&evaluation_key, ek_blob)?; | ||
|
|
||
| eprintln!("Wrote {}.", evaluation_key.display()); | ||
| Ok(()) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.