Bug 75049 - Enable NSS for carbon build. patch from beard, r=mcgreer, sr=nelsonb, a=asa. NSS_3_2_BRANCH
authorbryner%uiuc.edu
Thu, 28 Jun 2001 03:12:36 +0000
branchNSS_3_2_BRANCH
changeset 1694 67db43116c2aa33d001c2af29b4016280a50d6a4
parent 1689 d1994a8e37f2bcc1512b8740e071e1a9b69521c1
child 1695 f09d27d3feeeb5c14b82eac06acaa7ef58b39186
child 1744 0f2aa6bf753d07926e7b1bd23a313fa6ac0b531e
push idunknown
push userunknown
push dateunknown
reviewersmcgreer, nelsonb, asa
bugs75049
Bug 75049 - Enable NSS for carbon build. patch from beard, r=mcgreer, sr=nelsonb, a=asa.
security/nss/lib/util/mac_rand.c
--- a/security/nss/lib/util/mac_rand.c
+++ b/security/nss/lib/util/mac_rand.c
@@ -39,16 +39,17 @@
 #include "mcom_db.h"
 #ifdef XP_MAC
 #include <Events.h>
 #include <OSUtils.h>
 #include <QDOffscreen.h>
 #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);
 void FE_ReadScreen();
 
 static size_t CopyLowBits(void *dst, size_t dstlen, void *src, size_t srclen)
 {
     union endianness {
@@ -68,18 +69,19 @@ static size_t CopyLowBits(void *dst, siz
         /* little-endian case */
         memcpy(dst, src, dstlen);
     }
     return dstlen;
 }
 
 size_t RNG_GetNoise(void *buf, size_t maxbytes)
 {
-    uint32 c = TickCount();
-    return CopyLowBits(buf, maxbytes,  &c, sizeof(c));
+    UnsignedWide microTickCount;
+    Microseconds(&microTickCount);
+    return CopyLowBits(buf, maxbytes,  &microTickCount, sizeof(microTickCount));
 }
 
 void RNG_FileForRNG(char *filename)
 {   
     unsigned char buffer[BUFSIZ];
     size_t bytes;
 #ifdef notdef /*sigh*/
     XP_File file;
@@ -120,24 +122,26 @@ void RNG_SystemInfoForRNG()
 	    RNG_RandomUpdate(&sec, bytes);
     }
 /* User specific variables */
 	{
 		MachineLocation loc;
 		ReadLocation(&loc);
 		RNG_RandomUpdate( &loc, sizeof(loc));
 	}
+#if !TARGET_CARBON
 /* User name */
 	{
 		unsigned long userRef;
 		Str32 userName;
 		GetDefaultUser(&userRef, userName);
 		RNG_RandomUpdate( &userRef, sizeof(userRef));
 		RNG_RandomUpdate( userName, sizeof(userName));
 	}
+#endif
 /* Mouse location */
 	{
 		Point mouseLoc;
 		GetMouse(&mouseLoc);
 		RNG_RandomUpdate( &mouseLoc, sizeof(mouseLoc));
 	}
 /* Keyboard time threshold */
 	{
@@ -150,21 +154,23 @@ void RNG_SystemInfoForRNG()
 		keyLast = LMGetKbdLast();
 		RNG_RandomUpdate( &keyLast, sizeof(keyLast));
 	}
 /* Volume */
 	{
 		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;
 		ProcessInfoRec pi;
 	
 		process.highLongOfPSN = process.lowLongOfPSN  = kNoProcess;
 		
 		while (GetNextProcess(&process) == noErr)
@@ -174,56 +180,85 @@ void RNG_SystemInfoForRNG()
 			pi.processName = NULL;
 			pi.processAppSpec = &fileSpec;
 			GetProcessInformation(&process, &pi);
 			RNG_RandomUpdate( &pi, sizeof(pi));
 			RNG_RandomUpdate( &fileSpec, sizeof(fileSpec));
 		}
 	}
 	
+#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();
 		RNG_RandomUpdate( &scrapSize, sizeof(scrapSize));
 	}
 /* Scrap count */
 	{
 		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;
 		GetVolParmsInfoBuffer	volInfo;
 		pb.ioParam.ioVRefNum = 0;
 		pb.ioParam.ioNamePtr = nil;
 		pb.ioParam.ioBuffer = (Ptr) &volInfo;
 		pb.ioParam.ioReqCount = sizeof(volInfo);
 		PBHGetVolParmsSync(&pb);
 		RNG_RandomUpdate( &volInfo, sizeof(volInfo));
 	}
+#if !TARGET_CARBON
 /* Event queue */
 	{
 		EvQElPtr		eventQ;
 		for (eventQ = (EvQElPtr) LMGetEventQueue()->qHead; 
 				eventQ; 
 				eventQ = (EvQElPtr)eventQ->qLink)
 			RNG_RandomUpdate( &eventQ->evtQWhat, sizeof(EventRecord));
 	}
+#endif
 	FE_ReadScreen();
 	RNG_FileForRNG(NULL);
 }
 
 void FE_ReadScreen()
 {
 	UInt16				coords[4];
 	PixMapHandle 		pmap;