Skip to content

Commit ec8fd64

Browse files
committed
Add test vectors for hash algorithms
Test algorithms against vector data from NSRL (NIST): http://www.nsrl.nist.gov/testdata/
1 parent 4552197 commit ec8fd64

File tree

201 files changed

+645
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+645
-0
lines changed

test/node.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var test = require('tape');
22

33
var crypto = require('crypto');
44
var cryptoB = require('../');
5+
var fs = require('fs');
56

67
function assertSame(name, fn) {
78
test(name, function (t) {
@@ -43,6 +44,25 @@ algorithms.forEach(function (algorithm) {
4344
});
4445
});
4546

47+
function pad(n, w) {
48+
n = n + ''; return new Array(w - n.length + 1).join('0') + n;
49+
}
50+
51+
var vectors = fs.readdirSync(__dirname + '/vectors').sort().
52+
filter(function (t) { return t.match(/\.dat$/); }).
53+
map(function (t) { return fs.readFileSync(__dirname + '/vectors/' + t); });
54+
55+
['md5', 'sha1', 'sha256'].forEach(function (algorithm) {
56+
test(algorithm, function (t) {
57+
function hash(data) { return cryptoB.createHash(algorithm).update(data).digest('hex'); }
58+
59+
var hashes = fs.readFileSync(__dirname + '/vectors/byte-hashes.' + algorithm).toString().split(/\r?\n/);
60+
t.plan(vectors.length);
61+
for (var i = 0; i < vectors.length; i++) {
62+
t.equal(hash(vectors[i]), hashes[i], 'byte' + pad(i, 4) + '.dat');
63+
}
64+
});
65+
});
4666

4767
test('randomBytes', function (t) {
4868
t.plan(5);

test/vectors/Readme.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
File formats:
3+
4+
There are two files included for this byte-oriented test.
5+
One file contains the messages and the other file contains the hashes.
6+
7+
The message files provided use "compact strings" to store the message values.
8+
Compact strings are used to represented the messages in a compact form.
9+
A compact string has the form
10+
z || b || n(1) || n(2) || ... || n(z)
11+
where z>=0 that represents the number of n, b is either 0 or 1, and
12+
each n(i) is a decimal integer representing a positive number.
13+
The length of the compact string is given by the summation of the n(i).
14+
15+
The compact string is interpreted as the representation of the bit string
16+
consisting of b repeated n(1) times, followed by 1-b repeated n(2) times,
17+
followed by b repeated n(3) times, and so on.
18+
19+
Example:
20+
M = 5 1 7 13 5 1 2
21+
where z = 5 and b = 1. Then the compact string M represents the bit string
22+
1111111000000000000011111011
23+
where 1 is repeated 7 times, 0 is repeated 13 times, 1 is repeated 5 times,
24+
0 is repeated 1 time, and 1 is repeated 2 times.
25+

test/vectors/byte-hashes.md5

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
d41d8cd98f00b204e9800998ecf8427e
2+
c3e97dd6e97fb5125688c97f36720cbe
3+
038701ca277a9d4de87bff428dd30a12
4+
bc60c6192e361d99b59d47250668a852
5+
542c3a0ab6b51bc6a88fa7bb567bca3e
6+
e035f9e748a2a09a4fbdcf18c4f58bf1
7+
3b4cc9226a236742d72578c5915b6c3c
8+
35950208a022baac90056636827158ce
9+
84cedff2ed1b78b395cc8651094f4ce3
10+
7badf748f4cb700272a72edfea22e9bf
11+
a1bb6e142739dbdb0925747d95e0a1ad
12+
0cd9b72dfdee8efd2e1515f4c5a62284
13+
ef07c13e75d50578d09052aa21a7cffb
14+
cf3b261af9344bf83b4dd82b30242c78
15+
530710f65fb98fff8eb927e2938cb8c5
16+
4e6d73658b27e19d4bb4500625001e39
17+
c8e5f2f272b1ef88ec62dd0d9d54e902
18+
031cbf1fb05b4ec09f3c93235d0f49ac
19+
8c0e1400df02ba8c4809b705e5f5e114
20+
57ec48278e19f71f54c570a5ab306df7
21+
ecd3dc346a2337b95389a094a031610f
22+
f11d91eae492225cbd82ef356aa96f9f
23+
26bd8b480216c723ce75da98b9bd430c
24+
80999c2d12f623e4f87e0550a8e3523a
25+
00945c1bd739ce389ac24bb93f6f9a85
26+
7ab55f0bd5dca5b17ecaa7fef73ed87b
27+
e3cedd606ad51dd18532abd3079a3e0c
28+
df5ecc6732e22cc25836398a10222e97
29+
863b6d9962ee3761bbb9cd8a8367589e
30+
683c9384e29efe82dd3ac847904c28e8
31+
b3d948e72159ddc9c600d75512c5f115
32+
ce8633a6cf189b07e022147bbbd0f350
33+
8df17372eb32a0afa4fc47837262ff61
34+
62c63ca91890ce6f78a59c0bdb1e7bab
35+
1eda4bb0259a939548ec4ceb39facde4
36+
c4f37a2c450f2a23322513b372e668a5
37+
cab8f06436c5ad45f982490215836f4e
38+
3a43bc720714a2a42a73a76085542f86
39+
03f2f4033b258e6eb1e101f1ed4c24b4
40+
2ceb33cec5ecad4a50f6bd3a831ae77c
41+
dd808f695d28f93562cfcb164bc3cce4
42+
01c6d7a87e94bf685205ec8d7c5196af
43+
ef0e93e8928f8bae1b216da8e661fc9b
44+
c8da55117d7d4b7ee8ddc8dc4ba73aa6
45+
bbfc64583c6d4c2ef4b0358464d4d028
46+
3bb5864481f2e66387419dd1a168aadc
47+
0d725d3a1d3d97d7b5ea8293bbbf32ba
48+
915eb22a15f7673f983672b6c353b6c8
49+
13b51da3e8a1422bfd58b79c4e19de64
50+
e69d6c03102464f22c395f9fa27108de
51+
132fa4cbedaa7bd965b0b5900211be48
52+
e37ff5d9f14249f327a19dd5296e6c7e
53+
4881a65cf107b1d034ff3ecd64ab9cb4
54+
547e92d01c0b699cfdf43f91714cfe2d
55+
aa2b3a055b56845f19109f21d3c783f4
56+
eb1f01cc647ece73b2192537200bb8b9
57+
1db274ef41b1ad71f713df2b05207e1a
58+
d8b4ec343b4310345efc6da9cee8a2ec
59+
082ee3b2be7910f7350368e395a63d90
60+
d247c4070ae1de106bcb438a2dacac23
61+
f8cbc4f3af45befc792679f2b113f1cb
62+
9031006a437019c5dcd987a31731ebd9
63+
a6b62759ee3883258fbdeeb8b56e6283
64+
4933898605b4a1b970b674a2dde92292
65+
f0684ca20de4607232f3e158e81a37f2
66+
c0b3fdecb3bb7b4ff0c936f378ccb027
67+
50652123b5e0e51bb5bc3fdde3c6a750
68+
ed4526ba8226d969f47edbb27b2f1144
69+
80e6f61dff9da8673fa16dbbdb14d03d
70+
1d52744bf1450d7c5cfdf1f0bbf967c1
71+
3438a953124960bcc44611923a8844ee
72+
b2f341296dd7aabbd4fd8e011be68a7d
73+
322dba69658a92e9a9ace4d7177fb97d
74+
b94a434a98efa493fbbc989360671bb9
75+
cd9ce9a01ed810af70999d8ce4c63811
76+
4c639abb75a0ae0f22c3384cb9c68441
77+
fe31ffcced1717988c854c2f3492466e
78+
b56d81337f9bbf0d838df831e9b40216
79+
0be9161adfeb2dd1c3f20338bfb3ec4b
80+
be7b7c9fa1ab09d6578a3f2a82bfafe3
81+
f6bdc04b4611ddf0aa8403bcb04292f7
82+
1c7146a10f3c76b0c1dd4af354b14982
83+
0d3d987f94aee65f84436696bcf33ea4
84+
1a5c9ac3ee859361ad5477ea792506a3
85+
e827d60f27e35d8e5b05af748ba897dd
86+
5b7899bf7a6267d9b3b8c82f241a1d7b
87+
6dc9fe740cf4a4b93cb0953a3c2a6026
88+
27adf814806fd4a51c1ffc84122c5c8a
89+
f74e94ab992c8f27de264993a09ab429
90+
5eee0f1591d10c159763749ec86b9ecb
91+
46898964a3889615d9f7c22a81e0a0e7
92+
8fb58d6770971b0f12e40b31ad65b4a9
93+
eb4ce130268dc13731dcd16ff492d0a9
94+
23532a54e8005860ad5e77f4e3392827
95+
07fedc4dc4891d1a90c501a781a666f2
96+
83e8341035b37dd70a92a6eed5406927
97+
6c9f7b3b25734d58f21f5050642874a5
98+
ef661042e6624f4052ce86d8f233d780
99+
efe794cdfad5cb86656e29854a1f5c92
100+
e5f19a0045481443bae165f03598a9ba
101+
b8fe8691321edbf308a9d60bb817c6af
102+
f31fdd0f1aef106005e6d29b72229fa1
103+
239ed45c3cb734db446adfbbe3dab8a1
104+
2c2303411c7d25617a54106aca18070d
105+
de179c41aca8bcdc388964024948ff8e
106+
ca335b74d59bd50832267d3bf28f81df
107+
dabda7a1cbaa8ea5104c57c8950b703a
108+
076352a22ecea5ebc876812f62c1cb8d
109+
ee0a2bdec712a9413623d8a920714b96
110+
a927c3a99f2843de4133377c690db9b7
111+
1fa98cff485549d49799dc8cf987a8af
112+
74013a076a786a26c7e04217bb51031d
113+
a44ca9661e967bb2e98af65277dac72f
114+
d30897726b635548dbfa5cebffd9cd63
115+
4ad04a250b8029c9a7bf6529ee8793c3
116+
de41e337d96fd23619121ea709861e1a
117+
18e070fd32cf732b9f37a0083320eec2
118+
7dd4b27ca8906182f684d0ee4ddb98c4
119+
70a440a8bd06ff40f6e9135946eb174d
120+
b8d052366e752ce7c803abd24854e934
121+
8ab9dfff746ce3e62c6e04feb7b48528
122+
ecfca8b371616efe78e9916dbf825f5b
123+
5f76da828c37fc4edb4557953539c92a
124+
ecad54f76ce3bc233e02fc6fd7f94628
125+
e8a1cc06bfec7f677f36a693e1342400
126+
9ad0fe040e44a8e7146c3dd8582b6752
127+
4e56f978f94cf72158fd4311831b4f9f
128+
3b95686fe49f50006607d5978aaa3efc
129+
fa354daecc45f14b82b0e7e567d24282
130+
b7c30cf902e74c10e3d5c3af7e854f6b
131+
e9369a7ec98e63186bdae77025cb5519
132+
57b441e2f3397d2628657e636cd2fc80
133+
8ae3a1e880ffb884260ec26e8fcd71a5
134+
eb7d8f9199945e8a1e5c3708da45e08b
135+
d7dd1997c20a1029f9bd0fd1e2d2ed92
136+
a986ef62ef378583985cf0d0a34d17d0
137+
ad5bef0d6ad3434f871983ed09aaa43c
138+
326f662a5c18a14d26c3d35131ea4b4e
139+
ea4bf919aebf4add0024d91ee6f640d0
140+
9cc49e156084d2c757bd6d502bae8309
141+
9c18d4c75cc02337c277532ecea4b9fa
142+
4159a65b7db275742e998fb855e7b9f3
143+
df34d37f6b4ef078bd9570efdd8fd2e2
144+
84d2c12c4f0c28d288464d33a23f227c
145+
17b55bbd4222066960e54182e1e95f0b
146+
75eb69b22793852bc892ce264c421a1e
147+
de4abe78e28e2718200c76237f2ed42f
148+
1149c8fc988799f43f6e5069355e108b
149+
4129891ff13ddd62820f6f3cdbfa95da
150+
c8758df3c9ad4d311516ea39fe734052
151+
360ddf0b658fd764ef5ae9bf7a8a1a12
152+
ad054e0e84e2b8e2b02ce4dee7688226
153+
cb434f8c5fad9793ed142805afa861a0
154+
83a3d5436f96cb2cb31d929794425f31
155+
34dde0f0fe7d4fdb359df1fccbf5fcde
156+
7b77219e9549fad49e97c380f7e1f362
157+
053f4e89ae2355c5cb259d21e85eb9cd
158+
fc45c5118f642cc479e6a550756f1a4e
159+
0138351089a87a2ddc2d98255ce6b8cc
160+
1f3e42daa4b315f2a0e6a530e0cc6976
161+
aec4974f238a6e04dcb07e20ad861230
162+
7a27fedaeec41b5832bda3169d76cd05
163+
154bd1371ae66ad3ab9a9ee6b1324e36
164+
a4594c9e974eed1fc159cc306dd7378a
165+
431acd1a4a4d6036057c9906da8add5e
166+
f6afe47bdedf075c7e188b2640152cf7
167+
8bc3bd8625778f64ed7c29698025f292
168+
51f6bb4db8e6e61cc4333450c6035139
169+
0baff1c675866bf259d3ac9417a33464
170+
6e8a56a9a005c6c6239ccbdf48f59aa8
171+
6565bceb49f962f797f49084f3f819a1
172+
2267037a7f3e753c653218fcf67ce9c7
173+
aca1ae6237f498986991565b0307f0da
174+
785bb09a5f25730a3aed4de12da4d9ea
175+
4eb5472f4e5243fcd4a76533789e829a
176+
7d725ae9a8e569f49c56194226b64dee
177+
7396f5d4491e79ec1ac0ce7a105bb233
178+
aa64644a4877da34e2197c5f2dc375c5
179+
2165718fc24bf21f1c4e0623c8e8d811
180+
e1f45852024724f00ced7935e297983a
181+
deac06cde1f6b18a53a2cf0b03998da2
182+
8371f0970efbc6099c50afbbd4f0e477
183+
985d909280bc20607f4cb4941ae535f2
184+
abcdd18a791546544b52c0587dbd6107
185+
23e8b5a657c962a3e77979859ae1400e
186+
cc4fab29cc180ffa888be396ce6aa6f5
187+
b553506daedf701ccdc437fbf3e6bbe4
188+
d707ae093ab94607010ddda09fc8a5a8
189+
76bdae04521ba996636c4dc431040031
190+
556c14fd0f3ff7bd6b435bd630e48811
191+
b500501957d4b8b412ea0102c842dd5e
192+
d18506a74c66e4d8537269c10c783923
193+
c9b4b691f4d88b7d2b4d5b770b05c8bf
194+
ba915c678f944fe5a480364ddc3382a8
195+
78134c91a1ffb2e21594daa2c2a932fc
196+
6fc6c8790dfc301ee38b8b63e18def5c

0 commit comments

Comments
 (0)