X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/Security/libsecurity_cryptkit/lib/platform.c diff --git a/Security/libsecurity_cryptkit/lib/platform.c b/Security/libsecurity_cryptkit/lib/platform.c new file mode 100644 index 00000000..fa6c1b2e --- /dev/null +++ b/Security/libsecurity_cryptkit/lib/platform.c @@ -0,0 +1,197 @@ +/* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved. + * + * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT + * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE + * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE + * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE, + * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL + * EXPOSE YOU TO LIABILITY. + *************************************************************************** + * + * platform.c - platform-dependent C functions + * + * Revision History + * ---------------- + * 6 Sep 96 at NeXT + * Created. + */ + +#include "platform.h" +#include +#include "feeDebug.h" +#ifdef NeXT + +/* + * OpenStep.... + */ +void CKRaise(const char *reason) { + #if FEE_DEBUG + printf("CryptKit fatal error: %s\n", reason); + #endif + exit(1); +} + +#import "feeDebug.h" + +#if !defined(NeXT_PDO) && FEE_DEBUG + +/* + * Mach, private build. use quick microsecond-accurate system clock. + */ + +#include + +unsigned createRandomSeed() +{ + struct tsval tsp; + + (void)kern_timestamp(&tsp); + return tsp.low_val; +} + +#else + +/* + * OpenStep, normal case. + */ +#include +#include + +extern int getpid(); + +unsigned createRandomSeed(void) +{ + time_t curTime; + unsigned thisPid; + + time(&curTime); + thisPid = (unsigned)getpid(); + + return (unsigned)curTime ^ (unsigned)thisPid; +} + +#endif /* FEE_DEBUG */ + +#elif WIN32 + +/* + * OpenStep on Windows. + */ +#include /* for _getpid() */ + +void CKRaise(const char *reason) { + #if FEE_DEBUG + printf("CryptKit fatal error: %s\n", reason); + #endif + exit(1); +} + +extern void time(unsigned *tp); + +unsigned createRandomSeed() +{ + unsigned curTime; + unsigned thisPid; + + time(&curTime); + thisPid = _getpid(); + return (unsigned)curTime ^ (unsigned)thisPid; +} + + +#elif __MAC_BUILD__ + +/* + * Macintosh, all flavors. + */ +#include +#include + +void CKRaise(const char *reason) { + #if FEE_DEBUG + printf("CryptKit fatal error: %s\n", reason); + #endif + exit(1); +} + +/* for X, this isn't used except for testing when SecurityServer when + * Yarrow is not running. So let's strip it down so we don't have + * to link against CarbonCore. + */ +#define BARE_BONES_SEED 1 +#if BARE_BONES_SEED + +#include + +extern int getpid(); + +unsigned createRandomSeed() +{ + time_t curTime; + unsigned thisPid; + + time(&curTime); + thisPid = (unsigned)getpid(); + + return (unsigned)curTime ^ (unsigned)thisPid; +} + +#else /* BARE_BONES_SEED */ + +#include +#include + +// this is mighty pitiful anyway... +unsigned createRandomSeed() +{ + UnsignedWide curTime; + //unsigned ticks; /* use 16 bits */ + unsigned rtnHi; + unsigned rtnLo; + + /* FIXME - need a way to distinguish OS9x from Carbon. Carbon + * doesn't have LMGetTicks(). */ + + Microseconds(&curTime); /* low 16 bits are pretty good */ + + // Carbon hack + // rtnHi = LMGetTicks(); + rtnHi = 0x5a5aa5a5; + rtnLo = curTime.lo & 0xffff; + return (rtnHi ^ rtnLo); +} +#endif /* BARE_BONES_SEED */ + +#elif unix + +/* try for generic UNIX */ + +void CKRaise(const char *reason) { + #if FEE_DEBUG + printf("CryptKit fatal error: %s\n", reason); + #endif + exit(1); +} + +#include +#include + +extern int getpid(); + +unsigned createRandomSeed() +{ + time_t curTime; + unsigned thisPid; + + time(&curTime); + thisPid = (unsigned)getpid(); + + return (unsigned)curTime ^ (unsigned)thisPid; +} + + +#else + +#error platform-specific work needed in security_cryptkit/platform.c + +#endif