Skip to content

Commit 27a944d

Browse files
use 512 bit keys for HMAC-SHA256 as per spec
see encryption-alliance/unified-vault-format#31
1 parent 9fb01db commit 27a944d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

frontend/src/common/universalVaultFormat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class UniversalVaultFormat implements AccessTokenProducing, VaultTemplate
439439
public async computeRootDirIdHash(rootDirId: Uint8Array): Promise<string> {
440440
const textencoder = new TextEncoder();
441441
const initialSeed = await crypto.subtle.importKey('raw', this.metadata.initialSeed, { name: 'HKDF' }, false, ['deriveKey']);
442-
const hmacKey = await crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-512', salt: this.metadata.kdfSalt, info: textencoder.encode('hmac') }, initialSeed, { name: 'HMAC', hash: 'SHA-256', length: 256 }, false, ['sign']);
442+
const hmacKey = await crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-512', salt: this.metadata.kdfSalt, info: textencoder.encode('hmac') }, initialSeed, { name: 'HMAC', hash: 'SHA-256', length: 512 }, false, ['sign']);
443443
const rootDirHash = await crypto.subtle.sign('HMAC', hmacKey, rootDirId);
444444
return base32.stringify(new Uint8Array(rootDirHash).slice(0, 20));
445445
}

frontend/test/common/universalVaultFormat.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ describe('UVF', () => {
292292
const rootDirId = base64.parse('5WEGzwKkAHPwVSjT2Brr3P3zLz7oMiNpMn/qBvht7eM=');
293293
const hash = await uvf.computeRootDirIdHash(rootDirId);
294294
expect(hash).to.have.a.lengthOf(32);
295-
expect(hash).to.eq('RKHZLENL3PQIW6GZHE3KRRRGLFBHWHRU');
295+
expect(hash).to.eq('RZK7ZH7KBXULNEKBMGX3CU42PGUIAIX4');
296296
});
297297

298298
it('encryptFile() creates some ciphertext', async () => {
299-
const rootDirId = base64.parse('24UBEDeGu5taq7U4GqyA0MXUXb9HTYS6p3t9vvHGJAc=');
299+
const rootDirId = base64.parse('5WEGzwKkAHPwVSjT2Brr3P3zLz7oMiNpMn/qBvht7eM=');
300300
const fileContent = await uvf.encryptFile(rootDirId, uvf.metadata.initialSeedId);
301301
expect(fileContent).to.have.a.lengthOf(128);
302302
expect(fileContent.slice(0, 4)).to.eql(new Uint8Array([0x75, 0x76, 0x66, 0x01])); // magic bytes

0 commit comments

Comments
 (0)