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