/*
* 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
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <pthread.h>
#include <security/cryptoki.h>
#include "softGlobal.h"
#include "softSession.h"
#include "softObject.h"
#include "softOps.h"
{
if (!softtoken_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 encryption. */
goto clean_exit1;
}
/* Check to see if encrypt operation is already active. */
/* free the memory to avoid memory leak */
}
/*
* This active flag will remain ON until application calls either
* C_Encrypt or C_EncryptFinal to actually obtain the final piece
* of ciphertext.
*/
}
return (rv);
}
{
if (!softtoken_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 greater than zero length output.
*/
goto clean_exit;
}
/*
* Only check if pulEncryptedDataLen is NULL.
* No need to check if pEncryptedData is NULL because
* application might just ask for the length of buffer to hold
* the ciphertext.
*/
if (pulEncryptedDataLen == NULL) {
goto clean_exit;
}
/* Application must call C_EncryptInit before calling C_Encrypt. */
return (CKR_OPERATION_NOT_INITIALIZED);
}
/*
* C_Encrypt must be called without intervening C_EncryptUpdate
* calls.
*/
/*
* C_Encrypt can not be used to terminate a multi-part
* operation, so we'll leave the active encrypt operation
* flag on and let the application continue with the
* encrypt update operation.
*/
return (CKR_FUNCTION_FAILED);
}
if ((rv == CKR_BUFFER_TOO_SMALL) ||
/*
* We will not terminate the active encrypt operation flag,
* when the application-supplied buffer is too small, or
* the application asks for the length of buffer to hold
* the ciphertext.
*/
return (rv);
}
/* Clear context, free key, and release session counter */
return (rv);
}
{
if (!softtoken_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 yeild zero length output, but padded ones always
* result in greater than zero length output.
*/
goto clean_exit;
}
/*
* Only check if pulEncryptedPartLen is NULL.
* No need to check if pEncryptedPart is NULL because
* application might just ask for the length of buffer to hold
* the ciphertext.
*/
if (pulEncryptedPartLen == NULL) {
goto clean_exit;
}
/*
* Application must call C_EncryptInit before calling
* C_EncryptUpdate.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
/*
* If CKR_OK or CKR_BUFFER_TOO_SMALL, don't terminate the
* current encryption operation.
*/
return (rv);
}
/*
* After an error occurred, terminate the current encrypt
* operation by resetting the active and update flags.
*/
return (rv);
}
{
if (!softtoken_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
if (pulLastEncryptedPartLen == NULL) {
goto clean_exit;
}
/*
* Application must call C_EncryptInit before calling
* C_EncryptFinal.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
if ((rv == CKR_BUFFER_TOO_SMALL) ||
/*
* We will not terminate the active encrypt operation flag,
* when the application-supplied buffer is too small, or
* the application asks for the length of buffer to hold
* the ciphertext.
*/
return (rv);
}
/* Terminates the active encrypt operation. */
return (rv);
/* Terminates the active encrypt operation. */
return (rv);
}