xref: /freebsd/include/rpc/des_crypt.h (revision a4128aad8503277614f2d214011ef60a19447b83)
1 /*
2  *
3  * des_crypt.h, des library routine interface
4  * Copyright (C) 1986, Sun Microsystems, Inc.
5  */
6 /*-
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  * Copyright (c) 2009, Sun Microsystems, Inc.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  * - Redistributions of source code must retain the above copyright notice,
15  *   this list of conditions and the following disclaimer.
16  * - Redistributions in binary form must reproduce the above copyright notice,
17  *   this list of conditions and the following disclaimer in the documentation
18  *   and/or other materials provided with the distribution.
19  * - Neither the name of Sun Microsystems, Inc. nor the names of its
20  *   contributors may be used to endorse or promote products derived
21  *   from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*
36  * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
37  */
38 
39 /*
40  * des_crypt.h, des library routine interface
41  */
42 
43 #ifndef _DES_DES_CRYPT_H
44 #define _DES_DES_CRYPT_H
45 
46 #include <sys/cdefs.h>
47 #include <rpc/rpc.h>
48 
49 #define DES_MAXDATA 8192	/* max bytes encrypted in one call */
50 #define DES_DIRMASK (1 << 0)
51 #define DES_ENCRYPT (0*DES_DIRMASK)	/* Encrypt */
52 #define DES_DECRYPT (1*DES_DIRMASK)	/* Decrypt */
53 
54 
55 #define DES_DEVMASK (1 << 1)
56 #define	DES_HW (0*DES_DEVMASK)	/* Use hardware device */
57 #define DES_SW (1*DES_DEVMASK)	/* Use software device */
58 
59 
60 #define DESERR_NONE 0	/* succeeded */
61 #define DESERR_NOHWDEVICE 1	/* succeeded, but hw device not available */
62 #define DESERR_HWERROR 2	/* failed, hardware/driver error */
63 #define DESERR_BADPARAM 3	/* failed, bad parameter to call */
64 
65 #define DES_FAILED(err) \
66 	((err) > DESERR_NOHWDEVICE)
67 
68 /*
69  * cbc_crypt()
70  * ecb_crypt()
71  *
72  * Encrypt (or decrypt) len bytes of a buffer buf.
73  * The length must be a multiple of eight.
74  * The key should have odd parity in the low bit of each byte.
75  * ivec is the input vector, and is updated to the new one (cbc only).
76  * The mode is created by oring together the appropriate parameters.
77  * DESERR_NOHWDEVICE is returned if DES_HW was specified but
78  * there was no hardware to do it on (the data will still be
79  * encrypted though, in software).
80  */
81 
82 
83 /*
84  * Cipher Block Chaining mode
85  */
86 __BEGIN_DECLS
87 int cbc_crypt( char *, char *, unsigned int, unsigned int, char *);
88 __END_DECLS
89 
90 /*
91  * Electronic Code Book mode
92  */
93 __BEGIN_DECLS
94 int ecb_crypt( char *, char *, unsigned int, unsigned int );
95 __END_DECLS
96 
97 /*
98  * Set des parity for a key.
99  * DES parity is odd and in the low bit of each byte
100  */
101 __BEGIN_DECLS
102 void des_setparity( char *);
103 __END_DECLS
104 
105 #endif  /* _DES_DES_CRYPT_H */
106