1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * Signing and MACing Functions 28 * (as defined in PKCs#11 spec section 11.11) 29 */ 30 31 #include "metaGlobal.h" 32 33 34 /* 35 * meta_SignInit 36 * 37 */ 38 CK_RV 39 meta_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 40 CK_OBJECT_HANDLE hKey) 41 { 42 CK_RV rv; 43 meta_session_t *session; 44 meta_object_t *key; 45 46 if (pMechanism == NULL) 47 return (CKR_ARGUMENTS_BAD); 48 49 rv = meta_handle2session(hSession, &session); 50 if (rv != CKR_OK) 51 return (rv); 52 53 rv = meta_handle2object(hKey, &key); 54 if (rv != CKR_OK) { 55 REFRELEASE(session); 56 return (rv); 57 } 58 59 rv = meta_operation_init(CKF_SIGN, session, pMechanism, key); 60 61 OBJRELEASE(key); 62 REFRELEASE(session); 63 64 return (rv); 65 } 66 67 68 /* 69 * meta_Sign 70 * 71 */ 72 CK_RV 73 meta_Sign(CK_SESSION_HANDLE hSession, 74 CK_BYTE_PTR pData, CK_ULONG ulDataLen, 75 CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) 76 { 77 CK_RV rv; 78 meta_session_t *session; 79 80 rv = meta_handle2session(hSession, &session); 81 if (rv != CKR_OK) 82 return (rv); 83 84 if (pData == NULL || pulSignatureLen == NULL) { 85 meta_operation_cleanup(session, CKF_SIGN, FALSE); 86 REFRELEASE(session); 87 return (CKR_ARGUMENTS_BAD); 88 } 89 90 rv = meta_do_operation(CKF_SIGN, MODE_SINGLE, session, NULL, 91 pData, ulDataLen, pSignature, pulSignatureLen); 92 93 REFRELEASE(session); 94 95 return (rv); 96 } 97 98 99 /* 100 * meta_SignUpdate 101 * 102 */ 103 CK_RV 104 meta_SignUpdate(CK_SESSION_HANDLE hSession, 105 CK_BYTE_PTR pPart, CK_ULONG ulPartLen) 106 { 107 CK_RV rv; 108 meta_session_t *session; 109 110 rv = meta_handle2session(hSession, &session); 111 if (rv != CKR_OK) 112 return (rv); 113 114 if (pPart == NULL) { 115 meta_operation_cleanup(session, CKF_SIGN, FALSE); 116 REFRELEASE(session); 117 return (CKR_ARGUMENTS_BAD); 118 } 119 120 rv = meta_do_operation(CKF_SIGN, MODE_UPDATE, session, NULL, 121 pPart, ulPartLen, NULL, NULL); 122 123 REFRELEASE(session); 124 125 return (rv); 126 } 127 128 129 /* 130 * meta_SignFinal 131 * 132 */ 133 CK_RV 134 meta_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, 135 CK_ULONG_PTR pulSignatureLen) 136 { 137 CK_RV rv; 138 meta_session_t *session; 139 140 rv = meta_handle2session(hSession, &session); 141 if (rv != CKR_OK) 142 return (rv); 143 144 if (pulSignatureLen == NULL) { 145 meta_operation_cleanup(session, CKF_SIGN, FALSE); 146 REFRELEASE(session); 147 return (CKR_ARGUMENTS_BAD); 148 } 149 150 rv = meta_do_operation(CKF_SIGN, MODE_FINAL, session, NULL, 151 NULL, 0, pSignature, pulSignatureLen); 152 153 REFRELEASE(session); 154 155 return (rv); 156 } 157 158 /* 159 * meta_SignRecoverInit 160 * 161 */ 162 CK_RV 163 meta_SignRecoverInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 164 CK_OBJECT_HANDLE hKey) 165 { 166 CK_RV rv; 167 meta_session_t *session; 168 meta_object_t *key; 169 170 if (pMechanism == NULL) 171 return (CKR_ARGUMENTS_BAD); 172 173 rv = meta_handle2session(hSession, &session); 174 if (rv != CKR_OK) 175 return (rv); 176 177 rv = meta_handle2object(hKey, &key); 178 if (rv != CKR_OK) { 179 REFRELEASE(session); 180 return (rv); 181 } 182 183 rv = meta_operation_init(CKF_SIGN_RECOVER, session, pMechanism, key); 184 185 OBJRELEASE(key); 186 REFRELEASE(session); 187 188 return (rv); 189 } 190 191 192 /* 193 * meta_SignRecover 194 * 195 */ 196 CK_RV 197 meta_SignRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, 198 CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) 199 { 200 CK_RV rv; 201 meta_session_t *session; 202 203 rv = meta_handle2session(hSession, &session); 204 if (rv != CKR_OK) 205 return (rv); 206 207 if (pData == NULL || pulSignatureLen == NULL) { 208 meta_operation_cleanup(session, CKF_SIGN_RECOVER, FALSE); 209 REFRELEASE(session); 210 return (CKR_ARGUMENTS_BAD); 211 } 212 213 rv = meta_do_operation(CKF_SIGN_RECOVER, MODE_SINGLE, session, NULL, 214 pData, ulDataLen, pSignature, pulSignatureLen); 215 216 REFRELEASE(session); 217 218 return (rv); 219 } 220