xref: /freebsd/include/rpc/des_crypt.h (revision f7e2700f42901072d25967401d2d2716cdf48b78)
1f7e2700fSBill Paul /*
2f7e2700fSBill Paul  * @(#)des_crypt.h	2.1 88/08/11 4.0 RPCSRC;	from 1.4 88/02/08 (C) 1986 SMI
3f7e2700fSBill Paul  *
4f7e2700fSBill Paul  * des_crypt.h, des library routine interface
5f7e2700fSBill Paul  * Copyright (C) 1986, Sun Microsystems, Inc.
6f7e2700fSBill Paul  */
7f7e2700fSBill Paul /*
8f7e2700fSBill Paul  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
9f7e2700fSBill Paul  * unrestricted use provided that this legend is included on all tape
10f7e2700fSBill Paul  * media and as a part of the software program in whole or part.  Users
11f7e2700fSBill Paul  * may copy or modify Sun RPC without charge, but are not authorized
12f7e2700fSBill Paul  * to license or distribute it to anyone else except as part of a product or
13f7e2700fSBill Paul  * program developed by the user.
14f7e2700fSBill Paul  *
15f7e2700fSBill Paul  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
16f7e2700fSBill Paul  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
17f7e2700fSBill Paul  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
18f7e2700fSBill Paul  *
19f7e2700fSBill Paul  * Sun RPC is provided with no support and without any obligation on the
20f7e2700fSBill Paul  * part of Sun Microsystems, Inc. to assist in its use, correction,
21f7e2700fSBill Paul  * modification or enhancement.
22f7e2700fSBill Paul  *
23f7e2700fSBill Paul  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
24f7e2700fSBill Paul  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
25f7e2700fSBill Paul  * OR ANY PART THEREOF.
26f7e2700fSBill Paul  *
27f7e2700fSBill Paul  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
28f7e2700fSBill Paul  * or profits or other special, indirect and consequential damages, even if
29f7e2700fSBill Paul  * Sun has been advised of the possibility of such damages.
30f7e2700fSBill Paul  *
31f7e2700fSBill Paul  * Sun Microsystems, Inc.
32f7e2700fSBill Paul  * 2550 Garcia Avenue
33f7e2700fSBill Paul  * Mountain View, California  94043
34f7e2700fSBill Paul  */
35f7e2700fSBill Paul 
36f7e2700fSBill Paul #include <sys/cdefs.h>
37f7e2700fSBill Paul #include <rpc/rpc.h>
38f7e2700fSBill Paul 
39f7e2700fSBill Paul #define DES_MAXDATA 8192	/* max bytes encrypted in one call */
40f7e2700fSBill Paul #define DES_DIRMASK (1 << 0)
41f7e2700fSBill Paul #define DES_ENCRYPT (0*DES_DIRMASK)	/* Encrypt */
42f7e2700fSBill Paul #define DES_DECRYPT (1*DES_DIRMASK)	/* Decrypt */
43f7e2700fSBill Paul 
44f7e2700fSBill Paul 
45f7e2700fSBill Paul #define DES_DEVMASK (1 << 1)
46f7e2700fSBill Paul #define	DES_HW (0*DES_DEVMASK)	/* Use hardware device */
47f7e2700fSBill Paul #define DES_SW (1*DES_DEVMASK)	/* Use software device */
48f7e2700fSBill Paul 
49f7e2700fSBill Paul 
50f7e2700fSBill Paul #define DESERR_NONE 0	/* succeeded */
51f7e2700fSBill Paul #define DESERR_NOHWDEVICE 1	/* succeeded, but hw device not available */
52f7e2700fSBill Paul #define DESERR_HWERROR 2	/* failed, hardware/driver error */
53f7e2700fSBill Paul #define DESERR_BADPARAM 3	/* failed, bad parameter to call */
54f7e2700fSBill Paul 
55f7e2700fSBill Paul #define DES_FAILED(err) \
56f7e2700fSBill Paul 	((err) > DESERR_NOHWDEVICE)
57f7e2700fSBill Paul 
58f7e2700fSBill Paul /*
59f7e2700fSBill Paul  * cbc_crypt()
60f7e2700fSBill Paul  * ecb_crypt()
61f7e2700fSBill Paul  *
62f7e2700fSBill Paul  * Encrypt (or decrypt) len bytes of a buffer buf.
63f7e2700fSBill Paul  * The length must be a multiple of eight.
64f7e2700fSBill Paul  * The key should have odd parity in the low bit of each byte.
65f7e2700fSBill Paul  * ivec is the input vector, and is updated to the new one (cbc only).
66f7e2700fSBill Paul  * The mode is created by oring together the appropriate parameters.
67f7e2700fSBill Paul  * DESERR_NOHWDEVICE is returned if DES_HW was specified but
68f7e2700fSBill Paul  * there was no hardware to do it on (the data will still be
69f7e2700fSBill Paul  * encrypted though, in software).
70f7e2700fSBill Paul  */
71f7e2700fSBill Paul 
72f7e2700fSBill Paul 
73f7e2700fSBill Paul /*
74f7e2700fSBill Paul  * Cipher Block Chaining mode
75f7e2700fSBill Paul  */
76f7e2700fSBill Paul __BEGIN_DECLS
77f7e2700fSBill Paul #ifdef __STDC__
78f7e2700fSBill Paul int cbc_crypt __P(( char *, char *, unsigned int, unsigned int, char *));
79f7e2700fSBill Paul #else
80f7e2700fSBill Paul cbc_crypt(/* key, buf, len, mode, ivec */); /*
81f7e2700fSBill Paul 	char *key;
82f7e2700fSBill Paul 	char *buf;
83f7e2700fSBill Paul 	unsigned len;
84f7e2700fSBill Paul 	unsigned mode;
85f7e2700fSBill Paul 	char *ivec;
86f7e2700fSBill Paul */
87f7e2700fSBill Paul #endif
88f7e2700fSBill Paul 
89f7e2700fSBill Paul /*
90f7e2700fSBill Paul  * Electronic Code Book mode
91f7e2700fSBill Paul  */
92f7e2700fSBill Paul #ifdef __STDC__
93f7e2700fSBill Paul int ecb_crypt __P(( char *, char *, unsigned int, unsigned int ));
94f7e2700fSBill Paul #else
95f7e2700fSBill Paul ecb_crypt(/* key, buf, len, mode */); /*
96f7e2700fSBill Paul 	char *key;
97f7e2700fSBill Paul 	char *buf;
98f7e2700fSBill Paul 	unsigned len;
99f7e2700fSBill Paul 	unsigned mode;
100f7e2700fSBill Paul */
101f7e2700fSBill Paul #endif
102f7e2700fSBill Paul __END_DECLS
103f7e2700fSBill Paul 
104f7e2700fSBill Paul #ifndef KERNEL
105f7e2700fSBill Paul /*
106f7e2700fSBill Paul  * Set des parity for a key.
107f7e2700fSBill Paul  * DES parity is odd and in the low bit of each byte
108f7e2700fSBill Paul  */
109f7e2700fSBill Paul __BEGIN_DECLS
110f7e2700fSBill Paul #ifdef __STDC__
111f7e2700fSBill Paul void des_setparity __P(( char *));
112f7e2700fSBill Paul #else
113f7e2700fSBill Paul void
114f7e2700fSBill Paul des_setparity(/* key */); /*
115f7e2700fSBill Paul 	char *key;
116f7e2700fSBill Paul */
117f7e2700fSBill Paul #endif
118f7e2700fSBill Paul __END_DECLS
119f7e2700fSBill Paul #endif
120