Refactor src/crypto/**/*.js to use import & export
This commit is contained in:
parent
3aed324d51
commit
dea42df209
|
@ -24,9 +24,9 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var cipher = require('./cipher');
|
import cipher from './cipher';
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function encrypts a given with the specified prefixrandom
|
* This function encrypts a given with the specified prefixrandom
|
||||||
|
|
|
@ -14,7 +14,7 @@ import cast5 from './cast5.js';
|
||||||
import twofish from './twofish.js';
|
import twofish from './twofish.js';
|
||||||
import blowfish from './blowfish.js';
|
import blowfish from './blowfish.js';
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
/** @see module:crypto/cipher/aes */
|
/** @see module:crypto/cipher/aes */
|
||||||
aes128: aes[128],
|
aes128: aes[128],
|
||||||
aes192: aes[192],
|
aes192: aes[192],
|
||||||
|
|
|
@ -27,12 +27,12 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var random = require('./random.js'),
|
import random from './random.js';
|
||||||
cipher = require('./cipher'),
|
import cipher from './cipher';
|
||||||
publicKey = require('./public_key'),
|
import publicKey from './public_key';
|
||||||
type_mpi = require('../type/mpi.js');
|
import type_mpi from '../type/mpi.js';
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
/**
|
/**
|
||||||
* Encrypts data using the specified public key multiprecision integers
|
* Encrypts data using the specified public key multiprecision integers
|
||||||
* and the specified algorithm.
|
* and the specified algorithm.
|
||||||
|
|
|
@ -62,7 +62,7 @@ if(nodeCrypto) { // Use Node native crypto for all hash functions
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
|
|
||||||
md5: hash_fns.md5,
|
md5: hash_fns.md5,
|
||||||
sha1: hash_fns.sha1,
|
sha1: hash_fns.sha1,
|
||||||
|
|
|
@ -5,25 +5,32 @@
|
||||||
|
|
||||||
'use strict';
|
'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 = {
|
module.exports = {
|
||||||
/** @see module:crypto/cipher */
|
/** @see module:crypto/cipher */
|
||||||
cipher: require('./cipher'),
|
cipher: cipher,
|
||||||
/** @see module:crypto/hash */
|
/** @see module:crypto/hash */
|
||||||
hash: require('./hash'),
|
hash: hash,
|
||||||
/** @see module:crypto/cfb */
|
/** @see module:crypto/cfb */
|
||||||
cfb: require('./cfb.js'),
|
cfb: cfb,
|
||||||
/** @see module:crypto/public_key */
|
/** @see module:crypto/public_key */
|
||||||
publicKey: require('./public_key'),
|
publicKey: publicKey,
|
||||||
/** @see module:crypto/signature */
|
/** @see module:crypto/signature */
|
||||||
signature: require('./signature.js'),
|
signature: signature,
|
||||||
/** @see module:crypto/random */
|
/** @see module:crypto/random */
|
||||||
random: require('./random.js'),
|
random: random,
|
||||||
/** @see module:crypto/pkcs1 */
|
/** @see module:crypto/pkcs1 */
|
||||||
pkcs1: require('./pkcs1.js'),
|
pkcs1: pkcs1,
|
||||||
};
|
};
|
||||||
|
|
||||||
var crypto = require('./crypto.js');
|
|
||||||
|
|
||||||
for (var i in crypto) {
|
for (var i in crypto) {
|
||||||
module.exports[i] = crypto[i];
|
module.exports[i] = crypto[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,11 @@
|
||||||
|
|
||||||
'use strict';
|
'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})
|
* 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
|
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
|
* Create padding with secure random data
|
||||||
* @private
|
* @private
|
||||||
|
@ -73,7 +73,7 @@ function getPkcs1Padding(length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
eme: {
|
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})
|
* create a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.1|RFC 4880 13.1.1})
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BigInteger = require('./jsbn.js'),
|
import BigInteger from './jsbn.js';
|
||||||
random = require('../random.js'),
|
import random from '../random.js';
|
||||||
hashModule = require('../hash'),
|
import hashModule from '../hash';
|
||||||
util = require('../../util.js'),
|
import util from '../../util.js';
|
||||||
config = require('../../config');
|
import config from '../../config';
|
||||||
|
|
||||||
function DSA() {
|
export default function DSA() {
|
||||||
// s1 = ((g**s) mod p) mod q
|
// s1 = ((g**s) mod p) mod q
|
||||||
// s1 = ((s**-1)*(sha-1(m)+(s1*x) mod q)
|
// s1 = ((s**-1)*(sha-1(m)+(s1*x) mod q)
|
||||||
function sign(hashalgo, m, g, p, q, x) {
|
function sign(hashalgo, m, g, p, q, x) {
|
||||||
|
@ -126,5 +126,3 @@ function DSA() {
|
||||||
this.sign = sign;
|
this.sign = sign;
|
||||||
this.verify = verify;
|
this.verify = verify;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DSA;
|
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BigInteger = require('./jsbn.js'),
|
import BigInteger from './jsbn.js';
|
||||||
random = require('../random.js'),
|
import random from '../random.js';
|
||||||
util = require('../../util.js');
|
import util from '../../util.js';
|
||||||
|
|
||||||
function Elgamal() {
|
export default function Elgamal() {
|
||||||
|
|
||||||
function encrypt(m, g, p, y) {
|
function encrypt(m, g, p, y) {
|
||||||
// choose k in {2,...,p-2}
|
// choose k in {2,...,p-2}
|
||||||
|
@ -57,5 +57,3 @@ function Elgamal() {
|
||||||
this.encrypt = encrypt;
|
this.encrypt = encrypt;
|
||||||
this.decrypt = decrypt;
|
this.decrypt = decrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Elgamal;
|
|
||||||
|
|
|
@ -7,11 +7,15 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
/** @see module:crypto/public_key/rsa */
|
/** @see module:crypto/public_key/rsa */
|
||||||
rsa: require('./rsa.js'),
|
import rsa from './rsa.js';
|
||||||
/** @see module:crypto/public_key/elgamal */
|
/** @see module:crypto/public_key/elgamal */
|
||||||
elgamal: require('./elgamal.js'),
|
import elgamal from './elgamal.js';
|
||||||
/** @see module:crypto/public_key/dsa */
|
/** @see module:crypto/public_key/dsa */
|
||||||
dsa: require('./dsa.js')
|
import dsa from './dsa.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
rsa: rsa,
|
||||||
|
elgamal: elgamal,
|
||||||
|
dsa: dsa
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
* @module crypto/public_key/jsbn
|
* @module crypto/public_key/jsbn
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var util = require('../../util.js');
|
import util from '../../util.js';
|
||||||
|
|
||||||
// Basic JavaScript BN library - subset useful for RSA encryption.
|
// Basic JavaScript BN library - subset useful for RSA encryption.
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ var j_lm = ((canary & 0xffffff) == 0xefcafe);
|
||||||
|
|
||||||
// (public) Constructor
|
// (public) Constructor
|
||||||
|
|
||||||
function BigInteger(a, b, c) {
|
export default function BigInteger(a, b, c) {
|
||||||
if (a != null)
|
if (a != null)
|
||||||
if ("number" == typeof a) this.fromNumber(a, b, c);
|
if ("number" == typeof a) this.fromNumber(a, b, c);
|
||||||
else if (b == null && "string" != typeof a) this.fromString(a, 256);
|
else if (b == null && "string" != typeof a) this.fromString(a, 256);
|
||||||
|
@ -732,8 +732,6 @@ BigInteger.ZERO = nbv(0);
|
||||||
BigInteger.ONE = nbv(1);
|
BigInteger.ONE = nbv(1);
|
||||||
BigInteger.TWO = nbv(2);
|
BigInteger.TWO = nbv(2);
|
||||||
|
|
||||||
module.exports = BigInteger;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1654,8 +1652,6 @@ function bnpMillerRabin(t) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var BigInteger = require('./jsbn.js');
|
|
||||||
|
|
||||||
// protected
|
// protected
|
||||||
BigInteger.prototype.chunkSize = bnpChunkSize;
|
BigInteger.prototype.chunkSize = bnpChunkSize;
|
||||||
BigInteger.prototype.toRadix = bnpToRadix;
|
BigInteger.prototype.toRadix = bnpToRadix;
|
||||||
|
|
|
@ -26,10 +26,10 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BigInteger = require('./jsbn.js'),
|
import BigInteger from './jsbn.js';
|
||||||
util = require('../../util.js'),
|
import util from '../../util.js';
|
||||||
random = require('../random.js'),
|
import random from '../random.js';
|
||||||
config = require('../../config');
|
import config from '../../config';
|
||||||
|
|
||||||
function SecureRandom() {
|
function SecureRandom() {
|
||||||
function nextBytes(byteArray) {
|
function nextBytes(byteArray) {
|
||||||
|
@ -57,7 +57,7 @@ function unblind(t, n) {
|
||||||
return t.multiply(unblinder).mod(n);
|
return t.multiply(unblinder).mod(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RSA() {
|
export default function RSA() {
|
||||||
/**
|
/**
|
||||||
* This function uses jsbn Big Num library to decrypt RSA
|
* This function uses jsbn Big Num library to decrypt RSA
|
||||||
* @param m
|
* @param m
|
||||||
|
@ -265,5 +265,3 @@ function RSA() {
|
||||||
this.generate = generate;
|
this.generate = generate;
|
||||||
this.keyObject = KeyObject;
|
this.keyObject = KeyObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RSA;
|
|
||||||
|
|
|
@ -25,11 +25,11 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var TypeMPI = require('../type/mpi.js'),
|
import TypeMPI from '../type/mpi.js';
|
||||||
util = require('../util.js'),
|
import util from '../util.js';
|
||||||
nodeCrypto = util.detectNode() && require('crypto');
|
const nodeCrypto = util.detectNode() && require('crypto');
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
/**
|
/**
|
||||||
* Retrieve secure random byte array of the specified length
|
* Retrieve secure random byte array of the specified length
|
||||||
* @param {Integer} length Length in bytes to generate
|
* @param {Integer} length Length in bytes to generate
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var util = require('../util'),
|
import util from '../util';
|
||||||
publicKey = require('./public_key'),
|
import publicKey from './public_key';
|
||||||
pkcs1 = require('./pkcs1.js');
|
import pkcs1 from './pkcs1.js';
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {module:enums.publicKey} algo public Key algorithm
|
* @param {module:enums.publicKey} algo public Key algorithm
|
||||||
|
|
Loading…
Reference in New Issue
Block a user