xref: /titanic_50/usr/src/common/crypto/des/des_impl.h (revision 193974072f41a843678abf5f61979c748687e66b)
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 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Common definitions used by DES
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #define	DES_BLOCK_LEN	8
40 
41 #define	DES_COPY_BLOCK(src, dst) \
42 	(dst)[0] = (src)[0]; \
43 	(dst)[1] = (src)[1]; \
44 	(dst)[2] = (src)[2]; \
45 	(dst)[3] = (src)[3]; \
46 	(dst)[4] = (src)[4]; \
47 	(dst)[5] = (src)[5]; \
48 	(dst)[6] = (src)[6]; \
49 	(dst)[7] = (src)[7];
50 
51 #define	DES_XOR_BLOCK(src, dst) \
52 	(dst)[0] ^= (src)[0]; \
53 	(dst)[1] ^= (src)[1]; \
54 	(dst)[2] ^= (src)[2]; \
55 	(dst)[3] ^= (src)[3]; \
56 	(dst)[4] ^= (src)[4]; \
57 	(dst)[5] ^= (src)[5]; \
58 	(dst)[6] ^= (src)[6]; \
59 	(dst)[7] ^= (src)[7]
60 
61 typedef enum des_strength {
62 	DES = 1,
63 	DES2,
64 	DES3
65 } des_strength_t;
66 
67 #define	DES3_STRENGTH	0x08000000
68 
69 #define	DES_KEYSIZE	8
70 #define	DES_MINBITS	64
71 #define	DES_MAXBITS	64
72 #define	DES_MINBYTES	(DES_MINBITS / 8)
73 #define	DES_MAXBYTES	(DES_MAXBITS / 8)
74 #define	DES_IV_LEN	8
75 
76 #define	DES2_KEYSIZE	(2 * DES_KEYSIZE)
77 #define	DES2_MINBITS	(2 * DES_MINBITS)
78 #define	DES2_MAXBITS	(2 * DES_MAXBITS)
79 
80 #define	DES3_KEYSIZE	(3 * DES_KEYSIZE)
81 #define	DES3_MINBITS	(3 * DES_MINBITS)
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	__cplusplus
108 }
109 #endif
110 
111 #endif	/* _DES_IMPL_H */
112