Convert curve name to rustls key exchange group Maps OpenSSL curve names (e.g., "prime256v1", "secp384r1") to rustls KxGroups. Returns an error if the curve is not supported by rustls.
(
curve: &str,
)
| 2362 | /// Maps OpenSSL curve names (e.g., "prime256v1", "secp384r1") to rustls KxGroups. |
| 2363 | /// Returns an error if the curve is not supported by rustls. |
| 2364 | pub(super) fn curve_name_to_kx_group( |
| 2365 | curve: &str, |
| 2366 | ) -> Result<Vec<&'static dyn SupportedKxGroup>, String> { |
| 2367 | // Get the default crypto provider's key exchange groups |
| 2368 | let provider = rustls::crypto::aws_lc_rs::default_provider(); |
| 2369 | let all_groups = &provider.kx_groups; |
| 2370 | |
| 2371 | match curve { |
| 2372 | // P-256 (also known as secp256r1 or prime256v1) |
| 2373 | "prime256v1" | "secp256r1" => { |
| 2374 | // Find SECP256R1 in the provider's groups |
| 2375 | all_groups |
| 2376 | .iter() |
| 2377 | .find(|g| g.name() == rustls::NamedGroup::secp256r1) |
| 2378 | .map(|g| vec![*g]) |
| 2379 | .ok_or_else(|| "secp256r1 not supported by crypto provider".to_owned()) |
| 2380 | } |
| 2381 | // P-384 (also known as secp384r1 or prime384v1) |
| 2382 | "secp384r1" | "prime384v1" => all_groups |
| 2383 | .iter() |
| 2384 | .find(|g| g.name() == rustls::NamedGroup::secp384r1) |
| 2385 | .map(|g| vec![*g]) |
| 2386 | .ok_or_else(|| "secp384r1 not supported by crypto provider".to_owned()), |
| 2387 | // X25519 |
| 2388 | "X25519" | "x25519" => all_groups |
| 2389 | .iter() |
| 2390 | .find(|g| g.name() == rustls::NamedGroup::X25519) |
| 2391 | .map(|g| vec![*g]) |
| 2392 | .ok_or_else(|| "X25519 not supported by crypto provider".to_owned()), |
| 2393 | // P-521 (also known as secp521r1 or prime521v1) |
| 2394 | // Now supported with aws-lc-rs crypto provider |
| 2395 | "prime521v1" | "secp521r1" => all_groups |
| 2396 | .iter() |
| 2397 | .find(|g| g.name() == rustls::NamedGroup::secp521r1) |
| 2398 | .map(|g| vec![*g]) |
| 2399 | .ok_or_else(|| "secp521r1 not supported by crypto provider".to_owned()), |
| 2400 | // X448 |
| 2401 | // Now supported with aws-lc-rs crypto provider |
| 2402 | "X448" | "x448" => all_groups |
| 2403 | .iter() |
| 2404 | .find(|g| g.name() == rustls::NamedGroup::X448) |
| 2405 | .map(|g| vec![*g]) |
| 2406 | .ok_or_else(|| "X448 not supported by crypto provider".to_owned()), |
| 2407 | _ => Err(format!("unknown curve name '{curve}'")), |
| 2408 | } |
| 2409 | } |
no test coverage detected