Changeset 78149 in webkit


Ignore:
Timestamp:
Feb 9, 2011 3:11:56 PM (13 years ago)
Author:
abarth@webkit.org
Message:

2011-02-09 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

Add WTF::cryptographicallyRandomNumber
https://bugs.webkit.org/show_bug.cgi?id=54083

Introduce a cryptographically strong random number generator to WTF.
The random number generator is based on arc4random as found in:

http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/crypt/arc4random.c?rev=1.22

I've changed to source to WebKit style and abstracted the operating
system interaction to OSRandomSource. We'll use this functionality to
expose a cryptographically strong random number generator to
JavaScript.

  • Android.mk:
  • Android.v8.wtf.mk:
  • GNUmakefile.am:
  • JavaScriptCore.gypi:
  • JavaScriptCore.vcproj/WTF/WTF.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • config.h:
  • wtf/CMakeLists.txt:
  • wtf/CryptographicallyRandomNumber.cpp: Added. (WTF::initMutexIfNeeded): (WTF::init): (WTF::addRandomData): (WTF::stir): (WTF::stirIfNeeded): (WTF::getByte): (WTF::getWord): (WTF::cryptographicallyRandomNumber): (WTF::cryptographicallyRandomValues):
  • wtf/CryptographicallyRandomNumber.h: Added.
  • wtf/OSRandomSource.cpp: Added. (WTF::randomValuesFromOS):
  • wtf/OSRandomSource.h: Added.
  • wtf/wtf.pri:
