/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <strings.h>
#include <md5.h>
#include <pthread.h>
#include <stdlib.h>
#include <security/cryptoki.h>
#include "softGlobal.h"
#include "softOps.h"
#include "softSession.h"
#include "softObject.h"
/*
* soft_digest_init()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pMechanism: pointer to CK_MECHANISM struct provided by application
*
* Description:
* called by C_DigestInit(). This function allocates space for
* context, then calls the corresponding software provided digest
* init routine based on the mechanism.
*
* Returns:
* CKR_OK: success
* CKR_HOST_MEMORY: run out of system memory
* CKR_MECHANISM_INVALID: invalid mechanism type
*/
{
switch (pMechanism->mechanism) {
case CKM_MD5:
return (CKR_HOST_MEMORY);
}
break;
case CKM_SHA_1:
return (CKR_HOST_MEMORY);
}
break;
case CKM_SHA256:
case CKM_SHA384:
case CKM_SHA512:
return (CKR_HOST_MEMORY);
}
switch (pMechanism->mechanism) {
case CKM_SHA256:
break;
case CKM_SHA384:
break;
case CKM_SHA512:
break;
}
break;
default:
return (CKR_MECHANISM_INVALID);
}
return (CKR_OK);
}
/*
* soft_digest_common()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pData: pointer to the input data to be digested
* ulDataLen: length of the input data
* pDigest: pointer to the output data after digesting
* pulDigestLen: length of the output data
*
* Description:
* called by soft_digest() or soft_digest_final(). This function
* determines the length of output buffer and calls the corresponding
* software provided digest routine based on the mechanism.
*
* Returns:
* CKR_OK: success
* CKR_MECHANISM_INVALID: invalid mechanism type
* CKR_BUFFER_TOO_SMALL: the output buffer provided by application
* is too small
*/
{
/*
* Determine the output data length based on the mechanism
*/
case CKM_MD5:
digestLen = 16;
break;
case CKM_SHA_1:
digestLen = 20;
break;
case CKM_SHA256:
digestLen = 32;
break;
case CKM_SHA384:
digestLen = 48;
break;
case CKM_SHA512:
digestLen = 64;
break;
default:
return (CKR_MECHANISM_INVALID);
}
/*
* Application only wants to know the length of the
* buffer needed to hold the message digest.
*/
return (CKR_OK);
}
if (*pulDigestLen < digestLen) {
/*
* Application provides buffer too small to hold the
* digest message. Return the length of buffer needed
* to the application.
*/
return (CKR_BUFFER_TOO_SMALL);
}
/*
* Call the corresponding system provided software digest routine.
* If the soft_digest_common() is called by soft_digest_final()
* the pData is NULL, and the ulDataLen is zero.
*/
case CKM_MD5:
/*
* this is called by soft_digest()
*/
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
} else {
/*
* this is called by soft_digest_final()
*/
}
break;
case CKM_SHA_1:
/*
* this is called by soft_digest()
*/
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
} else {
/*
* this is called by soft_digest_final()
*/
}
break;
case CKM_SHA256:
case CKM_SHA384:
case CKM_SHA512:
/*
* this is called by soft_digest()
*/
} else {
/*
* this is called by soft_digest_final()
*/
}
break;
}
/* Paranoia on behalf of C_DigestKey callers: bzero the context */
}
return (CKR_OK);
}
/*
* soft_digest()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pData: pointer to the input data to be digested
* ulDataLen: length of the input data
* pDigest: pointer to the output data after digesting
* pulDigestLen: length of the output data
*
* Description:
* called by C_Digest(). This function calls soft_digest_common().
*
* Returns:
* see return values in soft_digest_common().
*/
{
pDigest, pulDigestLen));
}
/*
* soft_digest_update()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pPart: pointer to the input data to be digested
* ulPartLen: length of the input data
*
* Description:
* called by C_DigestUpdate(). This function calls the corresponding
* software provided digest update routine based on the mechanism.
*
* Returns:
* CKR_OK: success
* CKR_MECHANISM_INVALID: invalid MECHANISM type.
*/
{
case CKM_MD5:
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
break;
case CKM_SHA_1:
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
break;
case CKM_SHA256:
case CKM_SHA384:
case CKM_SHA512:
break;
default:
return (CKR_MECHANISM_INVALID);
}
return (CKR_OK);
}
/*
* soft_digest_final()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pDigest: pointer to the output data after digesting
* pulDigestLen: length of the output data
*
* Description:
* called by C_DigestFinal(). This function calls soft_digest_common().
*
* Returns:
* see return values in soft_digest_common().
*/
{
pDigest, pulDigestLen));
}
/*
* Perform digest init operation internally for the support of
* CKM_MD5_RSA_PKCS, CKM_SHA1_RSA_PKCS, CKM_SHA1_KEY_DERIVATION
* and CKM_MD5_KEY_DERIVATION mechanisms.
*
* This function is called with the session being held, and without
* its mutex taken.
*/
{
/* Check to see if digest operation is already active */
return (CKR_OPERATION_ACTIVE);
}
}
return (rv);
}
/*
* Call soft_digest_update() function with the value of a secret key.
*/
{
/* Only secret key is allowed to be digested */
return (CKR_KEY_INDIGESTIBLE);
(OBJ_SEC_VALUE_LEN(key_p) == 0))
return (CKR_KEY_SIZE_RANGE);
return (rv);
}
/*
* This function releases allocated digest context. The caller
* may (lock_held == B_TRUE) or may not (lock_held == B_FALSE)
* hold a session mutex.
*/
void
{
if (!lock_held)
}
if (!lock_held)
}