mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12:48 -05:00
Merge the ssh1_cipher type into ssh2_cipher.
The aim of this reorganisation is to make it easier to test all the ciphers in PuTTY in a uniform way. It was inconvenient that there were two separate vtable systems for the ciphers used in SSH-1 and SSH-2 with different functionality. Now there's only one type, called ssh_cipher. But really it's the old ssh2_cipher, just renamed: I haven't made any changes to the API on the SSH-2 side. Instead, I've removed ssh1_cipher completely, and adapted the SSH-1 BPP to use the SSH-2 style API. (The relevant differences are that ssh1_cipher encapsulated both the sending and receiving directions in one object - so now ssh1bpp has to make a separate cipher instance per direction - and that ssh1_cipher automatically initialised the IV to all zeroes, which ssh1bpp now has to do by hand.) The previous ssh1_cipher vtable for single-DES has been removed completely, because when converted into the new API it became identical to the SSH-2 single-DES vtable; so now there's just one vtable for DES-CBC which works in both protocols. The other two SSH-1 ciphers each had to stay separate, because 3DES is completely different between SSH-1 and SSH-2 (three layers of CBC structure versus one), and Blowfish varies in endianness and key length between the two. (Actually, while I'm here, I've only just noticed that the SSH-1 Blowfish cipher mis-describes itself in log messages as Blowfish-128. In fact it passes the whole of the input key buffer, which has length SSH1_SESSION_KEY_LENGTH == 32 bytes == 256 bits. So it's actually Blowfish-256, and has been all along!)
This commit is contained in:
34
import.c
34
import.c
@ -547,11 +547,11 @@ static ssh2_userkey *openssh_pem_read(
|
||||
des3_decrypt_pubkey_ossh(keybuf, key->iv,
|
||||
key->keyblob->u, key->keyblob->len);
|
||||
else {
|
||||
ssh2_cipher *cipher = ssh2_cipher_new(&ssh_aes128_cbc);
|
||||
ssh2_cipher_setkey(cipher, keybuf);
|
||||
ssh2_cipher_setiv(cipher, key->iv);
|
||||
ssh2_cipher_decrypt(cipher, key->keyblob->u, key->keyblob->len);
|
||||
ssh2_cipher_free(cipher);
|
||||
ssh_cipher *cipher = ssh_cipher_new(&ssh_aes128_cbc);
|
||||
ssh_cipher_setkey(cipher, keybuf);
|
||||
ssh_cipher_setiv(cipher, key->iv);
|
||||
ssh_cipher_decrypt(cipher, key->keyblob->u, key->keyblob->len);
|
||||
ssh_cipher_free(cipher);
|
||||
}
|
||||
|
||||
smemclr(&md5c, sizeof(md5c));
|
||||
@ -1388,16 +1388,16 @@ static ssh2_userkey *openssh_new_read(
|
||||
goto error;
|
||||
}
|
||||
{
|
||||
ssh2_cipher *cipher = ssh2_cipher_new(
|
||||
ssh_cipher *cipher = ssh_cipher_new(
|
||||
key->cipher == ON_E_AES256CBC ?
|
||||
&ssh_aes256_cbc : &ssh_aes256_sdctr);
|
||||
ssh2_cipher_setkey(cipher, keybuf);
|
||||
ssh2_cipher_setiv(cipher, keybuf + 32);
|
||||
ssh_cipher_setkey(cipher, keybuf);
|
||||
ssh_cipher_setiv(cipher, keybuf + 32);
|
||||
/* Decrypt the private section in place, casting away
|
||||
* the const from key->private being a ptrlen */
|
||||
ssh2_cipher_decrypt(cipher, (char *)key->private.ptr,
|
||||
key->private.len);
|
||||
ssh2_cipher_free(cipher);
|
||||
ssh_cipher_decrypt(cipher, (char *)key->private.ptr,
|
||||
key->private.len);
|
||||
ssh_cipher_free(cipher);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1588,17 +1588,17 @@ static bool openssh_new_write(
|
||||
* material: 32 bytes AES key + 16 bytes iv.
|
||||
*/
|
||||
unsigned char keybuf[48];
|
||||
ssh2_cipher *cipher;
|
||||
ssh_cipher *cipher;
|
||||
|
||||
openssh_bcrypt(passphrase,
|
||||
bcrypt_salt, sizeof(bcrypt_salt), bcrypt_rounds,
|
||||
keybuf, sizeof(keybuf));
|
||||
|
||||
cipher = ssh2_cipher_new(&ssh_aes256_sdctr);
|
||||
ssh2_cipher_setkey(cipher, keybuf);
|
||||
ssh2_cipher_setiv(cipher, keybuf + 32);
|
||||
ssh2_cipher_encrypt(cipher, cpblob->u, cpblob->len);
|
||||
ssh2_cipher_free(cipher);
|
||||
cipher = ssh_cipher_new(&ssh_aes256_sdctr);
|
||||
ssh_cipher_setkey(cipher, keybuf);
|
||||
ssh_cipher_setiv(cipher, keybuf + 32);
|
||||
ssh_cipher_encrypt(cipher, cpblob->u, cpblob->len);
|
||||
ssh_cipher_free(cipher);
|
||||
|
||||
smemclr(keybuf, sizeof(keybuf));
|
||||
}
|
||||
|
Reference in New Issue
Block a user