diff options
author | John Schmidt <john.schmidt.h@gmail.com> | 2014-05-07 18:04:54 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-20 08:31:06 -0300 |
commit | 85338fe1d5a56f82546e16c305c2048c081771e0 (patch) | |
tree | 1a14dcf2a4aa6c5276a4ea7802f4cbe576e9a6e3 | |
parent | 32d018b57edbc75d6a70c5cd3e8012d7f924f460 (diff) | |
download | rneovim-85338fe1d5a56f82546e16c305c2048c081771e0.tar.gz rneovim-85338fe1d5a56f82546e16c305c2048c081771e0.tar.bz2 rneovim-85338fe1d5a56f82546e16c305c2048c081771e0.zip |
Remove cryptography
As discussed in #694, vim encryption uses old,
obsolete algorithms that are poorly implemented.
Since insecure cryptography is worse than no
cryptgraphy, the community voted in favor of
removing all crypto.
Various alternatives to the old crypto is
being discussed in #701.
Closes #694.
33 files changed, 16 insertions, 1971 deletions
diff --git a/config/config.h.in b/config/config.h.in index 95d0d3cf68..88352b1d71 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -114,7 +114,6 @@ #define FEAT_COMPL_FUNC #define FEAT_CONCEAL #define FEAT_CON_DIALOG -#define FEAT_CRYPT #define FEAT_CSCOPE #define FEAT_CURSORBIND #define FEAT_DIFF diff --git a/src/nvim/blowfish.c b/src/nvim/blowfish.c deleted file mode 100644 index d48724ada4..0000000000 --- a/src/nvim/blowfish.c +++ /dev/null @@ -1,622 +0,0 @@ -/* - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - * - * Blowfish encryption for Vim; in Blowfish cipher feedback mode. - * Contributed by Mohsin Ahmed, http://www.cs.albany.edu/~mosh - * Based on http://www.schneier.com/blowfish.html by Bruce Schneier. - */ - -#include <string.h> - -#include "nvim/vim.h" -#include "nvim/blowfish.h" -#include "nvim/message.h" -#include "nvim/sha256.h" - -#define ARRAY_LENGTH(A) (sizeof(A) / sizeof(A[0])) - -#define BF_BLOCK 8 -#define BF_BLOCK_MASK 7 -#define BF_CFB_LEN (8 * (BF_BLOCK)) - -typedef union { - uint32_t ul[2]; - char_u uc[8]; -} block8; - - -static void bf_e_block(uint32_t *p_xl, uint32_t *p_xr); -static void bf_e_cblock(char_u *block); -static int bf_check_tables(uint32_t a_ipa[18], uint32_t a_sbi[4][256], - uint32_t val); -static int bf_self_test(void); - -/* Blowfish code */ -static uint32_t pax[18]; -static uint32_t ipa[18] = { - 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, - 0x03707344u, 0xa4093822u, 0x299f31d0u, - 0x082efa98u, 0xec4e6c89u, 0x452821e6u, - 0x38d01377u, 0xbe5466cfu, 0x34e90c6cu, - 0xc0ac29b7u, 0xc97c50ddu, 0x3f84d5b5u, - 0xb5470917u, 0x9216d5d9u, 0x8979fb1bu -}; - -static uint32_t sbx[4][256]; -static uint32_t sbi[4][256] = { - {0xd1310ba6u, 0x98dfb5acu, 0x2ffd72dbu, 0xd01adfb7u, - 0xb8e1afedu, 0x6a267e96u, 0xba7c9045u, 0xf12c7f99u, - 0x24a19947u, 0xb3916cf7u, 0x0801f2e2u, 0x858efc16u, - 0x636920d8u, 0x71574e69u, 0xa458fea3u, 0xf4933d7eu, - 0x0d95748fu, 0x728eb658u, 0x718bcd58u, 0x82154aeeu, - 0x7b54a41du, 0xc25a59b5u, 0x9c30d539u, 0x2af26013u, - 0xc5d1b023u, 0x286085f0u, 0xca417918u, 0xb8db38efu, - 0x8e79dcb0u, 0x603a180eu, 0x6c9e0e8bu, 0xb01e8a3eu, - 0xd71577c1u, 0xbd314b27u, 0x78af2fdau, 0x55605c60u, - 0xe65525f3u, 0xaa55ab94u, 0x57489862u, 0x63e81440u, - 0x55ca396au, 0x2aab10b6u, 0xb4cc5c34u, 0x1141e8ceu, - 0xa15486afu, 0x7c72e993u, 0xb3ee1411u, 0x636fbc2au, - 0x2ba9c55du, 0x741831f6u, 0xce5c3e16u, 0x9b87931eu, - 0xafd6ba33u, 0x6c24cf5cu, 0x7a325381u, 0x28958677u, - 0x3b8f4898u, 0x6b4bb9afu, 0xc4bfe81bu, 0x66282193u, - 0x61d809ccu, 0xfb21a991u, 0x487cac60u, 0x5dec8032u, - 0xef845d5du, 0xe98575b1u, 0xdc262302u, 0xeb651b88u, - 0x23893e81u, 0xd396acc5u, 0x0f6d6ff3u, 0x83f44239u, - 0x2e0b4482u, 0xa4842004u, 0x69c8f04au, 0x9e1f9b5eu, - 0x21c66842u, 0xf6e96c9au, 0x670c9c61u, 0xabd388f0u, - 0x6a51a0d2u, 0xd8542f68u, 0x960fa728u, 0xab5133a3u, - 0x6eef0b6cu, 0x137a3be4u, 0xba3bf050u, 0x7efb2a98u, - 0xa1f1651du, 0x39af0176u, 0x66ca593eu, 0x82430e88u, - 0x8cee8619u, 0x456f9fb4u, 0x7d84a5c3u, 0x3b8b5ebeu, - 0xe06f75d8u, 0x85c12073u, 0x401a449fu, 0x56c16aa6u, - 0x4ed3aa62u, 0x363f7706u, 0x1bfedf72u, 0x429b023du, - 0x37d0d724u, 0xd00a1248u, 0xdb0fead3u, 0x49f1c09bu, - 0x075372c9u, 0x80991b7bu, 0x25d479d8u, 0xf6e8def7u, - 0xe3fe501au, 0xb6794c3bu, 0x976ce0bdu, 0x04c006bau, - 0xc1a94fb6u, 0x409f60c4u, 0x5e5c9ec2u, 0x196a2463u, - 0x68fb6fafu, 0x3e6c53b5u, 0x1339b2ebu, 0x3b52ec6fu, - 0x6dfc511fu, 0x9b30952cu, 0xcc814544u, 0xaf5ebd09u, - 0xbee3d004u, 0xde334afdu, 0x660f2807u, 0x192e4bb3u, - 0xc0cba857u, 0x45c8740fu, 0xd20b5f39u, 0xb9d3fbdbu, - 0x5579c0bdu, 0x1a60320au, 0xd6a100c6u, 0x402c7279u, - 0x679f25feu, 0xfb1fa3ccu, 0x8ea5e9f8u, 0xdb3222f8u, - 0x3c7516dfu, 0xfd616b15u, 0x2f501ec8u, 0xad0552abu, - 0x323db5fau, 0xfd238760u, 0x53317b48u, 0x3e00df82u, - 0x9e5c57bbu, 0xca6f8ca0u, 0x1a87562eu, 0xdf1769dbu, - 0xd542a8f6u, 0x287effc3u, 0xac6732c6u, 0x8c4f5573u, - 0x695b27b0u, 0xbbca58c8u, 0xe1ffa35du, 0xb8f011a0u, - 0x10fa3d98u, 0xfd2183b8u, 0x4afcb56cu, 0x2dd1d35bu, - 0x9a53e479u, 0xb6f84565u, 0xd28e49bcu, 0x4bfb9790u, - 0xe1ddf2dau, 0xa4cb7e33u, 0x62fb1341u, 0xcee4c6e8u, - 0xef20cadau, 0x36774c01u, 0xd07e9efeu, 0x2bf11fb4u, - 0x95dbda4du, 0xae909198u, 0xeaad8e71u, 0x6b93d5a0u, - 0xd08ed1d0u, 0xafc725e0u, 0x8e3c5b2fu, 0x8e7594b7u, - 0x8ff6e2fbu, 0xf2122b64u, 0x8888b812u, 0x900df01cu, - 0x4fad5ea0u, 0x688fc31cu, 0xd1cff191u, 0xb3a8c1adu, - 0x2f2f2218u, 0xbe0e1777u, 0xea752dfeu, 0x8b021fa1u, - 0xe5a0cc0fu, 0xb56f74e8u, 0x18acf3d6u, 0xce89e299u, - 0xb4a84fe0u, 0xfd13e0b7u, 0x7cc43b81u, 0xd2ada8d9u, - 0x165fa266u, 0x80957705u, 0x93cc7314u, 0x211a1477u, - 0xe6ad2065u, 0x77b5fa86u, 0xc75442f5u, 0xfb9d35cfu, - 0xebcdaf0cu, 0x7b3e89a0u, 0xd6411bd3u, 0xae1e7e49u, - 0x00250e2du, 0x2071b35eu, 0x226800bbu, 0x57b8e0afu, - 0x2464369bu, 0xf009b91eu, 0x5563911du, 0x59dfa6aau, - 0x78c14389u, 0xd95a537fu, 0x207d5ba2u, 0x02e5b9c5u, - 0x83260376u, 0x6295cfa9u, 0x11c81968u, 0x4e734a41u, - 0xb3472dcau, 0x7b14a94au, 0x1b510052u, 0x9a532915u, - 0xd60f573fu, 0xbc9bc6e4u, 0x2b60a476u, 0x81e67400u, - 0x08ba6fb5u, 0x571be91fu, 0xf296ec6bu, 0x2a0dd915u, - 0xb6636521u, 0xe7b9f9b6u, 0xff34052eu, 0xc5855664u, - 0x53b02d5du, 0xa99f8fa1u, 0x08ba4799u, 0x6e85076au}, - {0x4b7a70e9u, 0xb5b32944u, 0xdb75092eu, 0xc4192623u, - 0xad6ea6b0u, 0x49a7df7du, 0x9cee60b8u, 0x8fedb266u, - 0xecaa8c71u, 0x699a17ffu, 0x5664526cu, 0xc2b19ee1u, - 0x193602a5u, 0x75094c29u, 0xa0591340u, 0xe4183a3eu, - 0x3f54989au, 0x5b429d65u, 0x6b8fe4d6u, 0x99f73fd6u, - 0xa1d29c07u, 0xefe830f5u, 0x4d2d38e6u, 0xf0255dc1u, - 0x4cdd2086u, 0x8470eb26u, 0x6382e9c6u, 0x021ecc5eu, - 0x09686b3fu, 0x3ebaefc9u, 0x3c971814u, 0x6b6a70a1u, - 0x687f3584u, 0x52a0e286u, 0xb79c5305u, 0xaa500737u, - 0x3e07841cu, 0x7fdeae5cu, 0x8e7d44ecu, 0x5716f2b8u, - 0xb03ada37u, 0xf0500c0du, 0xf01c1f04u, 0x0200b3ffu, - 0xae0cf51au, 0x3cb574b2u, 0x25837a58u, 0xdc0921bdu, - 0xd19113f9u, 0x7ca92ff6u, 0x94324773u, 0x22f54701u, - 0x3ae5e581u, 0x37c2dadcu, 0xc8b57634u, 0x9af3dda7u, - 0xa9446146u, 0x0fd0030eu, 0xecc8c73eu, 0xa4751e41u, - 0xe238cd99u, 0x3bea0e2fu, 0x3280bba1u, 0x183eb331u, - 0x4e548b38u, 0x4f6db908u, 0x6f420d03u, 0xf60a04bfu, - 0x2cb81290u, 0x24977c79u, 0x5679b072u, 0xbcaf89afu, - 0xde9a771fu, 0xd9930810u, 0xb38bae12u, 0xdccf3f2eu, - 0x5512721fu, 0x2e6b7124u, 0x501adde6u, 0x9f84cd87u, - 0x7a584718u, 0x7408da17u, 0xbc9f9abcu, 0xe94b7d8cu, - 0xec7aec3au, 0xdb851dfau, 0x63094366u, 0xc464c3d2u, - 0xef1c1847u, 0x3215d908u, 0xdd433b37u, 0x24c2ba16u, - 0x12a14d43u, 0x2a65c451u, 0x50940002u, 0x133ae4ddu, - 0x71dff89eu, 0x10314e55u, 0x81ac77d6u, 0x5f11199bu, - 0x043556f1u, 0xd7a3c76bu, 0x3c11183bu, 0x5924a509u, - 0xf28fe6edu, 0x97f1fbfau, 0x9ebabf2cu, 0x1e153c6eu, - 0x86e34570u, 0xeae96fb1u, 0x860e5e0au, 0x5a3e2ab3u, - 0x771fe71cu, 0x4e3d06fau, 0x2965dcb9u, 0x99e71d0fu, - 0x803e89d6u, 0x5266c825u, 0x2e4cc978u, 0x9c10b36au, - 0xc6150ebau, 0x94e2ea78u, 0xa5fc3c53u, 0x1e0a2df4u, - 0xf2f74ea7u, 0x361d2b3du, 0x1939260fu, 0x19c27960u, - 0x5223a708u, 0xf71312b6u, 0xebadfe6eu, 0xeac31f66u, - 0xe3bc4595u, 0xa67bc883u, 0xb17f37d1u, 0x018cff28u, - 0xc332ddefu, 0xbe6c5aa5u, 0x65582185u, 0x68ab9802u, - 0xeecea50fu, 0xdb2f953bu, 0x2aef7dadu, 0x5b6e2f84u, - 0x1521b628u, 0x29076170u, 0xecdd4775u, 0x619f1510u, - 0x13cca830u, 0xeb61bd96u, 0x0334fe1eu, 0xaa0363cfu, - 0xb5735c90u, 0x4c70a239u, 0xd59e9e0bu, 0xcbaade14u, - 0xeecc86bcu, 0x60622ca7u, 0x9cab5cabu, 0xb2f3846eu, - 0x648b1eafu, 0x19bdf0cau, 0xa02369b9u, 0x655abb50u, - 0x40685a32u, 0x3c2ab4b3u, 0x319ee9d5u, 0xc021b8f7u, - 0x9b540b19u, 0x875fa099u, 0x95f7997eu, 0x623d7da8u, - 0xf837889au, 0x97e32d77u, 0x11ed935fu, 0x16681281u, - 0x0e358829u, 0xc7e61fd6u, 0x96dedfa1u, 0x7858ba99u, - 0x57f584a5u, 0x1b227263u, 0x9b83c3ffu, 0x1ac24696u, - 0xcdb30aebu, 0x532e3054u, 0x8fd948e4u, 0x6dbc3128u, - 0x58ebf2efu, 0x34c6ffeau, 0xfe28ed61u, 0xee7c3c73u, - 0x5d4a14d9u, 0xe864b7e3u, 0x42105d14u, 0x203e13e0u, - 0x45eee2b6u, 0xa3aaabeau, 0xdb6c4f15u, 0xfacb4fd0u, - 0xc742f442u, 0xef6abbb5u, 0x654f3b1du, 0x41cd2105u, - 0xd81e799eu, 0x86854dc7u, 0xe44b476au, 0x3d816250u, - 0xcf62a1f2u, 0x5b8d2646u, 0xfc8883a0u, 0xc1c7b6a3u, - 0x7f1524c3u, 0x69cb7492u, 0x47848a0bu, 0x5692b285u, - 0x095bbf00u, 0xad19489du, 0x1462b174u, 0x23820e00u, - 0x58428d2au, 0x0c55f5eau, 0x1dadf43eu, 0x233f7061u, - 0x3372f092u, 0x8d937e41u, 0xd65fecf1u, 0x6c223bdbu, - 0x7cde3759u, 0xcbee7460u, 0x4085f2a7u, 0xce77326eu, - 0xa6078084u, 0x19f8509eu, 0xe8efd855u, 0x61d99735u, - 0xa969a7aau, 0xc50c06c2u, 0x5a04abfcu, 0x800bcadcu, - 0x9e447a2eu, 0xc3453484u, 0xfdd56705u, 0x0e1e9ec9u, - 0xdb73dbd3u, 0x105588cdu, 0x675fda79u, 0xe3674340u, - 0xc5c43465u, 0x713e38d8u, 0x3d28f89eu, 0xf16dff20u, - 0x153e21e7u, 0x8fb03d4au, 0xe6e39f2bu, 0xdb83adf7u}, - {0xe93d5a68u, 0x948140f7u, 0xf64c261cu, 0x94692934u, - 0x411520f7u, 0x7602d4f7u, 0xbcf46b2eu, 0xd4a20068u, - 0xd4082471u, 0x3320f46au, 0x43b7d4b7u, 0x500061afu, - 0x1e39f62eu, 0x97244546u, 0x14214f74u, 0xbf8b8840u, - 0x4d95fc1du, 0x96b591afu, 0x70f4ddd3u, 0x66a02f45u, - 0xbfbc09ecu, 0x03bd9785u, 0x7fac6dd0u, 0x31cb8504u, - 0x96eb27b3u, 0x55fd3941u, 0xda2547e6u, 0xabca0a9au, - 0x28507825u, 0x530429f4u, 0x0a2c86dau, 0xe9b66dfbu, - 0x68dc1462u, 0xd7486900u, 0x680ec0a4u, 0x27a18deeu, - 0x4f3ffea2u, 0xe887ad8cu, 0xb58ce006u, 0x7af4d6b6u, - 0xaace1e7cu, 0xd3375fecu, 0xce78a399u, 0x406b2a42u, - 0x20fe9e35u, 0xd9f385b9u, 0xee39d7abu, 0x3b124e8bu, - 0x1dc9faf7u, 0x4b6d1856u, 0x26a36631u, 0xeae397b2u, - 0x3a6efa74u, 0xdd5b4332u, 0x6841e7f7u, 0xca7820fbu, - 0xfb0af54eu, 0xd8feb397u, 0x454056acu, 0xba489527u, - 0x55533a3au, 0x20838d87u, 0xfe6ba9b7u, 0xd096954bu, - 0x55a867bcu, 0xa1159a58u, 0xcca92963u, 0x99e1db33u, - 0xa62a4a56u, 0x3f3125f9u, 0x5ef47e1cu, 0x9029317cu, - 0xfdf8e802u, 0x04272f70u, 0x80bb155cu, 0x05282ce3u, - 0x95c11548u, 0xe4c66d22u, 0x48c1133fu, 0xc70f86dcu, - 0x07f9c9eeu, 0x41041f0fu, 0x404779a4u, 0x5d886e17u, - 0x325f51ebu, 0xd59bc0d1u, 0xf2bcc18fu, 0x41113564u, - 0x257b7834u, 0x602a9c60u, 0xdff8e8a3u, 0x1f636c1bu, - 0x0e12b4c2u, 0x02e1329eu, 0xaf664fd1u, 0xcad18115u, - 0x6b2395e0u, 0x333e92e1u, 0x3b240b62u, 0xeebeb922u, - 0x85b2a20eu, 0xe6ba0d99u, 0xde720c8cu, 0x2da2f728u, - 0xd0127845u, 0x95b794fdu, 0x647d0862u, 0xe7ccf5f0u, - 0x5449a36fu, 0x877d48fau, 0xc39dfd27u, 0xf33e8d1eu, - 0x0a476341u, 0x992eff74u, 0x3a6f6eabu, 0xf4f8fd37u, - 0xa812dc60u, 0xa1ebddf8u, 0x991be14cu, 0xdb6e6b0du, - 0xc67b5510u, 0x6d672c37u, 0x2765d43bu, 0xdcd0e804u, - 0xf1290dc7u, 0xcc00ffa3u, 0xb5390f92u, 0x690fed0bu, - 0x667b9ffbu, 0xcedb7d9cu, 0xa091cf0bu, 0xd9155ea3u, - 0xbb132f88u, 0x515bad24u, 0x7b9479bfu, 0x763bd6ebu, - 0x37392eb3u, 0xcc115979u, 0x8026e297u, 0xf42e312du, - 0x6842ada7u, 0xc66a2b3bu, 0x12754cccu, 0x782ef11cu, - 0x6a124237u, 0xb79251e7u, 0x06a1bbe6u, 0x4bfb6350u, - 0x1a6b1018u, 0x11caedfau, 0x3d25bdd8u, 0xe2e1c3c9u, - 0x44421659u, 0x0a121386u, 0xd90cec6eu, 0xd5abea2au, - 0x64af674eu, 0xda86a85fu, 0xbebfe988u, 0x64e4c3feu, - 0x9dbc8057u, 0xf0f7c086u, 0x60787bf8u, 0x6003604du, - 0xd1fd8346u, 0xf6381fb0u, 0x7745ae04u, 0xd736fcccu, - 0x83426b33u, 0xf01eab71u, 0xb0804187u, 0x3c005e5fu, - 0x77a057beu, 0xbde8ae24u, 0x55464299u, 0xbf582e61u, - 0x4e58f48fu, 0xf2ddfda2u, 0xf474ef38u, 0x8789bdc2u, - 0x5366f9c3u, 0xc8b38e74u, 0xb475f255u, 0x46fcd9b9u, - 0x7aeb2661u, 0x8b1ddf84u, 0x846a0e79u, 0x915f95e2u, - 0x466e598eu, 0x20b45770u, 0x8cd55591u, 0xc902de4cu, - 0xb90bace1u, 0xbb8205d0u, 0x11a86248u, 0x7574a99eu, - 0xb77f19b6u, 0xe0a9dc09u, 0x662d09a1u, 0xc4324633u, - 0xe85a1f02u, 0x09f0be8cu, 0x4a99a025u, 0x1d6efe10u, - 0x1ab93d1du, 0x0ba5a4dfu, 0xa186f20fu, 0x2868f169u, - 0xdcb7da83u, 0x573906feu, 0xa1e2ce9bu, 0x4fcd7f52u, - 0x50115e01u, 0xa70683fau, 0xa002b5c4u, 0x0de6d027u, - 0x9af88c27u, 0x773f8641u, 0xc3604c06u, 0x61a806b5u, - 0xf0177a28u, 0xc0f586e0u, 0x006058aau, 0x30dc7d62u, - 0x11e69ed7u, 0x2338ea63u, 0x53c2dd94u, 0xc2c21634u, - 0xbbcbee56u, 0x90bcb6deu, 0xebfc7da1u, 0xce591d76u, - 0x6f05e409u, 0x4b7c0188u, 0x39720a3du, 0x7c927c24u, - 0x86e3725fu, 0x724d9db9u, 0x1ac15bb4u, 0xd39eb8fcu, - 0xed545578u, 0x08fca5b5u, 0xd83d7cd3u, 0x4dad0fc4u, - 0x1e50ef5eu, 0xb161e6f8u, 0xa28514d9u, 0x6c51133cu, - 0x6fd5c7e7u, 0x56e14ec4u, 0x362abfceu, 0xddc6c837u, - 0xd79a3234u, 0x92638212u, 0x670efa8eu, 0x406000e0u}, - {0x3a39ce37u, 0xd3faf5cfu, 0xabc27737u, 0x5ac52d1bu, - 0x5cb0679eu, 0x4fa33742u, 0xd3822740u, 0x99bc9bbeu, - 0xd5118e9du, 0xbf0f7315u, 0xd62d1c7eu, 0xc700c47bu, - 0xb78c1b6bu, 0x21a19045u, 0xb26eb1beu, 0x6a366eb4u, - 0x5748ab2fu, 0xbc946e79u, 0xc6a376d2u, 0x6549c2c8u, - 0x530ff8eeu, 0x468dde7du, 0xd5730a1du, 0x4cd04dc6u, - 0x2939bbdbu, 0xa9ba4650u, 0xac9526e8u, 0xbe5ee304u, - 0xa1fad5f0u, 0x6a2d519au, 0x63ef8ce2u, 0x9a86ee22u, - 0xc089c2b8u, 0x43242ef6u, 0xa51e03aau, 0x9cf2d0a4u, - 0x83c061bau, 0x9be96a4du, 0x8fe51550u, 0xba645bd6u, - 0x2826a2f9u, 0xa73a3ae1u, 0x4ba99586u, 0xef5562e9u, - 0xc72fefd3u, 0xf752f7dau, 0x3f046f69u, 0x77fa0a59u, - 0x80e4a915u, 0x87b08601u, 0x9b09e6adu, 0x3b3ee593u, - 0xe990fd5au, 0x9e34d797u, 0x2cf0b7d9u, 0x022b8b51u, - 0x96d5ac3au, 0x017da67du, 0xd1cf3ed6u, 0x7c7d2d28u, - 0x1f9f25cfu, 0xadf2b89bu, 0x5ad6b472u, 0x5a88f54cu, - 0xe029ac71u, 0xe019a5e6u, 0x47b0acfdu, 0xed93fa9bu, - 0xe8d3c48du, 0x283b57ccu, 0xf8d56629u, 0x79132e28u, - 0x785f0191u, 0xed756055u, 0xf7960e44u, 0xe3d35e8cu, - 0x15056dd4u, 0x88f46dbau, 0x03a16125u, 0x0564f0bdu, - 0xc3eb9e15u, 0x3c9057a2u, 0x97271aecu, 0xa93a072au, - 0x1b3f6d9bu, 0x1e6321f5u, 0xf59c66fbu, 0x26dcf319u, - 0x7533d928u, 0xb155fdf5u, 0x03563482u, 0x8aba3cbbu, - 0x28517711u, 0xc20ad9f8u, 0xabcc5167u, 0xccad925fu, - 0x4de81751u, 0x3830dc8eu, 0x379d5862u, 0x9320f991u, - 0xea7a90c2u, 0xfb3e7bceu, 0x5121ce64u, 0x774fbe32u, - 0xa8b6e37eu, 0xc3293d46u, 0x48de5369u, 0x6413e680u, - 0xa2ae0810u, 0xdd6db224u, 0x69852dfdu, 0x09072166u, - 0xb39a460au, 0x6445c0ddu, 0x586cdecfu, 0x1c20c8aeu, - 0x5bbef7ddu, 0x1b588d40u, 0xccd2017fu, 0x6bb4e3bbu, - 0xdda26a7eu, 0x3a59ff45u, 0x3e350a44u, 0xbcb4cdd5u, - 0x72eacea8u, 0xfa6484bbu, 0x8d6612aeu, 0xbf3c6f47u, - 0xd29be463u, 0x542f5d9eu, 0xaec2771bu, 0xf64e6370u, - 0x740e0d8du, 0xe75b1357u, 0xf8721671u, 0xaf537d5du, - 0x4040cb08u, 0x4eb4e2ccu, 0x34d2466au, 0x0115af84u, - 0xe1b00428u, 0x95983a1du, 0x06b89fb4u, 0xce6ea048u, - 0x6f3f3b82u, 0x3520ab82u, 0x011a1d4bu, 0x277227f8u, - 0x611560b1u, 0xe7933fdcu, 0xbb3a792bu, 0x344525bdu, - 0xa08839e1u, 0x51ce794bu, 0x2f32c9b7u, 0xa01fbac9u, - 0xe01cc87eu, 0xbcc7d1f6u, 0xcf0111c3u, 0xa1e8aac7u, - 0x1a908749u, 0xd44fbd9au, 0xd0dadecbu, 0xd50ada38u, - 0x0339c32au, 0xc6913667u, 0x8df9317cu, 0xe0b12b4fu, - 0xf79e59b7u, 0x43f5bb3au, 0xf2d519ffu, 0x27d9459cu, - 0xbf97222cu, 0x15e6fc2au, 0x0f91fc71u, 0x9b941525u, - 0xfae59361u, 0xceb69cebu, 0xc2a86459u, 0x12baa8d1u, - 0xb6c1075eu, 0xe3056a0cu, 0x10d25065u, 0xcb03a442u, - 0xe0ec6e0eu, 0x1698db3bu, 0x4c98a0beu, 0x3278e964u, - 0x9f1f9532u, 0xe0d392dfu, 0xd3a0342bu, 0x8971f21eu, - 0x1b0a7441u, 0x4ba3348cu, 0xc5be7120u, 0xc37632d8u, - 0xdf359f8du, 0x9b992f2eu, 0xe60b6f47u, 0x0fe3f11du, - 0xe54cda54u, 0x1edad891u, 0xce6279cfu, 0xcd3e7e6fu, - 0x1618b166u, 0xfd2c1d05u, 0x848fd2c5u, 0xf6fb2299u, - 0xf523f357u, 0xa6327623u, 0x93a83531u, 0x56cccd02u, - 0xacf08162u, 0x5a75ebb5u, 0x6e163697u, 0x88d273ccu, - 0xde966292u, 0x81b949d0u, 0x4c50901bu, 0x71c65614u, - 0xe6c6c7bdu, 0x327a140au, 0x45e1d006u, 0xc3f27b9au, - 0xc9aa53fdu, 0x62a80f00u, 0xbb25bfe2u, 0x35bdd2f6u, - 0x71126905u, 0xb2040222u, 0xb6cbcf7cu, 0xcd769c2bu, - 0x53113ec0u, 0x1640e3d3u, 0x38abbd60u, 0x2547adf0u, - 0xba38209cu, 0xf746ce76u, 0x77afa1c5u, 0x20756060u, - 0x85cbfe4eu, 0x8ae88dd8u, 0x7aaaf9b0u, 0x4cf9aa7eu, - 0x1948c25cu, 0x02fb8a8cu, 0x01c36ae4u, 0xd6ebe1f9u, - 0x90d4f869u, 0xa65cdea0u, 0x3f09252du, 0xc208e69fu, - 0xb74e6132u, 0xce77e25bu, 0x578fdfe3u, 0x3ac372e6u} -}; - -#define F1(i) \ - xl ^= pax[i]; \ - xr ^= ((sbx[0][xl >> 24] + \ - sbx[1][(xl & 0xFF0000) >> 16]) ^ \ - sbx[2][(xl & 0xFF00) >> 8]) + \ - sbx[3][xl & 0xFF]; - -#define F2(i) \ - xr ^= pax[i]; \ - xl ^= ((sbx[0][xr >> 24] + \ - sbx[1][(xr & 0xFF0000) >> 16]) ^ \ - sbx[2][(xr & 0xFF00) >> 8]) + \ - sbx[3][xr & 0xFF]; - - -static void bf_e_block(uint32_t *p_xl, uint32_t *p_xr) -{ - uint32_t temp; - uint32_t xl = *p_xl; - uint32_t xr = *p_xr; - - F1(0) F2(1) F1(2) F2(3) F1(4) F2(5) F1(6) F2(7) - F1(8) F2(9) F1(10) F2(11) F1(12) F2(13) F1(14) F2(15) - xl ^= pax[16]; - xr ^= pax[17]; - temp = xl; - xl = xr; - xr = temp; - *p_xl = xl; - *p_xr = xr; -} - -#ifdef WORDS_BIGENDIAN -# define htonl2(x) \ - x = ((((x) & 0xffL) << 24) | (((x) & 0xff00L) << 8) | \ - (((x) & 0xff0000L) >> 8) | (((x) & 0xff000000L) >> 24)) -#else // ifdef WORDS_BIGENDIAN -# define htonl2(x) -#endif // ifdef WORDS_BIGENDIAN - -static void bf_e_cblock(char_u *block) -{ - block8 bk; - - memcpy(bk.uc, block, 8); - htonl2(bk.ul[0]); - htonl2(bk.ul[1]); - bf_e_block(&bk.ul[0], &bk.ul[1]); - htonl2(bk.ul[0]); - htonl2(bk.ul[1]); - memcpy(block, bk.uc, 8); -} - -// Initialize the crypt method using "password" as the encryption key and -// "salt[salt_len]" as the salt. -void bf_key_init(char_u *password, char_u *salt, int salt_len) -{ - // Process the key 1000 times. - // See http://en.wikipedia.org/wiki/Key_strengthening. - char_u *key = sha256_key(password, salt, salt_len); - - int i; - for (i = 0; i < 1000; i++) { - key = sha256_key(key, salt, salt_len); - } - - // Convert the key from 64 hex chars to 32 binary chars. - int keylen = (int)STRLEN(key) / 2; - - if (keylen == 0) { - EMSG(_("E831: bf_key_init() called with empty password")); - return; - } - - unsigned u; - for (i = 0; i < keylen; i++) { - sscanf((char *)&key[i * 2], "%2x", &u); - key[i] = u; - } - - memmove(sbx, sbi, 4 * 4 * 256); - - int keypos = 0; - for (i = 0; i < 18; i++) { - uint32_t val = 0; - - int j; - for (j = 0; j < 4; j++) { - val = (val << 8) | key[keypos++ % keylen]; - } - pax[i] = ipa[i] ^ val; - } - - uint32_t data_l = 0; - uint32_t data_r = 0; - for (i = 0; i < 18; i += 2) { - bf_e_block(&data_l, &data_r); - pax[i + 0] = data_l; - pax[i + 1] = data_r; - } - - for (i = 0; i < 4; i++) { - int j; - for (j = 0; j < 256; j += 2) { - bf_e_block(&data_l, &data_r); - sbx[i][j + 0] = data_l; - sbx[i][j + 1] = data_r; - } - } -} - -/// BF Self test for corrupted tables or instructions -static int bf_check_tables(uint32_t a_ipa[18], uint32_t a_sbi[4][256], - uint32_t val) -{ - uint32_t c = 0; - int i; - for (i = 0; i < 18; i++) { - c ^= a_ipa[i]; - } - - for (i = 0; i < 4; i++) { - int j; - for (j = 0; j < 256; j++) { - c ^= a_sbi[i][j]; - } - } - return c == val; -} - -typedef struct { - char_u password[64]; - char_u salt[9]; - char_u plaintxt[9]; - char_u cryptxt[9]; - char_u badcryptxt[9]; // cryptxt when big/little endian is wrong. - uint32_t keysum; -} struct_bf_test_data; - -// Assert bf(password, plaintxt) is cryptxt. -// Assert csum(pax sbx(password)) is keysum. -static struct_bf_test_data bf_test_data[] = { - { - "password", - "salt", - "plaintxt", - "\xad\x3d\xfa\x7f\xe8\xea\x40\xf6", // cryptxt - "\x72\x50\x3b\x38\x10\x60\x22\xa7", // badcryptxt - 0x56701b5du // keysum - }, -}; - -// Return FAIL when there is something wrong with blowfish encryption. -static int bf_self_test(void) -{ - int err = 0; - if (!bf_check_tables(ipa, sbi, 0x6ffa520a)) { - err++; - } - - int bn = ARRAY_LENGTH(bf_test_data); - int i; - for (i = 0; i < bn; i++) { - bf_key_init((char_u *)(bf_test_data[i].password), bf_test_data[i].salt, - (int)STRLEN(bf_test_data[i].salt)); - - if (!bf_check_tables(pax, sbx, bf_test_data[i].keysum)) { - err++; - } - - // Don't modify bf_test_data[i].plaintxt, self test is idempotent. - block8 bk; - memcpy(bk.uc, bf_test_data[i].plaintxt, 8); - bf_e_cblock(bk.uc); - - if (memcmp(bk.uc, bf_test_data[i].cryptxt, 8) != 0) { - if ((err == 0) && (memcmp(bk.uc, bf_test_data[i].badcryptxt, 8) == 0)) { - EMSG(_("E817: Blowfish big/little endian use wrong")); - } - err++; - } - } - - return err > 0 ? FAIL : OK; -} - -// Cipher feedback mode. -static int randbyte_offset = 0; -static int update_offset = 0; -static char_u cfb_buffer[BF_CFB_LEN]; // 64 bytes - -// Initialize with seed "iv[iv_len]". -void bf_cfb_init(char_u *iv, int iv_len) -{ - randbyte_offset = update_offset = 0; - memset(cfb_buffer, 0, BF_CFB_LEN); - - if (iv_len > 0) { - int mi = iv_len > BF_CFB_LEN ? iv_len : BF_CFB_LEN; - int i; - for (i = 0; i < mi; i++) { - cfb_buffer[i % BF_CFB_LEN] ^= iv[i % iv_len]; - } - } -} - -#define BF_CFB_UPDATE(c) \ - { \ - cfb_buffer[update_offset] ^= (char_u)c; \ - if (++update_offset == BF_CFB_LEN) { \ - update_offset = 0; \ - } \ - } - -#define BF_RANBYTE(t) \ - { \ - if ((randbyte_offset & BF_BLOCK_MASK) == 0) { \ - bf_e_cblock(&cfb_buffer[randbyte_offset]); \ - } \ - t = cfb_buffer[randbyte_offset]; \ - if (++randbyte_offset == BF_CFB_LEN) { \ - randbyte_offset = 0; \ - } \ - } - -// Encrypt "from[len]" into "to[len]". -// "from" and "to" can be equal to encrypt in place. -void bf_crypt_encode(char_u *from, size_t len, char_u *to) -{ - size_t i; - for (i = 0; i < len; i++) { - int ztemp = from[i]; - int t; - BF_RANBYTE(t); - BF_CFB_UPDATE(ztemp); - to[i] = t ^ ztemp; - } -} - -/* - * Decrypt "ptr[len]" in place. - */ -void bf_crypt_decode(char_u *ptr, long len) -{ - char_u *p; - for (p = ptr; p < ptr + len; p++) { - int t; - BF_RANBYTE(t); - *p ^= t; - BF_CFB_UPDATE(*p); - } -} - -/* - * Initialize the encryption keys and the random header according to - * the given password. - * in: "passwd" password string with which to modify keys - */ -void bf_crypt_init_keys(char_u *passwd) -{ - char_u *p; - for (p = passwd; *p != NUL; p++) { - BF_CFB_UPDATE(*p); - } -} - -static int save_randbyte_offset; -static int save_update_offset; -static char_u save_cfb_buffer[BF_CFB_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(void) -{ - save_randbyte_offset = randbyte_offset; - save_update_offset = update_offset; - memmove(save_cfb_buffer, cfb_buffer, BF_CFB_LEN); - memmove(save_pax, pax, 4 * 18); - memmove(save_sbx, sbx, 4 * 4 * 256); -} - -/* - * Restore the current crypt state. Can only be used after - * bf_crypt_save(). - */ -void bf_crypt_restore(void) -{ - randbyte_offset = save_randbyte_offset; - update_offset = save_update_offset; - memmove(cfb_buffer, save_cfb_buffer, BF_CFB_LEN); - memmove(pax, save_pax, 4 * 18); - 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. - */ -int blowfish_self_test(void) -{ - if (sha256_self_test() == FAIL) { - EMSG(_("E818: sha256 test failed")); - return FAIL; - } - if (bf_self_test() == FAIL) { - EMSG(_("E819: Blowfish test failed")); - return FAIL; - } - return OK; -} diff --git a/src/nvim/blowfish.h b/src/nvim/blowfish.h deleted file mode 100644 index 2d1d0ba1a0..0000000000 --- a/src/nvim/blowfish.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef NVIM_BLOWFISH_H -#define NVIM_BLOWFISH_H - -void bf_key_init(char_u *password, char_u *salt, int salt_len); -void bf_cfb_init(char_u *iv, int iv_len); -void bf_crypt_encode(char_u *from, size_t len, char_u *to); -void bf_crypt_decode(char_u *ptr, long len); -void bf_crypt_init_keys(char_u *passwd); -void bf_crypt_save(void); -void bf_crypt_restore(void); -int blowfish_self_test(void); - -#endif // NVIM_BLOWFISH_H diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 42b7826981..03dd972df1 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1489,9 +1489,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_inex); clear_string_option(&buf->b_p_inde); clear_string_option(&buf->b_p_indk); - clear_string_option(&buf->b_p_cm); clear_string_option(&buf->b_p_fex); - clear_string_option(&buf->b_p_key); clear_string_option(&buf->b_p_kp); clear_string_option(&buf->b_p_mps); clear_string_option(&buf->b_p_fo); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 383cefc8d7..d658da9502 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -582,7 +582,6 @@ struct file_buffer { char_u *b_p_indk; /* 'indentkeys' */ char_u *b_p_fex; /* 'formatexpr' */ long_u b_p_fex_flags; /* flags for 'formatexpr' */ - char_u *b_p_key; /* 'key' */ char_u *b_p_kp; /* 'keywordprg' */ int b_p_lisp; /* 'lisp' */ char_u *b_p_mps; /* 'matchpairs' */ @@ -674,8 +673,6 @@ struct file_buffer { dictitem_T b_bufvar; /* variable for "b:" Dictionary */ dict_T *b_vars; /* internal variables, local to buffer */ - char_u *b_p_cm; /* 'cryptmethod' */ - /* When a buffer is created, it starts without a swap file. b_may_swap is * then set to indicate that a swap file may be opened later. It is reset * if a swap file could not be opened. diff --git a/src/nvim/crypt.c b/src/nvim/crypt.c deleted file mode 100644 index 2eb699d84e..0000000000 --- a/src/nvim/crypt.c +++ /dev/null @@ -1,237 +0,0 @@ -// Optional encryption support. -// Mohsin Ahmed, mosh@sasi.com, 98-09-24 -// Based on zip/crypt sources. -// -// NOTE FOR USA: Since 2000 exporting this code from the USA is allowed to -// most countries. There are a few exceptions, but that still should not be a -// problem since this code was originally created in Europe and India. -// -// Blowfish addition originally made by Mohsin Ahmed, -// http://www.cs.albany.edu/~mosh 2010-03-14 -// Based on blowfish by Bruce Schneier (http://www.schneier.com/blowfish.html) -// and sha256 by Christophe Devine. - -#include "nvim/vim.h" -#include "nvim/misc2.h" -#include "nvim/blowfish.h" -#include "nvim/ex_getln.h" -#include "nvim/message.h" -#include "nvim/option.h" -#include "nvim/strings.h" - -static void make_crc_tab(void); - -static uint32_t crc_32_tab[256]; - -// Fills the CRC table. -static void make_crc_tab(void) -{ - uint32_t s; - uint32_t t; - uint32_t v; - static bool done = false; - - if (done) { - return; - } - - for (t = 0; t < 256; t++) { - v = t; - - for (s = 0; s < 8; s++) { - v = (v >> 1) ^ ((v & 1) * (uint32_t)0xedb88320L); - } - crc_32_tab[t] = v; - } - done = true; -} - -#define CRC32(c, b) (crc_32_tab[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8)) - -static uint32_t keys[3]; // keys defining the pseudo-random sequence - -// Returns the next byte in the pseudo-random sequence. -#define DECRYPT_BYTE_ZIP(t) { \ - uint16_t temp; \ - temp = (uint16_t)keys[2] | 2; \ - t = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); \ -} - -// Updates the encryption keys with the next byte of plain text. -#define UPDATE_KEYS_ZIP(c) { \ - keys[0] = CRC32(keys[0], (c)); \ - keys[1] += keys[0] & 0xff; \ - keys[1] = keys[1] * 134775813L + 1; \ - keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \ -} - -static int crypt_busy = 0; -static uint32_t saved_keys[3]; -static int saved_crypt_method; - -int crypt_method_from_string(char_u *s) -{ - return *s == 'b' ? 1 : 0; -} - -int get_crypt_method(buf_T *buf) -{ - return crypt_method_from_string(*buf->b_p_cm == NUL ? p_cm : buf->b_p_cm); -} - -void set_crypt_method(buf_T *buf, int method) -{ - free_string_option(buf->b_p_cm); - buf->b_p_cm = vim_strsave((char_u *)(method == 0 ? "zip" : "blowfish")); -} - -void crypt_push_state(void) -{ - if (crypt_busy == 1) { - // Save the state - if (use_crypt_method == 0) { - saved_keys[0] = keys[0]; - saved_keys[1] = keys[1]; - saved_keys[2] = keys[2]; - } else { - bf_crypt_save(); - } - saved_crypt_method = use_crypt_method; - } else if (crypt_busy > 1) { - EMSG2(_(e_intern2), "crypt_push_state()"); - } - crypt_busy++; -} - -void crypt_pop_state(void) -{ - crypt_busy--; - - if (crypt_busy == 1) { - use_crypt_method = saved_crypt_method; - - if (use_crypt_method == 0) { - keys[0] = saved_keys[0]; - keys[1] = saved_keys[1]; - keys[2] = saved_keys[2]; - } else { - bf_crypt_restore(); - } - } -} - -void crypt_encode(char_u *from, size_t len, char_u *to) -{ - size_t i; - int ztemp; - int t; - - if (use_crypt_method == 0) { - for (i = 0; i < len; i++) { - ztemp = from[i]; - DECRYPT_BYTE_ZIP(t); - UPDATE_KEYS_ZIP(ztemp); - to[i] = t ^ ztemp; - } - } else { - bf_crypt_encode(from, len, to); - } -} - -void crypt_decode(char_u *ptr, long len) -{ - char_u *p; - - if (use_crypt_method == 0) { - for (p = ptr; p < ptr + len; p++) { - uint16_t temp; - - temp = (uint16_t)keys[2] | 2; - temp = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); - UPDATE_KEYS_ZIP(*p ^= temp); - } - } else { - bf_crypt_decode(ptr, len); - } -} - -void crypt_init_keys(char_u *passwd) -{ - if ((passwd != NULL) && (*passwd != NUL)) { - if (use_crypt_method == 0) { - char_u *p; - - make_crc_tab(); - keys[0] = 305419896L; - keys[1] = 591751049L; - keys[2] = 878082192L; - - for (p = passwd; *p != NUL; p++) { - UPDATE_KEYS_ZIP((int)*p); - } - } else { - bf_crypt_init_keys(passwd); - } - } -} - -void free_crypt_key(char_u *key) -{ - char_u *p; - - if (key != NULL) { - for (p = key; *p != NUL; p++) { - *p = 0; - } - free(key); - } -} - -char_u *get_crypt_key(int store, int twice) -{ - char_u *p1; - char_u *p2 = NULL; - int round; - - for (round = 0;; round++) { - cmdline_star = TRUE; - cmdline_row = msg_row; - char_u *prompt = (round == 0) - ? (char_u *) _("Enter encryption key: ") - : (char_u *) _("Enter same key again: "); - p1 = getcmdline_prompt(NUL, prompt, 0, EXPAND_NOTHING, NULL); - cmdline_star = FALSE; - if (p1 == NULL) { - break; - } - - if (round == twice) { - if ((p2 != NULL) && (STRCMP(p1, p2) != 0)) { - MSG(_("Keys don't match!")); - free_crypt_key(p1); - free_crypt_key(p2); - p2 = NULL; - round = -1; // Do it again - continue; - } - - if (store) { - set_option_value((char_u *) "key", 0L, p1, OPT_LOCAL); - free_crypt_key(p1); - p1 = curbuf->b_p_key; - } - break; - } - p2 = p1; - } - - // Since the user typed this, no need to wait for return. - if (msg_didout) { - msg_putchar('\n'); - } - need_wait_return = FALSE; - msg_didout = FALSE; - - free_crypt_key(p2); - return p1; -} diff --git a/src/nvim/crypt.h b/src/nvim/crypt.h deleted file mode 100644 index 388443787d..0000000000 --- a/src/nvim/crypt.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef NVIM_CRYPT_H -#define NVIM_CRYPT_H - -/// Returns the crypt method string as a number. -/// -/// @param s Pointer to the crypt method string. -/// -/// @return An integer value of the crypt method: -/// 0 for "zip", the old method. Also for any non-valid value. -/// 1 for "blowfish". -int crypt_method_from_string(char_u *s); - -/// Returns the crypt method of the buffer "buf" as a number. -/// -/// @param buf Pointer to the buffer. -/// -/// @return An integer value of the crypt method: -/// 0 for "zip", the old method. Also for any non-valid value. -/// 1 for "blowfish". -int get_crypt_method(buf_T *buf); - -/// Sets the crypt method for buffer "buf" to "method" using the -/// int value as returned by crypt_method_from_string(). -/// -/// @param buf Pointer to the buffer. -/// @param method Crypt method. -void set_crypt_method(buf_T *buf, int method); - -/// Prepares for initializing the encryption. If already doing encryption, -/// then save the state. -/// -/// This function must always be called symmetrically with crypt_pop_state(). -void crypt_push_state(void); - -/// Ends encryption. If already doing encryption before crypt_push_state(), -/// then restore the saved state. -/// -/// This function must always be called symmetrically with crypt_push_state(). -void crypt_pop_state(void); - -/// Encrypts "from[len]" into "to[len]". -/// For in-place encryption, "from" and "len" must be the same. -/// -/// @param from Pointer to the source string. -/// @param len Length of the strings. -/// @param to Pointer to the destination string. -void crypt_encode(char_u *from, size_t len, char_u *to); - -/// Decrypts "ptr[len]" in-place. -/// -/// @param ptr Pointer to the string. -/// @param len Length of the string. -void crypt_decode(char_u *ptr, long len); - -/// Initializes the encryption keys and the random header according to -/// the given password. -/// -/// If "password" is NULL or empty, the function doesn't do anything. -/// -/// @param passwd The password string with which to modify keys. -void crypt_init_keys(char_u *passwd); - -/// Frees an allocated crypt key and clears the text to make sure -/// nothing stays in memory. -/// -/// @param key The crypt key to be freed. -void free_crypt_key(char_u *key); - -/// Asks the user for the crypt key. -/// -/// When "store" is TRUE, the new key is stored in the 'key' option -/// and the 'key' option value is returned, which MUST NOT be freed -/// manually, but using free_crypt_key(). -/// When "store" is FALSE, the typed key is returned in allocated memory. -/// -/// @param store Determines, whether the new crypt key is stored. -/// @param twice Ask for the key twice. -/// -/// @return The crypt key. On failure, NULL is returned. -char_u *get_crypt_key(int store, int twice); - -#endif // NVIM_CRYPT_H diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 86b8aaecba..6e0681420b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -713,7 +713,6 @@ static void f_setreg(typval_T *argvars, typval_T *rettv); static void f_settabvar(typval_T *argvars, typval_T *rettv); static void f_settabwinvar(typval_T *argvars, typval_T *rettv); static void f_setwinvar(typval_T *argvars, typval_T *rettv); -static void f_sha256(typval_T *argvars, typval_T *rettv); static void f_shellescape(typval_T *argvars, typval_T *rettv); static void f_shiftwidth(typval_T *argvars, typval_T *rettv); static void f_simplify(typval_T *argvars, typval_T *rettv); @@ -6994,7 +6993,6 @@ static struct fst { {"settabvar", 3, 3, f_settabvar}, {"settabwinvar", 4, 4, f_settabwinvar}, {"setwinvar", 3, 3, f_setwinvar}, - {"sha256", 1, 1, f_sha256}, {"shellescape", 1, 2, f_shellescape}, {"shiftwidth", 0, 0, f_shiftwidth}, {"simplify", 1, 1, f_simplify}, @@ -10204,7 +10202,6 @@ static void f_has(typval_T *argvars, typval_T *rettv) "cmdline_hist", "comments", "conceal", - "cryptv", "cscope", "cursorbind", "cursorshape", @@ -13660,19 +13657,6 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off) } /* - * "sha256({string})" function - */ -static void f_sha256(typval_T *argvars, typval_T *rettv) -{ - char_u *p; - - p = get_tv_string(&argvars[0]); - rettv->vval.v_string = vim_strsave( - sha256_bytes(p, (int)STRLEN(p), NULL, 0)); - rettv->v_type = VAR_STRING; -} - -/* * "shellescape({string})" function */ static void f_shellescape(typval_T *argvars, typval_T *rettv) diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index b6285db274..85cd4cd2fe 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -1084,8 +1084,6 @@ enum CMD_index EXTRA|RANGE|NOTADR|COUNT|BANG|EDITCMD|ARGOPT|TRLBAR), EX(CMD_Print, "Print", ex_print, RANGE|WHOLEFOLD|COUNT|EXFLAGS|TRLBAR|CMDWIN), - EX(CMD_X, "X", ex_X, - TRLBAR), EX(CMD_tilde, "~", do_sub, RANGE|WHOLEFOLD|EXTRA|CMDWIN|MODIFY), diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 368d5c9b0c..7007cd3e22 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -14,7 +14,6 @@ #include "nvim/vim.h" #include "nvim/ex_docmd.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" @@ -40,7 +39,6 @@ #include "nvim/misc1.h" #include "nvim/misc2.h" #include "nvim/keymap.h" -#include "nvim/crypt.h" #include "nvim/file_search.h" #include "nvim/garray.h" #include "nvim/move.h" @@ -224,7 +222,6 @@ static void ex_digraphs(exarg_T *eap); static void ex_set(exarg_T *eap); static void ex_nohlsearch(exarg_T *eap); static void ex_match(exarg_T *eap); -static void ex_X(exarg_T *eap); static void ex_fold(exarg_T *eap); static void ex_foldopen(exarg_T *eap); static void ex_folddo(exarg_T *eap); @@ -9074,15 +9071,6 @@ static void ex_match(exarg_T *eap) eap->nextcmd = find_nextcmd(end); } -/* - * ":X": Get crypt key - */ -static void ex_X(exarg_T *eap) -{ - if (get_crypt_method(curbuf) == 0 || blowfish_self_test() == OK) - (void)get_crypt_key(TRUE, TRUE); -} - static void ex_fold(exarg_T *eap) { if (foldManualAllowed(TRUE)) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 4112c5288d..214b38dea7 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -14,7 +14,6 @@ #include "nvim/vim.h" #include "nvim/fileio.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" @@ -33,7 +32,6 @@ #include "nvim/message.h" #include "nvim/misc1.h" #include "nvim/misc2.h" -#include "nvim/crypt.h" #include "nvim/garray.h" #include "nvim/move.h" #include "nvim/normal.h" @@ -52,7 +50,6 @@ #include "nvim/window.h" #include "nvim/os/os.h" - #if defined(HAVE_UTIME) && defined(HAVE_UTIME_H) # include <utime.h> /* for struct utimbuf */ #endif @@ -60,27 +57,10 @@ #define BUFSIZE 8192 /* size of normal write buffer */ #define SMBUFSIZE 256 /* size of emergency write buffer */ -/* crypt_magic[0] is pkzip crypt, crypt_magic[1] is sha2+blowfish */ -static char *crypt_magic[] = {"VimCrypt~01!", "VimCrypt~02!"}; -static char crypt_magic_head[] = "VimCrypt~"; -# define CRYPT_MAGIC_LEN 12 /* must be multiple of 4! */ - -/* For blowfish, after the magic header, we store 8 bytes of salt and then 8 - * bytes of seed (initialisation vector). */ -static int crypt_salt_len[] = {0, 8}; -static int crypt_seed_len[] = {0, 8}; -#define CRYPT_SALT_LEN_MAX 8 -#define CRYPT_SEED_LEN_MAX 8 - static char_u *next_fenc(char_u **pp); static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp); static void check_marks_read(void); -static int crypt_method_from_magic(char *ptr, int len); -static char_u *check_for_cryptkey(char_u *cryptkey, char_u *ptr, - long *sizep, off_t *filesizep, - int newfile, char_u *fname, - int *did_ask); #ifdef UNIX static void set_file_time(char_u *fname, time_t atime, time_t mtime); #endif @@ -105,7 +85,6 @@ static int au_find_group(char_u *name); # define FIO_UCS4 0x08 /* convert UCS-4 */ # define FIO_UTF16 0x10 /* convert UTF-16 */ # define FIO_ENDIAN_L 0x80 /* little endian */ -# define FIO_ENCRYPTED 0x1000 /* encrypt written bytes */ # define FIO_NOCONVERT 0x2000 /* skip encoding conversion */ # define FIO_UCSBOM 0x4000 /* check for BOM at start of file */ # define FIO_ALL -1 /* allow all formats */ @@ -245,9 +224,6 @@ readfile ( char_u *p; off_t filesize = 0; int skip_read = FALSE; - char_u *cryptkey = NULL; - int did_ask_for_key = FALSE; - int crypt_method_used; context_sha256_T sha_ctx; int read_undo_file = FALSE; int split = 0; /* number of split lines */ @@ -812,11 +788,6 @@ retry: conv_error = 0; } - if (cryptkey != NULL) - /* Need to reset the state, but keep the key, don't want to ask for it - * again. */ - crypt_pop_state(); - /* * When retrying with another "fenc" and the first time "fileformat" * will be reset. @@ -1147,34 +1118,17 @@ retry: } } } - - /* - * At start of file: Check for magic number of encryption. - */ - if (filesize == 0) - cryptkey = check_for_cryptkey(cryptkey, ptr, &size, - &filesize, newfile, sfname, - &did_ask_for_key); - /* - * Decrypt the read bytes. - */ - if (cryptkey != NULL && size > 0) - crypt_decode(ptr, size); } + skip_read = FALSE; /* - * At start of file (or after crypt magic number): Check for BOM. + * At start of file: Check for BOM. * Also check for a BOM for other Unicode encodings, but not after * converting with 'charconvert' or when a BOM has already been * found. */ - if ((filesize == 0 - || (filesize == (CRYPT_MAGIC_LEN - + crypt_salt_len[use_crypt_method] - + crypt_seed_len[use_crypt_method]) - && cryptkey != NULL) - ) + if ((filesize == 0) && (fio_flags == FIO_UCSBOM || (!curbuf->b_p_bomb && tmpname == NULL @@ -1734,15 +1688,6 @@ failed: if (set_options) save_file_ff(curbuf); /* remember the current file format */ - crypt_method_used = use_crypt_method; - if (cryptkey != NULL) { - crypt_pop_state(); - if (cryptkey != curbuf->b_p_key) - free_crypt_key(cryptkey); - /* don't set cryptkey to NULL, it's used below as a flag that - * encryption was used */ - } - /* If editing a new file: set 'fenc' for the current buffer. * Also for ":read ++edit file". */ if (set_options) @@ -1881,13 +1826,6 @@ failed: STRCAT(IObuff, _("[converted]")); c = TRUE; } - if (cryptkey != NULL) { - if (crypt_method_used == 1) - STRCAT(IObuff, _("[blowfish]")); - else - STRCAT(IObuff, _("[crypted]")); - c = TRUE; - } if (conv_error != 0) { sprintf((char *)IObuff + STRLEN(IObuff), _("[CONVERSION ERROR in line %" PRId64 "]"), (int64_t)conv_error); @@ -1902,12 +1840,6 @@ failed: } if (msg_add_fileformat(fileformat)) c = TRUE; - if (cryptkey != NULL) - msg_add_lines(c, (long)linecnt, filesize - - CRYPT_MAGIC_LEN - - crypt_salt_len[use_crypt_method] - - crypt_seed_len[use_crypt_method]); - else msg_add_lines(c, (long)linecnt, filesize); free(keep_msg); @@ -2217,178 +2149,6 @@ static void check_marks_read(void) curbuf->b_marks_read = TRUE; } -/* - * Get the crypt method used for a file from "ptr[len]", the magic text at the - * start of the file. - * Returns -1 when no encryption used. - */ -static int crypt_method_from_magic(char *ptr, int len) -{ - int i; - - for (i = 0; i < (int)(sizeof(crypt_magic) / sizeof(crypt_magic[0])); i++) { - if (len < (CRYPT_MAGIC_LEN + crypt_salt_len[i] + crypt_seed_len[i])) - continue; - if (memcmp(ptr, crypt_magic[i], CRYPT_MAGIC_LEN) == 0) - return i; - } - - i = (int)STRLEN(crypt_magic_head); - if (len >= i && memcmp(ptr, crypt_magic_head, i) == 0) - EMSG(_("E821: File is encrypted with unknown method")); - - return -1; -} - -/* - * Check for magic number used for encryption. Applies to the current buffer. - * If found, the magic number is removed from ptr[*sizep] and *sizep and - * *filesizep are updated. - * Return the (new) encryption key, NULL for no encryption. - */ -static char_u * -check_for_cryptkey ( - char_u *cryptkey, /* previous encryption key or NULL */ - char_u *ptr, /* pointer to read bytes */ - long *sizep, /* length of read bytes */ - off_t *filesizep, /* nr of bytes used from file */ - int newfile, /* editing a new buffer */ - char_u *fname, /* file name to display */ - int *did_ask /* flag: whether already asked for key */ -) -{ - int method = crypt_method_from_magic((char *)ptr, *sizep); - int b_p_ro = curbuf->b_p_ro; - - if (method >= 0) { - /* Mark the buffer as read-only until the decryption has taken place. - * Avoids accidentally overwriting the file with garbage. */ - curbuf->b_p_ro = TRUE; - - set_crypt_method(curbuf, method); - if (method > 0) - (void)blowfish_self_test(); - if (cryptkey == NULL && !*did_ask) { - if (*curbuf->b_p_key) - cryptkey = curbuf->b_p_key; - else { - /* When newfile is TRUE, store the typed key in the 'key' - * option and don't free it. bf needs hash of the key saved. - * Don't ask for the key again when first time Enter was hit. - * Happens when retrying to detect encoding. */ - smsg((char_u *)_(need_key_msg), fname); - msg_scroll = TRUE; - cryptkey = get_crypt_key(newfile, FALSE); - *did_ask = TRUE; - - /* check if empty key entered */ - if (cryptkey != NULL && *cryptkey == NUL) { - if (cryptkey != curbuf->b_p_key) - free(cryptkey); - cryptkey = NULL; - } - } - } - - if (cryptkey != NULL) { - int seed_len = crypt_seed_len[method]; - int salt_len = crypt_salt_len[method]; - - crypt_push_state(); - use_crypt_method = method; - if (method == 0) - crypt_init_keys(cryptkey); - else { - bf_key_init(cryptkey, ptr + CRYPT_MAGIC_LEN, salt_len); - bf_cfb_init(ptr + CRYPT_MAGIC_LEN + salt_len, seed_len); - } - - /* Remove magic number from the text */ - *filesizep += CRYPT_MAGIC_LEN + salt_len + seed_len; - *sizep -= CRYPT_MAGIC_LEN + salt_len + seed_len; - memmove(ptr, ptr + CRYPT_MAGIC_LEN + salt_len + seed_len, - (size_t)*sizep); - /* Restore the read-only flag. */ - curbuf->b_p_ro = b_p_ro; - } - } - /* When starting to edit a new file which does not have encryption, clear - * the 'key' option, except when starting up (called with -x argument) */ - else if (newfile && *curbuf->b_p_key != NUL && !starting) - set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); - - return cryptkey; -} - -/* - * Check for magic number used for encryption. Applies to the current buffer. - * If found and decryption is possible returns OK; - */ -int prepare_crypt_read(FILE *fp) -{ - int method; - char_u buffer[CRYPT_MAGIC_LEN + CRYPT_SALT_LEN_MAX - + CRYPT_SEED_LEN_MAX + 2]; - - if (fread(buffer, CRYPT_MAGIC_LEN, 1, fp) != 1) - return FAIL; - method = crypt_method_from_magic((char *)buffer, - CRYPT_MAGIC_LEN + - CRYPT_SEED_LEN_MAX + - CRYPT_SALT_LEN_MAX); - if (method < 0 || method != get_crypt_method(curbuf)) - return FAIL; - - crypt_push_state(); - if (method == 0) - crypt_init_keys(curbuf->b_p_key); - else { - int salt_len = crypt_salt_len[method]; - int seed_len = crypt_seed_len[method]; - - if (fread(buffer, salt_len + seed_len, 1, fp) != 1) - return FAIL; - bf_key_init(curbuf->b_p_key, buffer, salt_len); - bf_cfb_init(buffer + salt_len, seed_len); - } - return OK; -} - -/* - * Prepare for writing encrypted bytes for buffer "buf". - * Returns a pointer to an allocated header of length "*lenp". - * When out of memory returns NULL. - * Otherwise calls crypt_push_state(), call crypt_pop_state() later. - */ -char_u *prepare_crypt_write(buf_T *buf, int *lenp) -{ - char_u *header = xcalloc(1, CRYPT_MAGIC_LEN + CRYPT_SALT_LEN_MAX - + CRYPT_SEED_LEN_MAX + 2); - int seed_len = crypt_seed_len[get_crypt_method(buf)]; - int salt_len = crypt_salt_len[get_crypt_method(buf)]; - char_u *salt; - char_u *seed; - - crypt_push_state(); - use_crypt_method = get_crypt_method(buf); /* select zip or blowfish */ - vim_strncpy(header, (char_u *)crypt_magic[use_crypt_method], - CRYPT_MAGIC_LEN); - if (use_crypt_method == 0) - crypt_init_keys(buf->b_p_key); - else { - /* Using blowfish, add salt and seed. */ - salt = header + CRYPT_MAGIC_LEN; - seed = salt + salt_len; - sha2_seed(salt, salt_len, seed, seed_len); - bf_key_init(buf->b_p_key, salt, salt_len); - bf_cfb_init(seed, seed_len); - } - - *lenp = CRYPT_MAGIC_LEN + salt_len + seed_len; - return header; -} - - #ifdef UNIX static void set_file_time ( @@ -2501,7 +2261,6 @@ buf_write ( #endif int write_undo_file = FALSE; context_sha256_T sha_ctx; - int crypt_method_used; if (fname == NULL || *fname == NUL) /* safety check */ return FAIL; @@ -3477,28 +3236,6 @@ restore_backup: write_info.bw_fd = fd; - - if (*buf->b_p_key != NUL && !filtering) { - char_u *header; - int header_len; - - header = prepare_crypt_write(buf, &header_len); - if (header == NULL) - end = 0; - else { - /* Write magic number, so that Vim knows that this file is - * encrypted when reading it again. This also undergoes utf-8 to - * ucs-2/4 conversion when needed. */ - write_info.bw_buf = header; - write_info.bw_len = header_len; - write_info.bw_flags = FIO_NOCONVERT; - if (buf_write_bytes(&write_info) == FAIL) - end = 0; - wb_flags |= FIO_ENCRYPTED; - free(header); - } - } - write_info.bw_buf = buffer; nchars = 0; @@ -3509,14 +3246,13 @@ restore_backup: write_bin = buf->b_p_bin; /* - * The BOM is written just after the encryption magic number. - * Skip it when appending and the file already existed, the BOM only makes - * sense at the start of the file. + * Skip the BOM when appending and the file already existed, the BOM + * only makes sense at the start of the file. */ if (buf->b_p_bomb && !write_bin && (!append || perm < 0)) { write_info.bw_len = make_bom(buffer, fenc); if (write_info.bw_len > 0) { - /* don't convert, do encryption */ + /* don't convert */ write_info.bw_flags = FIO_NOCONVERT | wb_flags; if (buf_write_bytes(&write_info) == FAIL) end = 0; @@ -3677,10 +3413,6 @@ restore_backup: if (!backup_copy) mch_set_acl(wfname, acl); #endif - crypt_method_used = use_crypt_method; - if (wb_flags & FIO_ENCRYPTED) - crypt_pop_state(); - if (wfname != fname) { /* @@ -3799,13 +3531,6 @@ restore_backup: /* may add [unix/dos/mac] */ if (msg_add_fileformat(fileformat)) c = TRUE; - if (wb_flags & FIO_ENCRYPTED) { - if (crypt_method_used == 1) - STRCAT(IObuff, _("[blowfish]")); - else - STRCAT(IObuff, _("[crypted]")); - c = TRUE; - } msg_add_lines(c, (long)lnum, nchars); /* add line/char count */ if (!shortmess(SHM_WRITE)) { if (append) @@ -4163,7 +3888,7 @@ static int time_differs(long t1, long t2) /* * Call write() to write a number of bytes to the file. - * Handles encryption and 'encoding' conversion. + * Handles 'encoding' conversion. * * Return FAIL for failure, OK otherwise. */ @@ -4177,7 +3902,7 @@ static int buf_write_bytes(struct bw_info *ip) #endif /* - * Skip conversion when writing the crypt magic number or the BOM. + * Skip conversion when writing the BOM. */ if (!(flags & FIO_NOCONVERT)) { char_u *p; @@ -4366,9 +4091,6 @@ static int buf_write_bytes(struct bw_info *ip) # endif } - if (flags & FIO_ENCRYPTED) /* encrypt the data */ - crypt_encode(buf, len, buf); - wlen = write_eintr(ip->bw_fd, buf, len); return (wlen < len) ? FAIL : OK; } diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h index a69f3a287e..2d61c21fb5 100644 --- a/src/nvim/fileio.h +++ b/src/nvim/fileio.h @@ -25,8 +25,6 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, void prep_exarg(exarg_T *eap, buf_T *buf); void set_file_options(int set_options, exarg_T *eap); void set_forced_fenc(exarg_T *eap); -int prepare_crypt_read(FILE *fp); -char_u *prepare_crypt_write(buf_T *buf, int *lenp); int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, diff --git a/src/nvim/globals.h b/src/nvim/globals.h index a2efb961cd..869972e3b4 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -103,8 +103,6 @@ EXTERN int exec_from_reg INIT(= FALSE); /* executing register */ EXTERN int screen_cleared INIT(= FALSE); /* screen has been cleared */ -EXTERN int use_crypt_method INIT(= 0); - /* * When '$' is included in 'cpoptions' option set: * When a change command is given that deletes only part of a line, a dollar @@ -1116,8 +1114,6 @@ EXTERN char_u e_invalidreg[] INIT(= N_("E850: Invalid register name")); EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM")); EXTERN char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP")); -EXTERN char need_key_msg[] INIT(= N_("Need encryption key for \"%s\"")); - /* For undo we need to know the lowest time possible. */ EXTERN time_t starttime; diff --git a/src/nvim/main.c b/src/nvim/main.c index 16a155fa20..8d7fbe0a02 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -12,7 +12,6 @@ #include "nvim/vim.h" #include "nvim/main.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" @@ -31,7 +30,6 @@ #include "nvim/message.h" #include "nvim/misc1.h" #include "nvim/misc2.h" -#include "nvim/crypt.h" #include "nvim/garray.h" #include "nvim/log.h" #include "nvim/memory.h" @@ -82,7 +80,6 @@ typedef struct { int want_full_screen; bool stdout_isatty; /* is stdout a terminal? */ char_u *term; /* specified terminal name */ - int ask_for_key; /* -x argument */ int no_swap_file; /* "-n" argument used */ int use_debug_break_level; int window_count; /* number of windows to use */ @@ -454,12 +451,6 @@ static char *(main_errors[]) = TIME_MSG("clearing screen"); } - if (params.ask_for_key) { - (void)blowfish_self_test(); - (void)get_crypt_key(TRUE, TRUE); - TIME_MSG("getting crypt key"); - } - no_wait_return = TRUE; /* @@ -1250,10 +1241,6 @@ static void command_line_scan(mparm_T *parmp) want_argument = TRUE; break; - case 'x': /* "-x" encrypted reading/writing of files */ - parmp->ask_for_key = TRUE; - break; - case 'X': /* "-X" don't connect to X server */ break; @@ -2250,7 +2237,6 @@ static void usage(void) main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>")); main_msg(_("-w <scriptout>\tAppend all typed commands to file <scriptout>")); main_msg(_("-W <scriptout>\tWrite all typed commands to file <scriptout>")); - main_msg(_("-x\t\t\tEdit encrypted files")); #ifdef STARTUPTIME main_msg(_("--startuptime <file>\tWrite startup timing messages to <file>")); #endif diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 77468bb855..bf40d27502 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -132,7 +132,6 @@ memfile_T *mf_open(char_u *fname, int flags) mf_hash_init(&mfp->mf_hash); mf_hash_init(&mfp->mf_trans); mfp->mf_page_size = MEMFILE_PAGE_SIZE; - mfp->mf_old_key = NULL; /* * Try to set the page size equal to the block size of the device. @@ -814,10 +813,6 @@ static int mf_read(memfile_T *mfp, bhdr_T *hp) return FAIL; } - /* Decrypt if 'key' is set and this is a data block. */ - if (*mfp->mf_buffer->b_p_key != NUL) - ml_decrypt_data(mfp, hp->bh_data, offset, size); - return OK; } @@ -894,7 +889,6 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp) /* * Write block "hp" with data size "size" to file "mfp->mf_fd". - * Takes care of encryption. * Return FAIL or OK. */ static int mf_write_block(memfile_T *mfp, bhdr_T *hp, off_t offset, unsigned size) @@ -902,17 +896,9 @@ static int mf_write_block(memfile_T *mfp, bhdr_T *hp, off_t offset, unsigned siz char_u *data = hp->bh_data; int result = OK; - /* Encrypt if 'key' is set and this is a data block. */ - if (*mfp->mf_buffer->b_p_key != NUL) { - data = ml_encrypt_data(mfp, data, offset, size); - } - if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) result = FAIL; - if (data != hp->bh_data) - free(data); - return result; } diff --git a/src/nvim/memfile_defs.h b/src/nvim/memfile_defs.h index 5a37103f62..818246d6db 100644 --- a/src/nvim/memfile_defs.h +++ b/src/nvim/memfile_defs.h @@ -75,8 +75,6 @@ struct nr_trans { blocknr_T nt_new_bnum; /* new, positive, number */ }; -#define MF_SEED_LEN 8 - struct memfile { char_u *mf_fname; /* name of the file */ char_u *mf_ffname; /* idem, full path */ @@ -94,14 +92,6 @@ struct memfile { blocknr_T mf_infile_count; /* number of pages in the file */ unsigned mf_page_size; /* number of bytes in a page */ int mf_dirty; /* TRUE if there are dirty blocks */ - buf_T *mf_buffer; /* bufer this memfile is for */ - char_u mf_seed[MF_SEED_LEN]; /* seed for encryption */ - - /* Values for key, method and seed used for reading data blocks when - * updating for a newly set key or method. Only when mf_old_key != NULL. */ - char_u *mf_old_key; - int mf_old_cm; - char_u mf_old_seed[MF_SEED_LEN]; }; #endif // NVIM_MEMFILE_DEFS_H diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 28f3f2a9cc..8d0bd9a6d0 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -45,7 +45,6 @@ #include "nvim/vim.h" #include "nvim/memline.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/eval.h" #include "nvim/fileio.h" @@ -57,7 +56,6 @@ #include "nvim/message.h" #include "nvim/misc1.h" #include "nvim/misc2.h" -#include "nvim/crypt.h" #include "nvim/option.h" #include "nvim/os_unix.h" #include "nvim/path.h" @@ -199,12 +197,6 @@ struct block0 { */ #define b0_flags b0_fname[B0_FNAME_SIZE_ORG - 2] -/* - * Crypt seed goes here, 8 bytes. New in Vim 7.3. - * Without encryption these bytes may be used for 'fenc'. - */ -#define b0_seed b0_fname[B0_FNAME_SIZE_ORG - 2 - MF_SEED_LEN] - /* The lowest two bits contain the fileformat. Zero means it's not set * (compatible with Vim 6.x), otherwise it's EOL_UNIX + 1, EOL_DOS + 1 or * EOL_MAC + 1. */ @@ -241,10 +233,8 @@ static linenr_T lowest_marked = 0; typedef enum { UB_FNAME = 0 /* update timestamp and filename */ , UB_SAME_DIR /* update the B0_SAME_DIR flag */ - , UB_CRYPT /* update crypt key */ } upd_block0_T; -static void ml_set_b0_crypt(buf_T *buf, ZERO_BL *b0p); static int ml_check_b0_id(ZERO_BL *b0p); static void ml_upd_block0(buf_T *buf, upd_block0_T what); static void set_b0_fname(ZERO_BL *, buf_T *buf); @@ -270,7 +260,6 @@ static long char_to_long(char_u *); #if defined(UNIX) || defined(WIN3264) static char_u *make_percent_swname(char_u *dir, char_u *name); #endif -static void ml_crypt_prepare(memfile_T *mfp, off_t offset, int reading); static void ml_updatechunk(buf_T *buf, long line, long len, int updtype); /* @@ -316,7 +305,6 @@ int ml_open(buf_T *buf) goto error; buf->b_ml.ml_mfp = mfp; - mfp->mf_buffer = buf; buf->b_ml.ml_flags = ML_EMPTY; buf->b_ml.ml_line_count = 1; curwin->w_nrwidth_line_count = 0; @@ -352,8 +340,6 @@ int ml_open(buf_T *buf) os_get_hostname((char *)b0p->b0_hname, B0_HNAME_SIZE); b0p->b0_hname[B0_HNAME_SIZE - 1] = NUL; long_to_char(os_get_pid(), b0p->b0_pid); - if (*buf->b_p_key != NUL) - ml_set_b0_crypt(buf, b0p); } /* @@ -413,141 +399,6 @@ error: } /* - * Prepare encryption for "buf" with block 0 "b0p". - */ -static void ml_set_b0_crypt(buf_T *buf, ZERO_BL *b0p) -{ - if (*buf->b_p_key == NUL) - b0p->b0_id[1] = BLOCK0_ID1; - else { - if (get_crypt_method(buf) == 0) - b0p->b0_id[1] = BLOCK0_ID1_C0; - else { - b0p->b0_id[1] = BLOCK0_ID1_C1; - /* Generate a seed and store it in block 0 and in the memfile. */ - sha2_seed(&b0p->b0_seed, MF_SEED_LEN, NULL, 0); - memmove(buf->b_ml.ml_mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN); - } - } -} - -/* - * Called after the crypt key or 'cryptmethod' was changed for "buf". - * Will apply this to the swapfile. - * "old_key" is the previous key. It is equal to buf->b_p_key when - * 'cryptmethod' is changed. - * "old_cm" is the previous 'cryptmethod'. It is equal to the current - * 'cryptmethod' when 'key' is changed. - */ -void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm) -{ - memfile_T *mfp = buf->b_ml.ml_mfp; - bhdr_T *hp; - int page_count; - int idx; - long error; - infoptr_T *ip; - PTR_BL *pp; - DATA_BL *dp; - blocknr_T bnum; - int top; - - if (mfp == NULL) - return; /* no memfile yet, nothing to do */ - - /* Set the key, method and seed to be used for reading, these must be the - * old values. */ - mfp->mf_old_key = old_key; - mfp->mf_old_cm = old_cm; - if (old_cm > 0) - memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN); - - /* Update block 0 with the crypt flag and may set a new seed. */ - ml_upd_block0(buf, UB_CRYPT); - - if (mfp->mf_infile_count > 2) { - /* - * Need to read back all data blocks from disk, decrypt them with the - * old key/method and mark them to be written. The algorithm is - * similar to what happens in ml_recover(), but we skip negative block - * numbers. - */ - ml_flush_line(buf); /* flush buffered line */ - (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ - - hp = NULL; - bnum = 1; /* start with block 1 */ - page_count = 1; /* which is 1 page */ - idx = 0; /* start with first index in block 1 */ - error = 0; - buf->b_ml.ml_stack_top = 0; - free(buf->b_ml.ml_stack); - buf->b_ml.ml_stack = NULL; - buf->b_ml.ml_stack_size = 0; /* no stack yet */ - - for (; !got_int; line_breakcheck()) { - if (hp != NULL) - mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ - - /* get the block (pointer or data) */ - if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL) { - if (bnum == 1) - break; - ++error; - } else { - pp = (PTR_BL *)(hp->bh_data); - if (pp->pb_id == PTR_ID) { /* it is a pointer block */ - if (pp->pb_count == 0) { - /* empty block? */ - ++error; - } else if (idx < (int)pp->pb_count) { /* go a block deeper */ - if (pp->pb_pointer[idx].pe_bnum < 0) { - /* Skip data block with negative block number. */ - ++idx; /* get same block again for next index */ - continue; - } - - /* going one block deeper in the tree, new entry in - * stack */ - top = ml_add_stack(buf); - ip = &(buf->b_ml.ml_stack[top]); - ip->ip_bnum = bnum; - ip->ip_index = idx; - - bnum = pp->pb_pointer[idx].pe_bnum; - page_count = pp->pb_pointer[idx].pe_page_count; - continue; - } - } else { /* not a pointer block */ - dp = (DATA_BL *)(hp->bh_data); - if (dp->db_id != DATA_ID) /* block id wrong */ - ++error; - else { - /* It is a data block, need to write it back to disk. */ - mf_put(mfp, hp, TRUE, FALSE); - hp = NULL; - } - } - } - - if (buf->b_ml.ml_stack_top == 0) /* finished */ - break; - - /* go one block up in the tree */ - ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); - bnum = ip->ip_bnum; - idx = ip->ip_index + 1; /* go to next index */ - page_count = 1; - } - - if (error > 0) - EMSG(_("E843: Error while updating swap file crypt")); - } - - mfp->mf_old_key = NULL; -} - -/* * ml_setname() is called when the file name of "buf" has been changed. * It may rename the swap file. */ @@ -818,8 +669,6 @@ static void ml_upd_block0(buf_T *buf, upd_block0_T what) else { if (what == UB_FNAME) set_b0_fname(b0p, buf); - else if (what == UB_CRYPT) - ml_set_b0_crypt(buf, b0p); else /* what == UB_SAME_DIR */ set_b0_dir_flag(b0p, buf); } @@ -906,12 +755,6 @@ static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf) int n; int size = B0_FNAME_SIZE_NOCRYPT; - /* Without encryption use the same offset as in Vim 7.2 to be compatible. - * With encryption it's OK to move elsewhere, the swap file is not - * compatible anyway. */ - if (*buf->b_p_key != NUL) - size = B0_FNAME_SIZE_CRYPT; - n = (int)STRLEN(buf->b_p_fenc); if ((int)STRLEN(b0p->b0_fname) + n + 1 > size) b0p->b0_flags &= ~B0_HAS_FENC; @@ -937,7 +780,6 @@ void ml_recover(void) ZERO_BL *b0p; int b0_ff; char_u *b0_fenc = NULL; - int b0_cm = -1; PTR_BL *pp; DATA_BL *dp; infoptr_T *ip; @@ -1013,7 +855,7 @@ void ml_recover(void) /* * Allocate a buffer structure for the swap file that is used for recovery. - * Only the memline and crypt information in it are really used. + * Only the memline in it is really used. */ buf = (buf_T *)alloc((unsigned)sizeof(buf_T)); @@ -1026,8 +868,6 @@ void ml_recover(void) buf->b_ml.ml_line_lnum = 0; /* no cached line */ buf->b_ml.ml_locked = NULL; /* no locked block */ buf->b_ml.ml_flags = 0; - buf->b_p_key = empty_option; - buf->b_p_cm = empty_option; /* * open the memfile from the old swap file @@ -1042,7 +882,6 @@ void ml_recover(void) goto theend; } buf->b_ml.ml_mfp = mfp; - mfp->mf_buffer = buf; /* * The page size set in mf_open() might be different from the page size @@ -1093,14 +932,6 @@ void ml_recover(void) goto theend; } - if (b0p->b0_id[1] == BLOCK0_ID1_C0) - b0_cm = 0; - else if (b0p->b0_id[1] == BLOCK0_ID1_C1) { - b0_cm = 1; - memmove(mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN); - } - set_crypt_method(buf, b0_cm); - /* * If we guessed the wrong page size, we have to recalculate the * highest block number in the file. @@ -1172,9 +1003,6 @@ void ml_recover(void) if (b0p->b0_flags & B0_HAS_FENC) { int fnsize = B0_FNAME_SIZE_NOCRYPT; - /* Use the same size as in add_b0_fenc(). */ - if (b0p->b0_id[1] != BLOCK0_ID1) - fnsize = B0_FNAME_SIZE_CRYPT; for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; --p) ; b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p)); @@ -1193,36 +1021,11 @@ void ml_recover(void) /* * Try reading the original file to obtain the values of 'fileformat', * 'fileencoding', etc. Ignore errors. The text itself is not used. - * When the file is encrypted the user is asked to enter the key. */ if (curbuf->b_ffname != NULL) orig_file_status = readfile(curbuf->b_ffname, NULL, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW); - if (b0_cm >= 0) { - /* Need to ask the user for the crypt key. If this fails we continue - * without a key, will probably get garbage text. */ - if (*curbuf->b_p_key != NUL) { - smsg((char_u *)_("Swap file is encrypted: \"%s\""), fname_used); - MSG_PUTS(_( - "\nIf you entered a new crypt key but did not write the text file,")); - MSG_PUTS(_("\nenter the new crypt key.")); - MSG_PUTS(_( - "\nIf you wrote the text file after changing the crypt key press enter")); - MSG_PUTS(_("\nto use the same key for text file and swap file")); - } else - smsg((char_u *)_(need_key_msg), fname_used); - buf->b_p_key = get_crypt_key(FALSE, FALSE); - if (buf->b_p_key == NULL) - buf->b_p_key = curbuf->b_p_key; - else if (*buf->b_p_key == NUL) { - free(buf->b_p_key); - buf->b_p_key = curbuf->b_p_key; - } - if (buf->b_p_key == NULL) - buf->b_p_key = empty_option; - } - /* Use the 'fileformat' and 'fileencoding' as stored in the swap file. */ if (b0_ff != 0) set_fileformat(b0_ff - 1, OPT_LOCAL); @@ -1454,10 +1257,6 @@ void ml_recover(void) MSG_PUTS(_("\nYou may want to delete the .swp file now.\n\n")); cmdline_row = msg_row; } - if (*buf->b_p_key != NUL && STRCMP(curbuf->b_p_key, buf->b_p_key) != 0) { - MSG_PUTS(_("Using crypt key from swap file for the text file.\n")); - set_option_value((char_u *)"key", 0L, buf->b_p_key, OPT_LOCAL); - } redraw_curbuf_later(NOT_VALID); theend: @@ -1469,9 +1268,6 @@ theend: mf_close(mfp, FALSE); /* will also free(mfp->mf_fname) */ } if (buf != NULL) { - if (buf->b_p_key != curbuf->b_p_key) - free_string_option(buf->b_p_key); - free_string_option(buf->b_p_cm); free(buf->b_ml.ml_stack); free(buf); } @@ -3927,108 +3723,6 @@ void ml_setflags(buf_T *buf) } } -/* - * If "data" points to a data block encrypt the text in it and return a copy - * in allocated memory. - */ -char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned size) -{ - DATA_BL *dp = (DATA_BL *)data; - char_u *head_end; - char_u *text_start; - char_u *new_data; - int text_len; - - if (dp->db_id != DATA_ID) - return data; - - new_data = xmalloc(size); - head_end = (char_u *)(&dp->db_index[dp->db_line_count]); - text_start = (char_u *)dp + dp->db_txt_start; - text_len = size - dp->db_txt_start; - - /* Copy the header and the text. */ - memmove(new_data, dp, head_end - (char_u *)dp); - - /* Encrypt the text. */ - crypt_push_state(); - ml_crypt_prepare(mfp, offset, FALSE); - crypt_encode(text_start, text_len, new_data + dp->db_txt_start); - crypt_pop_state(); - - /* Clear the gap. */ - if (head_end < text_start) - memset(new_data + (head_end - data), 0, text_start - head_end); - - return new_data; -} - -/* - * Decrypt the text in "data" if it points to a data block. - */ -void ml_decrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned size) -{ - DATA_BL *dp = (DATA_BL *)data; - char_u *head_end; - char_u *text_start; - int text_len; - - if (dp->db_id == DATA_ID) { - head_end = (char_u *)(&dp->db_index[dp->db_line_count]); - text_start = (char_u *)dp + dp->db_txt_start; - text_len = dp->db_txt_end - dp->db_txt_start; - - if (head_end > text_start || dp->db_txt_start > size - || dp->db_txt_end > size) - return; /* data was messed up */ - - /* Decrypt the text in place. */ - crypt_push_state(); - ml_crypt_prepare(mfp, offset, TRUE); - crypt_decode(text_start, text_len); - crypt_pop_state(); - } -} - -/* - * Prepare for encryption/decryption, using the key, seed and offset. - */ -static void ml_crypt_prepare(memfile_T *mfp, off_t offset, int reading) -{ - buf_T *buf = mfp->mf_buffer; - char_u salt[50]; - int method; - char_u *key; - char_u *seed; - - if (reading && mfp->mf_old_key != NULL) { - /* Reading back blocks with the previous key/method/seed. */ - method = mfp->mf_old_cm; - key = mfp->mf_old_key; - seed = mfp->mf_old_seed; - } else { - method = get_crypt_method(buf); - key = buf->b_p_key; - seed = mfp->mf_seed; - } - - use_crypt_method = method; /* select pkzip or blowfish */ - if (method == 0) { - vim_snprintf((char *)salt, sizeof(salt), "%s%" PRId64 "", - key, (int64_t)offset); - crypt_init_keys(salt); - } else { - /* Using blowfish, add salt and seed. We use the byte offset of the - * block for the salt. */ - vim_snprintf((char *)salt, sizeof(salt), "%" PRId64, (int64_t)offset); - bf_key_init(key, salt, (int)STRLEN(salt)); - bf_cfb_init(seed, MF_SEED_LEN); - } -} - - - - #define MLCS_MAXL 800 /* max no of lines in chunk */ #define MLCS_MINL 400 /* should be half of MLCS_MAXL */ diff --git a/src/nvim/memline.h b/src/nvim/memline.h index 99f2638e72..704a98b20e 100644 --- a/src/nvim/memline.h +++ b/src/nvim/memline.h @@ -5,7 +5,6 @@ #include "nvim/func_attr.h" int ml_open(buf_T *buf); -void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm); void ml_setname(buf_T *buf); void ml_open_files(void); void ml_open_file(buf_T *buf); @@ -37,10 +36,6 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name); char_u *get_file_in_dir(char_u *fname, char_u *dname); void ml_setflags(buf_T *buf); -char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset, - unsigned size) FUNC_ATTR_NONNULL_RET; -void ml_decrypt_data(memfile_T *mfp, char_u *data, off_t offset, - unsigned size); long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp); void goto_byte(long cnt); diff --git a/src/nvim/memory.c b/src/nvim/memory.c index b39c113f99..215eac2a33 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -6,7 +6,6 @@ #include "nvim/vim.h" #include "nvim/misc2.h" #include "nvim/file_search.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index 1292bc8eb4..b9b68c5d0b 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -14,7 +14,6 @@ #include "nvim/vim.h" #include "nvim/misc2.h" #include "nvim/file_search.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" diff --git a/src/nvim/option.c b/src/nvim/option.c index b5f480870e..49abc62c89 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -37,7 +37,6 @@ #include "nvim/vim.h" #include "nvim/option.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" @@ -59,7 +58,6 @@ #include "nvim/misc1.h" #include "nvim/misc2.h" #include "nvim/keymap.h" -#include "nvim/crypt.h" #include "nvim/garray.h" #include "nvim/cursor_shape.h" #include "nvim/move.h" @@ -137,7 +135,6 @@ # define PV_INEX OPT_BUF(BV_INEX) #define PV_INF OPT_BUF(BV_INF) #define PV_ISK OPT_BUF(BV_ISK) -# define PV_KEY OPT_BUF(BV_KEY) # define PV_KMAP OPT_BUF(BV_KMAP) #define PV_KP OPT_BOTH(OPT_BUF(BV_KP)) # define PV_LISP OPT_BUF(BV_LISP) @@ -253,7 +250,6 @@ static char_u *p_indk; static char_u *p_fex; static int p_inf; static char_u *p_isk; -static char_u *p_key; static int p_lisp; static int p_ml; static int p_ma; @@ -583,10 +579,6 @@ static struct vimoption (char_u *)&p_cpo, PV_NONE, {(char_u *)CPO_VI, (char_u *)CPO_VIM} SCRIPTID_INIT}, - {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF, - (char_u *)&p_cm, PV_CM, - {(char_u *)"zip", (char_u *)0L} - SCRIPTID_INIT}, {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM, (char_u *)&p_cspc, PV_NONE, {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT}, @@ -1009,10 +1001,6 @@ static struct vimoption {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM, (char_u *)&p_js, PV_NONE, {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT}, - {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC, - (char_u *)&p_key, PV_KEY, - {(char_u *)"", (char_u *)0L} - SCRIPTID_INIT}, {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME| P_PRI_MKRC, (char_u *)&p_keymap, PV_KMAP, @@ -1832,7 +1820,6 @@ static char *(p_ambw_values[]) = {"single", "double", NULL}; static char *(p_bg_values[]) = {"light", "dark", NULL}; static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL}; static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; -static char *(p_cm_values[]) = {"zip", "blowfish", NULL}; static char *(p_wop_values[]) = {"tagfile", NULL}; static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; static char *(p_mousem_values[]) = @@ -3596,9 +3583,7 @@ void check_buf_options(buf_T *buf) check_string_option(&buf->b_p_inex); check_string_option(&buf->b_p_inde); check_string_option(&buf->b_p_indk); - check_string_option(&buf->b_p_cm); check_string_option(&buf->b_p_fex); - check_string_option(&buf->b_p_key); check_string_option(&buf->b_p_kp); check_string_option(&buf->b_p_mps); check_string_option(&buf->b_p_fo); @@ -4135,59 +4120,7 @@ did_set_string_option ( errmsg = e_invarg; } } - /* 'cryptkey' */ - else if (gvarp == &p_key) { - /* Make sure the ":set" command doesn't show the new value in the - * history. */ - remove_key_from_history(); - if (STRCMP(curbuf->b_p_key, oldval) != 0) - /* Need to update the swapfile. */ - ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf)); - } else if (gvarp == &p_cm) { - if (opt_flags & OPT_LOCAL) - p = curbuf->b_p_cm; - else - p = p_cm; - if (check_opt_strings(p, p_cm_values, TRUE) != OK) - errmsg = e_invarg; - else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL) - errmsg = e_invarg; - else { - /* When setting the global value to empty, make it "zip". */ - if (*p_cm == NUL) { - if (new_value_alloced) - free_string_option(p_cm); - p_cm = vim_strsave((char_u *)"zip"); - new_value_alloced = TRUE; - } - /* Need to update the swapfile when the effective method changed. - * Set "s" to the effective old value, "p" to the effective new - * method and compare. */ - if ((opt_flags & OPT_LOCAL) && *oldval == NUL) - s = p_cm; /* was previously using the global value */ - else - s = oldval; - if (*curbuf->b_p_cm == NUL) - p = p_cm; /* is now using the global value */ - else - p = curbuf->b_p_cm; - if (STRCMP(s, p) != 0) - ml_set_crypt_key(curbuf, curbuf->b_p_key, - crypt_method_from_string(s)); - - /* If the global value changes need to update the swapfile for all - * buffers using that value. */ - if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0) { - buf_T *buf; - - for (buf = firstbuf; buf != NULL; buf = buf->b_next) - if (buf != curbuf && *buf->b_p_cm == NUL) - ml_set_crypt_key(buf, buf->b_p_key, - crypt_method_from_string(oldval)); - } - } - } /* 'matchpairs' */ else if (gvarp == &p_mps) { if (has_mbyte) { @@ -5923,12 +5856,7 @@ get_option_value ( if (varp == NULL) /* hidden option */ return -2; if (stringval != NULL) { - /* never return the value of the crypt key */ - if ((char_u **)varp == &curbuf->b_p_key - && **(char_u **)(varp) != NUL) - *stringval = vim_strsave((char_u *)"*****"); - else - *stringval = vim_strsave(*(char_u **)(varp)); + *stringval = vim_strsave(*(char_u **)(varp)); } return 0; } @@ -6756,7 +6684,6 @@ static char_u *get_varp_scope(struct vimoption *p, int opt_flags) case PV_INC: return (char_u *)&(curbuf->b_p_inc); case PV_DICT: return (char_u *)&(curbuf->b_p_dict); case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); - case PV_CM: return (char_u *)&(curbuf->b_p_cm); case PV_STL: return (char_u *)&(curwin->w_p_stl); case PV_UL: return (char_u *)&(curbuf->b_p_ul); } @@ -6802,8 +6729,6 @@ static char_u *get_varp(struct vimoption *p) ? (char_u *)&(curbuf->b_p_gp) : p->var; case PV_MP: return *curbuf->b_p_mp != NUL ? (char_u *)&(curbuf->b_p_mp) : p->var; - case PV_CM: return *curbuf->b_p_cm != NUL - ? (char_u *)&(curbuf->b_p_cm) : p->var; case PV_STL: return *curwin->w_p_stl != NUL ? (char_u *)&(curwin->w_p_stl) : p->var; case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL @@ -6873,7 +6798,6 @@ static char_u *get_varp(struct vimoption *p) case PV_INDE: return (char_u *)&(curbuf->b_p_inde); case PV_INDK: return (char_u *)&(curbuf->b_p_indk); case PV_FEX: return (char_u *)&(curbuf->b_p_fex); - case PV_KEY: return (char_u *)&(curbuf->b_p_key); case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); case PV_ML: return (char_u *)&(curbuf->b_p_ml); case PV_MPS: return (char_u *)&(curbuf->b_p_mps); @@ -7135,7 +7059,6 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_inde = vim_strsave(p_inde); buf->b_p_indk = vim_strsave(p_indk); buf->b_p_fex = vim_strsave(p_fex); - buf->b_p_key = vim_strsave(p_key); buf->b_p_sua = vim_strsave(p_sua); buf->b_p_keymap = vim_strsave(p_keymap); buf->b_kmap_state |= KEYMAP_INIT; @@ -7161,7 +7084,6 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_dict = empty_option; buf->b_p_tsr = empty_option; buf->b_p_qe = vim_strsave(p_qe); - buf->b_p_cm = empty_option; buf->b_p_udf = p_udf; /* @@ -7620,9 +7542,6 @@ option_value2string ( varp = *(char_u **)(varp); if (varp == NULL) /* just in case */ NameBuff[0] = NUL; - /* don't show the actual value of 'key', only that it's set */ - else if (opp->var == (char_u *)&p_key && *varp) - STRCPY(NameBuff, "*****"); else if (opp->flags & P_EXPAND) home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE); /* Translate 'pastetoggle' into special key names */ diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 3cb96e46a8..ae08b1fa5f 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -308,7 +308,6 @@ static char *(p_bkc_values[]) = EXTERN char_u *p_bdir; /* 'backupdir' */ EXTERN char_u *p_bex; /* 'backupext' */ EXTERN char_u *p_bsk; /* 'backupskip' */ -EXTERN char_u *p_cm; /* 'cryptmethod' */ EXTERN char_u *p_breakat; /* 'breakat' */ EXTERN char_u *p_cmp; /* 'casemap' */ EXTERN unsigned cmp_flags; @@ -688,7 +687,6 @@ enum { , BV_INEX , BV_INF , BV_ISK - , BV_KEY , BV_KMAP , BV_KP , BV_LISP diff --git a/src/nvim/sha256.c b/src/nvim/sha256.c index 549448a6e0..4a61ddc66f 100644 --- a/src/nvim/sha256.c +++ b/src/nvim/sha256.c @@ -9,7 +9,6 @@ /// /// Vim specific notes: /// Functions exported by this file: -/// 1. sha256_key() hashes the password to 64 bytes char string. /// 2. sha2_seed() generates a random header. /// sha256_self_test() is implicitly called once. @@ -284,23 +283,6 @@ char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, int salt_len) return hexit; } -/// Gets sha256(buf) as 64 hex characters in a static array. -/// -/// @param buf -/// @param salt -/// @param salt_len -/// -/// @returns sha256(buf) as 64 hex chars in static array. -char_u* sha256_key(char_u *buf, char_u *salt, int salt_len) -{ - // No passwd means don't encrypt - if ((buf == NULL) || (*buf == NUL)) { - return (char_u *)""; - } - - return sha256_bytes(buf, (int)STRLEN(buf), salt, salt_len); -} - // These are the standard FIPS-180-2 test vectors static char *sha_self_test_msg[] = { "abc", diff --git a/src/nvim/sha256.h b/src/nvim/sha256.h index 0df4746167..355b758cdd 100644 --- a/src/nvim/sha256.h +++ b/src/nvim/sha256.h @@ -11,7 +11,6 @@ void sha256_start(context_sha256_T *ctx); void sha256_update(context_sha256_T *ctx, char_u *input, uint32_t length); void sha256_finish(context_sha256_T *ctx, char_u digest[32]); char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, int salt_len); -char_u *sha256_key(char_u *buf, char_u *salt, int salt_len); int sha256_self_test(void); void sha2_seed(char_u *header, int header_len, char_u *salt, int salt_len); diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 0f35681546..6b229f7498 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -7731,7 +7731,6 @@ static buf_T *open_spellbuf(void) buf->b_spell = TRUE; buf->b_p_swf = TRUE; // may create a swap file - buf->b_p_key = empty_option; ml_open(buf); ml_open_file(buf); // create swap file now diff --git a/src/nvim/strings.c b/src/nvim/strings.c index fbad71e3c6..50669dfcfb 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -4,7 +4,6 @@ #include "nvim/strings.h" #include "nvim/misc2.h" #include "nvim/file_search.h" -#include "nvim/blowfish.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/diff.h" diff --git a/src/nvim/testdir/test71.in b/src/nvim/testdir/test71.in deleted file mode 100644 index 155fd413bc..0000000000 --- a/src/nvim/testdir/test71.in +++ /dev/null @@ -1,67 +0,0 @@ -Test for encryption. -The test data is in another file to avoid problems with 'encoding', especially -cp932. - -STARTTEST -:so small.vim -:set enc=latin1 -:bwipe! -:r test71a.in -:/^start of text/+1 -:let text_lines = getline('.', line('.') + 2) -:/^start of cm=zip bytes/+1 -:let cm0_bytes = getline('.', '.') -:/^start of cm=blowfish bytes/+1 -:let cm1_bytes = getline('.', '.') -:bwipe! -:call append(0, text_lines) -:$d -:X -foobar -foobar -:w! Xtestfile -:bwipe! -:e Xtestfile -foobar -:let cm0_read_back = getline('.', '$') -:set key= -:set cryptmethod=blowfish -:" If the blowfish test fails 'cryptmethod' will be 'zip' now. -:%s/^/\=&cryptmethod == 'blowfish' ? "OK " : "blowfish test failed "/ -:X -barfoo -barfoo -:w! Xtestfile -:bwipe! -:e Xtestfile -barfoo -:let cm1_read_back = getline('.', '$') -:bwipe! -:set bin noeol key= -:call append(0, cm0_bytes) -:$d -:set fenc=latin1 -:w! Xtestfile -:bwipe! -:set nobin -:e Xtestfile -foofoo -:let cm0_read_bin = getline('.', '$') -:bwipe! -:set bin noeol key= -:call append(0, cm1_bytes) -:$d -:set fenc=latin1 -:w! Xtestfile -:bwipe! -:set nobin -:e Xtestfile -barbar -:call append(0, cm0_read_bin) -:call append(0, cm1_read_back) -:call append(0, cm0_read_back) -:set key= fenc=latin1 -:w! test.out -:qa! -ENDTEST - diff --git a/src/nvim/testdir/test71.ok b/src/nvim/testdir/test71.ok deleted file mode 100644 index 24652c4380..0000000000 --- a/src/nvim/testdir/test71.ok +++ /dev/null @@ -1,10 +0,0 @@ -01234567890123456789012345678901234567 -line 2 foo bar blah -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -OK 01234567890123456789012345678901234567 -OK line 2 foo bar blah -OK line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -1234567890 -aábbccddeëff -asdfasdfasdf -0001112223333 diff --git a/src/nvim/testdir/test71a.in b/src/nvim/testdir/test71a.in deleted file mode 100644 index 85bd22cd01..0000000000 --- a/src/nvim/testdir/test71a.in +++ /dev/null @@ -1,14 +0,0 @@ - -start of text -01234567890123456789012345678901234567 -line 2 foo bar blah -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -end of text - -start of cm=zip bytes -VimCrypt~01!lV'Þ}Mg ê£V©çE#3Ž2Ué— -end of cm=zip bytes - -start of cm=blowfish bytes -VimCrypt~02!k)¾—#ÝSœõ=ºàÈ#¥M´†JÃAÍ¥M´†!€›õáÒ‚˜÷
Ú -end of cm=blowfish bytes diff --git a/src/nvim/testdir/test72.in b/src/nvim/testdir/test72.in index 220adad67a..0821764c3c 100644 --- a/src/nvim/testdir/test72.in +++ b/src/nvim/testdir/test72.in @@ -57,52 +57,6 @@ i u:e! Xtestfile :set undofile ul=100 uuuuuu:w >>test.out -:" And now with encryption, cryptmethod=zip -:e! Xtestfile -:set undofile cm=zip -ggdGimonday -tuesday -wednesday -thursday -friday:set ul=100 -kkkdd:set ul=100 -dd:set ul=100 -dd:set ul=100 -:X -foobar -foobar -:w! -:bwipe! -:e Xtestfile -foobar -:set key= -uu:w >>test.out -:" -:" -:" With encryption, cryptmethod=blowfish -:e! Xtestfile -:set undofile cm=blowfish -ggdGijan -feb -mar -apr -jun:set ul=100 -kk0ifoo :set ul=100 -dd:set ul=100 -ibar :set ul=100 -:X -foobar -foobar -:w! -:bwipe! -:e Xtestfile -foobar -:set key= -/bar -:.w >>test.out -u:.w >>test.out -u:.w >>test.out -u:.w >>test.out :" :" Rename the undo file so that it gets cleaned up. :call rename(".Xtestfile.un~", "Xtestundo") diff --git a/src/nvim/testdir/test72.ok b/src/nvim/testdir/test72.ok index bb267d0d8b..091b1e94a6 100644 --- a/src/nvim/testdir/test72.ok +++ b/src/nvim/testdir/test72.ok @@ -17,11 +17,3 @@ seven eight nine ten -monday -wednesday -thursday -friday -bar apr -apr -foo mar -mar diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 4d499cc28e..844ade790f 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -94,7 +94,6 @@ #include "nvim/misc1.h" #include "nvim/misc2.h" #include "nvim/memory.h" -#include "nvim/crypt.h" #include "nvim/garray.h" #include "nvim/option.h" #include "nvim/os_unix.h" @@ -121,9 +120,6 @@ static void u_freeentries(buf_T *buf, u_header_T *uhp, static void u_freeentry(u_entry_T *, long); static void corruption_error(char *mesg, char_u *file_name); static void u_free_uhp(u_header_T *uhp); -static size_t fwrite_crypt(buf_T *buf, char_u *ptr, size_t len, - FILE *fp); -static char_u *read_string_decrypt(buf_T *buf, FILE *fd, int len); static int serialize_header(FILE *fp, buf_T *buf, char_u *hash); static int serialize_uhp(FILE *fp, buf_T *buf, u_header_T *uhp); static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name); @@ -634,7 +630,6 @@ nomem: # define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */ # define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */ # define UF_VERSION 2 /* 2-byte undofile version number */ -# define UF_VERSION_CRYPT 0x8002 /* idem, encrypted */ /* extra fields for header */ # define UF_LAST_SAVE_NR 1 @@ -753,44 +748,6 @@ static void u_free_uhp(u_header_T *uhp) free(uhp); } -/* - * Like fwrite() but crypt the bytes when 'key' is set. - * Returns 1 if successful. - */ -static size_t fwrite_crypt(buf_T *buf, char_u *ptr, size_t len, FILE *fp) -{ - char_u *copy; - char_u small_buf[100]; - size_t i; - - if (*buf->b_p_key == NUL) - return fwrite(ptr, len, (size_t)1, fp); - if (len < 100) - copy = small_buf; /* no malloc()/free() for short strings */ - else { - copy = xmalloc(len); - } - crypt_encode(ptr, len, copy); - i = fwrite(copy, len, (size_t)1, fp); - if (copy != small_buf) - free(copy); - return i; -} - -/* - * Read a string of length "len" from "fd". - * When 'key' is set decrypt the bytes. - */ -static char_u *read_string_decrypt(buf_T *buf, FILE *fd, int len) -{ - char_u *ptr; - - ptr = read_string(fd, len); - if (ptr != NULL && *buf->b_p_key != NUL) - crypt_decode(ptr, len); - return ptr; -} - static int serialize_header(FILE *fp, buf_T *buf, char_u *hash) { int len; @@ -799,25 +756,7 @@ static int serialize_header(FILE *fp, buf_T *buf, char_u *hash) if (fwrite(UF_START_MAGIC, (size_t)UF_START_MAGIC_LEN, (size_t)1, fp) != 1) return FAIL; - /* If the buffer is encrypted then all text bytes following will be - * encrypted. Numbers and other info is not crypted. */ - if (*buf->b_p_key != NUL) { - char_u *header; - int header_len; - - put_bytes(fp, (long_u)UF_VERSION_CRYPT, 2); - header = prepare_crypt_write(buf, &header_len); - if (header == NULL) - return FAIL; - len = (int)fwrite(header, (size_t)header_len, (size_t)1, fp); - free(header); - if (len != 1) { - crypt_pop_state(); - return FAIL; - } - } else - put_bytes(fp, (long_u)UF_VERSION, 2); - + put_bytes(fp, (long_u)UF_VERSION, 2); /* Write a hash of the buffer text, so that we can verify it is still the * same when reading the buffer text. */ @@ -828,7 +767,7 @@ static int serialize_header(FILE *fp, buf_T *buf, char_u *hash) put_bytes(fp, (long_u)buf->b_ml.ml_line_count, 4); len = buf->b_u_line_ptr != NULL ? (int)STRLEN(buf->b_u_line_ptr) : 0; put_bytes(fp, (long_u)len, 4); - if (len > 0 && fwrite_crypt(buf, buf->b_u_line_ptr, (size_t)len, fp) != 1) + if (len > 0 && fwrite(buf->b_u_line_ptr, len, 1, fp) != 1) return FAIL; put_bytes(fp, (long_u)buf->b_u_line_lnum, 4); put_bytes(fp, (long_u)buf->b_u_line_colnr, 4); @@ -982,7 +921,7 @@ static int serialize_uep(FILE *fp, buf_T *buf, u_entry_T *uep) len = STRLEN(uep->ue_array[i]); if (put_bytes(fp, (long_u)len, 4) == FAIL) return FAIL; - if (len > 0 && fwrite_crypt(buf, uep->ue_array[i], len, fp) != 1) + if (len > 0 && fwrite(uep->ue_array[i], len, 1, fp) != 1) return FAIL; } return OK; @@ -1015,7 +954,7 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name) for (i = 0; i < uep->ue_size; ++i) { line_len = get4c(fp); if (line_len >= 0) - line = read_string_decrypt(curbuf, fp, line_len); + line = read_string(fp, line_len); else { line = NULL; corruption_error("line length", file_name); @@ -1107,7 +1046,6 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) FILE *fp = NULL; int perm; int write_ok = FALSE; - int do_crypt = FALSE; if (name == NULL) { file_name = u_get_undo_file_name(buf->b_ffname, FALSE); @@ -1245,8 +1183,6 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) */ if (serialize_header(fp, buf, hash) == FAIL) goto write_error; - if (*buf->b_p_key != NUL) - do_crypt = TRUE; /* * Iteratively serialize UHPs and their UEPs from the top down. @@ -1305,8 +1241,6 @@ write_error: #endif theend: - if (do_crypt) - crypt_pop_state(); if (file_name != name) free(file_name); } @@ -1343,7 +1277,6 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) #ifdef U_DEBUG int *uhp_table_used; #endif - int do_decrypt = FALSE; if (name == NULL) { file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE); @@ -1393,18 +1326,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) goto error; } version = get2c(fp); - if (version == UF_VERSION_CRYPT) { - if (*curbuf->b_p_key == NUL) { - EMSG2(_("E832: Non-encrypted file has encrypted undo file: %s"), - file_name); - goto error; - } - if (prepare_crypt_read(fp) == FAIL) { - EMSG2(_("E826: Undo file decryption failed: %s"), file_name); - goto error; - } - do_decrypt = TRUE; - } else if (version != UF_VERSION) { + if (version != UF_VERSION) { EMSG2(_("E824: Incompatible undo file: %s"), file_name); goto error; } @@ -1432,7 +1354,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) if (str_len < 0) goto error; if (str_len > 0) - line_ptr = read_string_decrypt(curbuf, fp, str_len); + line_ptr = read_string(fp, str_len); line_lnum = (linenr_T)get4c(fp); line_colnr = (colnr_T)get4c(fp); if (line_lnum < 0 || line_colnr < 0) { @@ -1602,8 +1524,6 @@ error: } theend: - if (do_decrypt) - crypt_pop_state(); if (fp != NULL) fclose(fp); if (file_name != name) diff --git a/src/nvim/version.c b/src/nvim/version.c index a140453c96..bab38a8d32 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -54,7 +54,6 @@ static char *(features[]) = { "+cmdline_info", "+comments", "+conceal", - "+cryptv", "+cscope", "+cursorbind", #ifdef CURSOR_SHAPE |