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