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