]> git.ardis.lu - static-encrypt/commitdiff
Reduce iv (nonce) size to 96 bits
authorArdis Lu <ardisglu@gmail.com>
Sat, 25 Feb 2023 04:13:02 +0000 (20:13 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 25 Feb 2023 04:13:02 +0000 (20:13 -0800)
NIST Special Publication 800-38D recommends EXACTLY 96 bits

decrypt.js
encrypt.js

index ff85e32df6c8465ba3823fde6169d61ef6e0d3a1..cfa06066517cf4376aafb033a8b4aa84675ad402 100644 (file)
@@ -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',
index febaffa51e91d8ec43bd5945afceab12b2ab89db..e8ccc52279a813c7d18e737d27a9615071ce2540 100644 (file)
@@ -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);
 
This page took 0.049122 seconds and 4 git commands to generate.