xref: /onnv-gate/usr/src/lib/pkcs11/pkcs11_kms/common/kmsCrypt.h (revision 12720:3db6e0082404)
1*12720SWyllys.Ingersoll@Sun.COM /*
2*12720SWyllys.Ingersoll@Sun.COM  * CDDL HEADER START
3*12720SWyllys.Ingersoll@Sun.COM  *
4*12720SWyllys.Ingersoll@Sun.COM  * The contents of this file are subject to the terms of the
5*12720SWyllys.Ingersoll@Sun.COM  * Common Development and Distribution License (the "License").
6*12720SWyllys.Ingersoll@Sun.COM  * You may not use this file except in compliance with the License.
7*12720SWyllys.Ingersoll@Sun.COM  *
8*12720SWyllys.Ingersoll@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12720SWyllys.Ingersoll@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*12720SWyllys.Ingersoll@Sun.COM  * See the License for the specific language governing permissions
11*12720SWyllys.Ingersoll@Sun.COM  * and limitations under the License.
12*12720SWyllys.Ingersoll@Sun.COM  *
13*12720SWyllys.Ingersoll@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12720SWyllys.Ingersoll@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12720SWyllys.Ingersoll@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*12720SWyllys.Ingersoll@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*12720SWyllys.Ingersoll@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*12720SWyllys.Ingersoll@Sun.COM  *
19*12720SWyllys.Ingersoll@Sun.COM  * CDDL HEADER END
20*12720SWyllys.Ingersoll@Sun.COM  *
21*12720SWyllys.Ingersoll@Sun.COM  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
22*12720SWyllys.Ingersoll@Sun.COM  */
23*12720SWyllys.Ingersoll@Sun.COM 
24*12720SWyllys.Ingersoll@Sun.COM #ifndef _KMSCRYPT_H
25*12720SWyllys.Ingersoll@Sun.COM #define	_KMSCRYPT_H
26*12720SWyllys.Ingersoll@Sun.COM 
27*12720SWyllys.Ingersoll@Sun.COM #ifdef __cplusplus
28*12720SWyllys.Ingersoll@Sun.COM extern "C" {
29*12720SWyllys.Ingersoll@Sun.COM #endif
30*12720SWyllys.Ingersoll@Sun.COM 
31*12720SWyllys.Ingersoll@Sun.COM #include <sys/types.h>
32*12720SWyllys.Ingersoll@Sun.COM #include <security/pkcs11t.h>
33*12720SWyllys.Ingersoll@Sun.COM #ifdef USESOLARIS_AES
34*12720SWyllys.Ingersoll@Sun.COM #include <modes/modes.h>
35*12720SWyllys.Ingersoll@Sun.COM #else
36*12720SWyllys.Ingersoll@Sun.COM #include <aes_cbc_crypt.h>
37*12720SWyllys.Ingersoll@Sun.COM #define	CBC_MODE AES_CBC_MODE
38*12720SWyllys.Ingersoll@Sun.COM #endif
39*12720SWyllys.Ingersoll@Sun.COM #include <aes_impl.h>
40*12720SWyllys.Ingersoll@Sun.COM #include "kmsObject.h"
41*12720SWyllys.Ingersoll@Sun.COM #include "kmsSession.h"
42*12720SWyllys.Ingersoll@Sun.COM 
43*12720SWyllys.Ingersoll@Sun.COM typedef struct kms_aes_ctx {
44*12720SWyllys.Ingersoll@Sun.COM 	void *key_sched;		/* pointer to key schedule */
45*12720SWyllys.Ingersoll@Sun.COM 	size_t keysched_len;		/* Length of the key schedule */
46*12720SWyllys.Ingersoll@Sun.COM 	uint8_t ivec[AES_BLOCK_LEN];	/* initialization vector */
47*12720SWyllys.Ingersoll@Sun.COM 	uint8_t data[AES_BLOCK_LEN];	/* for use by update */
48*12720SWyllys.Ingersoll@Sun.COM 	size_t remain_len;			/* for use by update */
49*12720SWyllys.Ingersoll@Sun.COM 	void *aes_cbc;			/* to be used by CBC mode */
50*12720SWyllys.Ingersoll@Sun.COM } kms_aes_ctx_t;
51*12720SWyllys.Ingersoll@Sun.COM 
52*12720SWyllys.Ingersoll@Sun.COM /*
53*12720SWyllys.Ingersoll@Sun.COM  * Function Prototypes.
54*12720SWyllys.Ingersoll@Sun.COM  */
55*12720SWyllys.Ingersoll@Sun.COM void *aes_cbc_ctx_init(void *, size_t, uint8_t *);
56*12720SWyllys.Ingersoll@Sun.COM 
57*12720SWyllys.Ingersoll@Sun.COM CK_RV kms_aes_crypt_init_common(kms_session_t *, CK_MECHANISM_PTR,
58*12720SWyllys.Ingersoll@Sun.COM 	kms_object_t *, boolean_t);
59*12720SWyllys.Ingersoll@Sun.COM 
60*12720SWyllys.Ingersoll@Sun.COM CK_RV kms_aes_encrypt_common(kms_session_t *, CK_BYTE_PTR, CK_ULONG,
61*12720SWyllys.Ingersoll@Sun.COM 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
62*12720SWyllys.Ingersoll@Sun.COM 
63*12720SWyllys.Ingersoll@Sun.COM CK_RV kms_aes_decrypt_common(kms_session_t *, CK_BYTE_PTR, CK_ULONG,
64*12720SWyllys.Ingersoll@Sun.COM 	CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
65*12720SWyllys.Ingersoll@Sun.COM 
66*12720SWyllys.Ingersoll@Sun.COM CK_RV kms_aes_encrypt_final(kms_session_t *, CK_BYTE_PTR, CK_ULONG_PTR);
67*12720SWyllys.Ingersoll@Sun.COM CK_RV kms_aes_decrypt_final(kms_session_t *, CK_BYTE_PTR, CK_ULONG_PTR);
68*12720SWyllys.Ingersoll@Sun.COM 
69*12720SWyllys.Ingersoll@Sun.COM void kms_crypt_cleanup(kms_session_t *, boolean_t, boolean_t);
70*12720SWyllys.Ingersoll@Sun.COM 
71*12720SWyllys.Ingersoll@Sun.COM #ifdef	__cplusplus
72*12720SWyllys.Ingersoll@Sun.COM }
73*12720SWyllys.Ingersoll@Sun.COM #endif
74*12720SWyllys.Ingersoll@Sun.COM 
75*12720SWyllys.Ingersoll@Sun.COM #endif /* _KMSCRYPT_H */
76