xref: /titanic_41/usr/src/lib/pkcs11/pkcs11_softtoken/common/softDualCrypt.c (revision 40db2e2b777b79f3dd0d6d9629593a07f86b9c0a)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <security/cryptoki.h>
30 #include "softGlobal.h"
31 #include "softSession.h"
32 #include "softObject.h"
33 #include "softOps.h"
34 
35 CK_RV
36 C_DigestEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
37     CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
38     CK_ULONG_PTR pulEncryptedPartLen)
39 {
40 
41 	CK_RV	rv;
42 
43 	/*
44 	 * All the front-end checkings will be done in the
45 	 * C_EncryptUpdate and C_DigestUpdate.
46 	 */
47 	rv = C_EncryptUpdate(hSession, pPart, ulPartLen,
48 	    pEncryptedPart, pulEncryptedPartLen);
49 
50 	if (rv != CKR_OK)
51 		return (rv);
52 
53 	/*
54 	 * If the application just wants to know the length of output
55 	 * buffer, then we do not digest the data.
56 	 */
57 	if (pEncryptedPart == NULL)
58 		return (CKR_OK);
59 
60 	return (C_DigestUpdate(hSession, pPart, ulPartLen));
61 }
62 
63 
64 CK_RV
65 C_DecryptDigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart,
66     CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen)
67 {
68 
69 	CK_RV	rv;
70 
71 	/*
72 	 * All the front-end checkings will be done in the
73 	 * C_DecryptUpdate and C_DigestUpdate.
74 	 */
75 	rv = C_DecryptUpdate(hSession, pEncryptedPart, ulEncryptedPartLen,
76 	    pPart, pulPartLen);
77 
78 	if (rv != CKR_OK)
79 		return (rv);
80 
81 	/*
82 	 * If the application just wants to know the length of output
83 	 * buffer, then we do not digest the data.
84 	 */
85 	if (pPart == NULL)
86 		return (CKR_OK);
87 
88 	return (C_DigestUpdate(hSession, pPart, *pulPartLen));
89 }
90 
91 
92 CK_RV
93 C_SignEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
94     CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
95     CK_ULONG_PTR pulEncryptedPartLen)
96 {
97 
98 	CK_RV	rv;
99 
100 	/*
101 	 * All the front-end checkings will be done in the
102 	 * C_EncryptUpdate and C_SignUpdate.
103 	 */
104 	rv = C_EncryptUpdate(hSession, pPart, ulPartLen,
105 	    pEncryptedPart, pulEncryptedPartLen);
106 
107 	if (rv != CKR_OK)
108 		return (rv);
109 
110 	/*
111 	 * If the application just wants to know the length of output
112 	 * buffer, then we do not sign the data.
113 	 */
114 	if (pEncryptedPart == NULL)
115 		return (CKR_OK);
116 
117 	return (C_SignUpdate(hSession, pPart, ulPartLen));
118 }
119 
120 
121 CK_RV
122 C_DecryptVerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart,
123     CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen)
124 {
125 
126 	CK_RV	rv;
127 
128 	/*
129 	 * All the front-end checkings will be done in the
130 	 * C_DecryptUpdate and C_VerifyUpdate.
131 	 */
132 	rv = C_DecryptUpdate(hSession, pEncryptedPart, ulEncryptedPartLen,
133 	    pPart, pulPartLen);
134 
135 	if (rv != CKR_OK)
136 		return (rv);
137 
138 	/*
139 	 * If the application just wants to know the length of output
140 	 * buffer, then we do not verify the data.
141 	 */
142 	if (pPart == NULL)
143 		return (CKR_OK);
144 
145 	return (C_VerifyUpdate(hSession, pPart, *pulPartLen));
146 }
147