diff src/blowfish.c @ 2267:c08f91142c41 vim73

Crypt the swapfile.
author Bram Moolenaar <bram@vim.org>
date Mon, 21 Jun 2010 06:15:46 +0200
parents b7cb69ab616d
children 2b33a7678e7b
line wrap: on
line diff
--- a/src/blowfish.c
+++ b/src/blowfish.c
@@ -436,13 +436,7 @@ bf_key_init(password, salt, salt_len)
         key[i] = j;
     }
 
-    for (i = 0; i < 256; ++i)
-    {
-	sbx[0][i] = sbi[0][i];
-	sbx[1][i] = sbi[1][i];
-	sbx[2][i] = sbi[2][i];
-	sbx[3][i] = sbi[3][i];
-    }
+    mch_memmove(sbx, sbi, 4 * 4 * 256);
 
     for (i = 0; i < 18; ++i)
     {
@@ -655,6 +649,40 @@ bf_crypt_init_keys(passwd)
     }
 }
 
+static int save_randbyte_offset;
+static int save_update_offset;
+static char_u save_ofb_buffer[BF_OFB_LEN];
+static UINT32_T save_pax[18];
+static UINT32_T save_sbx[4][256];
+
+/*
+ * Save the current crypt state.  Can only be used once before
+ * bf_crypt_restore().
+ */
+    void
+bf_crypt_save()
+{
+    save_randbyte_offset = randbyte_offset;
+    save_update_offset = update_offset;
+    mch_memmove(save_ofb_buffer, ofb_buffer, BF_OFB_LEN);
+    mch_memmove(save_pax, pax, 4 * 18);
+    mch_memmove(save_sbx, sbx, 4 * 4 * 256);
+}
+
+/*
+ * Restore the current crypt state.  Can only be used after
+ * bf_crypt_save().
+ */
+    void
+bf_crypt_restore()
+{
+    randbyte_offset = save_randbyte_offset;
+    update_offset = save_update_offset;
+    mch_memmove(ofb_buffer, save_ofb_buffer, BF_OFB_LEN);
+    mch_memmove(pax, save_pax, 4 * 18);
+    mch_memmove(sbx, save_sbx, 4 * 4 * 256);
+}
+
 /*
  * Run a test to check if the encryption works as expected.
  * Give an error and return FAIL when not.