rxkad: fix bg-fcrypt to work with roken
[openafs.git] / src / rxkad / bg-fcrypt.c
index cbaf0ee..92e3814 100644 (file)
@@ -2,22 +2,22 @@
  * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden).
  * All rights reserved.
- * 
+ *
  * 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 above 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. Neither the name of the Institute nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #include "afs/param.h"
 #else
 #include <afs/param.h>
+#include <roken.h>
 #endif
 
-RCSID
-    ("$Header$");
 
 #define DEBUG 0
 #ifdef KERNEL
@@ -72,7 +71,7 @@ RCSID
 #include "rxkad.h"
 #include "fcrypt.h"
 #include "private_data.h"
-#include <des/stats.h>
+#include "stats.h"
 
 /*
  * Unrolling of the inner loops helps the most on pentium chips
@@ -548,8 +547,7 @@ fc_keysched(void *key_, fc_KeySchedule sched)
     const unsigned char *key = key_;
 
     /* Do we have 56 bit longs or even longer longs? */
-#ifdef AFS_64BIT_ENV
-    unsigned long k;           /* k holds all 56 non parity bits */
+    afs_uint64 k;              /* k holds all 56 non parity bits */
 
     /* Compress out parity bits */
     k = (*key++) >> 1;
@@ -603,64 +601,7 @@ fc_keysched(void *key_, fc_KeySchedule sched)
     *sched++ = EFF_NTOHL((afs_uint32) k);
     ROT56R64(k, 11);
     *sched++ = EFF_NTOHL((afs_uint32) k);
-#else
-    afs_uint32 hi, lo;         /* hi is upper 24 bits and lo lower 32, total 56 */
-
-    /* Compress out parity bits */
-    lo = (*key++) >> 1;
-    lo <<= 7;
-    lo |= (*key++) >> 1;
-    lo <<= 7;
-    lo |= (*key++) >> 1;
-    lo <<= 7;
-    lo |= (*key++) >> 1;
-    hi = lo >> 4;
-    lo &= 0xf;
-    lo <<= 7;
-    lo |= (*key++) >> 1;
-    lo <<= 7;
-    lo |= (*key++) >> 1;
-    lo <<= 7;
-    lo |= (*key++) >> 1;
-    lo <<= 7;
-    lo |= (*key) >> 1;
 
-    /* Use lower 32 bits for schedule, rotate by 11 each round (16 times) */
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-    ROT56R(hi, lo, 11);
-    *sched++ = EFF_NTOHL(lo);
-#endif
     INC_RXKAD_STATS(fc_key_scheds);
     return 0;
 }
@@ -694,14 +635,14 @@ rxkad_EncryptPacket(const struct rx_connection * rx_connection_not_used,
 
     memcpy(ivec, iv, sizeof(ivec));    /* Must use copy of iv */
     for (frag = &packet->wirevec[1]; len; frag++) {
-       int iov_len = frag->iov_len;
-       afs_uint32 *iov_bas = (afs_uint32 *) frag->iov_base;
-       if (iov_len == 0)
+       int ilen = frag->iov_len;
+       afs_uint32 *ibas = (afs_uint32 *) frag->iov_base;
+       if (ilen == 0)
            return RXKADDATALEN;        /* Length mismatch */
-       if (len < iov_len)
-           iov_len = len;      /* Don't process to much data */
-       fc_cbc_enc(iov_bas, iov_bas, iov_len, sched, ivec);
-       len -= iov_len;
+       if (len < ilen)
+           ilen = len; /* Don't process to much data */
+       fc_cbc_enc(ibas, ibas, ilen, sched, ivec);
+       len -= ilen;
     }
     return 0;
 }
@@ -721,14 +662,14 @@ rxkad_DecryptPacket(const struct rx_connection * rx_connection_not_used,
     ADD_RXKAD_STATS(bytesDecrypted[rxkad_TypeIndex(tp->type)],len);
     memcpy(ivec, iv, sizeof(ivec));    /* Must use copy of iv */
     for (frag = &packet->wirevec[1]; len > 0; frag++) {
-       int iov_len = frag->iov_len;
-       afs_uint32 *iov_bas = (afs_uint32 *) frag->iov_base;
-       if (iov_len == 0)
+       int ilen = frag->iov_len;
+       afs_uint32 *ibas = (afs_uint32 *) frag->iov_base;
+       if (ilen == 0)
            return RXKADDATALEN;        /* Length mismatch */
-       if (len < iov_len)
-           iov_len = len;      /* Don't process to much data */
-       fc_cbc_dec(iov_bas, iov_bas, iov_len, sched, ivec);
-       len -= iov_len;
+       if (len < ilen)
+           ilen = len; /* Don't process to much data */
+       fc_cbc_dec(ibas, ibas, ilen, sched, ivec);
+       len -= ilen;
     }
     return 0;
 }