Sha256: e8d9df8dc71a04e7be04ae9d448d1fb436e0c2f6998101b37c2e574a5d418b04

Contents?: true

Size: 1.6 KB

Versions: 35

Compression:

Stored size: 1.6 KB

Contents

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

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(Buffer.from(v.input, 'base64').toString('hex'))
    }

    var buf = Buffer.from(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

35 entries across 34 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.18.0 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.18.2 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.16.1 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.15.2 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.18.4 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.18.1 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.14.0 test/dummy/node_modules/sha.js/test/vectors.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/sha.js/test/vectors.js
tang-0.2.1 spec/tang_app/node_modules/sha.js/test/vectors.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/sha.js/test/vectors.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/sha.js/test/vectors.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/sha.js/test/vectors.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/sha.js/test/vectors.js
tang-0.2.0 spec/tang_app/node_modules/sha.js/test/vectors.js
tang-0.1.0 spec/tang_app/node_modules/sha.js/test/vectors.js
tang-0.0.9 spec/tang_app/node_modules/sha.js/test/vectors.js
enju_library-0.3.8 spec/dummy/node_modules/sha.js/test/vectors.js
ilog-0.4.1 node_modules/sha.js/test/vectors.js