]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/platform.c
1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
11 * platform.c - platform-dependent C functions
27 void CKRaise(const char *reason
) {
29 printf("CryptKit fatal error: %s\n", reason
);
36 #if !defined(NeXT_PDO) && FEE_DEBUG
39 * Mach, private build. use quick microsecond-accurate system clock.
42 #include <kern/time_stamp.h>
44 unsigned createRandomSeed()
48 (void)kern_timestamp(&tsp
);
55 * OpenStep, normal case.
57 #include <sys/types.h>
62 unsigned createRandomSeed(void)
68 thisPid
= (unsigned)getpid();
70 return (unsigned)curTime
^ (unsigned)thisPid
;
73 #endif /* FEE_DEBUG */
78 * OpenStep on Windows.
80 #include <process.h> /* for _getpid() */
82 void CKRaise(const char *reason
) {
84 printf("CryptKit fatal error: %s\n", reason
);
89 extern void time(unsigned *tp
);
91 unsigned createRandomSeed()
98 return (unsigned)curTime
^ (unsigned)thisPid
;
105 * Macintosh, all flavors.
110 void CKRaise(const char *reason
) {
112 printf("CryptKit fatal error: %s\n", reason
);
117 /* for X, this isn't used except for testing when SecurityServer when
118 * Yarrow is not running. So let's strip it down so we don't have
119 * to link against CarbonCore.
121 #define BARE_BONES_SEED 1
124 #include <sys/types.h>
128 unsigned createRandomSeed()
134 thisPid
= (unsigned)getpid();
136 return (unsigned)curTime
^ (unsigned)thisPid
;
139 #else /* BARE_BONES_SEED */
141 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/Timer.h>
142 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/LowMem.h>
144 // this is mighty pitiful anyway...
145 unsigned createRandomSeed()
147 UnsignedWide curTime
;
148 //unsigned ticks; /* use 16 bits */
152 /* FIXME - need a way to distinguish OS9x from Carbon. Carbon
153 * doesn't have LMGetTicks(). */
155 Microseconds(&curTime
); /* low 16 bits are pretty good */
158 // rtnHi = LMGetTicks();
160 rtnLo
= curTime
.lo
& 0xffff;
161 return (rtnHi
^ rtnLo
);
163 #endif /* BARE_BONES_SEED */
167 /* try for generic UNIX */
169 void CKRaise(const char *reason
) {
171 printf("CryptKit fatal error: %s\n", reason
);
176 #include <sys/types.h>
181 unsigned createRandomSeed()
187 thisPid
= (unsigned)getpid();
189 return (unsigned)curTime
^ (unsigned)thisPid
;
195 #error platform-specific work needed in security_cryptkit/platform.c