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