diff --git a/CHANGELOG.md b/CHANGELOG.md index aacd9f0f8..c77ae3136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ + +# 0.23.5 - 2022-12-05 + +* Backport [fix soundness issue with `preallocated_gen_new`](https://github.com/rust-bitcoin/rust-secp256k1/pull/548) + # 0.23.4 - 2022-07-14 * [Disable automatic rerandomization of contexts under WASM](https://github.com/rust-bitcoin/rust-secp256k1/pull/474) diff --git a/Cargo.toml b/Cargo.toml index de7ff34a3..85aa64060 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "secp256k1" -version = "0.23.4" +version = "0.23.5" authors = [ "Dawid Ciężarkiewicz ", "Andrew Poelstra " ] license = "CC0-1.0" diff --git a/src/context.rs b/src/context.rs index fca1dc4ef..098e9233e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -297,8 +297,22 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> { } } -impl<'buf, C: Context + 'buf> Secp256k1 { - /// Lets you create a context with preallocated buffer in a generic manner(sign/verify/all) +/// Trait marking that a particular context object internally points to +/// memory that must outlive `'a` +/// +/// # Safety +/// +/// This trait is used internally to gate which context markers can safely +/// be used with the `preallocated_gen_new` function. Do not implement it +/// on your own structures. +pub unsafe trait PreallocatedContext<'a> {} + +unsafe impl<'buf> PreallocatedContext<'buf> for AllPreallocated<'buf> {} +unsafe impl<'buf> PreallocatedContext<'buf> for SignOnlyPreallocated<'buf> {} +unsafe impl<'buf> PreallocatedContext<'buf> for VerifyOnlyPreallocated<'buf> {} + +impl<'buf, C: Context + PreallocatedContext<'buf>> Secp256k1 { + /// Lets you create a context with a preallocated buffer in a generic manner (sign/verify/all). pub fn preallocated_gen_new(buf: &'buf mut [AlignedType]) -> Result, Error> { #[cfg(target_arch = "wasm32")] ffi::types::sanity_checks_for_wasm(); diff --git a/src/ecdsa/serialized_signature.rs b/src/ecdsa/serialized_signature.rs index cbc3d00df..79ef92d35 100644 --- a/src/ecdsa/serialized_signature.rs +++ b/src/ecdsa/serialized_signature.rs @@ -45,7 +45,7 @@ impl PartialEq for SerializedSignature { impl AsRef<[u8]> for SerializedSignature { #[inline] fn as_ref(&self) -> &[u8] { - &*self + self } }