/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Blowfish provider for the Kernel Cryptographic Framework (KCF)
*/
#include <sys/sysmacros.h>
#include <blowfish/blowfish_impl.h>
extern struct mod_ops mod_cryptoops;
/*
* Module linkage information for the kernel.
*/
"Blowfish Kernel SW Provider"
};
(void *)&modlcrypto,
};
/*
* CSPI information (entry points, provider info, etc.)
*/
typedef enum blowfish_mech_type {
/*
* Mechanism info structure passed to KCF during registration.
*/
/* BLOWFISH_ECB */
/* BLOWFISH_CBC */
};
/* operations are in-place if the output buffer is NULL */
};
static int blowfish_common_init_ctx(blowfish_ctx_t *,
static int blowfish_encrypt_atomic(crypto_provider_handle_t,
static int blowfish_decrypt_atomic(crypto_provider_handle_t,
};
static int blowfish_create_ctx_template(crypto_provider_handle_t,
static int blowfish_free_context(crypto_ctx_t *);
};
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
"Blowfish Software Provider",
{&modlinkage},
NULL,
sizeof (blowfish_mech_info_tab)/sizeof (crypto_mech_info_t),
};
int
_init(void)
{
int ret;
return (ret);
/* Register with KCF. If the registration fails, remove the module. */
&blowfish_prov_handle)) {
(void) mod_remove(&modlinkage);
return (EACCES);
}
return (0);
}
int
_fini(void)
{
/* Unregister from KCF if module is registered */
if (blowfish_prov_handle != NULL) {
return (EBUSY);
}
return (mod_remove(&modlinkage));
}
int
{
}
/*
* Initialize key schedules for blowfish
*/
static int
{
/*
* Only keys by value are supported by this module.
*/
case CRYPTO_KEY_RAW:
return (CRYPTO_KEY_SIZE_RANGE);
}
break;
default:
return (CRYPTO_KEY_TYPE_INCONSISTENT);
}
return (CRYPTO_SUCCESS);
}
/*
* KCF software provider control entry points.
*/
/* ARGSUSED */
static void
{
}
/*
* KCF software provider encrypt entry points.
*/
static int
{
int rv;
int kmflag;
/*
* Only keys by value are supported by this module.
*/
return (CRYPTO_KEY_TYPE_INCONSISTENT);
}
if (!BLOWFISH_VALID_MECH(mechanism))
return (CRYPTO_MECHANISM_INVALID);
return (CRYPTO_MECHANISM_PARAM_INVALID);
break;
break;
}
if (blowfish_ctx == NULL)
return (CRYPTO_HOST_MEMORY);
if (rv != CRYPTO_SUCCESS) {
return (rv);
}
return (CRYPTO_SUCCESS);
}
static void
{
/* LINTED: pointer alignment */
} else {
}
}
/* ARGSUSED */
static int
{
int ret;
/*
* Plaintext must be a multiple of blowfish block size.
* This test only works for non-padded mechanisms
* when blocksize is 2^N.
*/
return (CRYPTO_DATA_LEN_RANGE);
/*
* We need to just return the length needed to store the output.
* We should not destroy the context for the following case.
*/
return (CRYPTO_BUFFER_TOO_SMALL);
}
/*
* Do an update on the specified input data.
*/
(void) blowfish_free_context(ctx);
/* LINTED */
return (ret);
}
/* ARGSUSED */
static int
{
int ret;
/*
* Ciphertext must be a multiple of blowfish block size.
* This test only works for non-padded mechanisms
* when blocksize is 2^N.
*/
return (CRYPTO_ENCRYPTED_DATA_LEN_RANGE);
/*
* We need to just return the length needed to store the output.
* We should not destroy the context for the following case.
*/
return (CRYPTO_BUFFER_TOO_SMALL);
}
/*
* Do an update on the specified input data.
*/
(void) blowfish_free_context(ctx);
/* LINTED */
return (ret);
}
/* ARGSUSED */
static int
{
/* compute number of bytes that will hold the ciphertext */
out_len =
/* return length needed to store the output */
return (CRYPTO_BUFFER_TOO_SMALL);
}
/*
* Do the blowfish update on the specified input data.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
if (ret == CRYPTO_SUCCESS) {
if (plaintext != ciphertext)
} else {
}
return (ret);
}
/* ARGSUSED */
static int
{
/* compute number of bytes that will hold the plaintext */
out_len =
/* return length needed to store the output */
return (CRYPTO_BUFFER_TOO_SMALL);
}
/*
* Do the blowfish update on the specified input data.
*/
switch (ciphertext->cd_format) {
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
if (ret == CRYPTO_SUCCESS) {
if (ciphertext != plaintext)
} else {
}
return (ret);
}
/* ARGSUSED */
static int
{
/*
* There must be no unprocessed data.
* This happens if the length of the last data is
* not a multiple of the BLOWFISH block length.
*/
if (blowfish_ctx->bc_remainder_len > 0)
return (CRYPTO_DATA_LEN_RANGE);
(void) blowfish_free_context(ctx);
return (CRYPTO_SUCCESS);
}
/* ARGSUSED */
static int
{
/*
* There must be no unprocessed ciphertext.
* This happens if the length of the last ciphertext is
* not a multiple of the BLOWFISH block length.
*/
if (blowfish_ctx->bc_remainder_len > 0)
return (CRYPTO_ENCRYPTED_DATA_LEN_RANGE);
(void) blowfish_free_context(ctx);
return (CRYPTO_SUCCESS);
}
/* ARGSUSED */
static int
{
int ret;
/*
* Plaintext must be a multiple of blowfish block size.
* This test only works for non-padded mechanisms
* when blocksize is 2^N.
*/
return (CRYPTO_DATA_LEN_RANGE);
/* return length needed to store the output */
return (CRYPTO_BUFFER_TOO_SMALL);
}
if (!BLOWFISH_VALID_MECH(mechanism))
return (CRYPTO_MECHANISM_INVALID);
if (mechanism->cm_param_len != 0 &&
return (CRYPTO_MECHANISM_PARAM_INVALID);
if (ret != CRYPTO_SUCCESS)
return (ret);
/*
* Do an update on the specified input data.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
}
if (ret == CRYPTO_SUCCESS) {
if (plaintext != ciphertext)
} else {
}
return (ret);
}
/* ARGSUSED */
static int
{
int ret;
/*
* Ciphertext must be a multiple of blowfish block size.
* This test only works for non-padded mechanisms
* when blocksize is 2^N.
*/
return (CRYPTO_DATA_LEN_RANGE);
/* return length needed to store the output */
return (CRYPTO_BUFFER_TOO_SMALL);
}
if (!BLOWFISH_VALID_MECH(mechanism))
return (CRYPTO_MECHANISM_INVALID);
if (mechanism->cm_param_len != 0 &&
return (CRYPTO_MECHANISM_PARAM_INVALID);
if (ret != CRYPTO_SUCCESS)
return (ret);
/*
* Do an update on the specified input data.
*/
switch (ciphertext->cd_format) {
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
}
if (ret == CRYPTO_SUCCESS) {
if (ciphertext != plaintext)
} else {
}
return (ret);
}
/*
* KCF software provider context template entry points.
*/
/* ARGSUSED */
static int
{
void *keysched;
int rv;
if (!BLOWFISH_VALID_MECH(mechanism))
return (CRYPTO_MECHANISM_INVALID);
return (CRYPTO_HOST_MEMORY);
}
/*
* Initialize key schedule. Key length information is stored
* in the key.
*/
return (rv);
}
return (CRYPTO_SUCCESS);
}
/* ARGSUSED */
static int
{
if (blowfish_ctx != NULL) {
}
}
return (CRYPTO_SUCCESS);
}
/* ARGSUSED */
static int
{
void *keysched;
return (CRYPTO_HOST_MEMORY);
/*
* Initialize key schedule.
* Key length is stored in the key.
*/
} else {
}
break;
}
if (rv != CRYPTO_SUCCESS) {
}
}
return (rv);
}