annotate src/sha256.c @ 7156:0b4e65cf84fb v7.4.889

commit https://github.com/vim/vim/commit/74b738d414b2895b3365e26ae3b7792eb82ccf47 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Sep 29 18:08:33 2015 +0200 patch 7.4.889 Problem: Triggering OptionSet from setwinvar() isn't tested. Solution: Add a test. (Christian Brabandt)
author Christian Brabandt <cb@256bit.org>
date Tue, 29 Sep 2015 18:15:04 +0200
parents 2b340e5c5baa
children 0b6c37dd858d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 *
2184
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
4 *
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
7 * See README.txt for an overview of the Vim source code.
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 *
2184
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
9 * FIPS-180-2 compliant SHA-256 implementation
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
10 * GPL by Christophe Devine, applies to older version.
2184
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
11 * Modified for md5deep, in public domain.
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
12 * Modified For Vim, Mohsin Ahmed, http://www.cs.albany.edu/~mosh
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
13 * Mohsin Ahmed states this work is distributed under the VIM License or GPL,
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
14 * at your choice.
2184
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
15 *
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
16 * Vim specific notes:
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
17 * Functions exported by this file:
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
18 * 1. sha256_key() hashes the password to 64 bytes char string.
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
19 * 2. sha2_seed() generates a random header.
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
20 * sha256_self_test() is implicitly called once.
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 #include "vim.h"
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
25 #if defined(FEAT_CRYPT) || defined(FEAT_PERSISTENT_UNDO)
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 static void sha256_process __ARGS((context_sha256_T *ctx, char_u data[64]));
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 #define GET_UINT32(n, b, i) \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 { \
2199
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
31 (n) = ( (UINT32_T)(b)[(i) ] << 24) \
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
32 | ( (UINT32_T)(b)[(i) + 1] << 16) \
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
33 | ( (UINT32_T)(b)[(i) + 2] << 8) \
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
34 | ( (UINT32_T)(b)[(i) + 3] ); \
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 #define PUT_UINT32(n,b,i) \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 { \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 (b)[(i) ] = (char_u)((n) >> 24); \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 (b)[(i) + 1] = (char_u)((n) >> 16); \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 (b)[(i) + 2] = (char_u)((n) >> 8); \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 (b)[(i) + 3] = (char_u)((n) ); \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
45 void
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
46 sha256_start(ctx)
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 context_sha256_T *ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 ctx->total[0] = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 ctx->total[1] = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 ctx->state[0] = 0x6A09E667;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 ctx->state[1] = 0xBB67AE85;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 ctx->state[2] = 0x3C6EF372;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 ctx->state[3] = 0xA54FF53A;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 ctx->state[4] = 0x510E527F;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 ctx->state[5] = 0x9B05688C;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 ctx->state[6] = 0x1F83D9AB;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 ctx->state[7] = 0x5BE0CD19;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 static void
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 sha256_process(ctx, data)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 context_sha256_T *ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 char_u data[64];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 {
2199
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
67 UINT32_T temp1, temp2, W[64];
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
68 UINT32_T A, B, C, D, E, F, G, H;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 GET_UINT32(W[0], data, 0);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 GET_UINT32(W[1], data, 4);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 GET_UINT32(W[2], data, 8);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 GET_UINT32(W[3], data, 12);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 GET_UINT32(W[4], data, 16);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 GET_UINT32(W[5], data, 20);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 GET_UINT32(W[6], data, 24);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 GET_UINT32(W[7], data, 28);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 GET_UINT32(W[8], data, 32);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 GET_UINT32(W[9], data, 36);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 GET_UINT32(W[10], data, 40);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81 GET_UINT32(W[11], data, 44);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 GET_UINT32(W[12], data, 48);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 GET_UINT32(W[13], data, 52);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 GET_UINT32(W[14], data, 56);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 GET_UINT32(W[15], data, 60);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 #define SHR(x, n) ((x & 0xFFFFFFFF) >> n)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 #define ROTR(x, n) (SHR(x, n) | (x << (32 - n)))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 #define S0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 #define S1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 #define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 #define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 #define F0(x, y, z) ((x & y) | (z & (x | y)))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 #define F1(x, y, z) (z ^ (x & (y ^ z)))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 #define R(t) \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 ( \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 W[t] = S1(W[t - 2]) + W[t - 7] + \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 S0(W[t - 15]) + W[t - 16] \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 )
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 #define P(a,b,c,d,e,f,g,h,x,K) \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 { \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 temp1 = h + S3(e) + F1(e, f, g) + K + x; \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 temp2 = S2(a) + F0(a, b, c); \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 d += temp1; h = temp1 + temp2; \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 A = ctx->state[0];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 B = ctx->state[1];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 C = ctx->state[2];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 D = ctx->state[3];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 E = ctx->state[4];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 F = ctx->state[5];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 G = ctx->state[6];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 H = ctx->state[7];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 P( G, H, A, B, C, D, E, F, W[10], 0x243185BE);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137 P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141 P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 P( A, B, C, D, E, F, G, H, R(24), 0x983E5152);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 P( B, C, D, E, F, G, H, A, R(31), 0x14292967);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 P( F, G, H, A, B, C, D, E, R(35), 0x53380D13);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 P( E, F, G, H, A, B, C, D, R(36), 0x650A7354);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 P( B, C, D, E, F, G, H, A, R(39), 0x92722C85);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 P( E, F, G, H, A, B, C, D, R(44), 0xD192E819);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 P( D, E, F, G, H, A, B, C, R(45), 0xD6990624);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 P( B, C, D, E, F, G, H, A, R(47), 0x106AA070);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 P( G, H, A, B, C, D, E, F, R(50), 0x2748774C);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 P( G, H, A, B, C, D, E, F, R(58), 0x84C87814);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 ctx->state[0] += A;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 ctx->state[1] += B;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 ctx->state[2] += C;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 ctx->state[3] += D;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 ctx->state[4] += E;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 ctx->state[5] += F;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 ctx->state[6] += G;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 ctx->state[7] += H;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
196 void
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 sha256_update(ctx, input, length)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 context_sha256_T *ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 char_u *input;
2199
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
200 UINT32_T length;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 {
2199
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
202 UINT32_T left, fill;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 if (length == 0)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 return;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 left = ctx->total[0] & 0x3F;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 fill = 64 - left;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 ctx->total[0] += length;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 ctx->total[0] &= 0xFFFFFFFF;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 if (ctx->total[0] < length)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 ctx->total[1]++;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216 if (left && length >= fill)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 memcpy((void *)(ctx->buffer + left), (void *)input, fill);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 sha256_process(ctx, ctx->buffer);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 length -= fill;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 input += fill;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 left = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 while (length >= 64)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 sha256_process(ctx, input);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 length -= 64;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 input += 64;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 if (length)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 memcpy((void *)(ctx->buffer + left), (void *)input, length);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 static char_u sha256_padding[64] = {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 };
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
243 void
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244 sha256_finish(ctx, digest)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245 context_sha256_T *ctx;
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
246 char_u digest[32];
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 {
2199
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
248 UINT32_T last, padn;
014a996ac896 Use UINT32_T in the code, define it to uint32_t or unsigned int.
Bram Moolenaar <bram@vim.org>
parents: 2184
diff changeset
249 UINT32_T high, low;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 char_u msglen[8];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253 low = (ctx->total[0] << 3);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 PUT_UINT32(high, msglen, 0);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256 PUT_UINT32(low, msglen, 4);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 last = ctx->total[0] & 0x3F;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 padn = (last < 56) ? (56 - last) : (120 - last);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 sha256_update(ctx, sha256_padding, padn);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 sha256_update(ctx, msglen, 8);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 PUT_UINT32(ctx->state[0], digest, 0);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265 PUT_UINT32(ctx->state[1], digest, 4);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
266 PUT_UINT32(ctx->state[2], digest, 8);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 PUT_UINT32(ctx->state[3], digest, 12);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268 PUT_UINT32(ctx->state[4], digest, 16);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 PUT_UINT32(ctx->state[5], digest, 20);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
270 PUT_UINT32(ctx->state[6], digest, 24);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 PUT_UINT32(ctx->state[7], digest, 28);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 }
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
273 #endif /* FEAT_CRYPT || FEAT_PERSISTENT_UNDO */
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
274
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
275 #if defined(FEAT_CRYPT) || defined(PROTO)
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
276 static unsigned int get_some_time __ARGS((void));
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
278 /*
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
279 * Returns hex digest of "buf[buf_len]" in a static array.
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
280 * if "salt" is not NULL also do "salt[salt_len]".
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
281 */
4126
2b340e5c5baa updated for version 7.3.816
Bram Moolenaar <bram@vim.org>
parents: 3935
diff changeset
282 char_u *
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
283 sha256_bytes(buf, buf_len, salt, salt_len)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
284 char_u *buf;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
285 int buf_len;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
286 char_u *salt;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
287 int salt_len;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 char_u sha256sum[32];
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
290 static char_u hexit[65];
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291 int j;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292 context_sha256_T ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 sha256_self_test();
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
296 sha256_start(&ctx);
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
297 sha256_update(&ctx, buf, buf_len);
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
298 if (salt != NULL)
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
299 sha256_update(&ctx, salt, salt_len);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300 sha256_finish(&ctx, sha256sum);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 for (j = 0; j < 32; j++)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
302 sprintf((char *)hexit + j * 2, "%02x", sha256sum[j]);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 hexit[sizeof(hexit) - 1] = '\0';
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304 return hexit;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307 /*
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
308 * Returns sha256(buf) as 64 hex chars in static array.
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309 */
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
310 char_u *
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
311 sha256_key(buf, salt, salt_len)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
312 char_u *buf;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
313 char_u *salt;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
314 int salt_len;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 /* No passwd means don't encrypt */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 if (buf == NULL || *buf == NUL)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
318 return (char_u *)"";
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
320 return sha256_bytes(buf, (int)STRLEN(buf), salt, salt_len);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 /*
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 * These are the standard FIPS-180-2 test vectors
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 static char *sha_self_test_msg[] = {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 "abc",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 NULL
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 };
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333 static char *sha_self_test_vector[] = {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 "ba7816bf8f01cfea414140de5dae2223" \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 "b00361a396177a9cb410ff61f20015ad",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 "248d6a61d20638b8e5c026930c3e6039" \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 "a33ce45964ff2167f6ecedd419db06c1",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 "cdc76e5c9914fb9281a1c7e284d73e67" \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 "f1809a48a497200e046d39ccc7112cd0"
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
340 };
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
341
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
342 /*
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 * Perform a test on the SHA256 algorithm.
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 * Return FAIL or OK.
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
345 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 int
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
347 sha256_self_test()
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 int i, j;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 char output[65];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 context_sha256_T ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 char_u buf[1000];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 char_u sha256sum[32];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 static int failures = 0;
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
355 char_u *hexit;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 static int sha256_self_tested = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
358 if (sha256_self_tested > 0)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
359 return failures > 0 ? FAIL : OK;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
360 sha256_self_tested = 1;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
362 for (i = 0; i < 3; i++)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 if (i < 2)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 {
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
366 hexit = sha256_bytes((char_u *)sha_self_test_msg[i],
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
367 (int)STRLEN(sha_self_test_msg[i]),
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
368 NULL, 0);
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
369 STRCPY(output, hexit);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 else
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 {
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
373 sha256_start(&ctx);
2215
cccb71c2c5c1 Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents: 2214
diff changeset
374 vim_memset(buf, 'a', 1000);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
375 for (j = 0; j < 1000; j++)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 sha256_update(&ctx, (char_u *)buf, 1000);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 sha256_finish(&ctx, sha256sum);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 for (j = 0; j < 32; j++)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 sprintf(output + j * 2, "%02x", sha256sum[j]);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 if (memcmp(output, sha_self_test_vector[i], 64))
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
383 failures++;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
384 output[sizeof(output) - 1] = '\0';
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
385 /* printf("sha256_self_test %d failed %s\n", i, output); */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 return failures > 0 ? FAIL : OK;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 static unsigned int
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 get_some_time()
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 {
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
394 # ifdef HAVE_GETTIMEOFDAY
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 struct timeval tv;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 /* Using usec makes it less predictable. */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 gettimeofday(&tv, NULL);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 return (unsigned int)(tv.tv_sec + tv.tv_usec);
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
400 # else
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 return (unsigned int)time(NULL);
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
402 # endif
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
405 /*
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
406 * Fill "header[header_len]" with random_data.
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
407 * Also "salt[salt_len]" when "salt" is not NULL.
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409 void
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
410 sha2_seed(header, header_len, salt, salt_len)
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
411 char_u *header;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 int header_len;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
413 char_u *salt;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
414 int salt_len;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416 int i;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 static char_u random_data[1000];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418 char_u sha256sum[32];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 context_sha256_T ctx;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
420
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421 srand(get_some_time());
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423 for (i = 0; i < (int)sizeof(random_data) - 1; i++)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
424 random_data[i] = (char_u)((get_some_time() ^ rand()) & 0xff);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
425 sha256_start(&ctx);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 sha256_update(&ctx, (char_u *)random_data, sizeof(random_data));
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427 sha256_finish(&ctx, sha256sum);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
429 /* put first block into header. */
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 for (i = 0; i < header_len; i++)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431 header[i] = sha256sum[i % sizeof(sha256sum)];
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
432
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
433 /* put remaining block into salt. */
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
434 if (salt != NULL)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
435 for (i = 0; i < salt_len; i++)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
436 salt[i] = sha256sum[(i + header_len) % sizeof(sha256sum)];
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
439 #endif /* FEAT_CRYPT */