1 /*
2 * lib/crypto/des/weak_key.c
3 *
4 * Copyright 1989,1990 by the Massachusetts Institute of Technology.
5 * All Rights Reserved.
6 *
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
11 *
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
25 *
26 *
27 * Under U.S. law, this software may not be exported outside the US
28 * without license from the U.S. Commerce department.
29 *
30 * These routines form the library interface to the DES facilities.
31 *
32 * Originally written 8/85 by Steve Miller, MIT Project Athena.
33 */
34
35 #include "k5-int.h"
36 #include "des_int.h"
37
38 /*
39 * The following are the weak DES keys:
40 */
41 static const mit_des_cblock weak[16] = {
42 /* weak keys */
43 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
44 {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
45 {0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
46 {0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
47
48 /* semi-weak */
49 {0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
50 {0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
51
52 {0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
53 {0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
54
55 {0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
56 {0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
57
58 {0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
59 {0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
60
61 {0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
62 {0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
63
64 {0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
65 {0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
66 };
67
68 /*
69 * mit_des_is_weak_key: returns true iff key is a [semi-]weak des key.
70 *
71 * Requires: key has correct odd parity.
72 */
73 int
mit_des_is_weak_key(mit_des_cblock key)74 mit_des_is_weak_key(mit_des_cblock key)
75 {
76 int i;
77 const mit_des_cblock *weak_p = weak;
78
79 for (i = 0; i < (sizeof(weak)/sizeof(mit_des_cblock)); i++) {
80 if (!memcmp(weak_p++,key,sizeof(mit_des_cblock)))
81 return 1;
82 }
83
84 return 0;
85 }
86