mirror of
https://github.com/hanzoai/elliptic.git
synced 2026-09-23 23:51:03 +00:00
lib: move rand to brorand repo
This commit is contained in:
+1
-1
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"bn.js": "^0.15.0",
|
||||
"brorand": "^1.0.1",
|
||||
"hash.js": "^0.2.0",
|
||||
"inherits": "^2.0.1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user