/*
* 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 <stdlib.h>
#include <strings.h>
#include <security/cryptoki.h>
#include "softObject.h"
#include "softOps.h"
#include "softSession.h"
#include "softMAC.h"
#include "softRSA.h"
#include "softDSA.h"
#include "softEC.h"
#include "softCrypt.h"
/*
* soft_sign_init()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pMechanism: pointer to CK_MECHANISM struct provided by application
* key_p: pointer to key soft_object_t struct
*
* Description:
* called by C_SignInit(). This function calls the corresponding
* sign init routine based on the mechanism.
*
*/
{
switch (pMechanism->mechanism) {
case CKM_SSL3_MD5_MAC:
case CKM_SSL3_SHA1_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
case CKM_RSA_X_509:
case CKM_RSA_PKCS:
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
case CKM_DSA:
case CKM_DSA_SHA1:
case CKM_ECDSA:
case CKM_ECDSA_SHA1:
case CKM_DES_MAC_GENERAL:
case CKM_DES_MAC:
default:
return (CKR_MECHANISM_INVALID);
}
}
/*
* soft_sign()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pData: pointer to the input data to be signed
* ulDataLen: length of the input data
* pSignature: pointer to the signature after signing
* pulSignatureLen: pointer to the length of the signature
*
* Description:
* called by C_Sign(). This function calls the corresponding
* sign routine based on the mechanism.
*
*/
{
switch (mechanism) {
case CKM_SSL3_MD5_MAC:
case CKM_SSL3_SHA1_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
{
if (pSignature != NULL) {
/* Pass local buffer to avoid overflow. */
} else {
/* Pass original pSignature, let callee to handle it. */
}
return (rv);
}
case CKM_DES_MAC_GENERAL:
case CKM_DES_MAC:
{
if (pSignature != NULL) {
/* Pass local buffer to avoid overflow. */
B_FALSE);
} else {
/* Pass NULL, let callee to handle it. */
}
return (rv);
}
case CKM_RSA_X_509:
case CKM_RSA_PKCS:
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
case CKM_DSA:
case CKM_DSA_SHA1:
case CKM_ECDSA:
case CKM_ECDSA_SHA1:
default:
return (CKR_MECHANISM_INVALID);
}
}
/*
* soft_sign_update()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pPart: pointer to the input data to be signed
* ulPartLen: length of the input data
*
* Description:
* called by C_SignUpdate(). This function calls the corresponding
* sign update routine based on the mechanism.
*
*/
{
switch (mechanism) {
case CKM_SSL3_MD5_MAC:
case CKM_SSL3_SHA1_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
case CKM_DES_MAC_GENERAL:
case CKM_DES_MAC:
ulPartLen));
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
/*
* of the multiple-part digesting operation. In the final
* operation, the digest is encoded and then perform RSA
* signing.
*/
case CKM_DSA_SHA1:
case CKM_ECDSA_SHA1:
default:
/* PKCS11: The mechanism only supports single-part operation. */
return (CKR_MECHANISM_INVALID);
}
}
/*
* soft_sign_final()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pSignature: pointer to the signature after signing
* pulSignatureLen: pointer to the length of the signature
*
* Description:
* called by C_SignFinal(). This function calls the corresponding
* sign final routine based on the mechanism.
*
*/
{
switch (mechanism) {
case CKM_SSL3_MD5_MAC:
case CKM_SSL3_SHA1_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
{
if (pSignature != NULL) {
/* Pass local buffer to avoid overflow */
} else {
/* Pass original pSignature, let callee to handle it. */
}
return (rv);
}
case CKM_DES_MAC_GENERAL:
case CKM_DES_MAC:
{
if (pSignature != NULL) {
/* Pass local buffer to avoid overflow. */
} else {
/* Pass NULL, let callee to handle it. */
}
return (rv);
}
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
case CKM_DSA_SHA1:
case CKM_ECDSA_SHA1:
default:
/* PKCS11: The mechanism only supports single-part operation. */
return (CKR_MECHANISM_INVALID);
}
}
{
switch (pMechanism->mechanism) {
case CKM_RSA_X_509:
case CKM_RSA_PKCS:
default:
return (CKR_MECHANISM_INVALID);
}
}
{
switch (mechanism) {
case CKM_RSA_X_509:
case CKM_RSA_PKCS:
default:
return (CKR_MECHANISM_INVALID);
}
}
/*
* This function frees the allocated active crypto context.
* and the caller of this function may or may not hold the session mutex.
*/
void
{
if (!lock_held)
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
}
/* FALLTHRU */
case CKM_RSA_PKCS:
case CKM_RSA_X_509:
{
}
break;
}
case CKM_DSA_SHA1:
}
/* FALLTHRU */
case CKM_DSA:
{
}
break;
}
case CKM_SSL3_MD5_MAC:
case CKM_SSL3_SHA1_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
break;
case CKM_DES_MAC_GENERAL:
case CKM_DES_MAC:
}
break;
}
}
if (!lock_held)
}