-
Notifications
You must be signed in to change notification settings - Fork 228
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
deps: Use ed25519-consensus instead of ed25519-dalek (#1067) #1245
Merged
mzabaluev
merged 6 commits into
informalsystems:main
from
penumbra-zone:ed25519-consensus-rebase
Jan 10, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c876b6e
deps: Use ed25519-consensus instead of ed25519-dalek (#1067)
thanethomson 174ec35
try clippy fix
hdevalence 0324f0c
try clippy fix
hdevalence a2b6fb5
try clippy fix
hdevalence e39ee1c
use exhaustive match
hdevalence 58d87b4
another round of clippy fixes
hdevalence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
.changelog/unreleased/dependencies/1046-ed25519-consensus-dep.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- `[tendermint, tendermint-p2p]` Replaced the `ed25519-dalek` dependency with | ||
`ed25519-consensus` | ||
([#1046](https://github.com/informalsystems/tendermint-rs/pull/1046)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
//! Cryptographic private keys | ||
|
||
pub use ed25519_dalek::{Keypair as Ed25519, EXPANDED_SECRET_KEY_LENGTH as ED25519_KEYPAIR_SIZE}; | ||
pub use ed25519_consensus::SigningKey as Ed25519; | ||
|
||
use crate::prelude::*; | ||
use crate::public_key::PublicKey; | ||
use ed25519_consensus::VerificationKey; | ||
use serde::{de, ser, Deserialize, Serialize}; | ||
use subtle_encoding::{Base64, Encoding}; | ||
use zeroize::Zeroizing; | ||
|
||
use crate::{prelude::*, public_key::PublicKey}; | ||
pub const ED25519_KEYPAIR_SIZE: usize = 64; | ||
|
||
/// Private keys as parsed from configuration files | ||
#[derive(Serialize, Deserialize)] | ||
|
@@ -25,24 +29,28 @@ impl PrivateKey { | |
/// Get the public key associated with this private key | ||
pub fn public_key(&self) -> PublicKey { | ||
match self { | ||
PrivateKey::Ed25519(private_key) => private_key.public.into(), | ||
PrivateKey::Ed25519(signing_key) => PublicKey::Ed25519(signing_key.verification_key()), | ||
} | ||
} | ||
|
||
/// If applicable, borrow the Ed25519 keypair | ||
pub fn ed25519_keypair(&self) -> Option<&Ed25519> { | ||
pub fn ed25519_signing_key(&self) -> Option<&Ed25519> { | ||
match self { | ||
PrivateKey::Ed25519(keypair) => Some(keypair), | ||
PrivateKey::Ed25519(signing_key) => Some(signing_key), | ||
} | ||
} | ||
} | ||
|
||
/// Serialize an Ed25519 keypair as Base64 | ||
fn serialize_ed25519_keypair<S>(keypair: &Ed25519, serializer: S) -> Result<S::Ok, S::Error> | ||
fn serialize_ed25519_keypair<S>(signing_key: &Ed25519, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: ser::Serializer, | ||
{ | ||
let keypair_bytes = Zeroizing::new(keypair.to_bytes()); | ||
// Tendermint uses a serialization format inherited from Go that includes | ||
// a cached copy of the public key as the second half. | ||
let mut keypair_bytes = Zeroizing::new([0u8; ED25519_KEYPAIR_SIZE]); | ||
keypair_bytes[0..32].copy_from_slice(signing_key.as_bytes()); | ||
keypair_bytes[32..64].copy_from_slice(signing_key.verification_key().as_bytes()); | ||
Zeroizing::new(String::from_utf8(Base64::default().encode(&keypair_bytes[..])).unwrap()) | ||
.serialize(serializer) | ||
} | ||
|
@@ -63,5 +71,17 @@ where | |
return Err(D::Error::custom("invalid Ed25519 keypair size")); | ||
} | ||
|
||
Ed25519::from_bytes(&*keypair_bytes).map_err(D::Error::custom) | ||
// Tendermint uses a serialization format inherited from Go that includes a | ||
// cached copy of the public key as the second half. This is somewhat | ||
// dangerous, since there's no validation that the two parts are consistent | ||
// with each other, so we ignore the second half and just check consistency | ||
// with the re-derived data. | ||
let signing_key = Ed25519::try_from(&keypair_bytes[0..32]) | ||
.map_err(|_| D::Error::custom("invalid signing key"))?; | ||
let verification_key = VerificationKey::from(&signing_key); | ||
if &keypair_bytes[32..64] != verification_key.as_bytes() { | ||
return Err(D::Error::custom("keypair mismatch")); | ||
} | ||
Comment on lines
+74
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
|
||
Ok(signing_key) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is deliberately opaque, but we can't make the
Display
impl transparent in flex-error, so we have our own message. OK.