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