@@ -3,22 +3,22 @@ use openssl::derive::Deriver;
3
3
use openssl:: ec:: { EcGroup , EcKey , EcPoint , PointConversionForm } ;
4
4
use openssl:: error:: ErrorStack ;
5
5
use openssl:: nid:: Nid ;
6
- #[ cfg( feature = "x25519" ) ]
6
+ #[ cfg( not ( feature = "fips" ) ) ]
7
7
use openssl:: pkey:: Id ;
8
8
use openssl:: pkey:: { PKey , Private , Public } ;
9
9
use rustls:: crypto:: { ActiveKeyExchange , SharedSecret , SupportedKxGroup } ;
10
10
use rustls:: { Error , NamedGroup } ;
11
11
12
- /// Supported ` KeyExchange` groups.
13
- /// ```ignore
14
- /// SECP384R1
15
- /// SECP256R1
16
- /// X25519 // Enabled with the `x25519` feature
17
- /// ```
12
+ /// [ Supported KeyExchange groups](SupportedKxGroup) .
13
+ /// * [SECP384R1]
14
+ /// * [SECP256R1]
15
+ /// * [X25519]
16
+ ///
17
+ /// If the `fips` feature is enabled, only [SECP384R1] and [SECP256R1] are available.
18
18
pub const ALL_KX_GROUPS : & [ & dyn SupportedKxGroup ] = & [
19
19
SECP256R1 ,
20
20
SECP384R1 ,
21
- #[ cfg( feature = "x25519" ) ]
21
+ #[ cfg( not ( feature = "fips" ) ) ]
22
22
X25519 ,
23
23
] ;
24
24
@@ -36,26 +36,27 @@ struct EcKeyExchange {
36
36
pub_key : Vec < u8 > ,
37
37
}
38
38
39
- #[ cfg( feature = "x25519" ) ]
39
+ #[ cfg( not ( feature = "fips" ) ) ]
40
40
/// KXGroup for X25519
41
41
#[ derive( Debug ) ]
42
42
struct X25519KxGroup { }
43
43
44
- #[ cfg( feature = "x25519" ) ]
44
+ #[ cfg( not ( feature = "fips" ) ) ]
45
45
#[ derive( Debug ) ]
46
46
struct X25519KeyExchange {
47
47
private_key : PKey < Private > ,
48
48
public_key : Vec < u8 > ,
49
49
}
50
50
51
- #[ cfg( feature = "x25519" ) ]
51
+ #[ cfg( not( feature = "fips" ) ) ]
52
+ /// X25519 key exchange group as registered with [IANA](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8).
52
53
pub const X25519 : & dyn SupportedKxGroup = & X25519KxGroup { } ;
53
-
54
+ /// secp256r1 key exchange group as registered with [IANA](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8)
54
55
pub const SECP256R1 : & dyn SupportedKxGroup = & EcKxGroup {
55
56
name : NamedGroup :: secp256r1,
56
57
nid : Nid :: X9_62_PRIME256V1 ,
57
58
} ;
58
-
59
+ /// secp384r1 key exchange group as registered with [IANA](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8)
59
60
pub const SECP384R1 : & dyn SupportedKxGroup = & EcKxGroup {
60
61
name : NamedGroup :: secp384r1,
61
62
nid : Nid :: SECP384R1 ,
@@ -85,6 +86,10 @@ impl SupportedKxGroup for EcKxGroup {
85
86
fn name ( & self ) -> NamedGroup {
86
87
self . name
87
88
}
89
+
90
+ fn fips ( & self ) -> bool {
91
+ crate :: fips ( )
92
+ }
88
93
}
89
94
90
95
impl EcKeyExchange {
@@ -120,7 +125,7 @@ impl ActiveKeyExchange for EcKeyExchange {
120
125
}
121
126
}
122
127
123
- #[ cfg( feature = "x25519" ) ]
128
+ #[ cfg( not ( feature = "fips" ) ) ]
124
129
impl SupportedKxGroup for X25519KxGroup {
125
130
fn start ( & self ) -> Result < Box < dyn ActiveKeyExchange > , Error > {
126
131
PKey :: generate_x25519 ( )
@@ -139,7 +144,7 @@ impl SupportedKxGroup for X25519KxGroup {
139
144
}
140
145
}
141
146
142
- #[ cfg( feature = "x25519" ) ]
147
+ #[ cfg( not ( feature = "fips" ) ) ]
143
148
impl ActiveKeyExchange for X25519KeyExchange {
144
149
fn complete ( self : Box < Self > , peer_pub_key : & [ u8 ] ) -> Result < SharedSecret , Error > {
145
150
PKey :: public_key_from_raw_bytes ( peer_pub_key, Id :: X25519 )
0 commit comments