Fix all the lint noise, mostly semicolons, duplicate var definitions and ==0
This commit is contained in:
parent
17ad1f5fed
commit
dba6f379e8
|
@ -124,7 +124,7 @@ CleartextMessage.prototype.armor = function() {
|
||||||
hash: enums.read(enums.hash, config.prefer_hash_algorithm).toUpperCase(),
|
hash: enums.read(enums.hash, config.prefer_hash_algorithm).toUpperCase(),
|
||||||
text: this.text,
|
text: this.text,
|
||||||
data: this.packets.write()
|
data: this.packets.write()
|
||||||
}
|
};
|
||||||
return armor.encode(enums.armor.signed, body);
|
return armor.encode(enums.armor.signed, body);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ JXG = {
|
||||||
exists: (function(undefined) {
|
exists: (function(undefined) {
|
||||||
return function(v) {
|
return function(v) {
|
||||||
return !(v === undefined || v === null);
|
return !(v === undefined || v === null);
|
||||||
}
|
};
|
||||||
})()
|
})()
|
||||||
};
|
};
|
||||||
JXG.decompress = function(str) {
|
JXG.decompress = function(str) {
|
||||||
|
@ -142,24 +142,24 @@ JXG.Util.Unzip = function(barray) {
|
||||||
return bA[bytepos++];
|
return bA[bytepos++];
|
||||||
} else
|
} else
|
||||||
return -1;
|
return -1;
|
||||||
};
|
}
|
||||||
|
|
||||||
function byteAlign() {
|
function byteAlign() {
|
||||||
bb = 1;
|
bb = 1;
|
||||||
};
|
}
|
||||||
|
|
||||||
function readBit() {
|
function readBit() {
|
||||||
var carry;
|
var carry;
|
||||||
bits++;
|
bits++;
|
||||||
carry = (bb & 1);
|
carry = (bb & 1);
|
||||||
bb >>= 1;
|
bb >>= 1;
|
||||||
if (bb == 0) {
|
if (bb === 0) {
|
||||||
bb = readByte();
|
bb = readByte();
|
||||||
carry = (bb & 1);
|
carry = (bb & 1);
|
||||||
bb = (bb >> 1) | 0x80;
|
bb = (bb >> 1) | 0x80;
|
||||||
}
|
}
|
||||||
return carry;
|
return carry;
|
||||||
};
|
}
|
||||||
|
|
||||||
function readBits(a) {
|
function readBits(a) {
|
||||||
var res = 0,
|
var res = 0,
|
||||||
|
@ -172,12 +172,12 @@ JXG.Util.Unzip = function(barray) {
|
||||||
res = bitReverse[res] >> (8 - a);
|
res = bitReverse[res] >> (8 - a);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
};
|
}
|
||||||
|
|
||||||
function flushBuffer() {
|
function flushBuffer() {
|
||||||
//document.write('FLUSHBUFFER:'+buf32k);
|
//document.write('FLUSHBUFFER:'+buf32k);
|
||||||
bIdx = 0;
|
bIdx = 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
function addBuffer(a) {
|
function addBuffer(a) {
|
||||||
SIZE++;
|
SIZE++;
|
||||||
|
@ -189,14 +189,14 @@ JXG.Util.Unzip = function(barray) {
|
||||||
//document.write('ADDBUFFER:'+buf32k);
|
//document.write('ADDBUFFER:'+buf32k);
|
||||||
bIdx = 0;
|
bIdx = 0;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function HufNode() {
|
function HufNode() {
|
||||||
this.b0 = 0;
|
this.b0 = 0;
|
||||||
this.b1 = 0;
|
this.b1 = 0;
|
||||||
this.jump = null;
|
this.jump = null;
|
||||||
this.jumppos = -1;
|
this.jumppos = -1;
|
||||||
};
|
}
|
||||||
|
|
||||||
var LITERALS = 288;
|
var LITERALS = 288;
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
return fpos[len]++;
|
return fpos[len]++;
|
||||||
fpos[len]++;
|
fpos[len]++;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function Rec() {
|
function Rec() {
|
||||||
var curplace = Places[treepos];
|
var curplace = Places[treepos];
|
||||||
|
@ -269,7 +269,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
}
|
}
|
||||||
len--;
|
len--;
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
function CreateTree(currentTree, numval, lengths, show) {
|
function CreateTree(currentTree, numval, lengths, show) {
|
||||||
var i;
|
var i;
|
||||||
|
@ -314,7 +314,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
function DecodeValue(currentTree) {
|
function DecodeValue(currentTree) {
|
||||||
var len, i,
|
var len, i,
|
||||||
|
@ -353,10 +353,10 @@ JXG.Util.Unzip = function(barray) {
|
||||||
X = currentTree[xtreepos];
|
X = currentTree[xtreepos];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function DeflateLoop() {
|
function DeflateLoop() {
|
||||||
var last, c, type, i, len;
|
var last, c, type, i, j, len, dist;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/*if((last = readBit())){
|
/*if((last = readBit())){
|
||||||
|
@ -389,7 +389,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == 0) {
|
if (type === 0) {
|
||||||
var blockLen, cSum;
|
var blockLen, cSum;
|
||||||
|
|
||||||
// Stored
|
// Stored
|
||||||
|
@ -408,8 +408,6 @@ JXG.Util.Unzip = function(barray) {
|
||||||
addBuffer(c);
|
addBuffer(c);
|
||||||
}
|
}
|
||||||
} else if (type == 1) {
|
} else if (type == 1) {
|
||||||
var j;
|
|
||||||
|
|
||||||
/* Fixed Huffman tables -- fixed decode routine */
|
/* Fixed Huffman tables -- fixed decode routine */
|
||||||
while (1) {
|
while (1) {
|
||||||
/*
|
/*
|
||||||
|
@ -454,8 +452,6 @@ JXG.Util.Unzip = function(barray) {
|
||||||
/* EOF */
|
/* EOF */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
var len, dist;
|
|
||||||
|
|
||||||
j -= 256 + 1; /* bytes + EOF */
|
j -= 256 + 1; /* bytes + EOF */
|
||||||
len = readBits(cplext[j]) + cplens[j];
|
len = readBits(cplext[j]) + cplens[j];
|
||||||
|
|
||||||
|
@ -470,13 +466,13 @@ JXG.Util.Unzip = function(barray) {
|
||||||
|
|
||||||
/*fprintf(errfp, "@%d (l%02x,d%04x)\n", SIZE, len, dist);*/
|
/*fprintf(errfp, "@%d (l%02x,d%04x)\n", SIZE, len, dist);*/
|
||||||
for (j = 0; j < len; j++) {
|
for (j = 0; j < len; j++) {
|
||||||
var c = buf32k[(bIdx - dist) & 0x7fff];
|
c = buf32k[(bIdx - dist) & 0x7fff];
|
||||||
addBuffer(c);
|
addBuffer(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // while
|
} // while
|
||||||
} else if (type == 2) {
|
} else if (type == 2) {
|
||||||
var j, n, literalCodes, distCodes, lenCodes;
|
var n, literalCodes, distCodes, lenCodes;
|
||||||
var ll = new Array(288 + 32); // "static" just to preserve stack
|
var ll = new Array(288 + 32); // "static" just to preserve stack
|
||||||
|
|
||||||
// Dynamic Huffman tables
|
// Dynamic Huffman tables
|
||||||
|
@ -573,7 +569,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
len = literalTree.length;
|
len = literalTree.length;
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
distanceTree[i] = new HufNode();
|
distanceTree[i] = new HufNode();
|
||||||
var ll2 = new Array();
|
var ll2 = [];
|
||||||
for (i = literalCodes; i < ll.length; i++) {
|
for (i = literalCodes; i < ll.length; i++) {
|
||||||
ll2[i - literalCodes] = ll[i];
|
ll2[i - literalCodes] = ll[i];
|
||||||
}
|
}
|
||||||
|
@ -586,9 +582,8 @@ JXG.Util.Unzip = function(barray) {
|
||||||
outer: while (1) {
|
outer: while (1) {
|
||||||
j = DecodeValue(literalTree);
|
j = DecodeValue(literalTree);
|
||||||
if (j >= 256) { // In C64: if carry set
|
if (j >= 256) { // In C64: if carry set
|
||||||
var len, dist;
|
|
||||||
j -= 256;
|
j -= 256;
|
||||||
if (j == 0) {
|
if (j === 0) {
|
||||||
// EOF
|
// EOF
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -607,7 +602,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
if (bIdx - dist < 0) {
|
if (bIdx - dist < 0) {
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
var c = buf32k[(bIdx - dist) & 0x7fff];
|
c = buf32k[(bIdx - dist) & 0x7fff];
|
||||||
addBuffer(c);
|
addBuffer(c);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -620,7 +615,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
|
|
||||||
byteAlign();
|
byteAlign();
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
JXG.Util.Unzip.prototype.unzipFile = function(name) {
|
JXG.Util.Unzip.prototype.unzipFile = function(name) {
|
||||||
var i;
|
var i;
|
||||||
|
@ -631,7 +626,6 @@ JXG.Util.Unzip = function(barray) {
|
||||||
return unzipped[i][0];
|
return unzipped[i][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JXG.Util.Unzip.prototype.deflate = function() {
|
JXG.Util.Unzip.prototype.deflate = function() {
|
||||||
|
@ -646,7 +640,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
unzipped[files][1] = "DEFLATE";
|
unzipped[files][1] = "DEFLATE";
|
||||||
files++;
|
files++;
|
||||||
return unzipped;
|
return unzipped;
|
||||||
}
|
};
|
||||||
|
|
||||||
JXG.Util.Unzip.prototype.unzip = function() {
|
JXG.Util.Unzip.prototype.unzip = function() {
|
||||||
//convertToByteArray(input);
|
//convertToByteArray(input);
|
||||||
|
@ -771,8 +765,9 @@ JXG.Util.Unzip = function(barray) {
|
||||||
alert("filelen " + filelen);
|
alert("filelen " + filelen);
|
||||||
i = 0;
|
i = 0;
|
||||||
nameBuf = [];
|
nameBuf = [];
|
||||||
|
var c;
|
||||||
while (filelen--) {
|
while (filelen--) {
|
||||||
var c = readByte();
|
c = readByte();
|
||||||
if (c == "/" | c == ":") {
|
if (c == "/" | c == ":") {
|
||||||
i = 0;
|
i = 0;
|
||||||
} else if (i < NAMEMAX - 1)
|
} else if (i < NAMEMAX - 1)
|
||||||
|
@ -794,7 +789,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
CRC = 0xffffffff;
|
CRC = 0xffffffff;
|
||||||
SIZE = 0;
|
SIZE = 0;
|
||||||
|
|
||||||
if (size == 0 && fileOut.charAt(fileout.length - 1) == "/") {
|
if (size === 0 && fileOut.charAt(fileout.length - 1) == "/") {
|
||||||
//skipdir
|
//skipdir
|
||||||
if (debug)
|
if (debug)
|
||||||
alert("skipdir");
|
alert("skipdir");
|
||||||
|
@ -812,7 +807,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
skipdir();
|
skipdir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function skipdir() {
|
function skipdir() {
|
||||||
var crc,
|
var crc,
|
||||||
|
@ -925,7 +920,7 @@ JXG.Util.Unzip = function(barray) {
|
||||||
if (modeZIP)
|
if (modeZIP)
|
||||||
nextFile();
|
nextFile();
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1069,7 +1064,7 @@ JXG.Util.Base64 = {
|
||||||
lineno, i,
|
lineno, i,
|
||||||
destripped = [];
|
destripped = [];
|
||||||
|
|
||||||
if (wrap == null)
|
if (wrap === null)
|
||||||
wrap = 76;
|
wrap = 76;
|
||||||
|
|
||||||
stripped.replace(/ /g, "");
|
stripped.replace(/ /g, "");
|
||||||
|
@ -1224,7 +1219,7 @@ JXG.Util.utf8Decode = function(utftext) {
|
||||||
string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)));
|
string.push(String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)));
|
||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
return string.join('');
|
return string.join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@ module.exports = function () {
|
||||||
this.write();
|
this.write();
|
||||||
} else
|
} else
|
||||||
this.config = cf;
|
this.config = cf;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the config to HTML5 local storage
|
* Writes the config to HTML5 local storage
|
||||||
*/
|
*/
|
||||||
this.write = function () {
|
this.write = function () {
|
||||||
window.localStorage.setItem("config", JSON.stringify(this.config));
|
window.localStorage.setItem("config", JSON.stringify(this.config));
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -52,8 +52,9 @@ module.exports = {
|
||||||
prefixrandom = prefixrandom + prefixrandom.charAt(block_size - 2) + prefixrandom.charAt(block_size - 1);
|
prefixrandom = prefixrandom + prefixrandom.charAt(block_size - 2) + prefixrandom.charAt(block_size - 1);
|
||||||
util.print_debug("prefixrandom:" + util.hexstrdump(prefixrandom));
|
util.print_debug("prefixrandom:" + util.hexstrdump(prefixrandom));
|
||||||
var ciphertext = "";
|
var ciphertext = "";
|
||||||
|
var i;
|
||||||
// 1. The feedback register (FR) is set to the IV, which is all zeros.
|
// 1. The feedback register (FR) is set to the IV, which is all zeros.
|
||||||
for (var i = 0; i < block_size; i++) FR[i] = 0;
|
for (i = 0; i < block_size; i++) FR[i] = 0;
|
||||||
|
|
||||||
// 2. FR is encrypted to produce FRE (FR Encrypted). This is the
|
// 2. FR is encrypted to produce FRE (FR Encrypted). This is the
|
||||||
// encryption of an all-zero value.
|
// encryption of an all-zero value.
|
||||||
|
@ -61,10 +62,10 @@ module.exports = {
|
||||||
// 3. FRE is xored with the first BS octets of random data prefixed to
|
// 3. FRE is xored with the first BS octets of random data prefixed to
|
||||||
// the plaintext to produce C[1] through C[BS], the first BS octets
|
// the plaintext to produce C[1] through C[BS], the first BS octets
|
||||||
// of ciphertext.
|
// of ciphertext.
|
||||||
for (var i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ prefixrandom.charCodeAt(i));
|
for (i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ prefixrandom.charCodeAt(i));
|
||||||
|
|
||||||
// 4. FR is loaded with C[1] through C[BS].
|
// 4. FR is loaded with C[1] through C[BS].
|
||||||
for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i);
|
for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i);
|
||||||
|
|
||||||
// 5. FR is encrypted to produce FRE, the encryption of the first BS
|
// 5. FR is encrypted to produce FRE, the encryption of the first BS
|
||||||
// octets of ciphertext.
|
// octets of ciphertext.
|
||||||
|
@ -78,9 +79,9 @@ module.exports = {
|
||||||
|
|
||||||
if (resync) {
|
if (resync) {
|
||||||
// 7. (The resync step) FR is loaded with C3-C10.
|
// 7. (The resync step) FR is loaded with C3-C10.
|
||||||
for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i + 2);
|
for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i + 2);
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i);
|
for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(i);
|
||||||
}
|
}
|
||||||
// 8. FR is encrypted to produce FRE.
|
// 8. FR is encrypted to produce FRE.
|
||||||
FRE = cipherfn.encrypt(FR, key);
|
FRE = cipherfn.encrypt(FR, key);
|
||||||
|
@ -89,11 +90,11 @@ module.exports = {
|
||||||
// 9. FRE is xored with the first 8 octets of the given plaintext, now
|
// 9. FRE is xored with the first 8 octets of the given plaintext, now
|
||||||
// that we have finished encrypting the 10 octets of prefixed data.
|
// that we have finished encrypting the 10 octets of prefixed data.
|
||||||
// This produces C11-C18, the next 8 octets of ciphertext.
|
// This produces C11-C18, the next 8 octets of ciphertext.
|
||||||
for (var i = 0; i < block_size; i++)
|
for (i = 0; i < block_size; i++)
|
||||||
ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i));
|
ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i));
|
||||||
for (n = block_size + 2; n < plaintext.length; n += block_size) {
|
for (n = block_size + 2; n < plaintext.length; n += block_size) {
|
||||||
// 10. FR is loaded with C11-C18
|
// 10. FR is loaded with C11-C18
|
||||||
for (var i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(n + i);
|
for (i = 0; i < block_size; i++) FR[i] = ciphertext.charCodeAt(n + i);
|
||||||
|
|
||||||
// 11. FR is encrypted to produce FRE.
|
// 11. FR is encrypted to produce FRE.
|
||||||
FRE = cipherfn.encrypt(FR);
|
FRE = cipherfn.encrypt(FR);
|
||||||
|
@ -101,7 +102,7 @@ module.exports = {
|
||||||
// 12. FRE is xored with the next 8 octets of plaintext, to produce the
|
// 12. FRE is xored with the next 8 octets of plaintext, to produce the
|
||||||
// next 8 octets of ciphertext. These are loaded into FR and the
|
// next 8 octets of ciphertext. These are loaded into FR and the
|
||||||
// process is repeated until the plaintext is used up.
|
// process is repeated until the plaintext is used up.
|
||||||
for (var i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt((n - 2) +
|
for (i = 0; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt((n - 2) +
|
||||||
i));
|
i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,12 +110,12 @@ module.exports = {
|
||||||
// 9. FRE is xored with the first 8 octets of the given plaintext, now
|
// 9. FRE is xored with the first 8 octets of the given plaintext, now
|
||||||
// that we have finished encrypting the 10 octets of prefixed data.
|
// that we have finished encrypting the 10 octets of prefixed data.
|
||||||
// This produces C11-C18, the next 8 octets of ciphertext.
|
// This produces C11-C18, the next 8 octets of ciphertext.
|
||||||
for (var i = 2; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i));
|
for (i = 2; i < block_size; i++) ciphertext += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(i));
|
||||||
var tempCiphertext = ciphertext.substring(0, 2 * block_size).split('');
|
var tempCiphertext = ciphertext.substring(0, 2 * block_size).split('');
|
||||||
var tempCiphertextString = ciphertext.substring(block_size);
|
var tempCiphertextString = ciphertext.substring(block_size);
|
||||||
for (n = block_size; n < plaintext.length; n += block_size) {
|
for (n = block_size; n < plaintext.length; n += block_size) {
|
||||||
// 10. FR is loaded with C11-C18
|
// 10. FR is loaded with C11-C18
|
||||||
for (var i = 0; i < block_size; i++) FR[i] = tempCiphertextString.charCodeAt(i);
|
for (i = 0; i < block_size; i++) FR[i] = tempCiphertextString.charCodeAt(i);
|
||||||
tempCiphertextString = '';
|
tempCiphertextString = '';
|
||||||
|
|
||||||
// 11. FR is encrypted to produce FRE.
|
// 11. FR is encrypted to produce FRE.
|
||||||
|
@ -123,13 +124,12 @@ module.exports = {
|
||||||
// 12. FRE is xored with the next 8 octets of plaintext, to produce the
|
// 12. FRE is xored with the next 8 octets of plaintext, to produce the
|
||||||
// next 8 octets of ciphertext. These are loaded into FR and the
|
// next 8 octets of ciphertext. These are loaded into FR and the
|
||||||
// process is repeated until the plaintext is used up.
|
// process is repeated until the plaintext is used up.
|
||||||
for (var i = 0; i < block_size; i++) {
|
for (i = 0; i < block_size; i++) {
|
||||||
tempCiphertext.push(String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(n + i)));
|
tempCiphertext.push(String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(n + i)));
|
||||||
tempCiphertextString += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(n + i));
|
tempCiphertextString += String.fromCharCode(FRE[i] ^ plaintext.charCodeAt(n + i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ciphertext = tempCiphertext.join('');
|
ciphertext = tempCiphertext.join('');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ciphertext = ciphertext.substring(0, plaintext.length + 2 + block_size);
|
ciphertext = ciphertext.substring(0, plaintext.length + 2 + block_size);
|
||||||
|
@ -239,7 +239,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var n = resync ? 0 : 2;
|
n = resync ? 0 : 2;
|
||||||
|
|
||||||
text = text.join('');
|
text = text.join('');
|
||||||
|
|
||||||
|
@ -281,14 +281,15 @@ module.exports = {
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
var plaintext = [];
|
var plaintext = [];
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
if (iv == null)
|
var i;
|
||||||
for (var i = 0; i < block_size; i++) blockp += String.fromCharCode(0);
|
if (iv === null)
|
||||||
|
for (i = 0; i < block_size; i++) blockp += String.fromCharCode(0);
|
||||||
else
|
else
|
||||||
blockp = iv.substring(0, block_size);
|
blockp = iv.substring(0, block_size);
|
||||||
while (ciphertext.length > (block_size * pos)) {
|
while (ciphertext.length > (block_size * pos)) {
|
||||||
var decblock = cipherfn.encrypt(util.str2bin(blockp));
|
var decblock = cipherfn.encrypt(util.str2bin(blockp));
|
||||||
blockp = ciphertext.substring((pos * (block_size)) + offset, (pos * (block_size)) + (block_size) + offset);
|
blockp = ciphertext.substring((pos * (block_size)) + offset, (pos * (block_size)) + (block_size) + offset);
|
||||||
for (var i = 0; i < blockp.length; i++) {
|
for (i = 0; i < blockp.length; i++) {
|
||||||
plaintext.push(String.fromCharCode(blockp.charCodeAt(i) ^ decblock[i]));
|
plaintext.push(String.fromCharCode(blockp.charCodeAt(i) ^ decblock[i]));
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -296,4 +297,4 @@ module.exports = {
|
||||||
|
|
||||||
return plaintext.join('');
|
return plaintext.join('');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -493,8 +493,8 @@ function makeClass(length) {
|
||||||
|
|
||||||
this.encrypt = function(block) {
|
this.encrypt = function(block) {
|
||||||
return AESencrypt(block, this.key);
|
return AESencrypt(block, this.key);
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
c.blockSize = c.prototype.blockSize = 16;
|
c.blockSize = c.prototype.blockSize = 16;
|
||||||
c.keySize = c.prototype.keySize = length / 8;
|
c.keySize = c.prototype.keySize = length / 8;
|
||||||
|
@ -502,7 +502,7 @@ function makeClass(length) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {}
|
module.exports = {};
|
||||||
|
|
||||||
var types = [128, 192, 256];
|
var types = [128, 192, 256];
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* The constructor doesn't do much of anything. It's just here
|
* The constructor doesn't do much of anything. It's just here
|
||||||
* so we can start defining properties and methods and such.
|
* so we can start defining properties and methods and such.
|
||||||
*/
|
*/
|
||||||
function Blowfish() {};
|
function Blowfish() {}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Declare the block size so that protocols know what size
|
* Declare the block size so that protocols know what size
|
||||||
|
@ -407,7 +407,7 @@ function BF(key) {
|
||||||
|
|
||||||
this.encrypt = function(block) {
|
this.encrypt = function(block) {
|
||||||
return this.bf.encrypt_block(block);
|
return this.bf.encrypt_block(block);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -252,19 +252,22 @@ function openpgp_symenc_cast5() {
|
||||||
var t = new Array(8);
|
var t = new Array(8);
|
||||||
var k = new Array(32);
|
var k = new Array(32);
|
||||||
|
|
||||||
for (var i = 0; i < 4; i++) {
|
var i, j;
|
||||||
var j = i * 4;
|
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
j = i * 4;
|
||||||
t[i] = inn[j] << 24 | inn[j + 1] << 16 | inn[j + 2] << 8 | inn[j + 3];
|
t[i] = inn[j] << 24 | inn[j + 1] << 16 | inn[j + 2] << 8 | inn[j + 3];
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = [6, 7, 4, 5];
|
var x = [6, 7, 4, 5];
|
||||||
var ki = 0;
|
var ki = 0;
|
||||||
|
var w;
|
||||||
|
|
||||||
for (var half = 0; half < 2; half++) {
|
for (var half = 0; half < 2; half++) {
|
||||||
for (var round = 0; round < 4; round++) {
|
for (var round = 0; round < 4; round++) {
|
||||||
for (var j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
var a = scheduleA[round][j];
|
var a = scheduleA[round][j];
|
||||||
var w = t[a[1]];
|
w = t[a[1]];
|
||||||
|
|
||||||
w ^= sBox[4][(t[a[2] >>> 2] >>> (24 - 8 * (a[2] & 3))) & 0xff];
|
w ^= sBox[4][(t[a[2] >>> 2] >>> (24 - 8 * (a[2] & 3))) & 0xff];
|
||||||
w ^= sBox[5][(t[a[3] >>> 2] >>> (24 - 8 * (a[3] & 3))) & 0xff];
|
w ^= sBox[5][(t[a[3] >>> 2] >>> (24 - 8 * (a[3] & 3))) & 0xff];
|
||||||
|
@ -274,9 +277,9 @@ function openpgp_symenc_cast5() {
|
||||||
t[a[0]] = w;
|
t[a[0]] = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
var b = scheduleB[round][j];
|
var b = scheduleB[round][j];
|
||||||
var w = sBox[4][(t[b[0] >>> 2] >>> (24 - 8 * (b[0] & 3))) & 0xff];
|
w = sBox[4][(t[b[0] >>> 2] >>> (24 - 8 * (b[0] & 3))) & 0xff];
|
||||||
|
|
||||||
w ^= sBox[5][(t[b[1] >>> 2] >>> (24 - 8 * (b[1] & 3))) & 0xff];
|
w ^= sBox[5][(t[b[1] >>> 2] >>> (24 - 8 * (b[1] & 3))) & 0xff];
|
||||||
w ^= sBox[6][(t[b[2] >>> 2] >>> (24 - 8 * (b[2] & 3))) & 0xff];
|
w ^= sBox[6][(t[b[2] >>> 2] >>> (24 - 8 * (b[2] & 3))) & 0xff];
|
||||||
|
@ -288,7 +291,7 @@ function openpgp_symenc_cast5() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
this.masking[i] = k[i];
|
this.masking[i] = k[i];
|
||||||
this.rotate[i] = k[16 + i] & 0x1f;
|
this.rotate[i] = k[16 + i] & 0x1f;
|
||||||
}
|
}
|
||||||
|
@ -587,8 +590,7 @@ function openpgp_symenc_cast5() {
|
||||||
0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347, 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82,
|
0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347, 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82,
|
||||||
0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e);
|
0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d, 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e);
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
var util = require('../../util');
|
var util = require('../../util');
|
||||||
|
|
||||||
function cast5(key) {
|
function cast5(key) {
|
||||||
|
@ -597,7 +599,7 @@ function cast5(key) {
|
||||||
|
|
||||||
this.encrypt = function(block) {
|
this.encrypt = function(block) {
|
||||||
return this.cast5.encrypt(block);
|
return this.cast5.encrypt(block);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = cast5;
|
module.exports = cast5;
|
||||||
|
|
|
@ -81,7 +81,7 @@ function des(keys, message, encrypt, mode, iv, padding) {
|
||||||
//create the 16 or 48 subkeys we will need
|
//create the 16 or 48 subkeys we will need
|
||||||
var m = 0,
|
var m = 0,
|
||||||
i, j, temp, temp2, right1, right2, left, right, looping;
|
i, j, temp, temp2, right1, right2, left, right, looping;
|
||||||
var cbcleft, cbcleft2, cbcright, cbcright2
|
var cbcleft, cbcleft2, cbcright, cbcright2;
|
||||||
var endloop, loopinc;
|
var endloop, loopinc;
|
||||||
var len = message.length;
|
var len = message.length;
|
||||||
var chunk = 0;
|
var chunk = 0;
|
||||||
|
@ -378,7 +378,7 @@ function Des(key) {
|
||||||
des(des_createKeys(this.key[0]),
|
des(des_createKeys(this.key[0]),
|
||||||
util.bin2str(block), true, 0, null, null),
|
util.bin2str(block), true, 0, null, null),
|
||||||
false, 0, null, null), true, 0, null, null));
|
false, 0, null, null), true, 0, null, null));
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Des.keySize = Des.prototype.keySize = 24;
|
Des.keySize = Des.prototype.keySize = 24;
|
||||||
|
@ -393,12 +393,12 @@ function OriginalDes(key) {
|
||||||
this.encrypt = function(block, padding) {
|
this.encrypt = function(block, padding) {
|
||||||
var keys = des_createKeys(this.key);
|
var keys = des_createKeys(this.key);
|
||||||
return util.str2bin(des(keys, util.bin2str(block), true, 0, null, padding));
|
return util.str2bin(des(keys, util.bin2str(block), true, 0, null, padding));
|
||||||
}
|
};
|
||||||
|
|
||||||
this.decrypt = function(block, padding) {
|
this.decrypt = function(block, padding) {
|
||||||
var keys = des_createKeys(this.key);
|
var keys = des_createKeys(this.key);
|
||||||
return util.str2bin(des(keys, util.bin2str(block), false, 0, null, padding));
|
return util.str2bin(des(keys, util.bin2str(block), false, 0, null, padding));
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -406,4 +406,4 @@ module.exports = {
|
||||||
des: Des,
|
des: Des,
|
||||||
/** @static */
|
/** @static */
|
||||||
originalDes: OriginalDes
|
originalDes: OriginalDes
|
||||||
}
|
};
|
||||||
|
|
|
@ -10,16 +10,16 @@ var desModule = require('./des.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/** @see module:crypto/cipher/des.des */
|
/** @see module:crypto/cipher/des.des */
|
||||||
des: desModule['des'],
|
des: desModule.des,
|
||||||
/** @see module:crypto/cipher/des.originalDes */
|
/** @see module:crypto/cipher/des.originalDes */
|
||||||
originalDes: desModule['originalDes'],
|
originalDes: desModule.originalDes,
|
||||||
/** @see module:crypto/cipher/cast5 */
|
/** @see module:crypto/cipher/cast5 */
|
||||||
cast5: require('./cast5.js'),
|
cast5: require('./cast5.js'),
|
||||||
/** @see module:crypto/cipher/twofish */
|
/** @see module:crypto/cipher/twofish */
|
||||||
twofish: require('./twofish.js'),
|
twofish: require('./twofish.js'),
|
||||||
/** @see module:crypto/cipher/blowfish */
|
/** @see module:crypto/cipher/blowfish */
|
||||||
blowfish: require('./blowfish.js')
|
blowfish: require('./blowfish.js')
|
||||||
}
|
};
|
||||||
|
|
||||||
var aes = require('./aes.js');
|
var aes = require('./aes.js');
|
||||||
|
|
||||||
|
|
|
@ -373,7 +373,7 @@ function TF(key) {
|
||||||
|
|
||||||
this.encrypt = function(block) {
|
this.encrypt = function(block) {
|
||||||
return this.tf.encrypt([].concat(block), 0);
|
return this.tf.encrypt([].concat(block), 0);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,14 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
publicKeyEncrypt: function(algo, publicMPIs, data) {
|
publicKeyEncrypt: function(algo, publicMPIs, data) {
|
||||||
var result = (function() {
|
var result = (function() {
|
||||||
|
var m;
|
||||||
switch (algo) {
|
switch (algo) {
|
||||||
case 'rsa_encrypt':
|
case 'rsa_encrypt':
|
||||||
case 'rsa_encrypt_sign':
|
case 'rsa_encrypt_sign':
|
||||||
var rsa = new publicKey.rsa();
|
var rsa = new publicKey.rsa();
|
||||||
var n = publicMPIs[0].toBigInteger();
|
var n = publicMPIs[0].toBigInteger();
|
||||||
var e = publicMPIs[1].toBigInteger();
|
var e = publicMPIs[1].toBigInteger();
|
||||||
var m = data.toBigInteger();
|
m = data.toBigInteger();
|
||||||
return [rsa.encrypt(m, e, n)];
|
return [rsa.encrypt(m, e, n)];
|
||||||
|
|
||||||
case 'elgamal':
|
case 'elgamal':
|
||||||
|
@ -56,7 +57,7 @@ module.exports = {
|
||||||
var p = publicMPIs[0].toBigInteger();
|
var p = publicMPIs[0].toBigInteger();
|
||||||
var g = publicMPIs[1].toBigInteger();
|
var g = publicMPIs[1].toBigInteger();
|
||||||
var y = publicMPIs[2].toBigInteger();
|
var y = publicMPIs[2].toBigInteger();
|
||||||
var m = data.toBigInteger();
|
m = data.toBigInteger();
|
||||||
return elgamal.encrypt(m, g, p, y);
|
return elgamal.encrypt(m, g, p, y);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -84,6 +85,8 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
publicKeyDecrypt: function(algo, keyIntegers, dataIntegers) {
|
publicKeyDecrypt: function(algo, keyIntegers, dataIntegers) {
|
||||||
|
var p;
|
||||||
|
|
||||||
var bn = (function() {
|
var bn = (function() {
|
||||||
switch (algo) {
|
switch (algo) {
|
||||||
case 'rsa_encrypt_sign':
|
case 'rsa_encrypt_sign':
|
||||||
|
@ -91,7 +94,7 @@ module.exports = {
|
||||||
var rsa = new publicKey.rsa();
|
var rsa = new publicKey.rsa();
|
||||||
// 0 and 1 are the public key.
|
// 0 and 1 are the public key.
|
||||||
var d = keyIntegers[2].toBigInteger();
|
var d = keyIntegers[2].toBigInteger();
|
||||||
var p = keyIntegers[3].toBigInteger();
|
p = keyIntegers[3].toBigInteger();
|
||||||
var q = keyIntegers[4].toBigInteger();
|
var q = keyIntegers[4].toBigInteger();
|
||||||
var u = keyIntegers[5].toBigInteger();
|
var u = keyIntegers[5].toBigInteger();
|
||||||
var m = dataIntegers[0].toBigInteger();
|
var m = dataIntegers[0].toBigInteger();
|
||||||
|
@ -101,7 +104,7 @@ module.exports = {
|
||||||
var x = keyIntegers[3].toBigInteger();
|
var x = keyIntegers[3].toBigInteger();
|
||||||
var c1 = dataIntegers[0].toBigInteger();
|
var c1 = dataIntegers[0].toBigInteger();
|
||||||
var c2 = dataIntegers[1].toBigInteger();
|
var c2 = dataIntegers[1].toBigInteger();
|
||||||
var p = keyIntegers[0].toBigInteger();
|
p = keyIntegers[0].toBigInteger();
|
||||||
return elgamal.decrypt(c1, c2, p, x);
|
return elgamal.decrypt(c1, c2, p, x);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -74,7 +74,7 @@ module.exports = {
|
||||||
return 32;
|
return 32;
|
||||||
case 9:
|
case 9:
|
||||||
// - SHA384 [FIPS180]
|
// - SHA384 [FIPS180]
|
||||||
return 48
|
return 48;
|
||||||
case 10:
|
case 10:
|
||||||
// - SHA512 [FIPS180]
|
// - SHA512 [FIPS180]
|
||||||
return 64;
|
return 64;
|
||||||
|
@ -85,4 +85,4 @@ module.exports = {
|
||||||
throw new Error('Invalid hash algorithm.');
|
throw new Error('Invalid hash algorithm.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ module.exports = function (entree) {
|
||||||
var hex = md5(entree);
|
var hex = md5(entree);
|
||||||
var bin = util.hex2bin(hex);
|
var bin = util.hex2bin(hex);
|
||||||
return bin;
|
return bin;
|
||||||
}
|
};
|
||||||
|
|
||||||
function md5cycle(x, k) {
|
function md5cycle(x, k) {
|
||||||
var a = x[0],
|
var a = x[0],
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var RMDsize = 160;
|
var RMDsize = 160;
|
||||||
var X = new Array();
|
var X = [];
|
||||||
|
|
||||||
function ROL(x, n) {
|
function ROL(x, n) {
|
||||||
return new Number((x << n) | (x >>> (32 - n)));
|
return new Number((x << n) | (x >>> (32 - n)));
|
||||||
|
@ -98,7 +98,7 @@ function mixOneRound(a, b, c, d, e, x, s, roundNumber) {
|
||||||
d &= 0xffffffff;
|
d &= 0xffffffff;
|
||||||
e &= 0xffffffff;
|
e &= 0xffffffff;
|
||||||
|
|
||||||
var retBlock = new Array();
|
var retBlock = [];
|
||||||
retBlock[0] = a;
|
retBlock[0] = a;
|
||||||
retBlock[1] = b;
|
retBlock[1] = b;
|
||||||
retBlock[2] = c;
|
retBlock[2] = c;
|
||||||
|
@ -145,19 +145,21 @@ var indexes = [
|
||||||
];
|
];
|
||||||
|
|
||||||
function compress(MDbuf, X) {
|
function compress(MDbuf, X) {
|
||||||
blockA = new Array();
|
blockA = [];
|
||||||
blockB = new Array();
|
blockB = [];
|
||||||
|
|
||||||
var retBlock;
|
var retBlock;
|
||||||
|
|
||||||
for (var i = 0; i < 5; i++) {
|
var i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
blockA[i] = new Number(MDbuf[i]);
|
blockA[i] = new Number(MDbuf[i]);
|
||||||
blockB[i] = new Number(MDbuf[i]);
|
blockB[i] = new Number(MDbuf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var step = 0;
|
var step = 0;
|
||||||
for (var j = 0; j < 5; j++) {
|
for (j = 0; j < 5; j++) {
|
||||||
for (var i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
retBlock = mixOneRound(
|
retBlock = mixOneRound(
|
||||||
blockA[(step + 0) % 5],
|
blockA[(step + 0) % 5],
|
||||||
blockA[(step + 1) % 5],
|
blockA[(step + 1) % 5],
|
||||||
|
@ -179,8 +181,8 @@ function compress(MDbuf, X) {
|
||||||
}
|
}
|
||||||
|
|
||||||
step = 0;
|
step = 0;
|
||||||
for (var j = 5; j < 10; j++) {
|
for (j = 5; j < 10; j++) {
|
||||||
for (var i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
retBlock = mixOneRound(
|
retBlock = mixOneRound(
|
||||||
blockB[(step + 0) % 5],
|
blockB[(step + 0) % 5],
|
||||||
blockB[(step + 1) % 5],
|
blockB[(step + 1) % 5],
|
||||||
|
@ -228,7 +230,7 @@ function MDfinish(MDbuf, strptr, lswlen, mswlen) {
|
||||||
|
|
||||||
if ((lswlen & 63) > 55) {
|
if ((lswlen & 63) > 55) {
|
||||||
compress(MDbuf, X);
|
compress(MDbuf, X);
|
||||||
var X = new Array(16);
|
X = new Array(16);
|
||||||
zeroX(X);
|
zeroX(X);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,9 +261,9 @@ function RMD(message) {
|
||||||
var X = new Array(16);
|
var X = new Array(16);
|
||||||
zeroX(X);
|
zeroX(X);
|
||||||
|
|
||||||
var j = 0;
|
var i, j = 0;
|
||||||
for (var nbytes = length; nbytes > 63; nbytes -= 64) {
|
for (nbytes = length; nbytes > 63; nbytes -= 64) {
|
||||||
for (var i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
X[i] = BYTES_TO_DWORD(message.substr(j, 4));
|
X[i] = BYTES_TO_DWORD(message.substr(j, 4));
|
||||||
j += 4;
|
j += 4;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +272,7 @@ function RMD(message) {
|
||||||
|
|
||||||
MDfinish(MDbuf, message.substr(j), length, 0);
|
MDfinish(MDbuf, message.substr(j), length, 0);
|
||||||
|
|
||||||
for (var i = 0; i < RMDsize / 8; i += 4) {
|
for (i = 0; i < RMDsize / 8; i += 4) {
|
||||||
hashcode[i] = MDbuf[i >>> 2] & 255;
|
hashcode[i] = MDbuf[i >>> 2] & 255;
|
||||||
hashcode[i + 1] = (MDbuf[i >>> 2] >>> 8) & 255;
|
hashcode[i + 1] = (MDbuf[i >>> 2] >>> 8) & 255;
|
||||||
hashcode[i + 2] = (MDbuf[i >>> 2] >>> 16) & 255;
|
hashcode[i + 2] = (MDbuf[i >>> 2] >>> 16) & 255;
|
||||||
|
|
|
@ -1122,4 +1122,4 @@ module.exports = {
|
||||||
var shaObj = new jsSHA(str, "ASCII");
|
var shaObj = new jsSHA(str, "ASCII");
|
||||||
return shaObj.getHash("SHA-512", "ASCII");
|
return shaObj.getHash("SHA-512", "ASCII");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -17,8 +17,7 @@ module.exports = {
|
||||||
random: require('./random.js'),
|
random: require('./random.js'),
|
||||||
/** @see module:crypto/pkcs1 */
|
/** @see module:crypto/pkcs1 */
|
||||||
pkcs1: require('./pkcs1.js')
|
pkcs1: require('./pkcs1.js')
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
var crypto = require('./crypto.js');
|
var crypto = require('./crypto.js');
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
/**
|
/**
|
||||||
* ASN1 object identifiers for hashes (See RFC4880 5.2.2)
|
* ASN1 object identifiers for hashes (See RFC4880 5.2.2)
|
||||||
*/
|
*/
|
||||||
hash_headers = new Array();
|
hash_headers = [];
|
||||||
hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04,
|
hash_headers[1] = [0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04,
|
||||||
0x10
|
0x10
|
||||||
];
|
];
|
||||||
|
@ -83,10 +83,10 @@ module.exports = {
|
||||||
decode: function(message, len) {
|
decode: function(message, len) {
|
||||||
if (message.length < len)
|
if (message.length < len)
|
||||||
message = String.fromCharCode(0) + message;
|
message = String.fromCharCode(0) + message;
|
||||||
if (message.length < 12 || message.charCodeAt(0) != 0 || message.charCodeAt(1) != 2)
|
if (message.length < 12 || message.charCodeAt(0) !== 0 || message.charCodeAt(1) != 2)
|
||||||
return -1;
|
return -1;
|
||||||
var i = 2;
|
var i = 2;
|
||||||
while (message.charCodeAt(i) != 0 && message.length > i)
|
while (message.charCodeAt(i) !== 0 && message.length > i)
|
||||||
i++;
|
i++;
|
||||||
return message.substring(i + 1, message.length);
|
return message.substring(i + 1, message.length);
|
||||||
}
|
}
|
||||||
|
@ -105,14 +105,15 @@ module.exports = {
|
||||||
var data2 = "";
|
var data2 = "";
|
||||||
data2 += String.fromCharCode(0x00);
|
data2 += String.fromCharCode(0x00);
|
||||||
data2 += String.fromCharCode(0x01);
|
data2 += String.fromCharCode(0x01);
|
||||||
for (var i = 0; i < (keylength - hash_headers[algo].length - 3 -
|
var i;
|
||||||
|
for (i = 0; i < (keylength - hash_headers[algo].length - 3 -
|
||||||
hash.getHashByteLength(algo)); i++)
|
hash.getHashByteLength(algo)); i++)
|
||||||
|
|
||||||
data2 += String.fromCharCode(0xff);
|
data2 += String.fromCharCode(0xff);
|
||||||
|
|
||||||
data2 += String.fromCharCode(0x00);
|
data2 += String.fromCharCode(0x00);
|
||||||
|
|
||||||
for (var i = 0; i < hash_headers[algo].length; i++)
|
for (i = 0; i < hash_headers[algo].length; i++)
|
||||||
data2 += String.fromCharCode(hash_headers[algo][i]);
|
data2 += String.fromCharCode(hash_headers[algo][i]);
|
||||||
|
|
||||||
data2 += hash.digest(algo, data);
|
data2 += hash.digest(algo, data);
|
||||||
|
@ -126,12 +127,12 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
decode: function(algo, data) {
|
decode: function(algo, data) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
if (data.charCodeAt(0) == 0) i++;
|
if (data.charCodeAt(0) === 0) i++;
|
||||||
else if (data.charCodeAt(0) != 1) return -1;
|
else if (data.charCodeAt(0) != 1) return -1;
|
||||||
else i++;
|
else i++;
|
||||||
|
|
||||||
while (data.charCodeAt(i) == 0xFF) i++;
|
while (data.charCodeAt(i) == 0xFF) i++;
|
||||||
if (data.charCodeAt(i++) != 0) return -1;
|
if (data.charCodeAt(i++) !== 0) return -1;
|
||||||
var j = 0;
|
var j = 0;
|
||||||
for (j = 0; j < hash_headers[algo].length && j + i < data.length; j++) {
|
for (j = 0; j < hash_headers[algo].length && j + i < data.length; j++) {
|
||||||
if (data.charCodeAt(j + i) != hash_headers[algo][j]) return -1;
|
if (data.charCodeAt(j + i) != hash_headers[algo][j]) return -1;
|
||||||
|
@ -141,4 +142,4 @@ module.exports = {
|
||||||
return data.substring(i);
|
return data.substring(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -45,7 +45,7 @@ function DSA() {
|
||||||
var k = random.getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE), q.subtract(BigInteger.ONE));
|
var k = random.getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE), q.subtract(BigInteger.ONE));
|
||||||
var s1 = (g.modPow(k, p)).mod(q);
|
var s1 = (g.modPow(k, p)).mod(q);
|
||||||
var s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q);
|
var s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q);
|
||||||
var result = new Array();
|
var result = [];
|
||||||
result[0] = s1.toMPI();
|
result[0] = s1.toMPI();
|
||||||
result[1] = s2.toMPI();
|
result[1] = s2.toMPI();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -11,4 +11,4 @@ module.exports = {
|
||||||
elgamal: require('./elgamal.js'),
|
elgamal: require('./elgamal.js'),
|
||||||
/** @see module:crypto/public_key/dsa */
|
/** @see module:crypto/public_key/dsa */
|
||||||
dsa: require('./dsa.js')
|
dsa: require('./dsa.js')
|
||||||
}
|
};
|
||||||
|
|
|
@ -51,9 +51,9 @@ var j_lm = ((canary & 0xffffff) == 0xefcafe);
|
||||||
// (public) Constructor
|
// (public) Constructor
|
||||||
|
|
||||||
function BigInteger(a, b, c) {
|
function BigInteger(a, b, c) {
|
||||||
if (a != null)
|
if (a !== null)
|
||||||
if ("number" == typeof a) this.fromNumber(a, b, c);
|
if ("number" == typeof a) this.fromNumber(a, b, c);
|
||||||
else if (b == null && "string" != typeof a) this.fromString(a, 256);
|
else if (b === null && "string" != typeof a) this.fromString(a, 256);
|
||||||
else this.fromString(a, b);
|
else this.fromString(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ BigInteger.prototype.F2 = 2 * dbits - BI_FP;
|
||||||
|
|
||||||
// Digit conversions
|
// Digit conversions
|
||||||
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
var BI_RC = new Array();
|
var BI_RC = [];
|
||||||
var rr, vv;
|
var rr, vv;
|
||||||
rr = "0".charCodeAt(0);
|
rr = "0".charCodeAt(0);
|
||||||
for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||||||
|
@ -153,7 +153,7 @@ function int2char(n) {
|
||||||
|
|
||||||
function intAt(s, i) {
|
function intAt(s, i) {
|
||||||
var c = BI_RC[s.charCodeAt(i)];
|
var c = BI_RC[s.charCodeAt(i)];
|
||||||
return (c == null) ? -1 : c;
|
return (c === null) ? -1 : c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (protected) copy this to r
|
// (protected) copy this to r
|
||||||
|
@ -208,7 +208,7 @@ function bnpFromString(s, b) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
mi = false;
|
mi = false;
|
||||||
if (sh == 0)
|
if (sh === 0)
|
||||||
this[this.t++] = x;
|
this[this.t++] = x;
|
||||||
else if (sh + k > this.DB) {
|
else if (sh + k > this.DB) {
|
||||||
this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
|
this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
|
||||||
|
@ -218,7 +218,7 @@ function bnpFromString(s, b) {
|
||||||
sh += k;
|
sh += k;
|
||||||
if (sh >= this.DB) sh -= this.DB;
|
if (sh >= this.DB) sh -= this.DB;
|
||||||
}
|
}
|
||||||
if (k == 8 && (s[0] & 0x80) != 0) {
|
if (k == 8 && (s[0] & 0x80) !== 0) {
|
||||||
this.s = -1;
|
this.s = -1;
|
||||||
if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
|
if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
|
||||||
}
|
}
|
||||||
|
@ -290,11 +290,11 @@ function bnAbs() {
|
||||||
|
|
||||||
function bnCompareTo(a) {
|
function bnCompareTo(a) {
|
||||||
var r = this.s - a.s;
|
var r = this.s - a.s;
|
||||||
if (r != 0) return r;
|
if (r !== 0) return r;
|
||||||
var i = this.t;
|
var i = this.t;
|
||||||
r = i - a.t;
|
r = i - a.t;
|
||||||
if (r != 0) return r;
|
if (r !== 0) return r;
|
||||||
while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r;
|
while (--i >= 0) if ((r = this[i] - a[i]) !== 0) return r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,23 +303,23 @@ function bnCompareTo(a) {
|
||||||
function nbits(x) {
|
function nbits(x) {
|
||||||
var r = 1,
|
var r = 1,
|
||||||
t;
|
t;
|
||||||
if ((t = x >>> 16) != 0) {
|
if ((t = x >>> 16) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
r += 16;
|
r += 16;
|
||||||
}
|
}
|
||||||
if ((t = x >> 8) != 0) {
|
if ((t = x >> 8) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
r += 8;
|
r += 8;
|
||||||
}
|
}
|
||||||
if ((t = x >> 4) != 0) {
|
if ((t = x >> 4) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
r += 4;
|
r += 4;
|
||||||
}
|
}
|
||||||
if ((t = x >> 2) != 0) {
|
if ((t = x >> 2) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
r += 2;
|
r += 2;
|
||||||
}
|
}
|
||||||
if ((t = x >> 1) != 0) {
|
if ((t = x >> 1) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
r += 1;
|
r += 1;
|
||||||
}
|
}
|
||||||
|
@ -469,11 +469,11 @@ function bnpDivRemTo(m, q, r) {
|
||||||
if (pm.t <= 0) return;
|
if (pm.t <= 0) return;
|
||||||
var pt = this.abs();
|
var pt = this.abs();
|
||||||
if (pt.t < pm.t) {
|
if (pt.t < pm.t) {
|
||||||
if (q != null) q.fromInt(0);
|
if (q !== null) q.fromInt(0);
|
||||||
if (r != null) this.copyTo(r);
|
if (r !== null) this.copyTo(r);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (r == null) r = nbi();
|
if (r === null) r = nbi();
|
||||||
var y = nbi(),
|
var y = nbi(),
|
||||||
ts = this.s,
|
ts = this.s,
|
||||||
ms = m.s;
|
ms = m.s;
|
||||||
|
@ -487,14 +487,14 @@ function bnpDivRemTo(m, q, r) {
|
||||||
}
|
}
|
||||||
var ys = y.t;
|
var ys = y.t;
|
||||||
var y0 = y[ys - 1];
|
var y0 = y[ys - 1];
|
||||||
if (y0 == 0) return;
|
if (y0 === 0) return;
|
||||||
var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
|
var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
|
||||||
var d1 = this.FV / yt,
|
var d1 = this.FV / yt,
|
||||||
d2 = (1 << this.F1) / yt,
|
d2 = (1 << this.F1) / yt,
|
||||||
e = 1 << this.F2;
|
e = 1 << this.F2;
|
||||||
var i = r.t,
|
var i = r.t,
|
||||||
j = i - ys,
|
j = i - ys,
|
||||||
t = (q == null) ? nbi() : q;
|
t = (q === null) ? nbi() : q;
|
||||||
y.dlShiftTo(j, t);
|
y.dlShiftTo(j, t);
|
||||||
if (r.compareTo(t) >= 0) {
|
if (r.compareTo(t) >= 0) {
|
||||||
r[r.t++] = 1;
|
r[r.t++] = 1;
|
||||||
|
@ -512,7 +512,7 @@ function bnpDivRemTo(m, q, r) {
|
||||||
while (r[i] < --qd) r.subTo(t, r);
|
while (r[i] < --qd) r.subTo(t, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (q != null) {
|
if (q !== null) {
|
||||||
r.drShiftTo(ys, q);
|
r.drShiftTo(ys, q);
|
||||||
if (ts != ms) BigInteger.ZERO.subTo(q, q);
|
if (ts != ms) BigInteger.ZERO.subTo(q, q);
|
||||||
}
|
}
|
||||||
|
@ -580,7 +580,7 @@ Classic.prototype.sqrTo = cSqrTo;
|
||||||
function bnpInvDigit() {
|
function bnpInvDigit() {
|
||||||
if (this.t < 1) return 0;
|
if (this.t < 1) return 0;
|
||||||
var x = this[0];
|
var x = this[0];
|
||||||
if ((x & 1) == 0) return 0;
|
if ((x & 1) === 0) return 0;
|
||||||
var y = x & 3; // y == 1/x mod 2^2
|
var y = x & 3; // y == 1/x mod 2^2
|
||||||
y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
|
y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
|
||||||
y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
|
y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
|
||||||
|
@ -668,7 +668,7 @@ Montgomery.prototype.sqrTo = montSqrTo;
|
||||||
// (protected) true iff this is even
|
// (protected) true iff this is even
|
||||||
|
|
||||||
function bnpIsEven() {
|
function bnpIsEven() {
|
||||||
return ((this.t > 0) ? (this[0] & 1) : this.s) == 0;
|
return ((this.t > 0) ? (this[0] & 1) : this.s) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||||
|
@ -802,9 +802,9 @@ function bnClone() {
|
||||||
function bnIntValue() {
|
function bnIntValue() {
|
||||||
if (this.s < 0) {
|
if (this.s < 0) {
|
||||||
if (this.t == 1) return this[0] - this.DV;
|
if (this.t == 1) return this[0] - this.DV;
|
||||||
else if (this.t == 0) return -1;
|
else if (this.t === 0) return -1;
|
||||||
} else if (this.t == 1) return this[0];
|
} else if (this.t == 1) return this[0];
|
||||||
else if (this.t == 0) return 0;
|
else if (this.t === 0) return 0;
|
||||||
// assumes 16 < DB < 32
|
// assumes 16 < DB < 32
|
||||||
return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
|
return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
|
||||||
}
|
}
|
||||||
|
@ -812,13 +812,13 @@ function bnIntValue() {
|
||||||
// (public) return value as byte
|
// (public) return value as byte
|
||||||
|
|
||||||
function bnByteValue() {
|
function bnByteValue() {
|
||||||
return (this.t == 0) ? this.s : (this[0] << 24) >> 24;
|
return (this.t === 0) ? this.s : (this[0] << 24) >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (public) return value as short (assumes DB>=16)
|
// (public) return value as short (assumes DB>=16)
|
||||||
|
|
||||||
function bnShortValue() {
|
function bnShortValue() {
|
||||||
return (this.t == 0) ? this.s : (this[0] << 16) >> 16;
|
return (this.t === 0) ? this.s : (this[0] << 16) >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (protected) return x s.t. r^x < DV
|
// (protected) return x s.t. r^x < DV
|
||||||
|
@ -838,8 +838,8 @@ function bnSigNum() {
|
||||||
// (protected) convert to radix string
|
// (protected) convert to radix string
|
||||||
|
|
||||||
function bnpToRadix(b) {
|
function bnpToRadix(b) {
|
||||||
if (b == null) b = 10;
|
if (b === null) b = 10;
|
||||||
if (this.signum() == 0 || b < 2 || b > 36) return "0";
|
if (this.signum() === 0 || b < 2 || b > 36) return "0";
|
||||||
var cs = this.chunkSize(b);
|
var cs = this.chunkSize(b);
|
||||||
var a = Math.pow(b, cs);
|
var a = Math.pow(b, cs);
|
||||||
var d = nbv(a),
|
var d = nbv(a),
|
||||||
|
@ -858,7 +858,7 @@ function bnpToRadix(b) {
|
||||||
|
|
||||||
function bnpFromRadix(s, b) {
|
function bnpFromRadix(s, b) {
|
||||||
this.fromInt(0);
|
this.fromInt(0);
|
||||||
if (b == null) b = 10;
|
if (b === null) b = 10;
|
||||||
var cs = this.chunkSize(b);
|
var cs = this.chunkSize(b);
|
||||||
var d = Math.pow(b, cs),
|
var d = Math.pow(b, cs),
|
||||||
mi = false,
|
mi = false,
|
||||||
|
@ -867,7 +867,7 @@ function bnpFromRadix(s, b) {
|
||||||
for (var i = 0; i < s.length; ++i) {
|
for (var i = 0; i < s.length; ++i) {
|
||||||
var x = intAt(s, i);
|
var x = intAt(s, i);
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
if (s.charAt(i) == "-" && this.signum() == 0) mi = true;
|
if (s.charAt(i) == "-" && this.signum() === 0) mi = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
w = b * w + x;
|
w = b * w + x;
|
||||||
|
@ -903,7 +903,7 @@ function bnpFromNumber(a, b, c) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// new BigInteger(int,RNG)
|
// new BigInteger(int,RNG)
|
||||||
var x = new Array(),
|
var x = [],
|
||||||
t = a & 7;
|
t = a & 7;
|
||||||
x.length = (a >> 3) + 1;
|
x.length = (a >> 3) + 1;
|
||||||
b.nextBytes(x);
|
b.nextBytes(x);
|
||||||
|
@ -917,7 +917,7 @@ function bnpFromNumber(a, b, c) {
|
||||||
|
|
||||||
function bnToByteArray() {
|
function bnToByteArray() {
|
||||||
var i = this.t,
|
var i = this.t,
|
||||||
r = new Array();
|
r = [];
|
||||||
r[0] = this.s;
|
r[0] = this.s;
|
||||||
var p = this.DB - (i * this.DB) % 8,
|
var p = this.DB - (i * this.DB) % 8,
|
||||||
d, k = 0;
|
d, k = 0;
|
||||||
|
@ -944,7 +944,7 @@ function bnToByteArray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bnEquals(a) {
|
function bnEquals(a) {
|
||||||
return (this.compareTo(a) == 0);
|
return (this.compareTo(a) === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bnMin(a) {
|
function bnMin(a) {
|
||||||
|
@ -1052,25 +1052,25 @@ function bnShiftRight(n) {
|
||||||
// return index of lowest 1-bit in x, x < 2^31
|
// return index of lowest 1-bit in x, x < 2^31
|
||||||
|
|
||||||
function lbit(x) {
|
function lbit(x) {
|
||||||
if (x == 0) return -1;
|
if (x === 0) return -1;
|
||||||
var r = 0;
|
var r = 0;
|
||||||
if ((x & 0xffff) == 0) {
|
if ((x & 0xffff) === 0) {
|
||||||
x >>= 16;
|
x >>= 16;
|
||||||
r += 16;
|
r += 16;
|
||||||
}
|
}
|
||||||
if ((x & 0xff) == 0) {
|
if ((x & 0xff) === 0) {
|
||||||
x >>= 8;
|
x >>= 8;
|
||||||
r += 8;
|
r += 8;
|
||||||
}
|
}
|
||||||
if ((x & 0xf) == 0) {
|
if ((x & 0xf) === 0) {
|
||||||
x >>= 4;
|
x >>= 4;
|
||||||
r += 4;
|
r += 4;
|
||||||
}
|
}
|
||||||
if ((x & 3) == 0) {
|
if ((x & 3) === 0) {
|
||||||
x >>= 2;
|
x >>= 2;
|
||||||
r += 2;
|
r += 2;
|
||||||
}
|
}
|
||||||
if ((x & 1) == 0)++r;
|
if ((x & 1) === 0)++r;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1078,7 +1078,7 @@ function lbit(x) {
|
||||||
|
|
||||||
function bnGetLowestSetBit() {
|
function bnGetLowestSetBit() {
|
||||||
for (var i = 0; i < this.t; ++i)
|
for (var i = 0; i < this.t; ++i)
|
||||||
if (this[i] != 0) return i * this.DB + lbit(this[i]);
|
if (this[i] !== 0) return i * this.DB + lbit(this[i]);
|
||||||
if (this.s < 0) return this.t * this.DB;
|
if (this.s < 0) return this.t * this.DB;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1087,7 +1087,7 @@ function bnGetLowestSetBit() {
|
||||||
|
|
||||||
function cbit(x) {
|
function cbit(x) {
|
||||||
var r = 0;
|
var r = 0;
|
||||||
while (x != 0) {
|
while (x !== 0) {
|
||||||
x &= x - 1;
|
x &= x - 1;
|
||||||
++r;
|
++r;
|
||||||
}
|
}
|
||||||
|
@ -1107,8 +1107,8 @@ function bnBitCount() {
|
||||||
|
|
||||||
function bnTestBit(n) {
|
function bnTestBit(n) {
|
||||||
var j = Math.floor(n / this.DB);
|
var j = Math.floor(n / this.DB);
|
||||||
if (j >= this.t) return (this.s != 0);
|
if (j >= this.t) return (this.s !== 0);
|
||||||
return ((this[j] & (1 << (n % this.DB))) != 0);
|
return ((this[j] & (1 << (n % this.DB))) !== 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (protected) this op (1<<n)
|
// (protected) this op (1<<n)
|
||||||
|
@ -1240,7 +1240,7 @@ function bnpDMultiply(n) {
|
||||||
// (protected) this += n << w words, this >= 0
|
// (protected) this += n << w words, this >= 0
|
||||||
|
|
||||||
function bnpDAddOffset(n, w) {
|
function bnpDAddOffset(n, w) {
|
||||||
if (n == 0) return;
|
if (n === 0) return;
|
||||||
while (this.t <= w) this[this.t++] = 0;
|
while (this.t <= w) this[this.t++] = 0;
|
||||||
this[w] += n;
|
this[w] += n;
|
||||||
while (this[w] >= this.DV) {
|
while (this[w] >= this.DV) {
|
||||||
|
@ -1386,7 +1386,7 @@ function bnModPow(e, m) {
|
||||||
z = new Montgomery(m);
|
z = new Montgomery(m);
|
||||||
|
|
||||||
// precomputation
|
// precomputation
|
||||||
var g = new Array(),
|
var g = [],
|
||||||
n = 3,
|
n = 3,
|
||||||
k1 = k - 1,
|
k1 = k - 1,
|
||||||
km = (1 << k) - 1;
|
km = (1 << k) - 1;
|
||||||
|
@ -1414,7 +1414,7 @@ function bnModPow(e, m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
n = k;
|
n = k;
|
||||||
while ((w & 1) == 0) {
|
while ((w & 1) === 0) {
|
||||||
w >>= 1;
|
w >>= 1;
|
||||||
--n;
|
--n;
|
||||||
}
|
}
|
||||||
|
@ -1440,7 +1440,7 @@ function bnModPow(e, m) {
|
||||||
z.mulTo(r2, g[w], r);
|
z.mulTo(r2, g[w], r);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (j >= 0 && (e[j] & (1 << i)) == 0) {
|
while (j >= 0 && (e[j] & (1 << i)) === 0) {
|
||||||
z.sqrTo(r, r2);
|
z.sqrTo(r, r2);
|
||||||
t = r;
|
t = r;
|
||||||
r = r2;
|
r = r2;
|
||||||
|
@ -1494,7 +1494,7 @@ function bnpModInt(n) {
|
||||||
var d = this.DV % n,
|
var d = this.DV % n,
|
||||||
r = (this.s < 0) ? n - 1 : 0;
|
r = (this.s < 0) ? n - 1 : 0;
|
||||||
if (this.t > 0)
|
if (this.t > 0)
|
||||||
if (d == 0) r = this[0] % n;
|
if (d === 0) r = this[0] % n;
|
||||||
else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n;
|
else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -1503,14 +1503,14 @@ function bnpModInt(n) {
|
||||||
|
|
||||||
function bnModInverse(m) {
|
function bnModInverse(m) {
|
||||||
var ac = m.isEven();
|
var ac = m.isEven();
|
||||||
if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
|
if ((this.isEven() && ac) || m.signum() === 0) return BigInteger.ZERO;
|
||||||
var u = m.clone(),
|
var u = m.clone(),
|
||||||
v = this.clone();
|
v = this.clone();
|
||||||
var a = nbv(1),
|
var a = nbv(1),
|
||||||
b = nbv(0),
|
b = nbv(0),
|
||||||
c = nbv(0),
|
c = nbv(0),
|
||||||
d = nbv(1);
|
d = nbv(1);
|
||||||
while (u.signum() != 0) {
|
while (u.signum() !== 0) {
|
||||||
while (u.isEven()) {
|
while (u.isEven()) {
|
||||||
u.rShiftTo(1, u);
|
u.rShiftTo(1, u);
|
||||||
if (ac) {
|
if (ac) {
|
||||||
|
@ -1543,7 +1543,7 @@ function bnModInverse(m) {
|
||||||
d.subTo(b, d);
|
d.subTo(b, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
|
if (v.compareTo(BigInteger.ONE) !== 0) return BigInteger.ZERO;
|
||||||
if (d.compareTo(m) >= 0) return d.subtract(m);
|
if (d.compareTo(m) >= 0) return d.subtract(m);
|
||||||
if (d.signum() < 0) d.addTo(m, d);
|
if (d.signum() < 0) d.addTo(m, d);
|
||||||
else return d;
|
else return d;
|
||||||
|
@ -1578,7 +1578,7 @@ function bnIsProbablePrime(t) {
|
||||||
j = i + 1;
|
j = i + 1;
|
||||||
while (j < lowprimes.length && m < lplim) m *= lowprimes[j++];
|
while (j < lowprimes.length && m < lplim) m *= lowprimes[j++];
|
||||||
m = x.modInt(m);
|
m = x.modInt(m);
|
||||||
while (i < j) if (m % lowprimes[i++] == 0) return false;
|
while (i < j) if (m % lowprimes[i++] === 0) return false;
|
||||||
}
|
}
|
||||||
return x.millerRabin(t);
|
return x.millerRabin(t);
|
||||||
}
|
}
|
||||||
|
@ -1588,23 +1588,23 @@ function bnIsProbablePrime(t) {
|
||||||
function nbits(x) {
|
function nbits(x) {
|
||||||
var n = 1,
|
var n = 1,
|
||||||
t;
|
t;
|
||||||
if ((t = x >>> 16) != 0) {
|
if ((t = x >>> 16) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
n += 16;
|
n += 16;
|
||||||
}
|
}
|
||||||
if ((t = x >> 8) != 0) {
|
if ((t = x >> 8) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
n += 8;
|
n += 8;
|
||||||
}
|
}
|
||||||
if ((t = x >> 4) != 0) {
|
if ((t = x >> 4) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
n += 4;
|
n += 4;
|
||||||
}
|
}
|
||||||
if ((t = x >> 2) != 0) {
|
if ((t = x >> 2) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
n += 2;
|
n += 2;
|
||||||
}
|
}
|
||||||
if ((t = x >> 1) != 0) {
|
if ((t = x >> 1) !== 0) {
|
||||||
x = t;
|
x = t;
|
||||||
n += 1;
|
n += 1;
|
||||||
}
|
}
|
||||||
|
@ -1641,13 +1641,13 @@ function bnpMillerRabin(t) {
|
||||||
bases.push(j);
|
bases.push(j);
|
||||||
a.fromInt(j);
|
a.fromInt(j);
|
||||||
var y = a.modPow(r, this);
|
var y = a.modPow(r, this);
|
||||||
if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
|
if (y.compareTo(BigInteger.ONE) !== 0 && y.compareTo(n1) !== 0) {
|
||||||
var j = 1;
|
j = 1;
|
||||||
while (j++ < k && y.compareTo(n1) != 0) {
|
while (j++ < k && y.compareTo(n1) !== 0) {
|
||||||
y = y.modPowInt(2, this);
|
y = y.modPowInt(2, this);
|
||||||
if (y.compareTo(BigInteger.ONE) == 0) return false;
|
if (y.compareTo(BigInteger.ONE) === 0) return false;
|
||||||
}
|
}
|
||||||
if (y.compareTo(n1) != 0) return false;
|
if (y.compareTo(n1) !== 0) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -58,7 +58,7 @@ function RSA() {
|
||||||
util.print_debug("rsa.js decrypt\nxpn:" + util.hexstrdump(xp.toMPI()) + "\nxqn:" + util.hexstrdump(xq.toMPI()));
|
util.print_debug("rsa.js decrypt\nxpn:" + util.hexstrdump(xp.toMPI()) + "\nxqn:" + util.hexstrdump(xq.toMPI()));
|
||||||
|
|
||||||
var t = xq.subtract(xp);
|
var t = xq.subtract(xp);
|
||||||
if (t[0] == 0) {
|
if (t[0] === 0) {
|
||||||
t = xp.subtract(xq);
|
t = xp.subtract(xq);
|
||||||
t = t.multiply(u).mod(q);
|
t = t.multiply(u).mod(q);
|
||||||
t = q.subtract(t);
|
t = q.subtract(t);
|
||||||
|
@ -113,12 +113,12 @@ function RSA() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
key.p = new BigInteger(B - qs, 1, rng);
|
key.p = new BigInteger(B - qs, 1, rng);
|
||||||
if (key.p.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) == 0 && key.p.isProbablePrime(10))
|
if (key.p.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) === 0 && key.p.isProbablePrime(10))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
key.q = new BigInteger(qs, 1, rng);
|
key.q = new BigInteger(qs, 1, rng);
|
||||||
if (key.q.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) == 0 && key.q.isProbablePrime(10))
|
if (key.q.subtract(BigInteger.ONE).gcd(key.ee).compareTo(BigInteger.ONE) === 0 && key.q.isProbablePrime(10))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (key.p.compareTo(key.q) <= 0) {
|
if (key.p.compareTo(key.q) <= 0) {
|
||||||
|
@ -129,7 +129,7 @@ function RSA() {
|
||||||
var p1 = key.p.subtract(BigInteger.ONE);
|
var p1 = key.p.subtract(BigInteger.ONE);
|
||||||
var q1 = key.q.subtract(BigInteger.ONE);
|
var q1 = key.q.subtract(BigInteger.ONE);
|
||||||
var phi = p1.multiply(q1);
|
var phi = p1.multiply(q1);
|
||||||
if (phi.gcd(key.ee).compareTo(BigInteger.ONE) == 0) {
|
if (phi.gcd(key.ee).compareTo(BigInteger.ONE) === 0) {
|
||||||
key.n = key.p.multiply(key.q);
|
key.n = key.p.multiply(key.q);
|
||||||
key.d = key.ee.modInverse(phi);
|
key.d = key.ee.modInverse(phi);
|
||||||
key.dmp1 = key.d.mod(p1);
|
key.dmp1 = key.d.mod(p1);
|
||||||
|
|
|
@ -20,6 +20,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
verify: function(algo, hash_algo, msg_MPIs, publickey_MPIs, data) {
|
verify: function(algo, hash_algo, msg_MPIs, publickey_MPIs, data) {
|
||||||
var calc_hash = hashModule.digest(hash_algo, data);
|
var calc_hash = hashModule.digest(hash_algo, data);
|
||||||
|
var dopublic;
|
||||||
|
|
||||||
switch (algo) {
|
switch (algo) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -32,7 +33,7 @@ module.exports = {
|
||||||
var n = publickey_MPIs[0].toBigInteger();
|
var n = publickey_MPIs[0].toBigInteger();
|
||||||
var e = publickey_MPIs[1].toBigInteger();
|
var e = publickey_MPIs[1].toBigInteger();
|
||||||
var x = msg_MPIs[0].toBigInteger();
|
var x = msg_MPIs[0].toBigInteger();
|
||||||
var dopublic = rsa.verify(x, e, n);
|
dopublic = rsa.verify(x, e, n);
|
||||||
var hash = pkcs1.emsa.decode(hash_algo, dopublic.toMPI().substring(2));
|
var hash = pkcs1.emsa.decode(hash_algo, dopublic.toMPI().substring(2));
|
||||||
if (hash == -1) {
|
if (hash == -1) {
|
||||||
throw new Error('PKCS1 padding in message or key incorrect. Aborting...');
|
throw new Error('PKCS1 padding in message or key incorrect. Aborting...');
|
||||||
|
@ -52,12 +53,11 @@ module.exports = {
|
||||||
var g = publickey_MPIs[2].toBigInteger();
|
var g = publickey_MPIs[2].toBigInteger();
|
||||||
var y = publickey_MPIs[3].toBigInteger();
|
var y = publickey_MPIs[3].toBigInteger();
|
||||||
var m = data;
|
var m = data;
|
||||||
var dopublic = dsa.verify(hash_algo, s1, s2, m, p, q, g, y);
|
dopublic = dsa.verify(hash_algo, s1, s2, m, p, q, g, y);
|
||||||
return dopublic.compareTo(s1) == 0;
|
return dopublic.compareTo(s1) === 0;
|
||||||
default:
|
default:
|
||||||
throw new Error('Invalid signature algorithm.');
|
throw new Error('Invalid signature algorithm.');
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +73,8 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
sign: function(hash_algo, algo, keyIntegers, data) {
|
sign: function(hash_algo, algo, keyIntegers, data) {
|
||||||
|
|
||||||
|
var m;
|
||||||
|
|
||||||
switch (algo) {
|
switch (algo) {
|
||||||
case 1:
|
case 1:
|
||||||
// RSA (Encrypt or Sign) [HAC]
|
// RSA (Encrypt or Sign) [HAC]
|
||||||
|
@ -83,7 +85,7 @@ module.exports = {
|
||||||
var rsa = new publicKey.rsa();
|
var rsa = new publicKey.rsa();
|
||||||
var d = keyIntegers[2].toBigInteger();
|
var d = keyIntegers[2].toBigInteger();
|
||||||
var n = keyIntegers[0].toBigInteger();
|
var n = keyIntegers[0].toBigInteger();
|
||||||
var m = pkcs1.emsa.encode(hash_algo,
|
m = pkcs1.emsa.encode(hash_algo,
|
||||||
data, keyIntegers[0].byteLength());
|
data, keyIntegers[0].byteLength());
|
||||||
|
|
||||||
return rsa.sign(m, d, n).toMPI();
|
return rsa.sign(m, d, n).toMPI();
|
||||||
|
@ -97,7 +99,7 @@ module.exports = {
|
||||||
var g = keyIntegers[2].toBigInteger();
|
var g = keyIntegers[2].toBigInteger();
|
||||||
var y = keyIntegers[3].toBigInteger();
|
var y = keyIntegers[3].toBigInteger();
|
||||||
var x = keyIntegers[4].toBigInteger();
|
var x = keyIntegers[4].toBigInteger();
|
||||||
var m = data;
|
m = data;
|
||||||
var result = dsa.sign(hash_algo, m, g, p, q, x);
|
var result = dsa.sign(hash_algo, m, g, p, q, x);
|
||||||
|
|
||||||
return result[0].toString() + result[1].toString();
|
return result[0].toString() + result[1].toString();
|
||||||
|
@ -108,4 +110,4 @@ module.exports = {
|
||||||
throw new Error('Invalid signature algorithm.');
|
throw new Error('Invalid signature algorithm.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -213,7 +213,7 @@ function splitHeaders(text) {
|
||||||
|
|
||||||
var matchResult = reEmptyLine.exec(text);
|
var matchResult = reEmptyLine.exec(text);
|
||||||
|
|
||||||
if (matchResult != null) {
|
if (matchResult !== null) {
|
||||||
headers = text.slice(0, matchResult.index);
|
headers = text.slice(0, matchResult.index);
|
||||||
body = text.slice(matchResult.index + matchResult[0].length);
|
body = text.slice(matchResult.index + matchResult[0].length);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ function splitChecksum(text) {
|
||||||
|
|
||||||
var matchResult = reChecksumStart.exec(text);
|
var matchResult = reChecksumStart.exec(text);
|
||||||
|
|
||||||
if (matchResult != null) {
|
if (matchResult !== null) {
|
||||||
body = text.slice(0, matchResult.index);
|
body = text.slice(0, matchResult.index);
|
||||||
checksum = text.slice(matchResult.index + 1);
|
checksum = text.slice(matchResult.index + 1);
|
||||||
}
|
}
|
||||||
|
@ -268,14 +268,14 @@ function dearmor(text) {
|
||||||
// so we know the index of the data we are interested in.
|
// so we know the index of the data we are interested in.
|
||||||
var indexBase = 1;
|
var indexBase = 1;
|
||||||
|
|
||||||
var result, checksum;
|
var result, checksum, msg;
|
||||||
|
|
||||||
if (text.search(reSplit) != splittext[0].length) {
|
if (text.search(reSplit) != splittext[0].length) {
|
||||||
indexBase = 0;
|
indexBase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != 2) {
|
if (type != 2) {
|
||||||
var msg = splitHeaders(splittext[indexBase]);
|
msg = splitHeaders(splittext[indexBase]);
|
||||||
var msg_sum = splitChecksum(msg.body);
|
var msg_sum = splitChecksum(msg.body);
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
@ -286,7 +286,7 @@ function dearmor(text) {
|
||||||
checksum = msg_sum.checksum;
|
checksum = msg_sum.checksum;
|
||||||
} else {
|
} else {
|
||||||
// Reverse dash-escaping for msg and remove trailing whitespace at end of line
|
// Reverse dash-escaping for msg and remove trailing whitespace at end of line
|
||||||
var msg = splitHeaders(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n"));
|
msg = splitHeaders(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n"));
|
||||||
var sig = splitHeaders(splittext[indexBase + 1].replace(/^- /mg, ''));
|
var sig = splitHeaders(splittext[indexBase + 1].replace(/^- /mg, ''));
|
||||||
var sig_sum = splitChecksum(sig.body);
|
var sig_sum = splitChecksum(sig.body);
|
||||||
|
|
||||||
|
@ -300,10 +300,10 @@ function dearmor(text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!verifyCheckSum(result.data, checksum)) {
|
if (!verifyCheckSum(result.data, checksum)) {
|
||||||
throw new Error("Ascii armor integrity check on message failed: '"
|
throw new Error("Ascii armor integrity check on message failed: '" +
|
||||||
+ checksum
|
checksum +
|
||||||
+ "' should be '"
|
"' should be '" +
|
||||||
+ getCheckSum(result) + "'");
|
getCheckSum(result) + "'");
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ function s2r(t) {
|
||||||
|
|
||||||
for (n = 0; n < tl; n++) {
|
for (n = 0; n < tl; n++) {
|
||||||
c = t.charCodeAt(n);
|
c = t.charCodeAt(n);
|
||||||
if (s == 0) {
|
if (s === 0) {
|
||||||
r += b64s.charAt((c >> 2) & 63);
|
r += b64s.charAt((c >> 2) & 63);
|
||||||
a = (c & 3) << 4;
|
a = (c & 3) << 4;
|
||||||
} else if (s == 1) {
|
} else if (s == 1) {
|
||||||
|
@ -41,12 +41,12 @@ function s2r(t) {
|
||||||
} else if (s == 2) {
|
} else if (s == 2) {
|
||||||
r += b64s.charAt(a | ((c >> 6) & 3));
|
r += b64s.charAt(a | ((c >> 6) & 3));
|
||||||
l += 1;
|
l += 1;
|
||||||
if ((l % 60) == 0)
|
if ((l % 60) === 0)
|
||||||
r += "\n";
|
r += "\n";
|
||||||
r += b64s.charAt(c & 63);
|
r += b64s.charAt(c & 63);
|
||||||
}
|
}
|
||||||
l += 1;
|
l += 1;
|
||||||
if ((l % 60) == 0)
|
if ((l % 60) === 0)
|
||||||
r += "\n";
|
r += "\n";
|
||||||
|
|
||||||
s += 1;
|
s += 1;
|
||||||
|
@ -56,13 +56,13 @@ function s2r(t) {
|
||||||
if (s > 0) {
|
if (s > 0) {
|
||||||
r += b64s.charAt(a);
|
r += b64s.charAt(a);
|
||||||
l += 1;
|
l += 1;
|
||||||
if ((l % 60) == 0)
|
if ((l % 60) === 0)
|
||||||
r += "\n";
|
r += "\n";
|
||||||
r += '=';
|
r += '=';
|
||||||
l += 1;
|
l += 1;
|
||||||
}
|
}
|
||||||
if (s == 1) {
|
if (s == 1) {
|
||||||
if ((l % 60) == 0)
|
if ((l % 60) === 0)
|
||||||
r += "\n";
|
r += "\n";
|
||||||
r += '=';
|
r += '=';
|
||||||
}
|
}
|
||||||
|
@ -98,4 +98,4 @@ function r2s(t) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
encode: s2r,
|
encode: s2r,
|
||||||
decode: r2s
|
decode: r2s
|
||||||
}
|
};
|
||||||
|
|
|
@ -314,4 +314,4 @@ module.exports = {
|
||||||
|
|
||||||
throw new Error('Invalid enum value.');
|
throw new Error('Invalid enum value.');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
22
src/key.js
22
src/key.js
|
@ -128,11 +128,12 @@ Key.prototype.toPacketlist = function() {
|
||||||
packetlist.push(this.primaryKey);
|
packetlist.push(this.primaryKey);
|
||||||
packetlist.push(this.revocationSignature);
|
packetlist.push(this.revocationSignature);
|
||||||
packetlist.concat(this.directSignatures);
|
packetlist.concat(this.directSignatures);
|
||||||
for (var i = 0; i < this.users.length; i++) {
|
var i;
|
||||||
|
for (i = 0; i < this.users.length; i++) {
|
||||||
packetlist.concat(this.users[i].toPacketlist());
|
packetlist.concat(this.users[i].toPacketlist());
|
||||||
}
|
}
|
||||||
if (this.subKeys) {
|
if (this.subKeys) {
|
||||||
for (var i = 0; i < this.subKeys.length; i++) {
|
for (i = 0; i < this.subKeys.length; i++) {
|
||||||
packetlist.concat(this.subKeys[i].toPacketlist());
|
packetlist.concat(this.subKeys[i].toPacketlist());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,16 +258,17 @@ Key.prototype.isPrivate = function() {
|
||||||
Key.prototype.toPublic = function() {
|
Key.prototype.toPublic = function() {
|
||||||
var packetlist = new packet.list();
|
var packetlist = new packet.list();
|
||||||
var keyPackets = this.toPacketlist();
|
var keyPackets = this.toPacketlist();
|
||||||
|
var bytes;
|
||||||
for (var i = 0; i < keyPackets.length; i++) {
|
for (var i = 0; i < keyPackets.length; i++) {
|
||||||
switch (keyPackets[i].tag) {
|
switch (keyPackets[i].tag) {
|
||||||
case enums.packet.secret_key:
|
case enums.packet.secret_key:
|
||||||
var bytes = keyPackets[i].writePublicKey();
|
bytes = keyPackets[i].writePublicKey();
|
||||||
var pubKeyPacket = new packet.public_key();
|
var pubKeyPacket = new packet.public_key();
|
||||||
pubKeyPacket.read(bytes);
|
pubKeyPacket.read(bytes);
|
||||||
packetlist.push(pubKeyPacket);
|
packetlist.push(pubKeyPacket);
|
||||||
break;
|
break;
|
||||||
case enums.packet.secret_subkey:
|
case enums.packet.secret_subkey:
|
||||||
var bytes = keyPackets[i].writePublicKey();
|
bytes = keyPackets[i].writePublicKey();
|
||||||
var pubSubkeyPacket = new packet.public_subkey();
|
var pubSubkeyPacket = new packet.public_subkey();
|
||||||
pubSubkeyPacket.read(bytes);
|
pubSubkeyPacket.read(bytes);
|
||||||
packetlist.push(pubSubkeyPacket);
|
packetlist.push(pubSubkeyPacket);
|
||||||
|
@ -328,7 +330,7 @@ function isValidEncryptionKeyPacket(keyPacket, signature) {
|
||||||
((signature.keyFlags & enums.keyFlags.encrypt_communication) !== 0 ||
|
((signature.keyFlags & enums.keyFlags.encrypt_communication) !== 0 ||
|
||||||
(signature.keyFlags & enums.keyFlags.encrypt_storage) !== 0 ||
|
(signature.keyFlags & enums.keyFlags.encrypt_storage) !== 0 ||
|
||||||
!signature.keyFlags);
|
!signature.keyFlags);
|
||||||
};
|
}
|
||||||
|
|
||||||
function isValidSigningKeyPacket(keyPacket, signature) {
|
function isValidSigningKeyPacket(keyPacket, signature) {
|
||||||
return (keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.dsa) ||
|
return (keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.dsa) ||
|
||||||
|
@ -336,7 +338,7 @@ function isValidSigningKeyPacket(keyPacket, signature) {
|
||||||
keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.rsa_encrypt_sign)) &&
|
keyPacket.algorithm == enums.read(enums.publicKey, enums.publicKey.rsa_encrypt_sign)) &&
|
||||||
((signature.keyFlags & enums.keyFlags.sign_data) !== 0 ||
|
((signature.keyFlags & enums.keyFlags.sign_data) !== 0 ||
|
||||||
!signature.keyFlags);
|
!signature.keyFlags);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first valid encryption key packet for this key
|
* Returns the first valid encryption key packet for this key
|
||||||
|
@ -469,7 +471,7 @@ Key.prototype.getPrimaryUser = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return user ? {user: user, selfCertificate: userSelfCert} : null;
|
return user ? {user: user, selfCertificate: userSelfCert} : null;
|
||||||
}
|
};
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
Key.prototype.revoke = function() {
|
Key.prototype.revoke = function() {
|
||||||
|
@ -485,7 +487,7 @@ function User(userPacket) {
|
||||||
return new User(userPacket);
|
return new User(userPacket);
|
||||||
}
|
}
|
||||||
this.userId = userPacket.tag == enums.packet.userid ? userPacket : null;
|
this.userId = userPacket.tag == enums.packet.userid ? userPacket : null;
|
||||||
this.userAttribute = userPacket.tag == enums.packet.user_attribute ? userPacket : null
|
this.userAttribute = userPacket.tag == enums.packet.user_attribute ? userPacket : null;
|
||||||
this.selfCertifications = null;
|
this.selfCertifications = null;
|
||||||
this.otherCertifications = null;
|
this.otherCertifications = null;
|
||||||
this.revocationCertifications = null;
|
this.revocationCertifications = null;
|
||||||
|
@ -683,8 +685,8 @@ function readArmored(armoredText) {
|
||||||
var packetlist = new packet.list();
|
var packetlist = new packet.list();
|
||||||
packetlist.read(input.data);
|
packetlist.read(input.data);
|
||||||
var keyIndex = packetlist.indexOfTag(enums.packet.public_key, enums.packet.secret_key);
|
var keyIndex = packetlist.indexOfTag(enums.packet.public_key, enums.packet.secret_key);
|
||||||
if (keyIndex.length == 0) {
|
if (keyIndex.length === 0) {
|
||||||
throw new Error('No key packet found in armored text')
|
throw new Error('No key packet found in armored text');
|
||||||
}
|
}
|
||||||
for (var i = 0; i < keyIndex.length; i++) {
|
for (var i = 0; i < keyIndex.length; i++) {
|
||||||
var oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
|
var oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
|
||||||
|
|
|
@ -39,7 +39,7 @@ module.exports = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the current state of the keyring to HTML5 local storage.
|
* Saves the current state of the keyring to HTML5 local storage.
|
||||||
|
@ -52,5 +52,5 @@ module.exports = function () {
|
||||||
armoredKeys.push(keys[i].armor());
|
armoredKeys.push(keys[i].armor());
|
||||||
}
|
}
|
||||||
window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
|
window.localStorage.setItem("armoredKeys", JSON.stringify(armoredKeys));
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -184,10 +184,10 @@ Message.prototype.sign = function(privateKeys) {
|
||||||
if (!literalDataPacket) throw new Error('No literal data packet to sign.');
|
if (!literalDataPacket) throw new Error('No literal data packet to sign.');
|
||||||
|
|
||||||
var literalFormat = enums.write(enums.literal, literalDataPacket.format);
|
var literalFormat = enums.write(enums.literal, literalDataPacket.format);
|
||||||
var signatureType = literalFormat == enums.literal.binary
|
var signatureType = literalFormat == enums.literal.binary ?
|
||||||
? enums.signature.binary : enums.signature.text;
|
enums.signature.binary : enums.signature.text;
|
||||||
|
var i;
|
||||||
for (var i = 0; i < privateKeys.length; i++) {
|
for (i = 0; i < privateKeys.length; i++) {
|
||||||
var onePassSig = new packet.one_pass_signature();
|
var onePassSig = new packet.one_pass_signature();
|
||||||
onePassSig.type = signatureType;
|
onePassSig.type = signatureType;
|
||||||
//TODO get preferred hashg algo from key signature
|
//TODO get preferred hashg algo from key signature
|
||||||
|
@ -203,7 +203,7 @@ Message.prototype.sign = function(privateKeys) {
|
||||||
|
|
||||||
packetlist.push(literalDataPacket);
|
packetlist.push(literalDataPacket);
|
||||||
|
|
||||||
for (var i = privateKeys.length - 1; i >= 0; i--) {
|
for (i = privateKeys.length - 1; i >= 0; i--) {
|
||||||
var signaturePacket = new packet.signature();
|
var signaturePacket = new packet.signature();
|
||||||
signaturePacket.signatureType = signatureType;
|
signaturePacket.signatureType = signatureType;
|
||||||
signaturePacket.hashAlgorithm = config.prefer_hash_algorithm;
|
signaturePacket.hashAlgorithm = config.prefer_hash_algorithm;
|
||||||
|
|
|
@ -158,7 +158,7 @@ function generateKeyPair(keyType, numBits, userId, passphrase) {
|
||||||
exports.encryptMessage = encryptMessage;
|
exports.encryptMessage = encryptMessage;
|
||||||
exports.signAndEncryptMessage = signAndEncryptMessage;
|
exports.signAndEncryptMessage = signAndEncryptMessage;
|
||||||
exports.decryptMessage = decryptMessage;
|
exports.decryptMessage = decryptMessage;
|
||||||
exports.decryptAndVerifyMessage = decryptAndVerifyMessage
|
exports.decryptAndVerifyMessage = decryptAndVerifyMessage;
|
||||||
exports.signClearMessage = signClearMessage;
|
exports.signClearMessage = signClearMessage;
|
||||||
exports.verifyClearSignedMessage = verifyClearSignedMessage;
|
exports.verifyClearSignedMessage = verifyClearSignedMessage;
|
||||||
exports.generateKeyPair = generateKeyPair;
|
exports.generateKeyPair = generateKeyPair;
|
||||||
|
|
|
@ -39,11 +39,11 @@ module.exports = {
|
||||||
signature: require('./signature.js'),
|
signature: require('./signature.js'),
|
||||||
/** @see module:packet/trust */
|
/** @see module:packet/trust */
|
||||||
trust: require('./trust.js')
|
trust: require('./trust.js')
|
||||||
}
|
};
|
||||||
|
|
||||||
for (var i in enums.packet) {
|
for (var i in enums.packet) {
|
||||||
var packetClass = module.exports[i];
|
var packetClass = module.exports[i];
|
||||||
|
|
||||||
if (packetClass != undefined)
|
if (packetClass !== undefined)
|
||||||
packetClass.prototype.tag = enums.packet[i];
|
packetClass.prototype.tag = enums.packet[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ module.exports = function () {
|
||||||
this.compressed = bytes.substr(1);
|
this.compressed = bytes.substr(1);
|
||||||
|
|
||||||
this.decompress();
|
this.decompress();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,11 +74,11 @@ module.exports = function () {
|
||||||
* @return {String} binary compressed packet
|
* @return {String} binary compressed packet
|
||||||
*/
|
*/
|
||||||
this.write = function() {
|
this.write = function() {
|
||||||
if (this.compressed == null)
|
if (this.compressed === null)
|
||||||
this.compress();
|
this.compress();
|
||||||
|
|
||||||
return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed;
|
return String.fromCharCode(enums.write(enums.compression, this.algorithm)) + this.compressed;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +86,7 @@ module.exports = function () {
|
||||||
* read by read_packet
|
* read by read_packet
|
||||||
*/
|
*/
|
||||||
this.decompress = function() {
|
this.decompress = function() {
|
||||||
var decompressed;
|
var decompressed, compdata, radix;
|
||||||
|
|
||||||
switch (this.algorithm) {
|
switch (this.algorithm) {
|
||||||
case 'uncompressed':
|
case 'uncompressed':
|
||||||
|
@ -94,9 +94,9 @@ module.exports = function () {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'zip':
|
case 'zip':
|
||||||
var compData = this.compressed;
|
compData = this.compressed;
|
||||||
|
|
||||||
var radix = base64.encode(compData).replace(/\n/g, "");
|
radix = base64.encode(compData).replace(/\n/g, "");
|
||||||
// no header in this case, directly call deflate
|
// no header in this case, directly call deflate
|
||||||
var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix));
|
var jxg_obj = new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(radix));
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ module.exports = function () {
|
||||||
|
|
||||||
if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951
|
if (compressionMethod == 8) { //CM 8 is for DEFLATE, RFC 1951
|
||||||
// remove 4 bytes ADLER32 checksum from the end
|
// remove 4 bytes ADLER32 checksum from the end
|
||||||
var compData = this.compressed.substring(0, this.compressed.length - 4);
|
compData = this.compressed.substring(0, this.compressed.length - 4);
|
||||||
var radix = base64.encode(compData).replace(/\n/g, "");
|
radix = base64.encode(compData).replace(/\n/g, "");
|
||||||
//TODO check ADLER32 checksum
|
//TODO check ADLER32 checksum
|
||||||
decompressed = JXG.decompress(radix);
|
decompressed = JXG.decompress(radix);
|
||||||
break;
|
break;
|
||||||
|
@ -128,15 +128,13 @@ module.exports = function () {
|
||||||
case 'bzip2':
|
case 'bzip2':
|
||||||
// TODO: need to implement this
|
// TODO: need to implement this
|
||||||
throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
|
throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Compression algorithm unknown :" + this.alogrithm);
|
throw new Error("Compression algorithm unknown :" + this.alogrithm);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.packets.read(decompressed);
|
this.packets.read(decompressed);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compress the packet data (member decompressedData)
|
* Compress the packet data (member decompressedData)
|
||||||
|
@ -152,23 +150,19 @@ module.exports = function () {
|
||||||
case 'zip':
|
case 'zip':
|
||||||
// - ZIP [RFC1951]
|
// - ZIP [RFC1951]
|
||||||
throw new Error("Compression algorithm ZIP [RFC1951] is not implemented.");
|
throw new Error("Compression algorithm ZIP [RFC1951] is not implemented.");
|
||||||
break;
|
|
||||||
|
|
||||||
case 'zlib':
|
case 'zlib':
|
||||||
// - ZLIB [RFC1950]
|
// - ZLIB [RFC1950]
|
||||||
// TODO: need to implement this
|
// TODO: need to implement this
|
||||||
throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented.");
|
throw new Error("Compression algorithm ZLIB [RFC1950] is not implemented.");
|
||||||
break;
|
|
||||||
|
|
||||||
case 'bzip2':
|
case 'bzip2':
|
||||||
// - BZip2 [BZ2]
|
// - BZip2 [BZ2]
|
||||||
// TODO: need to implement this
|
// TODO: need to implement this
|
||||||
throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
|
throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Compression algorithm unknown :" + this.type);
|
throw new Error("Compression algorithm unknown :" + this.type);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -47,7 +47,7 @@ module.exports = function () {
|
||||||
text = text.replace(/\r/g, '').replace(/\n/g, '\r\n');
|
text = text.replace(/\r/g, '').replace(/\n/g, '\r\n');
|
||||||
// encode UTF8
|
// encode UTF8
|
||||||
this.data = this.format == 'utf8' ? util.encode_utf8(text) : text;
|
this.data = this.format == 'utf8' ? util.encode_utf8(text) : text;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns literal data packets as native JavaScript string
|
* Returns literal data packets as native JavaScript string
|
||||||
|
@ -59,7 +59,7 @@ module.exports = function () {
|
||||||
var text = util.decode_utf8(this.data);
|
var text = util.decode_utf8(this.data);
|
||||||
// normalize EOL to \n
|
// normalize EOL to \n
|
||||||
return text.replace(/\r\n/g, '\n');
|
return text.replace(/\r\n/g, '\n');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the packet data to value represented by the provided string of bytes.
|
* Set the packet data to value represented by the provided string of bytes.
|
||||||
|
@ -69,7 +69,7 @@ module.exports = function () {
|
||||||
this.setBytes = function(bytes, format) {
|
this.setBytes = function(bytes, format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.data = bytes;
|
this.data = bytes;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +78,7 @@ module.exports = function () {
|
||||||
*/
|
*/
|
||||||
this.getBytes = function() {
|
this.getBytes = function() {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,7 +105,7 @@ module.exports = function () {
|
||||||
var data = bytes.substring(6 + filename_len);
|
var data = bytes.substring(6 + filename_len);
|
||||||
|
|
||||||
this.setBytes(data, format);
|
this.setBytes(data, format);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a string representation of the packet
|
* Creates a string representation of the packet
|
||||||
|
@ -125,5 +125,5 @@ module.exports = function () {
|
||||||
result += util.writeDate(this.date);
|
result += util.writeDate(this.date);
|
||||||
result += data;
|
result += data;
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -50,5 +50,5 @@ module.exports = function () {
|
||||||
return true;
|
return true;
|
||||||
// marker packet does not contain "PGP"
|
// marker packet does not contain "PGP"
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -74,7 +74,7 @@ module.exports = function () {
|
||||||
// signature to be applied to the same message data.
|
// signature to be applied to the same message data.
|
||||||
this.flags = bytes.charCodeAt(mypos++);
|
this.flags = bytes.charCodeAt(mypos++);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a string representation of a one-pass signature packet
|
* creates a string representation of a one-pass signature packet
|
||||||
|
@ -91,5 +91,5 @@ module.exports = function () {
|
||||||
result += String.fromCharCode(this.flags);
|
result += String.fromCharCode(this.flags);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -123,8 +123,8 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
read: function(input, position, len) {
|
read: function(input, position, len) {
|
||||||
// some sanity checks
|
// some sanity checks
|
||||||
if (input == null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) &
|
if (input === null || input.length <= position || input.substring(position).length < 2 || (input.charCodeAt(position) &
|
||||||
0x80) == 0) {
|
0x80) === 0) {
|
||||||
throw new Error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");
|
throw new Error("Error during parsing. This message / key is probably not containing a valid OpenPGP format.");
|
||||||
}
|
}
|
||||||
var mypos = position;
|
var mypos = position;
|
||||||
|
@ -133,7 +133,7 @@ module.exports = {
|
||||||
var packet_length;
|
var packet_length;
|
||||||
|
|
||||||
format = 0; // 0 = old format; 1 = new format
|
format = 0; // 0 = old format; 1 = new format
|
||||||
if ((input.charCodeAt(mypos) & 0x40) != 0) {
|
if ((input.charCodeAt(mypos) & 0x40) !== 0) {
|
||||||
format = 1;
|
format = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,27 +207,28 @@ module.exports = {
|
||||||
// EEEK, we're reading the full data here...
|
// EEEK, we're reading the full data here...
|
||||||
var mypos2 = mypos + packet_length;
|
var mypos2 = mypos + packet_length;
|
||||||
bodydata = input.substring(mypos, mypos + packet_length);
|
bodydata = input.substring(mypos, mypos + packet_length);
|
||||||
|
var tmplen;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (input.charCodeAt(mypos2) < 192) {
|
if (input.charCodeAt(mypos2) < 192) {
|
||||||
var tmplen = input.charCodeAt(mypos2++);
|
tmplen = input.charCodeAt(mypos2++);
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
break;
|
break;
|
||||||
} else if (input.charCodeAt(mypos2) >= 192 && input.charCodeAt(mypos2) < 224) {
|
} else if (input.charCodeAt(mypos2) >= 192 && input.charCodeAt(mypos2) < 224) {
|
||||||
var tmplen = ((input.charCodeAt(mypos2++) - 192) << 8) + (input.charCodeAt(mypos2++)) + 192;
|
tmplen = ((input.charCodeAt(mypos2++) - 192) << 8) + (input.charCodeAt(mypos2++)) + 192;
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
break;
|
break;
|
||||||
} else if (input.charCodeAt(mypos2) > 223 && input.charCodeAt(mypos2) < 255) {
|
} else if (input.charCodeAt(mypos2) > 223 && input.charCodeAt(mypos2) < 255) {
|
||||||
var tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F);
|
tmplen = 1 << (input.charCodeAt(mypos2++) & 0x1F);
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
mypos2 += tmplen;
|
mypos2 += tmplen;
|
||||||
} else {
|
} else {
|
||||||
mypos2++;
|
mypos2++;
|
||||||
var tmplen = (input.charCodeAt(mypos2++) << 24) | (input.charCodeAt(mypos2++) << 16) | (input[mypos2++]
|
tmplen = (input.charCodeAt(mypos2++) << 24) | (input.charCodeAt(mypos2++) << 16) | (input[mypos2++]
|
||||||
.charCodeAt() << 8) | input.charCodeAt(mypos2++);
|
.charCodeAt() << 8) | input.charCodeAt(mypos2++);
|
||||||
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
bodydata += input.substring(mypos2, mypos2 + tmplen);
|
||||||
packet_length += tmplen;
|
packet_length += tmplen;
|
||||||
|
@ -250,7 +251,7 @@ module.exports = {
|
||||||
real_packet_length = packet_length;
|
real_packet_length = packet_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bodydata == null) {
|
if (bodydata === null) {
|
||||||
bodydata = input.substring(mypos, mypos + real_packet_length);
|
bodydata = input.substring(mypos, mypos + real_packet_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,4 +261,4 @@ module.exports = {
|
||||||
offset: mypos + real_packet_length
|
offset: mypos + real_packet_length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ module.exports = packetlist = function () {
|
||||||
|
|
||||||
packet.read(parsed.packet);
|
packet.read(parsed.packet);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a binary representation of openpgp objects contained within the
|
* Creates a binary representation of openpgp objects contained within the
|
||||||
|
@ -56,7 +56,7 @@ module.exports = packetlist = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a packet to the list. This is the only supported method of doing so;
|
* Adds a packet to the list. This is the only supported method of doing so;
|
||||||
|
@ -69,7 +69,7 @@ module.exports = packetlist = function () {
|
||||||
|
|
||||||
this[this.length] = packet;
|
this[this.length] = packet;
|
||||||
this.length++;
|
this.length++;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new packetList with all packets that pass the test implemented by the provided function.
|
* Creates a new packetList with all packets that pass the test implemented by the provided function.
|
||||||
|
@ -85,7 +85,7 @@ module.exports = packetlist = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new packetList with all packets from the given types
|
* Creates a new packetList with all packets from the given types
|
||||||
|
@ -96,13 +96,13 @@ module.exports = packetlist = function () {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
for (var i = 0; i < this.length; i++) {
|
for (var i = 0; i < this.length; i++) {
|
||||||
if (args.some(function(packetType) {return that[i].tag == packetType})) {
|
if (args.some(function(packetType) {return that[i].tag == packetType;})) {
|
||||||
filtered.push(this[i]);
|
filtered.push(this[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the provided callback once for each element
|
* Executes the provided callback once for each element
|
||||||
|
@ -111,7 +111,7 @@ module.exports = packetlist = function () {
|
||||||
for (var i = 0; i < this.length; i++) {
|
for (var i = 0; i < this.length; i++) {
|
||||||
callback(this[i]);
|
callback(this[i]);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Traverses packet tree and returns first matching packet
|
* Traverses packet tree and returns first matching packet
|
||||||
|
@ -132,7 +132,7 @@ module.exports = packetlist = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns array of found indices by tag
|
* Returns array of found indices by tag
|
||||||
|
@ -142,26 +142,26 @@ module.exports = packetlist = function () {
|
||||||
var tagIndex = [];
|
var tagIndex = [];
|
||||||
var that = this;
|
var that = this;
|
||||||
for (var i = 0; i < this.length; i++) {
|
for (var i = 0; i < this.length; i++) {
|
||||||
if (args.some(function(packetType) {return that[i].tag == packetType})) {
|
if (args.some(function(packetType) {return that[i].tag == packetType;})) {
|
||||||
tagIndex.push(i);
|
tagIndex.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tagIndex;
|
return tagIndex;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns slice of packetlist
|
* Returns slice of packetlist
|
||||||
*/
|
*/
|
||||||
this.slice = function(begin, end) {
|
this.slice = function(begin, end) {
|
||||||
if (!end) {
|
if (!end) {
|
||||||
end = this.length
|
end = this.length;
|
||||||
}
|
}
|
||||||
var part = new packetlist();
|
var part = new packetlist();
|
||||||
for (var i = begin; i < end; i++) {
|
for (var i = begin; i < end; i++) {
|
||||||
part.push(this[i]);
|
part.push(this[i]);
|
||||||
}
|
}
|
||||||
return part;
|
return part;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concatenates packetlist or array of packets
|
* Concatenates packetlist or array of packets
|
||||||
|
@ -172,6 +172,5 @@ module.exports = packetlist = function () {
|
||||||
this.push(packetlist[i]);
|
this.push(packetlist[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ module.exports = function () {
|
||||||
|
|
||||||
this.mpi[i] = new type_mpi();
|
this.mpi[i] = new type_mpi();
|
||||||
|
|
||||||
p += this.mpi[i].read(bmpi.substr(p))
|
p += this.mpi[i].read(bmpi.substr(p));
|
||||||
|
|
||||||
if (p > bmpi.length) {
|
if (p > bmpi.length) {
|
||||||
throw new Error('Error reading MPI @:' + p);
|
throw new Error('Error reading MPI @:' + p);
|
||||||
|
@ -181,7 +181,7 @@ module.exports = function () {
|
||||||
for (var i = 0; i < mpicount; i++) {
|
for (var i = 0; i < mpicount; i++) {
|
||||||
toHash += this.mpi[i].toBytes();
|
toHash += this.mpi[i].toBytes();
|
||||||
}
|
}
|
||||||
return crypto.hash.md5(toHash)
|
return crypto.hash.md5(toHash);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -124,7 +124,7 @@ module.exports = function () {
|
||||||
enums.write(enums.publicKey, this.publicKeyAlgorithm));
|
enums.write(enums.publicKey, this.publicKeyAlgorithm));
|
||||||
|
|
||||||
for (var i = 0; i < this.encrypted.length; i++) {
|
for (var i = 0; i < this.encrypted.length; i++) {
|
||||||
result += this.encrypted[i].write()
|
result += this.encrypted[i].write();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -169,7 +169,7 @@ module.exports = function () {
|
||||||
result,
|
result,
|
||||||
key.mpi[0].byteLength());
|
key.mpi[0].byteLength());
|
||||||
|
|
||||||
var key = decoded.substring(1, decoded.length - 2);
|
key = decoded.substring(1, decoded.length - 2);
|
||||||
|
|
||||||
if (checksum != util.calc_checksum(key)) {
|
if (checksum != util.calc_checksum(key)) {
|
||||||
throw new Error('Checksum mismatch');
|
throw new Error('Checksum mismatch');
|
||||||
|
|
|
@ -28,4 +28,4 @@ var publicKey = require('./public_key.js');
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
publicKey.call(this);
|
publicKey.call(this);
|
||||||
}
|
};
|
||||||
|
|
|
@ -261,6 +261,6 @@ module.exports = function () {
|
||||||
this.isDecrypted = true;
|
this.isDecrypted = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports.prototype = new publicKey();
|
module.exports.prototype = new publicKey();
|
||||||
|
|
|
@ -28,4 +28,4 @@ var secretKey = require('./secret_key.js');
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
secretKey.call(this);
|
secretKey.call(this);
|
||||||
}
|
};
|
||||||
|
|
|
@ -171,7 +171,6 @@ module.exports = packetSignature = function () {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('Version ' + version + ' of the signature is unsupported.');
|
throw new Error('Version ' + version + ' of the signature is unsupported.');
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two-octet field holding left 16 bits of signed hash value.
|
// Two-octet field holding left 16 bits of signed hash value.
|
||||||
|
@ -363,6 +362,7 @@ module.exports = packetSignature = function () {
|
||||||
|
|
||||||
// The leftwost bit denotes a "critical" packet, but we ignore it.
|
// The leftwost bit denotes a "critical" packet, but we ignore it.
|
||||||
var type = bytes.charCodeAt(mypos++) & 0x7F;
|
var type = bytes.charCodeAt(mypos++) & 0x7F;
|
||||||
|
var seconds;
|
||||||
|
|
||||||
// subpacket type
|
// subpacket type
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -372,9 +372,9 @@ module.exports = packetSignature = function () {
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Signature Expiration Time in seconds
|
// Signature Expiration Time in seconds
|
||||||
var seconds = util.readNumber(bytes.substr(mypos));
|
seconds = util.readNumber(bytes.substr(mypos));
|
||||||
|
|
||||||
this.signatureNeverExpires = seconds == 0;
|
this.signatureNeverExpires = seconds === 0;
|
||||||
this.signatureExpirationTime = seconds;
|
this.signatureExpirationTime = seconds;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -397,10 +397,10 @@ module.exports = packetSignature = function () {
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
// Key Expiration Time in seconds
|
// Key Expiration Time in seconds
|
||||||
var seconds = util.readNumber(bytes.substr(mypos));
|
seconds = util.readNumber(bytes.substr(mypos));
|
||||||
|
|
||||||
this.keyExpirationTime = seconds;
|
this.keyExpirationTime = seconds;
|
||||||
this.keyNeverExpires = seconds == 0;
|
this.keyNeverExpires = seconds === 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
|
@ -435,9 +435,9 @@ module.exports = packetSignature = function () {
|
||||||
// We extract key/value tuple from the byte stream.
|
// We extract key/value tuple from the byte stream.
|
||||||
mypos += 4;
|
mypos += 4;
|
||||||
var m = util.readNumber(bytes.substr(mypos, 2));
|
var m = util.readNumber(bytes.substr(mypos, 2));
|
||||||
mypos += 2
|
mypos += 2;
|
||||||
var n = util.readNumber(bytes.substr(mypos, 2));
|
var n = util.readNumber(bytes.substr(mypos, 2));
|
||||||
mypos += 2
|
mypos += 2;
|
||||||
|
|
||||||
var name = bytes.substr(mypos, m),
|
var name = bytes.substr(mypos, m),
|
||||||
value = bytes.substr(mypos + m, n);
|
value = bytes.substr(mypos + m, n);
|
||||||
|
@ -464,7 +464,7 @@ module.exports = packetSignature = function () {
|
||||||
break;
|
break;
|
||||||
case 25:
|
case 25:
|
||||||
// Primary User ID
|
// Primary User ID
|
||||||
this.isPrimaryUserID = bytes[mypos++] != 0;
|
this.isPrimaryUserID = bytes[mypos++] !== 0;
|
||||||
break;
|
break;
|
||||||
case 26:
|
case 26:
|
||||||
// Policy URI
|
// Policy URI
|
||||||
|
@ -504,7 +504,6 @@ module.exports = packetSignature = function () {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("Unknown signature subpacket type " + type + " @:" + mypos);
|
throw new Error("Unknown signature subpacket type " + type + " @:" + mypos);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -556,7 +555,7 @@ module.exports = packetSignature = function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
case t.key:
|
case t.key:
|
||||||
if (data.key == undefined)
|
if (data.key === undefined)
|
||||||
throw new Error('Key packet is required for this sigtature.');
|
throw new Error('Key packet is required for this sigtature.');
|
||||||
|
|
||||||
return data.key.writeOld();
|
return data.key.writeOld();
|
||||||
|
@ -568,11 +567,10 @@ module.exports = packetSignature = function () {
|
||||||
return '';
|
return '';
|
||||||
case t.third_party:
|
case t.third_party:
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Unknown signature type.')
|
throw new Error('Unknown signature type.');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.calculateTrailer = function() {
|
this.calculateTrailer = function() {
|
||||||
|
@ -583,8 +581,8 @@ module.exports = packetSignature = function () {
|
||||||
trailer += String.fromCharCode(4); // Version
|
trailer += String.fromCharCode(4); // Version
|
||||||
trailer += String.fromCharCode(0xFF);
|
trailer += String.fromCharCode(0xFF);
|
||||||
trailer += util.writeNumber(this.signatureData.length, 4);
|
trailer += util.writeNumber(this.signatureData.length, 4);
|
||||||
return trailer
|
return trailer;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -625,7 +623,7 @@ module.exports = packetSignature = function () {
|
||||||
bytes + this.signatureData + trailer);
|
bytes + this.signatureData + trailer);
|
||||||
|
|
||||||
return this.verified;
|
return this.verified;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies signature expiration date
|
* Verifies signature expiration date
|
||||||
|
@ -636,5 +634,6 @@ module.exports = packetSignature = function () {
|
||||||
return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
|
return Date.now() > (this.created.getTime() + this.signatureExpirationTime*1000);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
|
@ -64,16 +64,16 @@ module.exports = function () {
|
||||||
|
|
||||||
this.write = function() {
|
this.write = function() {
|
||||||
|
|
||||||
return String.fromCharCode(1) // Version
|
// 1 = Version
|
||||||
+ this.encrypted;
|
return String.fromCharCode(1) + this.encrypted;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.encrypt = function(sessionKeyAlgorithm, key) {
|
this.encrypt = function(sessionKeyAlgorithm, key) {
|
||||||
var bytes = this.packets.write()
|
var bytes = this.packets.write();
|
||||||
|
|
||||||
var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm);
|
var prefixrandom = crypto.getPrefixRandom(sessionKeyAlgorithm);
|
||||||
var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length -
|
var prefix = prefixrandom + prefixrandom.charAt(prefixrandom.length - 2) + prefixrandom.charAt(prefixrandom.length -
|
||||||
1)
|
1);
|
||||||
|
|
||||||
var tohash = bytes;
|
var tohash = bytes;
|
||||||
|
|
||||||
|
|
|
@ -75,13 +75,13 @@ module.exports = function () {
|
||||||
|
|
||||||
if (done < bytes.length) {
|
if (done < bytes.length) {
|
||||||
this.encrypted = bytes.substr(done);
|
this.encrypted = bytes.substr(done);
|
||||||
this.sessionKeyEncryptionAlgorithm = algo
|
this.sessionKeyEncryptionAlgorithm = algo;
|
||||||
} else
|
} else
|
||||||
this.sessionKeyAlgorithm = algo;
|
this.sessionKeyAlgorithm = algo;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.write = function() {
|
this.write = function() {
|
||||||
var algo = this.encrypted == null ?
|
var algo = this.encrypted === null ?
|
||||||
this.sessionKeyAlgorithm :
|
this.sessionKeyAlgorithm :
|
||||||
this.sessionKeyEncryptionAlgorithm;
|
this.sessionKeyEncryptionAlgorithm;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ module.exports = function () {
|
||||||
String.fromCharCode(enums.write(enums.symmetric, algo)) +
|
String.fromCharCode(enums.write(enums.symmetric, algo)) +
|
||||||
this.s2k.write();
|
this.s2k.write();
|
||||||
|
|
||||||
if (this.encrypted != null)
|
if (this.encrypted !== null)
|
||||||
bytes += this.encrypted;
|
bytes += this.encrypted;
|
||||||
return bytes;
|
return bytes;
|
||||||
};
|
};
|
||||||
|
@ -101,7 +101,7 @@ module.exports = function () {
|
||||||
* @return {String} The unencrypted session key
|
* @return {String} The unencrypted session key
|
||||||
*/
|
*/
|
||||||
this.decrypt = function(passphrase) {
|
this.decrypt = function(passphrase) {
|
||||||
var algo = this.sessionKeyEncryptionAlgorithm != null ?
|
var algo = this.sessionKeyEncryptionAlgorithm !== null ?
|
||||||
this.sessionKeyEncryptionAlgorithm :
|
this.sessionKeyEncryptionAlgorithm :
|
||||||
this.sessionKeyAlgorithm;
|
this.sessionKeyAlgorithm;
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ module.exports = function () {
|
||||||
var length = crypto.cipher[algo].keySize;
|
var length = crypto.cipher[algo].keySize;
|
||||||
var key = this.s2k.produce_key(passphrase, length);
|
var key = this.s2k.produce_key(passphrase, length);
|
||||||
|
|
||||||
if (this.encrypted == null) {
|
if (this.encrypted === null) {
|
||||||
this.sessionKey = key;
|
this.sessionKey = key;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,4 +55,4 @@ module.exports = function () {
|
||||||
this.write = function () {
|
this.write = function () {
|
||||||
return util.encode_utf8(this.userid);
|
return util.encode_utf8(this.userid);
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -63,4 +63,4 @@ module.exports = function () {
|
||||||
|
|
||||||
module.exports.mapToHex = function(keyId) {
|
module.exports.mapToHex = function(keyId) {
|
||||||
return keyId.toHex();
|
return keyId.toHex();
|
||||||
}
|
};
|
||||||
|
|
|
@ -97,4 +97,4 @@ module.exports = function mpi() {
|
||||||
this.fromBigInteger = function(bn) {
|
this.fromBigInteger = function(bn) {
|
||||||
this.data = bn.clone();
|
this.data = bn.clone();
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -99,7 +99,6 @@ module.exports = function s2k() {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Unknown s2k type.");
|
throw new Error("Unknown s2k type.");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
|
@ -70,7 +70,7 @@ module.exports = {
|
||||||
while (h.length < 2) h = "0" + h;
|
while (h.length < 2) h = "0" + h;
|
||||||
r.push(" " + h);
|
r.push(" " + h);
|
||||||
i++;
|
i++;
|
||||||
if (i % 32 == 0)
|
if (i % 32 === 0)
|
||||||
r.push("\n ");
|
r.push("\n ");
|
||||||
}
|
}
|
||||||
return r.join('');
|
return r.join('');
|
||||||
|
@ -82,7 +82,7 @@ module.exports = {
|
||||||
* @return {String} String containing the hexadecimal values
|
* @return {String} String containing the hexadecimal values
|
||||||
*/
|
*/
|
||||||
hexstrdump: function (str) {
|
hexstrdump: function (str) {
|
||||||
if (str == null)
|
if (str === null)
|
||||||
return "";
|
return "";
|
||||||
var r = [];
|
var r = [];
|
||||||
var e = str.length;
|
var e = str.length;
|
||||||
|
@ -250,7 +250,7 @@ module.exports = {
|
||||||
|
|
||||||
getLeftNBits: function (string, bitcount) {
|
getLeftNBits: function (string, bitcount) {
|
||||||
var rest = bitcount % 8;
|
var rest = bitcount % 8;
|
||||||
if (rest == 0)
|
if (rest === 0)
|
||||||
return string.substring(0, bitcount / 8);
|
return string.substring(0, bitcount / 8);
|
||||||
var bytes = (bitcount - rest) / 8 + 1;
|
var bytes = (bitcount - rest) / 8 + 1;
|
||||||
var result = string.substring(0, bytes);
|
var result = string.substring(0, bytes);
|
||||||
|
@ -266,7 +266,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
shiftRight: function (value, bitcount) {
|
shiftRight: function (value, bitcount) {
|
||||||
var temp = util.str2bin(value);
|
var temp = util.str2bin(value);
|
||||||
if (bitcount % 8 != 0) {
|
if (bitcount % 8 !== 0) {
|
||||||
for (var i = temp.length - 1; i >= 0; i--) {
|
for (var i = temp.length - 1; i >= 0; i--) {
|
||||||
temp[i] >>= bitcount % 8;
|
temp[i] >>= bitcount % 8;
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user