Mercurial > vim
comparison src/misc2.c @ 2245:4e0124f5aee2 vim73
Optimize the blowfish crypt/decrypt code a bit more.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 02 Jun 2010 20:32:23 +0200 |
parents | caca0ddd789b |
children | c08f91142c41 |
comparison
equal
deleted
inserted
replaced
2244:caca0ddd789b | 2245:4e0124f5aee2 |
---|---|
3766 DECRYPT_BYTE_ZIP(t); | 3766 DECRYPT_BYTE_ZIP(t); |
3767 UPDATE_KEYS_ZIP(ztemp); | 3767 UPDATE_KEYS_ZIP(ztemp); |
3768 to[i] = t ^ ztemp; | 3768 to[i] = t ^ ztemp; |
3769 } | 3769 } |
3770 else | 3770 else |
3771 for (i = 0; i < len; ++i) | 3771 bf_crypt_encode(from, len, to); |
3772 { | |
3773 ztemp = from[i]; | |
3774 t = bf_ranbyte(); | |
3775 bf_ofb_update(ztemp); | |
3776 to[i] = t ^ ztemp; | |
3777 } | |
3778 } | 3772 } |
3779 | 3773 |
3780 /* | 3774 /* |
3781 * Decrypt "ptr[len]" in place. | 3775 * Decrypt "ptr[len]" in place. |
3782 */ | 3776 */ |
3795 temp = (ush)keys[2] | 2; | 3789 temp = (ush)keys[2] | 2; |
3796 temp = (int)(((unsigned)(temp * (temp ^ 1)) >> 8) & 0xff); | 3790 temp = (int)(((unsigned)(temp * (temp ^ 1)) >> 8) & 0xff); |
3797 UPDATE_KEYS_ZIP(*p ^= temp); | 3791 UPDATE_KEYS_ZIP(*p ^= temp); |
3798 } | 3792 } |
3799 else | 3793 else |
3800 for (p = ptr; p < ptr + len; ++p) | 3794 bf_crypt_decode(ptr, len); |
3801 bf_ofb_update(*p ^= bf_ranbyte()); | |
3802 } | 3795 } |
3803 | 3796 |
3804 /* | 3797 /* |
3805 * Initialize the encryption keys and the random header according to | 3798 * Initialize the encryption keys and the random header according to |
3806 * the given password. | 3799 * the given password. |
3810 crypt_init_keys(passwd) | 3803 crypt_init_keys(passwd) |
3811 char_u *passwd; /* password string with which to modify keys */ | 3804 char_u *passwd; /* password string with which to modify keys */ |
3812 { | 3805 { |
3813 if (passwd != NULL && *passwd != NUL) | 3806 if (passwd != NULL && *passwd != NUL) |
3814 { | 3807 { |
3815 make_crc_tab(); | |
3816 keys[0] = 305419896L; | |
3817 keys[1] = 591751049L; | |
3818 keys[2] = 878082192L; | |
3819 if (use_crypt_method == 0) | 3808 if (use_crypt_method == 0) |
3820 while (*passwd != '\0') | 3809 { |
3810 char_u *p; | |
3811 | |
3812 make_crc_tab(); | |
3813 keys[0] = 305419896L; | |
3814 keys[1] = 591751049L; | |
3815 keys[2] = 878082192L; | |
3816 for (p = passwd; *p!= NUL; ++p) | |
3821 { | 3817 { |
3822 UPDATE_KEYS_ZIP((int)*passwd++); | 3818 UPDATE_KEYS_ZIP((int)*p); |
3823 } | 3819 } |
3820 } | |
3824 else | 3821 else |
3825 while (*passwd != '\0') | 3822 bf_crypt_init_keys(passwd); |
3826 bf_ofb_update((int)*passwd++); | |
3827 } | 3823 } |
3828 } | 3824 } |
3829 | 3825 |
3830 /* | 3826 /* |
3831 * Free an allocated crypt key. Clear the text to make sure it doesn't stay | 3827 * Free an allocated crypt key. Clear the text to make sure it doesn't stay |
6318 /* ">>" doesn't work well when shifting more bits than avail */ | 6314 /* ">>" doesn't work well when shifting more bits than avail */ |
6319 putc(0, fd); | 6315 putc(0, fd); |
6320 else | 6316 else |
6321 { | 6317 { |
6322 #if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4 | 6318 #if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4 |
6323 c = wtime >> (i * 8); | 6319 c = (int)(wtime >> (i * 8)); |
6324 #else | 6320 #else |
6325 c = (long_u)wtime >> (i * 8); | 6321 c = (int)((long_u)wtime >> (i * 8)); |
6326 #endif | 6322 #endif |
6327 putc(c, fd); | 6323 putc(c, fd); |
6328 } | 6324 } |
6329 } | 6325 } |
6330 } | 6326 } |