/* -*-c-*-
*
- * $Id: desx.c,v 1.1 2001/04/03 19:36:50 mdw Exp $
+ * $Id$
*
* Implementation of DESX
*
* (c) 2001 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Catacomb.
*
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
- *
+ *
* Catacomb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Library General Public
* License along with Catacomb; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: desx.c,v $
- * Revision 1.1 2001/04/03 19:36:50 mdw
- * New block cipher DESX added.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <assert.h>
/*----- Tables ------------------------------------------------------------*/
-static octet s[256] = DESX_S;
+static const octet s[256] = DESX_S;
/*----- Global variables --------------------------------------------------*/
-const octet desx_keysz[] = { KSZ_SET, 7, 8, 15, 16, 23, 24, 0 };
+const octet desx_keysz[] = { KSZ_SET, 23, 7, 8, 15, 16, 24, 0 };
/*----- Main code ---------------------------------------------------------*/
k->postb = LOAD32(p + 4);
} else {
octet b[16];
+ uint32 x, y;
- if (n == 7) {
-
- /* --- Expand 7 bits to 8 bits --- *
- *
- * Cloned and hacked from @des_init@ to set parity.
- */
-
- uint32 x, y, z;
- x = LOAD32(kk + 0);
- x = (x & 0xfe000000) | ((x & 0x01fffff0) >> 1);
- x = (x & 0xfffe0000) | ((x & 0x0001fff8) >> 1);
- x = (x & 0xfffffe00) | ((x & 0x000001fc) >> 1);
- z = x; z ^= z >> 4; z ^= z >> 2; z ^= z >> 1;
- x |= (z & 0x01010101) ^ 0x01010101;
-
- y = LOAD32(kk + 3) << 1;
- y = (y & 0x000000fe) | ((y & 0x1fffff00) << 1);
- y = (y & 0x0000fefe) | ((y & 0x3fff0000) << 1);
- y = (y & 0x00fefefe) | ((y & 0x7f000000) << 1);
- z = y; z ^= z >> 4; z ^= z >> 2; z ^= z >> 1;
- y |= (z & 0x01010101) ^ 0x01010101;
-
- kk = b + 8;
- STORE32(kk + 0, x); STORE32(kk + 4, y);
- }
-
+ des_expand(kk, n, &x, &y);
+ STORE32(b + 8, x); STORE32(b + 12, y);
memset(b, 0, 8);
- mangle(b, kk);
+ mangle(b, b + 8);
mangle(b, q);
k->posta = LOAD32(b + 0);
- k->postb = LOAD32(b + 4);
+ k->postb = LOAD32(b + 4);
}
}
}