Skip to content

Commit

Permalink
crypto: Signature of all zero bytes should be Unknown
Browse files Browse the repository at this point in the history
Currently defaults to Ed25519, which does not match octez reference
  • Loading branch information
emturner committed Dec 20, 2023
1 parent b7bf966 commit e1273b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ parameterized by the lifetime of the input byte slice.
- Add explicit prefix check during base58check decoding.
- Hash input before signing with `SecretKeyEd25519`, to match octez impl.
- Fix `BlsSignature` base58 check encoding/decoding.
- Fix all zeros signature encoding: should be `Unknown` rather than defaulting to `Ed25519`.

### Security

Expand Down
8 changes: 2 additions & 6 deletions crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,8 @@ impl HashType {
Err(FromBytesError::InvalidSize)
} else {
let mut hash = Vec::with_capacity(self.base58check_prefix().len() + data.len());
if matches!(self, Self::UnknownSignature) && data == [0; Self::Ed25519Signature.size()]
{
hash.extend(Self::Ed25519Signature.base58check_prefix());
} else {
hash.extend(self.base58check_prefix());
}

hash.extend(self.base58check_prefix());
hash.extend(data);
hash.to_base58check()
// currently the error is returned if the input lenght exceeds 128 bytes
Expand Down
11 changes: 11 additions & 0 deletions crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ impl ::std::fmt::Display for Signature {
write!(f, "{}", self.to_base58_check())
}
}

#[cfg(test)]
mod test {
#[test]
fn test() {
assert_eq!(
&super::Signature::try_from([0; 64].to_vec()).unwrap().to_base58_check(),
"sigMzJ4GVAvXEd2RjsKGfG2H9QvqTSKCZsuB2KiHbZRGFz72XgF6KaKADznh674fQgBatxw3xdHqTtMHUZAGRprxy64wg1aq"
);
}
}

0 comments on commit e1273b0

Please sign in to comment.