/*
* 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 <sys/sysmacros.h>
/*
* Message digest routines
*/
/*
* The following are the possible returned values common to all the routines
* below. The applicability of some of these return values depends on the
* presence of the arguments.
*
* CRYPTO_SUCCESS: The operation completed successfully.
* CRYPTO_QUEUED: A request was submitted successfully. The callback
* routine will be called when the operation is done.
* CRYPTO_MECHANISM_INVALID or CRYPTO_INVALID_MECH_PARAM
* for problems with the 'mech'.
* CRYPTO_INVALID_DATA for bogus 'data'
* CRYPTO_HOST_MEMORY for failure to allocate memory to handle this work.
* CRYPTO_INVALID_CONTEXT: Not a valid context.
* CRYPTO_BUSY: Cannot process the request now. Schedule a
* crypto_bufcall(), or try later.
* CRYPTO_NOT_SUPPORTED and CRYPTO_MECH_NOT_SUPPORTED:
* No provider is capable of a function or a mechanism.
*/
/*
* crypto_digest_prov()
*
* Arguments:
* pd: pointer to the descriptor of the provider to use for this
* operation.
* sid: provider session id.
* mech: crypto_mechanism_t pointer.
* mech_type is a valid value previously returned by
* crypto_mech2id();
* When the mech's parameter is not NULL, its definition depends
* on the standard definition of the mechanism.
* data: The message to be digested.
* digest: Storage for the digest. The length needed depends on the
* mechanism.
* cr: crypto_call_req_t calling conditions and call back info.
*
* Description:
* Asynchronously submits a request for, or synchronously performs the
* digesting operation of 'data' on the specified
* provider with the specified session.
* When complete and successful, 'digest' will contain the digest value.
* The caller should hold a reference on the specified provider
* descriptor before calling this function.
*
* Context:
* Process or interrupt, according to the semantics dictated by the 'cr'.
*
* Returns:
* See comment in the beginning of the file.
*/
int
{
int rv;
if (rv != CRYPTO_SUCCESS)
return (rv);
}
/* no crypto context to carry between multiple parts. */
return (rv);
}
/*
* Same as crypto_digest_prov(), but relies on the KCF scheduler to
* choose a provider. See crypto_digest_prov() comments for more information.
*/
int
{
int error;
/* The pd is returned held */
return (error);
}
/* The fast path for SW providers. */
} else {
} else {
/* no crypto context to carry between multiple parts. */
B_FALSE);
}
}
IS_RECOVERABLE(error)) {
/* Add pd to the linked list of providers tried. */
goto retry;
}
return (error);
}
/*
* crypto_digest_init_prov()
*
* pd: pointer to the descriptor of the provider to use for this
* operation.
* sid: provider session id.
* mech: crypto_mechanism_t pointer.
* mech_type is a valid value previously returned by
* crypto_mech2id();
* When the mech's parameter is not NULL, its definition depends
* on the standard definition of the mechanism.
* ctxp: Pointer to a crypto_context_t.
* cr: crypto_call_req_t calling conditions and call back info.
*
* Description:
* Asynchronously submits a request for, or synchronously performs the
* initialization of a message digest operation on the specified
* provider with the specified session.
* When complete and successful, 'ctxp' will contain a crypto_context_t
* valid for later calls to digest_update() and digest_final().
* The caller should hold a reference on the specified provider
* descriptor before calling this function.
*/
int
{
int error;
if (error != CRYPTO_SUCCESS)
return (error);
}
/* Allocate and initialize the canonical context */
return (CRYPTO_HOST_MEMORY);
}
/* The fast path for SW providers. */
} else {
B_FALSE);
}
else {
/* Release the hold done in kcf_new_ctx(). */
}
return (error);
}
/*
* Same as crypto_digest_init_prov(), but relies on the KCF scheduler
* to choose a provider. See crypto_digest_init_prov() comments for
* more information.
*/
int
{
int error;
/* The pd is returned held */
return (error);
}
/*
* The hardware provider has limited digest support.
* So, we fallback early here to using a software provider.
*
* XXX - need to enhance to do the fallback later in
* crypto_digest_update() if the size of accumulated input data
* exceeds the maximum size digestable by hardware provider.
*/
} else {
}
IS_RECOVERABLE(error)) {
/* Add pd to the linked list of providers tried. */
goto retry;
}
return (error);
}
/*
* crypto_digest_update()
*
* Arguments:
* context: A crypto_context_t initialized by digest_init().
* data: The part of message to be digested.
* cr: crypto_call_req_t calling conditions and call back info.
*
* Description:
* Asynchronously submits a request for, or synchronously performs a
* part of a message digest operation.
*
* Context:
* Process or interrupt, according to the semantics dictated by the 'cr'.
*
* Returns:
* See comment in the beginning of the file.
*/
int
{
int error;
return (CRYPTO_INVALID_CONTEXT);
}
/* The fast path for SW providers. */
} else {
}
return (error);
}
/*
* crypto_digest_final()
*
* Arguments:
* context: A crypto_context_t initialized by digest_init().
* digest: The storage for the digest.
* cr: crypto_call_req_t calling conditions and call back info.
*
* Description:
* Asynchronously submits a request for, or synchronously performs the
* final part of a message digest operation.
*
* Context:
* Process or interrupt, according to the semantics dictated by the 'cr'.
*
* Returns:
* See comment in the beginning of the file.
*/
int
{
int error;
return (CRYPTO_INVALID_CONTEXT);
}
/* The fast path for SW providers. */
} else {
}
/* Release the hold done in kcf_new_ctx() during init step. */
return (error);
}
/*
* Performs a digest update on the specified key. Note that there is
* no k-API crypto_digest_key() equivalent of this function.
*/
int
{
int error;
return (CRYPTO_INVALID_CONTEXT);
}
/* The fast path for SW providers. */
} else {
}
return (error);
}
/*
* See comments for crypto_digest_update() and crypto_digest_final().
*/
int
{
int error;
return (CRYPTO_INVALID_CONTEXT);
}
/* The fast path for SW providers. */
} else {
}
/* Release the hold done in kcf_new_ctx() during init step. */
return (error);
}