17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * lib/crypto/des/weak_key.c
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Copyright 1989,1990 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate  * All Rights Reserved.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
19*159d09a2SMark Phalan  * permission.  Furthermore if you modify this software you must label
20*159d09a2SMark Phalan  * your software as modified software and not distribute it in such a
21*159d09a2SMark Phalan  * fashion that it might be confused with the original M.I.T. software.
22*159d09a2SMark Phalan  * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
247c478bd9Sstevel@tonic-gate  * or implied warranty.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * Under U.S. law, this software may not be exported outside the US
287c478bd9Sstevel@tonic-gate  * without license from the U.S. Commerce department.
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * These routines form the library interface to the DES facilities.
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * Originally written 8/85 by Steve Miller, MIT Project Athena.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
35*159d09a2SMark Phalan #include "k5-int.h"
36*159d09a2SMark Phalan #include "des_int.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * The following are the weak DES keys:
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate static const mit_des_cblock weak[16] = {
427c478bd9Sstevel@tonic-gate     /* weak keys */
437c478bd9Sstevel@tonic-gate     {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
447c478bd9Sstevel@tonic-gate     {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
457c478bd9Sstevel@tonic-gate     {0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
467c478bd9Sstevel@tonic-gate     {0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate     /* semi-weak */
497c478bd9Sstevel@tonic-gate     {0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
507c478bd9Sstevel@tonic-gate     {0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     {0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
537c478bd9Sstevel@tonic-gate     {0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate     {0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
567c478bd9Sstevel@tonic-gate     {0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate     {0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
597c478bd9Sstevel@tonic-gate     {0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate     {0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
627c478bd9Sstevel@tonic-gate     {0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate     {0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
657c478bd9Sstevel@tonic-gate     {0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * mit_des_is_weak_key: returns true iff key is a [semi-]weak des key.
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  * Requires: key has correct odd parity.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate int
74*159d09a2SMark Phalan mit_des_is_weak_key(mit_des_cblock key)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate     int i;
777c478bd9Sstevel@tonic-gate     const mit_des_cblock *weak_p = weak;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate     for (i = 0; i < (sizeof(weak)/sizeof(mit_des_cblock)); i++) {
80*159d09a2SMark Phalan 	if (!memcmp(weak_p++,key,sizeof(mit_des_cblock)))
817c478bd9Sstevel@tonic-gate 	    return 1;
827c478bd9Sstevel@tonic-gate     }
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate     return 0;
857c478bd9Sstevel@tonic-gate }
86