From ab7abcf24b73bd19bffb7a00bc98189b72f8f395 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 24 Feb 2023 20:13:02 -0800 Subject: [PATCH] Reduce iv (nonce) size to 96 bits NIST Special Publication 800-38D recommends EXACTLY 96 bits --- decrypt.js | 8 ++++---- encrypt.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/decrypt.js b/decrypt.js index ff85e32..cfa0606 100644 --- a/decrypt.js +++ b/decrypt.js @@ -3,11 +3,11 @@ export default async function decrypt(content, password) { const contentBuffer = Uint8Array.from(atob(content), c => c.charCodeAt(0)); const salt = new Uint8Array(32); - const iv = new Uint8Array(32); - const ciphertext = new Uint8Array(contentBuffer.byteLength - 64); + const iv = new Uint8Array(12); + const ciphertext = new Uint8Array(contentBuffer.byteLength - 44); salt.set(contentBuffer.slice(0, 32)); - iv.set(contentBuffer.slice(32, 64)); - ciphertext.set(contentBuffer.slice(64)); + iv.set(contentBuffer.slice(32, 44)); + ciphertext.set(contentBuffer.slice(44)); const keyMaterial = await crypto.subtle.importKey( 'raw', diff --git a/encrypt.js b/encrypt.js index febaffa..e8ccc52 100644 --- a/encrypt.js +++ b/encrypt.js @@ -4,7 +4,7 @@ export default async function encrypt(plaintext, password) { const encodedPassword = encoder.encode(password); const salt = new Uint8Array(32); - const iv = new Uint8Array(32); + const iv = new Uint8Array(12); crypto.getRandomValues(salt); crypto.getRandomValues(iv); -- 2.47.3