File: README.md

package info (click to toggle)
node-hash-test-vectors 1.3.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,164 kB
  • sloc: makefile: 2; sh: 2
file content (80 lines) | stat: -rw-r--r-- 2,195 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# hash-test-vectors

The nist test vectors expanded to cover every hash function supported by node.js,
output is saved in a json file, so that it is possible to run tests in the browser.

NIST provides test vectors for sha and md5, and this module takes
that set and outputs a json file containing the input (in base 64)
plus all output of every hash function that node.js supports.

This makes it easy to test javascript hash functions, with fairly roboust coverage.

I took the original test vectors at http://www.nsrl.nist.gov/testdata/

## example

``` js
var vectors = require('hash-test-vectors')
var tape = require('tape')
var MySha1 = require('./my-sha1-implementation')

vectors.forEach(function (v, i) {

  tape('my-sha1 against test vector ' + i, function (t) {
    //test in bash64 encoding + as a buffer
    t.equal(new MySha1().update(v.input, 'base64').digest('hex'), v.sha1)
    t.equal(new MySha1().update(new Buffer(v.input, 'base64')).digest('hex'), v.sha1)
    t.end()
  })
})

```

## hmac example

hmac vectors taken from [rfc4231](http://tools.ietf.org/rfc/rfc4231.txt)
(included in this repo)

each test vector has `{key: hex, data: hex}` and the outputs of hmac with every
hash algorithm in node, also in hex encoding.

``` js
var vectors = require('hash-test-vectors')
var tape = require('tape')
var MySha1Hmac = require('./my-sha1-hmac-implementation')

vectors.forEach(function (v, i) {
  tape('my-sha1-hmac against test vector ' + i, function (t) {
    //test in bash64 encoding + as a buffer
    t.equal(new MySha1Hmac(new Buffer(v.key, 'hex')).update(v.data, 'hex').digest('hex'), v.sha1)
    t.end()
  })
})

```

## pbkdf2 example

pbkdf2 vectors taken from [rfc6070](http://tools.ietf.org/rfc/rfc6070.txt)
(also included in this repo)

``` js
var vectors = require('hash-test-vectors')
var tape = require('tape')
var MyPbkdf2 = require('./my-pbkdf2-implementation')

vectors.forEach(function (v, i) {
  tape('my-pbkdf2 against test vector ' + i, function (t) {
    //test in bash64 encoding + as a buffer
    var key = new MyPbkdf2(v.password, v.salt, v.iterations, v.length)
    t.equal(key.toString('hex')), v.sha1)
    t.end()
  })
})

```


## License

MIT