a00bbd49f690d1ba06d7dd0e14defbe0b23b9c3a
[openafs.git] / src / des / weak_key.c
1 /*
2  * Copyright 1989 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see the file
5  * <mit-copyright.h>.
6  *
7  * Under U.S. law, this software may not be exported outside the US
8  * without license from the U.S. Commerce department.
9  *
10  * These routines form the library interface to the DES facilities.
11  *
12  * Originally written 8/85 by Steve Miller, MIT Project Athena.
13  */
14
15 #include <afsconfig.h>
16 #include <afs/param.h>
17
18 RCSID("$Header$");
19
20 #include <des.h>
21 #include "des_internal.h"
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #else
25 #ifdef HAVE_STRINGS_H
26 #include <strings.h>
27 #endif
28 #endif
29
30 /*
31  * The following are the weak DES keys:
32  */
33 static const des_cblock weak[16] = {
34     /* weak keys */
35     {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
36     {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
37     {0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
38     {0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
39
40     /* semi-weak */
41     {0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
42     {0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
43
44     {0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
45     {0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
46
47     {0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
48     {0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
49
50     {0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
51     {0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
52
53     {0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
54     {0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
55
56     {0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
57     {0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
58 };
59
60 /*
61  * des_is_weak_key: returns true iff key is a [semi-]weak des key.
62  *
63  * Requires: key has correct odd parity.
64  */
65 int
66 des_is_weak_key(key)
67      des_cblock key;
68 {
69     int i;
70     const des_cblock *weak_p = weak;
71
72     for (i = 0; i < (sizeof(weak)/sizeof(des_cblock)); i++) {
73         if (!bcmp((char *)weak_p++,(char *)key,sizeof(des_cblock)))
74             return 1;
75     }
76
77     return 0;
78 }