]>
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. 
 109 #include <CrashReporterClient.h> 
 111 void CKRaise(const char *reason
) { 
 113         printf("CryptKit fatal error: %s\n", reason
); 
 116     if(asprintf(&msg
, "CryptKit fatal error: %s", reason
)) { 
 117         CRSetCrashLogMessage(msg
); 
 119         CRSetCrashLogMessage("CryptKit fatal error"); 
 124 /* for X, this isn't used except for testing when SecurityServer when 
 125  * Yarrow is not running. So let's strip it down so we don't have 
 126  * to link against CarbonCore.  
 128 #define BARE_BONES_SEED         1 
 131 #include <sys/types.h> 
 135 unsigned createRandomSeed() 
 141         thisPid 
= (unsigned)getpid(); 
 143         return (unsigned)curTime 
^ (unsigned)thisPid
; 
 146 #else   /* BARE_BONES_SEED */ 
 148 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/Timer.h> 
 149 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/LowMem.h> 
 151 // this is mighty pitiful anyway... 
 152 unsigned createRandomSeed() 
 154         UnsignedWide curTime
;            
 155         //unsigned ticks;                               /* use 16 bits */ 
 159         /* FIXME - need a way to distinguish OS9x from Carbon. Carbon 
 160          * doesn't have LMGetTicks(). */ 
 162         Microseconds(&curTime
);         /* low 16 bits are pretty good */ 
 165         // rtnHi = LMGetTicks(); 
 167         rtnLo 
= curTime
.lo 
& 0xffff; 
 168         return (rtnHi 
^ rtnLo
); 
 170 #endif  /* BARE_BONES_SEED */ 
 174 /* try for generic UNIX */ 
 176 void CKRaise(const char *reason
) { 
 178         printf("CryptKit fatal error: %s\n", reason
); 
 183 #include <sys/types.h> 
 188 unsigned createRandomSeed() 
 194         thisPid 
= (unsigned)getpid(); 
 196         return (unsigned)curTime 
^ (unsigned)thisPid
; 
 202 #error platform-specific work needed in security_cryptkit/platform.c