Skip to content

Commit

Permalink
Incorporate math-random-polyfill.js for better Math.random().
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Dec 6, 2016
1 parent 2b91eb4 commit 81b7c27
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -122,12 +122,12 @@ The client is built using HTML, CSS, and JavaScript on top of the [React](https:

File | Purpose
-----|--------
default.htm <br/> default.js <br/> default.css | PassWeb implementation
default.htm <br/> default.js <br/> default.css <br/> render.jsx <br/> render.js | PassWeb implementation
offline.appcache | Offline cache manifest
react.min.js <br/> react-dom.min.js <br/> lz-string.min.js <br/> aes.js <br/> pbkdf2.js <br/> sha512.js <br/> | External libraries
favicon.ico <br/> Resources\\\*.png <br/> Resources\\\*.svg <br/> | Image resources
App_Code\RemoteStorage.cs <br/> Web.config <br/> *App_Data\\PassWeb\\...* | ASP.NET server
NodeJs\\server.js <br/> NodeJs\\remotestorage.js <br/> NodeJs\\storage-file.js <br/> NodeJs\\storage-blob-azure.js <br/> NodeJs\\package.json <br/> | Node.js server
react.min.js <br/> react-dom.min.js <br/> lz-string.min.js <br/> aes.js <br/> pbkdf2.js <br/> sha512.js <br/> math-random-polyfill.js | External libraries
favicon.ico <br/> Resources\\\*.png <br/> Resources\\\*.svg | Image resources
App_Code\\RemoteStorage.cs <br/> Web.config | ASP.NET server
NodeJs\\server.js <br/> NodeJs\\remotestorage.js <br/> NodeJs\\storage-file.js <br/> NodeJs\\storage-blob-azure.js <br/> NodeJs\\package.json | Node.js server
Readme.md | This file
LICENSE | License

Expand Down
1 change: 1 addition & 0 deletions default.htm
Expand Up @@ -19,6 +19,7 @@
<div id="appContainer"></div>
<script src="react.min.js"></script>
<script src="react-dom.min.js"></script>
<script src="math-random-polyfill.js"></script>
<script src="render.js"></script>
<script src="lz-string.min.js"></script>
<script src="pbkdf2.js"></script>
Expand Down
32 changes: 32 additions & 0 deletions math-random-polyfill.js
@@ -0,0 +1,32 @@
// math-random-polyfill.js
// https://github.com/DavidAnson/math-random-polyfill
// 2016-12-03

(function iife () {
"use strict";
// Feature detection
var crypto = window.crypto || window.msCrypto;
if (window.Uint32Array && crypto && crypto.getRandomValues) {
// Capture functions and values
var Math_random = Math.random.bind(Math);
var crypto_getRandomValues = crypto.getRandomValues.bind(crypto);
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
var highShift = Math.pow(2, 32);
var highMask = Math.pow(2, 53 - 32) - 1;
// Polyfill Math.random
Math.random = function math_random_polyfill () {
try {
// Get random bits for numerator
var array = new Uint32Array(2);
crypto_getRandomValues(array);
var numerator = ((array[0] & highMask) * highShift) + array[1];
// Divide by maximum-value denominator
var denominator = MAX_SAFE_INTEGER + 1;
return numerator / denominator;
} catch (ex) {
// Exception in crypto.getRandomValues, fall back to Math.random
return Math_random();
}
};
}
}());
3 changes: 2 additions & 1 deletion offline.appcache
@@ -1,11 +1,12 @@
CACHE MANIFEST
# 2016-11-27
# 2016-12-05
aes.js
default.css
default.htm
default.js
favicon.ico
lz-string.min.js
math-random-polyfill.js
pbkdf2.js
react.min.js
react-dom.min.js
Expand Down

0 comments on commit 81b7c27

Please sign in to comment.