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