Changes to optimize decrypting. Changed toString in tag 18 to only print data in debug.
This commit is contained in:
parent
13b52ebd51
commit
d11fbaa1df
|
@ -179,7 +179,8 @@ function openpgp_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext,
|
||||||
util.print_debug("resync:"+resync);
|
util.print_debug("resync:"+resync);
|
||||||
var iblock = new Array(block_size);
|
var iblock = new Array(block_size);
|
||||||
var ablock = new Array(block_size);
|
var ablock = new Array(block_size);
|
||||||
var i, n, text = '';
|
var i, n = '';
|
||||||
|
var text = [];
|
||||||
|
|
||||||
// initialisation vector
|
// initialisation vector
|
||||||
for(i=0; i < block_size; i++) iblock[i] = 0;
|
for(i=0; i < block_size; i++) iblock[i] = 0;
|
||||||
|
@ -201,7 +202,7 @@ function openpgp_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext,
|
||||||
|| iblock[block_size-1]!=(ablock[1]^ciphertext.charCodeAt(block_size+1)))
|
|| iblock[block_size-1]!=(ablock[1]^ciphertext.charCodeAt(block_size+1)))
|
||||||
{
|
{
|
||||||
util.print_eror("error duding decryption. Symmectric encrypted data not valid.");
|
util.print_eror("error duding decryption. Symmectric encrypted data not valid.");
|
||||||
return text;
|
return text.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RFC4880: Tag 18 and Resync:
|
/* RFC4880: Tag 18 and Resync:
|
||||||
|
@ -220,7 +221,7 @@ function openpgp_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext,
|
||||||
for(i = 0; i<block_size && i+n < ciphertext.length; i++)
|
for(i = 0; i<block_size && i+n < ciphertext.length; i++)
|
||||||
{
|
{
|
||||||
iblock[i] = ciphertext.charCodeAt(n+i);
|
iblock[i] = ciphertext.charCodeAt(n+i);
|
||||||
text += String.fromCharCode(ablock[i]^iblock[i]);
|
text.push(String.fromCharCode(ablock[i]^iblock[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -231,13 +232,13 @@ function openpgp_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext,
|
||||||
for(i = 0; i<block_size && i+n < ciphertext.length; i++)
|
for(i = 0; i<block_size && i+n < ciphertext.length; i++)
|
||||||
{
|
{
|
||||||
iblock[i] = ciphertext.charCodeAt(n+i);
|
iblock[i] = ciphertext.charCodeAt(n+i);
|
||||||
text += String.fromCharCode(ablock[i]^iblock[i]);
|
text.push(String.fromCharCode(ablock[i]^iblock[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,7 +262,7 @@ function normal_cfb_encrypt(blockcipherencryptfn, block_size, key, plaintext, iv
|
||||||
function normal_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext, iv) {
|
function normal_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext, iv) {
|
||||||
var blockp ="";
|
var blockp ="";
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
var plaintext = "";
|
var plaintext = [];
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
if (iv == null)
|
if (iv == null)
|
||||||
for (var i = 0; i < block_size; i++) blockp += String.fromCharCode(0);
|
for (var i = 0; i < block_size; i++) blockp += String.fromCharCode(0);
|
||||||
|
@ -271,10 +272,10 @@ function normal_cfb_decrypt(blockcipherencryptfn, block_size, key, ciphertext, i
|
||||||
var decblock = blockcipherencryptfn(blockp, key);
|
var decblock = blockcipherencryptfn(blockp, key);
|
||||||
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 (var i=0; i < blockp.length; i++) {
|
||||||
plaintext += String.fromCharCode(blockp.charCodeAt(i) ^ decblock[i]);
|
plaintext.push(String.fromCharCode(blockp.charCodeAt(i) ^ decblock[i]));
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plaintext;
|
return plaintext.join('');
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ function openpgp_crypto_getPrefixRandom(algo) {
|
||||||
* @return [String] plaintext data
|
* @return [String] plaintext data
|
||||||
*/
|
*/
|
||||||
function openpgp_crypto_symmetricDecrypt(algo, key, data, openpgp_cfb) {
|
function openpgp_crypto_symmetricDecrypt(algo, key, data, openpgp_cfb) {
|
||||||
util.print_debug("openpgp_crypto_symmetricDecrypt:\nalgo:"+algo+"\nencrypteddata:"+util.hexstrdump(data));
|
util.print_debug_hexstr_dump("openpgp_crypto_symmetricDecrypt:\nalgo:"+algo+"\nencrypteddata:",data);
|
||||||
var n = 0;
|
var n = 0;
|
||||||
if (!openpgp_cfb)
|
if (!openpgp_cfb)
|
||||||
n = 2;
|
n = 2;
|
||||||
|
@ -188,7 +188,7 @@ function openpgp_crypto_symmetricDecrypt(algo, key, data, openpgp_cfb) {
|
||||||
* @return [String] plain text data of the prefixed data
|
* @return [String] plain text data of the prefixed data
|
||||||
*/
|
*/
|
||||||
function openpgp_crypto_MDCSystemBytes(algo, key, data) {
|
function openpgp_crypto_MDCSystemBytes(algo, key, data) {
|
||||||
util.print_debug("openpgp_crypto_symmetricDecrypt:\nencrypteddata:"+util.hexstrdump(data));
|
util.print_debug_hexstr_dump("openpgp_crypto_symmetricDecrypt:\nencrypteddata:",data);
|
||||||
switch(algo) {
|
switch(algo) {
|
||||||
case 0: // Plaintext or unencrypted data
|
case 0: // Plaintext or unencrypted data
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -39,7 +39,7 @@ function openpgp_msg_message() {
|
||||||
var packet;
|
var packet;
|
||||||
var position = 0;
|
var position = 0;
|
||||||
var len = decrypted.length;
|
var len = decrypted.length;
|
||||||
util.print_debug("openpgp.msg.messge decrypt:\n"+util.hexstrdump(decrypted));
|
util.print_debug_hexstr_dump("openpgp.msg.messge decrypt:\n",decrypted);
|
||||||
|
|
||||||
while (position != decrypted.length && (packet = openpgp_packet.read_packet(decrypted, position, len)) != null) {
|
while (position != decrypted.length && (packet = openpgp_packet.read_packet(decrypted, position, len)) != null) {
|
||||||
if (packet.tagType == 8) {
|
if (packet.tagType == 8) {
|
||||||
|
@ -49,7 +49,7 @@ function openpgp_msg_message() {
|
||||||
util.print_debug(packet.toString());
|
util.print_debug(packet.toString());
|
||||||
position += packet.headerLength+packet.packetLength;
|
position += packet.headerLength+packet.packetLength;
|
||||||
if (position > 38)
|
if (position > 38)
|
||||||
util.print_debug("openpgp.msg.messge decrypt:\n"+util.hexstrdump(decrypted.substring(position)));
|
util.print_debug_hexstr_dump("openpgp.msg.messge decrypt:\n",decrypted.substring(position));
|
||||||
len = decrypted.length - position;
|
len = decrypted.length - position;
|
||||||
if (packet.tagType == 11) {
|
if (packet.tagType == 11) {
|
||||||
this.text = packet.data;
|
this.text = packet.data;
|
||||||
|
|
|
@ -137,6 +137,11 @@ function openpgp_packet_encryptedintegrityprotecteddata() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toString() {
|
function toString() {
|
||||||
|
var data = '';
|
||||||
|
if(openpgp.config.debug)
|
||||||
|
data = ' data: Bytes ['
|
||||||
|
+ util.hexstrdump(this.encryptedData) + ']';
|
||||||
|
|
||||||
return '5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18)\n'
|
return '5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18)\n'
|
||||||
+ ' length: '
|
+ ' length: '
|
||||||
+ this.packetLength
|
+ this.packetLength
|
||||||
|
@ -144,8 +149,7 @@ function openpgp_packet_encryptedintegrityprotecteddata() {
|
||||||
+ ' version: '
|
+ ' version: '
|
||||||
+ this.version
|
+ this.version
|
||||||
+ '\n'
|
+ '\n'
|
||||||
+ ' data: Bytes ['
|
+ data;
|
||||||
+ util.hexstrdump(this.encryptedData) + ']';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.write_packet = write_packet;
|
this.write_packet = write_packet;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user