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 support for Ed25519 signing with composite key #265

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 14 additions & 5 deletions crates/web5/src/crypto/dsa/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,21 @@ impl Signer for Ed25519Signer {
.as_ref()
.ok_or(DsaError::MissingPrivateKey)?;
let decoded_d = general_purpose::URL_SAFE_NO_PAD.decode(d)?;
if decoded_d.len() != SECRET_KEY_LENGTH {

// some implementations of ed25519 couple the public key alongside the private key
// in which case, we need to splice out only the private key bytes
let signing_key = if decoded_d.len() == 64 {
let mut key_array = [0u8; 32];
key_array.copy_from_slice(&decoded_d[..32]);
SigningKey::from_bytes(&key_array)
} else if decoded_d.len() == 32 {
let mut key_array = [0u8; 32];
key_array.copy_from_slice(&decoded_d);
SigningKey::from_bytes(&key_array)
} else {
return Err(DsaError::InvalidKeyLength(SECRET_KEY_LENGTH.to_string()));
}
let mut key_array = [0u8; 32];
key_array.copy_from_slice(&decoded_d);
let signing_key = SigningKey::from_bytes(&key_array);
};

let signature = signing_key.sign(payload);
Ok(signature.to_vec())
}
Expand Down
Loading