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 * Encryption and Decryption Functions
30 * (as defined in PKCS#11 spec sections 11.8 and 11.9)
33 #include "metaGlobal.h"
41 meta_EncryptInit(CK_SESSION_HANDLE hSession
, CK_MECHANISM_PTR pMechanism
,
42 CK_OBJECT_HANDLE hKey
)
45 meta_session_t
*session
;
48 if (pMechanism
== NULL
)
49 return (CKR_ARGUMENTS_BAD
);
51 rv
= meta_handle2session(hSession
, &session
);
55 rv
= meta_handle2object(hKey
, &key
);
61 rv
= meta_operation_init_defer(CKF_ENCRYPT
, session
, pMechanism
, key
);
75 meta_Encrypt(CK_SESSION_HANDLE hSession
,
76 CK_BYTE_PTR pData
, CK_ULONG ulDataLen
,
77 CK_BYTE_PTR pEncryptedData
, CK_ULONG_PTR pulEncryptedDataLen
)
80 meta_session_t
*session
;
82 rv
= meta_handle2session(hSession
, &session
);
86 if (pData
== NULL
|| pulEncryptedDataLen
== NULL
) {
87 meta_operation_cleanup(session
, CKF_ENCRYPT
, FALSE
);
89 return (CKR_ARGUMENTS_BAD
);
92 rv
= meta_do_operation(CKF_ENCRYPT
, MODE_SINGLE
, session
, NULL
,
93 pData
, ulDataLen
, pEncryptedData
, pulEncryptedDataLen
);
106 meta_EncryptUpdate(CK_SESSION_HANDLE hSession
,
107 CK_BYTE_PTR pPart
, CK_ULONG ulPartLen
,
108 CK_BYTE_PTR pEncryptedPart
, CK_ULONG_PTR pulEncryptedPartLen
)
111 meta_session_t
*session
;
113 rv
= meta_handle2session(hSession
, &session
);
117 if (pPart
== NULL
|| pulEncryptedPartLen
== NULL
) {
118 meta_operation_cleanup(session
, CKF_ENCRYPT
, FALSE
);
120 return (CKR_ARGUMENTS_BAD
);
123 rv
= meta_do_operation(CKF_ENCRYPT
, MODE_UPDATE
, session
, NULL
,
124 pPart
, ulPartLen
, pEncryptedPart
, pulEncryptedPartLen
);
137 meta_EncryptFinal(CK_SESSION_HANDLE hSession
,
138 CK_BYTE_PTR pLastEncryptedPart
, CK_ULONG_PTR pulLastEncryptedPartLen
)
141 meta_session_t
*session
;
143 rv
= meta_handle2session(hSession
, &session
);
147 if (pulLastEncryptedPartLen
== NULL
) {
148 meta_operation_cleanup(session
, CKF_ENCRYPT
, FALSE
);
150 return (CKR_ARGUMENTS_BAD
);
153 rv
= meta_do_operation(CKF_ENCRYPT
, MODE_FINAL
, session
, NULL
,
154 NULL
, 0, pLastEncryptedPart
, pulLastEncryptedPartLen
);
167 meta_DecryptInit(CK_SESSION_HANDLE hSession
, CK_MECHANISM_PTR pMechanism
,
168 CK_OBJECT_HANDLE hKey
)
171 meta_session_t
*session
;
174 if (pMechanism
== NULL
)
175 return (CKR_ARGUMENTS_BAD
);
177 rv
= meta_handle2session(hSession
, &session
);
181 rv
= meta_handle2object(hKey
, &key
);
187 rv
= meta_operation_init_defer(CKF_DECRYPT
, session
, pMechanism
, key
);
201 meta_Decrypt(CK_SESSION_HANDLE hSession
,
202 CK_BYTE_PTR pEncryptedData
, CK_ULONG ulEncryptedDataLen
,
203 CK_BYTE_PTR pData
, CK_ULONG_PTR pulDataLen
)
206 meta_session_t
*session
;
208 rv
= meta_handle2session(hSession
, &session
);
212 if (pEncryptedData
== NULL
|| pulDataLen
== NULL
) {
213 meta_operation_cleanup(session
, CKF_DECRYPT
, FALSE
);
215 return (CKR_ARGUMENTS_BAD
);
218 rv
= meta_do_operation(CKF_DECRYPT
, MODE_SINGLE
, session
, NULL
,
219 pEncryptedData
, ulEncryptedDataLen
, pData
, pulDataLen
);
232 meta_DecryptUpdate(CK_SESSION_HANDLE hSession
,
233 CK_BYTE_PTR pEncryptedPart
, CK_ULONG ulEncryptedPartLen
,
234 CK_BYTE_PTR pPart
, CK_ULONG_PTR pulPartLen
)
237 meta_session_t
*session
;
239 rv
= meta_handle2session(hSession
, &session
);
243 if (pEncryptedPart
== NULL
|| pulPartLen
== NULL
) {
244 meta_operation_cleanup(session
, CKF_DECRYPT
, FALSE
);
246 return (CKR_ARGUMENTS_BAD
);
249 rv
= meta_do_operation(CKF_DECRYPT
, MODE_UPDATE
, session
, NULL
,
250 pEncryptedPart
, ulEncryptedPartLen
, pPart
, pulPartLen
);
263 meta_DecryptFinal(CK_SESSION_HANDLE hSession
,
264 CK_BYTE_PTR pLastPart
, CK_ULONG_PTR pulLastPartLen
)
267 meta_session_t
*session
;
269 rv
= meta_handle2session(hSession
, &session
);
273 if (pulLastPartLen
== NULL
) {
274 meta_operation_cleanup(session
, CKF_DECRYPT
, FALSE
);
276 return (CKR_ARGUMENTS_BAD
);
279 rv
= meta_do_operation(CKF_DECRYPT
, MODE_FINAL
, session
, NULL
,
280 NULL
, 0, pLastPart
, pulLastPartLen
);