dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / pkcs11 / libpkcs11 / common / metaSign.c
blobeca22fc7076a596fc04614b76e8fb988d74c5851
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 * Signing and MACing Functions
30 * (as defined in PKCs#11 spec section 11.11)
33 #include "metaGlobal.h"
37 * meta_SignInit
40 CK_RV
41 meta_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
42 CK_OBJECT_HANDLE hKey)
44 CK_RV rv;
45 meta_session_t *session;
46 meta_object_t *key;
48 if (pMechanism == NULL)
49 return (CKR_ARGUMENTS_BAD);
51 rv = meta_handle2session(hSession, &session);
52 if (rv != CKR_OK)
53 return (rv);
55 rv = meta_handle2object(hKey, &key);
56 if (rv != CKR_OK) {
57 REFRELEASE(session);
58 return (rv);
61 rv = meta_operation_init(CKF_SIGN, session, pMechanism, key);
63 OBJRELEASE(key);
64 REFRELEASE(session);
66 return (rv);
71 * meta_Sign
74 CK_RV
75 meta_Sign(CK_SESSION_HANDLE hSession,
76 CK_BYTE_PTR pData, CK_ULONG ulDataLen,
77 CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen)
79 CK_RV rv;
80 meta_session_t *session;
82 rv = meta_handle2session(hSession, &session);
83 if (rv != CKR_OK)
84 return (rv);
86 if (pData == NULL || pulSignatureLen == NULL) {
87 meta_operation_cleanup(session, CKF_SIGN, FALSE);
88 REFRELEASE(session);
89 return (CKR_ARGUMENTS_BAD);
92 rv = meta_do_operation(CKF_SIGN, MODE_SINGLE, session, NULL,
93 pData, ulDataLen, pSignature, pulSignatureLen);
95 REFRELEASE(session);
97 return (rv);
102 * meta_SignUpdate
105 CK_RV
106 meta_SignUpdate(CK_SESSION_HANDLE hSession,
107 CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
109 CK_RV rv;
110 meta_session_t *session;
112 rv = meta_handle2session(hSession, &session);
113 if (rv != CKR_OK)
114 return (rv);
116 if (pPart == NULL) {
117 meta_operation_cleanup(session, CKF_SIGN, FALSE);
118 REFRELEASE(session);
119 return (CKR_ARGUMENTS_BAD);
122 rv = meta_do_operation(CKF_SIGN, MODE_UPDATE, session, NULL,
123 pPart, ulPartLen, NULL, NULL);
125 REFRELEASE(session);
127 return (rv);
132 * meta_SignFinal
135 CK_RV
136 meta_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
137 CK_ULONG_PTR pulSignatureLen)
139 CK_RV rv;
140 meta_session_t *session;
142 rv = meta_handle2session(hSession, &session);
143 if (rv != CKR_OK)
144 return (rv);
146 if (pulSignatureLen == NULL) {
147 meta_operation_cleanup(session, CKF_SIGN, FALSE);
148 REFRELEASE(session);
149 return (CKR_ARGUMENTS_BAD);
152 rv = meta_do_operation(CKF_SIGN, MODE_FINAL, session, NULL,
153 NULL, 0, pSignature, pulSignatureLen);
155 REFRELEASE(session);
157 return (rv);
161 * meta_SignRecoverInit
164 CK_RV
165 meta_SignRecoverInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
166 CK_OBJECT_HANDLE hKey)
168 CK_RV rv;
169 meta_session_t *session;
170 meta_object_t *key;
172 if (pMechanism == NULL)
173 return (CKR_ARGUMENTS_BAD);
175 rv = meta_handle2session(hSession, &session);
176 if (rv != CKR_OK)
177 return (rv);
179 rv = meta_handle2object(hKey, &key);
180 if (rv != CKR_OK) {
181 REFRELEASE(session);
182 return (rv);
185 rv = meta_operation_init(CKF_SIGN_RECOVER, session, pMechanism, key);
187 OBJRELEASE(key);
188 REFRELEASE(session);
190 return (rv);
195 * meta_SignRecover
198 CK_RV
199 meta_SignRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData,
200 CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen)
202 CK_RV rv;
203 meta_session_t *session;
205 rv = meta_handle2session(hSession, &session);
206 if (rv != CKR_OK)
207 return (rv);
209 if (pData == NULL || pulSignatureLen == NULL) {
210 meta_operation_cleanup(session, CKF_SIGN_RECOVER, FALSE);
211 REFRELEASE(session);
212 return (CKR_ARGUMENTS_BAD);
215 rv = meta_do_operation(CKF_SIGN_RECOVER, MODE_SINGLE, session, NULL,
216 pData, ulDataLen, pSignature, pulSignatureLen);
218 REFRELEASE(session);
220 return (rv);