diff options
Diffstat (limited to 'src/federation/keys.rs')
| -rw-r--r-- | src/federation/keys.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/federation/keys.rs b/src/federation/keys.rs index a795db7..fa13ec4 100644 --- a/src/federation/keys.rs +++ b/src/federation/keys.rs @@ -254,6 +254,23 @@ fn written(key: &Key, signature: &[u8]) -> Vec<u8> { blob } +/// Of `sig`, an ECDSA signature by `key` as the federation spells it, two others of the +/// same key and message that check as SSH checks them: `s` high, the order less `s`; and +/// `r` with a zero byte more in front, the same number to SSH. +#[cfg(test)] +pub(crate) fn respelled(key: &Key, sig: &str) -> [String; 2] { + let blob = BASE64.decode(sig).expect("base64"); + let rs = &blob[written(key, &[]).len()..]; + let (r, s) = ecdsa_signature(rs).expect("r and s").split_scalars(); + let high = p256::ecdsa::Signature::from_scalars(r, -s).expect("a signature"); + let mut reader = Reader(rs); + let (r, s) = (reader.string().expect("r"), reader.string().expect("s")); + let mut longer = Vec::new(); + string(&mut longer, &[&[0], r].concat()); + string(&mut longer, s); + [mpints(&high), longer].map(|numbers| BASE64.encode(written(key, &numbers))) +} + #[cfg(test)] mod tests { use super::*; |
