X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/3755c313abec360a00ca7a84ce0b2f8db915d059..c2e3a6c92d062f019a60fa97d339db80fa0d88a3:/sshblowf.c diff --git a/sshblowf.c b/sshblowf.c index 9cbeed4f..650f9b9f 100644 --- a/sshblowf.c +++ b/sshblowf.c @@ -413,6 +413,32 @@ static void blowfish_msb_decrypt_cbc(unsigned char *blk, int len, ctx->iv1 = iv1; } +static void blowfish_msb_sdctr(unsigned char *blk, int len, + BlowfishContext * ctx) +{ + word32 b[2], iv0, iv1, tmp; + + assert((len & 7) == 0); + + iv0 = ctx->iv0; + iv1 = ctx->iv1; + + while (len > 0) { + blowfish_encrypt(iv0, iv1, b, ctx); + tmp = GET_32BIT_MSB_FIRST(blk); + PUT_32BIT_MSB_FIRST(blk, tmp ^ b[0]); + tmp = GET_32BIT_MSB_FIRST(blk + 4); + PUT_32BIT_MSB_FIRST(blk + 4, tmp ^ b[1]); + if ((iv0 = (iv0 + 1) & 0xffffffff) == 0) + iv1 = (iv1 + 1) & 0xffffffff; + blk += 8; + len -= 8; + } + + ctx->iv0 = iv0; + ctx->iv1 = iv1; +} + static void blowfish_setkey(BlowfishContext * ctx, const unsigned char *key, short keybytes) { @@ -498,6 +524,12 @@ static void blowfish_key(void *handle, unsigned char *key) blowfish_setkey(ctx, key, 16); } +static void blowfish256_key(void *handle, unsigned char *key) +{ + BlowfishContext *ctx = (BlowfishContext *)handle; + blowfish_setkey(ctx, key, 32); +} + static void blowfish_iv(void *handle, unsigned char *key) { BlowfishContext *ctx = (BlowfishContext *)handle; @@ -542,20 +574,41 @@ static void blowfish_ssh2_decrypt_blk(void *handle, unsigned char *blk, blowfish_msb_decrypt_cbc(blk, len, ctx); } +static void blowfish_ssh2_sdctr(void *handle, unsigned char *blk, + int len) +{ + BlowfishContext *ctx = (BlowfishContext *)handle; + blowfish_msb_sdctr(blk, len, ctx); +} + const struct ssh_cipher ssh_blowfish_ssh1 = { blowfish_ssh1_make_context, blowfish_free_context, blowfish_sesskey, blowfish_ssh1_encrypt_blk, blowfish_ssh1_decrypt_blk, - 8, "Blowfish" + 8, "Blowfish-128 CBC" }; static const struct ssh2_cipher ssh_blowfish_ssh2 = { blowfish_make_context, blowfish_free_context, blowfish_iv, blowfish_key, blowfish_ssh2_encrypt_blk, blowfish_ssh2_decrypt_blk, "blowfish-cbc", - 8, 128, "Blowfish" + 8, 128, "Blowfish-128 CBC" }; +static const struct ssh2_cipher ssh_blowfish_ssh2_ctr = { + blowfish_make_context, blowfish_free_context, blowfish_iv, blowfish256_key, + blowfish_ssh2_sdctr, blowfish_ssh2_sdctr, + "blowfish-ctr", + 8, 256, "Blowfish-256 SDCTR" +}; + +/* + * "blowfish-ctr" is disabled because it hasn't had any interoperability + * testing, which is in turn because I couldn't find another implementation + * to test against. Once it's been tested, it can be enabled in standard + * builds. + */ static const struct ssh2_cipher *const blowfish_list[] = { +/* &ssh_blowfish_ssh2_ctr, */ &ssh_blowfish_ssh2 };