@@ -615,9 +615,6 @@ pub struct SharedKeyGenParameters {
615615 /// instead of running full distributed keygen.
616616 #[ clap( long) ]
617617 pub existing_keyset_id : Option < RequestId > ,
618- /// Epoch ID for the existing keyset (optional, defaults to the request's epoch).
619- #[ clap( long) ]
620- pub existing_epoch_id : Option < EpochId > ,
621618 /// Reuse the tag from the existing keyset instead of using the new key ID as tag.
622619 /// This is only used when generating a key from existing shares.
623620 #[ clap( long, default_value_t = false ) ]
@@ -1263,16 +1260,16 @@ pub async fn fetch_ctxt_from_file(
12631260/// compressed storage or the legacy uncompressed layout.
12641261///
12651262/// If `uncompressed_keys` is explicitly `true`, fetches `[PublicKey, ServerKey]` only.
1266- /// Otherwise, tries `[CompressedXofKeySet]` first; on failure, falls back to
1267- /// `[PublicKey, ServerKey]`.
1263+ /// Otherwise, tries the current compressed layout `[CompressedXofKeySet, PublicKey]`
1264+ /// first; on failure, falls back to the legacy `[PublicKey, ServerKey]`.
12681265/// Returns the fetched party confs and a boolean indicating whether uncompressed keys were found.
12691266async fn fetch_keys_auto_detect (
12701267 key_id : & str ,
12711268 uncompressed_keys : bool ,
12721269 cc_conf : & CoreClientConfig ,
12731270 destination_prefix : & Path ,
12741271) -> anyhow:: Result < ( Vec < CoreConf > , bool ) > {
1275- let compressed_key_types = vec ! [ PubDataType :: CompressedXofKeySet ] ;
1272+ let compressed_key_types = vec ! [ PubDataType :: CompressedXofKeySet , PubDataType :: PublicKey ] ;
12761273 let key_types = vec ! [ PubDataType :: PublicKey , PubDataType :: ServerKey ] ;
12771274
12781275 if uncompressed_keys {
@@ -1293,7 +1290,7 @@ async fn fetch_keys_auto_detect(
12931290 Ok ( confs) => Ok ( ( confs, false ) ) ,
12941291 Err ( _) => {
12951292 tracing:: info!(
1296- "CompressedXofKeySet not found, trying legacy [PublicKey, ServerKey]..."
1293+ "Compressed layout [ CompressedXofKeySet, PublicKey] not found, trying legacy [PublicKey, ServerKey]..."
12971294 ) ;
12981295 let confs =
12991296 fetch_public_elements ( key_id, & key_types, cc_conf, destination_prefix, false )
@@ -2387,7 +2384,13 @@ fn print_timings(cmd: &str, durations: &mut [tokio::time::Duration], start: toki
23872384#[ cfg( test) ]
23882385mod tests {
23892386 use super :: * ;
2387+ use kms_lib:: engine:: base:: derive_request_id;
2388+ use kms_lib:: util:: key_setup:: test_tools:: load_pk_from_pub_storage;
2389+ use kms_lib:: vault:: storage:: { StorageType , file:: FileStorage , store_versioned_at_request_id} ;
23902390 use std:: env;
2391+ use tempfile:: tempdir;
2392+ use tfhe:: core_crypto:: prelude:: NormalizedHammingWeightBound ;
2393+ use tfhe:: xof_key_set:: CompressedXofKeySet ;
23912394
23922395 #[ test]
23932396 fn test_parse_hex ( ) {
@@ -2563,4 +2566,120 @@ mod tests {
25632566 ) ;
25642567 assert ! ( PreviousEpochParameters :: from_str( & input_string) . is_err( ) ) ;
25652568 }
2569+
2570+ #[ tokio:: test]
2571+ async fn fetch_keys_auto_detect_downloads_public_key_for_compressed_layout ( ) {
2572+ let remote_root = tempdir ( ) . unwrap ( ) ;
2573+ let destination_root = tempdir ( ) . unwrap ( ) ;
2574+ let object_folder = "PUB-p1" ;
2575+ let key_id = derive_request_id ( "fetch_keys_auto_detect_downloads_public_key" ) . unwrap ( ) ;
2576+
2577+ let params = kms_lib:: consts:: TEST_PARAM ;
2578+ let config = params. to_tfhe_config ( ) ;
2579+ let max_norm_hwt = params
2580+ . get_params_basics_handle ( )
2581+ . get_sk_deviations ( )
2582+ . map ( |x| x. pmax )
2583+ . unwrap_or ( 1.0 ) ;
2584+ let max_norm_hwt = NormalizedHammingWeightBound :: new ( max_norm_hwt) . unwrap ( ) ;
2585+ let ( _client_key, compressed_keyset) = CompressedXofKeySet :: generate (
2586+ config,
2587+ vec ! [ 1 , 2 , 3 , 4 ] ,
2588+ params. get_params_basics_handle ( ) . get_sec ( ) as u32 ,
2589+ max_norm_hwt,
2590+ key_id. into ( ) ,
2591+ )
2592+ . unwrap ( ) ;
2593+ let ( public_key, _server_key) = compressed_keyset
2594+ . clone ( )
2595+ . decompress ( )
2596+ . unwrap ( )
2597+ . into_raw_parts ( ) ;
2598+
2599+ let mut remote_storage = FileStorage :: new (
2600+ Some ( remote_root. path ( ) ) ,
2601+ StorageType :: PUB ,
2602+ Some ( object_folder) ,
2603+ )
2604+ . unwrap ( ) ;
2605+ store_versioned_at_request_id (
2606+ & mut remote_storage,
2607+ & key_id,
2608+ & compressed_keyset,
2609+ & PubDataType :: CompressedXofKeySet . to_string ( ) ,
2610+ )
2611+ . await
2612+ . unwrap ( ) ;
2613+ store_versioned_at_request_id (
2614+ & mut remote_storage,
2615+ & key_id,
2616+ & public_key,
2617+ & PubDataType :: PublicKey . to_string ( ) ,
2618+ )
2619+ . await
2620+ . unwrap ( ) ;
2621+
2622+ let cc_conf = CoreClientConfig {
2623+ kms_type : KmsType :: Threshold ,
2624+ cores : vec ! [ CoreConf {
2625+ party_id: 1 ,
2626+ address: "127.0.0.1:0" . to_string( ) ,
2627+ s3_endpoint: format!( "file://{}" , remote_root. path( ) . display( ) ) ,
2628+ object_folder: object_folder. to_string( ) ,
2629+ #[ cfg( feature = "testing" ) ]
2630+ private_object_folder: None ,
2631+ #[ cfg( feature = "testing" ) ]
2632+ config_path: None ,
2633+ } ] ,
2634+ decryption_mode : None ,
2635+ num_majority : 1 ,
2636+ num_reconstruct : 1 ,
2637+ fhe_params : Some ( FheParameter :: Test ) ,
2638+ } ;
2639+
2640+ let ( party_confs, detected_uncompressed) = fetch_keys_auto_detect (
2641+ & key_id. to_string ( ) ,
2642+ false ,
2643+ & cc_conf,
2644+ destination_root. path ( ) ,
2645+ )
2646+ . await
2647+ . unwrap ( ) ;
2648+
2649+ assert_eq ! ( party_confs. len( ) , 1 ) ;
2650+ assert ! (
2651+ !detected_uncompressed,
2652+ "compressed layout should not fall back to legacy uncompressed keys"
2653+ ) ;
2654+
2655+ let downloaded_pk_path = destination_root
2656+ . path ( )
2657+ . join ( object_folder)
2658+ . join ( PubDataType :: PublicKey . to_string ( ) )
2659+ . join ( key_id. to_string ( ) ) ;
2660+ assert ! (
2661+ downloaded_pk_path. exists( ) ,
2662+ "compressed auto-detect should download the authoritative standalone PublicKey"
2663+ ) ;
2664+
2665+ let _downloaded_pk =
2666+ load_pk_from_pub_storage ( Some ( destination_root. path ( ) ) , & key_id, Some ( object_folder) )
2667+ . await ;
2668+ let ( ciphertext, _format, _fhe_type) = compute_cipher_from_stored_key (
2669+ Some ( destination_root. path ( ) ) ,
2670+ TestingPlaintext :: U8 ( 42 ) ,
2671+ & key_id,
2672+ Some ( object_folder) ,
2673+ EncryptionConfig {
2674+ compression : true ,
2675+ precompute_sns : false ,
2676+ } ,
2677+ false ,
2678+ )
2679+ . await ;
2680+ assert ! (
2681+ !ciphertext. is_empty( ) ,
2682+ "encryption should succeed from freshly fetched compressed key material"
2683+ ) ;
2684+ }
25662685}
0 commit comments