mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-15 01:57:40 -05:00
Make ssh_key and ssh{2,1}_cipher into structs.
In commit 884a7df94
I claimed that all my trait-like vtable systems
now had the generic object type being a struct rather than a bare
vtable pointer (e.g. instead of 'Socket' being a typedef for a pointer
to a const Socket_vtable, it's a typedef for a struct _containing_ a
vtable pointer).
In fact, I missed a few. This commit converts ssh_key, ssh2_cipher and
ssh1_cipher into the same form as the rest.
This commit is contained in:
34
sshblowf.c
34
sshblowf.c
@ -576,20 +576,20 @@ static void blowfish_iv(BlowfishContext *ctx, const void *viv)
|
||||
struct blowfish_ssh1_ctx {
|
||||
/* In SSH-1, need one key for each direction */
|
||||
BlowfishContext contexts[2];
|
||||
ssh1_cipher vt;
|
||||
ssh1_cipher ciph;
|
||||
};
|
||||
|
||||
static ssh1_cipher *blowfish_ssh1_new(void)
|
||||
{
|
||||
struct blowfish_ssh1_ctx *ctx = snew(struct blowfish_ssh1_ctx);
|
||||
ctx->vt = &ssh1_blowfish;
|
||||
return &ctx->vt;
|
||||
ctx->ciph.vt = &ssh1_blowfish;
|
||||
return &ctx->ciph;
|
||||
}
|
||||
|
||||
static void blowfish_ssh1_free(ssh1_cipher *cipher)
|
||||
{
|
||||
struct blowfish_ssh1_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, ciph);
|
||||
smemclr(ctx, sizeof(*ctx));
|
||||
sfree(ctx);
|
||||
}
|
||||
@ -597,7 +597,7 @@ static void blowfish_ssh1_free(ssh1_cipher *cipher)
|
||||
static void blowfish_ssh1_sesskey(ssh1_cipher *cipher, const void *key)
|
||||
{
|
||||
struct blowfish_ssh1_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, ciph);
|
||||
blowfish_setkey(&ctx->contexts[0], key, SSH1_SESSION_KEY_LENGTH);
|
||||
ctx->contexts[0].iv0 = ctx->contexts[0].iv1 = 0;
|
||||
ctx->contexts[1] = ctx->contexts[0]; /* structure copy */
|
||||
@ -606,33 +606,33 @@ static void blowfish_ssh1_sesskey(ssh1_cipher *cipher, const void *key)
|
||||
static void blowfish_ssh1_encrypt_blk(ssh1_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct blowfish_ssh1_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, ciph);
|
||||
blowfish_lsb_encrypt_cbc(blk, len, ctx->contexts);
|
||||
}
|
||||
|
||||
static void blowfish_ssh1_decrypt_blk(ssh1_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct blowfish_ssh1_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh1_ctx, ciph);
|
||||
blowfish_lsb_decrypt_cbc(blk, len, ctx->contexts+1);
|
||||
}
|
||||
|
||||
struct blowfish_ssh2_ctx {
|
||||
BlowfishContext context;
|
||||
ssh2_cipher vt;
|
||||
ssh2_cipher ciph;
|
||||
};
|
||||
|
||||
static ssh2_cipher *blowfish_ssh2_new(const struct ssh2_cipheralg *alg)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx = snew(struct blowfish_ssh2_ctx);
|
||||
ctx->vt = alg;
|
||||
return &ctx->vt;
|
||||
ctx->ciph.vt = alg;
|
||||
return &ctx->ciph;
|
||||
}
|
||||
|
||||
static void blowfish_ssh2_free(ssh2_cipher *cipher)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, ciph);
|
||||
smemclr(ctx, sizeof(*ctx));
|
||||
sfree(ctx);
|
||||
}
|
||||
@ -640,35 +640,35 @@ static void blowfish_ssh2_free(ssh2_cipher *cipher)
|
||||
static void blowfish_ssh2_setiv(ssh2_cipher *cipher, const void *iv)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, ciph);
|
||||
blowfish_iv(&ctx->context, iv);
|
||||
}
|
||||
|
||||
static void blowfish_ssh2_setkey(ssh2_cipher *cipher, const void *key)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, vt);
|
||||
blowfish_setkey(&ctx->context, key, ctx->vt->padded_keybytes);
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, ciph);
|
||||
blowfish_setkey(&ctx->context, key, ctx->ciph.vt->padded_keybytes);
|
||||
}
|
||||
|
||||
static void blowfish_ssh2_encrypt_blk(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, ciph);
|
||||
blowfish_msb_encrypt_cbc(blk, len, &ctx->context);
|
||||
}
|
||||
|
||||
static void blowfish_ssh2_decrypt_blk(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, ciph);
|
||||
blowfish_msb_decrypt_cbc(blk, len, &ctx->context);
|
||||
}
|
||||
|
||||
static void blowfish_ssh2_sdctr(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct blowfish_ssh2_ctx *ctx =
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, vt);
|
||||
container_of(cipher, struct blowfish_ssh2_ctx, ciph);
|
||||
blowfish_msb_sdctr(blk, len, &ctx->context);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user