Diff

Differences From Artifact [8363ed8d3c]:

To Artifact [195b1c0ba3]:


  3175   3175   		if (args->CreateMutex == NULL || args->DestroyMutex == NULL || args->LockMutex == NULL || args->UnlockMutex == NULL) {
  3176   3176   			if (args->CreateMutex != NULL || args->DestroyMutex != NULL || args->LockMutex != NULL || args->UnlockMutex != NULL) {
  3177   3177   				CACKEY_DEBUG_PRINTF("Error. Some, but not All threading primitives provided.");
  3178   3178   
  3179   3179   				return(CKR_ARGUMENTS_BAD);
  3180   3180   			}
  3181   3181   		}
  3182         -
  3183         -		if (args->pReserved != NULL) {
  3184         -			CACKEY_DEBUG_PRINTF("Error. pReserved is not NULL.");
  3185         -
  3186         -			return(CKR_ARGUMENTS_BAD);
  3187         -		}
  3188   3182   	} else {
  3189   3183   		cackey_args.CreateMutex = NULL;
  3190   3184   		cackey_args.DestroyMutex = NULL;
  3191   3185   		cackey_args.LockMutex = NULL;
  3192   3186   		cackey_args.UnlockMutex = NULL;
  3193   3187   		cackey_args.flags = 0;
  3194   3188   	}
