Lines Matching defs:ctx

25 static int gen_init(EVP_PKEY_CTX *ctx, int operation)
29 if (ctx == NULL)
32 evp_pkey_ctx_free_old_ops(ctx);
33 ctx->operation = operation;
35 if (ctx->keymgmt == NULL || ctx->keymgmt->gen_init == NULL)
40 ctx->op.keymgmt.genctx =
41 evp_keymgmt_gen_init(ctx->keymgmt,
45 ctx->op.keymgmt.genctx =
46 evp_keymgmt_gen_init(ctx->keymgmt, OSSL_KEYMGMT_SELECT_KEYPAIR,
51 if (ctx->op.keymgmt.genctx == NULL)
61 if (ctx->pmeth == NULL
63 && ctx->pmeth->paramgen == NULL)
65 && ctx->pmeth->keygen == NULL))
71 if (ctx->pmeth->paramgen_init != NULL)
72 ret = ctx->pmeth->paramgen_init(ctx);
75 if (ctx->pmeth->keygen_init != NULL)
76 ret = ctx->pmeth->keygen_init(ctx);
82 if (ret <= 0 && ctx != NULL) {
83 evp_pkey_ctx_free_old_ops(ctx);
84 ctx->operation = EVP_PKEY_OP_UNDEFINED;
94 int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx)
96 return gen_init(ctx, EVP_PKEY_OP_PARAMGEN);
99 int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx)
101 return gen_init(ctx, EVP_PKEY_OP_KEYGEN);
106 EVP_PKEY_CTX *ctx = arg;
110 if (ctx->pkey_gencb == NULL)
122 ctx->keygen_info[0] = p;
123 ctx->keygen_info[1] = n;
125 return ctx->pkey_gencb(ctx);
128 int EVP_PKEY_generate(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
138 if (ctx == NULL)
141 if ((ctx->operation & EVP_PKEY_OP_TYPE_GEN) == 0)
152 if (ctx->op.keymgmt.genctx == NULL)
156 * Asssigning gentmp to ctx->keygen_info is something our legacy
164 ctx->keygen_info = gentmp;
165 ctx->keygen_info_count = 2;
168 if (ctx->pkey != NULL) {
169 EVP_KEYMGMT *tmp_keymgmt = ctx->keymgmt;
171 evp_pkey_export_to_provider(ctx->pkey, ctx->libctx,
172 &tmp_keymgmt, ctx->propquery);
180 ret = evp_keymgmt_gen_set_template(ctx->keymgmt,
181 ctx->op.keymgmt.genctx, keydata);
189 && (evp_keymgmt_util_gen(*ppkey, ctx->keymgmt, ctx->op.keymgmt.genctx,
190 ossl_callback_to_pkey_gencb, ctx)
193 ctx->keygen_info = NULL;
204 (*ppkey)->type = ctx->legacy_keytype;
214 * the pkey in ctx (if there is one) had better not be provided (because the
216 * here if ctx->op.keymgmt.genctx == NULL, but that should never be the case
217 * if ctx->pkey is provided because we don't allow this when we initialise
218 * the ctx.
220 if (ctx->pkey != NULL && !ossl_assert(!evp_pkey_is_provided(ctx->pkey)))
223 switch (ctx->operation) {
225 ret = ctx->pmeth->paramgen(ctx, *ppkey);
228 ret = ctx->pmeth->keygen(ctx, *ppkey);
259 int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
261 if (ctx->operation != EVP_PKEY_OP_PARAMGEN) {
265 return EVP_PKEY_generate(ctx, ppkey);
268 int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
270 if (ctx->operation != EVP_PKEY_OP_KEYGEN) {
274 return EVP_PKEY_generate(ctx, ppkey);
277 void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb)
279 ctx->pkey_gencb = cb;
282 EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx)
284 return ctx->pkey_gencb;
294 EVP_PKEY_CTX *ctx = BN_GENCB_get_arg(gcb);
295 ctx->keygen_info[0] = a;
296 ctx->keygen_info[1] = b;
297 return ctx->pkey_gencb(ctx);
300 void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx)
302 BN_GENCB_set(cb, trans_cb, ctx);
305 int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx)
308 return ctx->keygen_info_count;
309 if (idx < 0 || idx > ctx->keygen_info_count)
311 return ctx->keygen_info[idx];
339 static int fromdata_init(EVP_PKEY_CTX *ctx, int operation)
341 if (ctx == NULL || ctx->keytype == NULL)
344 evp_pkey_ctx_free_old_ops(ctx);
345 if (ctx->keymgmt == NULL)
348 ctx->operation = operation;
352 if (ctx != NULL)
353 ctx->operation = EVP_PKEY_OP_UNDEFINED;
358 int EVP_PKEY_fromdata_init(EVP_PKEY_CTX *ctx)
360 return fromdata_init(ctx, EVP_PKEY_OP_FROMDATA);
363 int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection,
369 if (ctx == NULL || (ctx->operation & EVP_PKEY_OP_FROMDATA) == 0) {
385 keydata = evp_keymgmt_util_fromdata(*ppkey, ctx->keymgmt, selection, params);
397 const OSSL_PARAM *EVP_PKEY_fromdata_settable(EVP_PKEY_CTX *ctx, int selection)
399 /* We call fromdata_init to get ctx->keymgmt populated */
400 if (fromdata_init(ctx, EVP_PKEY_OP_UNDEFINED) == 1)
401 return evp_keymgmt_import_types(ctx->keymgmt, selection);