xref: /onnv-gate/usr/src/lib/pkcs11/pkcs11_kms/common/kmsCrypt.h (revision 12720:3db6e0082404)
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  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
22  */
23 
24 #ifndef _KMSCRYPT_H
25 #define	_KMSCRYPT_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <sys/types.h>
32 #include <security/pkcs11t.h>
33 #ifdef USESOLARIS_AES
34 #include <modes/modes.h>
35 #else
36 #include <aes_cbc_crypt.h>
37 #define	CBC_MODE AES_CBC_MODE
38 #endif
39 #include <aes_impl.h>
40 #include "kmsObject.h"
41 #include "kmsSession.h"
42 
43 typedef struct kms_aes_ctx {
44 	void *key_sched;		/* pointer to key schedule */
45 	size_t keysched_len;		/* Length of the key schedule */
46 	uint8_t ivec[AES_BLOCK_LEN];	/* initialization vector */
47 	uint8_t data[AES_BLOCK_LEN];	/* for use by update */
48 	size_t remain_len;			/* for use by update */
49 	void *aes_cbc;			/* to be used by CBC mode */
50 } kms_aes_ctx_t;
51 
52 /*
53  * Function Prototypes.
54  */
55 void *aes_cbc_ctx_init(void *, size_t, uint8_t *);
56 
57 CK_RV kms_aes_crypt_init_common(kms_session_t *, CK_MECHANISM_PTR,
58 	kms_object_t *, boolean_t);
59 
60 CK_RV kms_aes_encrypt_common(kms_session_t *, CK_BYTE_PTR, CK_ULONG,
61 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
62 
63 CK_RV kms_aes_decrypt_common(kms_session_t *, CK_BYTE_PTR, CK_ULONG,
64 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
65 
66 CK_RV kms_aes_encrypt_final(kms_session_t *, CK_BYTE_PTR, CK_ULONG_PTR);
67 CK_RV kms_aes_decrypt_final(kms_session_t *, CK_BYTE_PTR, CK_ULONG_PTR);
68 
69 void kms_crypt_cleanup(kms_session_t *, boolean_t, boolean_t);
70 
71 #ifdef	__cplusplus
72 }
73 #endif
74 
75 #endif /* _KMSCRYPT_H */
76