@@ -114,37 +114,6 @@ pub fn combine<const N: usize>(shares: &[(u8, [u8; N])]) -> FastCryptoResult<[u8
114114 . expect ( "fixed length" ) )
115115}
116116
117- pub fn split_with_given_shares < const N : usize > (
118- given_shares : & [ [ u8 ; N ] ] ,
119- number_of_shares : u8 ,
120- ) -> FastCryptoResult < SecretSharing < N > > {
121- let threshold = given_shares. len ( ) ;
122- if threshold > number_of_shares as usize || threshold == 0 {
123- return Err ( InvalidInput ) ;
124- }
125-
126- let indices = ( 1 ..=number_of_shares) . collect_vec ( ) ;
127-
128- // Share each byte of the secret individually.
129- let ( secret, byte_shares) : ( Vec < u8 > , Vec < Vec < u8 > > ) = ( 0 ..N )
130- . map ( |i| {
131- split_byte_with_given_shares ( & given_shares. iter ( ) . map ( |s| s[ i] ) . collect_vec ( ) , & indices)
132- } )
133- . collect :: < FastCryptoResult < Vec < _ > > > ( ) ?
134- . into_iter ( )
135- . unzip ( ) ;
136-
137- // Combine the byte shares into shares.
138- let shares = transpose ( & byte_shares) ?;
139- let secret = secret. try_into ( ) . expect ( "fixed length" ) ;
140-
141- Ok ( SecretSharing {
142- secret,
143- indices,
144- shares,
145- } )
146- }
147-
148117/// Internal function to share a secret.
149118/// This is an implementation of Shamir's secret sharing over the Galois field of 256 elements.
150119/// See https://dl.acm.org/doi/10.1145/359168.359176.
@@ -175,44 +144,6 @@ fn split_byte<R: AllowedRng>(
175144 . collect ( ) )
176145}
177146
178- /// Create a secret sharing of `num_shares` shares such that at least `threshold` shares are needed
179- /// to reconstruct the byte and such that the first `threshold` shares will be the given ones.
180- ///
181- /// The shared secret will be determined by the given shares, and the process is deterministic.
182- ///
183- /// Returns the secret and a vector of the shares.
184- fn split_byte_with_given_shares (
185- given_shares : & [ u8 ] ,
186- indices : & [ u8 ] ,
187- ) -> FastCryptoResult < ( u8 , Vec < u8 > ) > {
188- let number_of_shares = indices. len ( ) ;
189- let threshold = given_shares. len ( ) + 1 ;
190- assert ! ( threshold <= number_of_shares && number_of_shares <= 255 && threshold > 0 ) ;
191- assert ! ( indices. iter( ) . all( |& i| i != 0 ) && indices. iter( ) . all_unique( ) ) ;
192-
193- // Construct the polynomial that interpolates the given shares and the secret.
194- let polynomial = Polynomial :: interpolate (
195- & indices
196- . iter ( )
197- . zip ( given_shares)
198- . map ( |( & x, & y) | ( x. into ( ) , y. into ( ) ) )
199- . collect_vec ( ) ,
200- ) ;
201-
202- // The secret is the constant term of the polynomial.
203- let secret = polynomial. 0 [ 0 ] . 0 ;
204-
205- // Evaluate the polynomial at the remaining indices to get the remaining shares.
206- let remaining_shares = indices[ given_shares. len ( ) ..]
207- . iter ( )
208- . map ( |i| polynomial. evaluate ( & i. into ( ) ) . 0 )
209- . collect ( ) ;
210-
211- let shares = [ given_shares. to_vec ( ) , remaining_shares] . concat ( ) ;
212-
213- Ok ( ( secret, shares) )
214- }
215-
216147/// Internal function to reconstruct a secret.
217148/// This is an implementation of Shamir's secret sharing over the Galois field of 256 elements.
218149/// See https://dl.acm.org/doi/10.1145/359168.359176.
@@ -324,44 +255,4 @@ mod tests {
324255
325256 assert_ne ! ( combine( & shares[ ..1 ] ) . unwrap( ) , expected) ;
326257 }
327-
328- #[ test]
329- fn test_split_byte_with_given_shares ( ) {
330- let given_shares = [ 5 , 19 ] ;
331- let indices = [ 1 , 2 , 3 , 4 , 5 ] ;
332-
333- let ( secret, shares) = split_byte_with_given_shares ( & given_shares, & indices) . unwrap ( ) ;
334-
335- let reconstructed = combine_byte ( & [
336- ( indices[ 0 ] , shares[ 0 ] ) ,
337- ( indices[ 2 ] , shares[ 2 ] ) ,
338- ( indices[ 4 ] , shares[ 4 ] ) ,
339- ] )
340- . unwrap ( ) ;
341- assert_eq ! ( reconstructed, secret) ;
342- }
343-
344- #[ test]
345- fn test_with_given_shares ( ) {
346- let given_shares = [
347- * b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ,
348- * b"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" ,
349- * b"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" ,
350- ] ;
351- let threshold = given_shares. len ( ) as u8 ;
352- let SecretSharing {
353- secret,
354- indices,
355- shares,
356- } = split_with_given_shares ( & given_shares, 5 ) . unwrap ( ) ;
357-
358- assert_eq ! ( threshold, given_shares. len( ) as u8 ) ;
359- assert_eq ! ( shares[ 0 ] , given_shares[ 0 ] ) ;
360- assert_eq ! ( shares[ 1 ] , given_shares[ 1 ] ) ;
361-
362- assert_eq ! (
363- secret,
364- combine( & ( 1 ..4 ) . map( |i| ( indices[ i] , shares[ i] ) ) . collect_vec( ) ) . unwrap( )
365- ) ;
366- }
367258}
0 commit comments