Many documentation improvements; more to come

This commit is contained in:
Mahrud Sayrafi 2018-03-08 17:55:44 -08:00
parent 184a988d0d
commit a5e7562066
No known key found for this signature in database
GPG Key ID: C24071B956C3245F
34 changed files with 400 additions and 218 deletions

View File

@ -16,66 +16,124 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/** /**
* This object contains global configuration values. * Global configuration values.
* @requires enums * @requires enums
* @module config/config
*/ */
import enums from '../enums'; import enums from '../enums';
export default { export default {
/** @property {Integer} prefer_hash_algorithm Default hash algorithm {@link module:enums.hash} */ /**
* @memberof module:config
* @property {Integer} prefer_hash_algorithm Default hash algorithm {@link module:enums.hash}
*/
prefer_hash_algorithm: enums.hash.sha256, prefer_hash_algorithm: enums.hash.sha256,
/** @property {Integer} encryption_cipher Default encryption cipher {@link module:enums.symmetric} */ /**
* @memberof module:config
* @property {Integer} encryption_cipher Default encryption cipher {@link module:enums.symmetric}
*/
encryption_cipher: enums.symmetric.aes256, encryption_cipher: enums.symmetric.aes256,
/** @property {Integer} compression Default compression algorithm {@link module:enums.compression} */ /**
* @memberof module:config
* @property {Integer} compression Default compression algorithm {@link module:enums.compression}
*/
compression: enums.compression.uncompressed, compression: enums.compression.uncompressed,
/** @property {Integer} deflate_level Default zip/zlib compression level, between 1 and 9 */ /**
* @memberof module:config
* @property {Integer} deflate_level Default zip/zlib compression level, between 1 and 9
*/
deflate_level: 6, deflate_level: 6,
/** /**
* Use Authenticated Encryption with Additional Data (AEAD) protection for symmetric encryption. * Use Authenticated Encryption with Additional Data (AEAD) protection for symmetric encryption.
* **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS** * **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS**
* @memberof module:config
* @property {Boolean} aead_protect * @property {Boolean} aead_protect
*/ */
aead_protect: false, aead_protect: false,
/** Use integrity protection for symmetric encryption /** Use integrity protection for symmetric encryption
* @property {Boolean} integrity_protect */ * @memberof module:config
* @property {Boolean} integrity_protect
*/
integrity_protect: true, integrity_protect: true,
/** @property {Boolean} ignore_mdc_error Fail on decrypt if message is not integrity protected */ /**
* @memberof module:config
* @property {Boolean} ignore_mdc_error Fail on decrypt if message is not integrity protected
*/
ignore_mdc_error: false, ignore_mdc_error: false,
/** @property {Boolean} checksum_required Do not throw error when armor is missing a checksum */ /**
* @memberof module:config
* @property {Boolean} checksum_required Do not throw error when armor is missing a checksum
*/
checksum_required: false, checksum_required: false,
/** @property {Boolean} rsa_blinding */ /**
* @memberof module:config
* @property {Boolean} rsa_blinding
*/
rsa_blinding: true, rsa_blinding: true,
/** Work-around for rare GPG decryption bug when encrypting with multiple passwords /**
* Slower and slightly less secure * Work-around for rare GPG decryption bug when encrypting with multiple passwords.
* **Slower and slightly less secure**
* @memberof module:config
* @property {Boolean} password_collision_check * @property {Boolean} password_collision_check
*/ */
password_collision_check: false, password_collision_check: false,
/** @property {Boolean} revocations_expire If true, expired revocation signatures are ignored */ /**
* @memberof module:config
* @property {Boolean} revocations_expire If true, expired revocation signatures are ignored
*/
revocations_expire: false, revocations_expire: false,
/** @property {Boolean} use_native Use native Node.js crypto/zlib and WebCrypto APIs when available */ /**
* @memberof module:config
* @property {Boolean} use_native Use native Node.js crypto/zlib and WebCrypto APIs when available
*/
use_native: true, use_native: true,
/** @property {Boolean} Use transferable objects between the Web Worker and main thread */ /**
* @memberof module:config
* @property {Boolean} Use transferable objects between the Web Worker and main thread
*/
zero_copy: false, zero_copy: false,
/** @property {Boolean} debug If enabled, debug messages will be printed */ /**
* @memberof module:config
* @property {Boolean} debug If enabled, debug messages will be printed
*/
debug: false, debug: false,
/** @property {Boolean} tolerant Ignore unsupported/unrecognizable packets instead of throwing an error */ /**
* @memberof module:config
* @property {Boolean} tolerant Ignore unsupported/unrecognizable packets instead of throwing an error
*/
tolerant: true, tolerant: true,
/** @property {Boolean} show_version Whether to include {@link module:config/config.versionstring} in armored messages */ /**
* @memberof module:config
* @property {Boolean} show_version Whether to include {@link module:config/config.versionstring} in armored messages
*/
show_version: true, show_version: true,
/** @property {Boolean} show_comment Whether to include {@link module:config/config.commentstring} in armored messages */ /**
* @memberof module:config
* @property {Boolean} show_comment Whether to include {@link module:config/config.commentstring} in armored messages
*/
show_comment: true, show_comment: true,
/** @property {String} versionstring A version string to be included in armored messages */ /**
* @memberof module:config
* @property {String} versionstring A version string to be included in armored messages
*/
versionstring: "OpenPGP.js VERSION", versionstring: "OpenPGP.js VERSION",
/** @property {String} commentstring A comment string to be included in armored messages */ /**
* @memberof module:config
* @property {String} commentstring A comment string to be included in armored messages
*/
commentstring: "https://openpgpjs.org", commentstring: "https://openpgpjs.org",
/** @property {String} keyserver */ /**
* @memberof module:config
* @property {String} keyserver
*/
keyserver: "https://keyserver.ubuntu.com", keyserver: "https://keyserver.ubuntu.com",
/** @property {String} node_store */ /**
* @memberof module:config
* @property {String} node_store
*/
node_store: "./openpgp.store" node_store: "./openpgp.store"
}; };

