Back to index

glibc  2.9
crypt.c
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 Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 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  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser 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(itr, __data, res)
00041      ufc_long itr, *res;
00042      struct crypt_data * __restrict __data;
00043 {
00044   int i;
00045   long32 s, *k;
00046   long32 *sb01 = (long32*)__data->sb0;
00047   long32 *sb23 = (long32*)__data->sb2;
00048   long32 l1, l2, r1, r2;
00049 
00050   l1 = (long32)res[0]; l2 = (long32)res[1];
00051   r1 = (long32)res[2]; r2 = (long32)res[3];
00052 
00053   while(itr--) {
00054     k = (long32*)__data->keysched;
00055     for(i=8; i--; ) {
00056       s = *k++ ^ r1;
00057       l1 ^= SBA(sb01, s & 0xffff); l2 ^= SBA(sb01, (s & 0xffff)+4);
00058       l1 ^= SBA(sb01, s >>= 16  ); l2 ^= SBA(sb01, (s         )+4);
00059       s = *k++ ^ r2;
00060       l1 ^= SBA(sb23, s & 0xffff); l2 ^= SBA(sb23, (s & 0xffff)+4);
00061       l1 ^= SBA(sb23, s >>= 16  ); l2 ^= SBA(sb23, (s         )+4);
00062 
00063       s = *k++ ^ l1;
00064       r1 ^= SBA(sb01, s & 0xffff); r2 ^= SBA(sb01, (s & 0xffff)+4);
00065       r1 ^= SBA(sb01, s >>= 16  ); r2 ^= SBA(sb01, (s         )+4);
00066       s = *k++ ^ l2;
00067       r1 ^= SBA(sb23, s & 0xffff); r2 ^= SBA(sb23, (s & 0xffff)+4);
00068       r1 ^= SBA(sb23, s >>= 16  ); r2 ^= SBA(sb23, (s         )+4);
00069     }
00070     s=l1; l1=r1; r1=s; s=l2; l2=r2; r2=s;
00071   }
00072   res[0] = l1; res[1] = l2; res[2] = r1; res[3] = r2;
00073 }
00074 
00075 #endif
00076 
00077 #ifdef _UFC_64_
00078 
00079 /*
00080  * 64 bit version
00081  */
00082 
00083 #define SBA(sb, v) (*(long64*)((char*)(sb)+(v)))
00084 
00085 void
00086 _ufc_doit_r(itr, __data, res)
00087      ufc_long itr, *res;
00088      struct crypt_data * __restrict __data;
00089 {
00090   int i;
00091   long64 l, r, s, *k;
00092   register long64 *sb01 = (long64*)__data->sb0;
00093   register long64 *sb23 = (long64*)__data->sb2;
00094 
00095   l = (((long64)res[0]) << 32) | ((long64)res[1]);
00096   r = (((long64)res[2]) << 32) | ((long64)res[3]);
00097 
00098   while(itr--) {
00099     k = (long64*)__data->keysched;
00100     for(i=8; i--; ) {
00101       s = *k++ ^ r;
00102       l ^= SBA(sb23, (s       ) & 0xffff);
00103       l ^= SBA(sb23, (s >>= 16) & 0xffff);
00104       l ^= SBA(sb01, (s >>= 16) & 0xffff);
00105       l ^= SBA(sb01, (s >>= 16)         );
00106 
00107       s = *k++ ^ l;
00108       r ^= SBA(sb23, (s       ) & 0xffff);
00109       r ^= SBA(sb23, (s >>= 16) & 0xffff);
00110       r ^= SBA(sb01, (s >>= 16) & 0xffff);
00111       r ^= SBA(sb01, (s >>= 16)         );
00112     }
00113     s=l; l=r; r=s;
00114   }
00115 
00116   res[0] = l >> 32; res[1] = l & 0xffffffff;
00117   res[2] = r >> 32; res[3] = r & 0xffffffff;
00118 }
00119 
00120 #endif