/*
* 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.
*/
/*
* In kernel module, the md4 module is created with one modlinkage,
* this is different to md5 and sha1 modules which have a legacy misc
*
* - a modlcrypto that allows the module to register with the Kernel
* Cryptographic Framework (KCF) as a software provider for the MD4
* mechanisms.
*/
#include <sys/sysmacros.h>
extern struct mod_ops mod_miscops;
extern struct mod_ops mod_cryptoops;
/*
* Module linkage information for the kernel.
*/
"MD4 Kernel SW Provider"
};
(void *)&modlcrypto,
};
/*
* CSPI information (entry points, provider info, etc.)
*/
typedef enum md4_mech_type {
/*
* Context for MD4 mechanism.
*/
typedef struct md4_ctx {
} md4_ctx_t;
/*
* Macros to access the MD4 contexts from a context passed
* by KCF to one of the entry points.
*/
/*
* Mechanism info structure passed to KCF during registration.
*/
/* MD4 */
0, 0, CRYPTO_KEYSIZE_UNIT_IN_BITS},
};
};
NULL,
};
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
"MD4 Software Provider",
{&modlinkage},
NULL,
sizeof (md4_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. */
(void) mod_remove(&modlinkage);
return (EACCES);
}
return (0);
}
int
_fini(void)
{
/* Unregister from KCF if module is registered */
if (md4_prov_handle != NULL) {
return (EBUSY);
}
return (mod_remove(&modlinkage));
}
int
{
}
/*
* KCF software provider control entry points.
*/
/* ARGSUSED */
static void
{
}
/*
* KCF software provider digest entry points.
*/
static int
{
return (CRYPTO_MECHANISM_INVALID);
/*
* Allocate and initialize MD4 context.
*/
crypto_kmflag(req));
return (CRYPTO_HOST_MEMORY);
return (CRYPTO_SUCCESS);
}
/*
* Helper MD4 digest update function for uio data.
*/
static int
{
/* we support only kernel buffer */
return (CRYPTO_ARGUMENTS_BAD);
/*
* Jump to the first iovec containing data to be
* digested.
*/
;
/*
* The caller specified an offset that is larger than the
* total size of the buffers it provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
/*
* Now do the digesting on the iovecs.
*/
vec_idx++;
offset = 0;
}
/*
* The end of the specified iovec's was reached but
* the length requested could not be processed, i.e.
* The caller requested to digest more data than it provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
return (CRYPTO_SUCCESS);
}
/*
* Helper MD4 digest final function for uio data.
* digest_len is the length of the desired digest. If digest_len
* is smaller than the default MD4 digest length, the caller
* must pass a scratch buffer, digest_scratch, which must
* be at least MD4_DIGEST_LENGTH bytes.
*/
static int
{
/* we support only kernel buffer */
return (CRYPTO_ARGUMENTS_BAD);
/*
* Jump to the first iovec containing ptr to the digest to
* be returned.
*/
;
/*
* The caller specified an offset that is
* larger than the total size of the buffers
* it provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
if (offset + digest_len <=
/*
* The computed MD4 digest will fit in the current
* iovec.
*/
if (digest_len != MD4_DIGEST_LENGTH) {
/*
* The caller requested a short digest. Digest
* into a scratch buffer and return to
* the user only what was requested.
*/
} else {
md4_ctx);
}
} else {
/*
* The computed digest will be crossing one or more iovec's.
* This is bad performance-wise but we need to support it.
* Allocate a small scratch buffer on the stack and
* copy it piece meal to the specified digest iovec's.
*/
cur_len);
vec_idx++;
offset = 0;
}
/*
* The end of the specified iovec's was reached but
* the length requested could not be processed, i.e.
* The caller requested to digest more data than it
* provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
}
return (CRYPTO_SUCCESS);
}
/*
* Helper MD4 digest update for mblk's.
*/
static int
{
/*
* Jump to the first mblk_t containing data to be digested.
*/
;
/*
* The caller specified an offset that is larger than the
* total size of the buffers it provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
/*
* Now do the digesting on the mblk chain.
*/
offset = 0;
}
/*
* The end of the mblk was reached but the length requested
* could not be processed, i.e. The caller requested
* to digest more data than it provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
return (CRYPTO_SUCCESS);
}
/*
* Helper MD4 digest final for mblk's.
* digest_len is the length of the desired digest. If digest_len
* is smaller than the default MD4 digest length, the caller
* must pass a scratch buffer, digest_scratch, which must
* be at least MD4_DIGEST_LENGTH bytes.
*/
static int
{
/*
* Jump to the first mblk_t that will be used to store the digest.
*/
;
/*
* The caller specified an offset that is larger than the
* total size of the buffers it provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
/*
* The computed MD4 digest will fit in the current mblk.
* Do the MD4Final() in-place.
*/
if (digest_len != MD4_DIGEST_LENGTH) {
/*
* The caller requested a short digest. Digest
* into a scratch buffer and return to
* the user only what was requested.
*/
} else {
}
} else {
/*
* The computed digest will be crossing one or more mblk's.
* This is bad performance-wise but we need to support it.
* Allocate a small scratch buffer on the stack and
* copy it piece meal to the specified digest iovec's.
*/
offset = 0;
}
/*
* The end of the specified mblk was reached but
* the length requested could not be processed, i.e.
* The caller requested to digest more data than it
* provided.
*/
return (CRYPTO_DATA_LEN_RANGE);
}
}
return (CRYPTO_SUCCESS);
}
/* ARGSUSED */
static int
{
/*
* We need to just return the length needed to store the output.
* We should not destroy the context for the following cases.
*/
return (CRYPTO_BUFFER_TOO_SMALL);
}
/*
* Do the MD4 update on the specified input data.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
data);
break;
case CRYPTO_DATA_MBLK:
data);
break;
default:
}
if (ret != CRYPTO_SUCCESS) {
/* the update failed, free context and bail */
return (ret);
}
/*
* Do an MD4 final, must be done separately since the digest
* type can be different than the input data type.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
/* all done, free context and return */
if (ret == CRYPTO_SUCCESS) {
} else {
}
return (ret);
}
/* ARGSUSED */
static int
{
/*
* Do the MD4 update on the specified input data.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
data);
break;
case CRYPTO_DATA_MBLK:
data);
break;
default:
}
return (ret);
}
/* ARGSUSED */
static int
{
/*
* We need to just return the length needed to store the output.
* We should not destroy the context for the following cases.
*/
return (CRYPTO_BUFFER_TOO_SMALL);
}
/*
* Do an MD4 final.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
/* all done, free context and return */
if (ret == CRYPTO_SUCCESS) {
} else {
}
return (ret);
}
/* ARGSUSED */
static int
{
return (CRYPTO_MECHANISM_INVALID);
/*
* Do the MD4 init.
*/
/*
* Do the MD4 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) {
/* the update failed, bail */
return (ret);
}
/*
* Do an MD4 final, must be done separately since the digest
* type can be different than the input data type.
*/
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
if (ret == CRYPTO_SUCCESS) {
} else {
}
return (ret);
}