1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Single-DES encryption, patch courtesy of Murphy Lam

[originally from svn r253]
This commit is contained in:
Simon Tatham 1999-10-25 08:59:40 +00:00
parent 2da19fc59d
commit 2d6fcb0a7a
7 changed files with 54 additions and 5 deletions

View File

@ -97,7 +97,7 @@ typedef struct {
int close_on_exit;
/* SSH options */
int nopty;
enum { CIPHER_3DES, CIPHER_BLOWFISH } cipher;
enum { CIPHER_3DES, CIPHER_BLOWFISH, CIPHER_DES } cipher;
/* Telnet options */
char termtype[32];
char termspeed[32];

22
ssh.c
View File

@ -213,6 +213,21 @@ static void s_wrpkt(void) {
s_write(pktout.data, biglen+4);
}
static int ssh_versioncmp(char *a, char *b) {
char *ae, *be;
unsigned long av, bv;
av = strtoul(a, &ae);
bv = strtoul(b, &be);
if (av != bv) return (av < bv ? -1 : +1);
if (*ae == '.') ae++;
if (*be == '.') be++;
av = strtoul(ae, &ae);
bv = strtoul(be, &be);
if (av != bv) return (av < bv ? -1 : +1);
return 0;
}
static int do_ssh_init(void) {
char c;
char version[10];
@ -248,8 +263,8 @@ static int do_ssh_init(void) {
break;
}
sprintf(vstring, "SSH-%s-7.7.7\n",
(strcmp(version, "1.5") <= 0 ? version : "1.5"));
sprintf(vstring, "SSH-%s-PuTTY\n",
(ssh_versioncmp(version, "1.5") <= 0 ? version : "1.5"));
s_write(vstring, strlen(vstring));
return 1;
}
@ -265,6 +280,7 @@ static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
int cipher_type;
extern struct ssh_cipher ssh_3des;
extern struct ssh_cipher ssh_des;
extern struct ssh_cipher ssh_blowfish;
crBegin;
@ -322,6 +338,7 @@ static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
}
cipher_type = cfg.cipher == CIPHER_BLOWFISH ? SSH_CIPHER_BLOWFISH :
cfg.cipher == CIPHER_DES ? SSH_CIPHER_DES :
SSH_CIPHER_3DES;
if ((supported_ciphers_mask & (1 << cipher_type)) == 0) {
c_write("Selected cipher not supported, falling back to 3DES\r\n", 53);
@ -341,6 +358,7 @@ static void ssh_protocol(unsigned char *in, int inlen, int ispkt) {
free(rsabuf);
cipher = cipher_type == SSH_CIPHER_BLOWFISH ? &ssh_blowfish :
cipher_type == SSH_CIPHER_DES ? &ssh_des :
&ssh_3des;
cipher->sesskey(session_key);

1
ssh.h
View File

@ -1,6 +1,7 @@
#include <string.h>
#define SSH_CIPHER_IDEA 1
#define SSH_CIPHER_DES 2
#define SSH_CIPHER_3DES 3
#define SSH_CIPHER_BLOWFISH 6

View File

@ -673,6 +673,27 @@ struct ssh_cipher ssh_3des = {
des3_decrypt_blk
};
static void des_sesskey(unsigned char *key) {
des_set_key(key, &ekey1);
memset(eiv1, 0, sizeof(eiv1));
des_set_key(key, &dkey1);
memset(div1, 0, sizeof(div1));
}
static void des_encrypt_blk(unsigned char *blk, int len) {
des_cbc_encrypt(&ekey1, eiv1, blk, blk, len);
}
static void des_decrypt_blk(unsigned char *blk, int len) {
des_cbc_decrypt(&dkey1, div1, blk, blk, len);
}
struct ssh_cipher ssh_des = {
des_sesskey,
des_encrypt_blk,
des_decrypt_blk
};
#ifdef DES_TEST
void des_encrypt_buf(DESContext *ks, unsigned char *out,

View File

@ -99,6 +99,7 @@
#define IDC3_CIPHERSTATIC 1019
#define IDC3_CIPHER3DES 1020
#define IDC3_CIPHERBLOWF 1021
#define IDC3_CIPHERDES 1022
#define IDC4_MBSTATIC 1001
#define IDC4_MBWINDOWS 1002

View File

@ -163,6 +163,7 @@ BEGIN
LTEXT "Cipher:", IDC3_CIPHERSTATIC, 3, 50, 40, 8
AUTORADIOBUTTON "&3DES", IDC3_CIPHER3DES, 46, 50, 35, 10, WS_GROUP
AUTORADIOBUTTON "&Blowfish", IDC3_CIPHERBLOWF, 84, 50, 40, 10
AUTORADIOBUTTON "&DES", IDC3_CIPHERDES, 127, 50, 30, 10
END
IDD_PANEL4 DIALOG DISCARDABLE 6, 30, 168, 163

View File

@ -148,7 +148,7 @@ static void save_settings (char *section, int do_host) {
wpps (sesskey, "UserName", cfg.username);
wppi (sesskey, "NoPTY", cfg.nopty);
wpps (sesskey, "Cipher", cfg.cipher == CIPHER_BLOWFISH ? "blowfish" :
"3des");
cfg.cipher == CIPHER_DES ? "des" : "3des");
wppi (sesskey, "RFCEnviron", cfg.rfc_environ);
wppi (sesskey, "BackspaceIsDelete", cfg.bksp_is_delete);
wppi (sesskey, "RXVTHomeEnd", cfg.rxvt_homeend);
@ -270,6 +270,8 @@ static void load_settings (char *section, int do_host) {
gpps (sesskey, "Cipher", "3des", cipher, 10);
if (!strcmp(cipher, "blowfish"))
cfg.cipher = CIPHER_BLOWFISH;
else if (!strcmp(cipher, "des"))
cfg.cipher = CIPHER_DES;
else
cfg.cipher = CIPHER_3DES;
}
@ -874,8 +876,10 @@ static int CALLBACK SshProc (HWND hwnd, UINT msg,
SetDlgItemText (hwnd, IDC3_TTEDIT, cfg.termtype);
SetDlgItemText (hwnd, IDC3_LOGEDIT, cfg.username);
CheckDlgButton (hwnd, IDC3_NOPTY, cfg.nopty);
CheckRadioButton (hwnd, IDC3_CIPHER3DES, IDC3_CIPHERBLOWF,
CheckRadioButton (hwnd, IDC3_CIPHER3DES, IDC3_CIPHERDES,
cfg.cipher == CIPHER_BLOWFISH ? IDC3_CIPHERBLOWF :
cfg.cipher == CIPHER_DES ? IDC3_CIPHERDES :
IDC3_CIPHER3DES);
break;
case WM_COMMAND:
@ -897,12 +901,15 @@ static int CALLBACK SshProc (HWND hwnd, UINT msg,
break;
case IDC3_CIPHER3DES:
case IDC3_CIPHERBLOWF:
case IDC3_CIPHERDES:
if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) {
if (IsDlgButtonChecked (hwnd, IDC3_CIPHER3DES))
cfg.cipher = CIPHER_3DES;
else if (IsDlgButtonChecked (hwnd, IDC3_CIPHERBLOWF))
cfg.cipher = CIPHER_BLOWFISH;
else if (IsDlgButtonChecked (hwnd, IDC3_CIPHERDES))
cfg.cipher = CIPHER_DES;
}
break;
}