xref: /freebsd/include/rpc/des_crypt.h (revision 2321c474185e657ad1bdb4ef0a323cb10ba09cfc)
1f7e2700fSBill Paul /*
2f7e2700fSBill Paul  * @(#)des_crypt.h	2.1 88/08/11 4.0 RPCSRC;	from 1.4 88/02/08 (C) 1986 SMI
3c4473420SPeter Wemm  * $FreeBSD$
4f7e2700fSBill Paul  *
5f7e2700fSBill Paul  * des_crypt.h, des library routine interface
6f7e2700fSBill Paul  * Copyright (C) 1986, Sun Microsystems, Inc.
7f7e2700fSBill Paul  */
82e322d37SHiroki Sato /*-
9*2321c474SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
10*2321c474SPedro F. Giffuni  *
112e322d37SHiroki Sato  * Copyright (c) 2009, Sun Microsystems, Inc.
122e322d37SHiroki Sato  * All rights reserved.
13f7e2700fSBill Paul  *
142e322d37SHiroki Sato  * Redistribution and use in source and binary forms, with or without
152e322d37SHiroki Sato  * modification, are permitted provided that the following conditions are met:
162e322d37SHiroki Sato  * - Redistributions of source code must retain the above copyright notice,
172e322d37SHiroki Sato  *   this list of conditions and the following disclaimer.
182e322d37SHiroki Sato  * - Redistributions in binary form must reproduce the above copyright notice,
192e322d37SHiroki Sato  *   this list of conditions and the following disclaimer in the documentation
202e322d37SHiroki Sato  *   and/or other materials provided with the distribution.
212e322d37SHiroki Sato  * - Neither the name of Sun Microsystems, Inc. nor the names of its
222e322d37SHiroki Sato  *   contributors may be used to endorse or promote products derived
232e322d37SHiroki Sato  *   from this software without specific prior written permission.
24f7e2700fSBill Paul  *
252e322d37SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
262e322d37SHiroki Sato  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
272e322d37SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
282e322d37SHiroki Sato  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
292e322d37SHiroki Sato  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
302e322d37SHiroki Sato  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
312e322d37SHiroki Sato  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
322e322d37SHiroki Sato  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
332e322d37SHiroki Sato  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
342e322d37SHiroki Sato  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
352e322d37SHiroki Sato  * POSSIBILITY OF SUCH DAMAGE.
36f7e2700fSBill Paul  */
378360efbdSAlfred Perlstein /*
388360efbdSAlfred Perlstein  * Copyright (c) 1986 - 1991 by Sun Microsystems, Inc.
398360efbdSAlfred Perlstein  */
408360efbdSAlfred Perlstein 
418360efbdSAlfred Perlstein /*
428360efbdSAlfred Perlstein  * des_crypt.h, des library routine interface
438360efbdSAlfred Perlstein  */
448360efbdSAlfred Perlstein 
458360efbdSAlfred Perlstein #ifndef _DES_DES_CRYPT_H
468360efbdSAlfred Perlstein #define _DES_DES_CRYPT_H
47f7e2700fSBill Paul 
48f7e2700fSBill Paul #include <sys/cdefs.h>
49f7e2700fSBill Paul #include <rpc/rpc.h>
50f7e2700fSBill Paul 
51f7e2700fSBill Paul #define DES_MAXDATA 8192	/* max bytes encrypted in one call */
52f7e2700fSBill Paul #define DES_DIRMASK (1 << 0)
53f7e2700fSBill Paul #define DES_ENCRYPT (0*DES_DIRMASK)	/* Encrypt */
54f7e2700fSBill Paul #define DES_DECRYPT (1*DES_DIRMASK)	/* Decrypt */
55f7e2700fSBill Paul 
56f7e2700fSBill Paul 
57f7e2700fSBill Paul #define DES_DEVMASK (1 << 1)
58f7e2700fSBill Paul #define	DES_HW (0*DES_DEVMASK)	/* Use hardware device */
59f7e2700fSBill Paul #define DES_SW (1*DES_DEVMASK)	/* Use software device */
60f7e2700fSBill Paul 
61f7e2700fSBill Paul 
62f7e2700fSBill Paul #define DESERR_NONE 0	/* succeeded */
63f7e2700fSBill Paul #define DESERR_NOHWDEVICE 1	/* succeeded, but hw device not available */
64f7e2700fSBill Paul #define DESERR_HWERROR 2	/* failed, hardware/driver error */
65f7e2700fSBill Paul #define DESERR_BADPARAM 3	/* failed, bad parameter to call */
66f7e2700fSBill Paul 
67f7e2700fSBill Paul #define DES_FAILED(err) \
68f7e2700fSBill Paul 	((err) > DESERR_NOHWDEVICE)
69f7e2700fSBill Paul 
70f7e2700fSBill Paul /*
71f7e2700fSBill Paul  * cbc_crypt()
72f7e2700fSBill Paul  * ecb_crypt()
73f7e2700fSBill Paul  *
74f7e2700fSBill Paul  * Encrypt (or decrypt) len bytes of a buffer buf.
75f7e2700fSBill Paul  * The length must be a multiple of eight.
76f7e2700fSBill Paul  * The key should have odd parity in the low bit of each byte.
77f7e2700fSBill Paul  * ivec is the input vector, and is updated to the new one (cbc only).
78f7e2700fSBill Paul  * The mode is created by oring together the appropriate parameters.
79f7e2700fSBill Paul  * DESERR_NOHWDEVICE is returned if DES_HW was specified but
80f7e2700fSBill Paul  * there was no hardware to do it on (the data will still be
81f7e2700fSBill Paul  * encrypted though, in software).
82f7e2700fSBill Paul  */
83f7e2700fSBill Paul 
84f7e2700fSBill Paul 
85f7e2700fSBill Paul /*
86f7e2700fSBill Paul  * Cipher Block Chaining mode
87f7e2700fSBill Paul  */
88f7e2700fSBill Paul __BEGIN_DECLS
89bb28f3c2SWarner Losh int cbc_crypt( char *, char *, unsigned int, unsigned int, char *);
908360efbdSAlfred Perlstein __END_DECLS
91f7e2700fSBill Paul 
92f7e2700fSBill Paul /*
93f7e2700fSBill Paul  * Electronic Code Book mode
94f7e2700fSBill Paul  */
958360efbdSAlfred Perlstein __BEGIN_DECLS
96bb28f3c2SWarner Losh int ecb_crypt( char *, char *, unsigned int, unsigned int );
97f7e2700fSBill Paul __END_DECLS
98f7e2700fSBill Paul 
99f7e2700fSBill Paul /*
100f7e2700fSBill Paul  * Set des parity for a key.
101f7e2700fSBill Paul  * DES parity is odd and in the low bit of each byte
102f7e2700fSBill Paul  */
103f7e2700fSBill Paul __BEGIN_DECLS
104bb28f3c2SWarner Losh void des_setparity( char *);
105f7e2700fSBill Paul __END_DECLS
1068360efbdSAlfred Perlstein 
1078360efbdSAlfred Perlstein #endif  /* _DES_DES_CRYPT_H */
108