/*
- * $Id: crypt.c,v 1.1 2003-06-11 06:29:30 srittau Exp $
+ * $Id: crypt.c,v 1.2 2003-06-11 07:14:09 srittau Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
#include "crypt.h"
/* Cannot perform in-place operation. dstlen must be at least srclen*2. */
-void hexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen)
+void atalk_hexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen)
{
static const unsigned char hextable[] = "0123456789ABCDEF";
/* Can perform in-place operation. dstlen must be at least srclen/2. */
#define unhex(x) (isdigit(x) ? (x) - '0' : toupper(x) + 10 - 'A')
-void unhexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen)
+void atalk_unhexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen)
{
assert(srclen % 2 == 0);
assert(dstlen >= srclen / 2);
memset(dst, 0, dstlen);
}
-int encrypt_start(CryptHandle *handle, u_int8_t *key)
+int atalk_encrypt_start(CryptHandle *handle, u_int8_t *key)
{
DES_key_schedule *sched = malloc(sizeof(DES_key_schedule));
DES_set_key_unchecked((DES_cblock *) key, sched);
return AFP_OK;
}
-int encrypt_do(CryptHandle handle, u_int8_t *dst, u_int8_t *src)
+int atalk_encrypt_do(CryptHandle handle, u_int8_t *dst, u_int8_t *src)
{
DES_ecb_encrypt((DES_cblock *) src, (DES_cblock *) dst,
(DES_key_schedule *) handle, DES_ENCRYPT);
return AFP_OK;
}
-void encrypt_end(CryptHandle handle)
+void atalk_encrypt_end(CryptHandle handle)
{
memset(handle, 0, sizeof(DES_key_schedule));
free(handle);
}
-int encrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src)
+int atalk_encrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src)
{
DES_key_schedule sched;
return AFP_OK;
}
-int decrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src)
+int atalk_decrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src)
{
DES_key_schedule sched;
#define __UAMS_CRYPT_H
/*
- * $Id: crypt.h,v 1.1 2003-06-11 06:29:30 srittau Exp $
+ * $Id: crypt.h,v 1.2 2003-06-11 07:14:12 srittau Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
typedef void *CryptHandle;
-void hexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen);
-void unhexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen);
+void atalk_hexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen);
+void atalk_unhexify(u_int8_t *dst, size_t dstlen, const u_int8_t *src, size_t srclen);
-int encrypt_start(CryptHandle *handle, u_int8_t *key);
-int encrypt_do(CryptHandle handle, u_int8_t *dst, u_int8_t *src);
-void encrypt_end(CryptHandle handle);
+int atalk_encrypt_start(CryptHandle *handle, u_int8_t *key);
+int atalk_encrypt_do(CryptHandle handle, u_int8_t *dst, u_int8_t *src);
+void atalk_encrypt_end(CryptHandle handle);
-int encrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src);
-int decrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src);
+int atalk_encrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src);
+int atalk_decrypt(u_int8_t *key, u_int8_t *dst, u_int8_t *src);
#endif /* __UAMS_CRYPT_H */
/*
- * $Id: uams_randnum.c,v 1.13 2003-06-11 06:29:30 srittau Exp $
+ * $Id: uams_randnum.c,v 1.14 2003-06-11 07:14:12 srittau Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
#define PASSWDLEN 8
static C_Block seskey;
-static Key_schedule seskeysched;
static struct passwd *randpwd;
static u_int8_t randbuf[8];
afppasswd_found:
if (!set)
- unhexify(p, sizeof(key), p, sizeof(key));
+ atalk_unhexify(p, sizeof(key), p, sizeof(key));
if (keyfd > -1) {
size_t len;
/* convert to binary key */
len = strlen((char *) key);
- unhexify(key, len, key, len);
+ atalk_unhexify(key, len, key, len);
if (set) {
/* NOTE: this takes advantage of the fact that passwd doesn't
* get used after this call if it's being set. */
- err = encrypt(key, passwd, passwd);
+ err = atalk_encrypt(key, passwd, passwd);
} else {
- err = decrypt(key, p, p);
+ err = atalk_decrypt(key, p, p);
}
memset(key, 0, sizeof(key));
int fd = fileno(fp);
/* convert to hex password */
- hexify(key, sizeof(key), passwd, DES_KEY_SZ);
+ atalk_hexify(key, sizeof(key), passwd, DES_KEY_SZ);
memcpy(p, key, sizeof(key));
/* get exclusive access to the user's password entry. we don't
ibuf += sizeof(sessid);
- err = encrypt(seskey, randbuf, randbuf);
+ err = atalk_encrypt(seskey, randbuf, randbuf);
memset(seskey, 0, sizeof(seskey));
if (err)
return err;
seskey[i] <<= 1;
/* encrypt randbuf */
- err = encrypt_start(&crypt_handle, seskey);
- encrypt_do(crypt_handle, randbuf, randbuf);
+ err = atalk_encrypt_start(&crypt_handle, seskey);
+ atalk_encrypt_do(crypt_handle, randbuf, randbuf);
/* test against client's reply */
if (memcmp(randbuf, ibuf, sizeof(randbuf))) { /* != */
memset(randbuf, 0, sizeof(randbuf));
- memset(&seskeysched, 0, sizeof(seskeysched));
return AFPERR_NOTAUTH;
}
ibuf += sizeof(randbuf);
memset(randbuf, 0, sizeof(randbuf));
/* encrypt client's challenge and send back */
- encrypt_do(crypt_handle, rbuf, ibuf);
- encrypt_end(crypt_handle);
+ atalk_encrypt_do(crypt_handle, rbuf, ibuf);
+ atalk_encrypt_end(crypt_handle);
memset(seskey, 0, sizeof(seskey));
*rbuflen = sizeof(randbuf);
return err;
/* use old passwd to decrypt new passwd */
- key_sched((C_Block *) seskey, seskeysched);
ibuf += PASSWDLEN; /* new passwd */
ibuf[PASSWDLEN] = '\0';
- ecb_encrypt( (C_Block *) ibuf, (C_Block *) ibuf, seskeysched, DES_DECRYPT);
+ err = atalk_decrypt(seskey, ibuf, ibuf);
+ if (err)
+ return err;
/* now use new passwd to decrypt old passwd */
- key_sched((C_Block *) ibuf, seskeysched);
ibuf -= PASSWDLEN; /* old passwd */
- ecb_encrypt((C_Block *) ibuf, (C_Block *) ibuf, seskeysched, DES_DECRYPT);
+ err = atalk_decrypt(ibuf, ibuf, ibuf);
+ if (err)
+ return err;
if (memcmp(seskey, ibuf, sizeof(seskey)))
err = AFPERR_NOTAUTH;
else if (memcmp(seskey, ibuf + PASSWDLEN, sizeof(seskey)) == 0)
err = randpass(pwd, passwdfile, ibuf + PASSWDLEN, sizeof(seskey), 1);
/* zero out some fields */
- memset(&seskeysched, 0, sizeof(seskeysched));
memset(seskey, 0, sizeof(seskey));
memset(ibuf, 0, sizeof(seskey)); /* old passwd */
memset(ibuf + PASSWDLEN, 0, sizeof(seskey)); /* new passwd */