comparison src/sha256.c @ 7835:4d7ce6c03fda v7.4.1214

commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 30 21:10:09 2016 +0100 patch 7.4.1214 Problem: Using old style function declarations. Solution: Change to new style function declarations. (script by Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Sat, 30 Jan 2016 21:15:04 +0100
parents 0b6c37dd858d
children 4aead6a9b7a9
comparison
equal deleted inserted replaced
7834:2d1dc9ec41ce 7835:4d7ce6c03fda
41 (b)[(i) + 2] = (char_u)((n) >> 8); \ 41 (b)[(i) + 2] = (char_u)((n) >> 8); \
42 (b)[(i) + 3] = (char_u)((n) ); \ 42 (b)[(i) + 3] = (char_u)((n) ); \
43 } 43 }
44 44
45 void 45 void
46 sha256_start(ctx) 46 sha256_start(context_sha256_T *ctx)
47 context_sha256_T *ctx;
48 { 47 {
49 ctx->total[0] = 0; 48 ctx->total[0] = 0;
50 ctx->total[1] = 0; 49 ctx->total[1] = 0;
51 50
52 ctx->state[0] = 0x6A09E667; 51 ctx->state[0] = 0x6A09E667;
58 ctx->state[6] = 0x1F83D9AB; 57 ctx->state[6] = 0x1F83D9AB;
59 ctx->state[7] = 0x5BE0CD19; 58 ctx->state[7] = 0x5BE0CD19;
60 } 59 }
61 60
62 static void 61 static void
63 sha256_process(ctx, data) 62 sha256_process(context_sha256_T *ctx, char_u data[64])
64 context_sha256_T *ctx;
65 char_u data[64];
66 { 63 {
67 UINT32_T temp1, temp2, W[64]; 64 UINT32_T temp1, temp2, W[64];
68 UINT32_T A, B, C, D, E, F, G, H; 65 UINT32_T A, B, C, D, E, F, G, H;
69 66
70 GET_UINT32(W[0], data, 0); 67 GET_UINT32(W[0], data, 0);
192 ctx->state[6] += G; 189 ctx->state[6] += G;
193 ctx->state[7] += H; 190 ctx->state[7] += H;
194 } 191 }
195 192
196 void 193 void
197 sha256_update(ctx, input, length) 194 sha256_update(context_sha256_T *ctx, char_u *input, UINT32_T length)
198 context_sha256_T *ctx;
199 char_u *input;
200 UINT32_T length;
201 { 195 {
202 UINT32_T left, fill; 196 UINT32_T left, fill;
203 197
204 if (length == 0) 198 if (length == 0)
205 return; 199 return;
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 233 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 234 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
241 }; 235 };
242 236
243 void 237 void
244 sha256_finish(ctx, digest) 238 sha256_finish(context_sha256_T *ctx, char_u digest[32])
245 context_sha256_T *ctx;
246 char_u digest[32];
247 { 239 {
248 UINT32_T last, padn; 240 UINT32_T last, padn;
249 UINT32_T high, low; 241 UINT32_T high, low;
250 char_u msglen[8]; 242 char_u msglen[8];
251 243
278 /* 270 /*
279 * Returns hex digest of "buf[buf_len]" in a static array. 271 * Returns hex digest of "buf[buf_len]" in a static array.
280 * if "salt" is not NULL also do "salt[salt_len]". 272 * if "salt" is not NULL also do "salt[salt_len]".
281 */ 273 */
282 char_u * 274 char_u *
283 sha256_bytes(buf, buf_len, salt, salt_len) 275 sha256_bytes(
284 char_u *buf; 276 char_u *buf,
285 int buf_len; 277 int buf_len,
286 char_u *salt; 278 char_u *salt,
287 int salt_len; 279 int salt_len)
288 { 280 {
289 char_u sha256sum[32]; 281 char_u sha256sum[32];
290 static char_u hexit[65]; 282 static char_u hexit[65];
291 int j; 283 int j;
292 context_sha256_T ctx; 284 context_sha256_T ctx;
306 298
307 /* 299 /*
308 * Returns sha256(buf) as 64 hex chars in static array. 300 * Returns sha256(buf) as 64 hex chars in static array.
309 */ 301 */
310 char_u * 302 char_u *
311 sha256_key(buf, salt, salt_len) 303 sha256_key(
312 char_u *buf; 304 char_u *buf,
313 char_u *salt; 305 char_u *salt,
314 int salt_len; 306 int salt_len)
315 { 307 {
316 /* No passwd means don't encrypt */ 308 /* No passwd means don't encrypt */
317 if (buf == NULL || *buf == NUL) 309 if (buf == NULL || *buf == NUL)
318 return (char_u *)""; 310 return (char_u *)"";
319 311
342 /* 334 /*
343 * Perform a test on the SHA256 algorithm. 335 * Perform a test on the SHA256 algorithm.
344 * Return FAIL or OK. 336 * Return FAIL or OK.
345 */ 337 */
346 int 338 int
347 sha256_self_test() 339 sha256_self_test(void)
348 { 340 {
349 int i, j; 341 int i, j;
350 char output[65]; 342 char output[65];
351 context_sha256_T ctx; 343 context_sha256_T ctx;
352 char_u buf[1000]; 344 char_u buf[1000];
387 } 379 }
388 return failures > 0 ? FAIL : OK; 380 return failures > 0 ? FAIL : OK;
389 } 381 }
390 382
391 static unsigned int 383 static unsigned int
392 get_some_time() 384 get_some_time(void)
393 { 385 {
394 # ifdef HAVE_GETTIMEOFDAY 386 # ifdef HAVE_GETTIMEOFDAY
395 struct timeval tv; 387 struct timeval tv;
396 388
397 /* Using usec makes it less predictable. */ 389 /* Using usec makes it less predictable. */
405 /* 397 /*
406 * Fill "header[header_len]" with random_data. 398 * Fill "header[header_len]" with random_data.
407 * Also "salt[salt_len]" when "salt" is not NULL. 399 * Also "salt[salt_len]" when "salt" is not NULL.
408 */ 400 */
409 void 401 void
410 sha2_seed(header, header_len, salt, salt_len) 402 sha2_seed(
411 char_u *header; 403 char_u *header,
412 int header_len; 404 int header_len,
413 char_u *salt; 405 char_u *salt,
414 int salt_len; 406 int salt_len)
415 { 407 {
416 int i; 408 int i;
417 static char_u random_data[1000]; 409 static char_u random_data[1000];
418 char_u sha256sum[32]; 410 char_u sha256sum[32];
419 context_sha256_T ctx; 411 context_sha256_T ctx;