diff options
Diffstat (limited to 'security/nss/lib/util/mac_rand.c')
-rw-r--r-- | security/nss/lib/util/mac_rand.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/security/nss/lib/util/mac_rand.c b/security/nss/lib/util/mac_rand.c index c8596a9f0..8578dfa08 100644 --- a/security/nss/lib/util/mac_rand.c +++ b/security/nss/lib/util/mac_rand.c @@ -44,6 +44,7 @@ #include <PPCToolbox.h> #include <Processes.h> #include <LowMem.h> +#include <Scrap.h> /* Static prototypes */ static size_t CopyLowBits(void *dst, size_t dstlen, void *src, size_t srclen); @@ -73,11 +74,12 @@ static size_t CopyLowBits(void *dst, size_t dstlen, void *src, size_t srclen) size_t RNG_GetNoise(void *buf, size_t maxbytes) { - uint32 c = TickCount(); - return CopyLowBits(buf, maxbytes, &c, sizeof(c)); + UnsignedWide microTickCount; + Microseconds(µTickCount); + return CopyLowBits(buf, maxbytes, µTickCount, sizeof(microTickCount)); } -void RNG_FileForRNG(char *filename) +void RNG_FileForRNG(const char *filename) { unsigned char buffer[BUFSIZ]; size_t bytes; @@ -125,6 +127,7 @@ void RNG_SystemInfoForRNG() ReadLocation(&loc); RNG_RandomUpdate( &loc, sizeof(loc)); } +#if !TARGET_CARBON /* User name */ { unsigned long userRef; @@ -133,6 +136,7 @@ void RNG_SystemInfoForRNG() RNG_RandomUpdate( &userRef, sizeof(userRef)); RNG_RandomUpdate( userName, sizeof(userName)); } +#endif /* Mouse location */ { Point mouseLoc; @@ -155,11 +159,13 @@ void RNG_SystemInfoForRNG() UInt8 volume = LMGetSdVolume(); RNG_RandomUpdate( &volume, sizeof(volume)); } +#if !TARGET_CARBON /* Current directory */ { SInt32 dir = LMGetCurDirStore(); RNG_RandomUpdate( &dir, sizeof(dir)); } +#endif /* Process information about all the processes in the machine */ { ProcessSerialNumber process; @@ -179,17 +185,21 @@ void RNG_SystemInfoForRNG() } } +#if !TARGET_CARBON /* Heap */ { THz zone = LMGetTheZone(); RNG_RandomUpdate( &zone, sizeof(zone)); } +#endif /* Screen */ { - GDHandle h = LMGetMainDevice(); /* GDHandle is **GDevice */ + GDHandle h = GetMainDevice(); /* GDHandle is **GDevice */ RNG_RandomUpdate( *h, sizeof(GDevice)); } + +#if !TARGET_CARBON /* Scrap size */ { SInt32 scrapSize = LMGetScrapSize(); @@ -200,6 +210,29 @@ void RNG_SystemInfoForRNG() SInt16 scrapCount = LMGetScrapCount(); RNG_RandomUpdate( &scrapCount, sizeof(scrapCount)); } +#else + { + ScrapRef scrap; + if (GetCurrentScrap(&scrap) == noErr) { + UInt32 flavorCount; + if (GetScrapFlavorCount(scrap, &flavorCount) == noErr) { + ScrapFlavorInfo* flavorInfo = (ScrapFlavorInfo*) malloc(flavorCount * sizeof(ScrapFlavorInfo)); + if (flavorInfo != NULL) { + if (GetScrapFlavorInfoList(scrap, &flavorCount, flavorInfo) == noErr) { + UInt32 i; + RNG_RandomUpdate(&flavorCount, sizeof(flavorCount)); + for (i = 0; i < flavorCount; ++i) { + Size flavorSize; + if (GetScrapFlavorSize(scrap, flavorInfo[i].flavorType, &flavorSize) == noErr) + RNG_RandomUpdate(&flavorSize, sizeof(flavorSize)); + } + } + free(flavorInfo); + } + } + } + } +#endif /* File stuff, last modified, etc. */ { HParamBlockRec pb; @@ -211,6 +244,7 @@ void RNG_SystemInfoForRNG() PBHGetVolParmsSync(&pb); RNG_RandomUpdate( &volInfo, sizeof(volInfo)); } +#if !TARGET_CARBON /* Event queue */ { EvQElPtr eventQ; @@ -219,6 +253,7 @@ void RNG_SystemInfoForRNG() eventQ = (EvQElPtr)eventQ->qLink) RNG_RandomUpdate( &eventQ->evtQWhat, sizeof(EventRecord)); } +#endif FE_ReadScreen(); RNG_FileForRNG(NULL); } |