Lines Matching refs:ctx
45 void mbedtls_pk_init(mbedtls_pk_context *ctx)
47 ctx->pk_info = NULL;
48 ctx->pk_ctx = NULL;
50 ctx->priv_id = MBEDTLS_SVC_KEY_ID_INIT;
53 memset(ctx->pub_raw, 0, sizeof(ctx->pub_raw));
54 ctx->pub_raw_len = 0;
55 ctx->ec_family = 0;
56 ctx->ec_bits = 0;
63 void mbedtls_pk_free(mbedtls_pk_context *ctx)
65 if (ctx == NULL) {
69 if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) {
70 ctx->pk_info->ctx_free_func(ctx->pk_ctx);
76 if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) {
77 psa_destroy_key(ctx->priv_id);
81 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context));
88 void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx)
90 ctx->pk_info = NULL;
91 ctx->rs_ctx = NULL;
97 void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx)
99 if (ctx == NULL || ctx->pk_info == NULL ||
100 ctx->pk_info->rs_free_func == NULL) {
104 ctx->pk_info->rs_free_func(ctx->rs_ctx);
106 ctx->pk_info = NULL;
107 ctx->rs_ctx = NULL;
140 int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info)
142 if (info == NULL || ctx->pk_info != NULL) {
147 ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) {
151 ctx->pk_info = info;
160 int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
167 if (ctx == NULL || ctx->pk_info != NULL) {
188 ctx->pk_info = info;
189 ctx->priv_id = key;
199 int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key,
207 if (ctx->pk_info != NULL) {
211 if ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL) {
215 ctx->pk_info = info;
217 rsa_alt = (mbedtls_rsa_alt_context *) ctx->pk_ctx;
231 int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type)
236 if (ctx == NULL || ctx->pk_info == NULL) {
240 return ctx->pk_info->can_do(type);
247 int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
255 if (ctx == NULL || ctx->pk_info == NULL) {
282 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_OPAQUE) {
296 if (ctx->pk_info->can_do(type) == 0) {
321 status = psa_get_key_attributes(ctx->priv_id, &attributes);
1016 static int pk_restart_setup(mbedtls_pk_restart_ctx *ctx,
1020 if (ctx == NULL || ctx->pk_info != NULL) {
1029 if ((ctx->rs_ctx = info->rs_alloc_func()) == NULL) {
1033 ctx->pk_info = info;
1042 int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
1052 if (ctx->pk_info == NULL ||
1061 ctx->pk_info->verify_rs_func != NULL) {
1064 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) {
1068 ret = ctx->pk_info->verify_rs_func(ctx,
1081 if (ctx->pk_info->verify_func == NULL) {
1085 return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len,
1092 int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
1096 return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len,
1104 mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
1112 if (ctx->pk_info == NULL) {
1116 if (!mbedtls_pk_can_do(ctx, type)) {
1126 return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len);
1131 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) {
1165 key_len = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*ctx), buf, &p);
1188 signature_length = sig_len > mbedtls_pk_get_len(ctx) ?
1189 mbedtls_pk_get_len(ctx) : sig_len;
1194 if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) {
1206 if (sig_len < mbedtls_pk_get_len(ctx)) {
1210 ret = mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_pk_rsa(*ctx),
1219 if (sig_len > mbedtls_pk_get_len(ctx)) {
1233 int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx,
1244 if (ctx->pk_info == NULL || pk_hashlen_helper(md_alg, &hash_len) != 0) {
1252 ctx->pk_info->sign_rs_func != NULL) {
1255 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) {
1259 ret = ctx->pk_info->sign_rs_func(ctx, md_alg,
1274 if (ctx->pk_info->sign_func == NULL) {
1278 return ctx->pk_info->sign_func(ctx, md_alg,
1287 int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
1292 return mbedtls_pk_sign_restartable(ctx, md_alg, hash, hash_len,
1301 mbedtls_pk_context *ctx,
1308 if (ctx->pk_info == NULL) {
1312 if (!mbedtls_pk_can_do(ctx, pk_type)) {
1317 return mbedtls_pk_sign(ctx, md_alg, hash, hash_len,
1329 if (mbedtls_pk_get_type(ctx) == MBEDTLS_PK_OPAQUE) {
1337 status = psa_get_key_attributes(ctx->priv_id, &key_attr);
1364 status = psa_sign_hash(ctx->priv_id, sign_alg,
1371 ctx->pk_ctx, hash, hash_len,
1375 if (sig_size < mbedtls_pk_get_len(ctx)) {
1383 mbedtls_rsa_context *const rsa_ctx = mbedtls_pk_rsa(*ctx);
1402 int mbedtls_pk_decrypt(mbedtls_pk_context *ctx,
1407 if (ctx->pk_info == NULL) {
1411 if (ctx->pk_info->decrypt_func == NULL) {
1415 return ctx->pk_info->decrypt_func(ctx, input, ilen,
1422 int mbedtls_pk_encrypt(mbedtls_pk_context *ctx,
1427 if (ctx->pk_info == NULL) {
1431 if (ctx->pk_info->encrypt_func == NULL) {
1435 return ctx->pk_info->encrypt_func(ctx, input, ilen,
1479 size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
1483 if (ctx == NULL || ctx->pk_info == NULL) {
1487 return ctx->pk_info->get_bitlen((mbedtls_pk_context *) ctx);
1493 int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
1495 if (ctx->pk_info == NULL) {
1499 if (ctx->pk_info->debug_func == NULL) {
1503 ctx->pk_info->debug_func((mbedtls_pk_context *) ctx, items);
1510 const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
1512 if (ctx == NULL || ctx->pk_info == NULL) {
1516 return ctx->pk_info->name;
1522 mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
1524 if (ctx == NULL || ctx->pk_info == NULL) {
1528 return ctx->pk_info->type;