ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * CDDL HEADER START
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * The contents of this file are subject to the terms of the
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * Common Development and Distribution License (the "License").
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * You may not use this file except in compliance with the License.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * See the License for the specific language governing permissions
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * and limitations under the License.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * When distributing Covered Code, include this CDDL HEADER in each
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * If applicable, add the following below this CDDL HEADER, with the
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * fields enclosed by brackets "[]" replaced with your own identifying
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * information: Portions Copyright [yyyy] [name of copyright owner]
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * CDDL HEADER END
4df55fde49134f9735f84011f23a767c75e393c7Janie Lu * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * Use is subject to license terms.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * Helper routine to know if this is a HMAC. We can't just check
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * the CKF_SIGN mech flag as it is set for non-HMAC mechs too.
b2a962217309a877fd63575155d80ad56aca8071krishna * Helper routine to allocate an emulation structure for the session.
b2a962217309a877fd63575155d80ad56aca8071krishna * buflen indicates the size of the scratch buffer to be allocated.
b2a962217309a877fd63575155d80ad56aca8071krishnaemulate_buf_init(kernel_session_t *session_p, int buflen, int opflag)
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna opp = (opflag & OP_DIGEST) ? &(session_p->digest) : \
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna ((opflag & OP_SIGN) ? &(session_p->sign) : &(session_p->verify));
0d94eea1ad2dcd8c1ad5169ee02e06c1b674e40aKrishna Yenduri * We can reuse the context structure, digest_buf_t.
0d94eea1ad2dcd8c1ad5169ee02e06c1b674e40aKrishna Yenduri * See if we can reuse the scratch buffer in the context too.
0d94eea1ad2dcd8c1ad5169ee02e06c1b674e40aKrishna Yenduri bufp = opp->context = calloc(1, sizeof (digest_buf_t));
b2a962217309a877fd63575155d80ad56aca8071krishna * Setup the support necessary to do this operation in a
b2a962217309a877fd63575155d80ad56aca8071krishna * single part. We allocate a buffer to accumulate the
b2a962217309a877fd63575155d80ad56aca8071krishna * input data from later calls. We also get ready for
b2a962217309a877fd63575155d80ad56aca8071krishna * the case where we have to do it in software by initializing
b2a962217309a877fd63575155d80ad56aca8071krishna * a standby context. The opflag tells if this is a sign or verify.
b2a962217309a877fd63575155d80ad56aca8071krishnaemulate_init(kernel_session_t *session_p, CK_MECHANISM_PTR pMechanism,
b2a962217309a877fd63575155d80ad56aca8071krishna if ((rv = emulate_buf_init(session_p, EDIGEST_LENGTH, opflag)) !=
b2a962217309a877fd63575155d80ad56aca8071krishna opp = (opflag & OP_SIGN) ? &(session_p->sign) : &(session_p->verify);
b2a962217309a877fd63575155d80ad56aca8071krishna rv = do_soft_hmac_init(get_spp(opp), pMechanism, keyp->ck_data,
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna#define DO_SOFT_UPDATE(opp, pPart, ulPartLen, opflag) \
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * Accumulate the input data in the buffer, allocating a bigger
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * buffer if needed. If we reach the maximum input data size
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * that can be accumulated, start using the software from then on.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna * The opflag tells if this is a digest, sign or verify.
ba5f469c0173c4d47f377c20b530f5be165d49dckrishnaemulate_update(kernel_session_t *session_p, CK_BYTE_PTR pPart,
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna /* Did we exceed the maximum allowed? */
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna } else if (ulPartLen > (bufp->buf_len - bufp->indata_len)) {
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna /* Try harder rather than failing */
b2a962217309a877fd63575155d80ad56aca8071krishna rv = do_soft_digest(get_spp(opp), pMechanism, NULL, 0,
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna DO_SOFT_UPDATE(opp, bufp->buf, bufp->indata_len, opflag);
ba5f469c0173c4d47f377c20b530f5be165d49dckrishna /* accumulate the update data */