ccbfeca1e3ef2d0354c5166e8110f3b88112845c
[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 <afs/param.h>
16 #include <afsconfig.h>
17
18 RCSID("$Header$");
19
20 #include <des.h>
21 #include "des_internal.h"
22 #if defined(HAVE_STRINGS_H)
23 #include <strings.h>
24 #endif
25 #if defined(HAVE_STRING_H)
26 #include <string.h>
27 #endif
28
29 /*
30  * The following are the weak DES keys:
31  */
32 static const des_cblock weak[16] = {
33     /* weak keys */
34     {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
35     {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
36     {0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
37     {0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
38
39     /* semi-weak */
40     {0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
41     {0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
42
43     {0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
44     {0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
45
46     {0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
47     {0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
48
49     {0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
50     {0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
51
52     {0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
53     {0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
54
55     {0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
56     {0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
57 };
58
59 /*
60  * des_is_weak_key: returns true iff key is a [semi-]weak des key.
61  *
62  * Requires: key has correct odd parity.
63  */
64 int
65 des_is_weak_key(key)
66      des_cblock key;
67 {
68     int i;
69     const des_cblock *weak_p = weak;
70
71     for (i = 0; i < (sizeof(weak)/sizeof(des_cblock)); i++) {
72         if (!bcmp((char *)weak_p++,(char *)key,sizeof(des_cblock)))
73             return 1;
74     }
75
76     return 0;
77 }