Home | History | Annotate | Line # | Download | only in des
      1  1.8      dsl /*	$NetBSD: des.h,v 1.8 2009/03/14 14:46:08 dsl Exp $	*/
      2  1.4   itojun /*	$KAME: des.h,v 1.7 2000/09/18 20:59:21 itojun Exp $	*/
      3  1.1  thorpej 
      4  1.1  thorpej /* lib/des/des.h */
      5  1.1  thorpej /* Copyright (C) 1995-1996 Eric Young (eay (at) mincom.oz.au)
      6  1.1  thorpej  * All rights reserved.
      7  1.1  thorpej  *
      8  1.1  thorpej  * This file is part of an SSL implementation written
      9  1.1  thorpej  * by Eric Young (eay (at) mincom.oz.au).
     10  1.1  thorpej  * The implementation was written so as to conform with Netscapes SSL
     11  1.1  thorpej  * specification.  This library and applications are
     12  1.1  thorpej  * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
     13  1.1  thorpej  * as long as the following conditions are aheared to.
     14  1.1  thorpej  *
     15  1.1  thorpej  * Copyright remains Eric Young's, and as such any Copyright notices in
     16  1.1  thorpej  * the code are not to be removed.  If this code is used in a product,
     17  1.1  thorpej  * Eric Young should be given attribution as the author of the parts used.
     18  1.1  thorpej  * This can be in the form of a textual message at program startup or
     19  1.1  thorpej  * in documentation (online or textual) provided with the package.
     20  1.1  thorpej  *
     21  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     22  1.1  thorpej  * modification, are permitted provided that the following conditions
     23  1.1  thorpej  * are met:
     24  1.1  thorpej  * 1. Redistributions of source code must retain the copyright
     25  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     26  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     27  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     28  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     29  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     30  1.1  thorpej  *    must display the following acknowledgement:
     31  1.1  thorpej  *    This product includes software developed by Eric Young (eay (at) mincom.oz.au)
     32  1.1  thorpej  *
     33  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
     34  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     35  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     36  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     37  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     38  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     39  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     40  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     41  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     42  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     43  1.1  thorpej  * SUCH DAMAGE.
     44  1.1  thorpej  *
     45  1.1  thorpej  * The licence and distribution terms for any publically available version or
     46  1.1  thorpej  * derivative of this code cannot be changed.  i.e. this code cannot simply be
     47  1.1  thorpej  * copied and put under another distribution licence
     48  1.1  thorpej  * [including the GNU Public Licence.]
     49  1.1  thorpej  */
     50  1.1  thorpej 
     51  1.1  thorpej #ifndef HEADER_DES_H
     52  1.1  thorpej #define HEADER_DES_H
     53  1.1  thorpej 
     54  1.1  thorpej #ifdef  __cplusplus
     55  1.1  thorpej extern "C" {
     56  1.1  thorpej #endif
     57  1.1  thorpej 
     58  1.2   itojun /* must be 32bit quantity */
     59  1.2   itojun #define DES_LONG u_int32_t
     60  1.1  thorpej 
     61  1.1  thorpej typedef unsigned char des_cblock[8];
     62  1.1  thorpej typedef struct des_ks_struct
     63  1.1  thorpej 	{
     64  1.5      tls 	union   {
     65  1.5      tls 	des_cblock cblock;
     66  1.5      tls 	/* make sure things are correct size on machines with
     67  1.5      tls 	 * 8 byte longs */
     68  1.5      tls 	DES_LONG deslong[2];
     69  1.5      tls 	} ks;
     70  1.5      tls 	int weak_key;
     71  1.5      tls } des_key_schedule[16];
     72  1.1  thorpej 
     73  1.1  thorpej #define DES_KEY_SZ 	(sizeof(des_cblock))
     74  1.1  thorpej #define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
     75  1.1  thorpej 
     76  1.1  thorpej #define DES_ENCRYPT	1
     77  1.1  thorpej #define DES_DECRYPT	0
     78  1.1  thorpej 
     79  1.1  thorpej #define DES_CBC_MODE	0
     80  1.1  thorpej #define DES_PCBC_MODE	1
     81  1.1  thorpej 
     82  1.1  thorpej extern int des_check_key;	/* defaults to false */
     83  1.1  thorpej 
     84  1.8      dsl char *des_options(void);
     85  1.8      dsl void des_ecb_encrypt(des_cblock *, des_cblock *,
     86  1.8      dsl 	des_key_schedule, int);
     87  1.8      dsl 
     88  1.8      dsl void des_encrypt1(DES_LONG *, des_key_schedule, int);
     89  1.8      dsl void des_encrypt2(DES_LONG *, des_key_schedule, int);
     90  1.8      dsl void des_encrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
     91  1.8      dsl 		      des_key_schedule);
     92  1.8      dsl void des_decrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
     93  1.8      dsl 		      des_key_schedule);
     94  1.5      tls 
     95  1.8      dsl void des_ecb3_encrypt(des_cblock *, des_cblock *, des_key_schedule,
     96  1.8      dsl 			  des_key_schedule, des_key_schedule, int);
     97  1.5      tls 
     98  1.8      dsl void des_ncbc_encrypt(const unsigned char *, unsigned char *, long,
     99  1.8      dsl 			  des_key_schedule, des_cblock *, int);
    100  1.5      tls 
    101  1.5      tls void des_ede3_cbc_encrypt(const unsigned char *, unsigned char *, long,
    102  1.6    perry 			  des_key_schedule, des_key_schedule,
    103  1.5      tls 			  des_key_schedule, des_cblock *, int);
    104  1.2   itojun 
    105  1.8      dsl void des_set_odd_parity(des_cblock *);
    106  1.8      dsl void des_fixup_key_parity(des_cblock *);
    107  1.8      dsl int des_is_weak_key(des_cblock *);
    108  1.8      dsl int des_set_key(des_cblock *, des_key_schedule);
    109  1.8      dsl int des_key_sched(des_cblock *, des_key_schedule);
    110  1.8      dsl int des_set_key_checked(des_cblock *, des_key_schedule);
    111  1.8      dsl void des_set_key_unchecked(des_cblock *, des_key_schedule);
    112  1.8      dsl int des_check_key_parity(des_cblock *);
    113  1.1  thorpej 
    114  1.1  thorpej #ifdef  __cplusplus
    115  1.1  thorpej }
    116  1.1  thorpej #endif
    117  1.1  thorpej 
    118  1.1  thorpej #endif
    119