@@ -23,14 +23,18 @@ static STR_VOPRF: &[u8] = b"VOPRF05";
23
23
/// message is sent from the client (who holds the input) to the server (who holds the OPRF key).
24
24
/// The client can also pass in an optional "pepper" string to be mixed in with the input through
25
25
/// an HKDF computation.
26
- pub ( crate ) fn blind_with_postprocessing < R : RngCore + CryptoRng , G : GroupWithMapToCurve > (
26
+ pub ( crate ) fn blind < R : RngCore + CryptoRng , G : GroupWithMapToCurve > (
27
27
input : & [ u8 ] ,
28
28
blinding_factor_rng : & mut R ,
29
- postprocess : fn ( G :: Scalar ) -> G :: Scalar ,
29
+ # [ cfg ( test ) ] postprocess : fn ( G :: Scalar ) -> G :: Scalar ,
30
30
) -> Result < ( Token < G > , G ) , InternalPakeError > {
31
31
let mapped_point = G :: map_to_curve ( input, Some ( STR_VOPRF ) ) ; // TODO: add contextString from RFC
32
32
let blinding_factor = G :: random_scalar ( blinding_factor_rng) ;
33
+ #[ cfg( test) ]
33
34
let blind = postprocess ( blinding_factor) ;
35
+ #[ cfg( not( test) ) ]
36
+ let blind = blinding_factor;
37
+
34
38
let blind_token = mapped_point * & blind;
35
39
Ok ( (
36
40
Token {
@@ -60,23 +64,34 @@ pub(crate) fn unblind_and_finalize<G: Group, H: Hash>(
60
64
Ok ( prk)
61
65
}
62
66
63
- // Benchmarking shims
67
+ ////////////////////////
68
+ // Benchmarking shims //
69
+ ////////////////////////
70
+
64
71
#[ cfg( feature = "bench" ) ]
72
+ #[ doc( hidden) ]
65
73
#[ inline]
66
74
pub fn blind_shim < R : RngCore + CryptoRng , G : GroupWithMapToCurve > (
67
75
input : & [ u8 ] ,
68
76
blinding_factor_rng : & mut R ,
69
77
) -> Result < ( Token < G > , G ) , InternalPakeError > {
70
- blind_with_postprocessing ( input, blinding_factor_rng, std:: convert:: identity)
78
+ blind (
79
+ input,
80
+ blinding_factor_rng,
81
+ #[ cfg( test) ]
82
+ std:: convert:: identity,
83
+ )
71
84
}
72
85
73
86
#[ cfg( feature = "bench" ) ]
87
+ #[ doc( hidden) ]
74
88
#[ inline]
75
89
pub fn evaluate_shim < G : Group > ( point : G , oprf_key : & G :: Scalar ) -> Result < G , InternalPakeError > {
76
90
evaluate ( point, oprf_key)
77
91
}
78
92
79
93
#[ cfg( feature = "bench" ) ]
94
+ #[ doc( hidden) ]
80
95
#[ inline]
81
96
pub fn unblind_and_finalize_shim < G : Group , H : Hash > (
82
97
token : & Token < G > ,
@@ -85,8 +100,10 @@ pub fn unblind_and_finalize_shim<G: Group, H: Hash>(
85
100
unblind_and_finalize :: < G , H > ( token, point)
86
101
}
87
102
88
- // Tests
89
- // =====
103
+ ///////////
104
+ // Tests //
105
+ // ===== //
106
+ ///////////
90
107
91
108
#[ cfg( test) ]
92
109
mod tests {
@@ -117,11 +134,8 @@ mod tests {
117
134
fn oprf_retrieval ( ) -> Result < ( ) , InternalPakeError > {
118
135
let input = b"hunter2" ;
119
136
let mut rng = OsRng ;
120
- let ( token, alpha) = blind_with_postprocessing :: < _ , RistrettoPoint > (
121
- & input[ ..] ,
122
- & mut rng,
123
- std:: convert:: identity,
124
- ) ?;
137
+ let ( token, alpha) =
138
+ blind :: < _ , RistrettoPoint > ( & input[ ..] , & mut rng, std:: convert:: identity) ?;
125
139
let oprf_key_bytes = arr ! [
126
140
u8 ; 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 ,
127
141
24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
@@ -139,12 +153,8 @@ mod tests {
139
153
let mut rng = OsRng ;
140
154
let mut input = vec ! [ 0u8 ; 64 ] ;
141
155
rng. fill_bytes ( & mut input) ;
142
- let ( token, alpha) = blind_with_postprocessing :: < _ , RistrettoPoint > (
143
- & input,
144
- & mut rng,
145
- std:: convert:: identity,
146
- )
147
- . unwrap ( ) ;
156
+ let ( token, alpha) =
157
+ blind :: < _ , RistrettoPoint > ( & input, & mut rng, std:: convert:: identity) . unwrap ( ) ;
148
158
let res = unblind_and_finalize :: < RistrettoPoint , sha2:: Sha256 > ( & token, alpha) . unwrap ( ) ;
149
159
150
160
let ( hashed_input, _) = Hkdf :: < Sha512 > :: extract ( Some ( STR_VOPRF ) , & input) ;
0 commit comments