@@ -762,15 +762,12 @@ static void test_TPM2_ParamEnc_XOR_Vector(void)
762762{
763763#ifndef WOLFTPM2_NO_WOLFCRYPT
764764 int rc ;
765- TPM2_AUTH_SESSION session ;
765+ TPMI_ALG_HASH authHash = TPM_ALG_SHA256 ;
766766 TPM2B_AUTH sessKey ;
767767 TPM2B_NONCE nonceCaller , nonceTPM ;
768768 const byte original [] = "XOR parameter encryption round-trip test" ;
769769 byte data [sizeof (original )];
770770
771- XMEMSET (& session , 0 , sizeof (session ));
772- session .authHash = TPM_ALG_SHA256 ;
773-
774771 sessKey .size = TPM_SHA256_DIGEST_SIZE ;
775772 XMEMSET (sessKey .buffer , 0xCC , sessKey .size );
776773
@@ -782,15 +779,19 @@ static void test_TPM2_ParamEnc_XOR_Vector(void)
782779 XMEMCPY (data , original , sizeof (original ));
783780
784781 /* Encrypt */
785- rc = TPM2_ParamEnc_XOR (& session , & sessKey , NULL , & nonceCaller , & nonceTPM ,
782+ rc = TPM2_ParamEnc_XOR (authHash , sessKey .buffer , sessKey .size ,
783+ nonceCaller .buffer , nonceCaller .size ,
784+ nonceTPM .buffer , nonceTPM .size ,
786785 data , sizeof (data ));
787786 AssertIntEQ (TPM_RC_SUCCESS , rc );
788787
789788 /* Data must differ from original */
790789 AssertIntNE (0 , XMEMCMP (data , original , sizeof (original )));
791790
792791 /* Encrypt again with same args — XOR is self-inverse */
793- rc = TPM2_ParamEnc_XOR (& session , & sessKey , NULL , & nonceCaller , & nonceTPM ,
792+ rc = TPM2_ParamEnc_XOR (authHash , sessKey .buffer , sessKey .size ,
793+ nonceCaller .buffer , nonceCaller .size ,
794+ nonceTPM .buffer , nonceTPM .size ,
794795 data , sizeof (data ));
795796 AssertIntEQ (TPM_RC_SUCCESS , rc );
796797
@@ -805,16 +806,13 @@ static void test_TPM2_ParamEnc_AESCFB_Vector(void)
805806{
806807#if !defined(WOLFTPM2_NO_WOLFCRYPT ) && defined(WOLFSSL_AES_CFB )
807808 int rc ;
808- TPM2_AUTH_SESSION session ;
809+ TPMI_ALG_HASH authHash = TPM_ALG_SHA256 ;
810+ UINT16 keyBits = MAX_AES_KEY_BITS ;
809811 TPM2B_AUTH sessKey ;
810812 TPM2B_NONCE nonceCaller , nonceTPM ;
811813 const byte original [] = "AES-CFB parameter encryption round-trip test" ;
812814 byte data [sizeof (original )];
813815
814- XMEMSET (& session , 0 , sizeof (session ));
815- session .authHash = TPM_ALG_SHA256 ;
816- session .symmetric .keyBits .aes = MAX_AES_KEY_BITS ;
817-
818816 sessKey .size = TPM_SHA256_DIGEST_SIZE ;
819817 XMEMSET (sessKey .buffer , 0xDD , sessKey .size );
820818
@@ -826,16 +824,22 @@ static void test_TPM2_ParamEnc_AESCFB_Vector(void)
826824 XMEMCPY (data , original , sizeof (original ));
827825
828826 /* Encrypt with (nonceCaller, nonceTPM) */
829- rc = TPM2_ParamEnc_AESCFB (& session , & sessKey , NULL , & nonceCaller ,
830- & nonceTPM , data , sizeof (data ));
827+ rc = TPM2_ParamEnc_AESCFB (authHash , keyBits ,
828+ sessKey .buffer , sessKey .size ,
829+ nonceCaller .buffer , nonceCaller .size ,
830+ nonceTPM .buffer , nonceTPM .size ,
831+ data , sizeof (data ), 1 );
831832 AssertIntEQ (TPM_RC_SUCCESS , rc );
832833
833834 /* Data must differ from original */
834835 AssertIntNE (0 , XMEMCMP (data , original , sizeof (original )));
835836
836- /* Decrypt: swap nonce args so KDFa produces same key */
837- rc = TPM2_ParamDec_AESCFB (& session , & sessKey , NULL , & nonceTPM ,
838- & nonceCaller , data , sizeof (data ));
837+ /* Decrypt: same nonce order, doEncrypt=0 */
838+ rc = TPM2_ParamEnc_AESCFB (authHash , keyBits ,
839+ sessKey .buffer , sessKey .size ,
840+ nonceCaller .buffer , nonceCaller .size ,
841+ nonceTPM .buffer , nonceTPM .size ,
842+ data , sizeof (data ), 0 );
839843 AssertIntEQ (TPM_RC_SUCCESS , rc );
840844
841845 /* Must match original */
@@ -849,15 +853,12 @@ static void test_TPM2_ParamDec_XOR_Roundtrip(void)
849853{
850854#ifndef WOLFTPM2_NO_WOLFCRYPT
851855 int rc ;
852- TPM2_AUTH_SESSION session ;
856+ TPMI_ALG_HASH authHash = TPM_ALG_SHA256 ;
853857 TPM2B_AUTH sessKey ;
854858 TPM2B_NONCE nonceCaller , nonceTPM ;
855859 const byte original [] = "XOR parameter decryption round-trip test" ;
856860 byte data [sizeof (original )];
857861
858- XMEMSET (& session , 0 , sizeof (session ));
859- session .authHash = TPM_ALG_SHA256 ;
860-
861862 sessKey .size = TPM_SHA256_DIGEST_SIZE ;
862863 XMEMSET (sessKey .buffer , 0xEE , sessKey .size );
863864
@@ -868,16 +869,21 @@ static void test_TPM2_ParamDec_XOR_Roundtrip(void)
868869
869870 XMEMCPY (data , original , sizeof (original ));
870871
871- /* Decrypt direction: XOR with (nonceCaller, nonceTPM) mask */
872- rc = TPM2_ParamDec_XOR (& session , & sessKey , NULL , & nonceCaller , & nonceTPM ,
872+ /* Decrypt direction uses (nonceTPM, nonceCaller) order. XOR is symmetric
873+ * so the same TPM2_ParamEnc_XOR call performs decryption. */
874+ rc = TPM2_ParamEnc_XOR (authHash , sessKey .buffer , sessKey .size ,
875+ nonceTPM .buffer , nonceTPM .size ,
876+ nonceCaller .buffer , nonceCaller .size ,
873877 data , sizeof (data ));
874878 AssertIntEQ (TPM_RC_SUCCESS , rc );
875879
876880 /* Data must differ from original */
877881 AssertIntNE (0 , XMEMCMP (data , original , sizeof (original )));
878882
879883 /* Apply same XOR again — self-inverse recovers original */
880- rc = TPM2_ParamDec_XOR (& session , & sessKey , NULL , & nonceCaller , & nonceTPM ,
884+ rc = TPM2_ParamEnc_XOR (authHash , sessKey .buffer , sessKey .size ,
885+ nonceTPM .buffer , nonceTPM .size ,
886+ nonceCaller .buffer , nonceCaller .size ,
881887 data , sizeof (data ));
882888 AssertIntEQ (TPM_RC_SUCCESS , rc );
883889
@@ -892,16 +898,13 @@ static void test_TPM2_ParamDec_AESCFB_Roundtrip(void)
892898{
893899#if !defined(WOLFTPM2_NO_WOLFCRYPT ) && defined(WOLFSSL_AES_CFB )
894900 int rc ;
895- TPM2_AUTH_SESSION session ;
901+ TPMI_ALG_HASH authHash = TPM_ALG_SHA256 ;
902+ UINT16 keyBits = MAX_AES_KEY_BITS ;
896903 TPM2B_AUTH sessKey ;
897904 TPM2B_NONCE nonceCaller , nonceTPM ;
898905 const byte original [] = "AES-CFB parameter decryption round-trip test" ;
899906 byte data [sizeof (original )];
900907
901- XMEMSET (& session , 0 , sizeof (session ));
902- session .authHash = TPM_ALG_SHA256 ;
903- session .symmetric .keyBits .aes = MAX_AES_KEY_BITS ;
904-
905908 sessKey .size = TPM_SHA256_DIGEST_SIZE ;
906909 XMEMSET (sessKey .buffer , 0xFF , sessKey .size );
907910
@@ -912,18 +915,23 @@ static void test_TPM2_ParamDec_AESCFB_Roundtrip(void)
912915
913916 XMEMCPY (data , original , sizeof (original ));
914917
915- /* Encrypt with ParamEnc_AESCFB (command direction) */
916- rc = TPM2_ParamEnc_AESCFB (& session , & sessKey , NULL , & nonceCaller ,
917- & nonceTPM , data , sizeof (data ));
918+ /* Encrypt: command direction uses (nonceCaller, nonceTPM), doEncrypt=1 */
919+ rc = TPM2_ParamEnc_AESCFB (authHash , keyBits ,
920+ sessKey .buffer , sessKey .size ,
921+ nonceCaller .buffer , nonceCaller .size ,
922+ nonceTPM .buffer , nonceTPM .size ,
923+ data , sizeof (data ), 1 );
918924 AssertIntEQ (TPM_RC_SUCCESS , rc );
919925
920926 /* Data must differ from original */
921927 AssertIntNE (0 , XMEMCMP (data , original , sizeof (original )));
922928
923- /* Decrypt with ParamDec_AESCFB: swap nonce args so internal KDFa
924- * produces the same key as encryption */
925- rc = TPM2_ParamDec_AESCFB (& session , & sessKey , NULL , & nonceTPM ,
926- & nonceCaller , data , sizeof (data ));
929+ /* Decrypt: same nonce order so KDFa produces the same key, doEncrypt=0 */
930+ rc = TPM2_ParamEnc_AESCFB (authHash , keyBits ,
931+ sessKey .buffer , sessKey .size ,
932+ nonceCaller .buffer , nonceCaller .size ,
933+ nonceTPM .buffer , nonceTPM .size ,
934+ data , sizeof (data ), 0 );
927935 AssertIntEQ (TPM_RC_SUCCESS , rc );
928936
929937 /* Must match original */
0 commit comments