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