@renovatebot/kbpgp
Version:
Keybase's PGP Implementation
74 lines (66 loc) • 2.33 kB
JavaScript
// Generated by IcedCoffeeScript 112.8.1
var AES, WordArray, ciphers, decrypt, encrypt, ref;
ref = require('triplesec'), ciphers = ref.ciphers, WordArray = ref.WordArray;
AES = ciphers.AES;
encrypt = function(arg) {
var block_cipher_class, block_size, c, cipher, e, iv, key, list, out, plaintext, pos;
block_cipher_class = arg.block_cipher_class, key = arg.key, cipher = arg.cipher, plaintext = arg.plaintext, iv = arg.iv;
block_cipher_class || (block_cipher_class = AES);
cipher || (cipher = new block_cipher_class(WordArray.from_buffer(key)));
block_size = cipher.blockSize;
c = WordArray.from_buffer(iv.slice(0, block_size));
pos = 0;
list = (function() {
var results;
results = [];
while (plaintext.length > pos) {
cipher.encryptBlock(c.words, 0);
e = c;
c = WordArray.from_buffer(plaintext.slice(pos, pos + block_size));
e.xor(c, {
n_words: c.words.length
});
pos += block_size;
c = e;
results.push(e.to_buffer());
}
return results;
})();
out = Buffer.concat(list);
return out.slice(0, plaintext.length);
};
decrypt = function(arg) {
var b, block_cipher_class, block_size, cipher, ciphertext, d, i, iv, key, list, out, pos;
block_cipher_class = arg.block_cipher_class, key = arg.key, cipher = arg.cipher, ciphertext = arg.ciphertext, iv = arg.iv;
block_cipher_class || (block_cipher_class = AES);
cipher || (cipher = new block_cipher_class(WordArray.from_buffer(key)));
block_size = cipher.blockSize;
iv || (iv = Buffer.from((function() {
var j, ref1, results;
results = [];
for (i = j = 0, ref1 = block_size; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
results.push(0);
}
return results;
})()));
b = WordArray.from_buffer(iv.slice(0, block_size));
pos = 0;
list = (function() {
var results;
results = [];
while (ciphertext.length > pos) {
cipher.encryptBlock(b.words, 0);
d = b;
b = WordArray.from_buffer(ciphertext.slice(pos, pos + block_size));
d.xor(b, {});
pos += block_size;
results.push(d.to_buffer());
}
return results;
})();
out = Buffer.concat(list);
return out.slice(out, ciphertext.length);
};
exports.encrypt = encrypt;
exports.decrypt = decrypt;
//# sourceMappingURL=cfb.js.map