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