comparison src/sha256.c @ 2199:014a996ac896 vim73

Use UINT32_T in the code, define it to uint32_t or unsigned int. Better autoconf check for uint32_t.
author Bram Moolenaar <bram@vim.org>
date Wed, 19 May 2010 21:57:45 +0200
parents 5028c4d6d825
children f8222d1f9a73
comparison
equal deleted inserted replaced
2198:e741fe7a0547 2199:014a996ac896
21 #include "vim.h" 21 #include "vim.h"
22 22
23 #ifdef FEAT_CRYPT 23 #ifdef FEAT_CRYPT
24 24
25 typedef struct { 25 typedef struct {
26 uint32_t total[2]; 26 UINT32_T total[2];
27 uint32_t state[8]; 27 UINT32_T state[8];
28 char_u buffer[64]; 28 char_u buffer[64];
29 } context_sha256_T; 29 } context_sha256_T;
30 30
31 static void sha256_starts __ARGS((context_sha256_T *ctx)); 31 static void sha256_starts __ARGS((context_sha256_T *ctx));
32 static void sha256_process __ARGS((context_sha256_T *ctx, char_u data[64])); 32 static void sha256_process __ARGS((context_sha256_T *ctx, char_u data[64]));
33 static void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, uint32_t length)); 33 static void sha256_update __ARGS((context_sha256_T *ctx, char_u *input, UINT32_T length));
34 static void sha256_finish __ARGS((context_sha256_T *ctx, char_u digest[32])); 34 static void sha256_finish __ARGS((context_sha256_T *ctx, char_u digest[32]));
35 static char_u *sha256_bytes __ARGS((char_u *buf, int buflen)); 35 static char_u *sha256_bytes __ARGS((char_u *buf, int buflen));
36 static unsigned int get_some_time __ARGS((void)); 36 static unsigned int get_some_time __ARGS((void));
37 37
38 38
39 #define GET_UINT32(n, b, i) \ 39 #define GET_UINT32(n, b, i) \
40 { \ 40 { \
41 (n) = ( (uint32_t)(b)[(i) ] << 24) \ 41 (n) = ( (UINT32_T)(b)[(i) ] << 24) \
42 | ( (uint32_t)(b)[(i) + 1] << 16) \ 42 | ( (UINT32_T)(b)[(i) + 1] << 16) \
43 | ( (uint32_t)(b)[(i) + 2] << 8) \ 43 | ( (UINT32_T)(b)[(i) + 2] << 8) \
44 | ( (uint32_t)(b)[(i) + 3] ); \ 44 | ( (UINT32_T)(b)[(i) + 3] ); \
45 } 45 }
46 46
47 #define PUT_UINT32(n,b,i) \ 47 #define PUT_UINT32(n,b,i) \
48 { \ 48 { \
49 (b)[(i) ] = (char_u)((n) >> 24); \ 49 (b)[(i) ] = (char_u)((n) >> 24); \
72 static void 72 static void
73 sha256_process(ctx, data) 73 sha256_process(ctx, data)
74 context_sha256_T *ctx; 74 context_sha256_T *ctx;
75 char_u data[64]; 75 char_u data[64];
76 { 76 {
77 uint32_t temp1, temp2, W[64]; 77 UINT32_T temp1, temp2, W[64];
78 uint32_t A, B, C, D, E, F, G, H; 78 UINT32_T A, B, C, D, E, F, G, H;
79 79
80 GET_UINT32(W[0], data, 0); 80 GET_UINT32(W[0], data, 0);
81 GET_UINT32(W[1], data, 4); 81 GET_UINT32(W[1], data, 4);
82 GET_UINT32(W[2], data, 8); 82 GET_UINT32(W[2], data, 8);
83 GET_UINT32(W[3], data, 12); 83 GET_UINT32(W[3], data, 12);
205 205
206 static void 206 static void
207 sha256_update(ctx, input, length) 207 sha256_update(ctx, input, length)
208 context_sha256_T *ctx; 208 context_sha256_T *ctx;
209 char_u *input; 209 char_u *input;
210 uint32_t length; 210 UINT32_T length;
211 { 211 {
212 uint32_t left, fill; 212 UINT32_T left, fill;
213 213
214 if (length == 0) 214 if (length == 0)
215 return; 215 return;
216 216
217 left = ctx->total[0] & 0x3F; 217 left = ctx->total[0] & 0x3F;
253 static void 253 static void
254 sha256_finish(ctx, digest) 254 sha256_finish(ctx, digest)
255 context_sha256_T *ctx; 255 context_sha256_T *ctx;
256 char_u digest[32]; 256 char_u digest[32];
257 { 257 {
258 uint32_t last, padn; 258 UINT32_T last, padn;
259 uint32_t high, low; 259 UINT32_T high, low;
260 char_u msglen[8]; 260 char_u msglen[8];
261 261
262 high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); 262 high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
263 low = (ctx->total[0] << 3); 263 low = (ctx->total[0] << 3);
264 264