@@ -6760,37 +6760,21 @@ CK_RV C_GenerateKey(CK_SESSION_HANDLE hSession,
67606760 ret = WP11_Object_SetSecretKey (pbkdf2Key , secretKeyData , secretKeyLen );
67616761 if (ret == 0 ) {
67626762 WP11_Object_SetKeyGeneration (pbkdf2Key , pMechanism -> mechanism );
6763- rv = AddObject (session , pbkdf2Key , pTemplate , ulCount , phKey );
6764- if (rv != CKR_OK ) {
6765- WP11_Object_Free (pbkdf2Key );
6766- }
6763+ rv = SetInitialStates (pbkdf2Key );
67676764 } else {
6768- WP11_Object_Free (pbkdf2Key );
67696765 rv = CKR_FUNCTION_FAILED ;
67706766 }
6767+ if (rv == CKR_OK ) {
6768+ rv = AddObject (session , pbkdf2Key , pTemplate , ulCount , phKey );
6769+ }
6770+ if (rv != CKR_OK ) {
6771+ WP11_Object_Free (pbkdf2Key );
6772+ }
67716773 }
67726774
67736775 wc_ForceZero (derivedKey , derivedKeyLen );
67746776 XFREE (derivedKey , NULL , DYNAMIC_TYPE_TMP_BUFFER );
67756777
6776- if (rv == CKR_OK ) {
6777- rv = WP11_Object_GetAttr (pbkdf2Key , CKA_SENSITIVE , & getVar ,
6778- & getVarLen );
6779- if ((rv == CKR_OK ) && (getVar == CK_TRUE )) {
6780- rv = WP11_Object_SetAttr (pbkdf2Key , CKA_ALWAYS_SENSITIVE ,
6781- & trueVar , sizeof (CK_BBOOL ));
6782- }
6783- if (rv == CKR_OK ) {
6784- rv = WP11_Object_GetAttr (pbkdf2Key , CKA_EXTRACTABLE ,
6785- & getVar , & getVarLen );
6786- if ((rv == CKR_OK ) && (getVar == CK_FALSE )) {
6787- rv = WP11_Object_SetAttr (pbkdf2Key ,
6788- CKA_NEVER_EXTRACTABLE ,
6789- & trueVar , sizeof (CK_BBOOL ));
6790- }
6791- }
6792- }
6793-
67946778 return rv ;
67956779 }
67966780#ifdef WOLFPKCS11_NSS
@@ -6877,37 +6861,21 @@ CK_RV C_GenerateKey(CK_SESSION_HANDLE hSession,
68776861 ret = WP11_Object_SetSecretKey (pbeKey , secretKeyData , secretKeyLen );
68786862 if (ret == 0 ) {
68796863 WP11_Object_SetKeyGeneration (pbeKey , pMechanism -> mechanism );
6880- rv = AddObject (session , pbeKey , pTemplate , ulCount , phKey );
6881- if (rv != CKR_OK ) {
6882- WP11_Object_Free (pbeKey );
6883- }
6864+ rv = SetInitialStates (pbeKey );
68846865 } else {
6885- WP11_Object_Free (pbeKey );
68866866 rv = CKR_FUNCTION_FAILED ;
68876867 }
6868+ if (rv == CKR_OK ) {
6869+ rv = AddObject (session , pbeKey , pTemplate , ulCount , phKey );
6870+ }
6871+ if (rv != CKR_OK ) {
6872+ WP11_Object_Free (pbeKey );
6873+ }
68886874 }
68896875
68906876 wc_ForceZero (derivedKey , derivedKeyLen );
68916877 XFREE (derivedKey , NULL , DYNAMIC_TYPE_TMP_BUFFER );
68926878
6893- if (rv == CKR_OK ) {
6894- rv = WP11_Object_GetAttr (pbeKey , CKA_SENSITIVE , & getVar ,
6895- & getVarLen );
6896- if ((rv == CKR_OK ) && (getVar == CK_TRUE )) {
6897- rv = WP11_Object_SetAttr (pbeKey , CKA_ALWAYS_SENSITIVE ,
6898- & trueVar , sizeof (CK_BBOOL ));
6899- }
6900- if (rv == CKR_OK ) {
6901- rv = WP11_Object_GetAttr (pbeKey , CKA_EXTRACTABLE ,
6902- & getVar , & getVarLen );
6903- if ((rv == CKR_OK ) && (getVar == CK_FALSE )) {
6904- rv = WP11_Object_SetAttr (pbeKey ,
6905- CKA_NEVER_EXTRACTABLE ,
6906- & trueVar , sizeof (CK_BBOOL ));
6907- }
6908- }
6909- }
6910-
69116879 return rv ;
69126880 }
69136881#endif
0 commit comments