1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/crypto/builtin/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 /*
28 * Under U.S. law, this software may not be exported outside the US
29 * without license from the U.S. Commerce department.
30 *
31 * These routines form the library interface to the DES facilities.
32 *
33 * Originally written 8/85 by Steve Miller, MIT Project Athena.
34 */
35
36 #include "crypto_int.h"
37 #include "des_int.h"
38
39 #ifdef K5_BUILTIN_DES
40
41 /*
42 * The following are the weak DES keys:
43 */
44 static const mit_des_cblock weak[16] = {
45 /* weak keys */
46 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
47 {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
48 {0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
49 {0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
50
51 /* semi-weak */
52 {0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
53 {0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
54
55 {0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
56 {0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
57
58 {0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
59 {0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
60
61 {0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
62 {0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
63
64 {0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
65 {0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
66
67 {0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
68 {0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
69 };
70
71 /*
72 * mit_des_is_weak_key: returns true iff key is a [semi-]weak des key.
73 *
74 * Requires: key has correct odd parity.
75 */
76 int
mit_des_is_weak_key(mit_des_cblock key)77 mit_des_is_weak_key(mit_des_cblock key)
78 {
79 unsigned int i;
80 const mit_des_cblock *weak_p = weak;
81
82 for (i = 0; i < (sizeof(weak)/sizeof(mit_des_cblock)); i++) {
83 if (!memcmp(weak_p++,key,sizeof(mit_des_cblock)))
84 return 1;
85 }
86
87 return 0;
88 }
89
90 #endif /* K5_BUILTIN_DES */
91