Fix SSH X25519 shared secret encoding for exchange hash

CRITICAL BUG FIX (RFC 8731 Section 3.1):
- X25519 output is little-endian
- SSH exchange hash requires big-endian encoding
- Reverse shared_secret bytes before mpint encoding
- Fix exchange hash computation in kex_exchange.rs
- Fix key derivation in crypto.rs
- Fix KEXINIT cookie to use random bytes

This resolves the fundamental encoding mismatch that caused
'Corrupted MAC on input' errors.

Next: verify signature verification after exchange hash fix.
This commit is contained in:
Warren
2026-06-14 19:13:18 +08:00
parent 0403a340c4
commit 76f707a31d
4 changed files with 66 additions and 35 deletions

View File

@@ -97,8 +97,9 @@ impl KexProposal {
payload.write_u8(PacketType::SSH_MSG_KEXINIT as u8)?;
// Cookie16字节随机数OpenSSH要求
// 简化:使用固定值(实际应随机生成)
let cookie = [0u8; 16];
let mut cookie = [0u8; 16];
use rand::Rng;
rand::thread_rng().fill(&mut cookie);
payload.write_all(&cookie)?;
// 10个算法列表SSH string格式length + data