@@ -89,6 +89,7 @@ impl MlKemPrivateKey {
8989 ///
9090 /// The private key is a 64-byte seed. Keep it secret.
9191 pub fn generate ( algorithm : Algorithm ) -> Result < ( MlKemPublicKey , MlKemPrivateKey ) , ErrorStack > {
92+ mlkem_available ( ) ?;
9293 match algorithm {
9394 Algorithm :: MlKem768 => {
9495 let ( pk, sk) = MlKem768PrivateKey :: generate ( ) ?;
@@ -110,6 +111,7 @@ impl MlKemPrivateKey {
110111
111112impl MlKemPublicKey {
112113 pub fn from_slice ( algorithm : Algorithm , public_key : & [ u8 ] ) -> Result < Self , ErrorStack > {
114+ mlkem_available ( ) ?;
113115 match algorithm {
114116 Algorithm :: MlKem768 => Ok ( Self ( Either :: MlKem768 ( Box :: new (
115117 MlKem768PublicKey :: from_slice ( public_key) ?,
@@ -158,6 +160,7 @@ impl MlKemPrivateKey {
158160 algorithm : Algorithm ,
159161 private_seed : & MlKemPrivateKeySeed ,
160162 ) -> Result < Self , ErrorStack > {
163+ mlkem_available ( ) ?;
161164 match algorithm {
162165 Algorithm :: MlKem768 => Ok ( Self ( Either :: MlKem768 ( Box :: new (
163166 MlKem768PrivateKey :: from_seed ( private_seed) ?,
@@ -614,6 +617,15 @@ impl fmt::Debug for MlKem1024PublicKey {
614617 }
615618}
616619
620+ fn mlkem_available ( ) -> Result < ( ) , ErrorStack > {
621+ if SHARED_SECRET_BYTES != 32 || PRIVATE_KEY_SEED_BYTES != 64 {
622+ return Err ( ErrorStack :: internal_error_str (
623+ "ML-KEM is unavailable in this build" ,
624+ ) ) ;
625+ }
626+ Ok ( ( ) )
627+ }
628+
617629#[ cfg( test) ]
618630mod tests {
619631 use super :: * ;
0 commit comments