-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathevpkdf.test.js
32 lines (25 loc) · 1.18 KB
/
evpkdf.test.js
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
import C from '../src/index';
beforeAll(async () => {
// the default hasher for EvpKDF is md5
await C.EvpKDF.loadWasm();
});
describe('algo-evpkdf-test', () => {
test('testVector', () => {
expect(C.EvpKDF('password', 'saltsalt', { keySize: (256+128)/32 }).toString()).toBe('fdbdf3419fff98bdb0241390f62a9db35f4aba29d77566377997314ebfc709f20b5ca7b1081f94b1ac12e3c8ba87d05a');
});
// There are no official test vectors that I could find, and the EVP implementation is short on comments.
// Need to use the C code to generate more test vectors.
// The iteration count in particular needs to be tested.
test('testInputIntegrity', () => {
let password = new C.lib.WordArray([0x12345678]);
let salt = new C.lib.WordArray([0x12345678]);
let expectedPassword = password.toString();
let expectedSalt = salt.toString();
C.EvpKDF(password, salt);
expect(password.toString()).toBe(expectedPassword);
expect(salt.toString()).toBe(expectedSalt);
});
test('testHelper', () => {
expect(C.EvpKDF('password', 'saltsalt', { keySize: (256+128)/32 }).toString()).toBe(new C.algo.EvpKDF({ keySize: (256+128)/32 }).compute('password', 'saltsalt').toString());
});
});