This branch uses the current version of asmcrypto.js

This commit is contained in:
Mahrud Sayrafi 2018-02-09 01:06:44 -08:00
parent e939d9b1ab
commit ed4cef102a
No known key found for this signature in database
GPG Key ID: C24071B956C3245F
6 changed files with 31 additions and 23 deletions

View File

@ -263,7 +263,7 @@ module.exports = function(grunt) {
// Load the plugin(s) // Load the plugin(s)
grunt.loadNpmTasks('grunt-browserify'); grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify-es');
grunt.loadNpmTasks('grunt-text-replace'); grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-jsbeautifier'); grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.loadNpmTasks('grunt-jsdoc'); grunt.loadNpmTasks('grunt-jsdoc');

View File

@ -57,11 +57,10 @@
"grunt-contrib-clean": "~1.1.0", "grunt-contrib-clean": "~1.1.0",
"grunt-contrib-connect": "~1.0.2", "grunt-contrib-connect": "~1.0.2",
"grunt-contrib-copy": "~1.0.0", "grunt-contrib-copy": "~1.0.0",
"grunt-contrib-uglify": "~3.2.1", "grunt-contrib-uglify-es": "^3.3.0",
"grunt-contrib-watch": "^1.0.0", "grunt-contrib-watch": "^1.0.0",
"grunt-jsbeautifier": "^0.2.13", "grunt-jsbeautifier": "^0.2.13",
"grunt-jsdoc": "^2.2.1", "grunt-jsdoc": "^2.2.1",
"grunt-keepalive": "^1.0.0",
"grunt-mocha-istanbul": "^5.0.2", "grunt-mocha-istanbul": "^5.0.2",
"grunt-mocha-test": "^0.13.3", "grunt-mocha-test": "^0.13.3",
"grunt-saucelabs": "9.0.0", "grunt-saucelabs": "9.0.0",
@ -73,12 +72,12 @@
"whatwg-fetch": "^2.0.3" "whatwg-fetch": "^2.0.3"
}, },
"dependencies": { "dependencies": {
"asmcrypto-lite": "github:openpgpjs/asmcrypto-lite", "asmcrypto.js": "github:mahrud/asmcrypto.js",
"asn1.js": "^5.0.0", "asn1.js": "^5.0.0",
"bn.js": "^4.11.8", "bn.js": "^4.11.8",
"buffer": "^5.0.8", "buffer": "^5.0.8",
"compressjs": "github:openpgpjs/compressjs.git", "compressjs": "github:openpgpjs/compressjs",
"elliptic": "github:openpgpjs/elliptic.git", "elliptic": "github:openpgpjs/elliptic",
"hash.js": "^1.1.3", "hash.js": "^1.1.3",
"jwk-to-pem": "^1.2.6", "jwk-to-pem": "^1.2.6",
"node-fetch": "^1.7.3", "node-fetch": "^1.7.3",

View File

@ -1,8 +1,9 @@
/** /**
* @requires asmcrypto.js
* @module crypto/cipher/aes * @module crypto/cipher/aes
*/ */
import asmCrypto from 'asmcrypto-lite'; import { AES_ECB } from 'asmcrypto.js';
// TODO use webCrypto or nodeCrypto when possible. // TODO use webCrypto or nodeCrypto when possible.
export default function aes(length) { export default function aes(length) {
@ -11,12 +12,12 @@ export default function aes(length) {
this.encrypt = function(block) { this.encrypt = function(block) {
block = Uint8Array.from(block); block = Uint8Array.from(block);
return Array.from(asmCrypto.AES_ECB.encrypt(block, this.key, false)); return Array.from(AES_ECB.encrypt(block, this.key, false));
}; };
this.decrypt = function(block) { this.decrypt = function(block) {
block = Uint8Array.from(block); block = Uint8Array.from(block);
return Array.from(asmCrypto.AES_ECB.decrypt(block, this.key, false)); return Array.from(AES_ECB.decrypt(block, this.key, false));
}; };
}; };

View File

@ -18,10 +18,15 @@
/** /**
* @fileoverview This module wraps native AES-GCM en/decryption for both * @fileoverview This module wraps native AES-GCM en/decryption for both
* the WebCrypto api as well as node.js' crypto api. * the WebCrypto api as well as node.js' crypto api.
* @requires asmcrypto.js
* @requires config
* @requires util
* @module crypto/gcm
*/ */
import asmCrypto from 'asmcrypto-lite'; import { AES_GCM } from 'asmcrypto.js';
import util from '../util.js'; import config from '../config';
import util from '../util';
const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9 const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9
const nodeCrypto = util.getNodeCrypto(); const nodeCrypto = util.getNodeCrypto();
@ -49,7 +54,7 @@ function encrypt(cipher, plaintext, key, iv) {
} else if (nodeCrypto) { // Node crypto library } else if (nodeCrypto) { // Node crypto library
return nodeEncrypt(plaintext, key, iv); return nodeEncrypt(plaintext, key, iv);
} // asm.js fallback } // asm.js fallback
return Promise.resolve(asmCrypto.AES_GCM.encrypt(plaintext, key, iv)); return Promise.resolve(AES_GCM.encrypt(plaintext, key, iv));
} }
/** /**
@ -70,7 +75,7 @@ function decrypt(cipher, ciphertext, key, iv) {
} else if (nodeCrypto) { // Node crypto library } else if (nodeCrypto) { // Node crypto library
return nodeDecrypt(ciphertext, key, iv); return nodeDecrypt(ciphertext, key, iv);
} // asm.js fallback } // asm.js fallback
return Promise.resolve(asmCrypto.AES_GCM.decrypt(ciphertext, key, iv)); return Promise.resolve(AES_GCM.decrypt(ciphertext, key, iv));
} }
export default { export default {

View File

@ -1,18 +1,20 @@
/** /**
* @requires crypto/hash/sha * @requires rusha
* @requires asmcrypto.js
* @requires hash.js
* @requires crypto/hash/md5 * @requires crypto/hash/md5
* @requires util * @requires util
* @module crypto/hash * @module crypto/hash
*/ */
import Rusha from 'rusha'; import Rusha from 'rusha';
import asmCrypto from 'asmcrypto-lite'; import { SHA256 } from 'asmcrypto.js';
import sha224 from 'hash.js/lib/hash/sha/224'; import sha224 from 'hash.js/lib/hash/sha/224';
import sha384 from 'hash.js/lib/hash/sha/384'; import sha384 from 'hash.js/lib/hash/sha/384';
import sha512 from 'hash.js/lib/hash/sha/512'; import sha512 from 'hash.js/lib/hash/sha/512';
import { ripemd160 } from 'hash.js/lib/hash/ripemd'; import { ripemd160 } from 'hash.js/lib/hash/ripemd';
import md5 from './md5'; import md5 from './md5';
import util from '../../util.js'; import util from '../../util';
const rusha = new Rusha(); const rusha = new Rusha();
const nodeCrypto = util.getNodeCrypto(); const nodeCrypto = util.getNodeCrypto();
@ -54,7 +56,7 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions
/** @see module:hash.js */ /** @see module:hash.js */
sha224: hashjs_hash(sha224), sha224: hashjs_hash(sha224),
/** @see module:asmcrypto */ /** @see module:asmcrypto */
sha256: asmCrypto.SHA256.bytes, sha256: SHA256.bytes,
/** @see module:hash.js */ /** @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

View File

@ -25,16 +25,17 @@
* created for OpenPGP that addresses the problem of detecting a modification to * created for OpenPGP that addresses the problem of detecting a modification to
* encrypted data. It is used in combination with a Modification Detection Code * encrypted data. It is used in combination with a Modification Detection Code
* packet. * packet.
* @requires asmcrypto.js
* @requires crypto * @requires crypto
* @requires util
* @requires enums * @requires enums
* @requires util
* @module packet/sym_encrypted_integrity_protected * @module packet/sym_encrypted_integrity_protected
*/ */
import asmCrypto from 'asmcrypto-lite'; import { AES_CFB } from 'asmcrypto.js';
import util from '../util.js';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums.js'; import enums from '../enums';
import util from '../util';
const nodeCrypto = util.getNodeCrypto(); const nodeCrypto = util.getNodeCrypto();
const Buffer = util.getNodeBuffer(); const Buffer = util.getNodeBuffer();
@ -145,7 +146,7 @@ function aesEncrypt(algo, prefix, pt, key) {
if (nodeCrypto) { // Node crypto library. if (nodeCrypto) { // Node crypto library.
return nodeEncrypt(algo, prefix, pt, key); return nodeEncrypt(algo, prefix, pt, key);
} // asm.js fallback } // asm.js fallback
return asmCrypto.AES_CFB.encrypt(util.concatUint8Array([prefix, pt]), key); return AES_CFB.encrypt(util.concatUint8Array([prefix, pt]), key);
} }
function aesDecrypt(algo, ct, key) { function aesDecrypt(algo, ct, key) {
@ -153,7 +154,7 @@ function aesDecrypt(algo, ct, key) {
if (nodeCrypto) { // Node crypto library. if (nodeCrypto) { // Node crypto library.
pt = nodeDecrypt(algo, ct, key); pt = nodeDecrypt(algo, ct, key);
} else { // asm.js fallback } else { // asm.js fallback
pt = asmCrypto.AES_CFB.decrypt(ct, key); pt = AES_CFB.decrypt(ct, key);
} }
return pt.subarray(crypto.cipher[algo].blockSize + 2, pt.length); // Remove random prefix return pt.subarray(crypto.cipher[algo].blockSize + 2, pt.length); // Remove random prefix
} }