Location:
trunk/Source/JavaScriptCore
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/Android.mk

    r77391 r78149  
    162162        wtf/Assertions.cpp \
    163163        wtf/ByteArray.cpp \
     164        wtf/CryptographicallyRandomNumber.cpp \
    164165        wtf/CurrentTime.cpp \
    165166        wtf/DateMath.cpp \
     
    168169        wtf/HashTable.cpp \
    169170        wtf/MainThread.cpp \
     171        wtf/OSRandomSource.cpp \
    170172        wtf/PageAllocationAligned.cpp\
    171173        wtf/PageBlock.cpp\
    172174        wtf/RandomNumber.cpp \
    173175        wtf/RefCountedLeakCounter.cpp \
    174     wtf/StackBounds.cpp \
     176        wtf/StackBounds.cpp \
    175177        wtf/TCSystemAlloc.cpp \
    176178        wtf/ThreadIdentifierDataPthreads.cpp \
  • trunk/Source/JavaScriptCore/Android.v8.wtf.mk

    r74360 r78149  
    3535        wtf/Assertions.cpp \
    3636        wtf/ByteArray.cpp \
     37        wtf/CryptographicallyRandomNumber.cpp \
    3738        wtf/CurrentTime.cpp \
    3839        wtf/DateMath.cpp \
     
    4142        wtf/HashTable.cpp \
    4243        wtf/MainThread.cpp \
     44        wtf/OSRandomSource.cpp \
    4345        wtf/RandomNumber.cpp \
    4446        wtf/RefCountedLeakCounter.cpp \
    45     wtf/StackBounds.cpp \
     47        wtf/StackBounds.cpp \
    4648        wtf/TCSystemAlloc.cpp \
    4749        wtf/ThreadIdentifierDataPthreads.cpp \
  • trunk/Source/JavaScriptCore/ChangeLog

    r78108 r78149  
     12011-02-09  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Add WTF::cryptographicallyRandomNumber
     6        https://bugs.webkit.org/show_bug.cgi?id=54083
     7
     8        Introduce a cryptographically strong random number generator to WTF.
     9        The random number generator is based on arc4random as found in:
     10
     11        http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/crypt/arc4random.c?rev=1.22
     12
     13        I've changed to source to WebKit style and abstracted the operating
     14        system interaction to OSRandomSource.  We'll use this functionality to
     15        expose a cryptographically strong random number generator to
     16        JavaScript.
     17
     18        * Android.mk:
     19        * Android.v8.wtf.mk:
     20        * GNUmakefile.am:
     21        * JavaScriptCore.gypi:
     22        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
     23        * JavaScriptCore.xcodeproj/project.pbxproj:
     24        * config.h:
     25        * wtf/CMakeLists.txt:
     26        * wtf/CryptographicallyRandomNumber.cpp: Added.
     27        (WTF::initMutexIfNeeded):
     28        (WTF::init):
     29        (WTF::addRandomData):
     30        (WTF::stir):
     31        (WTF::stirIfNeeded):
     32        (WTF::getByte):
     33        (WTF::getWord):
     34        (WTF::cryptographicallyRandomNumber):
     35        (WTF::cryptographicallyRandomValues):
     36        * wtf/CryptographicallyRandomNumber.h: Added.
     37        * wtf/OSRandomSource.cpp: Added.
     38        (WTF::randomValuesFromOS):
     39        * wtf/OSRandomSource.h: Added.
     40        * wtf/wtf.pri:
     41
    1422011-02-09  Geoffrey Garen  <ggaren@apple.com>
    243
  • trunk/Source/JavaScriptCore/GNUmakefile.am

    r77785 r78149  
    444444        Source/JavaScriptCore/wtf/ByteArray.h \
    445445        Source/JavaScriptCore/wtf/CrossThreadRefCounted.h \
     446        Source/JavaScriptCore/wtf/CryptographicallyRandomNumber.cpp \
     447        Source/JavaScriptCore/wtf/CryptographicallyRandomNumber.h \
    446448        Source/JavaScriptCore/wtf/CurrentTime.cpp \
    447449        Source/JavaScriptCore/wtf/CurrentTime.h \
     
    492494        Source/JavaScriptCore/wtf/NullPtr.h \
    493495        Source/JavaScriptCore/wtf/OSAllocator.h \
     496        Source/JavaScriptCore/wtf/OSRandomSource.cpp \
     497        Source/JavaScriptCore/wtf/OSRandomSource.h \
    494498        Source/JavaScriptCore/wtf/OwnArrayPtr.h \
    495499        Source/JavaScriptCore/wtf/OwnFastMallocPtr.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.gypi

    r78042 r78149  
    375375            'wtf/chromium/MainThreadChromium.cpp',
    376376            'wtf/CrossThreadRefCounted.h',
     377            'wtf/CryptographicallyRandomNumber.cpp',
     378            'wtf/CryptographicallyRandomNumber.h',
    377379            'wtf/CurrentTime.cpp',
    378380            'wtf/CurrentTime.h',
     
    417419            'wtf/OSAllocatorWin.cpp',
    418420            'wtf/OSAllocator.h',
     421            'wtf/OSRandomSource.cpp',
     422            'wtf/OSRandomSource.h',
    419423            'wtf/OwnArrayPtr.h',
    420424            'wtf/OwnFastMallocPtr.h',
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj

    r77785 r78149  
    562562                </File>
    563563                <File
     564                        RelativePath="..\..\wtf\CryptographicallyRandomNumber.cpp"
     565                        >
     566                </File>
     567                <File
     568                        RelativePath="..\..\wtf\CryptographicallyRandomNumber.h"
     569                        >
     570                </File>
     571                <File
    564572                        RelativePath="..\..\wtf\CurrentTime.cpp"
    565573                        >
     
    754762                </File>
    755763                <File
     764                        RelativePath="..\..\wtf\OSRandomSource.cpp"
     765                        >
     766                </File>
     767                <File
     768                        RelativePath="..\..\wtf\OSRandomSource.h"
     769                        >
     770                </File>
     771                <File
    756772                        RelativePath="..\..\wtf\OwnArrayPtr.h"
    757773                        >
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r78042 r78149  
    339339                972A485F12661E0800F4514F /* URLCharacterTypes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 972A485D12661E0800F4514F /* URLCharacterTypes.cpp */; };
    340340                972A48771266256F00F4514F /* URLEscape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 972A48741266256F00F4514F /* URLEscape.cpp */; };
     341                97941A5713029AAB004A3447 /* OSRandomSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97941A3F130299DB004A3447 /* OSRandomSource.cpp */; };
     342                97941A5A13029ACC004A3447 /* OSRandomSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 97941A40130299DB004A3447 /* OSRandomSource.h */; };
     343                97941A7E1302A098004A3447 /* CryptographicallyRandomNumber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97941A7C1302A098004A3447 /* CryptographicallyRandomNumber.cpp */; };
     344                97941A7F1302A098004A3447 /* CryptographicallyRandomNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 97941A7D1302A098004A3447 /* CryptographicallyRandomNumber.h */; };
    341345                A1712B3B11C7B212007A5315 /* RegExpCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1712B3A11C7B212007A5315 /* RegExpCache.cpp */; };
    342346                A1712B3F11C7B228007A5315 /* RegExpCache.h in Headers */ = {isa = PBXBuildFile; fileRef = A1712B3E11C7B228007A5315 /* RegExpCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    10071011                972A48751266256F00F4514F /* URLEscape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = URLEscape.h; path = url/src/URLEscape.h; sourceTree = "<group>"; };
    10081012                972A48761266256F00F4514F /* URLQueryCanonicalizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = URLQueryCanonicalizer.h; path = url/src/URLQueryCanonicalizer.h; sourceTree = "<group>"; };
     1013                97941A3F130299DB004A3447 /* OSRandomSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OSRandomSource.cpp; sourceTree = "<group>"; };
     1014                97941A40130299DB004A3447 /* OSRandomSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSRandomSource.h; sourceTree = "<group>"; };
     1015                97941A7C1302A098004A3447 /* CryptographicallyRandomNumber.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptographicallyRandomNumber.cpp; sourceTree = "<group>"; };
     1016                97941A7D1302A098004A3447 /* CryptographicallyRandomNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptographicallyRandomNumber.h; sourceTree = "<group>"; };
    10091017                97F6903A1169DF7F00A6BB46 /* Terminator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Terminator.h; sourceTree = "<group>"; };
    10101018                A1712B3A11C7B212007A5315 /* RegExpCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RegExpCache.cpp; sourceTree = "<group>"; };
     
    15381546                                FDA15C1612B03028003A583A /* Complex.h */,
    15391547                                0BDFFAD40FC6171000D69EF4 /* CrossThreadRefCounted.h */,
     1548                                97941A7C1302A098004A3447 /* CryptographicallyRandomNumber.cpp */,
     1549                                97941A7D1302A098004A3447 /* CryptographicallyRandomNumber.h */,
    15401550                                180B9AEF0F16C569009BDBC5 /* CurrentTime.cpp */,
    15411551                                180B9AF00F16C569009BDBC5 /* CurrentTime.h */,
     
    15801590                                1400067612A6F7830064D123 /* OSAllocator.h */,
    15811591                                1400069212A6F9E10064D123 /* OSAllocatorPosix.cpp */,
     1592                                97941A3F130299DB004A3447 /* OSRandomSource.cpp */,
     1593                                97941A40130299DB004A3447 /* OSRandomSource.h */,
    15821594                                9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */,
    15831595                                0BDFFAD10FC616EC00D69EF4 /* OwnFastMallocPtr.h */,
     
    24452457                                14C824AD12F7C785008F35E0 /* MarkedBlock.h in Headers */,
    24462458                                E4D8CEFB12FC439600BC9F5A /* BloomFilter.h in Headers */,
     2459                                97941A5A13029ACC004A3447 /* OSRandomSource.h in Headers */,
     2460                                97941A7F1302A098004A3447 /* CryptographicallyRandomNumber.h in Headers */,
    24472461                        );
    24482462                        runOnlyForDeploymentPostprocessing = 0;
     
    29142928                                E49DC16B12EF293E00184A1F /* SourceProviderCache.cpp in Sources */,
    29152929                                14C824AB12F7C77E008F35E0 /* MarkedBlock.cpp in Sources */,
     2930                                97941A5713029AAB004A3447 /* OSRandomSource.cpp in Sources */,
     2931                                97941A7E1302A098004A3447 /* CryptographicallyRandomNumber.cpp in Sources */,
    29162932                        );
    29172933                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/JavaScriptCore/config.h

    r59537 r78149  
    5353#ifndef _CRT_RAND_S
    5454#define _CRT_RAND_S
     55#define WTF_USE_OS_RANDOMNESS 1
    5556#endif
    5657#endif
    5758
     59#endif
     60
     61#if OS(DARWIN) || OS(UNIX)
     62#define WTF_USE_OS_RANDOMNESS 1
    5863#endif
    5964
  • trunk/Source/JavaScriptCore/wtf/CMakeLists.txt

    r77785 r78149  
    1010    Complex.h
    1111    CrossThreadRefCounted.h
     12    CryptographicallyRandomNumber.h
    1213    CurrentTime.h
    1314    DateMath.h
     
    4243    NullPtr.h
    4344    OSAllocator.h
     45    OSRandomSource.h
    4446    OwnArrayPtr.h
    4547    OwnFastMallocPtr.h
     
    104106    Assertions.cpp
    105107    ByteArray.cpp
     108    CryptographicallyRandomNumber.cpp
    106109    CurrentTime.cpp
    107110    DecimalNumber.cpp
     
    110113    MainThread.cpp
    111114    MD5.cpp
     115    OSRandomSource.cpp
    112116    RandomNumber.cpp
    113117    RefCountedLeakCounter.cpp
  • trunk/Source/JavaScriptCore/wtf/wtf.pri

    r76716 r78149  
    44    wtf/Assertions.cpp \
    55    wtf/ByteArray.cpp \
     6    wtf/CryptographicallyRandomNumber.cpp \
    67    wtf/CurrentTime.cpp \
    78    wtf/DateMath.cpp \
     
    1516    wtf/MainThread.cpp \
    1617    wtf/NullPtr.cpp \
     18    wtf/OSRandomSource.cpp \
    1719    wtf/qt/MainThreadQt.cpp \
    1820    wtf/qt/StringQt.cpp \
Note: See TracChangeset for help on using the changeset viewer.