comparison src/blowfish.c @ 2182:3cb515c62e9c vim73

Minor updates to blowfish encryption.
author Bram Moolenaar <bram@vim.org>
date Sun, 16 May 2010 23:02:33 +0200
parents f60a0c9cbe6c
children 5028c4d6d825
comparison
equal deleted inserted replaced
2180:f60a0c9cbe6c 2182:3cb515c62e9c
1 /* vi:set ts=8 sts=4 sw=4: 1 /* vi:set ts=8 sts=4 sw=4:
2 * 2 *
3 * Blowfish encryption for vim; in Blowfish output feedback mode. 3 * Blowfish encryption for Vim; in Blowfish output feedback mode.
4 * GPL(C) Mohsin Ahmed, http://www.cs.albany.edu/~mosh 4 * GPL(C) Mohsin Ahmed, http://www.cs.albany.edu/~mosh
5 * Based on http://www.schneier.com/blowfish.html by Bruce Schneier. 5 * Based on http://www.schneier.com/blowfish.html by Bruce Schneier.
6 */ 6 */
7 7
8 #include "vim.h" 8 #include "vim.h"
397 bf_key_init(password) 397 bf_key_init(password)
398 char_u *password; 398 char_u *password;
399 { 399 {
400 int i, j, keypos = 0; 400 int i, j, keypos = 0;
401 long_u val, data_l, data_r; 401 long_u val, data_l, data_r;
402 char *key; 402 char_u *key;
403 int keylen; 403 int keylen;
404 404
405 key = sha256_key((char *)password); 405 key = sha256_key(password);
406 keylen = STRLEN(key); 406 keylen = STRLEN(key);
407 for (i = 0; i < 256; ++i) 407 for (i = 0; i < 256; ++i)
408 { 408 {
409 sbx[0][i] = sbi[0][i]; 409 sbx[0][i] = sbi[0][i];
410 sbx[1][i] = sbi[1][i]; 410 sbx[1][i] = sbi[1][i];
414 414
415 for (i = 0; i < 18; ++i) 415 for (i = 0; i < 18; ++i)
416 { 416 {
417 val = 0; 417 val = 0;
418 for (j = 0; j < 4; ++j) 418 for (j = 0; j < 4; ++j)
419 val = (val << 8) | (key[keypos++ % keylen] & 0xff); 419 val = (val << 8) | key[keypos++ % keylen];
420 pax[i] = ipa[i] ^ val; 420 pax[i] = ipa[i] ^ val;
421 } 421 }
422 422
423 data_l = data_r = 0; 423 data_l = data_r = 0;
424 for (i = 0; i < 18; i += 2) 424 for (i = 0; i < 18; i += 2)