aboutsummaryrefslogtreecommitdiff
path: root/node_modules/sha.js/test/vectors.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/sha.js/test/vectors.js
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
node_modules
Diffstat (limited to 'node_modules/sha.js/test/vectors.js')
-rw-r--r--node_modules/sha.js/test/vectors.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/node_modules/sha.js/test/vectors.js b/node_modules/sha.js/test/vectors.js
new file mode 100644
index 000000000..4aef39cc3
--- /dev/null
+++ b/node_modules/sha.js/test/vectors.js
@@ -0,0 +1,76 @@
+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)
+ })
+}