Gate Rust support for ML-{KEM,DSA} on a crate feature.

These algorithms depend on `new_uninit`, which was only made stable with
Rust 1.82. To allow consumers to catch up, this change gates
ML-{KEM,DSA} support in `bssl-crypto` behind a (non-default) feature.

Change-Id: I6ffe60560a4dc0f802564c56498f6a0a073d94da
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75027
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: Adam Langley <agl@google.com>
diff --git a/rust/bssl-crypto/Cargo.toml b/rust/bssl-crypto/Cargo.toml
index 755da8c..0284015 100644
--- a/rust/bssl-crypto/Cargo.toml
+++ b/rust/bssl-crypto/Cargo.toml
@@ -10,4 +10,8 @@
 
 [features]
 default = []
+# `std` depends on the Rust `std` crate, but adds some useful trait impls if
+# available.
 std = []
+# `mlalgs` enables ML-KEM and ML-DSA support. This requires Rust 1.82.
+mlalgs = []
diff --git a/rust/bssl-crypto/src/lib.rs b/rust/bssl-crypto/src/lib.rs
index bd68760..d1abb93 100644
--- a/rust/bssl-crypto/src/lib.rs
+++ b/rust/bssl-crypto/src/lib.rs
@@ -28,7 +28,10 @@
 extern crate alloc;
 extern crate core;
 
-use alloc::{boxed::Box, vec::Vec};
+#[cfg(feature = "mlalgs")]
+use alloc::boxed::Box;
+
+use alloc::vec::Vec;
 use core::ffi::c_void;
 
 #[macro_use]
@@ -48,7 +51,9 @@
 pub mod hkdf;
 pub mod hmac;
 pub mod hpke;
+#[cfg(feature = "mlalgs")]
 pub mod mldsa;
+#[cfg(feature = "mlalgs")]
 pub mod mlkem;
 pub mod rsa;
 pub mod slhdsa;
@@ -247,6 +252,7 @@
 /// Requires that the given function completely initializes the value.
 ///
 /// Safety: the argument must fully initialize the pointed-to `T`.
+#[cfg(feature = "mlalgs")]
 unsafe fn initialized_boxed_struct<T, F>(init: F) -> Box<T>
 where
     F: FnOnce(*mut T),
@@ -262,6 +268,7 @@
 ///
 /// Safety: the argument must fully initialize the pointed-to `T` if it returns
 /// true. If it returns false then there are no safety requirements.
+#[cfg(feature = "mlalgs")]
 unsafe fn initialized_boxed_struct_fallible<T, F>(init: F) -> Option<Box<T>>
 where
     F: FnOnce(*mut T) -> bool,
@@ -398,6 +405,7 @@
     }
 }
 
+#[cfg(feature = "mlalgs")]
 fn as_cbs(buf: &[u8]) -> bssl_sys::CBS {
     bssl_sys::CBS {
         data: buf.as_ffi_ptr(),
@@ -455,6 +463,7 @@
     unsafe { Buffer::new(ptr, len) }
 }
 
+#[cfg(feature = "mlalgs")]
 /// Calls `func` with a `CBB` pointer that has been initialized to a vector
 /// of `len` bytes. That function must write exactly `len` bytes to the
 /// `CBB`. Those bytes are then returned as a vector.