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

feat!: expose secret key length as a constant #181

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
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: 10 additions & 4 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
pub trait SecretKey:
ByteArray + Clone + PartialEq + Eq + Add<Output = Self> + Default + Zeroize + ZeroizeOnDrop
{
/// The length of the key, in bytes
fn key_length() -> usize;
/// The length of the byte encoding of a key, in bytes
const KEY_LEN: usize;

/// The length of the byte encoding of a key, in bytes
fn key_length() -> usize {
Self::KEY_LEN
}

/// Generates a random secret key
fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self;
}
Expand All @@ -45,7 +51,7 @@ pub trait SecretKey:
pub trait PublicKey:
ByteArray + Add<Output = Self> + Clone + PartialOrd + Ord + Default + Serialize + DeserializeOwned + Zeroize
{
/// The output size len of Public Key
/// The length of the byte encoding of a key, in bytes
const KEY_LEN: usize;

/// The related [SecretKey](trait.SecretKey.html) type
Expand All @@ -55,7 +61,7 @@ pub trait PublicKey:
/// failure does occur (implementation error?), the function will panic.
fn from_secret_key(k: &Self::K) -> Self;

/// The length of the public key when converted to bytes
/// The length of the byte encoding of a key, in bytes
fn key_length() -> usize {
Self::KEY_LEN
}
Expand Down
9 changes: 2 additions & 7 deletions src/ristretto/ristretto_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ impl borsh::BorshDeserialize for RistrettoSecretKey {
}
}

const SCALAR_LENGTH: usize = 32;
const PUBLIC_KEY_LENGTH: usize = 32;

//----------------------------------------- Ristretto Secret Key ------------------------------------------------//
impl SecretKey for RistrettoSecretKey {
fn key_length() -> usize {
SCALAR_LENGTH
}
const KEY_LEN: usize = 32;

/// Return a random secret key on the `ristretto255` curve using the supplied CSPRNG.
fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self {
Expand Down Expand Up @@ -364,7 +359,7 @@ impl DomainSeparation for RistrettoGeneratorPoint {
impl PublicKey for RistrettoPublicKey {
type K = RistrettoSecretKey;

const KEY_LEN: usize = PUBLIC_KEY_LENGTH;
const KEY_LEN: usize = 32;

/// Generates a new Public key from the given secret key
fn from_secret_key(k: &Self::K) -> RistrettoPublicKey {
Expand Down