mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
Rename FROMFIELD to 'container_of'.
Ian Jackson points out that the Linux kernel has a macro of this name with the same purpose, and suggests that it's a good idea to use the same name as they do, so that at least some people reading one code base might recognise it from the other. I never really thought very hard about what order FROMFIELD's parameters should go in, and therefore I'm pleasantly surprised to find that my order agrees with the kernel's, so I don't have to permute every call site as part of making this change :-)
This commit is contained in:
38
sshdes.c
38
sshdes.c
@ -800,53 +800,53 @@ static ssh1_cipher *des_ssh1_new(void)
|
||||
|
||||
static void des3_ssh1_free(ssh1_cipher *cipher)
|
||||
{
|
||||
struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt);
|
||||
struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt);
|
||||
smemclr(ctx, sizeof(*ctx));
|
||||
sfree(ctx);
|
||||
}
|
||||
|
||||
static void des_ssh1_free(ssh1_cipher *cipher)
|
||||
{
|
||||
struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt);
|
||||
struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt);
|
||||
smemclr(ctx, sizeof(*ctx));
|
||||
sfree(ctx);
|
||||
}
|
||||
|
||||
static void des3_ssh1_sesskey(ssh1_cipher *cipher, const void *key)
|
||||
{
|
||||
struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt);
|
||||
struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt);
|
||||
des3_key(ctx->contexts, key);
|
||||
des3_key(ctx->contexts+3, key);
|
||||
}
|
||||
|
||||
static void des3_ssh1_encrypt_blk(ssh1_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt);
|
||||
struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt);
|
||||
des_3cbc_encrypt(blk, len, ctx->contexts);
|
||||
}
|
||||
|
||||
static void des3_ssh1_decrypt_blk(ssh1_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt);
|
||||
struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt);
|
||||
des_3cbc_decrypt(blk, len, ctx->contexts+3);
|
||||
}
|
||||
|
||||
static void des_ssh1_sesskey(ssh1_cipher *cipher, const void *key)
|
||||
{
|
||||
struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt);
|
||||
struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt);
|
||||
des_key(ctx->contexts, key);
|
||||
des_key(ctx->contexts+1, key);
|
||||
}
|
||||
|
||||
static void des_ssh1_encrypt_blk(ssh1_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt);
|
||||
struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt);
|
||||
des_cbc_encrypt(blk, len, ctx->contexts);
|
||||
}
|
||||
|
||||
static void des_ssh1_decrypt_blk(ssh1_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt);
|
||||
struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt);
|
||||
des_cbc_decrypt(blk, len, ctx->contexts+1);
|
||||
}
|
||||
|
||||
@ -876,21 +876,21 @@ static ssh2_cipher *des_ssh2_new(const struct ssh2_cipheralg *alg)
|
||||
|
||||
static void des3_ssh2_free(ssh2_cipher *cipher)
|
||||
{
|
||||
struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt);
|
||||
struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt);
|
||||
smemclr(ctx, sizeof(*ctx));
|
||||
sfree(ctx);
|
||||
}
|
||||
|
||||
static void des_ssh2_free(ssh2_cipher *cipher)
|
||||
{
|
||||
struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt);
|
||||
struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt);
|
||||
smemclr(ctx, sizeof(*ctx));
|
||||
sfree(ctx);
|
||||
}
|
||||
|
||||
static void des3_ssh2_setiv(ssh2_cipher *cipher, const void *iv)
|
||||
{
|
||||
struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt);
|
||||
struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt);
|
||||
des_iv(&ctx->contexts[0], iv);
|
||||
/* SSH-2 treats triple-DES as a single block cipher to wrap in
|
||||
* CBC, so there's only one IV required, not three */
|
||||
@ -898,49 +898,49 @@ static void des3_ssh2_setiv(ssh2_cipher *cipher, const void *iv)
|
||||
|
||||
static void des3_ssh2_setkey(ssh2_cipher *cipher, const void *key)
|
||||
{
|
||||
struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt);
|
||||
struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt);
|
||||
des3_key(ctx->contexts, key);
|
||||
}
|
||||
|
||||
static void des_ssh2_setiv(ssh2_cipher *cipher, const void *iv)
|
||||
{
|
||||
struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt);
|
||||
struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt);
|
||||
des_iv(&ctx->context, iv);
|
||||
}
|
||||
|
||||
static void des_ssh2_setkey(ssh2_cipher *cipher, const void *key)
|
||||
{
|
||||
struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt);
|
||||
struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt);
|
||||
des_key(&ctx->context, key);
|
||||
}
|
||||
|
||||
static void des3_ssh2_encrypt_blk(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt);
|
||||
struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt);
|
||||
des_cbc3_encrypt(blk, len, ctx->contexts);
|
||||
}
|
||||
|
||||
static void des3_ssh2_decrypt_blk(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt);
|
||||
struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt);
|
||||
des_cbc3_decrypt(blk, len, ctx->contexts);
|
||||
}
|
||||
|
||||
static void des3_ssh2_sdctr(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt);
|
||||
struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt);
|
||||
des_sdctr3(blk, len, ctx->contexts);
|
||||
}
|
||||
|
||||
static void des_ssh2_encrypt_blk(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt);
|
||||
struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt);
|
||||
des_cbc_encrypt(blk, len, &ctx->context);
|
||||
}
|
||||
|
||||
static void des_ssh2_decrypt_blk(ssh2_cipher *cipher, void *blk, int len)
|
||||
{
|
||||
struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt);
|
||||
struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt);
|
||||
des_cbc_decrypt(blk, len, &ctx->context);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user