@@ -4,31 +4,35 @@ use crate::error::Error;
4
4
use crate :: error:: Result ;
5
5
use crate :: WrapperErrorKind ;
6
6
use crate :: {
7
- abstraction:: public:: AssociatedTpmCurve ,
8
7
interface_types:: algorithm:: HashingAlgorithm ,
9
- structures:: {
10
- Attest , AttestInfo , DigestList , EccSignature , PcrSelectionList , Public , QuoteInfo ,
11
- Signature ,
12
- } ,
8
+ structures:: { Attest , AttestInfo , DigestList , PcrSelectionList , Public , QuoteInfo , Signature } ,
13
9
traits:: Marshall ,
14
10
} ;
15
11
use digest:: { Digest , DynDigest } ;
16
12
13
+ #[ cfg( any( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
14
+ use crate :: { abstraction:: public:: AssociatedTpmCurve , structures:: EccSignature } ;
15
+ #[ cfg( any( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
17
16
use ecdsa:: {
18
17
hazmat:: { DigestPrimitive , VerifyPrimitive } ,
19
18
PrimeCurve , SignatureSize , VerifyingKey ,
20
19
} ;
20
+ #[ cfg( any( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
21
21
use elliptic_curve:: {
22
22
generic_array:: ArrayLength ,
23
23
point:: AffinePoint ,
24
24
sec1:: { FromEncodedPoint , ModulusSize , ToEncodedPoint } ,
25
25
CurveArithmetic , FieldBytesSize ,
26
26
} ;
27
- use signature:: { hazmat:: PrehashVerifier , Verifier } ;
27
+ #[ cfg( any( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
28
+ use signature:: hazmat:: PrehashVerifier ;
28
29
29
30
#[ cfg( feature = "rsa" ) ]
30
31
use rsa:: { pkcs1v15, pss, RsaPublicKey } ;
32
+ #[ cfg( feature = "rsa" ) ]
33
+ use signature:: Verifier ;
31
34
35
+ #[ cfg( any( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
32
36
fn verify_ecdsa < C > (
33
37
public : & Public ,
34
38
message : & [ u8 ] ,
@@ -306,9 +310,10 @@ pub fn checkquote(
306
310
307
311
let bytes = attest. marshall ( ) ?;
308
312
309
- let mut hash_alg = None ;
310
- match ( public , signature ) {
313
+ let hash_alg = match ( public , signature ) {
314
+ # [ cfg ( any ( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
311
315
( Public :: Ecc { parameters, .. } , _) => {
316
+ let mut hash_alg = None ;
312
317
macro_rules! impl_check_ecdsa {
313
318
( $curve: ty) => {
314
319
if parameters. ecc_curve( ) == <$curve>:: TPM_CURVE {
@@ -319,7 +324,6 @@ pub fn checkquote(
319
324
{
320
325
return Ok ( false ) ;
321
326
}
322
-
323
327
hash_alg = Some ( sig. hashing_algorithm( ) ) ;
324
328
}
325
329
} ;
@@ -330,6 +334,12 @@ pub fn checkquote(
330
334
impl_check_ecdsa ! ( p256:: NistP256 ) ;
331
335
#[ cfg( feature = "p384" ) ]
332
336
impl_check_ecdsa ! ( p384:: NistP384 ) ;
337
+
338
+ if let Some ( h) = hash_alg {
339
+ h
340
+ } else {
341
+ return Err ( Error :: WrapperError ( WrapperErrorKind :: InvalidParam ) ) ;
342
+ }
333
343
}
334
344
#[ cfg( feature = "rsa" ) ]
335
345
( Public :: Rsa { .. } , sig @ Signature :: RsaSsa ( pkcs_sig) ) => {
@@ -340,7 +350,7 @@ pub fn checkquote(
340
350
if !verify_rsa_pkcs1v15 ( public, & bytes, & sig, pkcs_sig. hashing_algorithm ( ) ) ? {
341
351
return Ok ( false ) ;
342
352
}
343
- hash_alg = Some ( pkcs_sig. hashing_algorithm ( ) ) ;
353
+ pkcs_sig. hashing_algorithm ( )
344
354
}
345
355
#[ cfg( feature = "rsa" ) ]
346
356
( Public :: Rsa { .. } , sig @ Signature :: RsaPss ( pkcs_sig) ) => {
@@ -351,16 +361,13 @@ pub fn checkquote(
351
361
if !verify_rsa_pss ( public, & bytes, & sig, pkcs_sig. hashing_algorithm ( ) ) ? {
352
362
return Ok ( false ) ;
353
363
}
354
- hash_alg = Some ( pkcs_sig. hashing_algorithm ( ) ) ;
364
+ pkcs_sig. hashing_algorithm ( )
355
365
}
356
366
_ => {
357
367
return Err ( Error :: WrapperError ( WrapperErrorKind :: UnsupportedParam ) ) ;
358
368
}
359
369
} ;
360
370
361
- let Some ( hash_alg) = hash_alg else {
362
- return Ok ( false ) ;
363
- } ;
364
371
if qualifying_data != attest. extra_data ( ) . as_bytes ( ) {
365
372
return Ok ( false ) ;
366
373
}
0 commit comments