react / wstein / node_modules / browserify / node_modules / shasum / node_modules / sha.js / test / vectors.js
80540 views1var vectors = require('hash-test-vectors')2var tape = require('tape')3//var from = require('bops/typedarray/from')4var Buffer = require('buffer').Buffer5var hexpp = require('../hexpp')67var createHash = require('../')89function makeTest(alg, i, verbose) {10var v = vectors[i]1112tape(alg + ': NIST vector ' + i, function (t) {13if(verbose) {14console.log(v)15console.log('VECTOR', i)16console.log('INPUT', v.input)17console.log(hexpp(new Buffer(v.input, 'base64')))18console.log(new Buffer(v.input, 'base64').toString('hex'))19}20var buf = new Buffer(v.input, 'base64')21t.equal(createHash(alg).update(buf).digest('hex'), v[alg])2223i = ~~(buf.length / 2)24var buf1 = buf.slice(0, i)25var buf2 = buf.slice(i, buf.length)2627console.log(buf1.length, buf2.length, buf.length)28console.log(createHash(alg)._block.length)2930t.equal(31createHash(alg)32.update(buf1)33.update(buf2)34.digest('hex'),35v[alg]36)3738var j, buf33940i = ~~(buf.length / 3)41j = ~~(buf.length * 2 / 3)42buf1 = buf.slice(0, i)43buf2 = buf.slice(i, j)44buf3 = buf.slice(j, buf.length)4546t.equal(47createHash(alg)48.update(buf1)49.update(buf2)50.update(buf3)51.digest('hex'),52v[alg]53)5455setTimeout(function () {56//avoid "too much recursion" errors in tape in firefox57t.end()58})59})6061}6263if(process.argv[2])64makeTest(process.argv[2], parseInt(process.argv[3]), true)65else66vectors.forEach(function (v, i) {67makeTest('sha1', i)68makeTest('sha224', i)69makeTest('sha256', i)70makeTest('sha384', i)71makeTest('sha512', i)72})737475767778