162587Sitojun/*	$FreeBSD$	*/
291671Sume/*	$KAME: des.h,v 1.8 2001/09/10 04:03:57 itojun Exp $	*/
362587Sitojun
455009Sshin/* lib/des/des.h */
555009Sshin/* Copyright (C) 1995-1996 Eric Young (eay@mincom.oz.au)
655009Sshin * All rights reserved.
755009Sshin *
855009Sshin * This file is part of an SSL implementation written
955009Sshin * by Eric Young (eay@mincom.oz.au).
1055009Sshin * The implementation was written so as to conform with Netscapes SSL
1155009Sshin * specification.  This library and applications are
1255009Sshin * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
1355009Sshin * as long as the following conditions are aheared to.
1455009Sshin *
1555009Sshin * Copyright remains Eric Young's, and as such any Copyright notices in
1655009Sshin * the code are not to be removed.  If this code is used in a product,
1755009Sshin * Eric Young should be given attribution as the author of the parts used.
1855009Sshin * This can be in the form of a textual message at program startup or
1955009Sshin * in documentation (online or textual) provided with the package.
2055009Sshin *
2155009Sshin * Redistribution and use in source and binary forms, with or without
2255009Sshin * modification, are permitted provided that the following conditions
2355009Sshin * are met:
2455009Sshin * 1. Redistributions of source code must retain the copyright
2555009Sshin *    notice, this list of conditions and the following disclaimer.
2655009Sshin * 2. Redistributions in binary form must reproduce the above copyright
2755009Sshin *    notice, this list of conditions and the following disclaimer in the
2855009Sshin *    documentation and/or other materials provided with the distribution.
2955009Sshin * 3. All advertising materials mentioning features or use of this software
3055009Sshin *    must display the following acknowledgement:
3155009Sshin *    This product includes software developed by Eric Young (eay@mincom.oz.au)
3255009Sshin *
3355009Sshin * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
3455009Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3555009Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3655009Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
3755009Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3855009Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3955009Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4055009Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4155009Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4255009Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4355009Sshin * SUCH DAMAGE.
4455009Sshin *
4555009Sshin * The licence and distribution terms for any publically available version or
4655009Sshin * derivative of this code cannot be changed.  i.e. this code cannot simply be
4755009Sshin * copied and put under another distribution licence
4855009Sshin * [including the GNU Public Licence.]
4955009Sshin */
5055009Sshin
5155009Sshin#ifndef HEADER_DES_H
5262587Sitojun#define HEADER_DES_H
5355009Sshin
5455009Sshin#ifdef  __cplusplus
5555009Sshinextern "C" {
5655009Sshin#endif
5755009Sshin
5878064Sume/* must be 32bit quantity */
5978064Sume#define DES_LONG u_int32_t
6055009Sshin
6155009Sshintypedef unsigned char des_cblock[8];
6255009Sshintypedef struct des_ks_struct
6355009Sshin	{
6491671Sume	union   {
6591671Sume	des_cblock cblock;
6691671Sume	/* make sure things are correct size on machines with
6791671Sume	 * 8 byte longs */
6891671Sume	DES_LONG deslong[2];
6991671Sume	} ks;
7091671Sume	int weak_key;
7191671Sume} des_key_schedule[16];
7255009Sshin
7362587Sitojun#define DES_KEY_SZ 	(sizeof(des_cblock))
7462587Sitojun#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
7555009Sshin
7662587Sitojun#define DES_ENCRYPT	1
7762587Sitojun#define DES_DECRYPT	0
7855009Sshin
7962587Sitojun#define DES_CBC_MODE	0
8062587Sitojun#define DES_PCBC_MODE	1
8155009Sshin
8255009Sshinextern int des_check_key;	/* defaults to false */
8355009Sshin
8492756Salfredchar *des_options(void);
8592756Salfredvoid des_ecb_encrypt(des_cblock *, des_cblock *, des_key_schedule, int);
8691671Sume
8792756Salfredvoid des_encrypt1(DES_LONG *, des_key_schedule, int);
8892756Salfredvoid des_encrypt2(DES_LONG *, des_key_schedule, int);
8992756Salfredvoid des_encrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
9092756Salfred		      des_key_schedule);
9192756Salfredvoid des_decrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
9292756Salfred		      des_key_schedule);
9355009Sshin
9492756Salfredvoid des_ecb3_encrypt(des_cblock *, des_cblock *, des_key_schedule,
9592756Salfred			  des_key_schedule, des_key_schedule, int);
9691671Sume
9792756Salfredvoid des_ncbc_encrypt(const unsigned char *, unsigned char *, long,
9892756Salfred			  des_key_schedule, des_cblock *, int);
9991671Sume
10091671Sumevoid des_ede3_cbc_encrypt(const unsigned char *, unsigned char *, long,
10191671Sume			  des_key_schedule, des_key_schedule,
10291671Sume			  des_key_schedule, des_cblock *, int);
10391671Sume
10492756Salfredvoid des_set_odd_parity(des_cblock *);
10592756Salfredvoid des_fixup_key_parity(des_cblock *);
10692756Salfredint des_is_weak_key(des_cblock *);
10792756Salfredint des_set_key(des_cblock *, des_key_schedule);
10892756Salfredint des_key_sched(des_cblock *, des_key_schedule);
10992756Salfredint des_set_key_checked(des_cblock *, des_key_schedule);
11092756Salfredvoid des_set_key_unchecked(des_cblock *, des_key_schedule);
11192756Salfredint des_check_key_parity(des_cblock *);
11255009Sshin
11355009Sshin#ifdef  __cplusplus
11455009Sshin}
11555009Sshin#endif
11655009Sshin
11755009Sshin#endif
118