From: Tom Yu Date: Mon, 21 Sep 1998 22:30:28 +0000 (+0000) Subject: resurrecting X-Git-Tag: krb5-1.1-beta1~534 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c74eb99b1d4b05ff2a98eb7585770731a1627c5f;p=krb5.git resurrecting git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10933 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/os/.Sanitize b/src/lib/crypto/os/.Sanitize new file mode 100644 index 000000000..2e24ee69f --- /dev/null +++ b/src/lib/crypto/os/.Sanitize @@ -0,0 +1,39 @@ +# Sanitize.in for Kerberos V5 + +# Each directory to survive it's way into a release will need a file +# like this one called "./.Sanitize". All keyword lines must exist, +# and must exist in the order specified by this file. Each directory +# in the tree will be processed, top down, in the following order. + +# Hash started lines like this one are comments and will be deleted +# before anything else is done. Blank lines will also be squashed +# out. + +# The lines between the "Do-first:" line and the "Things-to-keep:" +# line are executed as a /bin/sh shell script before anything else is +# done in this + +Do-first: + +# All files listed between the "Things-to-keep:" line and the +# "Files-to-sed:" line will be kept. All other files will be removed. +# Directories listed in this section will have their own Sanitize +# called. Directories not listed will be removed in their entirety +# with rm -rf. + +Things-to-keep: + +.cvsignore +ChangeLog +Makefile.in +configure +configure.in +c_localaddr.c +c_ustime.c +rnd_confoun.c + +Things-to-lose: + +Do-last: + +# End of file. diff --git a/src/lib/crypto/os/ChangeLog b/src/lib/crypto/os/ChangeLog new file mode 100644 index 000000000..ebcb593a1 --- /dev/null +++ b/src/lib/crypto/os/ChangeLog @@ -0,0 +1,204 @@ +Wed Feb 18 16:08:30 1998 Tom Yu + + * Makefile.in: Remove trailing slash from thisconfigdir. Fix up + BUILDTOP for new conventions. + +Fri Feb 13 15:20:54 1998 Theodore Ts'o + + * Makefile.in (thisconfigdir), configure.in: Point the + configuration directory at our parent, and remove our + local configure.in + +Mon Feb 2 17:02:29 1998 Theodore Ts'o + + * Makefile.in: Define BUILDTOP and thisconfigdir in the Makefile + +Fri Nov 28 21:23:42 1997 Tom Yu + + * configure.in: Add AC_PROG_LN_S to deal with symlinking in + memmove.c. This is a kludge, as we really should have a more sane + way to deal with missing posix functions. + +Thu Sep 25 21:53:11 1997 Tom Yu + + * c_localaddr.c: Replace KRB5_USE_INET with something more sane. + +Tue Aug 12 09:09:14 1997 Ezra Peisach + + * Makefile.in (SRCS): Add $(srcdir) as needed. + +Fri Jul 4 00:13:02 1997 Theodore Y. Ts'o + + * c_localaddr.c (local_addr_fallback_kludge): Added Winsock + kludge for finding your local IP address. May not work + for all stacks, so we use it as a fallback. + +Sat Feb 22 18:54:53 1997 Richard Basch + + * Makefile.in: Use some of the new library list build rules in + win-post.in + +Mon Feb 17 17:24:41 1997 Richard Basch + + * c_ustime.c: Fixed microsecond adjustment code (win32) + +Thu Nov 21 00:58:04 EST 1996 Richard Basch + + * Makefile.in: Win32 build + + * c_ustime.c: The Win32 time calculation is different from DOS' + so the DOS version shouldn't be trying to use the same + part of the ifdef. + + * rnd_confoun.c: Fix function declaration (win32) + +Sun Dec 29 21:54:42 1996 Tom Yu + + * Makefile.in: + * configure.in: Update to use new library building procedure. + +Wed Jun 12 00:12:52 1996 Theodore Ts'o + + * c_ustime.c: Fix WIN32 to be _WIN32 + + * c_localaddr.c: Add #ifdef _WIN32 in places where we had #ifdef _MSDOS + + +Sat Feb 24 00:34:15 1996 Theodore Y. Ts'o + + * c_ustime.c (krb5_crypto_us_timeofday): Add Windows 95/NT time + function. (Does this time function work under Windows? + We'll find out....) + +Thu Feb 15 10:57:27 1996 Ezra Peisach + + * c_localaddr.c: Set magic number in krb5_address. + +Fri Oct 6 22:00:48 1995 Theodore Y. Ts'o + + * Makefile.in: Remove ##DOS!include of config/windows.in. + config/windows.in is now included by wconfig. + +Mon Sep 25 16:49:15 1995 Theodore Y. Ts'o + + * Makefile.in: Removed "foo:: foo-$(WHAT)" lines from the + Makefile. + +Fri Sep 22 12:00:00 1995 James Mattly + + * c_localaddr.c: change close on a socket to closesocket, sockets on + macintosh arn't files + +Wed Sep 13 10:33:53 1995 Keith Vetter (keithv@fusion.com) + + * Makefile.in: PC builds all C files because of function name changes. + * c_localtime.c, c_ustime.c: removed INTERFACE keyword. + +Wed Sep 13 17:32:36 1995 Theodore Y. Ts'o + + * c_localaddr.c (krb5_crypto_os_localaddr): Clear the buffer + before calling the SIOCGIFCONF ioctl. This makes purify + happy. + +Thu Sep 7 12:00:00 1995 James Mattly + + * Renamed ustime.c to c_ustime.c + * Renamed localaddr.c to c_localaddr.c because Mac can't have + two files with the same name. + * Makefile.in, .Sanitize updated for the above change. + +Thu Aug 24 18:40:48 1995 Theodore Y. Ts'o + + * .Sanitize: Update file list + +Sat Jul 29 03:17:21 1995 Tom Yu + + * localaddr.c (krb5_crypto_os_localaddr): Don't bash the return + from SIOCGIFCONF with the output of a SIOCGIFFLAGS. Duh. + +Wed Jul 19 17:17:54 1995 Tom Yu + + * localaddr.c: also add definition of max if it's not there. + + * localaddr.c: fix definition of ifreq_size so it actually works + +Mon Jul 17 16:04:00 1995 Sam Hartman + + * localaddr.c (krb5_crypto_os_localaddr): Deal with variable sized + ifreq structures if sockaddr contains sa_len field. + + * configure.in: Check to see if struct sockaddr has sa_len. + +Thu Jul 6 17:13:11 1995 Tom Yu + + * localaddr.c: migrated from lib/krb5/os + + * ustime.c: migrated from lib/krb5/os; removed context variable + from arglist. + + * Makefile.in: don't copy or remove localaddr.c and ustime.c; + they're local now. + +Fri Jun 9 19:18:41 1995 + + * configure.in: Remove standardized set of autoconf macros, which + are now handled by CONFIG_RULES. + +Thu May 25 22:16:35 1995 Theodore Y. Ts'o (tytso@dcl) + + * configure.in, Makefile.in: Add support for shared libraries. + +Thu Apr 13 15:49:16 1995 Keith Vetter (keithv@fusion.com) + + * *.[ch]: removed unneeded INTERFACE from non-api functions. + +Sat Mar 25 15:38:23 1995 Mark Eichin + + * Makefile.in (memmove.c): memmove.c is in krb5/posix, not krb5/os. + +Wed Mar 22 11:44:07 1995 + + * Makefile.in: Use $(SRCTOP) instead of $(srcdir), since Mac's + don't like dealing with $(U)$(U). + +Fri Mar 17 16:21:46 1995 Theodore Y. Ts'o (tytso@dcl) + + * Makefile.in: Fix rules for localdr.c, ustime.c, and memmove.c so + that they reference $(srcdir) where appropriate. + +Thu Mar 16 21:24:43 1995 John Gilmore (gnu at toad.com) + + * Makefile.in (LDFLAGS): Eliminate, comes in from pre.in. + (all-mac): Add. + (localaddr.c, ustime.c, memmove.c): Fix paths to work on Mac. + +Tue Mar 14 17:23:02 1995 Keith Vetter (keithv@fusion.com) + + * Makefile.in: no longer need to bring in ustime and localaddr for + windows since everything's going into one DLL in the end. + +Thu Mar 2 17:56:48 1995 Keith Vetter (keithv@fusion.com) + + * Makefile.in: changed LIBNAME for the PC, and brought in ustime + and localaddr from the krb/os directory. + * rnd_conf.c: added cast to the seed assignment. + +Mon Feb 20 16:25:36 1995 Keith Vetter (keithv@fusion.com) + + * Makfile.in: made to work for the PC + * rnd_confoun.c: added windows INTERFACE keyword + +Wed Jan 25 20:24:35 1995 John Gilmore (gnu at toad.com) + + * rnd_confoun.c: Replace <.../...> includes with "..."s. + +Mon Oct 24 14:58:14 1994 (tytso@rsx-11) + + * configure.in: + * rnd_confoun.c (krb5_random_confounder): Use the srand48/lrand48 + functions if available. + +Fri Oct 14 00:21:05 1994 Theodore Y. Ts'o (tytso@dcl) + + * Makefile.in: Remove symlinked files on make clean. + diff --git a/src/lib/crypto/os/c_localaddr.c b/src/lib/crypto/os/c_localaddr.c new file mode 100644 index 000000000..3b3bcb474 --- /dev/null +++ b/src/lib/crypto/os/c_localaddr.c @@ -0,0 +1,348 @@ +/* + * lib/crypto/os/c_localaddr.c + * + * Copyright 1990,1991 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * Return the protocol addresses supported by this host. + * + * XNS support is untested, but "Should just work". + */ + + +#define NEED_SOCKETS +#include "k5-int.h" + +#if !defined(HAVE_MACSOCK_H) && !defined(_MSDOS) && !defined(_WIN32) + +/* needed for solaris, harmless elsewhere... */ +#define BSD_COMP +#include +#include +#include + +/* + * The SIOCGIF* ioctls require a socket. + * It doesn't matter *what* kind of socket they use, but it has to be + * a socket. + * + * Of course, you can't just ask the kernel for a socket of arbitrary + * type; you have to ask for one with a valid type. + * + */ +#ifdef HAVE_NETINET_IN_H + +#include + +#ifndef USE_AF +#define USE_AF AF_INET +#define USE_TYPE SOCK_DGRAM +#define USE_PROTO 0 +#endif + +#endif + +#ifdef KRB5_USE_NS + +#include + +#ifndef USE_AF +#define USE_AF AF_NS +#define USE_TYPE SOCK_DGRAM +#define USE_PROTO 0 /* guess */ +#endif + +#endif +/* + * Add more address families here. + */ + +/* + * BSD 4.4 defines the size of an ifreq to be + * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len + * However, under earlier systems, sa_len isn't present, so the size is + * just sizeof(struct ifreq) + */ +#ifdef HAVE_SA_LEN +#ifndef max +#define max(a,b) ((a) > (b) ? (a) : (b)) +#endif +#define ifreq_size(i) max(sizeof(struct ifreq),\ + sizeof((i).ifr_name)+(i).ifr_addr.sa_len) +#else +#define ifreq_size(i) sizeof(struct ifreq) +#endif /* HAVE_SA_LEN*/ + + + +extern int errno; + +/* + * Return all the protocol addresses of this host. + * + * We could kludge up something to return all addresses, assuming that + * they're valid kerberos protocol addresses, but we wouldn't know the + * real size of the sockaddr or know which part of it was actually the + * host part. + * + * This uses the SIOCGIFCONF, SIOCGIFFLAGS, and SIOCGIFADDR ioctl's. + */ + +krb5_error_code +krb5_crypto_os_localaddr(addr) + krb5_address ***addr; +{ + struct ifreq *ifr, ifreq; + struct ifconf ifc; + int s, code, n, i; + char buf[1024]; + krb5_address *addr_temp [ 1024/sizeof(struct ifreq) ]; + int n_found; + int mem_err = 0; + + memset(buf, 0, sizeof(buf)); + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + + s = socket (USE_AF, USE_TYPE, USE_PROTO); + if (s < 0) + return errno; + + code = ioctl (s, SIOCGIFCONF, (char *)&ifc); + if (code < 0) { + int retval = errno; + closesocket (s); + return retval; + } + n = ifc.ifc_len; + +n_found = 0; + for (i = 0; i < n; i+= ifreq_size(*ifr) ) { + krb5_address *address; + ifr = (struct ifreq *)((caddr_t) ifc.ifc_buf+i); + + strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof (ifreq.ifr_name)); + if (ioctl (s, SIOCGIFFLAGS, (char *)&ifreq) < 0) + continue; + +#ifdef IFF_LOOPBACK + if (ifreq.ifr_flags & IFF_LOOPBACK) + continue; +#endif + + if (!(ifreq.ifr_flags & IFF_UP)) + /* interface is down; skip */ + continue; + + /* ifr->ifr_addr has what we want! */ + switch (ifr->ifr_addr.sa_family) { +#ifdef HAVE_NETINET_IN_H + case AF_INET: + { + struct sockaddr_in *in = + (struct sockaddr_in *)&ifr->ifr_addr; + + address = (krb5_address *) + malloc (sizeof(krb5_address)); + if (address) { + address->magic = KV5M_ADDRESS; + address->addrtype = ADDRTYPE_INET; + address->length = sizeof(struct in_addr); + address->contents = (unsigned char *)malloc(address->length); + if (!address->contents) { + krb5_xfree(address); + address = 0; + mem_err++; + } else { + memcpy ((char *)address->contents, + (char *)&in->sin_addr, + address->length); + break; + } + } else mem_err++; + } +#endif +#ifdef KRB5_USE_NS + case AF_XNS: + { + struct sockaddr_ns *ns = + (struct sockaddr_ns *)&ifr->ifr_addr; + address = (krb5_address *) + malloc (sizeof (krb5_address) + sizeof (struct ns_addr)); + if (address) { + address->magic = KV5M_ADDRESS; + address->addrtype = ADDRTYPE_XNS; + + /* XXX should we perhaps use ns_host instead? */ + + address->length = sizeof(struct ns_addr); + address->contents = (unsigned char *)malloc(address->length); + if (!address->contents) { + krb5_xfree(address); + address = 0; + mem_err++; + } else { + memcpy ((char *)address->contents, + (char *)&ns->sns_addr, + address->length); + break; + } + } else mem_err++; + break; + } +#endif + /* + * Add more address families here.. + */ + default: + continue; + } + if (address) + addr_temp[n_found++] = address; + address = 0; + } + closesocket(s); + + *addr = (krb5_address **)malloc (sizeof (krb5_address *) * (n_found+1)); + if (*addr == 0) + mem_err++; + + if (mem_err) { + for (i=0; imagic = KV5M_ADDRESS; + (*addr)[0]->addrtype = hostrec->h_addrtype; + (*addr)[0]->length = hostrec->h_length; + (*addr)[0]->contents = (unsigned char *)malloc((*addr)[0]->length); + if (!(*addr)[0]->contents) { + free((*addr)[0]); + free(*addr); + return ENOMEM; + } else { + memcpy ((*addr)[0]->contents, + hostrec->h_addr, + (*addr)[0]->length); + } + /* FIXME, deal with the case where gethostent returns multiple addrs */ + + return(0); +} +#endif diff --git a/src/lib/crypto/os/c_ustime.c b/src/lib/crypto/os/c_ustime.c new file mode 100644 index 000000000..e790acc95 --- /dev/null +++ b/src/lib/crypto/os/c_ustime.c @@ -0,0 +1,316 @@ +/* + * lib/crypto/os/c_ustime.c + * + * Copyright 1990,1991 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * krb5_mstimeofday for BSD 4.3 + */ + +#define NEED_SOCKETS +#include "k5-int.h" + +#ifdef macintosh + +/* We're a Macintosh -- do Mac time things. */ + +/* + * This code is derived from kerberos/src/lib/des/mac_time.c from + * the Cygnus Support release of Kerberos V4: + * + * mac_time.c + * (Originally time_stuff.c) + * Copyright 1989 by the Massachusetts Institute of Technology. + * Macintosh ooperating system interface for Kerberos. + */ + +#include "AddressXlation.h" /* for ip_addr, for #if 0'd net-time stuff */ + +#include /* Defines MachineLocation, used by getTimeZoneOffset */ +#include /* Defines BitTst(), called by getTimeZoneOffset() */ +#include /* Defines GetDateTime */ + +/* Mac Cincludes */ +#include +#include + +static krb5_int32 last_sec = 0, last_usec = 0; + +/* + * The Unix epoch is 1/1/70, the Mac epoch is 1/1/04. + * + * 70 - 4 = 66 year differential + * + * Thus the offset is: + * + * (66 yrs) * (365 days/yr) * (24 hours/day) * (60 mins/hour) * (60 secs/min) + * plus + * (17 leap days) * (24 hours/day) * (60 mins/hour) * (60 secs/min) + * + * Don't forget the offset from GMT. + */ + +/* returns the offset in hours between the mac local time and the GMT */ +/* unsigned krb5_int32 */ +krb5_int32 +getTimeZoneOffset() +{ + MachineLocation macLocation; + long gmtDelta; + + macLocation.u.gmtDelta=0L; + ReadLocation(&macLocation); + gmtDelta=macLocation.u.gmtDelta & 0x00FFFFFF; + if (BitTst((void *)&gmtDelta,23L)) + gmtDelta |= 0xFF000000; + gmtDelta /= 3600L; + return(gmtDelta); +} + +/* Returns the GMT in seconds (and fake microseconds) using the Unix epoch */ + +krb5_error_code +krb5_crypto_us_timeofday(seconds, microseconds) + krb5_int32 *seconds, *microseconds; +{ + krb5_int32 sec, usec; + time_t the_time; + + GetDateTime (&the_time); + + sec = the_time - + ((66 * 365 * 24 * 60 * 60) + (17 * 24 * 60 * 60) + + (getTimeZoneOffset() * 60 * 60)); + + usec = 0; /* Mac is too slow to count faster than once a second */ + + if ((sec == last_sec) && (usec == last_usec)) { + if (++last_usec >= 1000000) { + last_usec = 0; + last_sec++; + } + sec = last_sec; + usec = last_usec; + } + else { + last_sec = sec; + last_usec = usec; + } + + *seconds = sec; + *microseconds = usec; + + return 0; +} + + +#elif defined(_WIN32) + + /* Microsoft Windows NT and 95 (32bit) */ + /* This one works for WOW (Windows on Windows, ntvdm on Win-NT) */ + +#include +#include +#include + +krb5_error_code +krb5_crypto_us_timeofday(seconds, microseconds) +register krb5_int32 *seconds, *microseconds; +{ + struct _timeb timeptr; + krb5_int32 sec, usec; + static krb5_int32 last_sec = 0; + static krb5_int32 last_usec = 0; + + _ftime(&timeptr); /* Get the current time */ + sec = timeptr.time; + usec = timeptr.millitm * 1000; + + if ((sec == last_sec) && (usec <= last_usec)) { /* Same as last time??? */ + usec = ++last_usec; + if (usec >= 1000000) { + ++sec; + usec = 0; + } + } + last_sec = sec; /* Remember for next time */ + last_usec = usec; + + *seconds = sec; /* Return the values */ + *microseconds = usec; + + return 0; +} + +#elif defined (_MSDOS) + + +/* + * Originally written by John Gilmore, Cygnus Support, May '94. + * Public Domain. + */ + +#include +#include +#include +#include + +/* + * Time handling. Translate Unix time calls into Kerberos internal + * procedure calls. + * + * Due to the fact that DOS time can be unreliable we have reverted + * to using the AT hardware clock and converting it to Unix time. + */ + +static time_t win_gettime (); +static long win_time_get_epoch(); /* Adjust for MSC 7.00 bug */ + +krb5_error_code +krb5_crypto_us_timeofday(seconds, microseconds) +register krb5_int32 *seconds, *microseconds; +{ + krb5_int32 sec, usec; + static krb5_int32 last_sec = 0; + static krb5_int32 last_usec = 0; + + sec = win_gettime (); /* Get the current time */ + usec = 0; /* Can't do microseconds */ + + if (sec == last_sec) { /* Same as last time??? */ + usec = ++last_usec; /* Yep, so do microseconds */ + if (usec >= 1000000) { + ++sec; + usec = 0; + } + } + last_sec = sec; /* Remember for next time */ + last_usec = usec; + + *seconds = sec; /* Return the values */ + *microseconds = usec; + + return 0; +} + + +static time_t +win_gettime () { + struct tm tm; + union _REGS inregs; /* For calling BIOS */ + union _REGS outregs; + struct _timeb now; + time_t time; + long convert; /* MSC 7.00 bug work around */ + + _ftime(&now); /* Daylight savings time */ + + /* Get time from AT hardware clock INT 0x1A, AH=2 */ + memset(&inregs, 0, sizeof(inregs)); + inregs.h.ah = 2; + _int86(0x1a, &inregs, &outregs); + + /* 0x13 = decimal 13, hence the decoding below */ + tm.tm_sec = 10 * ((outregs.h.dh & 0xF0) >> 4) + (outregs.h.dh & 0x0F); + tm.tm_min = 10 * ((outregs.h.cl & 0xF0) >> 4) + (outregs.h.cl & 0x0F); + tm.tm_hour = 10 * ((outregs.h.ch & 0xF0) >> 4) + (outregs.h.ch & 0x0F); + + /* Get date from AT hardware clock INT 0x1A, AH=4 */ + memset(&inregs, 0, sizeof(inregs)); + inregs.h.ah = 4; + _int86(0x1a, &inregs, &outregs); + + tm.tm_mday = 10 * ((outregs.h.dl & 0xF0) >> 4) + (outregs.h.dl & 0x0F); + tm.tm_mon = 10 * ((outregs.h.dh & 0xF0) >> 4) + (outregs.h.dh & 0x0F) - 1; + tm.tm_year = 10 * ((outregs.h.cl & 0xF0) >> 4) + (outregs.h.cl & 0x0F); + tm.tm_year += 100 * ((10 * (outregs.h.ch & 0xF0) >> 4) + + (outregs.h.ch & 0x0F) - 19); + + tm.tm_wday = 0; + tm.tm_yday = 0; + tm.tm_isdst = now.dstflag; + + time = mktime(&tm); + + convert = win_time_get_epoch(); + return time + convert; + +} + + +/* + * This routine figures out the current time epoch and returns the + * conversion factor. It exists because + * Microloss screwed the pooch on the time() and _ftime() calls in + * its release 7.0 libraries. They changed the epoch to Dec 31, 1899! + * Idiots... We try to cope. + */ + +static struct tm jan_1_70 = {0, 0, 0, 1, 0, 70}; +static long epoch = 0; +static int epoch_set = 0; + +long +win_time_get_epoch() +{ + + if (!epoch_set) { + epoch = 0 - mktime (&jan_1_70); /* Seconds til 1970 localtime */ + epoch += _timezone; /* Seconds til 1970 GMT */ + epoch_set = 1; + } + return epoch; +} + + +#else + + +/* We're a Unix machine -- do Unix time things. */ + +extern int errno; + +static struct timeval last_tv = {0, 0}; + +krb5_error_code +krb5_crypto_us_timeofday(seconds, microseconds) + register krb5_int32 *seconds, *microseconds; +{ + struct timeval tv; + + if (gettimeofday(&tv, (struct timezone *)0) == -1) { + /* failed, return errno */ + return (krb5_error_code) errno; + } + if ((tv.tv_sec == last_tv.tv_sec) && (tv.tv_usec == last_tv.tv_usec)) { + if (++last_tv.tv_usec >= 1000000) { + last_tv.tv_usec = 0; + last_tv.tv_sec++; + } + tv = last_tv; + } else + last_tv = tv; + + *seconds = tv.tv_sec; + *microseconds = tv.tv_usec; + return 0; +} + +#endif diff --git a/src/lib/crypto/os/rnd_confoun.c b/src/lib/crypto/os/rnd_confoun.c new file mode 100644 index 000000000..e904cb5c7 --- /dev/null +++ b/src/lib/crypto/os/rnd_confoun.c @@ -0,0 +1,98 @@ +/* + * lib/crypto/os/rnd_confoun.c + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * krb5_random_confounder() + */ + +#include "k5-int.h" + +#ifdef HAVE_SYS_TIME_H +#include +#ifdef TIME_WITH_SYS_TIME +#include +#endif +#else +#include +#endif + +#ifdef HAVE_SRAND48 +#define SRAND srand48 +#define RAND lrand48 +#define RAND_TYPE long +#endif + +#if !defined(RAND_TYPE) && defined(HAVE_SRAND) +#define SRAND srand +#define RAND rand +#define RAND_TYPE int +#endif + +#if !defined(RAND_TYPE) && defined(HAVE_SRANDOM) +#define SRAND srandom +#define RAND random +#define RAND_TYPE long +#endif + +#if !defined(RAND_TYPE) +You need a random number generator! +#endif + +/* + * Generate a random confounder + */ +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_random_confounder(size, fillin) +size_t size; +krb5_pointer fillin; +{ + static int seeded = 0; + register krb5_octet *real_fill; + RAND_TYPE rval; + + if (!seeded) { + /* time() defined in 4.12.2.4, but returns a time_t, which is an + "arithmetic type" (4.12.1) */ + rval = (RAND_TYPE) time(0); + SRAND(rval); +#ifdef HAVE_GETPID + rval = RAND(); + rval ^= getpid(); + SRAND(rval); +#endif + seeded = 1; + } + + real_fill = (krb5_octet *)fillin; + while (size > 0) { + rval = RAND(); + *real_fill = rval & 0xff; + real_fill++; + size--; + if (size) { + *real_fill = (rval >> 8) & 0xff; + real_fill++; + size--; + } + } + return 0; +}