summaryrefslogtreecommitdiff
path: root/src/blowfish.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2010-06-21 06:15:46 +0200
committerBram Moolenaar <Bram@vim.org>2010-06-21 06:15:46 +0200
commita8ffcbbf5d6070380e41b3d0841c3944396a27c0 (patch)
treeb8608922fc9956be229912f1323b0d0a94de526c /src/blowfish.c
parent191e0a2bc7cb4787e19aa1f8c6958b47e05d7882 (diff)
downloadvim-git-a8ffcbbf5d6070380e41b3d0841c3944396a27c0.tar.gz
Crypt the swapfile.
Diffstat (limited to 'src/blowfish.c')
-rw-r--r--src/blowfish.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/blowfish.c b/src/blowfish.c
index f0b97b7b9..c8e68d224 100644
--- 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.