source: node_modules/sha.js/test/vectors.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[d24f17c]1var tape = require('tape')
2var vectors = require('hash-test-vectors')
3// var from = require('bops/typedarray/from')
4var Buffer = require('safe-buffer').Buffer
5
6var createHash = require('../')
7
8function makeTest (alg, i, verbose) {
9 var v = vectors[i]
10
11 tape(alg + ': NIST vector ' + i, function (t) {
12 if (verbose) {
13 console.log(v)
14 console.log('VECTOR', i)
15 console.log('INPUT', v.input)
16 console.log(Buffer.from(v.input, 'base64').toString('hex'))
17 }
18
19 var buf = Buffer.from(v.input, 'base64')
20 t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
21
22 i = ~~(buf.length / 2)
23 var buf1 = buf.slice(0, i)
24 var buf2 = buf.slice(i, buf.length)
25
26 console.log(buf1.length, buf2.length, buf.length)
27 console.log(createHash(alg)._block.length)
28
29 t.equal(
30 createHash(alg)
31 .update(buf1)
32 .update(buf2)
33 .digest('hex'),
34 v[alg]
35 )
36
37 var j, buf3
38
39 i = ~~(buf.length / 3)
40 j = ~~(buf.length * 2 / 3)
41 buf1 = buf.slice(0, i)
42 buf2 = buf.slice(i, j)
43 buf3 = buf.slice(j, buf.length)
44
45 t.equal(
46 createHash(alg)
47 .update(buf1)
48 .update(buf2)
49 .update(buf3)
50 .digest('hex'),
51 v[alg]
52 )
53
54 setTimeout(function () {
55 // avoid "too much recursion" errors in tape in firefox
56 t.end()
57 })
58 })
59}
60
61if (process.argv[2]) {
62 makeTest(process.argv[2], parseInt(process.argv[3], 10), true)
63} else {
64 vectors.forEach(function (v, i) {
65 makeTest('sha', i)
66 makeTest('sha1', i)
67 makeTest('sha224', i)
68 makeTest('sha256', i)
69 makeTest('sha384', i)
70 makeTest('sha512', i)
71 })
72}
Note: See TracBrowser for help on using the repository browser.