kernelDigest.c revision b232b5fcbfc9c96cd8e395cdd493503ccbad3d5d
/*
* 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 <errno.h>
#include <security/cryptoki.h>
#include "kernelGlobal.h"
#include "kernelSession.h"
#include "kernelEmulate.h"
static CK_RV
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
if (pMechanism == NULL)
return (CKR_ARGUMENTS_BAD);
/*
* Get the kernel's internal mechanism number.
*/
return (rv);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Acquire the session lock */
/*
* This active flag will remain ON until application calls either
* C_Digest or C_DigestFinal to actually obtain the value of
* the message digest.
*/
return (rv);
}
/*
* If pParameter is NULL, set cm_param_len to be 0, so that ioctl call
* will have a clean input data.
*/
else
break;
}
if (r < 0) {
} else {
}
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (rv);
}
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
{
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
goto clean_exit;
}
/* Acquire the session lock */
/* Application must call C_DigestInit before calling C_Digest */
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
/*
* C_Digest must be called without intervening C_DigestUpdate
* calls.
*/
/*
* C_Digest can not be used to terminate a multi-part
* operation, so we'll leave the active digest operation
* flag on and let the application continue with the
* digest update operation.
*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (CKR_FUNCTION_FAILED);
}
return (CKR_ARGUMENTS_BAD);
}
goto done;
goto clean_exit;
}
}
break;
}
if (r < 0) {
} else {
}
done:
if ((rv == CKR_BUFFER_TOO_SMALL) ||
/*
* We will not terminate the active digest operation flag,
* when the application-supplied buffer is too small, or
* the application asks for the length of buffer to hold
* the message digest.
*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
/*
* Terminates the active digest operation.
* Application needs to call C_DigestInit again for next
* digest operation.
*/
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
goto clean_exit;
}
/* Acquire the session lock */
/*
* Application must call C_DigestInit before calling
* C_DigestUpdate.
*/
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
/* Set update flag to protect C_Digest */
goto done;
}
&digest_update)) < 0) {
break;
}
if (r < 0) {
} else {
}
done:
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (CKR_OK);
}
/*
* After an error occurred, terminate the current digest
* operation by resetting the active and update flags.
*/
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
/* Obtain the object pointer. */
return (rv);
}
/* Check the key type */
goto clean_exit;
}
/*
* Application must call C_DigestInit before calling
* C_DigestKey.
*/
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
/*
* If the key object is from the HW provider, call CRYPTO_DIGEST_KEY
* ioctl. Otherwise, call CRYPTO_DIGEST_UPDATE ioctl and pass the key
* by value.
*/
if (key_p->is_lib_obj) {
} else {
}
if (!key_p->is_lib_obj) {
goto clean_exit;
}
&digest_key)) < 0) {
break;
}
if (r < 0) {
} else {
}
} else {
if (ulPartLen == 0) {
goto clean_exit;
}
goto clean_exit;
}
goto done;
}
&digest_update)) < 0) {
break;
}
if (r < 0) {
} else {
}
}
done:
/*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (CKR_OK);
}
/*
* After an error occurred, terminate the current digest
* operation by resetting the active and update flags.
*/
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (rv);
}
{
int r;
if (!kernel_initialized)
return (CKR_CRYPTOKI_NOT_INITIALIZED);
/*
* Obtain the session pointer. Also, increment the session
* reference count.
*/
return (rv);
if (pulDigestLen == NULL) {
goto clean_exit;
}
/* Acquire the session lock */
/*
* Application must call C_DigestInit before calling
* C_DigestFinal.
*/
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (CKR_OPERATION_NOT_INITIALIZED);
}
/* The order of checks is important here */
} else {
/*
* We end up here if an earlier C_DigestFinal() call
* took the C_Digest() path and it had returned
* CKR_BUFFER_TOO_SMALL.
*/
goto clean_exit;
}
}
goto done;
/*
* We are emulating a single-part operation now.
* So, clear the flag.
*/
goto clean_exit;
}
return (rv);
}
break;
}
if (r < 0) {
} else {
}
done:
if ((rv == CKR_BUFFER_TOO_SMALL) ||
/*
* We will not terminate the active digest operation flag,
* when the application-supplied buffer is too small, or
* the application asks for the length of buffer to hold
* the message digest.
*
* Decrement the session reference count.
* We do not hold the session lock.
*/
return (rv);
}
/* Terminates the active digest operation */
/*
* Decrement the session reference count.
* We hold the session lock, and REFRELE()
* will release the session lock for us.
*/
return (rv);
}