@@ -488,10 +488,11 @@ impl State {
488488 } ) ?;
489489
490490 // Select signature/hash for SKE by intersecting client's list
491- // with our key type (prefer SHA256, then SHA384)
491+ // with our key type, preferring the key's native hash algorithm
492492 let selected_signature = select_ske_signature_algorithm (
493493 server. client_signature_algorithms . as_ref ( ) ,
494494 server. engine . crypto_context ( ) . signature_algorithm ( ) ,
495+ server. engine . crypto_context ( ) . private_key_default_hash_algorithm ( ) ,
495496 ) ;
496497
497498 debug ! (
@@ -1182,9 +1183,13 @@ mod tests {
11821183fn select_ske_signature_algorithm (
11831184 client_algs : Option < & SignatureAndHashAlgorithmVec > ,
11841185 our_sig : SignatureAlgorithm ,
1186+ our_hash : HashAlgorithm ,
11851187) -> SignatureAndHashAlgorithm {
1186- // Our hash preference order
1187- let hash_pref = [ HashAlgorithm :: SHA256 , HashAlgorithm :: SHA384 ] ;
1188+ // Prefer the key's native hash first, then fall back to the other
1189+ let hash_pref = match our_hash {
1190+ HashAlgorithm :: SHA384 => [ HashAlgorithm :: SHA384 , HashAlgorithm :: SHA256 ] ,
1191+ _ => [ HashAlgorithm :: SHA256 , HashAlgorithm :: SHA384 ] ,
1192+ } ;
11881193
11891194 if let Some ( list) = client_algs {
11901195 for h in hash_pref. iter ( ) {
@@ -1197,17 +1202,8 @@ fn select_ske_signature_algorithm(
11971202 }
11981203 }
11991204
1200- // Fallback to our default hash for our key type
1201- let hash = engine_default_hash_for_sig ( our_sig) ;
1202- SignatureAndHashAlgorithm :: new ( hash, our_sig)
1203- }
1204-
1205- fn engine_default_hash_for_sig ( sig : SignatureAlgorithm ) -> HashAlgorithm {
1206- match sig {
1207- SignatureAlgorithm :: RSA => HashAlgorithm :: SHA256 ,
1208- SignatureAlgorithm :: ECDSA => HashAlgorithm :: SHA256 ,
1209- _ => HashAlgorithm :: SHA256 ,
1210- }
1205+ // Fallback: use the key's native hash
1206+ SignatureAndHashAlgorithm :: new ( our_hash, our_sig)
12111207}
12121208
12131209fn select_certificate_request_sig_algs (
0 commit comments