xref: /freebsd/crypto/krb5/src/lib/crypto/builtin/des/key_sched.c (revision b670c9bafc0e31c7609969bf374b2e80bdc00211)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/crypto/builtin/des/key_sched.c */
3 /*
4  * Copyright 1985, 1986, 1987, 1988, 1990 by the Massachusetts Institute
5  * of Technology.
6  * All Rights Reserved.
7  *
8  * Export of this software from the United States of America may
9  *   require a specific license from the United States Government.
10  *   It is the responsibility of any person or organization contemplating
11  *   export to obtain such a license before exporting.
12  *
13  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14  * distribute this software and its documentation for any purpose and
15  * without fee is hereby granted, provided that the above copyright
16  * notice appear in all copies and that both that copyright notice and
17  * this permission notice appear in supporting documentation, and that
18  * the name of M.I.T. not be used in advertising or publicity pertaining
19  * to distribution of the software without specific, written prior
20  * permission.  Furthermore if you modify this software you must label
21  * your software as modified software and not distribute it in such a
22  * fashion that it might be confused with the original M.I.T. software.
23  * M.I.T. makes no representations about the suitability of
24  * this software for any purpose.  It is provided "as is" without express
25  * or implied warranty.
26  */
27 
28 /*
29  * This routine computes the DES key schedule given a key.  The
30  * permutations and shifts have been done at compile time, resulting
31  * in a direct one-step mapping from the input key to the key
32  * schedule.
33  *
34  * Also checks parity and weak keys.
35  *
36  * Watch out for the subscripts -- most effectively start at 1 instead
37  * of at zero.  Maybe some bugs in that area.
38  *
39  * In case the user wants to cache the computed key schedule, it is
40  * passed as an arg.  Also implies that caller has explicit control
41  * over zeroing both the key schedule and the key.
42  *
43  * Originally written 6/85 by Steve Miller, MIT Project Athena.
44  */
45 
46 #include "crypto_int.h"
47 #include "des_int.h"
48 
49 #ifdef K5_BUILTIN_DES
50 
51 int
52 mit_des_key_sched(mit_des_cblock k, mit_des_key_schedule schedule)
53 {
54     mit_des_make_key_sched(k,schedule);
55 
56     if (!mit_des_check_key_parity(k))   /* bad parity --> return -1 */
57         return(-1);
58 
59     if (mit_des_is_weak_key(k))
60         return(-2);
61 
62     /* if key was good, return 0 */
63     return 0;
64 }
65 
66 #endif /* K5_BUILTIN_DES */
67