kernelDecrypt.c revision 87fa5c535cae2397ed924327bc36e7191c830aae
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <pthread.h>
#include <stdlib.h>
#include <errno.h>
#include <security/cryptoki.h>
#include "kernelGlobal.h"
#include "kernelSession.h"
#include "kernelObject.h"
/*
* Real decryptInit work. The caller doesn't hold the session lock.
*/
{
int r;
/* Check to see if key object allows for decryption. */
return (CKR_KEY_TYPE_INCONSISTENT);
}
/* Get the kernel's internal mechanism number. */
return (rv);
/*
* This active flag will remain ON until application calls either
* C_Decrypt or C_DecryptFinal to actually obtain the final piece
* of plaintext.
*/
/* set up key data */
if (!key_p->is_lib_obj) {
} else {
goto clean_exit;
}
/* KEF key lengths are expressed in bits */
CKR_OK) {
goto clean_exit;
}
} else {
goto clean_exit;
}
}
break;
}
if (r < 0) {
} else {
}
/* Free memory allocated for decrypt_init.di_key */
if (key_p->is_lib_obj) {
}
}
if (!ses_lock_held) {
}
if (ses_lock_held) {
}
return (rv);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
if (pMechanism == NULL) {
return (CKR_ARGUMENTS_BAD);
}
/* Obtain the session pointer. */
return (rv);
/* Obtain the object pointer. */
}
return (rv);
}
/*
* Real decrypt work. The caller doesn't hold the session lock.
*/
{
int r;
/* Application must call C_DecryptInit before calling C_Decrypt. */
goto clean_exit;
}
/*
* C_Decrypt must be called without intervening C_DecryptUpdate
* calls.
*/
/*
* C_Decrypt cannot be used to terminate a multiple-part
* operation, so we'll leave the active decrypt operation
* flag on and let the application continue with the
* decrypt update operation.
*/
goto clean_exit;
}
/*
* Certain mechanisms, where the length of the plaintext is
* same as the transformed ciphertext, can be optimized
* by the kernel into an in-place operation. Unfortunately,
* some applications use a plaintext buffer that is larger
* than it needs to be. We fix that here.
*/
} else {
}
break;
}
if (r < 0) {
} else {
}
if (ses_lock_held)
return (rv);
}
{
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
/*
* No need to check pData because application might
* just want to know the length of decrypted data.
*/
if (pulDataLen == NULL) {
goto clean_exit;
}
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 decrypt operation.
* Application needs to call C_DecryptInit again for next
* decrypt operation.
*/
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/* Obtain the session pointer. */
return (rv);
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);
}
&decrypt_update)) < 0) {
break;
}
if (r < 0) {
} else {
}
/*
* If CKR_OK or CKR_BUFFER_TOO_SMALL, set the output length.
* We 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);
}
{
int r;
if (!kernel_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);
}
&decrypt_final)) < 0) {
break;
}
if (r < 0) {
} else {
}
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 decrypt operation */
return (rv);
}