dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / pkcs11 / libpkcs11 / common / metaDigest.c
blob673b83cbfd6ed0765b837448480226f26a371cb9
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Message Digesting Functions
30 * (as defined in PKCS#11 spec section 11.10)
33 #include "metaGlobal.h"
37 * meta_DigestInit
40 CK_RV
41 meta_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism)
43 CK_RV rv;
44 meta_session_t *session;
46 if (pMechanism == NULL)
47 return (CKR_ARGUMENTS_BAD);
49 rv = meta_handle2session(hSession, &session);
50 if (rv != CKR_OK)
51 return (rv);
53 rv = meta_operation_init_defer(CKF_DIGEST, session, pMechanism, NULL);
55 REFRELEASE(session);
57 return (rv);
62 * meta_Digest
65 CK_RV
66 meta_Digest(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
67 CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen)
69 CK_RV rv;
70 meta_session_t *session;
73 if (pData == NULL || pulDigestLen == NULL)
74 return (CKR_ARGUMENTS_BAD);
76 rv = meta_handle2session(hSession, &session);
77 if (rv != CKR_OK)
78 return (rv);
80 rv = meta_do_operation(CKF_DIGEST, MODE_SINGLE, session, NULL,
81 pData, ulDataLen, pDigest, pulDigestLen);
83 REFRELEASE(session);
85 return (rv);
90 * meta_DigestUpdate
93 CK_RV
94 meta_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
95 CK_ULONG ulPartLen)
97 CK_RV rv;
98 meta_session_t *session;
101 if (pPart == NULL)
102 return (CKR_ARGUMENTS_BAD);
104 rv = meta_handle2session(hSession, &session);
105 if (rv != CKR_OK)
106 return (rv);
108 rv = meta_do_operation(CKF_DIGEST, MODE_UPDATE, session, NULL,
109 pPart, ulPartLen, NULL, NULL);
111 REFRELEASE(session);
113 return (rv);
118 * meta_DigestKey
120 * NOTE: This function can fail under certain circumstances!
121 * Unlike the other crypto functions, we didn't get the key object
122 * when the operation was initialized with C_DigestInit().
123 * Thus, the slot we're using for the digest operation may
124 * not be the slot containing the key -- if the key is extractible we can
125 * deal with it, but if it's not the operation will FAIL.
127 CK_RV
128 meta_DigestKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey)
130 CK_RV rv;
131 meta_session_t *session;
132 meta_object_t *key;
134 rv = meta_handle2session(hSession, &session);
135 if (rv != CKR_OK)
136 return (rv);
138 rv = meta_handle2object(hKey, &key);
139 if (rv != CKR_OK) {
140 REFRELEASE(session);
141 return (rv);
144 /* meta_do_operation() will clone the key, if needed. */
145 rv = meta_do_operation(CKF_DIGEST, MODE_UPDATE_WITHKEY, session, key,
146 NULL, 0, NULL, NULL);
148 OBJRELEASE(key);
149 REFRELEASE(session);
151 return (rv);
156 * meta_DigestFinal
159 CK_RV
160 meta_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest,
161 CK_ULONG_PTR pulDigestLen)
163 CK_RV rv;
164 meta_session_t *session;
166 if (pulDigestLen == NULL)
167 return (CKR_ARGUMENTS_BAD);
169 rv = meta_handle2session(hSession, &session);
170 if (rv != CKR_OK)
171 return (rv);
173 rv = meta_do_operation(CKF_DIGEST, MODE_FINAL, session, NULL,
174 NULL, 0, pDigest, pulDigestLen);
176 REFRELEASE(session);
178 return (rv);