Skip to content

Commit

Permalink
Add support for Ed25519 signing with composite key
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Jul 11, 2024
1 parent 4203a31 commit 031eda4
Showing 1 changed file with 14 additions and 5 deletions.
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

0 comments on commit 031eda4

Please sign in to comment.