................................................................................
  4974   4968   
  4975   4969   	return(CKR_OK);
  4976   4970   }
  4977   4971   
  4978   4972   CK_DEFINE_FUNCTION(CK_RV, C_Decrypt)(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen) {
  4979   4973   	CK_ULONG datalen_update, datalen_final;
  4980   4974   	CK_RV decrypt_ret;
         4975  +	int mutex_retval;
  4981   4976   
  4982   4977   	CACKEY_DEBUG_PRINTF("Called.");
  4983   4978   
  4984   4979   	if (!cackey_initialized) {
  4985   4980   		CACKEY_DEBUG_PRINTF("Error.  Not initialized.");
  4986   4981   
  4987   4982   		return(CKR_CRYPTOKI_NOT_INITIALIZED);
................................................................................
  4994   4989   	}
  4995   4990   
  4996   4991   	datalen_update = *pulDataLen;
  4997   4992   
  4998   4993   	decrypt_ret = C_DecryptUpdate(hSession, pEncryptedData, ulEncryptedDataLen, pData, &datalen_update);
  4999   4994   	if (decrypt_ret != CKR_OK) {
  5000   4995   		CACKEY_DEBUG_PRINTF("Error.  DecryptUpdate() returned failure (rv = %lu).", (unsigned long) decrypt_ret);
         4996  +
         4997  +		if (decrypt_ret != CKR_BUFFER_TOO_SMALL) {
         4998  +			/* Terminate decryption operation */
         4999  +
         5000  +			mutex_retval = cackey_mutex_lock(cackey_biglock);
         5001  +			if (mutex_retval != 0) {
         5002  +				CACKEY_DEBUG_PRINTF("Error.  Locking failed.");
         5003  +
         5004  +				return(CKR_GENERAL_ERROR);
         5005  +			}
         5006  +
         5007  +			if (!cackey_sessions[hSession].active) {
         5008  +				cackey_mutex_unlock(cackey_biglock);
         5009  +
         5010  +				CACKEY_DEBUG_PRINTF("Error.  Session not active.");
         5011  +		
         5012  +				return(CKR_SESSION_HANDLE_INVALID);
         5013  +			}
         5014  +
         5015  +			if (!cackey_sessions[hSession].decrypt_active) {
         5016  +				cackey_mutex_unlock(cackey_biglock);
         5017  +
         5018  +				CACKEY_DEBUG_PRINTF("Error.  Decrypt not active.");
         5019  +		
         5020  +				return(CKR_OPERATION_NOT_INITIALIZED);
         5021  +			}
         5022  +
         5023  +			cackey_sessions[hSession].decrypt_active = 0;
         5024  +
         5025  +			mutex_retval = cackey_mutex_unlock(cackey_biglock);
         5026  +			if (mutex_retval != 0) {
         5027  +				CACKEY_DEBUG_PRINTF("Error.  Unlocking failed.");
         5028  +
         5029  +				return(CKR_GENERAL_ERROR);
         5030  +			}
         5031  +		}
  5001   5032   
  5002   5033   		return(decrypt_ret);
  5003   5034   	}
  5004   5035   
  5005   5036   	if (pData) {
  5006   5037   		pData += datalen_update;
  5007   5038   	}
................................................................................
  5371   5402   
  5372   5403   	return(CKR_OK);
  5373   5404   }
  5374   5405   
  5375   5406   CK_DEFINE_FUNCTION(CK_RV, C_Sign)(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) {
  5376   5407   	unsigned long start_sign_bufused;
  5377   5408   	CK_RV sign_ret;
         5409  +	int mutex_retval;
  5378   5410   
  5379   5411   	CACKEY_DEBUG_PRINTF("Called.");
  5380   5412   
  5381   5413   	if (!cackey_initialized) {
  5382   5414   		CACKEY_DEBUG_PRINTF("Error.  Not initialized.");
  5383   5415   
  5384   5416   		return(CKR_CRYPTOKI_NOT_INITIALIZED);
................................................................................
  5391   5423   	}
  5392   5424   
  5393   5425   	start_sign_bufused = cackey_sessions[hSession].sign_bufused;
  5394   5426   
  5395   5427   	sign_ret = C_SignUpdate(hSession, pData, ulDataLen);
  5396   5428   	if (sign_ret != CKR_OK) {
  5397   5429   		CACKEY_DEBUG_PRINTF("Error.  SignUpdate() returned failure (rv = %lu).", (unsigned long) sign_ret);
         5430  +
         5431  +		if (sign_ret != CKR_BUFFER_TOO_SMALL) {
         5432  +			mutex_retval = cackey_mutex_lock(cackey_biglock);
         5433  +			if (mutex_retval != 0) {
         5434  +				CACKEY_DEBUG_PRINTF("Error.  Locking failed.");
         5435  +
         5436  +				return(CKR_GENERAL_ERROR);
         5437  +			}
         5438  +
         5439  +			if (!cackey_sessions[hSession].active) {
         5440  +				cackey_mutex_unlock(cackey_biglock);
         5441  +
         5442  +				CACKEY_DEBUG_PRINTF("Error.  Session not active.");
         5443  +		
         5444  +				return(CKR_SESSION_HANDLE_INVALID);
         5445  +			}
         5446  +
         5447  +			if (!cackey_sessions[hSession].sign_active) {
         5448  +				cackey_mutex_unlock(cackey_biglock);
         5449  +
         5450  +				CACKEY_DEBUG_PRINTF("Error.  Sign not active.");
         5451  +		
         5452  +				return(CKR_OPERATION_NOT_INITIALIZED);
         5453  +			}
         5454  +
         5455  +			cackey_sessions[hSession].sign_active = 0;
         5456  +
         5457  +			mutex_retval = cackey_mutex_unlock(cackey_biglock);
         5458  +			if (mutex_retval != 0) {
         5459  +				CACKEY_DEBUG_PRINTF("Error.  Unlocking failed.");
         5460  +
         5461  +				return(CKR_GENERAL_ERROR);
         5462  +			}
         5463  +		}
  5398   5464   
  5399   5465   		return(sign_ret);
  5400   5466   	}
  5401   5467   
  5402   5468   	sign_ret = C_SignFinal(hSession, pSignature, pulSignatureLen);
  5403   5469   	if (sign_ret != CKR_OK) {
  5404   5470   		if (sign_ret == CKR_BUFFER_TOO_SMALL) {