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]
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"
41 meta_DigestInit(CK_SESSION_HANDLE hSession
, CK_MECHANISM_PTR pMechanism
)
44 meta_session_t
*session
;
46 if (pMechanism
== NULL
)
47 return (CKR_ARGUMENTS_BAD
);
49 rv
= meta_handle2session(hSession
, &session
);
53 rv
= meta_operation_init_defer(CKF_DIGEST
, session
, pMechanism
, NULL
);
66 meta_Digest(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pData
, CK_ULONG ulDataLen
,
67 CK_BYTE_PTR pDigest
, CK_ULONG_PTR pulDigestLen
)
70 meta_session_t
*session
;
73 if (pData
== NULL
|| pulDigestLen
== NULL
)
74 return (CKR_ARGUMENTS_BAD
);
76 rv
= meta_handle2session(hSession
, &session
);
80 rv
= meta_do_operation(CKF_DIGEST
, MODE_SINGLE
, session
, NULL
,
81 pData
, ulDataLen
, pDigest
, pulDigestLen
);
94 meta_DigestUpdate(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pPart
,
98 meta_session_t
*session
;
102 return (CKR_ARGUMENTS_BAD
);
104 rv
= meta_handle2session(hSession
, &session
);
108 rv
= meta_do_operation(CKF_DIGEST
, MODE_UPDATE
, session
, NULL
,
109 pPart
, ulPartLen
, NULL
, NULL
);
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.
128 meta_DigestKey(CK_SESSION_HANDLE hSession
, CK_OBJECT_HANDLE hKey
)
131 meta_session_t
*session
;
134 rv
= meta_handle2session(hSession
, &session
);
138 rv
= meta_handle2object(hKey
, &key
);
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
);
160 meta_DigestFinal(CK_SESSION_HANDLE hSession
, CK_BYTE_PTR pDigest
,
161 CK_ULONG_PTR pulDigestLen
)
164 meta_session_t
*session
;
166 if (pulDigestLen
== NULL
)
167 return (CKR_ARGUMENTS_BAD
);
169 rv
= meta_handle2session(hSession
, &session
);
173 rv
= meta_do_operation(CKF_DIGEST
, MODE_FINAL
, session
, NULL
,
174 NULL
, 0, pDigest
, pulDigestLen
);