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