Merged in libdes3.21-branch
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@473 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,24 +1,127 @@
|
||||
/* des_locl.h */
|
||||
/* Copyright (C) 1993 Eric Young - see README for more details */
|
||||
|
||||
#ifndef __des_locl_h
|
||||
#define __des_locl_h
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "protos.h"
|
||||
|
||||
/*
|
||||
if (we have termios.h)
|
||||
define TERMIOS
|
||||
else if (we have termio.h)
|
||||
define TERMIO
|
||||
*/
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
|
||||
#define TERMIOS
|
||||
|
||||
#else /* !HAVE_TERMIOS_H */
|
||||
|
||||
#ifdef HAVE_TERMIO_H
|
||||
#define TERMIO
|
||||
#endif
|
||||
|
||||
#endif /* !HAVE_TERMIOS_H */
|
||||
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
/* lib/des/des_locl.h */
|
||||
/* Copyright (C) 1995 Eric Young (eay@mincom.oz.au)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of an SSL implementation written
|
||||
* by Eric Young (eay@mincom.oz.au).
|
||||
* The implementation was written so as to conform with Netscapes SSL
|
||||
* specification. This library and applications are
|
||||
* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
|
||||
* as long as the following conditions are aheared to.
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed. If this code is used in a product,
|
||||
* Eric Young should be given attribution as the author of the parts used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Eric Young (eay@mincom.oz.au)
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DES_LOCL_H
|
||||
#define HEADER_DES_LOCL_H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifndef MSDOS
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
|
||||
#endif
|
||||
#include "des.h"
|
||||
|
||||
/* the following is tweaked from a config script, that is why it is a
|
||||
* protected undef/define */
|
||||
#ifndef DES_USE_PTR
|
||||
#undef DES_USE_PTR
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#define RAND
|
||||
#undef PROTO
|
||||
#define PROTO
|
||||
#endif
|
||||
|
||||
#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifndef RAND
|
||||
#define RAND
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
#define getpid() 2
|
||||
extern int errno;
|
||||
#define RAND
|
||||
#undef PROTO
|
||||
#define PROTO
|
||||
#endif
|
||||
|
||||
#if defined(NOCONST)
|
||||
#define const
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
#undef PROTO
|
||||
#define PROTO
|
||||
#endif
|
||||
|
||||
#ifdef RAND
|
||||
#define srandom(s) srand(s)
|
||||
#define random rand
|
||||
#endif
|
||||
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
|
||||
@@ -26,58 +129,58 @@
|
||||
#define MAXWRITE (1024*16)
|
||||
#define BSIZE (MAXWRITE+4)
|
||||
|
||||
#define c2l(c,l) (l =((u_int32_t)(*((c)++))) , \
|
||||
l|=((u_int32_t)(*((c)++)))<< 8, \
|
||||
l|=((u_int32_t)(*((c)++)))<<16, \
|
||||
l|=((u_int32_t)(*((c)++)))<<24)
|
||||
#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
l|=((unsigned long)(*((c)++)))<<24L)
|
||||
|
||||
/* NOTE - c is not incremented as per c2l */
|
||||
#define c2ln(c,l1,l2,n) { \
|
||||
c+=n; \
|
||||
l1=l2=0; \
|
||||
switch (n) { \
|
||||
case 8: l2|=((u_int32_t)(*(--(c))))<<24; \
|
||||
case 7: l2|=((u_int32_t)(*(--(c))))<<16; \
|
||||
case 6: l2|=((u_int32_t)(*(--(c))))<< 8; \
|
||||
case 5: l2|=((u_int32_t)(*(--(c)))); \
|
||||
case 4: l1|=((u_int32_t)(*(--(c))))<<24; \
|
||||
case 3: l1|=((u_int32_t)(*(--(c))))<<16; \
|
||||
case 2: l1|=((u_int32_t)(*(--(c))))<< 8; \
|
||||
case 1: l1|=((u_int32_t)(*(--(c)))); \
|
||||
case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
|
||||
case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
|
||||
case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
|
||||
case 5: l2|=((unsigned long)(*(--(c)))); \
|
||||
case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
|
||||
case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
|
||||
case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
|
||||
case 1: l1|=((unsigned long)(*(--(c)))); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>24)&0xff))
|
||||
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
|
||||
|
||||
/* replacements for htonl and ntohl since I have no idea what to do
|
||||
* when faced with machines with 8 byte longs. */
|
||||
#define HDRSIZE 4
|
||||
|
||||
#define n2l(c,l) (l =((u_int32_t)(*((c)++)))<<24, \
|
||||
l|=((u_int32_t)(*((c)++)))<<16, \
|
||||
l|=((u_int32_t)(*((c)++)))<< 8, \
|
||||
l|=((u_int32_t)(*((c)++))))
|
||||
#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
l|=((unsigned long)(*((c)++))))
|
||||
|
||||
#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l) )&0xff))
|
||||
#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l) )&0xff))
|
||||
|
||||
/* NOTE - c is not incremented as per l2c */
|
||||
#define l2cn(l1,l2,c,n) { \
|
||||
c+=n; \
|
||||
switch (n) { \
|
||||
case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -85,27 +188,27 @@
|
||||
* compiler and the achitecture. gcc2 always seems to do well :-).
|
||||
* Inspired by Dana How <how@isl.stanford.edu>
|
||||
* DO NOT use the alternative version on machines with 8 byte longs. */
|
||||
#ifdef ALT_ECB
|
||||
#define D_ENCRYPT(L,R,S) \
|
||||
#ifdef DES_USR_PTR
|
||||
#define D_ENCRYPT(L,R,S) { \
|
||||
u=((R^s[S ])<<2); \
|
||||
t= R^s[S+1]; \
|
||||
t=((t>>2)+(t<<30)); \
|
||||
L^= \
|
||||
*(u_int32_t *)(des_SP+0x0100+((t )&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+0x0500+((t>>16)&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+0x0700+((t>>24)&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+ ((u )&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+0x0400+((u>>16)&0xfc))+ \
|
||||
*(u_int32_t *)(des_SP+0x0600+((u>>24)&0xfc));
|
||||
*(unsigned long *)(des_SP+0x0100+((t )&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+ ((u )&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \
|
||||
*(unsigned long *)(des_SP+0x0600+((u>>24)&0xfc)); }
|
||||
#else /* original version */
|
||||
#ifdef MSDOS
|
||||
#define D_ENCRYPT(L,R,S) \
|
||||
U.l=R^s[S+1]; \
|
||||
T.s[0]=((U.s[0]>>4)|(U.s[1]<<12))&0x3f3f; \
|
||||
T.s[1]=((U.s[1]>>4)|(U.s[0]<<12))&0x3f3f; \
|
||||
U.l=(R^s[S ])&0x3f3f3f3f; \
|
||||
U.l=(R^s[S ])&0x3f3f3f3fL; \
|
||||
L^= des_SPtrans[1][(T.c[0])]| \
|
||||
des_SPtrans[3][(T.c[1])]| \
|
||||
des_SPtrans[5][(T.c[2])]| \
|
||||
@@ -115,18 +218,18 @@
|
||||
des_SPtrans[4][(U.c[2])]| \
|
||||
des_SPtrans[6][(U.c[3])];
|
||||
#else
|
||||
#define D_ENCRYPT(L,R,S) \
|
||||
#define D_ENCRYPT(Q,R,S) {\
|
||||
u=(R^s[S ]); \
|
||||
t=R^s[S+1]; \
|
||||
t=((t>>4)+(t<<28)); \
|
||||
L^= des_SPtrans[1][(t )&0x3f]| \
|
||||
des_SPtrans[3][(t>> 8)&0x3f]| \
|
||||
des_SPtrans[5][(t>>16)&0x3f]| \
|
||||
des_SPtrans[7][(t>>24)&0x3f]| \
|
||||
des_SPtrans[0][(u )&0x3f]| \
|
||||
des_SPtrans[2][(u>> 8)&0x3f]| \
|
||||
des_SPtrans[4][(u>>16)&0x3f]| \
|
||||
des_SPtrans[6][(u>>24)&0x3f];
|
||||
t=((t>>4L)+(t<<28L)); \
|
||||
Q^= des_SPtrans[1][(t )&0x3f]| \
|
||||
des_SPtrans[3][(t>> 8L)&0x3f]| \
|
||||
des_SPtrans[5][(t>>16L)&0x3f]| \
|
||||
des_SPtrans[7][(t>>24L)&0x3f]| \
|
||||
des_SPtrans[0][(u )&0x3f]| \
|
||||
des_SPtrans[2][(u>> 8L)&0x3f]| \
|
||||
des_SPtrans[4][(u>>16L)&0x3f]| \
|
||||
des_SPtrans[6][(u>>24L)&0x3f]; }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -171,5 +274,23 @@
|
||||
(b)^=(t),\
|
||||
(a)^=((t)<<(n)))
|
||||
|
||||
#define IP(l,r) \
|
||||
{ \
|
||||
register unsigned long tt; \
|
||||
PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
|
||||
PERM_OP(l,r,tt,16,0x0000ffffL); \
|
||||
PERM_OP(r,l,tt, 2,0x33333333L); \
|
||||
PERM_OP(l,r,tt, 8,0x00ff00ffL); \
|
||||
PERM_OP(r,l,tt, 1,0x55555555L); \
|
||||
}
|
||||
|
||||
#endif /* __des_locl_h */
|
||||
#define FP(l,r) \
|
||||
{ \
|
||||
register unsigned long tt; \
|
||||
PERM_OP(l,r,tt, 1,0x55555555L); \
|
||||
PERM_OP(r,l,tt, 8,0x00ff00ffL); \
|
||||
PERM_OP(l,r,tt, 2,0x33333333L); \
|
||||
PERM_OP(r,l,tt,16,0x0000ffffL); \
|
||||
PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user