dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / pkcs11 / libpkcs11 / common / pkcs11Digest.c
blob2199a6e9083f968c89a1894ee4b8a01aef695d59
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <security/cryptoki.h>
30 #include "pkcs11Global.h"
31 #include "pkcs11Conf.h"
32 #include "pkcs11Session.h"
33 #include "pkcs11Slot.h"
36 * C_DigestInit will verify that the session handle is valid within
37 * the framework, that the mechanism is not disabled for the slot
38 * associated with this session, and then redirect to the underlying
39 * provider. Policy is only checked for C_DigestInit, since it is
40 * required to be called before C_Digest and C_DigestUpdate.
42 CK_RV
43 C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism)
46 CK_RV rv;
47 pkcs11_session_t *sessp;
48 CK_SLOT_ID slotid;
50 /* Check for a fastpath */
51 if (purefastpath || policyfastpath) {
52 if (policyfastpath &&
53 pkcs11_is_dismech(fast_slot, pMechanism->mechanism)) {
54 return (CKR_MECHANISM_INVALID);
56 return (fast_funcs->C_DigestInit(hSession, pMechanism));
59 if (!pkcs11_initialized) {
60 return (CKR_CRYPTOKI_NOT_INITIALIZED);
63 /* Obtain the session pointer */
64 HANDLE2SESSION(hSession, sessp, rv);
66 if (rv != CKR_OK) {
67 return (rv);
70 slotid = sessp->se_slotid;
72 /* Make sure this is not a disabled mechanism */
73 if (pkcs11_is_dismech(slotid, pMechanism->mechanism)) {
74 return (CKR_MECHANISM_INVALID);
77 /* Initialize the digest with the underlying provider */
78 rv = FUNCLIST(slotid)->C_DigestInit(sessp->se_handle,
79 pMechanism);
81 /* Present consistent interface to the application */
82 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
83 return (CKR_FUNCTION_FAILED);
86 return (rv);
90 * C_Digest is a pure wrapper to the underlying provider.
91 * The only argument checked is whether or not hSession is valid.
93 CK_RV
94 C_Digest(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
95 CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen)
98 CK_RV rv;
99 pkcs11_session_t *sessp;
101 /* Check for a fastpath */
102 if (purefastpath || policyfastpath) {
103 return (fast_funcs->C_Digest(hSession, pData, ulDataLen,
104 pDigest, pulDigestLen));
107 if (!pkcs11_initialized) {
108 return (CKR_CRYPTOKI_NOT_INITIALIZED);
111 /* Obtain the session pointer */
112 HANDLE2SESSION(hSession, sessp, rv);
114 if (rv != CKR_OK) {
115 return (rv);
118 /* Pass data to the provider */
119 rv = FUNCLIST(sessp->se_slotid)->C_Digest(sessp->se_handle, pData,
120 ulDataLen, pDigest, pulDigestLen);
122 /* Present consistent interface to the application */
123 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
124 return (CKR_FUNCTION_FAILED);
127 return (rv);
132 * C_DigestUpdate is a pure wrapper to the underlying provider.
133 * The only argument checked is whether or not hSession is valid.
135 CK_RV
136 C_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
137 CK_ULONG ulPartLen)
139 CK_RV rv;
140 pkcs11_session_t *sessp;
142 /* Check for a fastpath */
143 if (purefastpath || policyfastpath) {
144 return (fast_funcs->C_DigestUpdate(hSession, pPart,
145 ulPartLen));
148 if (!pkcs11_initialized) {
149 return (CKR_CRYPTOKI_NOT_INITIALIZED);
152 /* Obtain the session pointer */
153 HANDLE2SESSION(hSession, sessp, rv);
155 if (rv != CKR_OK) {
156 return (rv);
159 /* Pass data to the provider */
160 rv = FUNCLIST(sessp->se_slotid)->C_DigestUpdate(sessp->se_handle,
161 pPart, ulPartLen);
163 /* Present consistent interface to the application */
164 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
165 return (CKR_FUNCTION_FAILED);
168 return (rv);
172 * C_DigestKey is a pure wrapper to the underlying provider.
173 * The only argument checked is whether or not hSession is valid.
175 CK_RV
176 C_DigestKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey)
178 CK_RV rv;
179 pkcs11_session_t *sessp;
181 /* Check for a fastpath */
182 if (purefastpath || policyfastpath) {
183 return (fast_funcs->C_DigestKey(hSession, hKey));
186 if (!pkcs11_initialized) {
187 return (CKR_CRYPTOKI_NOT_INITIALIZED);
190 /* Obtain the session pointer */
191 HANDLE2SESSION(hSession, sessp, rv);
193 if (rv != CKR_OK) {
194 return (rv);
197 /* Pass data to the provider */
198 rv = FUNCLIST(sessp->se_slotid)->C_DigestKey(sessp->se_handle, hKey);
200 /* Present consistent interface to the application */
201 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
202 return (CKR_FUNCTION_FAILED);
205 return (rv);
209 * C_DigestFinal is a pure wrapper to the underlying provider.
210 * The only argument checked is whether or not hSession is valid.
212 CK_RV
213 C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest,
214 CK_ULONG_PTR pulDigestLen)
216 CK_RV rv;
217 pkcs11_session_t *sessp;
219 /* Check for a fastpath */
220 if (purefastpath || policyfastpath) {
221 return (fast_funcs->C_DigestFinal(hSession, pDigest,
222 pulDigestLen));
225 if (!pkcs11_initialized) {
226 return (CKR_CRYPTOKI_NOT_INITIALIZED);
229 /* Obtain the session pointer */
230 HANDLE2SESSION(hSession, sessp, rv);
232 if (rv != CKR_OK) {
233 return (rv);
236 /* Pass data to the provider */
237 rv = FUNCLIST(sessp->se_slotid)->C_DigestFinal(sessp->se_handle,
238 pDigest, pulDigestLen);
240 /* Present consistent interface to the application */
241 if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
242 return (CKR_FUNCTION_FAILED);
245 return (rv);