From: Ardis Lu Date: Sat, 25 Feb 2023 04:13:02 +0000 (-0800) Subject: Reduce iv (nonce) size to 96 bits X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=ab7abcf24b73bd19bffb7a00bc98189b72f8f395;p=static-encrypt Reduce iv (nonce) size to 96 bits NIST Special Publication 800-38D recommends EXACTLY 96 bits --- 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);