Skip to content

musig: Add warning to SecretNonce::dangerous_into_bytes about encoding instability #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/musig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ impl KeyAggCache {
/// thing that can or should be done with this nonce is to call [`Session::partial_sign`],
/// which will take ownership. This is to prevent accidental reuse of the nonce.
///
/// See the warning on [`Self::dangerous_into_bytes`] for more information about
/// See the warnings on [`Self::dangerous_into_bytes`] for more information about
/// the risks of non-standard workflows.
#[allow(missing_copy_implementations)]
#[derive(Debug)]
Expand Down Expand Up @@ -684,13 +684,20 @@ impl SecretNonce {
///
/// See <https://blockstream.com/2019/02/18/musig-a-new-multisignature-standard/>
/// for more details about these risks.
///
/// # Warning:
///
/// The underlying library, libsecp256k1, does not guarantee the byte format will be consistent
/// across versions or platforms. Special care should be taken to ensure the returned bytes are
/// only ever passed to `dangerous_from_bytes` from the same libsecp256k1 version, and the same
/// platform.
pub fn dangerous_into_bytes(self) -> [u8; secp256k1_sys::MUSIG_SECNONCE_SIZE] {
self.0.dangerous_into_bytes()
}

/// Function to create a new [`SecretNonce`] from a 32 byte array.
///
/// Refer to the warning on [`SecretNonce::dangerous_into_bytes`] for more details.
/// Refer to the warnings on [`SecretNonce::dangerous_into_bytes`] for more details.
pub fn dangerous_from_bytes(array: [u8; secp256k1_sys::MUSIG_SECNONCE_SIZE]) -> Self {
SecretNonce(ffi::MusigSecNonce::dangerous_from_bytes(array))
}
Expand Down
Loading