diff --git a/src/crypto/cfb.js b/src/crypto/cfb.js index 5d278a47..38bf513a 100644 --- a/src/crypto/cfb.js +++ b/src/crypto/cfb.js @@ -24,9 +24,9 @@ 'use strict'; -var cipher = require('./cipher'); +import cipher from './cipher'; -module.exports = { +export default { /** * This function encrypts a given with the specified prefixrandom diff --git a/src/crypto/cipher/index.js b/src/crypto/cipher/index.js index 04bb6ebc..ec09835a 100644 --- a/src/crypto/cipher/index.js +++ b/src/crypto/cipher/index.js @@ -14,7 +14,7 @@ import cast5 from './cast5.js'; import twofish from './twofish.js'; import blowfish from './blowfish.js'; -module.exports = { +export default { /** @see module:crypto/cipher/aes */ aes128: aes[128], aes192: aes[192], diff --git a/src/crypto/crypto.js b/src/crypto/crypto.js index 1d00f825..f6e17403 100644 --- a/src/crypto/crypto.js +++ b/src/crypto/crypto.js @@ -27,12 +27,12 @@ 'use strict'; -var random = require('./random.js'), - cipher = require('./cipher'), - publicKey = require('./public_key'), - type_mpi = require('../type/mpi.js'); +import random from './random.js'; +import cipher from './cipher'; +import publicKey from './public_key'; +import type_mpi from '../type/mpi.js'; -module.exports = { +export default { /** * Encrypts data using the specified public key multiprecision integers * and the specified algorithm. diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js index b1c27723..27be2d77 100644 --- a/src/crypto/hash/index.js +++ b/src/crypto/hash/index.js @@ -62,7 +62,7 @@ if(nodeCrypto) { // Use Node native crypto for all hash functions }; } -module.exports = { +export default { md5: hash_fns.md5, sha1: hash_fns.sha1, diff --git a/src/crypto/index.js b/src/crypto/index.js index 57411108..c3d6977e 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -5,25 +5,32 @@ 'use strict'; +import cipher from './cipher'; +import hash from './hash'; +import cfb from './cfb'; +import publicKey from './public_key'; +import signature from './signature'; +import random from './random'; +import pkcs1 from './pkcs1'; +import crypto from './crypto.js'; + module.exports = { /** @see module:crypto/cipher */ - cipher: require('./cipher'), + cipher: cipher, /** @see module:crypto/hash */ - hash: require('./hash'), + hash: hash, /** @see module:crypto/cfb */ - cfb: require('./cfb.js'), + cfb: cfb, /** @see module:crypto/public_key */ - publicKey: require('./public_key'), + publicKey: publicKey, /** @see module:crypto/signature */ - signature: require('./signature.js'), + signature: signature, /** @see module:crypto/random */ - random: require('./random.js'), + random: random, /** @see module:crypto/pkcs1 */ - pkcs1: require('./pkcs1.js'), + pkcs1: pkcs1, }; -var crypto = require('./crypto.js'); - for (var i in crypto) { module.exports[i] = crypto[i]; } diff --git a/src/crypto/pkcs1.js b/src/crypto/pkcs1.js index b50e74bd..17632a55 100644 --- a/src/crypto/pkcs1.js +++ b/src/crypto/pkcs1.js @@ -27,6 +27,11 @@ 'use strict'; +import random from './random.js'; +import util from '../util.js'; +import BigInteger from './public_key/jsbn.js'; +import hash from './hash'; + /** * ASN1 object identifiers for hashes (See {@link http://tools.ietf.org/html/rfc4880#section-5.2.2}) */ @@ -49,11 +54,6 @@ hash_headers[11] = [0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x00, 0x04, 0x1C ]; -var random = require('./random.js'), - util = require('../util.js'), - BigInteger = require('./public_key/jsbn.js'), - hash = require('./hash'); - /** * Create padding with secure random data * @private @@ -73,7 +73,7 @@ function getPkcs1Padding(length) { } -module.exports = { +export default { eme: { /** * create a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1}) diff --git a/src/crypto/public_key/dsa.js b/src/crypto/public_key/dsa.js index 56d8c670..d9c20eed 100644 --- a/src/crypto/public_key/dsa.js +++ b/src/crypto/public_key/dsa.js @@ -27,13 +27,13 @@ 'use strict'; -var BigInteger = require('./jsbn.js'), - random = require('../random.js'), - hashModule = require('../hash'), - util = require('../../util.js'), - config = require('../../config'); +import BigInteger from './jsbn.js'; +import random from '../random.js'; +import hashModule from '../hash'; +import util from '../../util.js'; +import config from '../../config'; -function DSA() { +export default function DSA() { // s1 = ((g**s) mod p) mod q // s1 = ((s**-1)*(sha-1(m)+(s1*x) mod q) function sign(hashalgo, m, g, p, q, x) { @@ -126,5 +126,3 @@ function DSA() { this.sign = sign; this.verify = verify; } - -module.exports = DSA; diff --git a/src/crypto/public_key/elgamal.js b/src/crypto/public_key/elgamal.js index dd1aa009..14b39016 100644 --- a/src/crypto/public_key/elgamal.js +++ b/src/crypto/public_key/elgamal.js @@ -26,11 +26,11 @@ 'use strict'; -var BigInteger = require('./jsbn.js'), - random = require('../random.js'), - util = require('../../util.js'); +import BigInteger from './jsbn.js'; +import random from '../random.js'; +import util from '../../util.js'; -function Elgamal() { +export default function Elgamal() { function encrypt(m, g, p, y) { // choose k in {2,...,p-2} @@ -57,5 +57,3 @@ function Elgamal() { this.encrypt = encrypt; this.decrypt = decrypt; } - -module.exports = Elgamal; diff --git a/src/crypto/public_key/index.js b/src/crypto/public_key/index.js index a0969e90..8e5dfc7b 100644 --- a/src/crypto/public_key/index.js +++ b/src/crypto/public_key/index.js @@ -7,11 +7,15 @@ 'use strict'; -module.exports = { - /** @see module:crypto/public_key/rsa */ - rsa: require('./rsa.js'), - /** @see module:crypto/public_key/elgamal */ - elgamal: require('./elgamal.js'), - /** @see module:crypto/public_key/dsa */ - dsa: require('./dsa.js') +/** @see module:crypto/public_key/rsa */ +import rsa from './rsa.js'; +/** @see module:crypto/public_key/elgamal */ +import elgamal from './elgamal.js'; +/** @see module:crypto/public_key/dsa */ +import dsa from './dsa.js'; + +export default { + rsa: rsa, + elgamal: elgamal, + dsa: dsa }; diff --git a/src/crypto/public_key/jsbn.js b/src/crypto/public_key/jsbn.js index d6313817..bc8b6a3f 100644 --- a/src/crypto/public_key/jsbn.js +++ b/src/crypto/public_key/jsbn.js @@ -1,9 +1,9 @@ /* - * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) + * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) * All Rights Reserved. * - * Modified by Recurity Labs GmbH - * + * Modified by Recurity Labs GmbH + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -15,9 +15,9 @@ * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER @@ -37,7 +37,7 @@ * @module crypto/public_key/jsbn */ -var util = require('../../util.js'); +import util from '../../util.js'; // Basic JavaScript BN library - subset useful for RSA encryption. @@ -50,7 +50,7 @@ var j_lm = ((canary & 0xffffff) == 0xefcafe); // (public) Constructor -function BigInteger(a, b, c) { +export default function BigInteger(a, b, c) { if (a != null) if ("number" == typeof a) this.fromNumber(a, b, c); else if (b == null && "string" != typeof a) this.fromString(a, 256); @@ -113,7 +113,7 @@ function am3(i, x, w, j, c, n) { } return c; } -/*if(j_lm && (navigator != undefined && +/*if(j_lm && (navigator != undefined && navigator.appName == "Microsoft Internet Explorer")) { BigInteger.prototype.am = am2; dbits = 30; @@ -732,8 +732,6 @@ BigInteger.ZERO = nbv(0); BigInteger.ONE = nbv(1); BigInteger.TWO = nbv(2); -module.exports = BigInteger; - @@ -753,7 +751,7 @@ module.exports = BigInteger; /* - * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) + * Copyright (c) 2003-2005 Tom Wu (tjw@cs.Stanford.EDU) * All Rights Reserved. * * Modified by Recurity Labs GmbH @@ -769,9 +767,9 @@ module.exports = BigInteger; * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER @@ -1654,8 +1652,6 @@ function bnpMillerRabin(t) { return true; } -var BigInteger = require('./jsbn.js'); - // protected BigInteger.prototype.chunkSize = bnpChunkSize; BigInteger.prototype.toRadix = bnpToRadix; diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 39efa2d1..0089de6e 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -26,10 +26,10 @@ 'use strict'; -var BigInteger = require('./jsbn.js'), - util = require('../../util.js'), - random = require('../random.js'), - config = require('../../config'); +import BigInteger from './jsbn.js'; +import util from '../../util.js'; +import random from '../random.js'; +import config from '../../config'; function SecureRandom() { function nextBytes(byteArray) { @@ -57,7 +57,7 @@ function unblind(t, n) { return t.multiply(unblinder).mod(n); } -function RSA() { +export default function RSA() { /** * This function uses jsbn Big Num library to decrypt RSA * @param m @@ -265,5 +265,3 @@ function RSA() { this.generate = generate; this.keyObject = KeyObject; } - -module.exports = RSA; diff --git a/src/crypto/random.js b/src/crypto/random.js index 1f26d67d..01b82944 100644 --- a/src/crypto/random.js +++ b/src/crypto/random.js @@ -25,11 +25,11 @@ 'use strict'; -var TypeMPI = require('../type/mpi.js'), - util = require('../util.js'), - nodeCrypto = util.detectNode() && require('crypto'); +import TypeMPI from '../type/mpi.js'; +import util from '../util.js'; +const nodeCrypto = util.detectNode() && require('crypto'); -module.exports = { +export default { /** * Retrieve secure random byte array of the specified length * @param {Integer} length Length in bytes to generate diff --git a/src/crypto/signature.js b/src/crypto/signature.js index 86e0782d..6ab0ce9f 100644 --- a/src/crypto/signature.js +++ b/src/crypto/signature.js @@ -7,11 +7,11 @@ 'use strict'; -var util = require('../util'), - publicKey = require('./public_key'), - pkcs1 = require('./pkcs1.js'); +import util from '../util'; +import publicKey from './public_key'; +import pkcs1 from './pkcs1.js'; -module.exports = { +export default { /** * * @param {module:enums.publicKey} algo public Key algorithm