@@ -16,7 +16,7 @@ use derive_where::derive_where;
1616use digest:: { Digest , Output } ;
1717use generic_array:: typenum:: Unsigned ;
1818use generic_array:: GenericArray ;
19- use rand_core:: { CryptoRng , RngCore } ;
19+ use rand_core:: { TryCryptoRng , TryRngCore } ;
2020
2121use crate :: common:: {
2222 derive_keypair, deterministic_blind_unchecked, generate_proof, hash_to_group, i2osp_2,
@@ -75,7 +75,7 @@ impl<CS: CipherSuite> VoprfClient<CS> {
7575 ///
7676 /// # Errors
7777 /// [`Error::Input`] if the `input` is empty or longer then [`u16::MAX`].
78- pub fn blind < R : RngCore + CryptoRng > (
78+ pub fn blind < R : TryRngCore + TryCryptoRng > (
7979 input : & [ u8 ] ,
8080 blinding_factor_rng : & mut R ,
8181 ) -> Result < VoprfClientBlindResult < CS > > {
@@ -196,9 +196,10 @@ impl<CS: CipherSuite> VoprfServer<CS> {
196196 ///
197197 /// # Errors
198198 /// [`Error::Protocol`] if the protocol fails and can't be completed.
199- pub fn new < R : RngCore + CryptoRng > ( rng : & mut R ) -> Result < Self > {
199+ pub fn new < R : TryRngCore + TryCryptoRng > ( rng : & mut R ) -> Result < Self > {
200200 let mut seed = GenericArray :: < _ , <CS :: Group as Group >:: ScalarLen > :: default ( ) ;
201- rng. fill_bytes ( & mut seed) ;
201+ rng. try_fill_bytes ( & mut seed)
202+ . map_err ( |_| Error :: Protocol ) ?;
202203 // This can't fail as the hash output is type constrained.
203204 Self :: new_from_seed ( & seed, & [ ] )
204205 }
@@ -238,7 +239,7 @@ impl<CS: CipherSuite> VoprfServer<CS> {
238239 /// Computes the second step for the multiplicative blinding version of
239240 /// DH-OPRF. This message is sent from the server (who holds the OPRF key)
240241 /// to the client.
241- pub fn blind_evaluate < R : RngCore + CryptoRng > (
242+ pub fn blind_evaluate < R : TryRngCore + TryCryptoRng > (
242243 & self ,
243244 rng : & mut R ,
244245 blinded_element : & BlindedElement < CS > ,
@@ -271,7 +272,7 @@ impl<CS: CipherSuite> VoprfServer<CS> {
271272 /// [`Error::Batch`] if the number of `blinded_elements` and
272273 /// `evaluation_elements` don't match or is longer then [`u16::MAX`]
273274 #[ cfg( feature = "alloc" ) ]
274- pub fn batch_blind_evaluate < ' a , R : RngCore + CryptoRng , I > (
275+ pub fn batch_blind_evaluate < ' a , R : TryRngCore + TryCryptoRng , I > (
275276 & self ,
276277 rng : & mut R ,
277278 blinded_elements : & ' a I ,
@@ -322,7 +323,7 @@ impl<CS: CipherSuite> VoprfServer<CS> {
322323 pub fn batch_blind_evaluate_finish <
323324 ' a ,
324325 ' b ,
325- R : RngCore + CryptoRng ,
326+ R : TryRngCore + TryCryptoRng ,
326327 IB : Iterator < Item = & ' a BlindedElement < CS > > + ExactSizeIterator ,
327328 IE ,
328329 > (
@@ -599,7 +600,7 @@ mod tests {
599600 let num_iterations = 10 ;
600601 for _ in 0 ..num_iterations {
601602 let mut input = [ 0u8 ; 32 ] ;
602- rng. fill_bytes ( & mut input) ;
603+ rng. try_fill_bytes ( & mut input) . unwrap ( ) ;
603604 let client_blind_result = VoprfClient :: < CS > :: blind ( & input, & mut rng) . unwrap ( ) ;
604605 inputs. push ( input) ;
605606 client_states. push ( client_blind_result. state ) ;
@@ -643,7 +644,7 @@ mod tests {
643644 let num_iterations = 10 ;
644645 for _ in 0 ..num_iterations {
645646 let mut input = [ 0u8 ; 32 ] ;
646- rng. fill_bytes ( & mut input) ;
647+ rng. try_fill_bytes ( & mut input) . unwrap ( ) ;
647648 let client_blind_result = VoprfClient :: < CS > :: blind ( & input, & mut rng) . unwrap ( ) ;
648649 inputs. push ( input) ;
649650 client_states. push ( client_blind_result. state ) ;
0 commit comments