Lines Matching refs:ctx
41 void mbedtls_pk_init(mbedtls_pk_context *ctx) in mbedtls_pk_init() argument
43 ctx->pk_info = NULL; in mbedtls_pk_init()
44 ctx->pk_ctx = NULL; in mbedtls_pk_init()
46 ctx->priv_id = MBEDTLS_SVC_KEY_ID_INIT; in mbedtls_pk_init()
49 memset(ctx->pub_raw, 0, sizeof(ctx->pub_raw)); in mbedtls_pk_init()
50 ctx->pub_raw_len = 0; in mbedtls_pk_init()
51 ctx->ec_family = 0; in mbedtls_pk_init()
52 ctx->ec_bits = 0; in mbedtls_pk_init()
59 void mbedtls_pk_free(mbedtls_pk_context *ctx) in mbedtls_pk_free() argument
61 if (ctx == NULL) { in mbedtls_pk_free()
65 if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) { in mbedtls_pk_free()
66 ctx->pk_info->ctx_free_func(ctx->pk_ctx); in mbedtls_pk_free()
72 if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) { in mbedtls_pk_free()
73 psa_destroy_key(ctx->priv_id); in mbedtls_pk_free()
77 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context)); in mbedtls_pk_free()
84 void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx) in mbedtls_pk_restart_init() argument
86 ctx->pk_info = NULL; in mbedtls_pk_restart_init()
87 ctx->rs_ctx = NULL; in mbedtls_pk_restart_init()
93 void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx) in mbedtls_pk_restart_free() argument
95 if (ctx == NULL || ctx->pk_info == NULL || in mbedtls_pk_restart_free()
96 ctx->pk_info->rs_free_func == NULL) { in mbedtls_pk_restart_free()
100 ctx->pk_info->rs_free_func(ctx->rs_ctx); in mbedtls_pk_restart_free()
102 ctx->pk_info = NULL; in mbedtls_pk_restart_free()
103 ctx->rs_ctx = NULL; in mbedtls_pk_restart_free()
136 int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info) in mbedtls_pk_setup() argument
138 if (info == NULL || ctx->pk_info != NULL) { in mbedtls_pk_setup()
143 ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) { in mbedtls_pk_setup()
147 ctx->pk_info = info; in mbedtls_pk_setup()
156 int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx, in mbedtls_pk_setup_opaque() argument
163 if (ctx == NULL || ctx->pk_info != NULL) { in mbedtls_pk_setup_opaque()
184 ctx->pk_info = info; in mbedtls_pk_setup_opaque()
185 ctx->priv_id = key; in mbedtls_pk_setup_opaque()
195 int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, in mbedtls_pk_setup_rsa_alt() argument
203 if (ctx->pk_info != NULL) { in mbedtls_pk_setup_rsa_alt()
207 if ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL) { in mbedtls_pk_setup_rsa_alt()
211 ctx->pk_info = info; in mbedtls_pk_setup_rsa_alt()
213 rsa_alt = (mbedtls_rsa_alt_context *) ctx->pk_ctx; in mbedtls_pk_setup_rsa_alt()
227 int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type) in mbedtls_pk_can_do() argument
232 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_can_do()
236 return ctx->pk_info->can_do(type); in mbedtls_pk_can_do()
243 int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg, in mbedtls_pk_can_do_ext() argument
251 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_can_do_ext()
278 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_OPAQUE) { in mbedtls_pk_can_do_ext()
292 if (ctx->pk_info->can_do(type) == 0) { in mbedtls_pk_can_do_ext()
317 status = psa_get_key_attributes(ctx->priv_id, &attributes); in mbedtls_pk_can_do_ext()
1012 static int pk_restart_setup(mbedtls_pk_restart_ctx *ctx, in pk_restart_setup() argument
1016 if (ctx == NULL || ctx->pk_info != NULL) { in pk_restart_setup()
1025 if ((ctx->rs_ctx = info->rs_alloc_func()) == NULL) { in pk_restart_setup()
1029 ctx->pk_info = info; in pk_restart_setup()
1038 int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, in mbedtls_pk_verify_restartable() argument
1048 if (ctx->pk_info == NULL || in mbedtls_pk_verify_restartable()
1057 ctx->pk_info->verify_rs_func != NULL) { in mbedtls_pk_verify_restartable()
1060 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { in mbedtls_pk_verify_restartable()
1064 ret = ctx->pk_info->verify_rs_func(ctx, in mbedtls_pk_verify_restartable()
1077 if (ctx->pk_info->verify_func == NULL) { in mbedtls_pk_verify_restartable()
1081 return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len, in mbedtls_pk_verify_restartable()
1088 int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, in mbedtls_pk_verify() argument
1092 return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len, in mbedtls_pk_verify()
1100 mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, in mbedtls_pk_verify_ext() argument
1108 if (ctx->pk_info == NULL) { in mbedtls_pk_verify_ext()
1112 if (!mbedtls_pk_can_do(ctx, type)) { in mbedtls_pk_verify_ext()
1122 return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len); in mbedtls_pk_verify_ext()
1127 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) { in mbedtls_pk_verify_ext()
1161 key_len = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*ctx), buf, &p); in mbedtls_pk_verify_ext()
1184 signature_length = sig_len > mbedtls_pk_get_len(ctx) ? in mbedtls_pk_verify_ext()
1185 mbedtls_pk_get_len(ctx) : sig_len; in mbedtls_pk_verify_ext()
1190 if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1202 if (sig_len < mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1206 ret = mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_pk_rsa(*ctx), in mbedtls_pk_verify_ext()
1215 if (sig_len > mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1229 int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx, in mbedtls_pk_sign_restartable() argument
1240 if (ctx->pk_info == NULL || pk_hashlen_helper(md_alg, &hash_len) != 0) { in mbedtls_pk_sign_restartable()
1248 ctx->pk_info->sign_rs_func != NULL) { in mbedtls_pk_sign_restartable()
1251 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { in mbedtls_pk_sign_restartable()
1255 ret = ctx->pk_info->sign_rs_func(ctx, md_alg, in mbedtls_pk_sign_restartable()
1270 if (ctx->pk_info->sign_func == NULL) { in mbedtls_pk_sign_restartable()
1274 return ctx->pk_info->sign_func(ctx, md_alg, in mbedtls_pk_sign_restartable()
1283 int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, in mbedtls_pk_sign() argument
1288 return mbedtls_pk_sign_restartable(ctx, md_alg, hash, hash_len, in mbedtls_pk_sign()
1297 mbedtls_pk_context *ctx, in mbedtls_pk_sign_ext() argument
1304 if (ctx->pk_info == NULL) { in mbedtls_pk_sign_ext()
1308 if (!mbedtls_pk_can_do(ctx, pk_type)) { in mbedtls_pk_sign_ext()
1313 return mbedtls_pk_sign(ctx, md_alg, hash, hash_len, in mbedtls_pk_sign_ext()
1325 if (mbedtls_pk_get_type(ctx) == MBEDTLS_PK_OPAQUE) { in mbedtls_pk_sign_ext()
1331 status = psa_sign_hash(ctx->priv_id, PSA_ALG_RSA_PSS(psa_md_alg), in mbedtls_pk_sign_ext()
1335 status = psa_sign_hash(ctx->priv_id, PSA_ALG_RSA_PSS_ANY_SALT(psa_md_alg), in mbedtls_pk_sign_ext()
1343 ctx->pk_ctx, hash, hash_len, in mbedtls_pk_sign_ext()
1347 if (sig_size < mbedtls_pk_get_len(ctx)) { in mbedtls_pk_sign_ext()
1355 mbedtls_rsa_context *const rsa_ctx = mbedtls_pk_rsa(*ctx); in mbedtls_pk_sign_ext()
1374 int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, in mbedtls_pk_decrypt() argument
1379 if (ctx->pk_info == NULL) { in mbedtls_pk_decrypt()
1383 if (ctx->pk_info->decrypt_func == NULL) { in mbedtls_pk_decrypt()
1387 return ctx->pk_info->decrypt_func(ctx, input, ilen, in mbedtls_pk_decrypt()
1394 int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, in mbedtls_pk_encrypt() argument
1399 if (ctx->pk_info == NULL) { in mbedtls_pk_encrypt()
1403 if (ctx->pk_info->encrypt_func == NULL) { in mbedtls_pk_encrypt()
1407 return ctx->pk_info->encrypt_func(ctx, input, ilen, in mbedtls_pk_encrypt()
1451 size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx) in mbedtls_pk_get_bitlen() argument
1455 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_bitlen()
1459 return ctx->pk_info->get_bitlen((mbedtls_pk_context *) ctx); in mbedtls_pk_get_bitlen()
1465 int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items) in mbedtls_pk_debug() argument
1467 if (ctx->pk_info == NULL) { in mbedtls_pk_debug()
1471 if (ctx->pk_info->debug_func == NULL) { in mbedtls_pk_debug()
1475 ctx->pk_info->debug_func((mbedtls_pk_context *) ctx, items); in mbedtls_pk_debug()
1482 const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx) in mbedtls_pk_get_name() argument
1484 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_name()
1488 return ctx->pk_info->name; in mbedtls_pk_get_name()
1494 mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx) in mbedtls_pk_get_type() argument
1496 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_type()
1500 return ctx->pk_info->type; in mbedtls_pk_get_type()