X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/32874aeac8dacbca26663777b39a79efc5d8dc4b..5a71c4ea7cbe7888e3dc79cea7b06cf56b0fecb5:/sshdes.c diff --git a/sshdes.c b/sshdes.c index 44fbf003..9cb9cfa6 100644 --- a/sshdes.c +++ b/sshdes.c @@ -757,6 +757,13 @@ static void des3_cskey(unsigned char *key) logevent("Initialised triple-DES client->server encryption"); } +static void des_cskey(unsigned char *key) +{ + des_key_setup(GET_32BIT_MSB_FIRST(key), + GET_32BIT_MSB_FIRST(key + 4), &cskeys[0]); + logevent("Initialised single-DES client->server encryption"); +} + static void des3_csiv(unsigned char *key) { cskeys[0].eiv0 = GET_32BIT_MSB_FIRST(key); @@ -780,6 +787,13 @@ static void des3_sckey(unsigned char *key) logevent("Initialised triple-DES server->client encryption"); } +static void des_sckey(unsigned char *key) +{ + des_key_setup(GET_32BIT_MSB_FIRST(key), + GET_32BIT_MSB_FIRST(key + 4), &sckeys[0]); + logevent("Initialised single-DES server->client encryption"); +} + static void des3_sesskey(unsigned char *key) { des3_cskey(key); @@ -806,6 +820,16 @@ static void des3_ssh2_decrypt_blk(unsigned char *blk, int len) des_cbc3_decrypt(blk, blk, len, sckeys); } +static void des_ssh2_encrypt_blk(unsigned char *blk, int len) +{ + des_cbc_encrypt(blk, blk, len, cskeys); +} + +static void des_ssh2_decrypt_blk(unsigned char *blk, int len) +{ + des_cbc_decrypt(blk, blk, len, sckeys); +} + void des3_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len) { DESContext ourkeys[3]; @@ -816,6 +840,7 @@ void des3_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len) des_key_setup(GET_32BIT_MSB_FIRST(key), GET_32BIT_MSB_FIRST(key + 4), &ourkeys[2]); des_3cbc_decrypt(blk, blk, len, ourkeys); + memset(ourkeys, 0, sizeof(ourkeys)); } void des3_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len) @@ -828,6 +853,39 @@ void des3_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len) des_key_setup(GET_32BIT_MSB_FIRST(key), GET_32BIT_MSB_FIRST(key + 4), &ourkeys[2]); des_3cbc_encrypt(blk, blk, len, ourkeys); + memset(ourkeys, 0, sizeof(ourkeys)); +} + +void des3_decrypt_pubkey_ossh(unsigned char *key, unsigned char *iv, + unsigned char *blk, int len) +{ + DESContext ourkeys[3]; + des_key_setup(GET_32BIT_MSB_FIRST(key), + GET_32BIT_MSB_FIRST(key + 4), &ourkeys[0]); + des_key_setup(GET_32BIT_MSB_FIRST(key + 8), + GET_32BIT_MSB_FIRST(key + 12), &ourkeys[1]); + des_key_setup(GET_32BIT_MSB_FIRST(key + 16), + GET_32BIT_MSB_FIRST(key + 20), &ourkeys[2]); + ourkeys[0].div0 = GET_32BIT_MSB_FIRST(iv); + ourkeys[0].div1 = GET_32BIT_MSB_FIRST(iv+4); + des_cbc3_decrypt(blk, blk, len, ourkeys); + memset(ourkeys, 0, sizeof(ourkeys)); +} + +void des3_encrypt_pubkey_ossh(unsigned char *key, unsigned char *iv, + unsigned char *blk, int len) +{ + DESContext ourkeys[3]; + des_key_setup(GET_32BIT_MSB_FIRST(key), + GET_32BIT_MSB_FIRST(key + 4), &ourkeys[0]); + des_key_setup(GET_32BIT_MSB_FIRST(key + 8), + GET_32BIT_MSB_FIRST(key + 12), &ourkeys[1]); + des_key_setup(GET_32BIT_MSB_FIRST(key + 16), + GET_32BIT_MSB_FIRST(key + 20), &ourkeys[2]); + ourkeys[0].eiv0 = GET_32BIT_MSB_FIRST(iv); + ourkeys[0].eiv1 = GET_32BIT_MSB_FIRST(iv+4); + des_cbc3_encrypt(blk, blk, len, ourkeys); + memset(ourkeys, 0, sizeof(ourkeys)); } static const struct ssh2_cipher ssh_3des_ssh2 = { @@ -839,6 +897,20 @@ static const struct ssh2_cipher ssh_3des_ssh2 = { 8, 168 }; +/* + * Single DES in ssh2. It isn't clear that "des-cbc" is an official + * cipher name, but ssh.com support it and apparently aren't the + * only people to do so, so we sigh and implement it anyway. + */ +static const struct ssh2_cipher ssh_des_ssh2 = { + des3_csiv, des_cskey, /* iv functions shared with 3des */ + des3_sciv, des_sckey, + des_ssh2_encrypt_blk, + des_ssh2_decrypt_blk, + "des-cbc", + 8, 56 +}; + static const struct ssh2_cipher *const des3_list[] = { &ssh_3des_ssh2 }; @@ -848,6 +920,15 @@ const struct ssh2_ciphers ssh2_3des = { des3_list }; +static const struct ssh2_cipher *const des_list[] = { + &ssh_des_ssh2 +}; + +const struct ssh2_ciphers ssh2_des = { + sizeof(des3_list) / sizeof(*des_list), + des_list +}; + const struct ssh_cipher ssh_3des = { des3_sesskey, des3_encrypt_blk, @@ -857,9 +938,8 @@ const struct ssh_cipher ssh_3des = { static void des_sesskey(unsigned char *key) { - des_key_setup(GET_32BIT_MSB_FIRST(key), - GET_32BIT_MSB_FIRST(key + 4), &cskeys[0]); - logevent("Initialised single-DES encryption"); + des_cskey(key); + des_sckey(key); } static void des_encrypt_blk(unsigned char *blk, int len)