2 * lib/krb4/password_to_key.c
4 * Copyright 1999, 2002 by the Massachusetts Institute of Technology.
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.
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.
26 * password_to_key functions merged from KfM
33 #include <CredentialsCache.h>
39 * passwd_to_key(): given a password, return a DES key.
40 * There are extra arguments here which (used to be?)
41 * used by srvtab_to_key().
43 * If the "passwd" argument is not null, generate a DES
44 * key from it, using string_to_key().
46 * If the "passwd" argument is null, then on a Unix system we call
47 * des_read_password() to prompt for a password and then convert it
48 * into a DES key. But "prompting" the user is harder in a Windows or
49 * Macintosh environment, so we rely on our caller to explicitly do
52 * In either case, the resulting key is put in the "key" argument,
57 key_proc_type *krb_get_keyprocs (key_proc_type keyproc)
59 static key_proc_type default_keyprocs[4] = { mit_passwd_to_key,
64 static key_proc_type user_keyprocs[2] = { NULL, NULL };
66 /* generate the list of key procs */
67 if (keyproc == NULL) {
68 return default_keyprocs; /* use the default */
70 user_keyprocs[0] = keyproc;
71 return user_keyprocs; /* use the caller provided keyprocs */
83 #if 0 /* what system? */
85 #pragma unused(instance)
90 des_string_to_key(passwd, key);
92 #if !(defined(_WIN32) || defined(USE_LOGIN_LIBRARY))
93 des_read_password((des_cblock *)key, "Password", 0);
101 /* So we can use a v4 kinit against a v5 kdc with no krb4 salted key */
113 if (user && instance && realm && passwd) {
114 len = MAX_K_NAME_SZ + strlen(passwd) + 1;
115 tlen = strlen(passwd) + strlen(realm) + strlen(user) + strlen(instance) + 1;
120 sprintf (p, "%s%s%s%s", passwd, realm, user, instance);
121 des_string_to_key (p, key);
137 #if 0 /* what system? */
139 #pragma unused(instance)
143 afs_string_to_key(passwd, realm, key);
145 #if !(defined(_WIN32) || defined(USE_LOGIN_LIBRARY))
146 des_read_password((des_cblock *)key, "Password", 0);