symKey = pk11_CreateSymKey(bestSlot, type, !isToken, wincx);
symKey = pk11_CreateSymKey(bestSlot, type, !isToken, PR_TRUE, wincx);
PK11_TokenKeyGenWithFlags(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,    SECItem *param, int keySize, SECItem *keyid, CK_FLAGS opFlags,    PK11AttrFlags attrFlags, void *wincx){    PK11SymKey *symKey;    CK_ATTRIBUTE genTemplate[MAX_TEMPL_ATTRS];    CK_ATTRIBUTE *attrs = genTemplate;    int count = sizeof(genTemplate)/sizeof(genTemplate[0]);    CK_SESSION_HANDLE session;    CK_MECHANISM mechanism;    CK_RV crv;    CK_BBOOL cktrue = CK_TRUE;    CK_BBOOL ckfalse = CK_FALSE;    CK_ULONG ck_key_size;       /* only used for variable-length keys */    PRBool isToken = ((attrFlags & PK11_ATTR_TOKEN) != 0);    if (pk11_BadAttrFlags(attrFlags)) {	PORT_SetError( SEC_ERROR_INVALID_ARGS );	return NULL;    }    if (keySize != 0) {        ck_key_size = keySize; /* Convert to PK11 type */        PK11_SETATTRS(attrs, CKA_VALUE_LEN, &ck_key_size, sizeof(ck_key_size)); 							attrs++;    }    /* Include key id value if provided */    if (keyid) {        PK11_SETATTRS(attrs, CKA_ID, keyid->data, keyid->len); attrs++;    }    attrs += pk11_AttrFlagsToAttributes(attrFlags, attrs, &cktrue, &ckfalse);    attrs += pk11_OpFlagsToAttributes(opFlags, attrs, &cktrue);    count = attrs - genTemplate;    PR_ASSERT(count <= sizeof(genTemplate)/sizeof(CK_ATTRIBUTE));    /* find a slot to generate the key into */    /* Only do slot management if this is not a token key */    if (!isToken && (slot == NULL || !PK11_DoesMechanism(slot,type))) {        PK11SlotInfo *bestSlot;        bestSlot = PK11_GetBestSlot(type,wincx);        if (bestSlot == NULL) {	    PORT_SetError( SEC_ERROR_NO_MODULE );	    return NULL;	}        symKey = pk11_CreateSymKey(bestSlot, type, !isToken, wincx);        PK11_FreeSlot(bestSlot);    } else {	symKey = pk11_CreateSymKey(slot, type, !isToken, wincx);    }    if (symKey == NULL) return NULL;    symKey->size = keySize;    symKey->origin = PK11_OriginGenerated;    /* Initialize the Key Gen Mechanism */    mechanism.mechanism = PK11_GetKeyGenWithSize(type, keySize);    if (mechanism.mechanism == CKM_FAKE_RANDOM) {	PORT_SetError( SEC_ERROR_NO_MODULE );	return NULL;    }    /* Set the parameters for the key gen if provided */    mechanism.pParameter = NULL;    mechanism.ulParameterLen = 0;    if (param) {	mechanism.pParameter = param->data;	mechanism.ulParameterLen = param->len;    }    /* Get session and perform locking */    if (isToken) {	PK11_Authenticate(symKey->slot,PR_TRUE,wincx);	/* Should always be original slot */        session = PK11_GetRWSession(symKey->slot);  	symKey->owner = PR_FALSE;    } else {        session = symKey->session;	if (session != CK_INVALID_SESSION) 	    pk11_EnterKeyMonitor(symKey);    }    if (session == CK_INVALID_SESSION) {	PK11_FreeSymKey(symKey);	PORT_SetError(SEC_ERROR_BAD_DATA);	return NULL;    }    crv = PK11_GETTAB(symKey->slot)->C_GenerateKey(session,			 &mechanism, genTemplate, count, &symKey->objectID);    /* Release lock and session */    if (isToken) {        PK11_RestoreROSession(symKey->slot, session);    } else {        pk11_ExitKeyMonitor(symKey);    }    if (crv != CKR_OK) {	PK11_FreeSymKey(symKey);	PORT_SetError( PK11_MapError(crv) );	return NULL;    }    return symKey;}