CK_ULONG out = maxLen; PRBool owner = PR_TRUE; CK_SESSION_HANDLE session; CK_RV crv;  if (key->keyType != rsaKey) { PORT_SetError( SEC_ERROR_INVALID_KEY ); return SECFailure; }   if (!PK11_HasAttributeSet(slot,key->pkcs11ID,CKA_PRIVATE)) { PK11_HandlePasswordCheck(slot, key->wincx); } session = pk11_GetNewSession(slot,&owner); if (!owner || !(slot->isThreadSafe)) PK11_EnterSlotMonitor(slot); crv = PK11_GETTAB(slot)->C_DecryptInit(session,&mech,key->pkcs11ID); if (crv != CKR_OK) { if (!owner || !(slot->isThreadSafe)) PK11_ExitSlotMonitor(slot); pk11_CloseSession(slot,session,owner); PORT_SetError( PK11_MapError(crv) ); return SECFailure; } crv = PK11_GETTAB(slot)->C_Decrypt(session,enc, encLen, data, &out); if (!owner || !(slot->isThreadSafe)) PK11_ExitSlotMonitor(slot); pk11_CloseSession(slot,session,owner); *outLen = out; if (crv != CKR_OK) { PORT_SetError( PK11_MapError(crv) ); return SECFailure; } return SECSuccess;
return pk11_PrivDecryptRaw(key, data, outLen, maxLen, enc, encLen, &mech);
PK11_PubDecryptRaw(SECKEYPrivateKey *key, unsigned char *data, 	unsigned *outLen, unsigned int maxLen, unsigned char *enc,							 unsigned encLen){    PK11SlotInfo *slot = key->pkcs11Slot;    CK_MECHANISM mech = {CKM_RSA_X_509, NULL, 0 };    CK_ULONG out = maxLen;    PRBool owner = PR_TRUE;    CK_SESSION_HANDLE session;    CK_RV crv;    if (key->keyType != rsaKey) {	PORT_SetError( SEC_ERROR_INVALID_KEY );	return SECFailure;    }    /* Why do we do a PK11_handle check here? for simple     * decryption? .. because the user may have asked for 'ask always'     * and this is a private key operation. In practice, thought, it's mute     * since only servers wind up using this function */    if (!PK11_HasAttributeSet(slot,key->pkcs11ID,CKA_PRIVATE)) {	PK11_HandlePasswordCheck(slot, key->wincx);    }    session = pk11_GetNewSession(slot,&owner);    if (!owner || !(slot->isThreadSafe)) PK11_EnterSlotMonitor(slot);    crv = PK11_GETTAB(slot)->C_DecryptInit(session,&mech,key->pkcs11ID);    if (crv != CKR_OK) {	if (!owner || !(slot->isThreadSafe)) PK11_ExitSlotMonitor(slot);	pk11_CloseSession(slot,session,owner);	PORT_SetError( PK11_MapError(crv) );	return SECFailure;    }    crv = PK11_GETTAB(slot)->C_Decrypt(session,enc, encLen,								data, &out);    if (!owner || !(slot->isThreadSafe)) PK11_ExitSlotMonitor(slot);    pk11_CloseSession(slot,session,owner);    *outLen = out;    if (crv != CKR_OK) {	PORT_SetError( PK11_MapError(crv) );	return SECFailure;    }    return SECSuccess;}