@@ -560,41 +560,38 @@ static void test_wolfTPM2_PolicyHash(void)
560560#ifndef WOLFTPM2_NO_WOLFCRYPT
561561 int rc ;
562562 byte digest [TPM_SHA256_DIGEST_SIZE ];
563+ byte digest0 [TPM_SHA256_DIGEST_SIZE ];
564+ byte digestFirst [TPM_SHA256_DIGEST_SIZE ];
563565 word32 digestSz ;
564566 const byte input [] = {0x01 , 0x02 , 0x03 , 0x04 };
565567
566568 /* Test 1: cc=0 (no command code, used by PolicyRefMake) */
567- {
568- byte digest0 [TPM_SHA256_DIGEST_SIZE ];
569- byte digestFirst [TPM_SHA256_DIGEST_SIZE ];
570-
571- XMEMSET (digest , 0xAA , sizeof (digest ));
572- digestSz = TPM_SHA256_DIGEST_SIZE ;
573- rc = wolfTPM2_PolicyHash (TPM_ALG_SHA256 , digest , & digestSz ,
574- 0 , input , sizeof (input ));
575- AssertIntEQ (rc , 0 );
576- XMEMCPY (digest0 , digest , digestSz );
569+ XMEMSET (digest , 0xAA , sizeof (digest ));
570+ digestSz = TPM_SHA256_DIGEST_SIZE ;
571+ rc = wolfTPM2_PolicyHash (TPM_ALG_SHA256 , digest , & digestSz ,
572+ 0 , input , sizeof (input ));
573+ AssertIntEQ (rc , 0 );
574+ XMEMCPY (digest0 , digest , digestSz );
577575
578- /* Test 2: cc=TPM_CC_FIRST (0x11F boundary) - must differ from cc=0 */
579- XMEMSET (digest , 0xAA , sizeof (digest ));
580- digestSz = TPM_SHA256_DIGEST_SIZE ;
581- rc = wolfTPM2_PolicyHash (TPM_ALG_SHA256 , digest , & digestSz ,
582- TPM_CC_FIRST , input , sizeof (input ));
583- AssertIntEQ (rc , 0 );
584- XMEMCPY (digestFirst , digest , digestSz );
576+ /* Test 2: cc=TPM_CC_FIRST (0x11F boundary) - must differ from cc=0 */
577+ XMEMSET (digest , 0xAA , sizeof (digest ));
578+ digestSz = TPM_SHA256_DIGEST_SIZE ;
579+ rc = wolfTPM2_PolicyHash (TPM_ALG_SHA256 , digest , & digestSz ,
580+ TPM_CC_FIRST , input , sizeof (input ));
581+ AssertIntEQ (rc , 0 );
582+ XMEMCPY (digestFirst , digest , digestSz );
585583
586- /* cc=0 and cc=TPM_CC_FIRST must produce different digests */
587- AssertIntNE (XMEMCMP (digest0 , digestFirst , digestSz ), 0 );
584+ /* cc=0 and cc=TPM_CC_FIRST must produce different digests */
585+ AssertIntNE (XMEMCMP (digest0 , digestFirst , digestSz ), 0 );
588586
589- /* Test 3: cc=TPM_CC_PolicyPCR (above boundary) - must differ from both */
590- XMEMSET (digest , 0xAA , sizeof (digest ));
591- digestSz = TPM_SHA256_DIGEST_SIZE ;
592- rc = wolfTPM2_PolicyHash (TPM_ALG_SHA256 , digest , & digestSz ,
593- TPM_CC_PolicyPCR , input , sizeof (input ));
594- AssertIntEQ (rc , 0 );
595- AssertIntNE (XMEMCMP (digest0 , digest , digestSz ), 0 );
596- AssertIntNE (XMEMCMP (digestFirst , digest , digestSz ), 0 );
597- }
587+ /* Test 3: cc=TPM_CC_PolicyPCR (above boundary) - must differ from both */
588+ XMEMSET (digest , 0xAA , sizeof (digest ));
589+ digestSz = TPM_SHA256_DIGEST_SIZE ;
590+ rc = wolfTPM2_PolicyHash (TPM_ALG_SHA256 , digest , & digestSz ,
591+ TPM_CC_PolicyPCR , input , sizeof (input ));
592+ AssertIntEQ (rc , 0 );
593+ AssertIntNE (XMEMCMP (digest0 , digest , digestSz ), 0 );
594+ AssertIntNE (XMEMCMP (digestFirst , digest , digestSz ), 0 );
598595
599596 printf ("Test TPM Wrapper:\tPolicyHash:\tPassed\n" );
600597#else
@@ -611,6 +608,18 @@ static void test_wolfTPM2_SensitiveToPrivate(void)
611608 TPM2B_NAME name ;
612609 TPM2B_DATA symSeed ;
613610 TPMT_SYM_DEF_OBJECT sym ;
611+ const byte expected [] = {
612+ 0x00 , 0x20 , 0x2b , 0x59 , 0xc0 , 0x69 , 0xf6 , 0x63 ,
613+ 0x7c , 0x2a , 0xe0 , 0x62 , 0xcf , 0x42 , 0x37 , 0x8b ,
614+ 0x79 , 0x5d , 0xb6 , 0x61 , 0x4f , 0x9f , 0x93 , 0x38 ,
615+ 0x82 , 0x06 , 0x2e , 0x28 , 0xbf , 0xd3 , 0x5c , 0x82 ,
616+ 0x1c , 0x03 , 0xb5 , 0x90 , 0x49 , 0x7a , 0x93 , 0x46 ,
617+ 0x31 , 0x51 , 0xe2 , 0xdd , 0x4f , 0x0a , 0x22 , 0x9b ,
618+ 0x2e , 0xd7 , 0x5d , 0xc6 , 0xe3 , 0x97 , 0xf4 , 0x75 ,
619+ 0xcf , 0xfd , 0xa9 , 0xe9 , 0xd3 , 0xa4 , 0x5f , 0x95 ,
620+ 0xa0 , 0x70 , 0x2f , 0x71 , 0x6c , 0xb8 , 0x90 , 0x39 ,
621+ 0x32 , 0x54 , 0x91 , 0x87 , 0x34 , 0x9b , 0xac , 0xef
622+ };
614623
615624 /* Fixed test inputs */
616625 XMEMSET (& sens , 0 , sizeof (sens ));
@@ -623,8 +632,9 @@ static void test_wolfTPM2_SensitiveToPrivate(void)
623632 sens .sensitiveArea .sensitiveType = TPM_ALG_RSA ;
624633 sens .sensitiveArea .authValue .size = 4 ;
625634 XMEMSET (sens .sensitiveArea .authValue .buffer , 0xAA , 4 );
626- sens .sensitiveArea .seedValue .size = 32 ;
627- XMEMSET (sens .sensitiveArea .seedValue .buffer , 0xBB , 32 );
635+ sens .sensitiveArea .seedValue .size = TPM_SHA256_DIGEST_SIZE ;
636+ XMEMSET (sens .sensitiveArea .seedValue .buffer , 0xBB ,
637+ TPM_SHA256_DIGEST_SIZE );
628638
629639 /* Set up a name (hash alg + digest) */
630640 name .size = 2 + TPM_SHA256_DIGEST_SIZE ;
@@ -639,34 +649,18 @@ static void test_wolfTPM2_SensitiveToPrivate(void)
639649 sym .mode .sym = TPM_ALG_CFB ;
640650
641651 /* Set up a symmetric seed (triggers outer wrap / KDFa) */
642- symSeed .size = 32 ;
643- XMEMSET (symSeed .buffer , 0xDD , 32 );
652+ symSeed .size = TPM_SHA256_DIGEST_SIZE ;
653+ XMEMSET (symSeed .buffer , 0xDD , TPM_SHA256_DIGEST_SIZE );
644654
645655 /* Expected output - pins KDFa "STORAGE" and "INTEGRITY" labels.
646656 * Bytes 0-1: integrity size (0x0020 = 32),
647657 * Bytes 2-33: HMAC integrity (via "INTEGRITY" label KDFa),
648658 * Bytes 34-79: AES-CFB encrypted sensitive (via "STORAGE" label KDFa) */
649- {
650- const byte expected [] = {
651- 0x00 , 0x20 , 0x2b , 0x59 , 0xc0 , 0x69 , 0xf6 , 0x63 ,
652- 0x7c , 0x2a , 0xe0 , 0x62 , 0xcf , 0x42 , 0x37 , 0x8b ,
653- 0x79 , 0x5d , 0xb6 , 0x61 , 0x4f , 0x9f , 0x93 , 0x38 ,
654- 0x82 , 0x06 , 0x2e , 0x28 , 0xbf , 0xd3 , 0x5c , 0x82 ,
655- 0x1c , 0x03 , 0xb5 , 0x90 , 0x49 , 0x7a , 0x93 , 0x46 ,
656- 0x31 , 0x51 , 0xe2 , 0xdd , 0x4f , 0x0a , 0x22 , 0x9b ,
657- 0x2e , 0xd7 , 0x5d , 0xc6 , 0xe3 , 0x97 , 0xf4 , 0x75 ,
658- 0xcf , 0xfd , 0xa9 , 0xe9 , 0xd3 , 0xa4 , 0x5f , 0x95 ,
659- 0xa0 , 0x70 , 0x2f , 0x71 , 0x6c , 0xb8 , 0x90 , 0x39 ,
660- 0x32 , 0x54 , 0x91 , 0x87 , 0x34 , 0x9b , 0xac , 0xef
661- };
662-
663- /* Call with no parent key - uses nameAlg directly */
664- rc = wolfTPM2_SensitiveToPrivate (& sens , & priv ,
665- TPM_ALG_SHA256 , & name , NULL , & sym , & symSeed );
666- AssertIntEQ (rc , 0 );
667- AssertIntEQ (priv .size , (int )sizeof (expected ));
668- AssertIntEQ (XMEMCMP (priv .buffer , expected , sizeof (expected )), 0 );
669- }
659+ rc = wolfTPM2_SensitiveToPrivate (& sens , & priv ,
660+ TPM_ALG_SHA256 , & name , NULL , & sym , & symSeed );
661+ AssertIntEQ (rc , 0 );
662+ AssertIntEQ (priv .size , (int )sizeof (expected ));
663+ AssertIntEQ (XMEMCMP (priv .buffer , expected , sizeof (expected )), 0 );
670664
671665 printf ("Test TPM Wrapper:\tSensitiveToPrivate:\tPassed\n" );
672666#else
0 commit comments