Select Git revision
Forked from
Nettle / nettle
Source project has a limited visibility.
-
Niels Möller authored
Rev: src/symmetric/desCode.h:1.4 Rev: src/symmetric/desKerb.c:1.3 Rev: src/symmetric/desTest.c:1.6 Rev: src/symmetric/desUtil.c:1.3
Niels Möller authoredRev: src/symmetric/desCode.h:1.4 Rev: src/symmetric/desKerb.c:1.3 Rev: src/symmetric/desTest.c:1.6 Rev: src/symmetric/desUtil.c:1.3
desUtil.c 4.02 KiB
/* desUtil.c
*
* $id:$ */
/* des - fast & portable DES encryption & decryption.
* Copyright (C) 1992 Dana L. How
* Please see the file `descore.README' for the complete copyright notice.
*/
#include "desCode.h"
#include "RCSID.h"
RCSID2(desUtil_cRcs, "$Id$");
/* various tables */
UINT32 des_keymap[] = {
#include "keymap.h"
};
static UINT8 rotors[] = {
#include "rotors.h"
};
static char parity[] = {
#include "parity.h"
};
RCSID2(ego, "\n\nFast DES Library Copyright (c) 1991 Dana L. How\n\n");
/* set up the method list from the key */
int
DesMethod(UINT32 *method, const UINT8 *k)
{
register UINT32 n, w;
register char * b0, * b1;
char bits0[56], bits1[56];
/* check for bad parity and weak keys */
b0 = parity;
n = b0[k[0]]; n <<= 4;
n |= b0[k[1]]; n <<= 4;
n |= b0[k[2]]; n <<= 4;
n |= b0[k[3]]; n <<= 4;
n |= b0[k[4]]; n <<= 4;
n |= b0[k[5]]; n <<= 4;
n |= b0[k[6]]; n <<= 4;
n |= b0[k[7]];
w = 0X88888888L;
/* report bad parity in key */
if ( n & w )
return -1;
/* report a weak or semi-weak key */
if ( !((n - (w >> 3)) & w) ) { /* 1 in 10^10 keys passes this test */
if ( n < 0X41415151 ) {
if ( n < 0X31312121 ) {
if ( n < 0X14141515 ) {
/* 01 01 01 01 01 01 01 01 */
if ( n == 0X11111111 ) return -2;
/* 01 1F 01 1F 01 0E 01 0E */
if ( n == 0X13131212 ) return -2;
} else {
/* 01 E0 01 E0 01 F1 01 F1 */
if ( n == 0X14141515 ) return -2;
/* 01 FE 01 FE 01 FE 01 FE */
if ( n == 0X16161616 ) return -2;
}
} else {
if ( n < 0X34342525 ) {