/*
* 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
*/
/*
*/
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <security/cryptoki.h>
#include "softSession.h"
#include "softObject.h"
#include "softCrypt.h"
#include <blowfish/blowfish_impl.h>
{
if (soft_blowfish_ctx == NULL) {
return (CKR_HOST_MEMORY);
}
return (CKR_HOST_MEMORY);
}
/*
* If this is a non-sensitive key and it does NOT have
* a key schedule yet, then allocate one and expand it.
* Otherwise, if it's a non-sensitive key, and it DOES have
* a key schedule already attached to it, just copy the
* pre-expanded schedule to the context and avoid the
* extra key schedule expansion operation.
*/
void *ks;
(void) pthread_rwlock_unlock(
&key_p->object_rwlock);
return (CKR_HOST_MEMORY);
}
}
}
} else {
/*
* Initialize key schedule for Blowfish.
* blowfish_init_keysched() requires key length in bits.
*/
}
return (CKR_OK);
}
/*
* soft_blowfish_encrypt_common()
*
* Arguments:
* session_p: pointer to soft_session_t struct
* pData: pointer to the input data to be encrypted
* ulDataLen: length of the input data
* pEncrypted: pointer to the output data after encryption
* pulEncryptedLen: pointer to the length of the output data
* update: boolean flag indicates caller is soft_encrypt
* or soft_encrypt_update
*
* Description:
* This function calls the corresponding encrypt routine based
* on the mechanism.
*
* Returns:
* CKR_OK: success
* CKR_BUFFER_TOO_SMALL: the output buffer provided by application
* is too small
* CKR_FUNCTION_FAILED: encrypt function failed
* CKR_DATA_LEN_RANGE: the input data is not a multiple of blocksize
*/
{
int rc = 0;
/*
* Blowfish only takes input length that is a multiple of blocksize
* for C_Encrypt function with the mechanism CKM_BLOWFISH_CBC.
*
*/
if (!update) {
if ((ulDataLen % BLOWFISH_BLOCK_LEN) != 0) {
goto cleanup;
}
/*
* If application asks for the length of the output buffer
* to hold the ciphertext?
*/
if (pEncrypted == NULL) {
return (CKR_OK);
}
/* Is the application-supplied buffer large enough? */
if (*pulEncryptedLen < out_len) {
return (CKR_BUFFER_TOO_SMALL);
}
} else {
/*
* Called by C_EncryptUpdate
*
* Add the lengths of last remaining data and current
* plaintext together to get the total input length.
*/
/*
* If the total input length is less than one blocksize,
* we will need to delay encryption until when more data
* comes in next C_EncryptUpdate or when C_EncryptFinal
* is called.
*/
if (total_len < BLOWFISH_BLOCK_LEN) {
if (pEncrypted != NULL) {
/*
* Save input data and its length in
* the remaining buffer of BLOWFISH context.
*/
}
/* Set encrypted data length to 0. */
*pulEncryptedLen = 0;
return (CKR_OK);
}
/* Compute the length of remaining data. */
/*
* Make sure that the output length is a multiple of
* blocksize.
*/
/*
* If application asks for the length of the output buffer
* to hold the ciphertext?
*/
if (pEncrypted == NULL) {
return (CKR_OK);
}
/* Is the application-supplied buffer large enough? */
if (*pulEncryptedLen < out_len) {
return (CKR_BUFFER_TOO_SMALL);
}
if (soft_blowfish_ctx->remain_len != 0) {
/*
* Copy last remaining data and current input data
* to the output buffer.
*/
(void) memmove(pEncrypted +
in_buf = pEncrypted;
} else {
}
}
/*
* Begin Encryption now.
*/
/* Encrypt multiple blocks of data. */
if (rc == 0) {
if (update) {
/*
* For encrypt update, if there is remaining data,
* save it and it's length in the context.
*/
if (remain != 0)
return (CKR_OK);
}
} else {
*pulEncryptedLen = 0;
}
if (blowfish_ctx != NULL) {
}
sizeof (soft_blowfish_ctx_t));
return (rv);
}
{
int rc = 0;
/*
* Blowfish only takes input length that is a multiple of 16 bytes
* for C_Decrypt function using CKM_BLOWFISH_CBC.
*/
if (!update) {
/* Called by C_Decrypt */
if ((ulEncryptedLen % BLOWFISH_BLOCK_LEN) != 0) {
goto cleanup;
}
/*
* If application asks for the length of the output buffer
* to hold the plaintext?
*/
return (CKR_OK);
}
/* Is the application-supplied buffer large enough? */
if (*pulDataLen < ulEncryptedLen) {
return (CKR_BUFFER_TOO_SMALL);
}
in_buf = pEncrypted;
} else {
/*
* Called by C_DecryptUpdate
*
* Add the lengths of last remaining data and current
* input data together to get the total input length.
*/
if (total_len < BLOWFISH_BLOCK_LEN) {
}
/* Set output data length to 0. */
*pulDataLen = 0;
return (CKR_OK);
}
/* Compute the length of remaining data. */
/*
* Make sure that the output length is a multiple of
* blocksize.
*/
/*
* if application asks for the length of the output buffer
* to hold the plaintext?
*/
*pulDataLen = out_len;
return (CKR_OK);
}
/*
* Is the application-supplied buffer large enough?
*/
if (*pulDataLen < out_len) {
*pulDataLen = out_len;
return (CKR_BUFFER_TOO_SMALL);
}
if (soft_blowfish_ctx->remain_len != 0) {
/*
* Copy last remaining data and current input data
* to the output buffer.
*/
} else {
in_buf = pEncrypted;
}
}
/* Decrypt multiple blocks of data. */
if (rc == 0) {
*pulDataLen = out_len;
if (update) {
/*
* For decrypt update, if there is remaining data,
* save it and its length in the context.
*/
if (remain != 0)
remain);
return (CKR_OK);
}
} else {
*pulDataLen = 0;
}
if (blowfish_ctx != NULL) {
}
sizeof (soft_blowfish_ctx_t));
return (rv);
}
/*
* Allocate and initialize a context for BLOWFISH CBC mode of operation.
*/
void *
{
return (NULL);
return (cbc_ctx);
}