Add ecdh and P256 bindings to bssl-crypto

Bug: 285223043
Change-Id: Ia997b9765476d05c58649ee49ebf04905e65c478
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60267
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
diff --git a/rust/bssl-crypto/src/lib.rs b/rust/bssl-crypto/src/lib.rs
index 99140b7..0ad352d 100644
--- a/rust/bssl-crypto/src/lib.rs
+++ b/rust/bssl-crypto/src/lib.rs
@@ -53,6 +53,13 @@
 /// Memory-manipulation operations.
 pub mod mem;
 
+/// Elliptic curve diffie-hellman operations.
+pub mod ecdh;
+
+pub(crate) mod bn;
+pub(crate) mod ec;
+pub(crate) mod pkey;
+
 #[cfg(test)]
 mod test_helpers;
 
@@ -111,7 +118,7 @@
 /// Implementations of `ForeignTypeRef` must guarantee the following:
 ///
 /// - `Self::from_ptr(x).as_ptr() == x`
-/// - `Self::from_mut_ptr(x).as_ptr() == x`
+/// - `Self::from_ptr_mut(x).as_ptr() == x`
 unsafe trait ForeignTypeRef: Sized {
     /// The raw C type.
     type CType;
@@ -144,3 +151,26 @@
         self as *const _ as *mut _
     }
 }
+
+/// A helper trait implemented by types which has an owned reference to foreign types.
+///
+/// # Safety
+///
+/// Implementations of `ForeignType` must guarantee the following:
+///
+/// - `Self::from_ptr(x).as_ptr() == x`
+unsafe trait ForeignType {
+    /// The raw C type.
+    type CType;
+
+    /// Constructs an instance of this type from its raw type.
+    ///
+    /// # Safety
+    ///
+    /// - `ptr` must be a valid, immutable, instance of `CType`.
+    /// - Ownership of `ptr` is passed to the implementation, and will free `ptr` when dropped.
+    unsafe fn from_ptr(ptr: *mut Self::CType) -> Self;
+
+    /// Returns a raw pointer to the wrapped value.
+    fn as_ptr(&self) -> *mut Self::CType;
+}