xref: /titanic_41/usr/src/lib/pkcs11/pkcs11_softtoken/common/softCrypt.h (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SOFTCRYPT_H
28 #define	_SOFTCRYPT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <security/pkcs11t.h>
38 #include <aes_impl.h>
39 #include <blowfish_impl.h>
40 #include <des_impl.h>
41 #include <bignum.h>
42 #include "softObject.h"
43 #include "softSession.h"
44 
45 #define	DES_MAC_LEN	(DES_BLOCK_LEN / 2)
46 
47 typedef struct soft_des_ctx {
48 	void *key_sched;		/* pointer to key schedule */
49 	size_t keysched_len;		/* Length of the key schedule */
50 	uint8_t ivec[DES_BLOCK_LEN];	/* initialization vector */
51 	uint8_t data[DES_BLOCK_LEN];	/* for use by update */
52 	size_t remain_len;		/* for use by update */
53 	void *des_cbc;			/* to be used by CBC mode */
54 	CK_KEY_TYPE key_type;		/* used to determine DES or DES3 */
55 	size_t mac_len;			/* digest len in bytes */
56 } soft_des_ctx_t;
57 
58 typedef struct soft_aes_ctx {
59 	void *key_sched;		/* pointer to key schedule */
60 	size_t keysched_len;		/* Length of the key schedule */
61 	uint8_t ivec[AES_BLOCK_LEN];	/* initialization vector */
62 	uint8_t data[AES_BLOCK_LEN];	/* for use by update */
63 	size_t remain_len;			/* for use by update */
64 	void *aes_cbc;			/* to be used by CBC mode */
65 } soft_aes_ctx_t;
66 
67 typedef struct soft_blowfish_ctx {
68 	void *key_sched;		/* pointer to key schedule */
69 	size_t keysched_len;		/* Length of the key schedule */
70 	uint8_t ivec[BLOWFISH_BLOCK_LEN];	/* initialization vector */
71 	uint8_t data[BLOWFISH_BLOCK_LEN];	/* for use by update */
72 	size_t remain_len;			/* for use by update */
73 	void *blowfish_cbc;			/* to be used by CBC mode */
74 } soft_blowfish_ctx_t;
75 
76 /*
77  * Function Prototypes.
78  */
79 void *des_cbc_ctx_init(void *, size_t, uint8_t *, CK_KEY_TYPE);
80 
81 CK_RV soft_des_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
82 	soft_object_t *, boolean_t);
83 
84 CK_RV soft_des_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
85 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
86 
87 CK_RV soft_des_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
88 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
89 
90 CK_RV soft_des_sign_verify_common(soft_session_t *session_p, CK_BYTE_PTR pData,
91 	CK_ULONG ulDataLen, CK_BYTE_PTR pSigned, CK_ULONG_PTR pulSignedLen,
92 	boolean_t sign_op, boolean_t Final);
93 
94 CK_RV soft_des_sign_verify_init_common(soft_session_t *session_p,
95     CK_MECHANISM_PTR pMechanism, soft_object_t *key_p, boolean_t sign_op);
96 
97 CK_RV soft_des_mac_sign_verify_update(soft_session_t *session_p,
98 	CK_BYTE_PTR pPart, CK_ULONG ulPartLen);
99 
100 void soft_add_pkcs7_padding(CK_BYTE *, int, CK_ULONG);
101 
102 CK_RV soft_remove_pkcs7_padding(CK_BYTE *, CK_ULONG, CK_ULONG *, int);
103 
104 CK_RV soft_arcfour_crypt_init(soft_session_t *, CK_MECHANISM_PTR,
105 	soft_object_t *, boolean_t);
106 
107 CK_RV soft_arcfour_crypt(crypto_active_op_t *, CK_BYTE_PTR, CK_ULONG,
108 	CK_BYTE_PTR, CK_ULONG_PTR);
109 
110 void *aes_cbc_ctx_init(void *, size_t, uint8_t *);
111 
112 CK_RV soft_aes_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
113 	soft_object_t *, boolean_t);
114 
115 CK_RV soft_aes_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
116 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
117 
118 CK_RV soft_aes_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
119 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
120 
121 void *blowfish_cbc_ctx_init(void *, size_t, uint8_t *);
122 
123 CK_RV soft_blowfish_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
124 	soft_object_t *, boolean_t);
125 
126 CK_RV soft_blowfish_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
127 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
128 
129 CK_RV soft_blowfish_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
130 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
131 
132 CK_RV convert_rv(BIG_ERR_CODE);
133 
134 BIG_ERR_CODE convert_brv(CK_RV);
135 
136 #ifdef	__cplusplus
137 }
138 #endif
139 
140 #endif /* _SOFTCRYPT_H */
141