Skip to content

Commit de640bf

Browse files
committed
modularize
1 parent 4f48f87 commit de640bf

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
var bn = require('bn.js');
2+
var randomBytes = require('randombytes');
23
module.exports = crt;
3-
function blind(priv, crypto) {
4-
var r = getr(priv, crypto);
4+
function blind(priv) {
5+
var r = getr(priv);
56
var blinder = r.toRed(bn.mont(priv.modulus))
67
.redPow(new bn(priv.publicExponent)).fromRed();
78
return {
89
blinder: blinder,
910
unblinder:r.invm(priv.modulus)
1011
};
1112
}
12-
function crt(msg, priv, crypto) {
13-
var blinds = blind(priv, crypto);
13+
function crt(msg, priv) {
14+
var blinds = blind(priv);
1415
var len = priv.modulus.byteLength();
1516
var mod = bn.mont(priv.modulus);
1617
var blinded = new bn(msg).mul(blinds.blinder).mod(priv.modulus);
@@ -35,11 +36,11 @@ function crt(msg, priv, crypto) {
3536
return out;
3637
}
3738
crt.getr = getr;
38-
function getr(priv, crypto) {
39+
function getr(priv) {
3940
var len = priv.modulus.byteLength();
40-
var r = new bn(crypto.randomBytes(len));
41+
var r = new bn(randomBytes(len));
4142
while (r.cmp(priv.modulus) >= 0 || !r.mod(priv.prime1) || !r.mod(priv.prime2)) {
42-
r = new bn(crypto.randomBytes(len));
43+
r = new bn(randomBytes(len));
4344
}
4445
return r;
4546
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"author": "",
1010
"license": "MIT",
1111
"dependencies": {
12-
"bn.js": "^1.0.0"
12+
"bn.js": "^1.0.0",
13+
"randombytes": "^2.0.1"
1314
},
1415
"repository": {
1516
"type": "git",
@@ -18,6 +19,6 @@
1819
"devDependencies": {
1920
"tap-spec": "^2.1.2",
2021
"tape": "^3.0.3",
21-
"parse-asn1": "^1.2.0"
22+
"parse-asn1": "^3.0.0"
2223
}
2324
}

test.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)