@@ -220,6 +220,12 @@ pub enum Error {
220220#[ derive( Copy , Clone , Serialize , Deserialize ) ]
221221struct EncapsulationKeyBytes ( #[ serde( with = "serde_bytes" ) ] [ u8 ; ENCAPSULATION_KEY_LEN ] ) ;
222222
223+ impl From < & EncapsulationKey > for EncapsulationKeyBytes {
224+ fn from ( ek : & EncapsulationKey ) -> Self {
225+ Self ( ek. to_bytes ( ) )
226+ }
227+ }
228+
223229impl ConditionallySelectable for EncapsulationKeyBytes {
224230 fn conditional_select ( a : & Self , b : & Self , choice : Choice ) -> Self {
225231 Self ( <[ u8 ; ENCAPSULATION_KEY_LEN ] >:: conditional_select (
@@ -310,18 +316,21 @@ impl RotSender for MlKemOt {
310316 . zip ( receiver_msg. eks1 . iter ( ) )
311317 . enumerate ( )
312318 {
313- // Reconstruct encapsulation keys: ek_j = r_j + H(r_{1-j})
319+ // Step 5: Receive (r_0, r_1) from the receiver (done above).
314320 let r0 = EncapsulationKey :: from_bytes ( & r0_bytes. 0 ) ;
315321 let r1 = EncapsulationKey :: from_bytes ( & r1_bytes. 0 ) ;
316322
323+ // Step 6: Reconstruct encapsulation keys: ek_j = r_j + H(r_{1-j}).
317324 let ek0 = & r0 + & hash_to_key ( & r1) ;
318325 let ek1 = & r1 + & hash_to_key ( & r0) ;
319326
320- let ( ct0, key0) = encapsulate ( & EncapsulationKeyBytes ( ek0. to_bytes ( ) ) , & mut self . rng ) ;
321- let key0 = hash ( & key0, i) ;
327+ // Step 7: Encapsulate to both reconstructed keys.
328+ let ( ct0, ss0) = encapsulate ( & ( & ek0) . into ( ) , & mut self . rng ) ;
329+ let ( ct1, ss1) = encapsulate ( & ( & ek1) . into ( ) , & mut self . rng ) ;
322330
323- let ( ct1, key1) = encapsulate ( & EncapsulationKeyBytes ( ek1. to_bytes ( ) ) , & mut self . rng ) ;
324- let key1 = hash ( & key1, i) ;
331+ // Step 8: Derive OT output keys.
332+ let key0 = hash ( & ss0, i) ;
333+ let key1 = hash ( & ss1, i) ;
325334
326335 cts0. push ( ct0) ;
327336 cts1. push ( ct1) ;
@@ -372,10 +381,8 @@ impl RotReceiver for MlKemOt {
372381
373382 // Step 3: Compute correlated key: r_b = ek - H(r_{1-b}).
374383 let r_b = & ek - & hash_to_key ( & r_1_b) ;
375-
376- // Serialize both keys.
377- let r_b_bytes = EncapsulationKeyBytes ( r_b. to_bytes ( ) ) ;
378- let r_1_b_bytes = EncapsulationKeyBytes ( r_1_b. to_bytes ( ) ) ;
384+ let r_b_bytes: EncapsulationKeyBytes = ( & r_b) . into ( ) ;
385+ let r_1_b_bytes: EncapsulationKeyBytes = ( & r_1_b) . into ( ) ;
379386
380387 // Step 4: Select (r_0, r_1) based on choice bit (constant-time).
381388 // If b=0: r_0 = real, r_1 = random.
0 commit comments