xref: /titanic_52/usr/src/lib/pkcs11/pkcs11_softtoken/common/softCrypt.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2004 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 <des_impl.h>
40 #include <bignum.h>
41 #include "softObject.h"
42 #include "softSession.h"
43 
44 #define	DES_MAC_LEN	(DES_BLOCK_LEN / 2)
45 
46 typedef struct soft_des_ctx {
47 	void *key_sched;		/* pointer to key schedule */
48 	size_t keysched_len;		/* Length of the key schedule */
49 	uint8_t ivec[DES_BLOCK_LEN];	/* initialization vector */
50 	uint8_t data[DES_BLOCK_LEN];	/* for use by update */
51 	size_t remain_len;		/* for use by update */
52 	void *des_cbc;			/* to be used by CBC mode */
53 	CK_KEY_TYPE key_type;		/* used to determine DES or DES3 */
54 	size_t mac_len;			/* digest len in bytes */
55 } soft_des_ctx_t;
56 
57 typedef struct soft_aes_ctx {
58 	void *key_sched;		/* pointer to key schedule */
59 	size_t keysched_len;		/* Length of the key schedule */
60 	uint8_t ivec[AES_BLOCK_LEN];	/* initialization vector */
61 	uint8_t data[AES_BLOCK_LEN];	/* for use by update */
62 	size_t remain_len;			/* for use by update */
63 	void *aes_cbc;			/* to be used by CBC mode */
64 } soft_aes_ctx_t;
65 
66 /*
67  * Function Prototypes.
68  */
69 void *des_cbc_ctx_init(void *, size_t, uint8_t *, CK_KEY_TYPE);
70 
71 CK_RV soft_des_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
72 	soft_object_t *, boolean_t);
73 
74 CK_RV soft_des_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
75 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
76 
77 CK_RV soft_des_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
78 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
79 
80 CK_RV soft_des_sign_verify_common(soft_session_t *session_p, CK_BYTE_PTR pData,
81 	CK_ULONG ulDataLen, CK_BYTE_PTR pSigned, CK_ULONG_PTR pulSignedLen,
82 	boolean_t sign_op, boolean_t Final);
83 
84 CK_RV soft_des_sign_verify_init_common(soft_session_t *session_p,
85     CK_MECHANISM_PTR pMechanism, soft_object_t *key_p, boolean_t sign_op);
86 
87 CK_RV soft_des_mac_sign_verify_update(soft_session_t *session_p,
88 	CK_BYTE_PTR pPart, CK_ULONG ulPartLen);
89 
90 void soft_add_pkcs7_padding(CK_BYTE *, int, CK_ULONG);
91 
92 CK_RV soft_remove_pkcs7_padding(CK_BYTE *, CK_ULONG, CK_ULONG *, int);
93 
94 CK_RV soft_arcfour_crypt_init(soft_session_t *, CK_MECHANISM_PTR,
95 	soft_object_t *, boolean_t);
96 
97 CK_RV soft_arcfour_crypt(crypto_active_op_t *, CK_BYTE_PTR, CK_ULONG,
98 	CK_BYTE_PTR, CK_ULONG_PTR);
99 
100 void *aes_cbc_ctx_init(void *, size_t, uint8_t *);
101 
102 CK_RV soft_aes_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
103 	soft_object_t *, boolean_t);
104 
105 CK_RV soft_aes_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
106 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
107 
108 CK_RV soft_aes_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
109 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
110 
111 CK_RV convert_rv(BIG_ERR_CODE);
112 
113 BIG_ERR_CODE convert_brv(CK_RV);
114 
115 #ifdef	__cplusplus
116 }
117 #endif
118 
119 #endif /* _SOFTCRYPT_H */
120