xref: /illumos-gate/usr/src/common/crypto/des/des_impl.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DES_IMPL_H
28 #define	_DES_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Common definitions used by DES
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #define	DES_BLOCK_LEN	8
41 
42 #define	DES_XOR_BLOCK(src, dst) \
43 	(dst)[0] ^= (src)[0]; \
44 	(dst)[1] ^= (src)[1]; \
45 	(dst)[2] ^= (src)[2]; \
46 	(dst)[3] ^= (src)[3]; \
47 	(dst)[4] ^= (src)[4]; \
48 	(dst)[5] ^= (src)[5]; \
49 	(dst)[6] ^= (src)[6]; \
50 	(dst)[7] ^= (src)[7]
51 
52 typedef enum des_strength {
53 	DES = 1,
54 	DES2,
55 	DES3
56 } des_strength_t;
57 
58 #define	DES_KEYSIZE	8
59 #define	DES_MINBITS	64
60 #define	DES_MAXBITS	64
61 #define	DES_MINBYTES	(DES_MINBITS / 8)
62 #define	DES_MAXBYTES	(DES_MAXBITS / 8)
63 #define	DES_IV_LEN	8
64 
65 #define	DES2_KEYSIZE	(2 * DES_KEYSIZE)
66 #define	DES2_MINBITS	(2 * DES_MINBITS)
67 #define	DES2_MAXBITS	(2 * DES_MAXBITS)
68 
69 #define	DES3_KEYSIZE	(3 * DES_KEYSIZE)
70 #define	DES3_MINBITS	(3 * DES_MINBITS)
71 #define	DES3_MAXBITS	(3 * DES_MAXBITS)
72 #define	DES3_MINBYTES	(DES3_MINBITS / 8)
73 #define	DES3_MAXBYTES	(DES3_MAXBITS / 8)
74 
75 extern uint64_t des_crypt_impl(uint64_t *, uint64_t, int);
76 extern void des_ks(uint64_t *, uint64_t);
77 extern void des_crunch_block(void *, uint8_t *, uint8_t *, boolean_t);
78 extern void des3_crunch_block(void *, uint8_t *, uint8_t *, boolean_t);
79 extern void des_init_keysched(uint8_t *, des_strength_t, void *);
80 extern void *des_alloc_keysched(size_t *, des_strength_t, int);
81 extern boolean_t des_keycheck(uint8_t *, des_strength_t, uint8_t *);
82 
83 #ifdef	__cplusplus
84 }
85 #endif
86 
87 #endif	/* _DES_IMPL_H */
88