diff options
author | Bram Moolenaar <Bram@vim.org> | 2023-05-27 18:02:55 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-05-27 18:02:55 +0100 |
commit | 3a2a60ce4a8e73594bca16814672fcc243d093ac (patch) | |
tree | 4a105c50b7f3a3e219e49bd73f5f4730d90bcefd /src/crypt.c | |
parent | a40c0bcc83c32da02869f59b10538d6327df61c5 (diff) |
patch 9.0.1583: get E304 when using 'cryptmethod' "xchacha20v2"v9.0.1583
Problem: Get E304 when using 'cryptmethod' "xchacha20v2". (Steve Mynott)
Solution: Add 4th crypt method to block zero ID check. Avoid syncing a swap
file before reading the file. (closes #12433)
Diffstat (limited to 'src/crypt.c')
-rw-r--r-- | src/crypt.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/crypt.c b/src/crypt.c index 3acbfa27c0..daa608ae68 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -525,7 +525,8 @@ crypt_create_from_header( if (arg.cat_seed_len > 0) arg.cat_seed = header + CRYPT_MAGIC_LEN + arg.cat_salt_len; if (arg.cat_add_len > 0) - arg.cat_add = header + CRYPT_MAGIC_LEN + arg.cat_salt_len + arg.cat_seed_len; + arg.cat_add = header + CRYPT_MAGIC_LEN + + arg.cat_salt_len + arg.cat_seed_len; return crypt_create(method_nr, key, &arg); } @@ -603,7 +604,8 @@ crypt_create_for_writing( if (arg.cat_seed_len > 0) arg.cat_seed = *header + CRYPT_MAGIC_LEN + arg.cat_salt_len; if (arg.cat_add_len > 0) - arg.cat_add = *header + CRYPT_MAGIC_LEN + arg.cat_salt_len + arg.cat_seed_len; + arg.cat_add = *header + CRYPT_MAGIC_LEN + + arg.cat_salt_len + arg.cat_seed_len; // TODO: Should this be crypt method specific? (Probably not worth // it). sha2_seed is pretty bad for large amounts of entropy, so make @@ -795,10 +797,14 @@ crypt_check_method(int method) } } -#ifdef FEAT_SODIUM - static void +/* + * If the crypt method for "curbuf" does not support encrypting the swap file + * then disable the swap file. + */ + void crypt_check_swapfile_curbuf(void) { +#ifdef FEAT_SODIUM int method = crypt_get_method_nr(curbuf); if (crypt_method_is_sodium(method)) { @@ -809,8 +815,8 @@ crypt_check_swapfile_curbuf(void) msg_scroll = TRUE; msg(_("Note: Encryption of swapfile not supported, disabling swap file")); } -} #endif +} void crypt_check_current_method(void) @@ -863,9 +869,7 @@ crypt_get_key( set_option_value_give_err((char_u *)"key", 0L, p1, OPT_LOCAL); crypt_free_key(p1); p1 = curbuf->b_p_key; -#ifdef FEAT_SODIUM crypt_check_swapfile_curbuf(); -#endif } break; } @@ -959,7 +963,8 @@ crypt_sodium_init_( sodium_free(sd_state); return FAIL; } - if (state->method_nr == CRYPT_M_SOD2) + // "cat_add" should not be NULL, check anyway for safety + if (state->method_nr == CRYPT_M_SOD2 && arg->cat_add != NULL) { memcpy(arg->cat_add, &opslimit, sizeof(opslimit)); arg->cat_add += sizeof(opslimit); |