WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Remove code seeding RNG from /dev/urandom. The random mo

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Remove code seeding RNG from /dev/urandom. The random module's default RNG is
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 09 Oct 2005 11:16:11 +0000
Delivery-date: Sun, 09 Oct 2005 11:13:45 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@ewan
# Node ID 59440a003278185ad0846ac571da107a0c141b4c
# Parent  f15892b95965e1f7f2f636734c743c5919554cd7
Remove code seeding RNG from /dev/urandom.  The random module's default RNG is
already seeded from the clock, so this is unnecessary, non-portable, and
expensive.  This should improve start-up time of Xend.  Replace twisty maze of
code with something sensible.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r f15892b95965 -r 59440a003278 tools/python/xen/xend/uuid.py
--- a/tools/python/xen/xend/uuid.py     Sun Oct  9 10:53:34 2005
+++ b/tools/python/xen/xend/uuid.py     Sun Oct  9 10:57:24 2005
@@ -13,14 +13,19 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
 # Copyright (C) 2005 Mike Wray <mike.wray@xxxxxx>
+# Copyright (C) 2005 XenSource Ltd
 #============================================================================
+
 
 """Universal(ly) Unique Identifiers (UUIDs).
 """
+
+
 import commands
 import random
 
-def uuidgen(random=True):
+
+def getUuidUuidgen(random = True):
     """Generate a UUID using the command uuidgen.
 
     If random is true (default) generates a random uuid.
@@ -33,50 +38,21 @@
         cmd += " -t"
     return commands.getoutput(cmd)
 
-class UuidFactoryUuidgen:
 
-    """A uuid factory using uuidgen."""
+def getUuidRandom():
+    """Generate a random UUID."""
+    
+    bytes = [ random.randint(0, 255) for i in range(0, 16) ]
+    # Encode the variant.
+    bytes[6] = (bytes[6] & 0x0f) | 0x40
+    bytes[8] = (bytes[8] & 0x3f) | 0x80
+    f = "%02x"
+    return ( "-".join([f*4, f*2, f*2, f*2, f*6]) % tuple(bytes) )
 
-    def __init__(self):
-        pass
 
-    def getUuid(self):
-        return uuidgen()
+#uuidFactory = getUuidUuidgen
+uuidFactory = getUuidRandom
 
-class UuidFactoryRandom:
-
-    """A random uuid factory."""
-
-    def __init__(self):
-        f = file("/dev/urandom", "r")
-        seed = f.read(16)
-        f.close()
-        self.rand = random.Random(seed)
-
-    def randBytes(self, n):
-        return [ self.rand.randint(0, 255) for i in range(0, n) ]
-
-    def getUuid(self):
-        bytes = self.randBytes(16)
-        # Encode the variant.
-        bytes[6] = (bytes[6] & 0x0f) | 0x40
-        bytes[8] = (bytes[8] & 0x3f) | 0x80
-        f = "%02x"
-        return ( "-".join([f*4, f*2, f*2, f*2, f*6]) % tuple(bytes) )
-
-def getFactory():
-    """Get the factory to use for creating uuids.
-    This is so it's easy to change the uuid factory.
-    For example, for testing we might want repeatable uuids
-    rather than the random ones we normally use.
-    """
-    global uuidFactory
-    try:
-        uuidFactory
-    except:
-        #uuidFactory = UuidFactoryUuidgen()
-        uuidFactory = UuidFactoryRandom()
-    return uuidFactory
 
 def getUuid():
-    return getFactory().getUuid()
+    return uuidFactory()

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Remove code seeding RNG from /dev/urandom. The random module's default RNG is, Xen patchbot -unstable <=