Skip to content

Commit e045714

Browse files
author
s.vychegzhanin
committed
some comments
1 parent a9008f1 commit e045714

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/encryptEngines/js.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = function (keyPair, options) {
88
encrypt: function (buffer, usePrivate) {
99
var m, c;
1010
if (usePrivate) {
11+
/* Type 1: zeros padding for private key encrypt */
1112
m = new BigInteger(pkcs1Scheme.encPad(buffer, {type: 1}));
1213
c = keyPair.$doPrivate(m);
1314
} else {
@@ -22,6 +23,7 @@ module.exports = function (keyPair, options) {
2223

2324
if (usePublic) {
2425
m = keyPair.$doPublic(c);
26+
/* Type 1: zeros padding for private key decrypt */
2527
return pkcs1Scheme.encUnPad(m.toBuffer(keyPair.encryptedDataLength), {type: 1});
2628
} else {
2729
m = keyPair.$doPrivate(c);

src/schemes/pkcs1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports.makeScheme = function (key, options) {
5050
throw new Error("Message too long for RSA (n=" + this.key.encryptedDataLength + ", l=" + buffer.length + ")");
5151
}
5252

53+
/* Type 1: zeros padding for private key encrypt */
5354
if (options.type === 1) {
5455
filled = new Buffer(this.key.encryptedDataLength - buffer.length - 1);
5556
filled.fill(0xff, 0, filled.length - 1);
@@ -58,6 +59,7 @@ module.exports.makeScheme = function (key, options) {
5859

5960
return Buffer.concat([filled, buffer]);
6061
} else {
62+
/* random padding for public key encrypt */
6163
filled = new Buffer(this.key.encryptedDataLength - buffer.length);
6264
filled[0] = 0;
6365
filled[1] = 2;
@@ -88,6 +90,7 @@ module.exports.makeScheme = function (key, options) {
8890
return null;
8991
}
9092

93+
/* Type 1: zeros padding for private key decrypt */
9194
if (options.type === 1) {
9295
if (buffer[0] !== 0 && buffer[1] !== 1) {
9396
return null;
@@ -99,6 +102,7 @@ module.exports.makeScheme = function (key, options) {
99102
}
100103
}
101104
} else {
105+
/* random padding for public key decrypt */
102106
if (buffer[0] !== 0 && buffer[1] !== 2) {
103107
return null;
104108
}

0 commit comments

Comments
 (0)