@@ -12,11 +12,7 @@ use crate::error::Error;
1212use crate :: service:: * ;
1313use crate :: types:: * ;
1414
15- //TODO:alt3r-3go: sign() and verify() are the only two methods that are actually different between -pkcs and -pss.
16- // Moreover, the key::Kind::Rsa2K could also probably be parametrized, instead of having a dedicated kind
17- // for each. Overall this means the class structure can probably be simplified - need to decide.
18-
19- #[ cfg( feature = "rsa2k-pkcs" ) ]
15+ #[ cfg( feature = "rsa2k" ) ]
2016impl DeriveKey for super :: Rsa2kPkcs
2117{
2218 #[ inline( never) ]
@@ -55,7 +51,7 @@ impl DeriveKey for super::Rsa2kPkcs
5551 }
5652}
5753
58- #[ cfg( feature = "rsa2k-pkcs " ) ]
54+ #[ cfg( feature = "rsa2k" ) ]
5955impl DeserializeKey for super :: Rsa2kPkcs
6056{
6157 #[ inline( never) ]
@@ -73,7 +69,7 @@ impl DeserializeKey for super::Rsa2kPkcs
7369 let private_key: RsaPrivateKey = DecodePrivateKey :: from_pkcs8_der ( & request. serialized_key )
7470 . map_err ( |_| Error :: InvalidSerializedKey ) ?;
7571
76- // We store our keys in PKCS#8 DER format as well
72+ // We store our keys in PKCS#8 DER format
7773 let private_key_der = private_key. to_pkcs8_der ( )
7874 . expect ( "Failed to serialize an RSA 2K private key to PKCS#8 DER" ) ;
7975
@@ -88,7 +84,7 @@ impl DeserializeKey for super::Rsa2kPkcs
8884 }
8985}
9086
91- #[ cfg( feature = "rsa2k-pkcs " ) ]
87+ #[ cfg( feature = "rsa2k" ) ]
9288impl GenerateKey for super :: Rsa2kPkcs
9389{
9490 #[ inline( never) ]
@@ -125,7 +121,7 @@ impl GenerateKey for super::Rsa2kPkcs
125121 }
126122}
127123
128- #[ cfg( feature = "rsa2k-pkcs " ) ]
124+ #[ cfg( feature = "rsa2k" ) ]
129125impl SerializeKey for super :: Rsa2kPkcs
130126{
131127 #[ inline( never) ]
@@ -140,8 +136,6 @@ impl SerializeKey for super::Rsa2kPkcs
140136 . material ;
141137
142138 let serialized_key = match request. format {
143- // TODO:alt3r-3go: There are "Der" and "Asn1Der" commented out in KeySerialization enum,
144- // should those be used instead?
145139 KeySerialization :: Raw => {
146140 let mut serialized_key = Message :: new ( ) ;
147141 serialized_key. extend_from_slice ( & priv_key_der) . map_err ( |_| Error :: InternalError ) ?;
@@ -155,7 +149,7 @@ impl SerializeKey for super::Rsa2kPkcs
155149 }
156150}
157151
158- #[ cfg( feature = "rsa2k-pkcs " ) ]
152+ #[ cfg( feature = "rsa2k" ) ]
159153impl Exists for super :: Rsa2kPkcs
160154{
161155 #[ inline( never) ]
@@ -169,7 +163,7 @@ impl Exists for super::Rsa2kPkcs
169163 }
170164}
171165
172- #[ cfg( feature = "rsa2k-pkcs " ) ]
166+ #[ cfg( feature = "rsa2k" ) ]
173167impl Sign for super :: Rsa2kPkcs
174168{
175169 #[ inline( never) ]
@@ -188,12 +182,9 @@ impl Sign for super::Rsa2kPkcs
188182 . expect ( "Failed to deserialize an RSA 2K private key from PKCS#8 DER" ) ;
189183
190184 // RSA lib takes in a hash value to sign, not raw data.
191- // TODO:alt3r-3go: Do we assume we get digest into this function, or we calculate it ourselves?
192- // use sha2::digest::Digest;
193- // let digest_to_sign: [u8; 32] = sha2::Sha256::digest(&request.message).into();
185+ // We assume we get digest into this function, too.
194186
195- // TODO:alt3r-3go: There's also .sign_blinded(), which is supposed to protect the private key from timing side channels,
196- // but requires an RNG instance - decide if we want to always use it.
187+ // TODO: Consider using .sign_blinded(), which is supposed to protect the private key from timing side channels
197188 use rsa:: padding:: PaddingScheme ;
198189 use rsa:: hash:: Hash ;
199190 let native_signature = priv_key
@@ -211,7 +202,7 @@ impl Sign for super::Rsa2kPkcs
211202 }
212203}
213204
214- #[ cfg( feature = "rsa2k-pkcs " ) ]
205+ #[ cfg( feature = "rsa2k" ) ]
215206impl Verify for super :: Rsa2kPkcs
216207{
217208 #[ inline( never) ]
@@ -223,7 +214,7 @@ impl Verify for super::Rsa2kPkcs
223214 return Err ( Error :: InvalidSerializationFormat ) ;
224215 }
225216
226- // TODO:alt3r-3go: This must not be a hardcoded magic number, need to generalize
217+ // TODO: This must not be a hardcoded magic number, convert when a common mechanism is available
227218 if request. signature . len ( ) != 256 {
228219 return Err ( Error :: WrongSignatureLength ) ;
229220 }
@@ -250,11 +241,11 @@ impl Verify for super::Rsa2kPkcs
250241 }
251242}
252243
253- #[ cfg( not( feature = "rsa2k-pkcs " ) ) ]
244+ #[ cfg( not( feature = "rsa2k" ) ) ]
254245impl DeriveKey for super :: Rsa2kPkcs { }
255- #[ cfg( not( feature = "rsa2k-pkcs " ) ) ]
246+ #[ cfg( not( feature = "rsa2k" ) ) ]
256247impl GenerateKey for super :: Rsa2kPkcs { }
257- #[ cfg( not( feature = "rsa2k-pkcs " ) ) ]
248+ #[ cfg( not( feature = "rsa2k" ) ) ]
258249impl Sign for super :: Rsa2kPkcs { }
259- #[ cfg( not( feature = "rsa2k-pkcs " ) ) ]
250+ #[ cfg( not( feature = "rsa2k" ) ) ]
260251impl Verify for super :: Rsa2kPkcs { }
0 commit comments