annotate src/sha256.c @ 3850:8eb5b61161b4 v7.3.682

updated for version 7.3.682 Problem: Compiler complains about incompatible types. Solution: Remove type casts. (hint by Danek Duvall)
author Bram Moolenaar <bram@vim.org>
date Thu, 04 Oct 2012 22:38:37 +0200
parents ccda151dde4e
children ee138f29259e
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
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
10 * GPL by Christophe Devine.
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
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
13 *
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
14 * Vim specific notes:
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
15 * Functions exported by this file:
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
16 * 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
17 * 2. sha2_seed() generates a random header.
5028c4d6d825 Fixed encryption big/little endian test.
Bram Moolenaar <bram@vim.org>
parents: 2182
diff changeset
18 * 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
19 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 #include "vim.h"
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
23 #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
24
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 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
26
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 #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
28 { \
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
29 (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
30 | ( (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
31 | ( (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
32 | ( (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
33 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 #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
36 { \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 (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
38 (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
39 (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
40 (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
41 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
43 void
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
44 sha256_start(ctx)
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 context_sha256_T *ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 ctx->total[0] = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 ctx->total[1] = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 ctx->state[0] = 0x6A09E667;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 ctx->state[1] = 0xBB67AE85;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 ctx->state[2] = 0x3C6EF372;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 ctx->state[3] = 0xA54FF53A;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 ctx->state[4] = 0x510E527F;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 ctx->state[5] = 0x9B05688C;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 ctx->state[6] = 0x1F83D9AB;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 ctx->state[7] = 0x5BE0CD19;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 static void
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 sha256_process(ctx, data)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 context_sha256_T *ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 char_u data[64];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 {
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
65 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
66 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
67
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 #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
86 #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
87
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 #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
89 #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
90
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 #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
92 #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
93
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 #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
95 #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
96
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 #define R(t) \
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 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
100 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
101 )
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 #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
104 { \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 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
106 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
107 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
108 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 A = ctx->state[0];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 B = ctx->state[1];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 C = ctx->state[2];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 D = ctx->state[3];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 E = ctx->state[4];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 F = ctx->state[5];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 G = ctx->state[6];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 H = ctx->state[7];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 ctx->state[0] += A;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 ctx->state[1] += B;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 ctx->state[2] += C;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 ctx->state[3] += D;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 ctx->state[4] += E;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 ctx->state[5] += F;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 ctx->state[6] += G;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 ctx->state[7] += H;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
194 void
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 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
196 context_sha256_T *ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 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
198 UINT32_T length;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 {
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 left, fill;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 if (length == 0)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 return;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 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
206 fill = 64 - left;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 ctx->total[0] += length;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 ctx->total[0] &= 0xFFFFFFFF;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 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
212 ctx->total[1]++;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 if (left && length >= fill)
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 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
217 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
218 length -= fill;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 input += fill;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 left = 0;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 while (length >= 64)
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 sha256_process(ctx, input);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 length -= 64;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 input += 64;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 if (length)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 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
232 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 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
235 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
236 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
237 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
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 };
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
241 void
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 sha256_finish(ctx, digest)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 context_sha256_T *ctx;
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
244 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
245 {
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
246 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
247 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
248 char_u msglen[8];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 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
251 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
252
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253 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
254 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
255
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256 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
257 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
258
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 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
260 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
261
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270 }
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
271 #endif /* FEAT_CRYPT || FEAT_PERSISTENT_UNDO */
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
272
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
273 #if defined(FEAT_CRYPT) || defined(PROTO)
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
274 static char_u *sha256_bytes __ARGS((char_u *buf, int buf_len, char_u *salt, int salt_len));
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
275 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
276
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
277 /*
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
278 * 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
279 * 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
280 */
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
281 static char_u *
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
282 sha256_bytes(buf, buf_len, salt, salt_len)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
283 char_u *buf;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
284 int buf_len;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
285 char_u *salt;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
286 int salt_len;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288 char_u sha256sum[32];
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
289 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
290 int j;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291 context_sha256_T ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293 sha256_self_test();
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
295 sha256_start(&ctx);
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
296 sha256_update(&ctx, buf, buf_len);
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
297 if (salt != NULL)
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
298 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
299 sha256_finish(&ctx, sha256sum);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300 for (j = 0; j < 32; j++)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
301 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
302 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
303 return hexit;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304 }
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 /*
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
307 * 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
308 */
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
309 char_u *
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
310 sha256_key(buf, salt, salt_len)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
311 char_u *buf;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
312 char_u *salt;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
313 int salt_len;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 /* 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
316 if (buf == NULL || *buf == NUL)
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
317 return (char_u *)"";
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
319 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
320 }
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 * 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
324 */
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 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
327 "abc",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 NULL
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 };
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 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
333 "ba7816bf8f01cfea414140de5dae2223" \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 "b00361a396177a9cb410ff61f20015ad",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 "248d6a61d20638b8e5c026930c3e6039" \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 "a33ce45964ff2167f6ecedd419db06c1",
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 "cdc76e5c9914fb9281a1c7e284d73e67" \
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 "f1809a48a497200e046d39ccc7112cd0"
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 };
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 * 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
343 * Return FAIL or OK.
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
345 int
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 sha256_self_test()
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
347 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348 int i, j;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 char output[65];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 context_sha256_T ctx;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 char_u buf[1000];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 char_u sha256sum[32];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 static int failures = 0;
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
354 char_u *hexit;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 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
356
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 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
358 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
359 sha256_self_tested = 1;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
360
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361 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
362 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 if (i < 2)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 {
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
365 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
366 (int)STRLEN(sha_self_test_msg[i]),
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
367 NULL, 0);
2182
3cb515c62e9c Minor updates to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
368 STRCPY(output, hexit);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 else
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 {
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2199
diff changeset
372 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
373 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
374 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
375 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
376 sha256_finish(&ctx, sha256sum);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 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
378 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
379 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 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
381 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 failures++;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
383 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
384 /* 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
385 }
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 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
388 }
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 static unsigned int
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 get_some_time()
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 {
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
393 # ifdef HAVE_GETTIMEOFDAY
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394 struct timeval tv;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396 /* 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
397 gettimeofday(&tv, NULL);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 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
399 # else
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 return (unsigned int)time(NULL);
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
401 # endif
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 }
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 /*
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
405 * Fill "header[header_len]" with random_data.
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
406 * 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
407 */
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408 void
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
409 sha2_seed(header, header_len, salt, salt_len)
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
410 char_u *header;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411 int header_len;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
412 char_u *salt;
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
413 int salt_len;
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 {
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 int i;
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416 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
417 char_u sha256sum[32];
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418 context_sha256_T ctx;
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
419
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420 srand(get_some_time());
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 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
423 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
424 sha256_start(&ctx);
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 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
426 sha256_finish(&ctx, sha256sum);
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
428 /* 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
429 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
430 header[i] = sha256sum[i % sizeof(sha256sum)];
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
431
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
432 /* put remaining block into salt. */
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
433 if (salt != NULL)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
434 for (i = 0; i < salt_len; i++)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2265
diff changeset
435 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
436 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2217
diff changeset
438 #endif /* FEAT_CRYPT */