static char *crypt_md5_wrapper(const char *pass_new) { /* * Code lifted from Marek Michalkiewicz's shadow suite. (CG) * removed use of static variables (AGM) */ struct timeval tv; MD5_CTX ctx; unsigned char result[16]; char *cp = (char *) result; unsigned char tmp[16]; int i; char *x = NULL; GoodMD5Init(&ctx); gettimeofday(&tv, (struct timezone *) 0); GoodMD5Update(&ctx, (void *) &tv, sizeof tv); i = getpid(); GoodMD5Update(&ctx, (void *) &i, sizeof i); i = clock(); GoodMD5Update(&ctx, (void *) &i, sizeof i); GoodMD5Update(&ctx, result, sizeof result); GoodMD5Final(tmp, &ctx); strcpy(cp, "$1$"); /* magic for the MD5 */ cp += strlen(cp); for (i = 0; i < 8; i++) *cp++ = i64c(tmp[i] & 077); *cp = '\0'; /* no longer need cleartext */ x = Goodcrypt_md5(pass_new, (const char *) result); return x; }
/* <where> must point to a buffer of at least <length>+1 length */ static void crypt_make_salt(char *where, int length) { struct timeval tv; MD5_CTX ctx; unsigned char tmp[16]; unsigned char *src = (unsigned char *)where; int i; #ifdef PAM_PATH_RANDOMDEV int fd; int rv; if ((rv = fd = open(PAM_PATH_RANDOMDEV, O_RDONLY)) != -1) { while ((rv = read(fd, where, length)) != length && errno == EINTR); close (fd); } if (rv != length) { #endif /* * Code lifted from Marek Michalkiewicz's shadow suite. (CG) * removed use of static variables (AGM) * * will work correctly only for length <= 16 */ src = tmp; GoodMD5Init(&ctx); gettimeofday(&tv, (struct timezone *) 0); GoodMD5Update(&ctx, (void *) &tv, sizeof tv); i = getpid(); GoodMD5Update(&ctx, (void *) &i, sizeof i); i = clock(); GoodMD5Update(&ctx, (void *) &i, sizeof i); GoodMD5Update(&ctx, src, length); GoodMD5Final(tmp, &ctx); #ifdef PAM_PATH_RANDOMDEV } #endif for (i = 0; i < length; i++) *where++ = i64c(src[i] & 077); *where = '\0'; }