Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue25515

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Always use os.urandom for generating uuid4s
Type:Stage:resolved
Components:Library (Lib)Versions:Python 3.6, Python 3.5, Python 2.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: alex, barry, dstufft, jayvdb, python-dev
Priority:normalKeywords:needs review, patch

Created on2015-10-29 22:30 byalex, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
uuid.diffalex,2015-10-29 22:30review
Messages (5)
msg253697 -(view)Author: Alex Gaynor (alex)*(Python committer)Date: 2015-10-29 22:30
Right now uuid4 can be implemented one of 3 ways:- If there's a libuuid (and it's not OS X's) it uses that.- Fallback to os.urandom- If that raises an exception, fall back to the random moduleI propose to simplify this to _just_ use os.urandom always. Reasons:- Its security properties are more obviously correct. (There's a large comment in uuid.py about how libuuid doees the wrong thing with fork on OS X, who knows if it's correct on other platforms)- It's simpler.- It's faster:a_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10.3 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 9.99 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10.2 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10.2 usec per loopa_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.94 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.92 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.97 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.93 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.94 usec per loopa_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$ python --versionPython 2.7.3
msg253698 -(view)Author: Alex Gaynor (alex)*(Python committer)Date: 2015-10-29 22:31
(Note that the speed difference would be even bigger on a recent python, 2.7.3 was before the file descriptor was cached for os.urandom)
msg253699 -(view)Author: Barry A. Warsaw (barry)*(Python committer)Date: 2015-10-29 22:58
On Oct 29, 2015, at 10:30 PM, Alex Gaynor wrote:>Right now uuid4 can be implemented one of 3 ways:If you're hacking on the uuid module, keep in mindissue22807
msg253707 -(view)Author: Donald Stufft (dstufft)*(Python committer)Date: 2015-10-30 01:57
This looks like a good idea to me, faster and more secure seems like a total win.
msg253713 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2015-10-30 03:40
New changeset24bdc4940e81 by Benjamin Peterson in branch '2.7':always use os.urandom for the uuid4 algorithm (closes#25515)https://hg.python.org/cpython/rev/24bdc4940e81New changeset70be1f9c9255 by Benjamin Peterson in branch '3.5':always use os.urandom for the uuid4 algorithm (closes#25515)https://hg.python.org/cpython/rev/70be1f9c9255New changeset756d040aa8e8 by Benjamin Peterson in branch 'default':merge 3.5 (#25515)https://hg.python.org/cpython/rev/756d040aa8e8
History
DateUserActionArgs
2022-04-11 14:58:23adminsetgithub: 69701
2015-10-30 03:40:45python-devsetstatus: open -> closed

nosy: +python-dev
messages: +msg253713

resolution: fixed
stage: resolved
2015-10-30 01:57:45dstufftsetmessages: +msg253707
2015-10-29 22:58:35barrysetnosy: +barry
messages: +msg253699
2015-10-29 22:33:04jayvdbsetnosy: +jayvdb
2015-10-29 22:31:26alexsetmessages: +msg253698
2015-10-29 22:30:56alexcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp