/*
* 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 2013 Saso Kiselkov. All rights reserved.
*/
#include <sys/sysmacros.h>
#define SKEIN_MODULE_IMPL
/*
* Like the sha2 module, we create the skein module with two modlinkages:
* - modlmisc to allow direct calls to Skein_* API functions.
* - modlcrypto to integrate well into the Kernel Crypto Framework (KCF).
*/
"Skein Message-Digest Algorithm"
};
"Skein Kernel SW Provider"
};
};
0, 0, CRYPTO_KEYSIZE_UNIT_IN_BITS},
0, 0, CRYPTO_KEYSIZE_UNIT_IN_BITS},
0, 0, CRYPTO_KEYSIZE_UNIT_IN_BITS},
};
};
NULL,
};
NULL,
skein_update, /* using regular digest update is OK here */
skein_final, /* using regular digest final is OK here */
};
static int skein_create_ctx_template(crypto_provider_handle_t,
static int skein_free_context(crypto_ctx_t *);
};
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
"Skein Software Provider",
{&modlinkage},
NULL,
sizeof (skein_mech_info_tab) / sizeof (crypto_mech_info_t),
};
typedef struct skein_ctx {
union {
} sc_u;
} skein_ctx_t;
do { \
switch (sc->sc_mech_type) { \
case SKEIN_256_MECH_INFO_TYPE: \
case SKEIN_256_MAC_MECH_INFO_TYPE: \
__VA_ARGS__); \
break; \
case SKEIN_512_MECH_INFO_TYPE: \
case SKEIN_512_MAC_MECH_INFO_TYPE: \
__VA_ARGS__); \
break; \
case SKEIN1024_MECH_INFO_TYPE: \
case SKEIN1024_MAC_MECH_INFO_TYPE: \
__VA_ARGS__); \
break; \
} \
} while (0)
static int
{
/*LINTED(E_BAD_PTR_CAST_ALIGN)*/
param->sp_digest_bitlen == 0) {
return (CRYPTO_MECHANISM_PARAM_INVALID);
}
} else {
case SKEIN_256_MECH_INFO_TYPE:
*result = 256;
break;
case SKEIN_512_MECH_INFO_TYPE:
*result = 512;
break;
case SKEIN1024_MECH_INFO_TYPE:
*result = 1024;
break;
default:
return (CRYPTO_MECHANISM_INVALID);
}
}
return (CRYPTO_SUCCESS);
}
int
_init(void)
{
int error;
return (error);
/*
* Try to register with KCF - failure shouldn't unload us, since we
*/
return (0);
}
int
{
}
/*
* KCF software provider control entry points.
*/
/* ARGSUSED */
static void
{
}
/*
* General Skein hashing helper functions.
*/
/*
* Performs an Update on a context with uio input 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);
}
/*
* Performs a Final on a context and writes to a uio digest output.
*/
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);
}
/* The computed digest will fit in the current iovec. */
} else {
if (digest_tmp == NULL)
return (CRYPTO_HOST_MEMORY);
length);
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);
}
/*
* Performs an Update on a context with mblk input data.
*/
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);
}
/*
* Performs a Final on a context and writes to an mblk digest output.
*/
static int
{
/* Jump to the first mblk_t that will be used to store the digest. */
;
/* caller specified offset is too large */
return (CRYPTO_DATA_LEN_RANGE);
}
/* The digest will fit in the current mblk. */
} else {
/* Split the digest up between the individual buffers. */
if (digest_tmp == NULL)
return (CRYPTO_HOST_MEMORY);
offset = 0;
}
/* digest too long to fit in the mblk buffers */
return (CRYPTO_DATA_LEN_RANGE);
}
}
return (CRYPTO_SUCCESS);
}
/*
* KCF software provider digest entry points.
*/
/*
* Initializes a skein digest context to the configuration in `mechanism'.
* The mechanism cm_type must be one of SKEIN_*_MECH_INFO_TYPE. The cm_param
* field may contain a skein_param_t structure indicating the length of the
* digest the algorithm should produce. Otherwise the default output lengths
* are applied (32 bytes for Skein-256, 64 bytes for Skein-512 and 128 bytes
* for Skein-1024).
*/
static int
{
return (CRYPTO_MECHANISM_INVALID);
crypto_kmflag(req));
return (CRYPTO_HOST_MEMORY);
if (error != CRYPTO_SUCCESS)
goto errout;
return (CRYPTO_SUCCESS);
return (error);
}
/*
* Executes a skein_update and skein_digest on a pre-initialized crypto
* context in a single step. See the documentation to these functions to
* see what to pass here.
*/
static int
{
return (CRYPTO_BUFFER_TOO_SMALL);
}
if (error != CRYPTO_SUCCESS) {
return (error);
}
return (error);
}
/*
* Performs a skein Update with the input message in `data' (successive calls
* can push more data). This is used both for digest and MAC operation.
* Supported input data formats are raw, uio and mblk.
*/
/*ARGSUSED*/
static int
{
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
return (error);
}
/*
* Performs a skein Final, writing the output to `digest'. This is used both
* for digest and MAC operation.
* Supported output digest formats are raw, uio and mblk.
*/
/*ARGSUSED*/
static int
{
return (CRYPTO_BUFFER_TOO_SMALL);
}
case CRYPTO_DATA_RAW:
break;
case CRYPTO_DATA_UIO:
break;
case CRYPTO_DATA_MBLK:
break;
default:
}
if (error == CRYPTO_SUCCESS)
else
return (error);
}
/*
* Performs a full skein digest computation in a single call, configuring the
* algorithm according to `mechanism', reading the input to be digested from
* `data' and writing the output to `digest'.
*/
/*ARGSUSED*/
static int
{
int error;
/* Init */
return (CRYPTO_MECHANISM_INVALID);
if (error != CRYPTO_SUCCESS)
goto out;
goto out;
goto out;
out:
if (error == CRYPTO_SUCCESS)
else
return (error);
}
/*
* Helper function that builds a Skein MAC context from the provided
* mechanism and key.
*/
static int
{
int error;
return (CRYPTO_MECHANISM_INVALID);
return (CRYPTO_ARGUMENTS_BAD);
if (error != CRYPTO_SUCCESS)
return (error);
return (CRYPTO_SUCCESS);
}
/*
* KCF software provide mac entry points.
*/
/*
* Initializes a skein MAC context. You may pass a ctx_template, in which
* case the template will be reused to make initialization more efficient.
* Otherwise a new context will be constructed. The mechanism cm_type must
* be one of SKEIN_*_MAC_MECH_INFO_TYPE. Same as in skein_digest_init, you
* may pass a skein_param_t in cm_param to configure the length of the
* digest. The key must be in raw format.
*/
static int
{
int error;
crypto_kmflag(req));
return (CRYPTO_HOST_MEMORY);
if (ctx_template != NULL) {
} else {
if (error != CRYPTO_SUCCESS)
goto errout;
}
return (CRYPTO_SUCCESS);
return (error);
}
/*
* The MAC update and final calls are reused from the regular digest code.
*/
/*ARGSUSED*/
/*
* Same as skein_digest_atomic, performs an atomic Skein MAC operation in
* one step. All the same properties apply to the arguments of this
* function as to those of the partial operations above.
*/
static int
{
/* faux crypto context just for skein_digest_{update,final} */
int error;
if (ctx_template != NULL) {
} else {
if (error != CRYPTO_SUCCESS)
goto errout;
}
goto errout;
goto errout;
return (CRYPTO_SUCCESS);
return (error);
}
/*
* KCF software provider context management entry points.
*/
/*
* Constructs a context template for the Skein MAC algorithm. The same
* properties apply to the arguments of this function as to those of
* skein_mac_init.
*/
/*ARGSUSED*/
static int
{
int error;
return (CRYPTO_HOST_MEMORY);
if (error != CRYPTO_SUCCESS)
goto errout;
*ctx_template = ctx_tmpl;
*ctx_template_size = sizeof (*ctx_tmpl);
return (CRYPTO_SUCCESS);
return (error);
}
/*
* Frees a skein context in a parent crypto context.
*/
static int
{
}
return (CRYPTO_SUCCESS);
}