From 9697bfd21dde432bf41956e73f73c162eff352a8 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 25 Oct 1999 08:59:40 +0000 Subject: [PATCH] Single-DES encryption, patch courtesy of Murphy Lam git-svn-id: svn://svn.tartarus.org/sgt/putty@253 cda61777-01e9-0310-a592-d414129be87e --- putty.h | 2 +- ssh.c | 22 ++++++++++++++++++++-- ssh.h | 1 + sshdes.c | 21 +++++++++++++++++++++ win_res.h | 1 + win_res.rc | 1 + windlg.c | 11 +++++++++-- 7 files changed, 54 insertions(+), 5 deletions(-) diff --git a/putty.h b/putty.h index 0ca50aa5..56f504c0 100644 --- a/putty.h +++ b/putty.h @@ -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]; diff --git a/ssh.c b/ssh.c index 0d53ddbf..edac1822 100644 --- a/ssh.c +++ b/ssh.c @@ -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); diff --git a/ssh.h b/ssh.h index a252ef83..2aac8560 100644 --- a/ssh.h +++ b/ssh.h @@ -1,6 +1,7 @@ #include #define SSH_CIPHER_IDEA 1 +#define SSH_CIPHER_DES 2 #define SSH_CIPHER_3DES 3 #define SSH_CIPHER_BLOWFISH 6 diff --git a/sshdes.c b/sshdes.c index 3be52749..aa6b94f6 100644 --- a/sshdes.c +++ b/sshdes.c @@ -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, diff --git a/win_res.h b/win_res.h index a956cfa7..ae5c554e 100644 --- a/win_res.h +++ b/win_res.h @@ -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 diff --git a/win_res.rc b/win_res.rc index b89b6b51..61e19dd0 100644 --- a/win_res.rc +++ b/win_res.rc @@ -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 diff --git a/windlg.c b/windlg.c index e7d58fd6..d13a8c43 100644 --- a/windlg.c +++ b/windlg.c @@ -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; } -- 2.11.0