@@ -16,7 +16,6 @@ use chacha20poly1305::{
16
16
aead:: { generic_array:: GenericArray , AeadInPlace , NewAead } ,
17
17
ChaCha20Poly1305 ,
18
18
} ;
19
- use ed25519_dalek:: { self as ed25519, Signer , Verifier } ;
20
19
use merlin:: Transcript ;
21
20
use rand_core:: OsRng ;
22
21
use subtle:: ConstantTimeEq ;
@@ -61,7 +60,7 @@ pub struct Handshake<S> {
61
60
62
61
/// `AwaitingEphKey` means we're waiting for the remote ephemeral pubkey.
63
62
pub struct AwaitingEphKey {
64
- local_privkey : ed25519 :: Keypair ,
63
+ local_privkey : ed25519_consensus :: SigningKey ,
65
64
local_eph_privkey : Option < EphemeralSecret > ,
66
65
}
67
66
@@ -71,15 +70,15 @@ pub struct AwaitingAuthSig {
71
70
kdf : Kdf ,
72
71
recv_cipher : ChaCha20Poly1305 ,
73
72
send_cipher : ChaCha20Poly1305 ,
74
- local_signature : ed25519 :: Signature ,
73
+ local_signature : ed25519_consensus :: Signature ,
75
74
}
76
75
77
76
#[ allow( clippy:: use_self) ]
78
77
impl Handshake < AwaitingEphKey > {
79
78
/// Initiate a handshake.
80
79
#[ must_use]
81
80
pub fn new (
82
- local_privkey : ed25519 :: Keypair ,
81
+ local_privkey : ed25519_consensus :: SigningKey ,
83
82
protocol_version : Version ,
84
83
) -> ( Self , EphemeralPublic ) {
85
84
// Generate an ephemeral key for perfect forward secrecy.
@@ -151,9 +150,9 @@ impl Handshake<AwaitingEphKey> {
151
150
152
151
// Sign the challenge bytes for authentication.
153
152
let local_signature = if self . protocol_version . has_transcript ( ) {
154
- sign_challenge ( & sc_mac , & self . state . local_privkey ) ?
153
+ self . state . local_privkey . sign ( & sc_mac )
155
154
} else {
156
- sign_challenge ( & kdf . challenge , & self . state . local_privkey ) ?
155
+ self . state . local_privkey . sign ( & kdf . challenge )
157
156
} ;
158
157
159
158
Ok ( Handshake {
@@ -186,22 +185,23 @@ impl Handshake<AwaitingAuthSig> {
186
185
187
186
let remote_pubkey = match pk_sum {
188
187
proto:: crypto:: public_key:: Sum :: Ed25519 ( ref bytes) => {
189
- ed25519:: PublicKey :: from_bytes ( bytes) . map_err ( Error :: signature)
188
+ ed25519_consensus:: VerificationKey :: try_from ( & bytes[ ..] )
189
+ . map_err ( |_| Error :: signature ( ) )
190
190
} ,
191
191
proto:: crypto:: public_key:: Sum :: Secp256k1 ( _) => Err ( Error :: unsupported_key ( ) ) ,
192
192
} ?;
193
193
194
- let remote_sig =
195
- ed25519 :: Signature :: try_from ( auth_sig_msg . sig . as_slice ( ) ) . map_err ( Error :: signature) ?;
194
+ let remote_sig = ed25519_consensus :: Signature :: try_from ( auth_sig_msg . sig . as_slice ( ) )
195
+ . map_err ( |_| Error :: signature ( ) ) ?;
196
196
197
197
if self . protocol_version . has_transcript ( ) {
198
198
remote_pubkey
199
- . verify ( & self . state . sc_mac , & remote_sig )
200
- . map_err ( Error :: signature) ?;
199
+ . verify ( & remote_sig , & self . state . sc_mac )
200
+ . map_err ( |_| Error :: signature ( ) ) ?;
201
201
} else {
202
202
remote_pubkey
203
- . verify ( & self . state . kdf . challenge , & remote_sig )
204
- . map_err ( Error :: signature) ?;
203
+ . verify ( & remote_sig , & self . state . kdf . challenge )
204
+ . map_err ( |_| Error :: signature ( ) ) ?;
205
205
}
206
206
207
207
// We've authorized.
@@ -279,7 +279,7 @@ impl<IoHandler: Read + Write + Send + Sync> SecretConnection<IoHandler> {
279
279
/// * if receiving the signature fails
280
280
pub fn new (
281
281
mut io_handler : IoHandler ,
282
- local_privkey : ed25519 :: Keypair ,
282
+ local_privkey : ed25519_consensus :: SigningKey ,
283
283
protocol_version : Version ,
284
284
) -> Result < Self , Error > {
285
285
// Start a handshake process.
@@ -470,20 +470,12 @@ fn share_eph_pubkey<IoHandler: Read + Write + Send + Sync>(
470
470
protocol_version. decode_initial_handshake ( & buf)
471
471
}
472
472
473
- /// Sign the challenge with the local private key
474
- fn sign_challenge (
475
- challenge : & [ u8 ; 32 ] ,
476
- local_privkey : & dyn Signer < ed25519:: Signature > ,
477
- ) -> Result < ed25519:: Signature , Error > {
478
- local_privkey. try_sign ( challenge) . map_err ( Error :: signature)
479
- }
480
-
481
473
// TODO(ismail): change from DecodeError to something more generic
482
474
// this can also fail while writing / sending
483
475
fn share_auth_signature < IoHandler : Read + Write + Send + Sync > (
484
476
sc : & mut SecretConnection < IoHandler > ,
485
- pubkey : & ed25519 :: PublicKey ,
486
- local_signature : & ed25519 :: Signature ,
477
+ pubkey : & ed25519_consensus :: VerificationKey ,
478
+ local_signature : & ed25519_consensus :: Signature ,
487
479
) -> Result < proto:: p2p:: AuthSigMessage , Error > {
488
480
let buf = sc
489
481
. protocol_version
0 commit comments