0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

49
web/node_modules/crypto-browserify/test/aes.js generated vendored Normal file
View file

@ -0,0 +1,49 @@
var test = require('tape')
var crypto = require('browserify-cipher/browser')
var randomBytes = require('pseudorandombytes')
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)
}
}
runIt(1)
test('getCiphers', function (t) {
t.plan(1)
t.ok(crypto.getCiphers().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')
})

50
web/node_modules/crypto-browserify/test/create-hash.js generated vendored Normal file
View file

@ -0,0 +1,50 @@
var test = require('tape')
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
var encodings = ['hex', 'base64'] // FIXME: test binary
var vectors = require('hash-test-vectors')
testLib('createHash in crypto-browserify', require('../').createHash)
testLib('create-hash/browser', require('create-hash/browser'))
function testLib (name, createHash) {
algorithms.forEach(function (algorithm) {
runTest(name, createHash, algorithm)
})
}
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)
}
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)
}
})
}

50
web/node_modules/crypto-browserify/test/create-hmac.js generated vendored Normal file
View file

@ -0,0 +1,50 @@
var test = require('tape')
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'))
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()
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 + ')', 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'))
hmac.end(input.data, 'hex')
var output = hmac.read()
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)
}
})
})
}

49
web/node_modules/crypto-browserify/test/dh.js generated vendored Normal file
View file

@ -0,0 +1,49 @@
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')
})
})
})
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')
})
})
})

61
web/node_modules/crypto-browserify/test/ecdh.js generated vendored Normal file
View file

@ -0,0 +1,61 @@
var mods = [
'secp256k1',
'secp224r1',
'prime256v1',
'prime192v1'
]
var test = require('tape')
var _crypto = require('../')
var createECDH1 = _crypto.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 + ' 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')
})
})

19
web/node_modules/crypto-browserify/test/index.js generated vendored Normal file
View file

@ -0,0 +1,19 @@
require('./create-hash')
require('./create-hmac')
if (!process.browser) {
require('./dh')
}
require('./pbkdf2')
try {
require('randombytes')(8)
require('./ecdh')
require('./public-encrypt')
require('./random-bytes')
require('./sign')
require('./random-fill')
} catch (e) {
console.log('no secure rng avaiable')
}
require('./aes')

51
web/node_modules/crypto-browserify/test/node/dh.js generated vendored Normal file
View file

@ -0,0 +1,51 @@
var test = require('tape')
var cryptoB = require('../../')
var crypto = require('crypto')
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()
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')
})
})
})
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')
})
})
})

21
web/node_modules/crypto-browserify/test/pbkdf2.js generated vendored Normal file
View file

@ -0,0 +1,21 @@
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
var key = crypto.pbkdf2Sync(input.password, input.salt, input.iterations, input.length)
if (key.toString('hex') !== input.sha1) {
console.log(input)
}
t.equal(key.toString('hex'), input.sha1)
})
t.end()
})

View file

@ -0,0 +1,36 @@
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'
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')
})
})
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')
})
})

View file

@ -0,0 +1,60 @@
var test = require('tape')
var crypto = require('../')
var randomBytesFunctions = {
randomBytes: require('randombytes'),
pseudoRandomBytes: crypto.pseudoRandomBytes
}
for (var randomBytesName in randomBytesFunctions) {
// Both randomBytes and pseudoRandomBytes should provide the same interface
var randomBytes = randomBytesFunctions[randomBytesName]
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(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 + ' seem random', function (t) {
var L = 1000
var b = randomBytes(L)
var mean = [].reduce.call(b, 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
// 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)
// 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()
})
}

53
web/node_modules/crypto-browserify/test/random-fill.js generated vendored Normal file
View file

@ -0,0 +1,53 @@
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()
}
})
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()
})
})
test('seems random', function (t) {
var L = 1000
var b = crypto.randomFillSync(Buffer.alloc(L))
var mean = [].reduce.call(b, 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
// 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)
// 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()
})

59
web/node_modules/crypto-browserify/test/sign.js generated vendored Normal file
View file

@ -0,0 +1,59 @@
var test = require('tape')
var nodeCrypto = require('../')
var ourCrypto = require('browserify-sign/browser')
var rsa = {
'private': '2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a',
'public': '2d2d2d2d2d424547494e20525341205055424c4943204b45592d2d2d2d2d0a4d49494242674b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f773437457843744157700a4473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a524331666f48440a44554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38506a61486a0a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a7641754f0a6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f5247302f560a46642b5a654d353235315465547658483639356e6c53476175566c3941674d424141453d0a2d2d2d2d2d454e4420525341205055424c4943204b45592d2d2d2d2d0a'
}
var ec = {
'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')
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')
})
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 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('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')
})
})
}
testit(rsa, new Buffer('rsa with sha256'), 'RSA-SHA256')
testit(ec, new Buffer('ec with sha1'), 'ecdsa-with-SHA1')