@@ -50,22 +50,6 @@ pub struct ShellKahe {
5050}
5151
5252impl ShellKahe {
53- pub fn new (
54- shell_kahe_config : ShellKaheConfig ,
55- public_seed : & Seed ,
56- ) -> Result < Self , status:: StatusError > {
57- Self :: validate_kahe_config ( & shell_kahe_config) ?;
58- let num_coeffs = 1 << shell_kahe_config. log_n ;
59- let public_kahe_parameters = kahe:: create_public_parameters (
60- shell_kahe_config. log_n as u64 ,
61- shell_kahe_config. log_t as u64 ,
62- & shell_kahe_config. moduli ,
63- shell_kahe_config. num_public_polynomials ,
64- & public_seed,
65- ) ?;
66- Ok ( Self { config : shell_kahe_config, num_coeffs, public_kahe_parameters } )
67- }
68-
6953 /// Validates KAHE parameters in ShellKaheConfig.
7054 fn validate_kahe_config ( config : & ShellKaheConfig ) -> Result < ( ) , status:: StatusError > {
7155 if config. log_t > BIG_INT_BITS {
@@ -113,6 +97,30 @@ impl KaheBase for ShellKahe {
11397
11498 type Rng = SingleThreadHkdfPrng ;
11599
100+ type Config = ShellKaheConfig ;
101+
102+ fn new (
103+ shell_kahe_config : Self :: Config ,
104+ context_string : & [ u8 ] ,
105+ ) -> Result < Self , status:: StatusError > {
106+ Self :: validate_kahe_config ( & shell_kahe_config) ?;
107+ let num_coeffs = 1 << shell_kahe_config. log_n ;
108+ let public_seed = single_thread_hkdf:: compute_hkdf (
109+ context_string,
110+ b"" ,
111+ b"ShellKahe.public_seed" ,
112+ single_thread_hkdf:: seed_length ( ) ,
113+ ) ?;
114+ let public_kahe_parameters = kahe:: create_public_parameters (
115+ shell_kahe_config. log_n as u64 ,
116+ shell_kahe_config. log_t as u64 ,
117+ & shell_kahe_config. moduli ,
118+ shell_kahe_config. num_public_polynomials ,
119+ & public_seed,
120+ ) ?;
121+ Ok ( Self { config : shell_kahe_config, num_coeffs, public_kahe_parameters } )
122+ }
123+
116124 fn add_keys_in_place (
117125 & self ,
118126 left : & Self :: SecretKey ,
@@ -299,6 +307,8 @@ mod test {
299307 /// Default ID used in tests.
300308 const DEFAULT_ID : & str = "default" ;
301309
310+ const CONTEXT_STRING : & [ u8 ] = b"test_context_string" ;
311+
302312 #[ gtest]
303313 fn test_encrypt_decrypt_short ( ) -> googletest:: Result < ( ) > {
304314 let plaintext_modulus_bits = 39 ;
@@ -307,8 +317,7 @@ mod test {
307317 PackedVectorConfig { base : 10 , dimension : 2 , num_packed_coeffs : 5 } ,
308318 ) ] ) ;
309319 let kahe_config = make_kahe_config_for ( plaintext_modulus_bits, packed_vector_configs) ?;
310- let public_seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
311- let kahe = ShellKahe :: new ( kahe_config, & public_seed) ?;
320+ let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
312321
313322 let pt = HashMap :: from ( [ ( String :: from ( DEFAULT_ID ) , vec ! [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ] ) ;
314323 let seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
@@ -327,8 +336,7 @@ mod test {
327336 PackedVectorConfig { base : 10 , dimension : 2 , num_packed_coeffs : 5 } ,
328337 ) ] ) ;
329338 let kahe_config = make_kahe_config_for ( plaintext_modulus_bits, packed_vector_configs) ?;
330- let public_seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
331- let kahe = ShellKahe :: new ( kahe_config, & public_seed) ?;
339+ let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
332340
333341 let pt = HashMap :: from ( [ ( String :: from ( DEFAULT_ID ) , vec ! [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ] ) ;
334342 let seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
@@ -364,8 +372,7 @@ mod test {
364372 packed_vector_config. num_packed_coeffs = num_messages;
365373 set_kahe_num_public_polynomials ( & mut kahe_config) ;
366374
367- let public_seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
368- let kahe = ShellKahe :: new ( kahe_config, & public_seed) ?;
375+ let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
369376
370377 let seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
371378 let mut prng = SingleThreadHkdfPrng :: create ( & seed) ?;
@@ -397,8 +404,7 @@ mod test {
397404 ) ] ) ;
398405 let kahe_config = make_kahe_config_for ( plaintext_modulus_bits, packed_vector_configs) ?;
399406
400- let public_seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
401- let kahe = ShellKahe :: new ( kahe_config, & public_seed) ?;
407+ let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
402408 let seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
403409 let mut prng = SingleThreadHkdfPrng :: create ( & seed) ?;
404410
@@ -434,8 +440,7 @@ mod test {
434440 let packed_vector_configs = HashMap :: from ( [ ] ) ;
435441 let kahe_config = make_kahe_config_for ( plaintext_modulus_bits, packed_vector_configs) ?;
436442
437- let public_seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
438- let kahe = ShellKahe :: new ( kahe_config, & public_seed) ?;
443+ let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
439444 let seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
440445 let mut prng = SingleThreadHkdfPrng :: create ( & seed) ?;
441446
@@ -477,8 +482,7 @@ mod test {
477482 let plaintext_modulus_bits = 39 ;
478483 let packed_vector_configs = HashMap :: from ( [ ] ) ;
479484 let kahe_config = make_kahe_config_for ( plaintext_modulus_bits, packed_vector_configs) ?;
480- let public_seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
481- let kahe = ShellKahe :: new ( kahe_config, & public_seed) ?;
485+ let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
482486
483487 // The seed used to sample the secret keys.
484488 let seed = SingleThreadHkdfPrng :: generate_seed ( ) ?;
0 commit comments