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