Skip to content
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

Add byte accessors to ElligatorSwiftSharedSecret #676

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
14 changes: 14 additions & 0 deletions src/ellswift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,20 @@ impl ElligatorSwift {
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ElligatorSwiftSharedSecret([u8; 32]);

impl ElligatorSwiftSharedSecret {
/// Creates shared secret from bytes.
///
/// This is generally not needed except for unusual cases like restoring the secret from a
/// database.
pub const fn from_secret_bytes(bytes: [u8; 32]) -> Self { Self(bytes) }

/// Returns the secret bytes as an array.
pub const fn to_secret_bytes(self) -> [u8; 32] { self.0 }

/// Returns the secret bytes as a reference to an array.
pub const fn as_secret_bytes(&self) -> &[u8; 32] { &self.0 }
}

/// Represents which party we are in the ECDH, A is the initiator, B is the responder.
/// This is important because the hash of the shared secret is different depending on which party
/// we are. In this context, "we" means the party that is using this library, and possesses the
Expand Down
Loading