aboutsummaryrefslogtreecommitdiffstats
path: root/src/access
diff options
context:
space:
mode:
authorslopulus <slop@lassul.us>2026-11-17 19:57:56 +0100
committertv <tv@krebsco.de>2026-11-17 21:09:37 +0100
commita1e398621eec9472ad67f1eafeba9ff23b012c2f (patch)
treeadbbf48890e8f1129c8bf40b4145e16fd411b843 /src/access
parent393fb4d70fc6bf88debc4ca13d644ea7de9602f5 (diff)
keys: a party's key may be ecdsa-sha2-nistp256, its signature low-S only
A party's keys may be held where no file has them, in a Secure Enclave or a phone, and those are ECDSA keys on NIST P-256. Everywhere a party's key counts (a version's keys, a key set, the key an event is signed with) such a key is taken beside an Ed25519 one, spelled as `ssh-keygen` writes it, without a comment: `ecdsa-sha2-nistp256`, a space, and the base64 of its SSH encoding, its point uncompressed and on the curve. Its signature is SSHSIG as an Ed25519 one is, hashed with `sha512`, its inner signature over SHA-256 as SSH signs with such a key. ECDSA signatures are malleable: of `s` and the curve's order less `s`, both check. So the federation takes one spelling alone: `s` low, at most half the order, `r` and `s` each SSH's shortest mpint, and the blob reading back to itself as an Ed25519 one does. What anyone makes of a party's signature is then none, as before. The vectors are a key `ssh-keygen -t ecdsa -b 256` made, a first version naming it, and a write and a key set `ssh-keygen -Y sign` signed with it, each taken; the signature's high-S twin, which checks as ECDSA, and its `r` spelled longer are none. Ed25519 keys and signatures are spelled and checked as they were.
Diffstat (limited to 'src/access')
-rw-r--r--src/access/sshsig.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/access/sshsig.rs b/src/access/sshsig.rs
index e25d8a7..740a727 100644
--- a/src/access/sshsig.rs
+++ b/src/access/sshsig.rs
@@ -198,7 +198,12 @@ pub(crate) fn sign(key: &SigningKey, namespace: &str, message: &[u8]) -> String
}
/// What a signature is made over.
-fn signed_data(namespace: &[u8], reserved: &[u8], algorithm: &[u8], hash: &[u8]) -> Vec<u8> {
+pub(crate) fn signed_data(
+ namespace: &[u8],
+ reserved: &[u8],
+ algorithm: &[u8],
+ hash: &[u8],
+) -> Vec<u8> {
let mut signed = MAGIC.to_vec();
string(&mut signed, namespace);
string(&mut signed, reserved);
@@ -207,13 +212,14 @@ fn signed_data(namespace: &[u8], reserved: &[u8], algorithm: &[u8], hash: &[u8])
signed
}
-fn string(out: &mut Vec<u8>, bytes: &[u8]) {
+/// `bytes` as SSH's string: a big-endian `u32` length, then the bytes.
+pub(crate) fn string(out: &mut Vec<u8>, bytes: &[u8]) {
out.extend_from_slice(&(bytes.len() as u32).to_be_bytes());
out.extend_from_slice(bytes);
}
/// Reads SSH's encoding.
-struct Reader<'a>(&'a [u8]);
+pub(crate) struct Reader<'a>(pub(crate) &'a [u8]);
impl<'a> Reader<'a> {
fn u32(&mut self) -> Result<u32, String> {
@@ -222,7 +228,7 @@ impl<'a> Reader<'a> {
Ok(u32::from_be_bytes(*bytes))
}
- fn string(&mut self) -> Result<&'a [u8], String> {
+ pub(crate) fn string(&mut self) -> Result<&'a [u8], String> {
let length = self.u32()? as usize;
if self.0.len() < length {
return Err("cut short".to_owned());
@@ -232,7 +238,7 @@ impl<'a> Reader<'a> {
Ok(bytes)
}
- fn end(&self) -> Result<(), String> {
+ pub(crate) fn end(&self) -> Result<(), String> {
if self.0.is_empty() {
Ok(())
} else {