View File

@ -1,4 +1,5 @@
/** /**
* @fileoverview Provides functions for storing and retrieving configuration from HTML5 local storage.
* @module config/localStorage * @module config/localStorage
*/ */

View File

@ -15,7 +15,13 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// Implementation of RFC 3394 AES Key Wrap & Key Unwrap funcions /**
* @fileoverview Implementation of RFC 3394 AES Key Wrap & Key Unwrap funcions
* @see module:crypto/public_key/elliptic/ecdh
* @requires crypto/cipher
* @requires util
* @module crypto/aes_kw
*/
import cipher from './cipher'; import cipher from './cipher';
import util from '../util'; import util from '../util';
@ -127,6 +133,21 @@ function pack() {
} }
export default { export default {
/**
* AES key wrap
* @function
* @param {String} key
* @param {String} data
* @returns {Uint8Array}
*/
wrap, wrap,
/**
* AES key unwrap
* @function
* @param {String} key
* @param {String} data
* @returns {Uint8Array}
* @throws {Error}
*/
unwrap unwrap
}; };

View File

@ -27,8 +27,8 @@ import cipher from './cipher';
export default { export default {
/** /**
* This function encrypts a given with the specified prefixrandom * This function encrypts a given plaintext with the specified prefixrandom
* using the specified blockcipher to encrypt a message * using the specified blockcipher
* @param {Uint8Array} prefixrandom random bytes of block_size length * @param {Uint8Array} prefixrandom random bytes of block_size length
* to be used in prefixing the data * to be used in prefixing the data
* @param {String} cipherfn the algorithm cipher class to encrypt * @param {String} cipherfn the algorithm cipher class to encrypt
@ -163,9 +163,9 @@ export default {
result[iblock.length + 1] = ablock[1] ^ ciphertext[block_size + 1]; result[iblock.length + 1] = ablock[1] ^ ciphertext[block_size + 1];
return result; return result;
}, },
/** /**
* This function decrypts a given plaintext using the specified * This function decrypts a given ciphertext using the specified blockcipher
* blockcipher to decrypt a message
* @param {String} cipherfn the algorithm cipher class to decrypt * @param {String} cipherfn the algorithm cipher class to decrypt
* data in one block_size encryption, {@link module:crypto/cipher}. * data in one block_size encryption, {@link module:crypto/cipher}.
* @param {Uint8Array} key Uint8Array representation of key to be used to decrypt the ciphertext. * @param {Uint8Array} key Uint8Array representation of key to be used to decrypt the ciphertext.
@ -177,7 +177,6 @@ export default {
* encryptedintegrityprotecteddata packet is not resyncing the IV. * encryptedintegrityprotecteddata packet is not resyncing the IV.
* @returns {Uint8Array} the plaintext data * @returns {Uint8Array} the plaintext data
*/ */
decrypt: function(cipherfn, key, ciphertext, resync) { decrypt: function(cipherfn, key, ciphertext, resync) {
cipherfn = new cipher[cipherfn](key); cipherfn = new cipher[cipherfn](key);
const block_size = cipherfn.blockSize; const block_size = cipherfn.blockSize;

View File

@ -1,6 +1,5 @@
/** /**
* @requires asmcrypto.js * @requires asmcrypto.js
* @module crypto/cipher/aes
*/ */
import { AES_ECB } from 'asmcrypto.js/src/aes/ecb/exports'; import { AES_ECB } from 'asmcrypto.js/src/aes/ecb/exports';

View File

@ -3,10 +3,6 @@
* Originally written by nklein software (nklein.com) * Originally written by nklein software (nklein.com)
*/ */
/**
* @module crypto/cipher/blowfish
*/
/* /*
* Javascript implementation based on Bruce Schneier's reference implementation. * Javascript implementation based on Bruce Schneier's reference implementation.
* *
@ -387,7 +383,6 @@ Blowfish.prototype.init = function(key) {
}; };
// added by Recurity Labs // added by Recurity Labs
function BF(key) { function BF(key) {
this.bf = new Blowfish(); this.bf = new Blowfish();
this.bf.init(key); this.bf.init(key);

View File

@ -14,8 +14,6 @@
// CAST5 constructor // CAST5 constructor
/** @module crypto/cipher/cast5 */
function OpenpgpSymencCast5() { function OpenpgpSymencCast5() {
this.BlockSize = 8; this.BlockSize = 8;
this.KeySize = 16; this.KeySize = 16;

View File

@ -21,10 +21,6 @@
//des //des
//this takes the key, the message, and whether to encrypt or decrypt //this takes the key, the message, and whether to encrypt or decrypt
/**
* @module crypto/cipher/des
*/
function des(keys, message, encrypt, mode, iv, padding) { function des(keys, message, encrypt, mode, iv, padding) {
//declaring this locally speeds things up a bit //declaring this locally speeds things up a bit
const spfunction1 = new Array( const spfunction1 = new Array(

View File

@ -15,21 +15,75 @@ import twofish from './twofish';
import blowfish from './blowfish'; import blowfish from './blowfish';
export default { export default {
/** @see module:crypto/cipher/aes */ /**
* AES-128 encryption and decryption (ID 7)
* @function
* @param {String} key 128-bit key
* @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
* @see {@link https://csrc.nist.gov/publications/fips/fips197/fips-197.pdf|NIST FIPS-197}
* @returns {Object}
* @requires asmcrypto.js
*/
aes128: aes(128), aes128: aes(128),
/**
* AES-128 Block Cipher (ID 8)
* @function
* @param {String} key 192-bit key
* @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
* @see {@link https://csrc.nist.gov/publications/fips/fips197/fips-197.pdf|NIST FIPS-197}
* @returns {Object}
* @requires asmcrypto.js
*/
aes192: aes(192), aes192: aes(192),
/**
* AES-128 Block Cipher (ID 9)
* @function
* @param {String} key 256-bit key
* @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
* @see {@link https://csrc.nist.gov/publications/fips/fips197/fips-197.pdf|NIST FIPS-197}
* @returns {Object}
* @requires asmcrypto.js
*/
aes256: aes(256), aes256: aes(256),
/** @see module:crypto/cipher/des~DES */ // Not in OpenPGP specifications
des: des.DES, des: des.DES,
/** @see module:crypto/cipher/des~TripleDES */ /**
* Triple DES Block Cipher (ID 2)
* @function
* @param {String} key 192-bit key
* @see {@link https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-67r2.pdf|NIST SP 800-67}
* @returns {Object}
*/
tripledes: des.TripleDES, tripledes: des.TripleDES,
/** @see module:crypto/cipher/cast5 */ /**
* CAST-128 Block Cipher (ID 3)
* @function
* @param {String} key 128-bit key
* @see {@link https://tools.ietf.org/html/rfc2144|The CAST-128 Encryption Algorithm}
* @returns {Object}
*/
cast5: cast5, cast5: cast5,
/** @see module:crypto/cipher/twofish */ /**
* Twofish Block Cipher (ID 10)
* @function
* @param {String} key 256-bit key
* @see {@link https://tools.ietf.org/html/rfc4880#ref-TWOFISH|TWOFISH}
* @returns {Object}
*/
twofish: twofish, twofish: twofish,
/** @see module:crypto/cipher/blowfish */ /**
* Blowfish Block Cipher (ID 4)
* @function
* @param {String} key 128-bit key
* @see {@link https://tools.ietf.org/html/rfc4880#ref-BLOWFISH|BLOWFISH}
* @returns {Object}
*/
blowfish: blowfish, blowfish: blowfish,
/** Not implemented */ /**
* Not implemented
* @function
* @throws {Error}
*/
idea: function() { idea: function() {
throw new Error('IDEA symmetric-key algorithm not implemented'); throw new Error('IDEA symmetric-key algorithm not implemented');
} }

View File

@ -1,3 +1,5 @@
/* eslint-disable no-mixed-operators */
/* Modified by Recurity Labs GmbH /* Modified by Recurity Labs GmbH
* *
* Cipher.js * Cipher.js
@ -18,12 +20,6 @@
* *
*/ */
/**
* @module crypto/cipher/twofish
*/
/* eslint-disable no-mixed-operators */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Math //Math
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -339,22 +335,13 @@ function createTwofish() {
function TF(key) { function TF(key) {
this.tf = createTwofish(); this.tf = createTwofish();
this.tf.open(toArray(key), 0); this.tf.open(Array.from(key), 0);
this.encrypt = function(block) { this.encrypt = function(block) {
return this.tf.encrypt(toArray(block), 0); return this.tf.encrypt(Array.from(block), 0);
}; };
} }
function toArray(typedArray) {
// Array.apply([], typedArray) does not work in PhantomJS 1.9
const result = [];
for (let i = 0; i < typedArray.length; i++) {
result[i] = typedArray[i];
}
return result;
}
TF.keySize = TF.prototype.keySize = 32; TF.keySize = TF.prototype.keySize = 32;
TF.blockSize = TF.prototype.blockSize = 16; TF.blockSize = TF.prototype.blockSize = 16;

View File

@ -18,6 +18,8 @@
// The GPG4Browsers crypto interface // The GPG4Browsers crypto interface
/** /**
* @fileoverview Provides functions for asymmetric encryption and decryption as
* well as key generation and parameter handling for all public-key cryptosystems.
* @requires crypto/public_key * @requires crypto/public_key
* @requires crypto/cipher * @requires crypto/cipher
* @requires crypto/random * @requires crypto/random

View File

@ -1,5 +1,8 @@
/** /**
* @fileoverview Hashing functions * @fileoverview Provides an interface to hashing functions available in Node.js or external libraries.
* @see {@link https://github.com/srijs/rusha|Rusha}
* @see {@link https://github.com/asmcrypto/asmcrypto.js|asmCrypto}
* @see {@link https://github.com/indutny/hash.js|hash.js}
* @requires rusha * @requires rusha
* @requires asmcrypto.js * @requires asmcrypto.js
* @requires hash.js * @requires hash.js
@ -31,7 +34,7 @@ function node_hash(type) {
function hashjs_hash(hash) { function hashjs_hash(hash) {
return function(data) { return function(data) {
return util.str_to_Uint8Array(util.hex_to_str(hash().update(data).digest('hex'))); return util.hex_to_Uint8Array(hash().update(data).digest('hex'));
}; };
} }
@ -48,34 +51,34 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions
}; };
} else { // Use JS fallbacks } else { // Use JS fallbacks
hash_fns = { hash_fns = {
/** @see module:./md5 */
md5: md5, md5: md5,
/** @see module:rusha */
sha1: function(data) { sha1: function(data) {
return util.str_to_Uint8Array(util.hex_to_str(rusha.digest(data))); return util.hex_to_Uint8Array(rusha.digest(data));
}, },
/** @see module:hash.js */
sha224: hashjs_hash(sha224), sha224: hashjs_hash(sha224),
/** @see module:asmcrypto */
sha256: SHA256.bytes, sha256: SHA256.bytes,
/** @see module:hash.js */
sha384: hashjs_hash(sha384), sha384: hashjs_hash(sha384),
// TODO, benchmark this vs asmCrypto's SHA512 // TODO, benchmark this vs asmCrypto's SHA512
/** @see module:hash.js */
sha512: hashjs_hash(sha512), sha512: hashjs_hash(sha512),
/** @see module:hash.js */
ripemd: hashjs_hash(ripemd160) ripemd: hashjs_hash(ripemd160)
}; };
} }
export default { export default {
/** @see module:md5 */
md5: hash_fns.md5, md5: hash_fns.md5,
/** @see rusha */
sha1: hash_fns.sha1, sha1: hash_fns.sha1,
/** @see hash.js */
sha224: hash_fns.sha224, sha224: hash_fns.sha224,
/** @see asmCrypto */
sha256: hash_fns.sha256, sha256: hash_fns.sha256,
/** @see hash.js */
sha384: hash_fns.sha384, sha384: hash_fns.sha384,
/** @see hash.js */
sha512: hash_fns.sha512, sha512: hash_fns.sha512,
/** @see hash.js */
ripemd: hash_fns.ripemd, ripemd: hash_fns.ripemd,
/** /**

View File

@ -14,15 +14,11 @@
/** /**
* @requires util * @requires util
* @module crypto/hash/md5
*/ */
import util from '../../util'; import util from '../../util';
/** // MD5 Digest
* MD5 hash
* @param {String} entree string to hash
*/
function md5(entree) { function md5(entree) {
const digest = md51(util.Uint8Array_to_str(entree)); const digest = md51(util.Uint8Array_to_str(entree));
return util.hex_to_Uint8Array(hex(digest)); return util.hex_to_Uint8Array(hex(digest));

View File

@ -16,7 +16,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/** /**
* PKCS1 encoding * @fileoverview Provides EME-PKCS1-v1_5 encoding and decoding and EMSA-PKCS1-v1_5 encoding function
* @see module:crypto/public_key/rsa
* @see module:crypto/public_key/elliptic/ecdh
* @see module:packet/public_key_encrypted_session_key
* @requires crypto/random * @requires crypto/random
* @requires crypto/hash * @requires crypto/hash
* @requires util * @requires util
@ -27,8 +30,14 @@ import random from './random';
import hash from './hash'; import hash from './hash';
import util from '../util'; import util from '../util';
/** @namespace */
const eme = {};
/** @namespace */
const emsa = {};
/** /**
* ASN1 object identifiers for hashes (See {@link https://tools.ietf.org/html/rfc4880#section-5.2.2}) * ASN1 object identifiers for hashes
* @see {@link https://tools.ietf.org/html/rfc4880#section-5.2.2}
*/ */
const hash_headers = []; const 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,
@ -65,17 +74,15 @@ async function getPkcs1Padding(length) {
return result; return result;
} }
export default {
eme: {
/** /**
* create a EME-PKCS1-v1_5 padding (See {@link https://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1}) * Create a EME-PKCS1-v1_5 padded message
* @see {@link https://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1}
* @param {String} M message to be encoded * @param {String} M message to be encoded
* @param {Integer} k the length in octets of the key modulus * @param {Integer} k the length in octets of the key modulus
* @returns {Promise<String>} EME-PKCS1 padded message * @returns {Promise<String>} EME-PKCS1 padded message
* @async * @async
*/ */
encode: async function(M, k) { eme.encode = async function(M, k) {
const mLen = M.length; const mLen = M.length;
// length checking // length checking
if (mLen > k - 11) { if (mLen > k - 11) {
@ -91,13 +98,15 @@ export default {
PS + PS +
String.fromCharCode(0) + String.fromCharCode(0) +
M; M;
}, };
/** /**
* decodes a EME-PKCS1-v1_5 padding (See {@link https://tools.ietf.org/html/rfc4880#section-13.1.2|RFC 4880 13.1.2}) * Decode a EME-PKCS1-v1_5 padded message
* @see {@link https://tools.ietf.org/html/rfc4880#section-13.1.2|RFC 4880 13.1.2}
* @param {String} EM encoded message, an octet string * @param {String} EM encoded message, an octet string
* @returns {String} message, an octet string * @returns {String} message, an octet string
*/ */
decode: function(EM) { eme.decode = function(EM) {
// leading zeros truncated by bn.js // leading zeros truncated by bn.js
if (EM.charCodeAt(0) !== 0) { if (EM.charCodeAt(0) !== 0) {
EM = String.fromCharCode(0) + EM; EM = String.fromCharCode(0) + EM;
@ -114,18 +123,17 @@ export default {
return EM.substr(i); return EM.substr(i);
} }
throw new Error('Decryption error'); throw new Error('Decryption error');
} };
},
emsa: {
/** /**
* create a EMSA-PKCS1-v1_5 padding (See {@link https://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3}) * Create a EMSA-PKCS1-v1_5 padded message
* @see {@link https://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3}
* @param {Integer} algo Hash algorithm type used * @param {Integer} algo Hash algorithm type used
* @param {String} M message to be encoded * @param {String} M message to be encoded
* @param {Integer} emLen intended length in octets of the encoded message * @param {Integer} emLen intended length in octets of the encoded message
* @returns {String} encoded message * @returns {String} encoded message
*/ */
encode: function(algo, M, emLen) { emsa.encode = function(algo, M, emLen) {
let i; let i;
// Apply the hash function to the message M to produce a hash value H // Apply the hash function to the message M to produce a hash value H
const H = util.Uint8Array_to_str(hash.digest(algo, util.str_to_Uint8Array(M))); const H = util.Uint8Array_to_str(hash.digest(algo, util.str_to_Uint8Array(M)));
@ -159,6 +167,6 @@ export default {
String.fromCharCode(0x00) + String.fromCharCode(0x00) +
T; T;
return util.str_to_hex(EM); return util.str_to_hex(EM);
}
}
}; };
export default { eme, emsa };

View File

@ -15,7 +15,11 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// Functions to add and remove PKCS5 padding /**
* @fileoverview Functions to add and remove PKCS5 padding
* @see module:packet/public_key_encrypted_session_key
* @module crypto/pkcs5
*/
/** /**
* Add pkcs5 padding to a text. * Add pkcs5 padding to a text.

View File

@ -1,24 +1,24 @@
/** /**
* @fileoverview Asymmetric cryptography functions * @fileoverview Asymmetric cryptography functions
* @see module:crypto/public_key/dsa * @requires crypto/public_key/dsa
* @see module:crypto/public_key/elgamal * @requires crypto/public_key/elgamal
* @see module:crypto/public_key/elliptic * @requires crypto/public_key/elliptic
* @see module:crypto/public_key/rsa * @requires crypto/public_key/rsa
* @module crypto/public_key * @module crypto/public_key
*/ */
/** @see module:crypto/public_key/rsa */
import rsa from './rsa'; import rsa from './rsa';
/** @see module:crypto/public_key/elgamal */
import elgamal from './elgamal'; import elgamal from './elgamal';
/** @see module:crypto/public_key/elliptic */
import elliptic from './elliptic'; import elliptic from './elliptic';
/** @see module:crypto/public_key/dsa */
import dsa from './dsa'; import dsa from './dsa';
export default { export default {
/** @see module:crypto/public_key/rsa */
rsa: rsa, rsa: rsa,
/** @see module:crypto/public_key/elgamal */
elgamal: elgamal, elgamal: elgamal,
/** @see module:crypto/public_key/elliptic */
elliptic: elliptic, elliptic: elliptic,
/** @see module:crypto/public_key/dsa */
dsa: dsa dsa: dsa
}; };

View File

@ -49,11 +49,11 @@ function promisifyIE11Op(keyObj, err) {
export default { export default {
/** Create signature /** Create signature
* @param m message as BN * @param {BN} m message
* @param n public MPI part as BN * @param {BN} n RSA public modulus
* @param e public MPI part as BN * @param {BN} e RSA public exponent
* @param d private MPI part as BN * @param {BN} d RSA private exponent
* @returns BN * @returns {BN} RSA Signature
* @async * @async
*/ */
sign: async function(m, n, e, d) { sign: async function(m, n, e, d) {
@ -66,10 +66,10 @@ export default {
/** /**
* Verify signature * Verify signature
* @param s signature as BN * @param {BN} s signature
* @param n public MPI part as BN * @param {BN} n RSA public modulus
* @param e public MPI part as BN * @param {BN} e RSA public exponent
* @returns BN * @returns {BN}
* @async * @async
*/ */
verify: async function(s, n, e) { verify: async function(s, n, e) {
@ -82,10 +82,10 @@ export default {
/** /**
* Encrypt message * Encrypt message
* @param m message as BN * @param {BN} m message
* @param n public MPI part as BN * @param {BN} n RSA public modulus
* @param e public MPI part as BN * @param {BN} e RSA public exponent
* @returns BN * @returns {BN} RSA Ciphertext
* @async * @async
*/ */
encrypt: async function(m, n, e) { encrypt: async function(m, n, e) {
@ -98,14 +98,14 @@ export default {
/** /**
* Decrypt RSA message * Decrypt RSA message
* @param m message as BN * @param {BN} m message
* @param n RSA public modulus n as BN * @param {BN} n RSA public modulus
* @param e RSA public exponent as BN * @param {BN} e RSA public exponent
* @param d RSA d as BN * @param {BN} d RSA private exponent
* @param p RSA p as BN * @param {BN} p RSA private prime p
* @param q RSA q as BN * @param {BN} q RSA private prime q
* @param u RSA u as BN * @param {BN} u RSA private inverse of prime q
* @returns {BN} The decrypted value of the message * @returns {BN} RSA Plaintext
* @async * @async
*/ */
decrypt: async function(m, n, e, d, p, q, u) { decrypt: async function(m, n, e, d, p, q, u) {
@ -141,7 +141,11 @@ export default {
}, },
/** /**
* Generate a new random private key B bits long with public exponent E * Generate a new random private key B bits long with public exponent E.
*
* When possible, webCrypto is used. Otherwise, primes are generated using
* 40 rounds of the Miller-Rabin probabilistic random prime generation algorithm.
* @see module:crypto/public_key/prime
* @param {Integer} B RSA bit length * @param {Integer} B RSA bit length
* @param {String} E RSA public exponent in hex string * @param {String} E RSA public exponent in hex string
* @returns {{n: BN, e: BN, d: BN, * @returns {{n: BN, e: BN, d: BN,

View File

@ -18,6 +18,7 @@
// The GPG4Browsers crypto interface // The GPG4Browsers crypto interface
/** /**
* @fileoverview Provides tools for retrieving secure randomness from browsers or Node.js
* @requires bn.js * @requires bn.js
* @requires type/mpi * @requires type/mpi
* @requires util * @requires util

View File

@ -1,4 +1,5 @@
/** /**
* @fileoverview Provides functions for asymmetric signing and signature verification
* @requires bn.js * @requires bn.js
* @requires crypto/public_key * @requires crypto/public_key
* @requires crypto/pkcs1 * @requires crypto/pkcs1

View File

@ -16,6 +16,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/** /**
* @fileoverview Provides the Keyring class
* @requires key * @requires key
* @requires keyring/localstore * @requires keyring/localstore
* @module keyring/keyring * @module keyring/keyring

View File

@ -16,6 +16,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/** /**
* @fileoverview Provides the LocalStore class
* @requires config * @requires config
* @requires key * @requires key
* @requires util * @requires util

View File

@ -1,6 +1,6 @@
/** /**
* @requires enums * @requires enums
* @module packet * @module packet/all_packets
*/ */
import enums from '../enums.js'; import enums from '../enums.js';

View File

@ -16,6 +16,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/** /**
* @fileoverview Functions for reading and writing packets
* @requires enums * @requires enums
* @requires util * @requires util
* @module packet/packet * @module packet/packet

View File

@ -1,5 +1,6 @@
/* eslint-disable callback-return */ /* eslint-disable callback-return */
/** /**
* @fileoverview Provides a class for representing lists of OpenPGP packets.
* @requires util * @requires util
* @requires enums * @requires enums
* @requires packet * @requires packet

View File

@ -36,6 +36,8 @@ import type_keyid from '../type/keyid';
import type_mpi from '../type/mpi'; import type_mpi from '../type/mpi';
/** /**
* A Public-Key packet starts a series of packets that forms an OpenPGP
* key (sometimes called an OpenPGP certificate).
* @constructor * @constructor
*/ */
function PublicKey() { function PublicKey() {
@ -159,7 +161,7 @@ PublicKey.prototype.getKeyId = function () {
} }
this.keyid = new type_keyid(); this.keyid = new type_keyid();
if (this.version === 4) { if (this.version === 4) {
this.keyid.read(util.str_to_Uint8Array(util.hex_to_str(this.getFingerprint()).substr(12, 8))); this.keyid.read(util.hex_to_Uint8Array(this.getFingerprint()).subarray(12, 20));
} else if (this.version === 3) { } else if (this.version === 3) {
const arr = this.params[0].write(); const arr = this.params[0].write();
this.keyid.read(arr.subarray(arr.length - 8, arr.length)); this.keyid.read(arr.subarray(arr.length - 8, arr.length));

View File

@ -25,6 +25,11 @@ import publicKey from './public_key.js';
import enums from '../enums.js'; import enums from '../enums.js';
/** /**
* A Public-Subkey packet (tag 14) has exactly the same format as a
* Public-Key packet, but denotes a subkey. One or more subkeys may be
* associated with a top-level key. By convention, the top-level key
* provides signature services, and the subkeys provide encryption
* services.
* @constructor * @constructor
* @extends module:packet/public_key * @extends module:packet/public_key
*/ */

View File

@ -39,6 +39,9 @@ import type_s2k from '../type/s2k.js';
import type_keyid from '../type/keyid.js'; import type_keyid from '../type/keyid.js';
/** /**
* A Secret-Key packet contains all the information that is found in a
* Public-Key packet, including the public-key material, but also
* includes the secret-key material after all the public-key fields.
* @constructor * @constructor
* @extends module:packet/public_key * @extends module:packet/public_key
*/ */

View File

@ -25,6 +25,8 @@ import secretKey from './secret_key.js';
import enums from '../enums.js'; import enums from '../enums.js';
/** /**
* A Secret-Subkey packet (tag 7) is the subkey analog of the Secret
* Key packet and has exactly the same format.
* @constructor * @constructor
* @extends module:packet/secret_key * @extends module:packet/secret_key
*/ */

View File

@ -21,17 +21,21 @@
* *
* {@link https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1}: * {@link https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1}:
* AEAD Protected Data Packet * AEAD Protected Data Packet
* @requires crypto
* @requires enums
* @requires util
* @module packet/sym_encrypted_aead_protected
*/ */
import util from '../util';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums'; import enums from '../enums';
import util from '../util';
const VERSION = 1; // A one-octet version number of the data packet. const VERSION = 1; // A one-octet version number of the data packet.
const IV_LEN = crypto.gcm.ivLength; // currently only AES-GCM is supported const IV_LEN = crypto.gcm.ivLength; // currently only AES-GCM is supported
/** /**
* @class * @constructor
*/ */
function SymEncryptedAEADProtected() { function SymEncryptedAEADProtected() {
this.tag = enums.packet.symEncryptedAEADProtected; this.tag = enums.packet.symEncryptedAEADProtected;

View File

@ -1,4 +1,17 @@
/** /**
* Implementation of the Trust Packet (Tag 12)
*
* {@link https://tools.ietf.org/html/rfc4880#section-5.10|RFC4880 5.10}:
* The Trust packet is used only within keyrings and is not normally
* exported. Trust packets contain data that record the user's
* specifications of which key holders are trustworthy introducers,
* along with other information that implementing software uses for
* trust information. The format of Trust packets is defined by a given
* implementation.
*
* Trust packets SHOULD NOT be emitted to output streams that are
* transferred to other users, and they SHOULD be ignored on any input
* other than local keyring files.
* @requires enums * @requires enums
* @module packet/trust * @module packet/trust
*/ */

View File

@ -81,7 +81,7 @@ Keyid.fromClone = function (clone) {
Keyid.fromId = function (hex) { Keyid.fromId = function (hex) {
const keyid = new Keyid(); const keyid = new Keyid();
keyid.read(util.str_to_Uint8Array(util.hex_to_str(hex))); keyid.read(util.hex_to_Uint8Array(hex));
return keyid; return keyid;
}; };

View File

@ -23,9 +23,10 @@
*/ */
import config from './config'; import config from './config';
import util from './util'; // re-import module to access util functions
import b64 from './encoding/base64'; import b64 from './encoding/base64';
const util = { export default {
isString: function(data) { isString: function(data) {
return typeof data === 'string' || String.prototype.isPrototypeOf(data); return typeof data === 'string' || String.prototype.isPrototypeOf(data);
@ -534,5 +535,3 @@ const util = {
return /</.test(data) && />$/.test(data); return /</.test(data) && />$/.test(data);
} }
}; };
export default util;

View File

@ -15,6 +15,18 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/**
* @fileoverview Provides functions for maintaining browser workers
* @see module:openpgp.initWorker
* @see module:openpgp.getWorker
* @see module:openpgp.destroyWorker
* @see module:worker/worker
* @requires util
* @requires crypto
* @requires packet
* @module worker/async_proxy
*/
import util from '../util.js'; import util from '../util.js';
import crypto from '../crypto'; import crypto from '../crypto';
import packet from '../packet'; import packet from '../packet';
@ -98,6 +110,7 @@ AsyncProxy.prototype.getID = function() {
/** /**
* Send message to worker with random data * Send message to worker with random data
* @param {Integer} size Number of bytes to send * @param {Integer} size Number of bytes to send
* @async
*/ */
AsyncProxy.prototype.seedRandom = async function(workerId, size) { AsyncProxy.prototype.seedRandom = async function(workerId, size) {
const buf = await crypto.random.getRandomBytes(size); const buf = await crypto.random.getRandomBytes(size);
@ -118,6 +131,7 @@ AsyncProxy.prototype.terminate = function() {
* @param {String} method the public api function to be delegated to the worker thread * @param {String} method the public api function to be delegated to the worker thread
* @param {Object} options the api function's options * @param {Object} options the api function's options
* @returns {Promise} see the corresponding public api functions for their return types * @returns {Promise} see the corresponding public api functions for their return types
* @async
*/ */
AsyncProxy.prototype.delegate = function(method, options) { AsyncProxy.prototype.delegate = function(method, options) {

View File

@ -19,6 +19,15 @@
/* eslint-disable no-var */ /* eslint-disable no-var */
/* eslint-disable vars-on-top */ /* eslint-disable vars-on-top */
/**
* @fileoverview Provides functions for communicating with workers
* @see module:openpgp.initWorker
* @see module:openpgp.getWorker
* @see module:openpgp.destroyWorker
* @see module:worker/async_proxy
* @module worker/worker
*/
self.window = {}; // to make UMD bundles work self.window = {}; // to make UMD bundles work
importScripts('openpgp.js'); importScripts('openpgp.js');