X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/4e66da02f19648ee1be862e67ba1d1fc5549fb7f..02dfbd5b7af7816959dbd39c1fe628451204e35f:/desx.c diff --git a/desx.c b/desx.c index 060815d..9c7f8eb 100644 --- a/desx.c +++ b/desx.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: desx.c,v 1.2 2004/04/02 01:03:49 mdw Exp $ + * $Id$ * * Implementation of DESX * @@ -27,17 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: desx.c,v $ - * Revision 1.2 2004/04/02 01:03:49 mdw - * Miscellaneous constification. - * - * Revision 1.1 2001/04/03 19:36:50 mdw - * New block cipher DESX added. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -60,7 +49,7 @@ 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 ---------------------------------------------------------*/ @@ -111,35 +100,12 @@ void desx_init(desx_ctx *k, const void *buf, size_t sz) 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);