Update to asmcrypto.js 2
This commit is contained in:
parent
e66d44e42d
commit
d489f3369f
package.json
src
|
@ -75,7 +75,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mattiasbuelens/web-streams-polyfill": "0.1.0-alpha.4",
|
"@mattiasbuelens/web-streams-polyfill": "0.1.0-alpha.4",
|
||||||
"address-rfc2822": "^2.0.3",
|
"address-rfc2822": "^2.0.3",
|
||||||
"asmcrypto.js": "^0.22.0",
|
"asmcrypto.js": "^2.3.0",
|
||||||
"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",
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @requires asmcrypto.js
|
* @requires asmcrypto.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AES_ECB } from 'asmcrypto.js/src/aes/ecb/ecb';
|
import { AES_ECB } from 'asmcrypto.js/dist_es8/aes/ecb';
|
||||||
|
|
||||||
// TODO use webCrypto or nodeCrypto when possible.
|
// TODO use webCrypto or nodeCrypto when possible.
|
||||||
function aes(length) {
|
function aes(length) {
|
||||||
|
@ -10,11 +10,11 @@ function aes(length) {
|
||||||
const aes_ecb = new AES_ECB(key);
|
const aes_ecb = new AES_ECB(key);
|
||||||
|
|
||||||
this.encrypt = function(block) {
|
this.encrypt = function(block) {
|
||||||
return aes_ecb.encrypt(block).result;
|
return aes_ecb.encrypt(block);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.decrypt = function(block) {
|
this.decrypt = function(block) {
|
||||||
return aes_ecb.decrypt(block).result;
|
return aes_ecb.decrypt(block);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @module crypto/cmac
|
* @module crypto/cmac
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AES_CBC } from 'asmcrypto.js/src/aes/cbc/exports';
|
import { AES_CBC } from 'asmcrypto.js/dist_es8/aes/cbc';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
|
|
||||||
const webCrypto = util.getWebCrypto();
|
const webCrypto = util.getWebCrypto();
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* @module crypto/eax
|
* @module crypto/eax
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AES_CTR } from 'asmcrypto.js/src/aes/ctr/exports';
|
import { AES_CTR } from 'asmcrypto.js/dist_es8/aes/ctr';
|
||||||
import CMAC from './cmac';
|
import CMAC from './cmac';
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
* @module crypto/gcm
|
* @module crypto/gcm
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AES_GCM } from 'asmcrypto.js/src/aes/gcm/exports';
|
import { AES_GCM } from 'asmcrypto.js/dist_es8/aes/gcm';
|
||||||
import util from '../util';
|
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
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
* @module crypto/hash
|
* @module crypto/hash
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SHA1 } from 'asmcrypto.js/src/hash/sha1/exports';
|
import { Sha1 } from 'asmcrypto.js/dist_es8/hash/sha1/sha1';
|
||||||
import { SHA256 } from 'asmcrypto.js/src/hash/sha256/exports';
|
import { Sha256 } from 'asmcrypto.js/dist_es8/hash/sha256/sha256';
|
||||||
import { SHA512 } from 'asmcrypto.js/src/hash/sha512/exports';
|
import { Sha512 } from 'asmcrypto.js/dist_es8/hash/sha512/sha512';
|
||||||
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 { ripemd160 } from 'hash.js/lib/hash/ripemd';
|
import { ripemd160 } from 'hash.js/lib/hash/ripemd';
|
||||||
|
@ -68,11 +68,11 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions
|
||||||
} else { // Use JS fallbacks
|
} else { // Use JS fallbacks
|
||||||
hash_fns = {
|
hash_fns = {
|
||||||
md5: md5,
|
md5: md5,
|
||||||
sha1: asmcrypto_hash(SHA1),
|
sha1: asmcrypto_hash(Sha1),
|
||||||
sha224: hashjs_hash(sha224),
|
sha224: hashjs_hash(sha224),
|
||||||
sha256: asmcrypto_hash(SHA256),
|
sha256: asmcrypto_hash(Sha256),
|
||||||
sha384: hashjs_hash(sha384),
|
sha384: hashjs_hash(sha384),
|
||||||
sha512: asmcrypto_hash(SHA512),
|
sha512: asmcrypto_hash(Sha512),
|
||||||
ripemd: hashjs_hash(ripemd160)
|
ripemd: hashjs_hash(ripemd160)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* @requires util
|
* @requires util
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AES_CFB, AES_CFB_Decrypt, AES_CFB_Encrypt } from 'asmcrypto.js/src/aes/cfb/exports';
|
import { AES_CFB } from 'asmcrypto.js/dist_es8/aes/cfb';
|
||||||
|
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import crypto from '../crypto';
|
import crypto from '../crypto';
|
||||||
|
@ -169,8 +169,8 @@ function aesEncrypt(algo, pt, key) {
|
||||||
if (nodeCrypto) { // Node crypto library.
|
if (nodeCrypto) { // Node crypto library.
|
||||||
return nodeEncrypt(algo, pt, key);
|
return nodeEncrypt(algo, pt, key);
|
||||||
} // asm.js fallback
|
} // asm.js fallback
|
||||||
const cfb = new AES_CFB_Encrypt(key);
|
const cfb = new AES_CFB(key);
|
||||||
return stream.transform(pt, value => cfb.process(value).result, () => cfb.finish().result);
|
return stream.transform(pt, value => cfb.AES_Encrypt_process(value), () => cfb.AES_Encrypt_finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
function aesDecrypt(algo, ct, key) {
|
function aesDecrypt(algo, ct, key) {
|
||||||
|
@ -179,8 +179,8 @@ function aesDecrypt(algo, ct, key) {
|
||||||
pt = nodeDecrypt(algo, ct, key);
|
pt = nodeDecrypt(algo, ct, key);
|
||||||
} else { // asm.js fallback
|
} else { // asm.js fallback
|
||||||
if (util.isStream(ct)) {
|
if (util.isStream(ct)) {
|
||||||
const cfb = new AES_CFB_Decrypt(key);
|
const cfb = new AES_CFB(key);
|
||||||
pt = stream.transform(ct, value => cfb.process(value).result, () => cfb.finish().result);
|
pt = stream.transform(ct, value => cfb.AES_Decrypt_process(value), () => cfb.AES_Decrypt_finish());
|
||||||
} else {
|
} else {
|
||||||
pt = AES_CFB.decrypt(ct, key);
|
pt = AES_CFB.decrypt(ct, key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user