Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crypto-browserify

Package Overview
Dependencies
Maintainers
5
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-browserify - npm Package Compare versions

Comparing version 3.12.0 to 3.12.1

.eslintrc

1000

example/bundle.js

@@ -0,417 +1,407 @@

'use strict';
var require = function (file, cwd) {
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) throw new Error(
'Failed to resolve module ' + file + ', tried ' + resolved
);
var res = mod._cached ? mod._cached : mod();
return res;
}
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) {
throw new Error('Failed to resolve module ' + file + ', tried ' + resolved);
}
var res = mod._cached ? mod._cached : mod();
return res;
};
require.paths = [];
require.modules = {};
require.extensions = [".js",".coffee"];
require.extensions = ['.js', '.coffee'];
require._core = {
'assert': true,
'events': true,
'fs': true,
'path': true,
'vm': true
assert: true,
events: true,
fs: true,
path: true,
vm: true
};
require.resolve = (function () {
return function (x, cwd) {
if (!cwd) cwd = '/';
if (require._core[x]) return x;
var path = require.modules.path();
cwd = path.resolve('/', cwd);
var y = cwd || '/';
if (x.match(/^(?:\.\.?\/|\/)/)) {
var m = loadAsFileSync(path.resolve(y, x))
|| loadAsDirectorySync(path.resolve(y, x));
if (m) return m;
}
var n = loadNodeModulesSync(x, y);
if (n) return n;
throw new Error("Cannot find module '" + x + "'");
function loadAsFileSync (x) {
if (require.modules[x]) {
return x;
}
for (var i = 0; i < require.extensions.length; i++) {
var ext = require.extensions[i];
if (require.modules[x + ext]) return x + ext;
}
}
function loadAsDirectorySync (x) {
x = x.replace(/\/+$/, '');
var pkgfile = x + '/package.json';
if (require.modules[pkgfile]) {
var pkg = require.modules[pkgfile]();
var b = pkg.browserify;
if (typeof b === 'object' && b.main) {
var m = loadAsFileSync(path.resolve(x, b.main));
if (m) return m;
}
else if (typeof b === 'string') {
var m = loadAsFileSync(path.resolve(x, b));
if (m) return m;
}
else if (pkg.main) {
var m = loadAsFileSync(path.resolve(x, pkg.main));
if (m) return m;
}
}
return loadAsFileSync(x + '/index');
}
function loadNodeModulesSync (x, start) {
var dirs = nodeModulesPathsSync(start);
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var m = loadAsFileSync(dir + '/' + x);
if (m) return m;
var n = loadAsDirectorySync(dir + '/' + x);
if (n) return n;
}
var m = loadAsFileSync(x);
if (m) return m;
}
function nodeModulesPathsSync (start) {
var parts;
if (start === '/') parts = [ '' ];
else parts = path.normalize(start).split('/');
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') continue;
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
dirs.push(dir);
}
return dirs;
}
};
})();
return function (x, cwd) {
if (!cwd) { cwd = '/'; }
if (require._core[x]) { return x; }
var path = require.modules.path();
cwd = path.resolve('/', cwd);
var y = cwd || '/';
if (x.match(/^(?:\.\.?\/|\/)/)) {
var m = loadAsFileSync(path.resolve(y, x))
|| loadAsDirectorySync(path.resolve(y, x));
if (m) { return m; }
}
var n = loadNodeModulesSync(x, y);
if (n) { return n; }
throw new Error("Cannot find module '" + x + "'");
function loadAsFileSync(x) {
if (require.modules[x]) {
return x;
}
for (var i = 0; i < require.extensions.length; i++) {
var ext = require.extensions[i];
if (require.modules[x + ext]) { return x + ext; }
}
}
function loadAsDirectorySync(x) {
x = x.replace(/\/+$/, '');
var pkgfile = x + '/package.json';
if (require.modules[pkgfile]) {
var pkg = require.modules[pkgfile]();
var b = pkg.browserify;
if (typeof b === 'object' && b.main) {
var m = loadAsFileSync(path.resolve(x, b.main));
if (m) { return m; }
} else if (typeof b === 'string') {
var m = loadAsFileSync(path.resolve(x, b));
if (m) { return m; }
} else if (pkg.main) {
var m = loadAsFileSync(path.resolve(x, pkg.main));
if (m) { return m; }
}
}
return loadAsFileSync(x + '/index');
}
function loadNodeModulesSync(x, start) {
var dirs = nodeModulesPathsSync(start);
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var m = loadAsFileSync(dir + '/' + x);
if (m) { return m; }
var n = loadAsDirectorySync(dir + '/' + x);
if (n) { return n; }
}
var m = loadAsFileSync(x);
if (m) { return m; }
}
function nodeModulesPathsSync(start) {
var parts;
if (start === '/') { parts = ['']; } else { parts = path.normalize(start).split('/'); }
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') { continue; }
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
dirs.push(dir);
}
return dirs;
}
};
}());
require.alias = function (from, to) {
var path = require.modules.path();
var res = null;
try {
res = require.resolve(from + '/package.json', '/');
}
catch (err) {
res = require.resolve(from, '/');
}
var basedir = path.dirname(res);
var keys = (Object.keys || function (obj) {
var res = [];
for (var key in obj) res.push(key)
return res;
})(require.modules);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key.slice(0, basedir.length + 1) === basedir + '/') {
var f = key.slice(basedir.length);
require.modules[to + f] = require.modules[basedir + f];
}
else if (key === basedir) {
require.modules[to] = require.modules[basedir];
}
}
var path = require.modules.path();
var res = null;
try {
res = require.resolve(from + '/package.json', '/');
} catch (err) {
res = require.resolve(from, '/');
}
var basedir = path.dirname(res);
var keys = (Object.keys || function (obj) {
var res = [];
for (var key in obj) { res.push(key); }
return res;
})(require.modules);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key.slice(0, basedir.length + 1) === basedir + '/') {
var f = key.slice(basedir.length);
require.modules[to + f] = require.modules[basedir + f];
} else if (key === basedir) {
require.modules[to] = require.modules[basedir];
}
}
};
require.define = function (filename, fn) {
var dirname = require._core[filename]
? ''
: require.modules.path().dirname(filename)
;
var require_ = function (file) {
return require(file, dirname)
};
require_.resolve = function (name) {
return require.resolve(name, dirname);
};
require_.modules = require.modules;
require_.define = require.define;
var module_ = { exports : {} };
require.modules[filename] = function () {
require.modules[filename]._cached = module_.exports;
fn.call(
module_.exports,
require_,
module_,
module_.exports,
dirname,
filename
);
require.modules[filename]._cached = module_.exports;
return module_.exports;
};
var dirname = require._core[filename]
? ''
: require.modules.path().dirname(filename);
var require_ = function (file) {
return require(file, dirname);
};
require_.resolve = function (name) {
return require.resolve(name, dirname);
};
require_.modules = require.modules;
require_.define = require.define;
var module_ = { exports: {} };
require.modules[filename] = function () {
require.modules[filename]._cached = module_.exports;
fn.call(
module_.exports,
require_,
module_,
module_.exports,
dirname,
filename
);
require.modules[filename]._cached = module_.exports;
return module_.exports;
};
};
if (typeof process === 'undefined') process = {};
if (typeof process === 'undefined') { process = {}; }
if (!process.nextTick) process.nextTick = (function () {
var queue = [];
var canPost = typeof window !== 'undefined'
&& window.postMessage && window.addEventListener
;
if (canPost) {
window.addEventListener('message', function (ev) {
if (ev.source === window && ev.data === 'browserify-tick') {
ev.stopPropagation();
if (queue.length > 0) {
var fn = queue.shift();
fn();
}
}
}, true);
}
return function (fn) {
if (canPost) {
queue.push(fn);
window.postMessage('browserify-tick', '*');
}
else setTimeout(fn, 0);
};
})();
if (!process.nextTick) {
process.nextTick = (function () {
var queue = [];
var canPost = typeof window !== 'undefined'
&& window.postMessage && window.addEventListener;
if (canPost) {
window.addEventListener('message', function (ev) {
if (ev.source === window && ev.data === 'browserify-tick') {
ev.stopPropagation();
if (queue.length > 0) {
var fn = queue.shift();
fn();
}
}
}, true);
}
if (!process.title) process.title = 'browser';
return function (fn) {
if (canPost) {
queue.push(fn);
window.postMessage('browserify-tick', '*');
} else { setTimeout(fn, 0); }
};
}());
}
if (!process.binding) process.binding = function (name) {
if (name === 'evals') return require('vm')
else throw new Error('No such module')
};
if (!process.title) { process.title = 'browser'; }
if (!process.cwd) process.cwd = function () { return '.' };
if (!process.binding) {
process.binding = function (name) {
if (name === 'evals') { return require('vm'); }
throw new Error('No such module');
};
}
if (!process.env) process.env = {};
if (!process.argv) process.argv = [];
if (!process.cwd) { process.cwd = function () { return '.'; }; }
require.define("path", function (require, module, exports, __dirname, __filename) {
function filter (xs, fn) {
var res = [];
for (var i = 0; i < xs.length; i++) {
if (fn(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
if (!process.env) { process.env = {}; }
if (!process.argv) { process.argv = []; }
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length; i >= 0; i--) {
var last = parts[i];
if (last == '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
require.define('path', function (require, module, exports, __dirname, __filename) {
function filter(xs, fn) {
var res = [];
for (var i = 0; i < xs.length; i++) {
if (fn(xs[i], i, xs)) { res.push(xs[i]); }
}
return res;
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length; i >= 0; i--) {
var last = parts[i];
if (last == '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
return parts;
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
// Regex to split a filename into [*, dir, basename, ext]
// posix version
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
return parts;
}
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
// Regex to split a filename into [*, dir, basename, ext]
// posix version
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0)
? arguments[i]
: process.cwd();
// path.resolve([from ...], to)
// posix version
exports.resolve = function () {
var resolvedPath = '',
resolvedAbsolute = false;
// Skip empty and invalid entries
if (typeof path !== 'string' || !path) {
continue;
}
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
var path = i >= 0
? arguments[i]
: process.cwd();
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// Skip empty and invalid entries
if (typeof path !== 'string' || !path) {
continue;
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function (p) {
return !!p;
}), !resolvedAbsolute).join('/');
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = path.charAt(0) === '/',
trailingSlash = path.slice(-1) === '/';
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
// path.normalize(path)
// posix version
exports.normalize = function (path) {
var isAbsolute = path.charAt(0) === '/',
trailingSlash = path.slice(-1) === '/';
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// Normalize the path
path = normalizeArray(filter(path.split('/'), function (p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
return p && typeof p === 'string';
}).join('/'));
};
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.join = function () {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function (p, index) {
return p && typeof p === 'string';
}).join('/'));
};
exports.dirname = function(path) {
var dir = splitPathRe.exec(path)[1] || '';
var isWindows = false;
if (!dir) {
// No dirname
return '.';
} else if (dir.length === 1 ||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
// It is just a slash or a drive letter with a slash
return dir;
} else {
// It is a full dirname, strip trailing slash
return dir.substring(0, dir.length - 1);
}
};
exports.dirname = function (path) {
var dir = splitPathRe.exec(path)[1] || '';
var isWindows = false;
if (!dir) {
// No dirname
return '.';
} else if (
dir.length === 1
|| (isWindows && dir.length <= 3 && dir.charAt(1) === ':')
) {
// It is just a slash or a drive letter with a slash
return dir;
}
// It is a full dirname, strip trailing slash
return dir.substring(0, dir.length - 1);
};
exports.basename = function(path, ext) {
var f = splitPathRe.exec(path)[2] || '';
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.basename = function (path, ext) {
var f = splitPathRe.exec(path)[2] || '';
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function (path) {
return splitPathRe.exec(path)[3] || '';
};
exports.extname = function(path) {
return splitPathRe.exec(path)[3] || '';
};
});
require.define("crypto", function (require, module, exports, __dirname, __filename) {
module.exports = require("crypto-browserify")
require.define('crypto', function (require, module, exports, __dirname, __filename) {
module.exports = require('crypto-browserify');
});
require.define("/node_modules/crypto-browserify/package.json", function (require, module, exports, __dirname, __filename) {
module.exports = {}
require.define('/node_modules/crypto-browserify/package.json', function (require, module, exports, __dirname, __filename) {
module.exports = {};
});
require.define("/node_modules/crypto-browserify/index.js", function (require, module, exports, __dirname, __filename) {
var sha = require('./sha')
require.define('/node_modules/crypto-browserify/index.js', function (require, module, exports, __dirname, __filename) {
var sha = require('./sha');
var algorithms = {
sha1: {
hex: sha.hex_sha1,
binary: sha.b64_sha1,
ascii: sha.str_sha1
}
}
var algorithms = {
sha1: {
hex: sha.hex_sha1,
binary: sha.b64_sha1,
ascii: sha.str_sha1
}
};
function error () {
var m = [].slice.call(arguments).join(' ')
throw new Error([
m,
'we accept pull requests',
'http://github.com/dominictarr/crypto-browserify'
].join('\n'))
}
function error() {
var m = Array.prototype.slice.call(arguments).join(' ');
throw new Error(m+'\nwe accept pull requests\nhttp://github.com/browserify/crypto-browserify'.join('\n'));
}
exports.createHash = function (alg) {
alg = alg || 'sha1'
if(!algorithms[alg])
error('algorithm:', alg, 'is not yet supported')
var s = ''
_alg = algorithms[alg]
return {
update: function (data) {
s += data
return this
},
digest: function (enc) {
enc = enc || 'binary'
var fn
if(!(fn = _alg[enc]))
error('encoding:', enc , 'is not yet supported for algorithm', alg)
var r = fn(s)
s = null //not meant to use the hash after you've called digest.
return r
}
}
}
// the least I can do is make error messages for the rest of the node.js/crypto api.
;['createCredentials'
, 'createHmac'
, 'createCypher'
, 'createCypheriv'
, 'createDecipher'
, 'createDecipheriv'
, 'createSign'
, 'createVerify'
, 'createDeffieHellman',
, 'pbkdf2',
, 'randomBytes' ].forEach(function (name) {
exports[name] = function () {
error('sorry,', name, 'is not implemented yet')
}
})
exports.createHash = function (alg) {
alg = alg || 'sha1';
if (!algorithms[alg]) { error('algorithm:', alg, 'is not yet supported'); }
var s = '';
_alg = algorithms[alg];
return {
update: function (data) {
s += data;
return this;
},
digest: function (enc) {
enc = enc || 'binary';
var fn;
if (!(fn = _alg[enc])) { error('encoding:', enc, 'is not yet supported for algorithm', alg); }
var r = fn(s);
s = null; // not meant to use the hash after you've called digest.
return r;
}
};
}
// the least I can do is make error messages for the rest of the node.js/crypto api.
;[
'createCredentials',
'createHmac',
'createCypher',
'createCypheriv',
'createDecipher',
'createDecipheriv',
'createSign',
'createVerify',
'createDeffieHellman',,
'pbkdf2',,
'randomBytes'
].forEach(function (name) {
exports[name] = function () {
error('sorry,', name, 'is not implemented yet');
};
});
});
require.define("/node_modules/crypto-browserify/sha.js", function (require, module, exports, __dirname, __filename) {
require.define('/node_modules/crypto-browserify/sha.js', function (require, module, exports, __dirname, __filename) {
/*

@@ -426,213 +416,191 @@ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined

exports.hex_sha1 = hex_sha1;
exports.b64_sha1 = b64_sha1;
exports.str_sha1 = str_sha1;
exports.hex_hmac_sha1 = hex_hmac_sha1;
exports.b64_hmac_sha1 = b64_hmac_sha1;
exports.str_hmac_sha1 = str_hmac_sha1;
exports.hex_sha1 = hex_sha1;
exports.b64_sha1 = b64_sha1;
exports.str_sha1 = str_sha1;
exports.hex_hmac_sha1 = hex_hmac_sha1;
exports.b64_hmac_sha1 = b64_hmac_sha1;
exports.str_hmac_sha1 = str_hmac_sha1;
/*
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ''; /* base-64 pad character. "=" for strict RFC compliance */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
/*
/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
function hex_sha1(s) { return binb2hex(core_sha1(str2binb(s), s.length * chrsz)); }
function b64_sha1(s) { return binb2b64(core_sha1(str2binb(s), s.length * chrsz)); }
function str_sha1(s) { return binb2str(core_sha1(str2binb(s), s.length * chrsz)); }
function hex_hmac_sha1(key, data) { return binb2hex(core_hmac_sha1(key, data)); }
function b64_hmac_sha1(key, data) { return binb2b64(core_hmac_sha1(key, data)); }
function str_hmac_sha1(key, data) { return binb2str(core_hmac_sha1(key, data)); }
/*
/*
* Perform a simple self-test to see if the VM is working
*/
function sha1_vm_test()
{
return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
}
function sha1_vm_test() {
return hex_sha1('abc') == 'a9993e364706816aba3e25717850c26c9cd0d89d';
}
/*
/*
* Calculate the SHA-1 of an array of big-endian words, and a bit length
*/
function core_sha1(x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << (24 - len % 32);
x[((len + 64 >> 9) << 4) + 15] = len;
function core_sha1(x, len) {
/* append padding */
x[len >> 5] |= 0x80 << (24 - len % 32);
x[((len + 64 >> 9) << 4) + 15] = len;
var w = Array(80);
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
var e = -1009589776;
var w = Array(80);
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
var e = -1009589776;
for(var i = 0; i < x.length; i += 16)
{
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
var olde = e;
for (var i = 0; i < x.length; i += 16) {
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
var olde = e;
for(var j = 0; j < 80; j++)
{
if(j < 16) w[j] = x[i + j];
else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
safe_add(safe_add(e, w[j]), sha1_kt(j)));
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
}
for (var j = 0; j < 80; j++) {
if (j < 16) { w[j] = x[i + j]; } else { w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1); }
var t = safe_add(
safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
safe_add(safe_add(e, w[j]), sha1_kt(j))
);
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
}
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
e = safe_add(e, olde);
}
return Array(a, b, c, d, e);
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
e = safe_add(e, olde);
}
return Array(a, b, c, d, e);
}
}
/*
/*
* Perform the appropriate triplet combination function for the current
* iteration
*/
function sha1_ft(t, b, c, d)
{
if(t < 20) return (b & c) | ((~b) & d);
if(t < 40) return b ^ c ^ d;
if(t < 60) return (b & c) | (b & d) | (c & d);
return b ^ c ^ d;
}
function sha1_ft(t, b, c, d) {
if (t < 20) { return (b & c) | (~b & d); }
if (t < 40) { return b ^ c ^ d; }
if (t < 60) { return (b & c) | (b & d) | (c & d); }
return b ^ c ^ d;
}
/*
/*
* Determine the appropriate additive constant for the current iteration
*/
function sha1_kt(t)
{
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
(t < 60) ? -1894007588 : -899497514;
}
function sha1_kt(t) {
return t < 20 ? 1518500249 : t < 40 ? 1859775393
: t < 60 ? -1894007588 : -899497514;
}
/*
/*
* Calculate the HMAC-SHA1 of a key and some data
*/
function core_hmac_sha1(key, data)
{
var bkey = str2binb(key);
if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
function core_hmac_sha1(key, data) {
var bkey = str2binb(key);
if (bkey.length > 16) { bkey = core_sha1(bkey, key.length * chrsz); }
var ipad = Array(16), opad = Array(16);
for(var i = 0; i < 16; i++)
{
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5C5C5C5C;
}
var ipad = Array(16),
opad = Array(16);
for (var i = 0; i < 16; i++) {
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5C5C5C5C;
}
var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
return core_sha1(opad.concat(hash), 512 + 160);
}
var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
return core_sha1(opad.concat(hash), 512 + 160);
}
/*
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function safe_add(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
/*
/*
* Bitwise rotate a 32-bit number to the left.
*/
function rol(num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt));
}
function rol(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
/*
/*
* Convert an 8-bit or 16-bit string to an array of big-endian words
* In 8-bit function, characters >255 have their hi-byte silently ignored.
*/
function str2binb(str)
{
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
return bin;
}
function str2binb(str) {
var bin = Array();
var mask = (1 << chrsz) - 1;
for (var i = 0; i < str.length * chrsz; i += chrsz) { bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i % 32); }
return bin;
}
/*
/*
* Convert an array of big-endian words to a string
*/
function binb2str(bin)
{
var str = "";
var mask = (1 << chrsz) - 1;
for(var i = 0; i < bin.length * 32; i += chrsz)
str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
return str;
}
function binb2str(bin) {
var str = '';
var mask = (1 << chrsz) - 1;
for (var i = 0; i < bin.length * 32; i += chrsz) { str += String.fromCharCode((bin[i >> 5] >>> (32 - chrsz - i % 32)) & mask); }
return str;
}
/*
/*
* Convert an array of big-endian words to a hex string.
*/
function binb2hex(binarray)
{
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i < binarray.length * 4; i++)
{
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
}
return str;
}
function binb2hex(binarray) {
var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef';
var str = '';
for (var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
}
return str;
}
/*
/*
* Convert an array of big-endian words to a base-64 string
*/
function binb2b64(binarray)
{
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = "";
for(var i = 0; i < binarray.length * 4; i += 3)
{
var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
| (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
| ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
for(var j = 0; j < 4; j++)
{
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
}
}
return str;
}
function binb2b64(binarray) {
var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var str = '';
for (var i = 0; i < binarray.length * 4; i += 3) {
var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
for (var j = 0; j < 4; j++) {
if (i * 8 + j * 6 > binarray.length * 32) { str += b64pad; } else { str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F); }
}
}
return str;
}
});
require.define("/test.js", function (require, module, exports, __dirname, __filename) {
var crypto = require('crypto')
var abc = crypto.createHash('sha1').update('abc').digest('hex')
console.log(abc)
//require('hello').inlineCall().call2()
require.define('/test.js', function (require, module, exports, __dirname, __filename) {
var crypto = require('crypto');
var abc = crypto.createHash('sha1').update('abc').digest('hex');
console.log(abc);
// require('hello').inlineCall().call2()
});
require("/test.js");
require('/test.js');

@@ -1,4 +0,6 @@

var crypto = require('crypto')
var abc = crypto.createHash('sha1').update('abc').digest('hex')
console.log(abc)
'use strict';
var crypto = require('crypto');
var abc = crypto.createHash('sha1').update('abc').digest('hex');
console.log(abc);
// require('hello').inlineCall().call2()

@@ -1,97 +0,103 @@

'use strict'
'use strict';
exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
exports.createHash = exports.Hash = require('create-hash')
exports.createHmac = exports.Hmac = require('create-hmac')
// eslint-disable-next-line no-multi-assign
exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes');
var algos = require('browserify-sign/algos')
var algoKeys = Object.keys(algos)
var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys)
// eslint-disable-next-line no-multi-assign
exports.createHash = exports.Hash = require('create-hash');
// eslint-disable-next-line no-multi-assign
exports.createHmac = exports.Hmac = require('create-hmac');
var algos = require('browserify-sign/algos');
var algoKeys = Object.keys(algos);
var hashes = [
'sha1',
'sha224',
'sha256',
'sha384',
'sha512',
'md5',
'rmd160'
].concat(algoKeys);
exports.getHashes = function () {
return hashes
}
return hashes;
};
var p = require('pbkdf2')
exports.pbkdf2 = p.pbkdf2
exports.pbkdf2Sync = p.pbkdf2Sync
var p = require('pbkdf2');
exports.pbkdf2 = p.pbkdf2;
exports.pbkdf2Sync = p.pbkdf2Sync;
var aes = require('browserify-cipher')
var aes = require('browserify-cipher');
exports.Cipher = aes.Cipher
exports.createCipher = aes.createCipher
exports.Cipheriv = aes.Cipheriv
exports.createCipheriv = aes.createCipheriv
exports.Decipher = aes.Decipher
exports.createDecipher = aes.createDecipher
exports.Decipheriv = aes.Decipheriv
exports.createDecipheriv = aes.createDecipheriv
exports.getCiphers = aes.getCiphers
exports.listCiphers = aes.listCiphers
exports.Cipher = aes.Cipher;
exports.createCipher = aes.createCipher;
exports.Cipheriv = aes.Cipheriv;
exports.createCipheriv = aes.createCipheriv;
exports.Decipher = aes.Decipher;
exports.createDecipher = aes.createDecipher;
exports.Decipheriv = aes.Decipheriv;
exports.createDecipheriv = aes.createDecipheriv;
exports.getCiphers = aes.getCiphers;
exports.listCiphers = aes.listCiphers;
var dh = require('diffie-hellman')
var dh = require('diffie-hellman');
exports.DiffieHellmanGroup = dh.DiffieHellmanGroup
exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup
exports.getDiffieHellman = dh.getDiffieHellman
exports.createDiffieHellman = dh.createDiffieHellman
exports.DiffieHellman = dh.DiffieHellman
exports.DiffieHellmanGroup = dh.DiffieHellmanGroup;
exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup;
exports.getDiffieHellman = dh.getDiffieHellman;
exports.createDiffieHellman = dh.createDiffieHellman;
exports.DiffieHellman = dh.DiffieHellman;
var sign = require('browserify-sign')
var sign = require('browserify-sign');
exports.createSign = sign.createSign
exports.Sign = sign.Sign
exports.createVerify = sign.createVerify
exports.Verify = sign.Verify
exports.createSign = sign.createSign;
exports.Sign = sign.Sign;
exports.createVerify = sign.createVerify;
exports.Verify = sign.Verify;
exports.createECDH = require('create-ecdh')
exports.createECDH = require('create-ecdh');
var publicEncrypt = require('public-encrypt')
var publicEncrypt = require('public-encrypt');
exports.publicEncrypt = publicEncrypt.publicEncrypt
exports.privateEncrypt = publicEncrypt.privateEncrypt
exports.publicDecrypt = publicEncrypt.publicDecrypt
exports.privateDecrypt = publicEncrypt.privateDecrypt
exports.publicEncrypt = publicEncrypt.publicEncrypt;
exports.privateEncrypt = publicEncrypt.privateEncrypt;
exports.publicDecrypt = publicEncrypt.publicDecrypt;
exports.privateDecrypt = publicEncrypt.privateDecrypt;
// the least I can do is make error messages for the rest of the node.js/crypto api.
// ;[
// [
// 'createCredentials'
// ].forEach(function (name) {
// exports[name] = function () {
// throw new Error([
// 'sorry, ' + name + ' is not implemented yet',
// 'we accept pull requests',
// 'https://github.com/crypto-browserify/crypto-browserify'
// ].join('\n'))
// }
// })
// throw new Error('sorry, ' + name + ' is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
// };
// });
var rf = require('randomfill')
var rf = require('randomfill');
exports.randomFill = rf.randomFill
exports.randomFillSync = rf.randomFillSync
exports.randomFill = rf.randomFill;
exports.randomFillSync = rf.randomFillSync;
exports.createCredentials = function () {
throw new Error([
'sorry, createCredentials is not implemented yet',
'we accept pull requests',
'https://github.com/crypto-browserify/crypto-browserify'
].join('\n'))
}
throw new Error('sorry, createCredentials is not implemented yet\nwe accept pull requests\nhttps://github.com/browserify/crypto-browserify');
};
exports.constants = {
'DH_CHECK_P_NOT_SAFE_PRIME': 2,
'DH_CHECK_P_NOT_PRIME': 1,
'DH_UNABLE_TO_CHECK_GENERATOR': 4,
'DH_NOT_SUITABLE_GENERATOR': 8,
'NPN_ENABLED': 1,
'ALPN_ENABLED': 1,
'RSA_PKCS1_PADDING': 1,
'RSA_SSLV23_PADDING': 2,
'RSA_NO_PADDING': 3,
'RSA_PKCS1_OAEP_PADDING': 4,
'RSA_X931_PADDING': 5,
'RSA_PKCS1_PSS_PADDING': 6,
'POINT_CONVERSION_COMPRESSED': 2,
'POINT_CONVERSION_UNCOMPRESSED': 4,
'POINT_CONVERSION_HYBRID': 6
}
DH_CHECK_P_NOT_SAFE_PRIME: 2,
DH_CHECK_P_NOT_PRIME: 1,
DH_UNABLE_TO_CHECK_GENERATOR: 4,
DH_NOT_SUITABLE_GENERATOR: 8,
NPN_ENABLED: 1,
ALPN_ENABLED: 1,
RSA_PKCS1_PADDING: 1,
RSA_SSLV23_PADDING: 2,
RSA_NO_PADDING: 3,
RSA_PKCS1_OAEP_PADDING: 4,
RSA_X931_PADDING: 5,
RSA_PKCS1_PSS_PADDING: 6,
POINT_CONVERSION_COMPRESSED: 2,
POINT_CONVERSION_UNCOMPRESSED: 4,
POINT_CONVERSION_HYBRID: 6
};
{
"author": "Dominic Tarr <dominic.tarr@gmail.com> (dominictarr.com)",
"name": "crypto-browserify",
"description": "implementation of crypto for the browser",
"version": "3.12.0",
"homepage": "https://github.com/crypto-browserify/crypto-browserify",
"repository": {
"type": "git",
"url": "git://github.com/crypto-browserify/crypto-browserify.git"
},
"scripts": {
"standard": "standard",
"test": "npm run standard && npm run unit",
"unit": "node test/",
"browser": "zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- test/index.js"
},
"engines": {
"node": "*"
},
"dependencies": {
"browserify-cipher": "^1.0.0",
"browserify-sign": "^4.0.0",
"create-ecdh": "^4.0.0",
"create-hash": "^1.1.0",
"create-hmac": "^1.1.0",
"diffie-hellman": "^5.0.0",
"inherits": "^2.0.1",
"pbkdf2": "^3.0.3",
"public-encrypt": "^4.0.0",
"randombytes": "^2.0.0",
"randomfill": "^1.0.3"
},
"devDependencies": {
"hash-test-vectors": "~1.3.2",
"pseudorandombytes": "^2.0.0",
"safe-buffer": "^5.1.1",
"standard": "^5.0.2",
"tape": "~2.3.2",
"zuul": "^3.6.0"
},
"optionalDependencies": {},
"browser": {
"crypto": false
},
"license": "MIT"
"author": "Dominic Tarr <dominic.tarr@gmail.com> (dominictarr.com)",
"name": "crypto-browserify",
"description": "implementation of crypto for the browser",
"version": "3.12.1",
"homepage": "https://github.com/browserify/crypto-browserify",
"sideEffects": false,
"repository": {
"type": "git",
"url": "git://github.com/browserify/crypto-browserify.git"
},
"scripts": {
"lint": "eslint --ext=js,mjs .",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "npx npm@'>=10.2' audit --production"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"engines": {
"node": ">= 0.10"
},
"dependencies": {
"browserify-cipher": "^1.0.1",
"browserify-sign": "^4.2.3",
"create-ecdh": "^4.0.4",
"create-hash": "^1.2.0",
"create-hmac": "^1.1.7",
"diffie-hellman": "^5.0.3",
"hash-base": "~3.0.4",
"inherits": "^2.0.4",
"pbkdf2": "^3.1.2",
"public-encrypt": "^4.0.3",
"randombytes": "^2.1.0",
"randomfill": "^1.0.4"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.1",
"eslint": "=8.8.0",
"hash-test-vectors": "^1.3.2",
"nyc": "^10.3.2",
"object.entries": "^1.1.8",
"pseudorandombytes": "^2.0.0",
"safe-buffer": "^5.2.1",
"semver": "^6.3.1",
"tape": "^5.9.0"
},
"browser": {
"crypto": false
},
"license": "MIT"
}

@@ -1,12 +0,15 @@

# crypto-browserify
# crypto-browserify <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
A port of node's `crypto` module to the browser.
[![Build Status](https://travis-ci.org/crypto-browserify/crypto-browserify.svg?branch=master)](https://travis-ci.org/crypto-browserify/crypto-browserify)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![Sauce Test Status](https://saucelabs.com/browser-matrix/crypto-browserify.svg)](https://saucelabs.com/u/crypto-browserify)
The goal of this module is to reimplement node's crypto module,
in pure javascript so that it can run in the browser.
[![npm badge][npm-badge-png]][package-url]
The goal of this module is to reimplement node's crypto module, in pure javascript so that it can run in the browser.
Here is the subset that is currently implemented:

@@ -41,8 +44,6 @@

All deps must be compatible with node's crypto
(generate example inputs and outputs with node,
and save base64 strings inside JSON, so that tests can run in the browser.
(generate example inputs and outputs with node, and save base64 strings inside JSON, so that tests can run in the browser)
see [sha.js](https://github.com/dominictarr/sha.js)
Crypto is _extra serious_ so please do not hesitate to review the code,
and post comments if you do.
Crypto is _extra serious_ so please do not hesitate to review the code, and post comments if you do.

@@ -52,1 +53,17 @@ ## License

MIT
[package-url]: https://npmjs.org/package/crypto-browserify
[npm-version-svg]: https://versionbadg.es/browserify/crypto-browserify.svg
[deps-svg]: https://david-dm.org/browserify/crypto-browserify.svg
[deps-url]: https://david-dm.org/browserify/crypto-browserify
[dev-deps-svg]: https://david-dm.org/browserify/crypto-browserify/dev-status.svg
[dev-deps-url]: https://david-dm.org/browserify/crypto-browserify#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/crypto-browserify.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/crypto-browserify.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/crypto-browserify.svg
[downloads-url]: https://npm-stat.com/charts.html?package=crypto-browserify
[codecov-image]: https://codecov.io/gh/browserify/crypto-browserify/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/browserify/crypto-browserify/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/browserify/crypto-browserify
[actions-url]: https://github.com/browserify/crypto-browserify/actions

@@ -1,49 +0,54 @@

var test = require('tape')
var crypto = require('browserify-cipher/browser')
var randomBytes = require('pseudorandombytes')
'use strict';
function runIt (i) {
crypto.listCiphers().forEach(function (cipher) {
test('run: ' + i, function (t) {
t.test('ciphers: ' + cipher, function (t) {
t.plan(1)
var data = randomBytes(562)
var password = randomBytes(20)
var crypter = crypto.createCipher(cipher, password)
var decrypter = crypto.createDecipher(cipher, password)
var out = []
out.push(decrypter.update(crypter.update(data)))
out.push(decrypter.update(crypter.final()))
if (cipher.indexOf('gcm') > -1) {
decrypter.setAuthTag(crypter.getAuthTag())
}
out.push(decrypter.final())
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'))
})
})
})
if (i < 4) {
setTimeout(runIt, 0, i + 1)
}
var test = require('tape');
var bcCrypto = require('browserify-cipher/browser');
var bcCyphers = bcCrypto.getCiphers();
var randomBytes = require('pseudorandombytes');
for (var i = 0; i < 4; i += 1) {
bcCrypto.listCiphers().forEach(function (cipher) {
test('run: ' + i, function (t) {
/* eslint no-loop-func: 0 */
t.test('ciphers: ' + cipher, function (st) {
st.plan(1);
var data = randomBytes(562);
var password = randomBytes(20);
var crypter = bcCrypto.createCipher(cipher, password);
var decrypter = bcCrypto.createDecipher(cipher, password);
var out = [];
out.push(decrypter.update(crypter.update(data)));
out.push(decrypter.update(crypter['final']()));
if (cipher.indexOf('gcm') > -1) {
decrypter.setAuthTag(crypter.getAuthTag());
}
out.push(decrypter['final']());
st.equals(data.toString('hex'), Buffer.concat(out).toString('hex'));
});
});
});
}
runIt(1)
test('getCiphers', function (t) {
t.plan(1)
t.ok(crypto.getCiphers().length, 'get ciphers returns an array')
})
t.plan(1);
t.ok(bcCyphers.length, 'get ciphers returns an array');
});
test('through crypto browserify works', function (t) {
t.plan(2)
var crypto = require('../')
var cipher = 'aes-128-ctr'
var data = randomBytes(562)
var password = randomBytes(20)
var crypter = crypto.createCipher(cipher, password)
var decrypter = crypto.createDecipher(cipher, password)
var out = []
out.push(decrypter.update(crypter.update(data)))
out.push(decrypter.update(crypter.final()))
out.push(decrypter.final())
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'))
t.ok(crypto.getCiphers().length, 'get ciphers returns an array')
})
// eslint-disable-next-line global-require
test('through crypto browserify works', { skip: !require('crypto').createCipher && 'node 22+ removes createCipher' }, function (t) {
t.plan(2);
var crypto = require('../'); // eslint-disable-line global-require
var cipher = 'aes-128-ctr';
var data = randomBytes(562);
var password = randomBytes(20);
var crypter = crypto.createCipher(cipher, password);
var decrypter = crypto.createDecipher(cipher, password);
var out = [];
out.push(decrypter.update(crypter.update(data)));
out.push(decrypter.update(crypter['final']()));
out.push(decrypter['final']());
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'));
t.ok(crypto.getCiphers().length, 'get ciphers returns an array');
});

@@ -1,50 +0,51 @@

var test = require('tape')
'use strict';
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
var encodings = ['hex', 'base64'] // FIXME: test binary
var vectors = require('hash-test-vectors')
var test = require('tape');
var satisfies = require('semver').satisfies;
testLib('createHash in crypto-browserify', require('../').createHash)
testLib('create-hash/browser', require('create-hash/browser'))
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'];
var encodings = ['hex', 'base64']; // FIXME: test binary
var vectors = require('hash-test-vectors');
function testLib (name, createHash) {
algorithms.forEach(function (algorithm) {
runTest(name, createHash, algorithm)
})
function runTest(name, createHash, algorithm) {
var isUnsupported = satisfies(process.version, '^17') && (
algorithm === 'rmd160'
|| algorithm === 'hmac(rmd160)'
);
test(
name + ' test ' + algorithm + ' against test vectors',
{ skip: isUnsupported && 'this node version does not support ' + algorithm },
function (t) {
vectors.forEach(function (obj, i) {
var input = new Buffer(obj.input, 'base64');
var node = obj[algorithm];
var js = createHash(algorithm).update(input).digest('hex');
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
encodings.forEach(function (encoding) {
var eInput = new Buffer(obj.input, 'base64').toString(encoding);
var eNode = obj[algorithm];
var eJS = createHash(algorithm).update(eInput, encoding).digest('hex');
t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode);
});
input = new Buffer(obj.input, 'base64');
node = obj[algorithm];
var hash = createHash(algorithm);
hash.end(input);
js = hash.read().toString('hex');
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
});
t.end();
}
);
}
function runTest (name, createHash, algorithm) {
test(name + ' test ' + algorithm + ' against test vectors', function (t) {
run(0)
function run (i) {
if (i >= vectors.length) {
return t.end()
}
var obj = vectors[i]
var input = new Buffer(obj.input, 'base64')
var node = obj[algorithm]
var js = createHash(algorithm).update(input).digest('hex')
if (js !== node) {
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node)
}
function testLib(name, createHash) {
algorithms.forEach(function (algorithm) {
runTest(name, createHash, algorithm);
});
}
encodings.forEach(function (encoding) {
var input = new Buffer(obj.input, 'base64').toString(encoding)
var node = obj[algorithm]
var js = createHash(algorithm).update(input, encoding).digest('hex')
if (js !== node) {
t.equal(js, node, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + node)
}
})
input = new Buffer(obj.input, 'base64')
node = obj[algorithm]
var hash = createHash(algorithm)
hash.end(input)
js = hash.read().toString('hex')
if (js !== node) {
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node)
}
setTimeout(run, 0, i + 1)
}
})
}
testLib('createHash in crypto-browserify', require('../').createHash);
testLib('create-hash/browser', require('create-hash/browser'));

@@ -1,50 +0,54 @@

var test = require('tape')
'use strict';
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
var vectors = require('hash-test-vectors/hmac')
testLib('createHmac in crypto-browserify', require('../').createHmac)
testLib('create-hmac/browser', require('create-hmac/browser'))
var test = require('tape');
var satisfies = require('semver').satisfies;
function testLib (name, createHmac) {
algorithms.forEach(function (alg) {
test(name + ' hmac(' + alg + ')', function (t) {
run(0)
function run (i) {
if (i >= vectors.length) {
return t.end()
}
var input = vectors[i]
var output = createHmac(alg, new Buffer(input.key, 'hex'))
.update(input.data, 'hex').digest()
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'];
var vectors = require('hash-test-vectors/hmac');
output = input.truncate ? output.slice(0, input.truncate) : output
output = output.toString('hex')
if (output !== input[alg]) {
t.equal(output, input[alg])
}
setTimeout(run, 0, i + 1)
}
})
function testLib(name, createHmac) {
algorithms.forEach(function (alg) {
var isUnsupported = satisfies(process.version, '^17') && (
alg === 'rmd160'
|| alg === 'hmac(rmd160)'
);
test(
name + ' hmac(' + alg + ')',
{ skip: isUnsupported && 'this node version does not support ' + alg },
function (t) {
vectors.forEach(function (input) {
var output = createHmac(alg, new Buffer(input.key, 'hex'))
.update(input.data, 'hex').digest();
test('hmac(' + alg + ')', function (t) {
run(0)
function run (i) {
if (i >= vectors.length) {
return t.end()
}
var input = vectors[i]
var hmac = createHmac(alg, new Buffer(input.key, 'hex'))
output = input.truncate ? output.slice(0, input.truncate) : output;
output = output.toString('hex');
t.equal(output, input[alg]);
});
hmac.end(input.data, 'hex')
var output = hmac.read()
t.end();
}
);
output = input.truncate ? output.slice(0, input.truncate) : output
output = output.toString('hex')
if (output !== input[alg]) {
t.equal(output, input[alg])
}
setTimeout(run, 0, i + 1)
}
})
})
test(
'hmac(' + alg + ')',
{ skip: isUnsupported && 'this node version does not support ' + alg },
function (t) {
vectors.forEach(function (input) {
var hmac = createHmac(alg, new Buffer(input.key, 'hex'));
hmac.end(input.data, 'hex');
var output = hmac.read();
output = input.truncate ? output.slice(0, input.truncate) : output;
output = output.toString('hex');
t.equal(output, input[alg]);
});
t.end();
}
);
});
}
testLib('createHmac in crypto-browserify', require('../').createHmac);
testLib('create-hmac/browser', require('create-hmac/browser'));

@@ -1,49 +0,60 @@

var test = require('tape')
var crypto = require('diffie-hellman/browser')
'use strict';
var test = require('tape');
var crypto = require('diffie-hellman/browser');
test('diffie-hellman mod groups', function (t) {
[
'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16'
].forEach(function (mod) {
t.test(mod, function (t) {
t.plan(3)
var dh1 = crypto.getDiffieHellman(mod)
var p1 = dh1.getPrime().toString('hex')
dh1.generateKeys()
var dh2 = crypto.getDiffieHellman(mod)
var p2 = dh2.getPrime().toString('hex')
dh2.generateKeys()
t.equals(p1, p2, 'equal primes')
var pubk1 = dh1.getPublicKey()
var pubk2 = dh2.getPublicKey()
t.notEquals(pubk1, pubk2, 'diff public keys')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
})
})
[
'modp1',
'modp2',
'modp5',
'modp14',
'modp15',
'modp16'
].forEach(function (mod) {
t.test(mod, function (st) {
st.plan(3);
var dh1 = crypto.getDiffieHellman(mod);
var p1 = dh1.getPrime().toString('hex');
dh1.generateKeys();
var dh2 = crypto.getDiffieHellman(mod);
var p2 = dh2.getPrime().toString('hex');
dh2.generateKeys();
st.equals(p1, p2, 'equal primes');
var pubk1 = dh1.getPublicKey();
var pubk2 = dh2.getPublicKey();
st.notEquals(pubk1, pubk2, 'diff public keys');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex');
st.equals(pub1, pub2, 'equal secrets');
});
});
});
test('diffie-hellman key lengths', function (t) {
[
64, 65, 192
].forEach(function (len) {
t.test('' + len, function (t) {
t.plan(3)
var dh2 = crypto.createDiffieHellman(len)
var prime2 = dh2.getPrime()
var p2 = prime2.toString('hex')
var dh1 = crypto.createDiffieHellman(prime2)
var p1 = dh1.getPrime().toString('hex')
dh1.generateKeys()
dh2.generateKeys()
t.equals(p1, p2, 'equal primes')
var pubk1 = dh1.getPublicKey()
var pubk2 = dh2.getPublicKey()
t.notEquals(pubk1, pubk2, 'diff public keys')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
})
})
[
64,
65,
192
].forEach(function (len) {
t.test(String(len), function (st) {
st.plan(3);
var dh2 = crypto.createDiffieHellman(len);
var prime2 = dh2.getPrime();
var p2 = prime2.toString('hex');
var dh1 = crypto.createDiffieHellman(prime2);
var p1 = dh1.getPrime().toString('hex');
dh1.generateKeys();
dh2.generateKeys();
st.equals(p1, p2, 'equal primes');
var pubk1 = dh1.getPublicKey();
var pubk2 = dh2.getPublicKey();
st.notEquals(pubk1, pubk2, 'diff public keys');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex');
st.equals(pub1, pub2, 'equal secrets');
});
});
});

@@ -0,61 +1,62 @@

'use strict';
var mods = [
'secp256k1',
'secp224r1',
'prime256v1',
'prime192v1'
]
var test = require('tape')
var _crypto = require('../')
var createECDH1 = _crypto.createECDH
var createECDH2 = require('create-ecdh/browser')
'secp256k1',
'secp224r1',
'prime256v1',
'prime192v1'
];
var test = require('tape');
var createECDH1 = require('../').createECDH;
var createECDH2 = require('create-ecdh/browser');
mods.forEach(function (mod) {
test('createECDH: ' + mod + ' uncompressed', function (t) {
t.plan(2)
var dh1 = createECDH1(mod)
dh1.generateKeys()
var dh2 = createECDH2(mod)
dh2.generateKeys()
var pubk1 = dh1.getPublicKey()
var pubk2 = dh2.getPublicKey()
t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(pubk1).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
test('createECDH: ' + mod + ' uncompressed', function (t) {
t.plan(2);
var dh1 = createECDH1(mod);
dh1.generateKeys();
var dh2 = createECDH2(mod);
dh2.generateKeys();
var pubk1 = dh1.getPublicKey();
var pubk2 = dh2.getPublicKey();
t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(pubk1).toString('hex');
t.equals(pub1, pub2, 'equal secrets');
});
test('createECDH: ' + mod + ' compressed', function (t) {
t.plan(2)
var dh1 = createECDH1(mod)
dh1.generateKeys()
var dh2 = createECDH2(mod)
dh2.generateKeys()
var pubk1 = dh1.getPublicKey(null, 'compressed')
var pubk2 = dh2.getPublicKey(null, 'compressed')
t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(pubk1).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
test('createECDH: ' + mod + ' compressed', function (t) {
t.plan(2);
var dh1 = createECDH1(mod);
dh1.generateKeys();
var dh2 = createECDH2(mod);
dh2.generateKeys();
var pubk1 = dh1.getPublicKey(null, 'compressed');
var pubk2 = dh2.getPublicKey(null, 'compressed');
t.notEquals(pubk1.toString('hex'), pubk2.toString('hex'), 'diff public keys');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(pubk1).toString('hex');
t.equals(pub1, pub2, 'equal secrets');
});
test('createECDH: ' + mod + ' set stuff', function (t) {
t.plan(5)
var dh1 = createECDH1(mod)
var dh2 = createECDH2(mod)
dh1.generateKeys()
dh2.generateKeys()
dh1.setPrivateKey(dh2.getPrivateKey())
dh1.setPublicKey(dh2.getPublicKey())
var priv1 = dh1.getPrivateKey('hex')
var priv2 = dh2.getPrivateKey('hex')
t.equals(priv1, priv2, 'same private key')
var pubk1 = dh1.getPublicKey()
var pubk2 = dh2.getPublicKey()
t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed')
t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed')
t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(pubk1).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
})
test('createECDH: ' + mod + ' set stuff', function (t) {
t.plan(5);
var dh1 = createECDH1(mod);
var dh2 = createECDH2(mod);
dh1.generateKeys();
dh2.generateKeys();
dh1.setPrivateKey(dh2.getPrivateKey());
dh1.setPublicKey(dh2.getPublicKey());
var priv1 = dh1.getPrivateKey('hex');
var priv2 = dh2.getPrivateKey('hex');
t.equals(priv1, priv2, 'same private key');
var pubk1 = dh1.getPublicKey();
var pubk2 = dh2.getPublicKey();
t.equals(pubk1.toString('hex'), pubk2.toString('hex'), 'same public keys, uncompressed');
t.equals(dh1.getPublicKey('hex', 'compressed'), dh2.getPublicKey('hex', 'compressed'), 'same public keys compressed');
t.equals(dh1.getPublicKey('hex', 'hybrid'), dh2.getPublicKey('hex', 'hybrid'), 'same public keys hybrid');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(pubk1).toString('hex');
t.equals(pub1, pub2, 'equal secrets');
});
});

@@ -0,19 +1,22 @@

'use strict';
require('./create-hash')
require('./create-hmac')
/* eslint-disable global-require */
require('./create-hash');
require('./create-hmac');
if (!process.browser) {
require('./dh')
require('./dh');
}
require('./pbkdf2')
require('./pbkdf2');
try {
require('randombytes')(8)
require('./ecdh')
require('./public-encrypt')
require('./random-bytes')
require('./sign')
require('./random-fill')
require('randombytes')(8);
require('./ecdh');
require('./public-encrypt');
require('./random-bytes');
require('./sign');
require('./random-fill');
} catch (e) {
console.log('no secure rng avaiable')
console.log('no secure rng avaiable');
}
require('./aes')
require('./aes');

@@ -1,51 +0,69 @@

var test = require('tape')
var cryptoB = require('../../')
var crypto = require('crypto')
'use strict';
var test = require('tape');
var cryptoB = require('../../');
var crypto = require('crypto');
var satisfies = require('semver').satisfies;
test('diffie-hellman mod groups', function (t) {
[
'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16'
].forEach(function (mod) {
t.test(mod, function (t) {
t.plan(3)
var dh1 = cryptoB.getDiffieHellman(mod)
var p1 = dh1.getPrime().toString('hex')
dh1.generateKeys()
[
'modp1',
'modp2',
'modp5',
'modp14',
'modp15',
'modp16'
].forEach(function (mod) {
t.test(mod, function (st) {
st.plan(3);
var dh1 = cryptoB.getDiffieHellman(mod);
var p1 = dh1.getPrime().toString('hex');
dh1.generateKeys();
var dh2 = crypto.getDiffieHellman(mod)
var p2 = dh2.getPrime().toString('hex')
dh2.generateKeys()
t.equals(p1, p2, 'equal primes')
var pubk1 = dh1.getPublicKey()
var pubk2 = dh2.getPublicKey()
t.notEquals(pubk1, pubk2, 'diff public keys')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(pubk1).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
})
})
var dh2 = crypto.getDiffieHellman(mod);
var p2 = dh2.getPrime().toString('hex');
dh2.generateKeys();
st.equals(p1, p2, 'equal primes');
var pubk1 = dh1.getPublicKey();
var pubk2 = dh2.getPublicKey();
st.notEquals(pubk1, pubk2, 'diff public keys');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(pubk1).toString('hex');
st.equals(pub1, pub2, 'equal secrets');
});
});
});
test('diffie-hellman key lengths', function (t) {
[
64, 65, 192
].forEach(function (len) {
t.test('' + len, function (t) {
t.plan(3)
var dh2 = cryptoB.createDiffieHellman(len)
var prime2 = dh2.getPrime()
var p2 = prime2.toString('hex')
var dh1 = crypto.createDiffieHellman(prime2)
var p1 = dh1.getPrime().toString('hex')
dh1.generateKeys()
dh2.generateKeys()
t.equals(p1, p2, 'equal primes')
var pubk1 = dh1.getPublicKey()
var pubk2 = dh2.getPublicKey()
t.notEquals(pubk1, pubk2, 'diff public keys')
var pub1 = dh1.computeSecret(pubk2).toString('hex')
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex')
t.equals(pub1, pub2, 'equal secrets')
})
})
})
[
64,
65,
192,
512,
1024
].forEach(function (len) {
var modulusTooSmall = satisfies(process.version, '>= 17') && len < 512;
t.test(String(len), { skip: modulusTooSmall && 'node 17+ requires a length >= 512' }, function (st) {
var dh2 = cryptoB.createDiffieHellman(len);
var prime2 = dh2.getPrime();
var p2 = prime2.toString('hex');
var dh1 = crypto.createDiffieHellman(prime2);
var p1 = dh1.getPrime().toString('hex');
dh1.generateKeys();
dh2.generateKeys();
st.equals(p1, p2, 'equal primes');
var pubk1 = dh1.getPublicKey();
var pubk2 = dh2.getPublicKey();
st.notEquals(pubk1, pubk2, 'diff public keys');
var pub1 = dh1.computeSecret(pubk2).toString('hex');
var pub2 = dh2.computeSecret(dh1.getPublicKey()).toString('hex');
st.equals(pub1, pub2, 'equal secrets');
st.end();
});
});
});

@@ -1,21 +0,23 @@

var tape = require('tape')
var crypto = require('pbkdf2/browser')
'use strict';
var vectors = require('hash-test-vectors/pbkdf2')
var tape = require('tape');
var crypto = require('pbkdf2/browser');
var vectors = require('hash-test-vectors/pbkdf2');
tape('pbkdf2', function (t) {
vectors.forEach(function (input) {
// skip inputs that will take way too long
if (input.iterations > 10000) return
vectors.forEach(function (input) {
// skip inputs that will take way too long
if (input.iterations > 10000) { return; }
var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length)
var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length);
if (key.toString('hex') !== input.sha1) {
console.log(input)
}
if (key.toString('hex') !== input.sha1) {
console.log(input);
}
t.equal(key.toString('hex'), input.sha1)
})
t.equal(key.toString('hex'), input.sha1);
});
t.end()
})
t.end();
});

@@ -1,36 +0,39 @@

var test = require('tape')
var crypto1 = require('../')
'use strict';
var test = require('tape');
var crypto1 = require('../');
var rsa = {
'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a'
}
var crypto2 = require('public-encrypt/browser')
rsa.private = new Buffer(rsa.private, 'hex')
rsa.public = new Buffer(rsa.public, 'hex')
var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280'
'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a'
};
var crypto2 = require('public-encrypt/browser');
rsa['private'] = new Buffer(rsa['private'], 'hex');
rsa['public'] = new Buffer(rsa['public'], 'hex');
var encrypted = '0bcd6462ad7a563be2d42b0b73e0b0a163886304e7723b025f97605144fe1781e84acdc4031327d6bccd67fe13183e8fbdc8c5fe947b49d011ce3ebb08b11e83b87a77328ca57ee77cfdc78743b0749366643d7a21b2abcd4aa32dee9832938445540ee3007b7a70191c8dc9ff2ad76fe8dfaa5362d9d2c4b31a67b816d7b7970a293cb95bf3437a301bedb9f431b7075aa2f9df77b4385bea2a37982beda467260b384a58258b5eb4e36a0e0bf7dff83589636f5f97bf542084f0f76868c9f3f989a27fee5b8cd2bfee0bae1eae958df7c3184e5a40fda101196214f371606feca4330b221f30577804bbd4f61578a84e85dcd298849f509e630d275280';
test('publicEncrypt/privateDecrypt', function (t) {
t.test('can decrypt', function (t) {
t.plan(2)
// note encryption is ranomized so can't test to see if they encrypt the same
t.equals(crypto1.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly')
t.equals(crypto2.privateDecrypt(rsa.private, new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly')
})
t.test('can round trip', function (t) {
t.plan(2)
var msg = 'this is a message'
// note encryption is ranomized so can't test to see if they encrypt the same
t.equals(crypto1.privateDecrypt(rsa.private, crypto2.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it')
t.equals(crypto2.privateDecrypt(rsa.private, crypto1.publicEncrypt(rsa.public, new Buffer(msg))).toString(), msg, 'round trip it')
})
})
t.test('can decrypt', function (st) {
st.plan(2);
// note encryption is ranomized so can't test to see if they encrypt the same
st.equals(crypto1.privateDecrypt(rsa['private'], new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly');
st.equals(crypto2.privateDecrypt(rsa['private'], new Buffer(encrypted, 'hex')).toString(), 'hello there I am a nice message', 'decrypt it properly');
});
t.test('can round trip', function (st) {
st.plan(2);
var msg = 'this is a message';
// note encryption is ranomized so can't test to see if they encrypt the same
st.equals(crypto1.privateDecrypt(rsa['private'], crypto2.publicEncrypt(rsa['public'], new Buffer(msg))).toString(), msg, 'round trip it');
st.equals(crypto2.privateDecrypt(rsa['private'], crypto1.publicEncrypt(rsa['public'], new Buffer(msg))).toString(), msg, 'round trip it');
});
});
test('privateEncrypt/publicDecrypt', function (t) {
t.test('can round trip', function (t) {
t.plan(2)
var msg = 'this is a message'
// note encryption is ranomized so can't test to see if they encrypt the same
t.equals(crypto1.publicDecrypt(rsa.public, crypto2.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it')
t.equals(crypto2.publicDecrypt(rsa.public, crypto1.privateEncrypt(rsa.private, new Buffer(msg))).toString(), msg, 'round trip it')
})
})
t.test('can round trip', function (st) {
st.plan(2);
var msg = 'this is a message';
// note encryption is ranomized so can't test to see if they encrypt the same
st.equals(crypto1.publicDecrypt(rsa['public'], crypto2.privateEncrypt(rsa['private'], new Buffer(msg))).toString(), msg, 'round trip it');
st.equals(crypto2.publicDecrypt(rsa['public'], crypto1.privateEncrypt(rsa['private'], new Buffer(msg))).toString(), msg, 'round trip it');
});
});

@@ -1,60 +0,65 @@

var test = require('tape')
var crypto = require('../')
'use strict';
var test = require('tape');
var crypto = require('../');
var randomBytes = require('randombytes');
var entries = require('object.entries');
var randomBytesFunctions = {
randomBytes: require('randombytes'),
pseudoRandomBytes: crypto.pseudoRandomBytes
}
randomBytes: randomBytes,
pseudoRandomBytes: crypto.pseudoRandomBytes
};
for (var randomBytesName in randomBytesFunctions) {
// Both randomBytes and pseudoRandomBytes should provide the same interface
var randomBytes = randomBytesFunctions[randomBytesName]
// Both randomBytes and pseudoRandomBytes should provide the same interface
entries(randomBytesFunctions).forEach(function (entry) {
var randomBytesName = entry[0];
var randomBytesFn = entry[1];
test('get error message', function (t) {
try {
var b = randomBytes(10)
t.ok(Buffer.isBuffer(b))
t.end()
} catch (err) {
t.ok(/not supported/.test(err.message), '"not supported" is in error message')
t.end()
}
})
test('get error message', function (t) {
try {
var b = randomBytesFn(10);
t.ok(Buffer.isBuffer(b));
t.end();
} catch (err) {
t.ok((/not supported/).test(err.message), '"not supported" is in error message');
t.end();
}
});
test(randomBytesName, function (t) {
t.plan(5)
t.equal(randomBytes(10).length, 10)
t.ok(Buffer.isBuffer(randomBytes(10)))
randomBytes(10, function (ex, bytes) {
t.error(ex)
t.equal(bytes.length, 10)
t.ok(Buffer.isBuffer(bytes))
t.end()
})
})
test(randomBytesName, function (t) {
t.plan(5);
t.equal(randomBytesFn(10).length, 10);
t.ok(Buffer.isBuffer(randomBytesFn(10)));
randomBytesFn(10, function (ex, bytes) {
t.error(ex);
t.equal(bytes.length, 10);
t.ok(Buffer.isBuffer(bytes));
t.end();
});
});
test(randomBytesName + ' seem random', function (t) {
var L = 1000
var b = randomBytes(L)
test(randomBytesName + ' seem random', function (t) {
var L = 1000;
var buffer = randomBytesFn(L);
var mean = [].reduce.call(b, function (a, b) { return a + b }, 0) / L
var mean = Array.prototype.reduce.call(buffer, function (a, b) { return a + b; }, 0) / L;
// test that the random numbers are plausably random.
// Math.random() will pass this, but this will catch
// terrible mistakes such as this blunder:
// https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835
// test that the random numbers are plausably random.
// Math.random() will pass this, but this will catch
// terrible mistakes such as this blunder:
// https://github.com/browserify/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835
// this doesn't check that the bytes are in a random *order*
// but it's better than nothing.
// this doesn't check that the bytes are in a random *order*
// but it's better than nothing.
var expected = 256 / 2
var smean = Math.sqrt(mean)
var expected = 256 / 2;
var smean = Math.sqrt(mean);
// console.log doesn't work right on testling, *grumble grumble*
console.log(JSON.stringify([expected - smean, mean, expected + smean]))
t.ok(mean < expected + smean)
t.ok(mean > expected - smean)
// console.log doesn't work right on testling, *grumble grumble*
console.log(JSON.stringify([expected - smean, mean, expected + smean]));
t.ok(mean < expected + smean);
t.ok(mean > expected - smean);
t.end()
})
}
t.end();
});
});

@@ -1,53 +0,55 @@

var test = require('tape')
var crypto = require('../')
var Buffer = require('safe-buffer').Buffer
'use strict';
var test = require('tape');
var crypto = require('../');
var Buffer = require('safe-buffer').Buffer;
test('get error message', function (t) {
try {
var b = crypto.randomFillSync(Buffer.alloc(10))
t.ok(Buffer.isBuffer(b))
t.end()
} catch (err) {
t.ok(/not supported/.test(err.message), '"not supported" is in error message')
t.end()
}
})
try {
var b = crypto.randomFillSync(Buffer.alloc(10));
t.ok(Buffer.isBuffer(b));
t.end();
} catch (err) {
t.ok((/not supported/).test(err.message), '"not supported" is in error message');
t.end();
}
});
test('randomfill', function (t) {
t.plan(5)
t.equal(crypto.randomFillSync(Buffer.alloc(10)).length, 10)
t.ok(Buffer.isBuffer(crypto.randomFillSync(Buffer.alloc(10))))
crypto.randomFill(Buffer.alloc(10), function (ex, bytes) {
t.error(ex)
t.equal(bytes.length, 10)
t.ok(Buffer.isBuffer(bytes))
t.end()
})
})
t.plan(5);
t.equal(crypto.randomFillSync(Buffer.alloc(10)).length, 10);
t.ok(Buffer.isBuffer(crypto.randomFillSync(Buffer.alloc(10))));
crypto.randomFill(Buffer.alloc(10), function (ex, bytes) {
t.error(ex);
t.equal(bytes.length, 10);
t.ok(Buffer.isBuffer(bytes));
t.end();
});
});
test('seems random', function (t) {
var L = 1000
var b = crypto.randomFillSync(Buffer.alloc(L))
var L = 1000;
var buffer = crypto.randomFillSync(Buffer.alloc(L));
var mean = [].reduce.call(b, function (a, b) {
return a + b
}, 0) / L
var mean = Array.prototype.reduce.call(buffer, function (a, b) {
return a + b;
}, 0) / L;
// test that the random numbers are plausably random.
// Math.random() will pass this, but this will catch
// terrible mistakes such as this blunder:
// https://github.com/dominictarr/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835
// test that the random numbers are plausably random.
// Math.random() will pass this, but this will catch
// terrible mistakes such as this blunder:
// https://github.com/browserify/crypto-browserify/commit/3267955e1df7edd1680e52aeede9a89506ed2464#commitcomment-7916835
// this doesn't check that the bytes are in a random *order*
// but it's better than nothing.
// this doesn't check that the bytes are in a random *order*
// but it's better than nothing.
var expected = 256 / 2
var smean = Math.sqrt(mean)
var expected = 256 / 2;
var smean = Math.sqrt(mean);
// console.log doesn't work right on testling, *grumble grumble*
console.log(JSON.stringify([expected - smean, mean, expected + smean]))
t.ok(mean < expected + smean)
t.ok(mean > expected - smean)
// console.log doesn't work right on testling, *grumble grumble*
console.log(JSON.stringify([expected - smean, mean, expected + smean]));
t.ok(mean < expected + smean);
t.ok(mean > expected - smean);
t.end()
})
t.end();
});

@@ -1,59 +0,61 @@

var test = require('tape')
var nodeCrypto = require('../')
var ourCrypto = require('browserify-sign/browser')
'use strict';
var test = require('tape');
var nodeCrypto = require('../');
var ourCrypto = require('browserify-sign/browser');
var rsa = {
'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a'
}
'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a'
};
var ec = {
'private': '2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a'
}
'private': '2d2d2d2d2d424547494e2045432050524956415445204b45592d2d2d2d2d0a4d485143415145454944463658763853762f2f77475557442b6337383070704772553051645a5743417a78415150515838722f756f416347425375424241414b0a6f55514451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e595152696a6134652f71454d696b4f484a616937676565557265550a7235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e442045432050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d465977454159484b6f5a497a6a3043415159464b34454541416f4451674145495a656f7744796c6c73344b2f7766426a4f313862596f37674778386e5951520a696a6134652f71454d696b4f484a616937676565557265557235586b792f4178377332644774656773504e7350674765354d705176673d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a'
};
rsa.private = new Buffer(rsa.private, 'hex')
rsa.public = new Buffer(rsa.public, 'hex')
ec.private = new Buffer(ec.private, 'hex')
ec.public = new Buffer(ec.public, 'hex')
rsa['private'] = new Buffer(rsa['private'], 'hex');
rsa['public'] = new Buffer(rsa['public'], 'hex');
ec['private'] = new Buffer(ec['private'], 'hex');
ec['public'] = new Buffer(ec['public'], 'hex');
function testit (keys, message, scheme) {
var pub = keys.public
var priv = keys.private
test(message.toString(), function (t) {
t.test('js sign and verify', function (t) {
t.plan(t)
var mySign = ourCrypto.createSign(scheme)
var mySig = mySign.update(message).sign(priv)
var myVer = ourCrypto.createVerify(scheme)
t.ok(myVer.update(message).verify(pub, mySig), 'validates')
})
function testit(keys, message, scheme) {
var pub = keys['public'];
var priv = keys['private'];
test(message.toString(), function (t) {
t.test('js sign and verify', function (st) {
st.plan(1);
var mySign = ourCrypto.createSign(scheme);
var mySig = mySign.update(message).sign(priv);
var myVer = ourCrypto.createVerify(scheme);
st.ok(myVer.update(message).verify(pub, mySig), 'validates');
});
t.test('node sign and verify', function (t) {
t.plan(t)
var mySign = nodeCrypto.createSign(scheme)
var mySig = mySign.update(message).sign(priv)
var myVer = nodeCrypto.createVerify(scheme)
t.ok(myVer.update(message).verify(pub, mySig), 'validates')
})
t.test('node sign and verify', function (st) {
st.plan(1);
var mySign = nodeCrypto.createSign(scheme);
var mySig = mySign.update(message).sign(priv);
var myVer = nodeCrypto.createVerify(scheme);
st.ok(myVer.update(message).verify(pub, mySig), 'validates');
});
t.test('node sign and js verify', function (t) {
t.plan(t)
var mySign = nodeCrypto.createSign(scheme)
var mySig = mySign.update(message).sign(priv)
var myVer = ourCrypto.createVerify(scheme)
t.ok(myVer.update(message).verify(pub, mySig), 'validates')
})
t.test('node sign and js verify', function (st) {
st.plan(1);
var mySign = nodeCrypto.createSign(scheme);
var mySig = mySign.update(message).sign(priv);
var myVer = ourCrypto.createVerify(scheme);
st.ok(myVer.update(message).verify(pub, mySig), 'validates');
});
t.test('js sign and node verify', function (t) {
t.plan(t)
var mySign = ourCrypto.createSign(scheme)
var mySig = mySign.update(message).sign(priv)
var myVer = nodeCrypto.createVerify(scheme)
t.ok(myVer.update(message).verify(pub, mySig), 'validates')
})
})
t.test('js sign and node verify', function (st) {
st.plan(1);
var mySign = ourCrypto.createSign(scheme);
var mySig = mySign.update(message).sign(priv);
var myVer = nodeCrypto.createVerify(scheme);
st.ok(myVer.update(message).verify(pub, mySig), 'validates');
});
});
}
testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256')
testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1')
testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256');
testit(ec, new Buffer('ec with sha1'), 'sha256');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc