mux/src/crypt/crypt.cpp

Go to the documentation of this file.
00001 /*
00002  * UFC-crypt: ultra fast crypt(3) implementation
00003  *
00004  * Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; see the file COPYING.LIB.  If not,
00018  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  *
00021  * @(#)crypt.c  2.25 12/20/96
00022  *
00023  * Semiportable C version
00024  *
00025  */
00026 
00027 #include "ufc-crypt.h"
00028 #include "crypt.h"
00029 #include "crypt-private.h"
00030 
00031 #ifdef _UFC_32_
00032 
00033 /*
00034  * 32 bit version
00035  */
00036 
00037 #define SBA(sb, v) (*(long32*)((char*)(sb)+(v)))
00038 
00039 void
00040 _ufc_doit_r(ufc_long itr, struct crypt_data *__data, ufc_long *res)
00041 {
00042   int i;
00043   long32 s, *k;
00044   long32 *sb01 = (long32*)__data->sb0;
00045   long32 *sb23 = (long32*)__data->sb2;
00046   long32 l1, l2, r1, r2;
00047 
00048   l1 = (long32)res[0]; l2 = (long32)res[1];
00049   r1 = (long32)res[2]; r2 = (long32)res[3];
00050 
00051   while(itr--) {
00052     k = (long32*)__data->keysched;
00053     for(i=8; i--; ) {
00054       s = *k++ ^ r1;
00055       l1 ^= SBA(sb01, s & 0xffff); l2 ^= SBA(sb01, (s & 0xffff)+4);
00056       l1 ^= SBA(sb01, s >>= 16  ); l2 ^= SBA(sb01, (s         )+4);
00057       s = *k++ ^ r2;
00058       l1 ^= SBA(sb23, s & 0xffff); l2 ^= SBA(sb23, (s & 0xffff)+4);
00059       l1 ^= SBA(sb23, s >>= 16  ); l2 ^= SBA(sb23, (s         )+4);
00060 
00061       s = *k++ ^ l1;
00062       r1 ^= SBA(sb01, s & 0xffff); r2 ^= SBA(sb01, (s & 0xffff)+4);
00063       r1 ^= SBA(sb01, s >>= 16  ); r2 ^= SBA(sb01, (s         )+4);
00064       s = *k++ ^ l2;
00065       r1 ^= SBA(sb23, s & 0xffff); r2 ^= SBA(sb23, (s & 0xffff)+4);
00066       r1 ^= SBA(sb23, s >>= 16  ); r2 ^= SBA(sb23, (s         )+4);
00067     }
00068     s=l1; l1=r1; r1=s; s=l2; l2=r2; r2=s;
00069   }
00070   res[0] = l1; res[1] = l2; res[2] = r1; res[3] = r2;
00071 }
00072 
00073 #endif
00074 
00075 #ifdef _UFC_64_
00076 
00077 /*
00078  * 64 bit version
00079  */
00080 
00081 #define SBA(sb, v) (*(long64*)((char*)(sb)+(v)))
00082 
00083 void
00084 _ufc_doit_r(itr, __data, res)
00085      ufc_long itr, *res;
00086      struct crypt_data *__data;
00087 {
00088   int i;
00089   long64 l, r, s, *k;
00090   register long64 *sb01 = (long64*)__data->sb0;
00091   register long64 *sb23 = (long64*)__data->sb2;
00092 
00093   l = (((long64)res[0]) << 32) | ((long64)res[1]);
00094   r = (((long64)res[2]) << 32) | ((long64)res[3]);
00095 
00096   while(itr--) {
00097     k = (long64*)__data->keysched;
00098     for(i=8; i--; ) {
00099       s = *k++ ^ r;
00100       l ^= SBA(sb23, (s       ) & 0xffff);
00101       l ^= SBA(sb23, (s >>= 16) & 0xffff);
00102       l ^= SBA(sb01, (s >>= 16) & 0xffff);
00103       l ^= SBA(sb01, (s >>= 16)         );
00104 
00105       s = *k++ ^ l;
00106       r ^= SBA(sb23, (s       ) & 0xffff);
00107       r ^= SBA(sb23, (s >>= 16) & 0xffff);
00108       r ^= SBA(sb01, (s >>= 16) & 0xffff);
00109       r ^= SBA(sb01, (s >>= 16)         );
00110     }
00111     s=l; l=r; r=s;
00112   }
00113 
00114   res[0] = l >> 32; res[1] = l & 0xffffffff;
00115   res[2] = r >> 32; res[3] = r & 0xffffffff;
00116 }
00117 
00118 #endif

Generated on Mon May 28 04:40:08 2007 for MUX by  doxygen 1.4.7