@@ -470,10 +470,13 @@ impl MlKem {
470470 ss : & mut [ u8 ] ,
471471 rng : & mut RNG ,
472472 ) -> Result < ( ) , i32 > {
473+ // Verify the cipher text length is as expected based on the parameter
474+ // set (key type) in use.
473475 let expected_ct_size = self . cipher_text_size ( ) ?;
474476 if ct. len ( ) != expected_ct_size {
475477 return Err ( sys:: wolfCrypt_ErrorCodes_BUFFER_E) ;
476478 }
479+ // Verify the shared secret length is as expected.
477480 if ss. len ( ) != Self :: SHARED_SECRET_SIZE {
478481 return Err ( sys:: wolfCrypt_ErrorCodes_BUFFER_E) ;
479482 }
@@ -535,10 +538,13 @@ impl MlKem {
535538 if rand. len ( ) != Self :: ENC_RAND_SIZE {
536539 return Err ( sys:: wolfCrypt_ErrorCodes_BUFFER_E) ;
537540 }
541+ // Verify the cipher text length is as expected based on the parameter
542+ // set (key type) in use.
538543 let expected_ct_size = self . cipher_text_size ( ) ?;
539544 if ct. len ( ) != expected_ct_size {
540545 return Err ( sys:: wolfCrypt_ErrorCodes_BUFFER_E) ;
541546 }
547+ // Verify the shared secret length is as expected.
542548 if ss. len ( ) != Self :: SHARED_SECRET_SIZE {
543549 return Err ( sys:: wolfCrypt_ErrorCodes_BUFFER_E) ;
544550 }
@@ -598,6 +604,7 @@ impl MlKem {
598604 /// }
599605 /// ```
600606 pub fn decapsulate ( & mut self , ss : & mut [ u8 ] , ct : & [ u8 ] ) -> Result < ( ) , i32 > {
607+ // Verify the shared secret length is as expected.
601608 if ss. len ( ) != Self :: SHARED_SECRET_SIZE {
602609 return Err ( sys:: wolfCrypt_ErrorCodes_BUFFER_E) ;
603610 }
0 commit comments