lib: move rand to brorand repo

This commit is contained in:
Fedor Indutny
2014-11-05 12:03:56 -05:00
parent 274e36de37
commit 2d6a4b9476
3 changed files with 2 additions and 50 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ var elliptic = exports;
elliptic.version = require('../package.json').version;
elliptic.utils = require('./elliptic/utils');
elliptic.rand = require('./elliptic/rand');
elliptic.rand = require('brorand');
elliptic.hmacDRBG = require('./elliptic/hmac-drbg');
elliptic.curve = require('./elliptic/curve');
elliptic.curves = require('./elliptic/curves');
-49
View File
@@ -1,49 +0,0 @@
var assert = require('assert');
var elliptic = require('../elliptic');
var r;
module.exports = function rand(len) {
if (!r)
r = new Rand();
return r.generate(len);
};
function Rand() {
}
Rand.prototype.generate = function generate(len) {
return this._rand(len);
};
if (typeof window === 'object') {
if (window.crypto && window.crypto.getRandomValues) {
// Modern browsers
Rand.prototype._rand = function _rand(n) {
var arr = new Uint8Array(n);
window.crypto.getRandomValues(arr);
return arr;
};
} else if (window.msCrypto && window.msCrypto.getRandomValues) {
// IE
Rand.prototype._rand = function _rand(n) {
var arr = new Uint8Array(n);
window.msCrypto.getRandomValues(arr);
return arr;
};
} else {
// Old junk
Rand.prototype._rand = function() {
throw new Error('Not implemented yet');
};
}
} else {
// Node.js
var crypto;
Rand.prototype._rand = function _rand(n) {
if (!crypto)
crypto = require('cry' + 'pto');
return crypto.randomBytes(n);
};
}
+1
View File
@@ -29,6 +29,7 @@
},
"dependencies": {
"bn.js": "^0.15.0",
"brorand": "^1.0.1",
"hash.js": "^0.2.0",
"inherits": "^2.0.1"
}