Reworking bssl_crypto: digest

Change-Id: I43de22995908ea39b19aa03d167c62a9580ba7b1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/65168
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Maurice Lam <yukl@google.com>
diff --git a/rust/bssl-crypto/src/lib.rs b/rust/bssl-crypto/src/lib.rs
index 022f5a3..dea522f 100644
--- a/rust/bssl-crypto/src/lib.rs
+++ b/rust/bssl-crypto/src/lib.rs
@@ -30,6 +30,9 @@
 
 use core::ffi::c_void;
 
+#[macro_use]
+mod macros;
+
 /// Authenticated Encryption with Additional Data algorithms.
 pub mod aead;
 
@@ -39,7 +42,6 @@
 /// Ciphers.
 pub mod cipher;
 
-/// Hash functions.
 pub mod digest;
 
 /// Ed25519, a signature scheme.
@@ -247,6 +249,20 @@
     fn as_ptr(&self) -> *mut Self::CType;
 }
 
+/// Returns a BoringSSL structure that is initialized by some function.
+/// Requires that the given function completely initializes the value.
+///
+/// (Tagged `unsafe` because a no-op argument would otherwise expose
+/// uninitialized memory.)
+unsafe fn initialized_struct<T, F>(init: F) -> T
+where
+    F: FnOnce(*mut T),
+{
+    let mut out_uninit = core::mem::MaybeUninit::<T>::uninit();
+    init(out_uninit.as_mut_ptr());
+    unsafe { out_uninit.assume_init() }
+}
+
 /// Wrap a closure that initializes an output buffer and return that buffer as
 /// an array. Requires that the closure fully initialize the given buffer.
 ///
@@ -290,3 +306,8 @@
         None
     }
 }
+
+/// Used to prevent external implementations of internal traits.
+mod sealed {
+    pub struct Sealed;
+}