xref: /illumos-gate/usr/src/uts/common/rpc/des_crypt.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28 /*
29  * Portions of this source code were derived from Berkeley
30  * 4.3 BSD under license from the Regents of the University of
31  * California.
32  */
33 
34 /*
35  * des_crypt.h, des library routine interface
36  */
37 
38 #ifndef _DES_DES_CRYPT_H
39 #define	_DES_DES_CRYPT_H
40 
41 #include <sys/types.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define	DES_MAXDATA 8192	/* max bytes encrypted in one call */
48 #define	DES_DIRMASK (1 << 0)
49 #define	DES_ENCRYPT (0 * DES_DIRMASK)	/* Encrypt */
50 #define	DES_DECRYPT (1 * DES_DIRMASK)	/* Decrypt */
51 
52 
53 #define	DES_DEVMASK (1 << 1)
54 #define	DES_HW (0 * DES_DEVMASK)	/* Use hardware device */
55 #define	DES_SW (1 * DES_DEVMASK)	/* Use software device */
56 
57 
58 #define	DESERR_NONE 0		/* succeeded */
59 #define	DESERR_NOHWDEVICE 1	/* succeeded, but hw device not available */
60 #define	DESERR_HWERROR 2	/* failed, hardware/driver error */
61 #define	DESERR_BADPARAM 3	/* failed, bad parameter to call */
62 
63 #define	DES_FAILED(err) \
64 	((err) > DESERR_NOHWDEVICE)
65 
66 /*
67  * cbc_crypt()
68  * ecb_crypt()
69  *
70  * Encrypt (or decrypt) len bytes of a buffer buf.
71  * The length must be a multiple of eight.
72  * The key should have odd parity in the low bit of each byte.
73  * ivec is the input vector, and is updated to the new one (cbc only).
74  * The mode is created by oring together the appropriate parameters.
75  * DESERR_NOHWDEVICE is returned if DES_HW was specified but
76  * there was no hardware to do it on (the data will still be
77  * encrypted though, in software).
78  */
79 
80 
81 /*
82  * Cipher Block Chaining mode
83  */
84 #ifdef __STDC__
85 int cbc_crypt(char *key, char *buf, size_t len, unsigned int mode, char *ivec);
86 #else
87 int cbc_crypt();
88 #endif
89 
90 
91 /*
92  * Electronic Code Book mode
93  */
94 #ifdef __STDC__
95 int ecb_crypt(char *key, char *buf, size_t len, unsigned int mode);
96 #else
97 int ecb_crypt();
98 #endif
99 
100 
101 #ifndef _KERNEL
102 /*
103  * Set des parity for a key.
104  * DES parity is odd and in the low bit of each byte
105  */
106 #ifdef __STDC__
107 void des_setparity(char *key);
108 #else
109 void des_setparity();
110 #endif
111 #endif	/* _KERNEL */
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif	/* _DES_DES_CRYPT_H */
118