Sha256: d1c86c2e55bc70d8c5312cc243ee2c79cb1de7c187b1f8df84f283e04de55e11

Contents?: true

Size: 1.68 KB

Versions: 8

Compression:

Stored size: 1.68 KB

Contents

var tape = require('tape')
var vectors = require('hash-test-vectors')
// var from = require('bops/typedarray/from')
var Buffer = require('buffer').Buffer
var hexpp = require('../hexpp')

var createHash = require('../')

function makeTest (alg, i, verbose) {
  var v = vectors[i]

  tape(alg + ': NIST vector ' + i, function (t) {
    if (verbose) {
      console.log(v)
      console.log('VECTOR', i)
      console.log('INPUT', v.input)
      console.log(hexpp(new Buffer(v.input, 'base64')))
      console.log(new Buffer(v.input, 'base64').toString('hex'))
    }

    var buf = new Buffer(v.input, 'base64')
    t.equal(createHash(alg).update(buf).digest('hex'), v[alg])

    i = ~~(buf.length / 2)
    var buf1 = buf.slice(0, i)
    var buf2 = buf.slice(i, buf.length)

    console.log(buf1.length, buf2.length, buf.length)
    console.log(createHash(alg)._block.length)

    t.equal(
      createHash(alg)
        .update(buf1)
        .update(buf2)
        .digest('hex'),
      v[alg]
    )

    var j, buf3

    i = ~~(buf.length / 3)
    j = ~~(buf.length * 2 / 3)
    buf1 = buf.slice(0, i)
    buf2 = buf.slice(i, j)
    buf3 = buf.slice(j, buf.length)

    t.equal(
      createHash(alg)
        .update(buf1)
        .update(buf2)
        .update(buf3)
        .digest('hex'),
      v[alg]
    )

    setTimeout(function () {
      // avoid "too much recursion" errors in tape in firefox
      t.end()
    })
  })

}

if (process.argv[2]) {
  makeTest(process.argv[2], parseInt(process.argv[3], 10), true)

} else {
  vectors.forEach(function (v, i) {
    makeTest('sha', i)
    makeTest('sha1', i)
    makeTest('sha224', i)
    makeTest('sha256', i)
    makeTest('sha384', i)
    makeTest('sha512', i)
  })
}

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
lanes-0.8.0 node_modules/sha.js/test/vectors.js
minimum_viable_product-0.0.11 test/dummy/node_modules/sha.js/test/vectors.js
brwy_rails-0.0.6 test/dummy/node_modules/sha.js/test/vectors.js
brwy_rails-0.0.5 test/dummy/node_modules/sha.js/test/vectors.js
brwy_rails-0.0.4 test/dummy/node_modules/sha.js/test/vectors.js
brwy_rails-0.0.3 test/dummy/node_modules/sha.js/test/vectors.js
brwy_rails-0.0.2 test/dummy/node_modules/sha.js/test/vectors.js
brwy_rails-0.0.1 test/dummy/node_modules/sha.js/test/vectors.js