@@ -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 ] ,
@@ -310,9 +314,10 @@ pub fn checkquote(
310
314
311
315
let bytes = attest. marshall ( ) ?;
312
316
313
- let mut hash_alg = None ;
314
- match ( public , signature ) {
317
+ let hash_alg = match ( public , signature ) {
318
+ # [ cfg ( any ( feature = "p224" , feature = "p256" , feature = "p384" ) ) ]
315
319
( Public :: Ecc { parameters, .. } , _) => {
320
+ let mut hash_alg = None ;
316
321
macro_rules! impl_check_ecdsa {
317
322
( $curve: ty) => {
318
323
if parameters. ecc_curve( ) == <$curve>:: TPM_CURVE {
@@ -323,12 +328,10 @@ pub fn checkquote(
323
328
{
324
329
return Ok ( false ) ;
325
330
}
326
-
327
331
hash_alg = Some ( sig. hashing_algorithm( ) ) ;
328
332
}
329
333
} ;
330
334
}
331
-
332
335
//#[cfg(feature = "p192")]
333
336
//impl_check_ecdsa!(p192::NistP192);
334
337
#[ cfg( feature = "p224" ) ]
@@ -341,6 +344,12 @@ pub fn checkquote(
341
344
//impl_check_ecdsa!(p521::NistP521);
342
345
//#[cfg(feature = "sm2")]
343
346
//impl_check_ecdsa!(sm2::Sm2);
347
+
348
+ if let Some ( h) = hash_alg {
349
+ h
350
+ } else {
351
+ return Err ( Error :: WrapperError ( WrapperErrorKind :: InvalidParam ) ) ;
352
+ }
344
353
}
345
354
#[ cfg( feature = "rsa" ) ]
346
355
( Public :: Rsa { .. } , sig @ Signature :: RsaSsa ( pkcs_sig) ) => {
@@ -351,7 +360,7 @@ pub fn checkquote(
351
360
if !verify_rsa_pkcs1v15 ( public, & bytes, & sig, pkcs_sig. hashing_algorithm ( ) ) ? {
352
361
return Ok ( false ) ;
353
362
}
354
- hash_alg = Some ( pkcs_sig. hashing_algorithm ( ) ) ;
363
+ pkcs_sig. hashing_algorithm ( )
355
364
}
356
365
#[ cfg( feature = "rsa" ) ]
357
366
( Public :: Rsa { .. } , sig @ Signature :: RsaPss ( pkcs_sig) ) => {
@@ -362,16 +371,13 @@ pub fn checkquote(
362
371
if !verify_rsa_pss ( public, & bytes, & sig, pkcs_sig. hashing_algorithm ( ) ) ? {
363
372
return Ok ( false ) ;
364
373
}
365
- hash_alg = Some ( pkcs_sig. hashing_algorithm ( ) ) ;
374
+ pkcs_sig. hashing_algorithm ( )
366
375
}
367
376
_ => {
368
377
return Err ( Error :: WrapperError ( WrapperErrorKind :: UnsupportedParam ) ) ;
369
378
}
370
379
} ;
371
380
372
- let Some ( hash_alg) = hash_alg else {
373
- return Ok ( false ) ;
374
- } ;
375
381
if qualifying_data != attest. extra_data ( ) . as_bytes ( ) {
376
382
return Ok ( false ) ;
377
383
}
0 commit comments