Changeset 53928 in webkit


Ignore:
Timestamp:
Jan 27, 2010 6:07:59 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-27 Kwang Yul Seo <skyul@company100.net>

Reviewed by Eric Seidel.

[BREWMP] Port WTF's randomNumber
https://bugs.webkit.org/show_bug.cgi?id=33566

Use GETRAND to generate 4 byte random byte sequence to implement
weakRandomNumber. Create a secure random number generator with
AEECLSID_RANDOM to implement randomNumber.

  • wtf/RandomNumber.cpp: (WTF::weakRandomNumber): (WTF::randomNumber):
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r53926 r53928  
     12010-01-27  Kwang Yul Seo  <skyul@company100.net>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [BREWMP] Port WTF's randomNumber
     6        https://bugs.webkit.org/show_bug.cgi?id=33566
     7
     8        Use GETRAND to generate 4 byte random byte sequence to implement
     9        weakRandomNumber. Create a secure random number generator with
     10        AEECLSID_RANDOM to implement randomNumber.
     11
     12        * wtf/RandomNumber.cpp:
     13        (WTF::weakRandomNumber):
     14        (WTF::randomNumber):
     15
    1162010-01-27  Kwang Yul Seo  <skyul@company100.net>
    217
  • trunk/JavaScriptCore/wtf/RandomNumber.cpp

    r52791 r53928  
    4141#endif
    4242
     43#if PLATFORM(BREWMP)
     44#include <AEEAppGen.h>
     45#include <AEESource.h>
     46#include <AEEStdLib.h>
     47#endif
     48
    4349namespace WTF {
    4450
     
    4854    // rand_s is incredibly slow on windows so we fall back on rand for Math.random
    4955    return (rand() + (rand() / (RAND_MAX + 1.0))) / (RAND_MAX + 1.0);
     56#elif PLATFORM(BREWMP)
     57    uint32_t bits;
     58    GETRAND(reinterpret_cast<byte*>(&bits), sizeof(uint32_t));
     59    return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
    5060#else
    5161    return randomNumber();
     
    100110    fullRandom &= (1LL << 53) - 1;
    101111    return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53);
     112#elif PLATFORM(BREWMP)
     113    uint32_t bits;
     114    ISource* randomSource;
     115
     116    IShell* shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell;
     117    ISHELL_CreateInstance(shell, AEECLSID_RANDOM, reinterpret_cast<void**>(&randomSource));
     118    ISOURCE_Read(randomSource, reinterpret_cast<char*>(&bits), 4);
     119    ISOURCE_Release(randomSource);
     120
     121    return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
    102122#else
    103123    uint32_t part1 = rand() & (RAND_MAX - 1);
Note: See TracChangeset for help on using the changeset viewer.