dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / pkcs11 / libpkcs11 / common / metaVerify.c
blob9b0ba20041df35e4a061a48d2e0e3bd69f559e98
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 * Functions for Verifying Signatures and MACS
30 * (as defined in PKCS#11 spec section 11.13)
33 #include "metaGlobal.h"
37 * meta_VerifyInit
40 CK_RV
41 meta_VerifyInit(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_VERIFY, session, pMechanism, key);
63 OBJRELEASE(key);
64 REFRELEASE(session);
66 return (rv);
71 * meta_Verify
74 CK_RV
75 meta_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
76 CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen)
78 CK_RV rv;
79 meta_session_t *session;
81 rv = meta_handle2session(hSession, &session);
82 if (rv != CKR_OK)
83 return (rv);
85 /* Note: unlike other ops, both buffers are inputs, and required. */
86 if (pData == NULL || pSignature == NULL) {
87 meta_operation_cleanup(session, CKF_VERIFY, FALSE);
88 REFRELEASE(session);
89 return (CKR_ARGUMENTS_BAD);
92 rv = meta_do_operation(CKF_VERIFY, MODE_SINGLE, session, NULL,
93 pData, ulDataLen, pSignature, &ulSignatureLen);
95 REFRELEASE(session);
97 return (rv);
102 * meta_VerifyUpdate
105 CK_RV
106 meta_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
107 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_VERIFY, FALSE);
118 REFRELEASE(session);
119 return (CKR_ARGUMENTS_BAD);
122 rv = meta_do_operation(CKF_VERIFY, MODE_UPDATE, session, NULL,
123 pPart, ulPartLen, NULL, NULL);
125 REFRELEASE(session);
127 return (rv);
132 * meta_VerifyFinal
135 CK_RV
136 meta_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
137 CK_ULONG ulSignatureLen)
139 CK_RV rv;
140 meta_session_t *session;
142 rv = meta_handle2session(hSession, &session);
143 if (rv != CKR_OK)
144 return (rv);
147 * Unlike other ops the buffer is an input. Allow NULL if there's
148 * no more input.
150 if (pSignature == NULL && ulSignatureLen != 0) {
151 meta_operation_cleanup(session, CKF_VERIFY, FALSE);
152 REFRELEASE(session);
153 return (CKR_ARGUMENTS_BAD);
156 rv = meta_do_operation(CKF_VERIFY, MODE_FINAL, session, NULL,
157 pSignature, ulSignatureLen, NULL, NULL);
159 REFRELEASE(session);
161 return (rv);
166 * meta_VerifyRecoverInit
169 CK_RV
170 meta_VerifyRecoverInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
171 CK_OBJECT_HANDLE hKey)
173 CK_RV rv;
174 meta_session_t *session;
175 meta_object_t *key;
177 if (pMechanism == NULL)
178 return (CKR_ARGUMENTS_BAD);
180 rv = meta_handle2session(hSession, &session);
181 if (rv != CKR_OK)
182 return (rv);
184 rv = meta_handle2object(hKey, &key);
185 if (rv != CKR_OK) {
186 REFRELEASE(session);
187 return (rv);
190 rv = meta_operation_init(CKF_VERIFY_RECOVER, session, pMechanism, key);
192 OBJRELEASE(key);
193 REFRELEASE(session);
195 return (rv);
200 * meta_VerifyRecover
203 CK_RV
204 meta_VerifyRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
205 CK_ULONG ulSignatureLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen)
207 CK_RV rv;
208 meta_session_t *session;
210 rv = meta_handle2session(hSession, &session);
211 if (rv != CKR_OK)
212 return (rv);
214 if (pSignature == NULL || pulDataLen == NULL) {
215 meta_operation_cleanup(session, CKF_VERIFY_RECOVER, FALSE);
216 REFRELEASE(session);
217 return (CKR_ARGUMENTS_BAD);
220 rv = meta_do_operation(CKF_VERIFY_RECOVER, MODE_SINGLE, session, NULL,
221 pSignature, ulSignatureLen, pData, pulDataLen);
223 REFRELEASE(session);
225 return (rv);