#include "krb.h"
#include <string.h>
#include "autoconf.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
extern char *malloc(), *calloc(), *realloc();
#endif
int
krb_mk_preauth(preauth_p, preauth_len,
key_proc, aname, inst, realm, password, key)
char **preauth_p;
int *preauth_len;
key_proc_type key_proc;
char *aname;
char *inst;
char *realm;
char *password;
C_Block key;
{
#ifdef NOENCRYPTION
*preauth_len = strlen(aname) + 1;
*preauth_p = malloc(*preauth_len);
strcpy(*preauth_p, aname);
#else
des_key_schedule key_s;
int sl = strlen(aname);
#endif
(*key_proc)(aname, inst, realm, password, key);
#ifndef NOENCRYPTION
*preauth_len = (((sl + 1) / 8) + 1) * 8;
*preauth_p = malloc((size_t)*preauth_len);
if (des_key_sched(key, key_s)) {
return 1;
}
des_pcbc_encrypt((des_cblock *)aname, (des_cblock *)*preauth_p,
(long)(sl + 1), key_s, (des_cblock *)key, DES_ENCRYPT);
memset(key_s, 0, sizeof(key_s));
#endif
return 0;
}
void
krb_free_preauth(preauth_p, preauth_len)
char *preauth_p;
int preauth_len;
{
free(preauth_p);
return;
}