17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5690caf98Sizick  * Common Development and Distribution License (the "License").
6690caf98Sizick  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22436935a1SVladimir Kotal  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_DES_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_DES_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Common definitions used by DES
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #define	DES_BLOCK_LEN	8
387c478bd9Sstevel@tonic-gate 
3923c57df7Smcpowers #define	DES_COPY_BLOCK(src, dst) \
4023c57df7Smcpowers 	(dst)[0] = (src)[0]; \
4123c57df7Smcpowers 	(dst)[1] = (src)[1]; \
4223c57df7Smcpowers 	(dst)[2] = (src)[2]; \
4323c57df7Smcpowers 	(dst)[3] = (src)[3]; \
4423c57df7Smcpowers 	(dst)[4] = (src)[4]; \
4523c57df7Smcpowers 	(dst)[5] = (src)[5]; \
4623c57df7Smcpowers 	(dst)[6] = (src)[6]; \
4723c57df7Smcpowers 	(dst)[7] = (src)[7];
4823c57df7Smcpowers 
497c478bd9Sstevel@tonic-gate #define	DES_XOR_BLOCK(src, dst) \
507c478bd9Sstevel@tonic-gate 	(dst)[0] ^= (src)[0]; \
517c478bd9Sstevel@tonic-gate 	(dst)[1] ^= (src)[1]; \
527c478bd9Sstevel@tonic-gate 	(dst)[2] ^= (src)[2]; \
537c478bd9Sstevel@tonic-gate 	(dst)[3] ^= (src)[3]; \
547c478bd9Sstevel@tonic-gate 	(dst)[4] ^= (src)[4]; \
557c478bd9Sstevel@tonic-gate 	(dst)[5] ^= (src)[5]; \
567c478bd9Sstevel@tonic-gate 	(dst)[6] ^= (src)[6]; \
577c478bd9Sstevel@tonic-gate 	(dst)[7] ^= (src)[7]
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef enum des_strength {
607c478bd9Sstevel@tonic-gate 	DES = 1,
617c478bd9Sstevel@tonic-gate 	DES2,
627c478bd9Sstevel@tonic-gate 	DES3
637c478bd9Sstevel@tonic-gate } des_strength_t;
647c478bd9Sstevel@tonic-gate 
6523c57df7Smcpowers #define	DES3_STRENGTH	0x08000000
6623c57df7Smcpowers 
677c478bd9Sstevel@tonic-gate #define	DES_KEYSIZE	8
687c478bd9Sstevel@tonic-gate #define	DES_MINBITS	64
697c478bd9Sstevel@tonic-gate #define	DES_MAXBITS	64
707c478bd9Sstevel@tonic-gate #define	DES_MINBYTES	(DES_MINBITS / 8)
717c478bd9Sstevel@tonic-gate #define	DES_MAXBYTES	(DES_MAXBITS / 8)
727c478bd9Sstevel@tonic-gate #define	DES_IV_LEN	8
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	DES2_KEYSIZE	(2 * DES_KEYSIZE)
757c478bd9Sstevel@tonic-gate #define	DES2_MINBITS	(2 * DES_MINBITS)
767c478bd9Sstevel@tonic-gate #define	DES2_MAXBITS	(2 * DES_MAXBITS)
77436935a1SVladimir Kotal #define	DES2_MINBYTES	(DES2_MINBITS / 8)
78436935a1SVladimir Kotal #define	DES2_MAXBYTES	(DES2_MAXBITS / 8)
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	DES3_KEYSIZE	(3 * DES_KEYSIZE)
81436935a1SVladimir Kotal #define	DES3_MINBITS	(2 * DES_MINBITS)	/* DES3 handles CKK_DES2 keys */
827c478bd9Sstevel@tonic-gate #define	DES3_MAXBITS	(3 * DES_MAXBITS)
837c478bd9Sstevel@tonic-gate #define	DES3_MINBYTES	(DES3_MINBITS / 8)
847c478bd9Sstevel@tonic-gate #define	DES3_MAXBYTES	(DES3_MAXBITS / 8)
857c478bd9Sstevel@tonic-gate 
8623c57df7Smcpowers extern int des_encrypt_contiguous_blocks(void *, char *, size_t,
8723c57df7Smcpowers     crypto_data_t *);
8823c57df7Smcpowers extern int des_decrypt_contiguous_blocks(void *, char *, size_t,
8923c57df7Smcpowers     crypto_data_t *);
907c478bd9Sstevel@tonic-gate extern uint64_t des_crypt_impl(uint64_t *, uint64_t, int);
917c478bd9Sstevel@tonic-gate extern void des_ks(uint64_t *, uint64_t);
9223c57df7Smcpowers extern int des_crunch_block(const void *, const uint8_t *, uint8_t *,
9323c57df7Smcpowers     boolean_t);
9423c57df7Smcpowers extern int des3_crunch_block(const void *, const uint8_t *, uint8_t *,
9523c57df7Smcpowers     boolean_t);
967c478bd9Sstevel@tonic-gate extern void des_init_keysched(uint8_t *, des_strength_t, void *);
977c478bd9Sstevel@tonic-gate extern void *des_alloc_keysched(size_t *, des_strength_t, int);
987c478bd9Sstevel@tonic-gate extern boolean_t des_keycheck(uint8_t *, des_strength_t, uint8_t *);
99690caf98Sizick extern void des_parity_fix(uint8_t *, des_strength_t, uint8_t *);
10023c57df7Smcpowers extern void des_copy_block(uint8_t *, uint8_t *);
10123c57df7Smcpowers extern void des_xor_block(uint8_t *, uint8_t *);
10223c57df7Smcpowers extern int des_encrypt_block(const void *, const uint8_t *, uint8_t *);
10323c57df7Smcpowers extern int des3_encrypt_block(const void *, const uint8_t *, uint8_t *);
10423c57df7Smcpowers extern int des_decrypt_block(const void *, const uint8_t *, uint8_t *);
10523c57df7Smcpowers extern int des3_decrypt_block(const void *, const uint8_t *, uint8_t *);
1067c478bd9Sstevel@tonic-gate 
107*6ea3c060SGarrett D'Amore #ifdef _DES_IMPL
108b5a2d845SHai-May Chao 
109b5a2d845SHai-May Chao #ifdef _KERNEL
110b5a2d845SHai-May Chao typedef enum des_mech_type {
111b5a2d845SHai-May Chao 	DES_ECB_MECH_INFO_TYPE,		/* SUN_CKM_DES_ECB */
112b5a2d845SHai-May Chao 	DES_CBC_MECH_INFO_TYPE,		/* SUN_CKM_DES_CBC */
113b5a2d845SHai-May Chao 	DES_CFB_MECH_INFO_TYPE,		/* SUN_CKM_DES_CFB */
114b5a2d845SHai-May Chao 	DES3_ECB_MECH_INFO_TYPE,	/* SUN_CKM_DES3_ECB */
115b5a2d845SHai-May Chao 	DES3_CBC_MECH_INFO_TYPE,	/* SUN_CKM_DES3_CBC */
116b5a2d845SHai-May Chao 	DES3_CFB_MECH_INFO_TYPE		/* SUN_CKM_DES3_CFB */
117b5a2d845SHai-May Chao } des_mech_type_t;
118b5a2d845SHai-May Chao 
119*6ea3c060SGarrett D'Amore #endif	/* _KERNEL */
120*6ea3c060SGarrett D'Amore #endif	/* _DES_IMPL */
121b5a2d845SHai-May Chao 
1227c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate #endif
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #endif	/* _DES_IMPL_H */
127