Lines Matching defs:ctx

22 static void dh_clear_ctx(struct dh_ctx *ctx)
24 mpi_free(ctx->p);
25 mpi_free(ctx->g);
26 mpi_free(ctx->xa);
27 memset(ctx, 0, sizeof(*ctx));
36 static int _compute_val(const struct dh_ctx *ctx, MPI base, MPI val)
39 return mpi_powm(val, base, ctx->xa, ctx->p);
55 static int dh_set_params(struct dh_ctx *ctx, struct dh *params)
60 ctx->p = mpi_read_raw_data(params->p, params->p_size);
61 if (!ctx->p)
64 ctx->g = mpi_read_raw_data(params->g, params->g_size);
65 if (!ctx->g)
74 struct dh_ctx *ctx = dh_get_ctx(tfm);
78 dh_clear_ctx(ctx);
83 if (dh_set_params(ctx, &params) < 0)
86 ctx->xa = mpi_read_raw_data(params.key, params.key_size);
87 if (!ctx->xa)
93 dh_clear_ctx(ctx);
107 static int dh_is_pubkey_valid(struct dh_ctx *ctx, MPI y)
115 if (unlikely(!ctx->p))
126 if (mpi_cmp_ui(y, 1) < 1 || mpi_cmp(y, ctx->p) >= 0)
138 q = mpi_alloc(mpi_get_nlimbs(ctx->p));
148 mpi_rshift(q, ctx->p, 1);
150 ret = mpi_powm(val, y, q, ctx->p);
170 struct dh_ctx *ctx = dh_get_ctx(tfm);
178 if (unlikely(!ctx->xa)) {
189 ret = dh_is_pubkey_valid(ctx, base);
193 base = ctx->g;
196 ret = _compute_val(ctx, base, val);
219 ret = mpi_sub_ui(pone, ctx->p, 1);
230 if (dh_is_pubkey_valid(ctx, val)) {
253 struct dh_ctx *ctx = dh_get_ctx(tfm);
255 return mpi_get_size(ctx->p);
260 struct dh_ctx *ctx = dh_get_ctx(tfm);
262 dh_clear_ctx(ctx);
300 struct dh_safe_prime_instance_ctx *ctx = kpp_instance_ctx(inst);
302 crypto_drop_kpp(&ctx->dh_spawn);
556 struct dh_safe_prime_instance_ctx *ctx;
570 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
574 ctx = kpp_instance_ctx(inst);
576 err = crypto_grab_kpp(&ctx->dh_spawn, kpp_crypto_instance(inst),
582 dh_alg = crypto_spawn_kpp_alg(&ctx->dh_spawn);
586 ctx->safe_prime = safe_prime;