/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*/
#include <string.h>
#include <strings.h>
#include <security/cryptoki.h>
#include "kmsGlobal.h"
#include "kmsCrypt.h"
/*
* kms_decrypt_init()
*
* Arguments:
* session_p: pointer to kms_session_t struct
* pMechanism: pointer to CK_MECHANISM struct provided by application
* key_p: pointer to key kms_object_t struct
*
* Description:
* called by C_DecryptInit(). This function calls the corresponding
* decrypt init routine based on the mechanism.
*
* Returns:
* CKR_OK: success
* CKR_HOST_MEMORY: run out of system memory
* CKR_MECHANISM_PARAM_INVALID: invalid parameters in mechanism
* CKR_MECHANISM_INVALID: invalid mechanism type
* CKR_KEY_TYPE_INCONSISTENT: incorrect type of key to use
* with the specified mechanism
*/
{
switch (pMechanism->mechanism) {
case CKM_AES_CBC:
case CKM_AES_CBC_PAD:
{
return (CKR_KEY_TYPE_INCONSISTENT);
}
return (CKR_MECHANISM_PARAM_INVALID);
}
return (rv);
/* Save Initialization Vector (IV) in the context. */
/* Allocate a context for AES cipher-block chaining. */
kms_aes_ctx->ivec);
return (CKR_HOST_MEMORY);
}
return (rv);
}
default:
return (CKR_MECHANISM_INVALID);
}
}
{
if (!kms_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
if (pMechanism == NULL) {
goto clean_exit;
}
/* Obtain the object pointer. */
goto clean_exit;
/* Check to see if key object allows for decryption. */
goto clean_exit1;
}
/* Check to see if decrypt operation is already active. */
/* free the memory to avoid memory leak */
}
/*
* This active flag will remain ON until application calls either
* C_Decrypt or C_DecryptFinal to actually obtain the final piece
* of plaintext.
*/
}
return (rv);
}
{
if (!kms_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
/*
* Only check if input buffer is null. How to handle zero input
* length depends on the mechanism in use. For secret key mechanisms,
* unpadded ones yield zero length output, but padded ones always
* result in smaller than original, possibly zero, length output.
*/
if (pEncryptedData == NULL) {
goto clean_exit;
}
/*
* No need to check pData because application might
* just want to know the length of decrypted data.
*/
if (pulDataLen == NULL) {
goto clean_exit;
}
/* Application must call C_DecryptInit before calling C_Decrypt. */
return (CKR_OPERATION_NOT_INITIALIZED);
}
/*
* C_Decrypt must be called without intervening C_DecryptUpdate
* calls.
*/
/*
* C_Decrypt can not be used to terminate a multi-part
* operation, so we'll leave the active decrypt operation
* flag on and let the application continue with the
* decrypt update operation.
*/
return (CKR_FUNCTION_FAILED);
}
if ((rv == CKR_BUFFER_TOO_SMALL) ||
/*
* We will not terminate the active decrypt operation flag,
* when the application-supplied buffer is too small, or
* the application asks for the length of buffer to hold
* the plaintext.
*/
return (rv);
}
/* Clear context, free key, and release session counter */
return (rv);
}
{
if (!kms_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
/*
* Only check if input buffer is null. How to handle zero input
* length depends on the mechanism in use. For secret key mechanisms,
* unpadded ones yield zero length output, but padded ones always
* result in smaller than original, possibly zero, length output.
*/
if (pEncryptedPart == NULL) {
goto clean_exit;
}
/*
* Only check if pulPartLen is NULL.
* No need to check if pPart is NULL because application
* might just ask for the length of buffer to hold the
* recovered data.
*/
if (pulPartLen == NULL) {
goto clean_exit;
}
/*
* Application must call C_DecryptInit before calling
* C_DecryptUpdate.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
/*
* If CKR_OK or CKR_BUFFER_TOO_SMALL, don't terminate the
* current decryption operation.
*/
return (rv);
}
/*
* After an error occurred, terminate the current decrypt
* operation by resetting the active and update flags.
*/
return (rv);
}
{
if (!kms_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
if (pulLastPartLen == NULL) {
goto clean_exit;
}
/*
* Application must call C_DecryptInit before calling
* C_DecryptFinal.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
if ((rv == CKR_BUFFER_TOO_SMALL) ||
/*
* We will not terminate the active decrypt operation flag,
* when the application-supplied buffer is too small, or
* the application asks for the length of buffer to hold
* the plaintext.
*/
return (rv);
}
/* Terminates the active encrypt operation. */
return (rv);
/* Terminates the active decrypt operation */
return (rv);
}