xref: /illumos-gate/usr/src/common/crypto/des/des_impl.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_DES_IMPL_H
27 #define	_DES_IMPL_H
28 
29 /*
30  * Common definitions used by DES
31  */
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #define	DES_BLOCK_LEN	8
38 
39 #define	DES_COPY_BLOCK(src, dst) \
40 	(dst)[0] = (src)[0]; \
41 	(dst)[1] = (src)[1]; \
42 	(dst)[2] = (src)[2]; \
43 	(dst)[3] = (src)[3]; \
44 	(dst)[4] = (src)[4]; \
45 	(dst)[5] = (src)[5]; \
46 	(dst)[6] = (src)[6]; \
47 	(dst)[7] = (src)[7];
48 
49 #define	DES_XOR_BLOCK(src, dst) \
50 	(dst)[0] ^= (src)[0]; \
51 	(dst)[1] ^= (src)[1]; \
52 	(dst)[2] ^= (src)[2]; \
53 	(dst)[3] ^= (src)[3]; \
54 	(dst)[4] ^= (src)[4]; \
55 	(dst)[5] ^= (src)[5]; \
56 	(dst)[6] ^= (src)[6]; \
57 	(dst)[7] ^= (src)[7]
58 
59 typedef enum des_strength {
60 	DES = 1,
61 	DES2,
62 	DES3
63 } des_strength_t;
64 
65 #define	DES3_STRENGTH	0x08000000
66 
67 #define	DES_KEYSIZE	8
68 #define	DES_MINBITS	64
69 #define	DES_MAXBITS	64
70 #define	DES_MINBYTES	(DES_MINBITS / 8)
71 #define	DES_MAXBYTES	(DES_MAXBITS / 8)
72 #define	DES_IV_LEN	8
73 
74 #define	DES2_KEYSIZE	(2 * DES_KEYSIZE)
75 #define	DES2_MINBITS	(2 * DES_MINBITS)
76 #define	DES2_MAXBITS	(2 * DES_MAXBITS)
77 #define	DES2_MINBYTES	(DES2_MINBITS / 8)
78 #define	DES2_MAXBYTES	(DES2_MAXBITS / 8)
79 
80 #define	DES3_KEYSIZE	(3 * DES_KEYSIZE)
81 #define	DES3_MINBITS	(2 * DES_MINBITS)	/* DES3 handles CKK_DES2 keys */
82 #define	DES3_MAXBITS	(3 * DES_MAXBITS)
83 #define	DES3_MINBYTES	(DES3_MINBITS / 8)
84 #define	DES3_MAXBYTES	(DES3_MAXBITS / 8)
85 
86 extern int des_encrypt_contiguous_blocks(void *, char *, size_t,
87     crypto_data_t *);
88 extern int des_decrypt_contiguous_blocks(void *, char *, size_t,
89     crypto_data_t *);
90 extern uint64_t des_crypt_impl(uint64_t *, uint64_t, int);
91 extern void des_ks(uint64_t *, uint64_t);
92 extern int des_crunch_block(const void *, const uint8_t *, uint8_t *,
93     boolean_t);
94 extern int des3_crunch_block(const void *, const uint8_t *, uint8_t *,
95     boolean_t);
96 extern void des_init_keysched(uint8_t *, des_strength_t, void *);
97 extern void *des_alloc_keysched(size_t *, des_strength_t, int);
98 extern boolean_t des_keycheck(uint8_t *, des_strength_t, uint8_t *);
99 extern void des_parity_fix(uint8_t *, des_strength_t, uint8_t *);
100 extern void des_copy_block(uint8_t *, uint8_t *);
101 extern void des_xor_block(uint8_t *, uint8_t *);
102 extern int des_encrypt_block(const void *, const uint8_t *, uint8_t *);
103 extern int des3_encrypt_block(const void *, const uint8_t *, uint8_t *);
104 extern int des_decrypt_block(const void *, const uint8_t *, uint8_t *);
105 extern int des3_decrypt_block(const void *, const uint8_t *, uint8_t *);
106 
107 #ifdef _DES_IMPL
108 
109 #ifdef _KERNEL
110 typedef enum des_mech_type {
111 	DES_ECB_MECH_INFO_TYPE,		/* SUN_CKM_DES_ECB */
112 	DES_CBC_MECH_INFO_TYPE,		/* SUN_CKM_DES_CBC */
113 	DES_CFB_MECH_INFO_TYPE,		/* SUN_CKM_DES_CFB */
114 	DES3_ECB_MECH_INFO_TYPE,	/* SUN_CKM_DES3_ECB */
115 	DES3_CBC_MECH_INFO_TYPE,	/* SUN_CKM_DES3_CBC */
116 	DES3_CFB_MECH_INFO_TYPE		/* SUN_CKM_DES3_CFB */
117 } des_mech_type_t;
118 
119 #endif	/* _KERNEL */
120 #endif	/* _DES_IMPL */
121 
122 #ifdef	__cplusplus
123 }
124 #endif
125 
126 #endif	/* _DES_IMPL_H */
127