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