Skip to content

Commit

Permalink
Merge #559: Backport and bump 0.24.2
Browse files Browse the repository at this point in the history
5c6225e Bump version to 0.24.2 (Tobin C. Harding)
0a696b2 Add saftey docs for PreallocatedContext trait (Tobin C. Harding)
dd194b6 context: introduce unsafe `PreallocatedContext` trait (Andrew Poelstra)

Pull request description:

  I believe this is what tcharding meant by #558

ACKs for top commit:
  apoelstra:
    utACK 5c6225e

Tree-SHA512: 54cac9bd146e9dd32cf28f3a914053c7a68e99756e29431e0324691b2ef803dac044bb7002183c2773e042ac5f34f3a43646e46823bc1349ffb34f2eaa4c42a6
  • Loading branch information
apoelstra committed Dec 7, 2022
2 parents 15a8c20 + 5c6225e commit 959bd25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@

# 0.24.2 - 2022-12-05

* Backport [fix soundness issue with `preallocated_gen_new`](https://github.com/rust-bitcoin/rust-secp256k1/pull/548)

# 0.24.1 - 2022-10-25

* [Fix broken deserialization logic of `KeyPair`](https://github.com/rust-bitcoin/rust-secp256k1/issues/491) that previously always panicked. After the patch deserialization only panics if neither the `global-context` nor the `alloc` (default) feature is active.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "secp256k1"
version = "0.24.1"
version = "0.24.2"
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
"Andrew Poelstra <apoelstra@wpsoftware.net>" ]
license = "CC0-1.0"
Expand Down
18 changes: 16 additions & 2 deletions src/context.rs
Expand Up @@ -300,8 +300,22 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
}
}

impl<'buf, C: Context + 'buf> Secp256k1<C> {
/// 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<C> {
/// 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<Secp256k1<C>, Error> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();
Expand Down

0 comments on commit 959bd25

Please sign in to comment.