UNPKG

1.91 kBJavaScriptView Raw
1var tape = require('tape')
2var blake2b = require('./')
3var vectors = require('blake2b/test-vectors.json')
4
5blake2b.ready(function () {
6 tape('hello world', function (t) {
7 var hash = blake2b()
8 .update(Buffer.from('hello'))
9 .update(Buffer.from(' '))
10 .update(Buffer.from('world'))
11 .digest('hex')
12
13 t.same(hash, '256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610')
14 t.end()
15 })
16
17 tape('hello world', function (t) {
18 var hash = blake2b(64)
19 .update(Buffer.from('hello'))
20 .update(Buffer.from(' '))
21 .update(Buffer.from('world'))
22 .digest('hex')
23
24 t.same(hash, '021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0')
25 t.end()
26 })
27
28 tape('both at the same time', function (t) {
29 var a = blake2b()
30 var b = blake2b(64)
31
32 var hash = a
33 .update(Buffer.from('hello'))
34 .update(Buffer.from(' '))
35 .update(Buffer.from('world'))
36 .digest('hex')
37
38 t.same(hash, '256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610')
39
40 var hash = b
41 .update(Buffer.from('hello'))
42 .update(Buffer.from(' '))
43 .update(Buffer.from('world'))
44 .digest('hex')
45
46 t.same(hash, '021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0')
47 t.end()
48 })
49
50 vectors.forEach(function (vector, i) {
51 tape('test-vectors.json #' + i, function (t) {
52 var key = vector.key && Buffer.from(vector.key, 'hex')
53 var salt = vector.salt && Buffer.from(vector.salt, 'hex')
54 var personal = vector.personal && Buffer.from(vector.personal, 'hex')
55
56 var hash = blake2b(vector.outlen, key, salt, personal)
57 .update(Buffer.from(vector.input, 'hex'))
58 .digest('hex')
59
60 t.same(hash, vector.out)
61 t.end()
62 })
63 })
64})
65