Lines Matching full:if
10 #if defined(MBEDTLS_PK_C)
19 #if defined(MBEDTLS_RSA_C)
23 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
26 #if defined(MBEDTLS_ECDSA_C)
30 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
45 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_init()
48 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in mbedtls_pk_init()
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()
69 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in mbedtls_pk_free()
72 if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) { in mbedtls_pk_free()
80 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
95 if (ctx == NULL || ctx->pk_info == NULL || in mbedtls_pk_restart_free()
113 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_info_from_type()
117 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_info_from_type()
123 #if defined(MBEDTLS_PK_CAN_ECDSA_SOME) in mbedtls_pk_info_from_type()
138 if (info == NULL || ctx->pk_info != NULL) { in mbedtls_pk_setup()
142 if ((info->ctx_alloc_func != NULL) && in mbedtls_pk_setup()
152 #if defined(MBEDTLS_USE_PSA_CRYPTO)
163 if (ctx == NULL || ctx->pk_info != NULL) { in mbedtls_pk_setup_opaque()
167 if (PSA_SUCCESS != psa_get_key_attributes(key, &attributes)) { in mbedtls_pk_setup_opaque()
173 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_setup_opaque()
174 if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) { in mbedtls_pk_setup_opaque()
178 if (type == PSA_KEY_TYPE_RSA_KEY_PAIR) { in mbedtls_pk_setup_opaque()
191 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
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()
225 * Tell if a PK can do the operations of the given type
232 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_can_do()
239 #if defined(MBEDTLS_USE_PSA_CRYPTO)
241 * Tell if a PK can do the operations of the given PSA algorithm
251 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_can_do_ext()
256 if (PSA_ALG_IS_ECDSA(alg) == 0 && in mbedtls_pk_can_do_ext()
265 if (usage == 0 || in mbedtls_pk_can_do_ext()
273 if (PSA_ALG_IS_SIGN_HASH(alg) && in mbedtls_pk_can_do_ext()
278 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_OPAQUE) { in mbedtls_pk_can_do_ext()
281 if (PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_ECDH(alg)) { in mbedtls_pk_can_do_ext()
283 } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || in mbedtls_pk_can_do_ext()
286 } else if (PSA_ALG_IS_RSA_PSS(alg)) { in mbedtls_pk_can_do_ext()
292 if (ctx->pk_info->can_do(type) == 0) { in mbedtls_pk_can_do_ext()
318 if (status != PSA_SUCCESS) { in mbedtls_pk_can_do_ext()
328 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_can_do_ext()
334 if ((key_usage & usage) != usage) { in mbedtls_pk_can_do_ext()
345 if (alg == key_alg) { in mbedtls_pk_can_do_ext()
348 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_can_do_ext()
349 if (alg == key_alg2) { in mbedtls_pk_can_do_ext()
355 * If key_alg [or key_alg2] is a hash-and-sign with a wildcard for the hash, in mbedtls_pk_can_do_ext()
359 if (PSA_ALG_IS_SIGN_HASH(alg)) { in mbedtls_pk_can_do_ext()
360 if (PSA_ALG_IS_SIGN_HASH(key_alg) && in mbedtls_pk_can_do_ext()
365 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_can_do_ext()
366 if (PSA_ALG_IS_SIGN_HASH(key_alg2) && in mbedtls_pk_can_do_ext()
378 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
379 #if defined(MBEDTLS_RSA_C)
383 if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) { in psa_algorithm_for_rsa()
384 if (want_crypt) { in psa_algorithm_for_rsa()
391 if (want_crypt) { in psa_algorithm_for_rsa()
407 if (usage == PSA_KEY_USAGE_SIGN_MESSAGE) { in mbedtls_pk_get_psa_attributes()
409 } else if (usage == PSA_KEY_USAGE_SIGN_HASH) { in mbedtls_pk_get_psa_attributes()
411 } else if (usage == PSA_KEY_USAGE_DECRYPT) { in mbedtls_pk_get_psa_attributes()
421 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_get_psa_attributes()
443 if (want_private && !has_private) { in mbedtls_pk_get_psa_attributes()
456 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_get_psa_attributes()
463 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in mbedtls_pk_get_psa_attributes()
467 if (pk->priv_id != MBEDTLS_SVC_KEY_ID_INIT) { in mbedtls_pk_get_psa_attributes()
483 if (!sign_ok) { in mbedtls_pk_get_psa_attributes()
486 #if defined(MBEDTLS_ECDSA_DETERMINISTIC) in mbedtls_pk_get_psa_attributes()
494 if (!derive_ok) { in mbedtls_pk_get_psa_attributes()
501 if (want_private && !has_private) { in mbedtls_pk_get_psa_attributes()
513 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) in mbedtls_pk_get_psa_attributes()
518 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_get_psa_attributes()
524 if (status != PSA_SUCCESS) { in mbedtls_pk_get_psa_attributes()
533 if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type) || in mbedtls_pk_get_psa_attributes()
540 if (old_type != PSA_KEY_TYPE_RSA_KEY_PAIR) { in mbedtls_pk_get_psa_attributes()
545 if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type))) { in mbedtls_pk_get_psa_attributes()
554 * on the input if the required usage is private. We just need in mbedtls_pk_get_psa_attributes()
555 * to adjust the type correctly if the required usage is public. */ in mbedtls_pk_get_psa_attributes()
556 if (!want_private) { in mbedtls_pk_get_psa_attributes()
560 if ((usage & more_usage) == 0) { in mbedtls_pk_get_psa_attributes()
580 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_get_psa_attributes()
587 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) || defined(MBEDTLS_USE_PSA_CRYPTO)
597 if (status != PSA_SUCCESS) { in export_import_into_psa()
612 if (status == PSA_ERROR_NOT_PERMITTED /*missing COPY usage*/ || in copy_into_psa()
616 * - If the old key does not allow PSA_KEY_USAGE_COPY. in copy_into_psa()
617 * - If the old key's usage does not allow what attributes wants. in copy_into_psa()
627 if (status != PSA_SUCCESS) { in copy_into_psa()
632 if (old_type != psa_get_key_type(attributes)) { in copy_into_psa()
646 #if defined(MBEDTLS_RSA_C) in import_pair_into_psa()
649 if (psa_get_key_type(attributes) != PSA_KEY_TYPE_RSA_KEY_PAIR) { in import_pair_into_psa()
658 if (ret < 0) { in import_pair_into_psa()
670 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in import_pair_into_psa()
678 * and if it's specified, psa_import_key() will know from the key in import_pair_into_psa()
681 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in import_pair_into_psa()
689 if (to_type != PSA_KEY_TYPE_ECC_KEY_PAIR(from_family)) { in import_pair_into_psa()
693 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in import_pair_into_psa()
694 if (mbedtls_svc_key_id_is_null(pk->priv_id)) { in import_pair_into_psa()
700 if (ec->d.n == 0) { in import_pair_into_psa()
713 if (ret < 0) { in import_pair_into_psa()
725 #if defined(MBEDTLS_USE_PSA_CRYPTO) in import_pair_into_psa()
741 #if defined(MBEDTLS_RSA_C) || \ in import_public_into_psa()
750 #if defined(MBEDTLS_RSA_C) in import_public_into_psa()
753 if (psa_type != PSA_KEY_TYPE_RSA_PUBLIC_KEY) { in import_public_into_psa()
760 if (ret < 0) { in import_public_into_psa()
768 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in import_public_into_psa()
776 * and if it's specified, psa_import_key() will know from the key in import_public_into_psa()
778 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in import_public_into_psa()
779 if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family)) { in import_public_into_psa()
789 if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(from_family)) { in import_public_into_psa()
795 if (ret < 0) { in import_public_into_psa()
804 #if defined(MBEDTLS_USE_PSA_CRYPTO) in import_public_into_psa()
810 if (status != PSA_SUCCESS) { in import_public_into_psa()
815 if (psa_type != PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(old_type)) { in import_public_into_psa()
821 if (status != PSA_SUCCESS) { in import_public_into_psa()
843 * if we error out before calling psa_import_key(). */ in mbedtls_pk_import_into_psa()
846 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) in mbedtls_pk_import_into_psa()
847 if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSA_ALT) { in mbedtls_pk_import_into_psa()
853 if (want_public) { in mbedtls_pk_import_into_psa()
873 if (pk == NULL) { in copy_from_psa()
878 if (status != PSA_SUCCESS) { in copy_from_psa()
882 if (public_only) { in copy_from_psa()
887 if (status != PSA_SUCCESS) { in copy_from_psa()
893 if (public_only) { in copy_from_psa()
898 #if defined(MBEDTLS_RSA_C) in copy_from_psa()
899 if ((key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) || in copy_from_psa()
903 if (ret != 0) { in copy_from_psa()
907 if (key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) { in copy_from_psa()
912 if (ret != 0) { in copy_from_psa()
918 if (PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH) { in copy_from_psa()
922 if (PSA_ALG_IS_RSA_OAEP(alg_type) || PSA_ALG_IS_RSA_PSS(alg_type)) { in copy_from_psa()
924 } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg_type) || in copy_from_psa()
928 if (ret != 0) { in copy_from_psa()
933 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in copy_from_psa()
934 if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) || in copy_from_psa()
939 if (ret != 0) { in copy_from_psa()
945 if (ret != 0) { in copy_from_psa()
949 if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type)) { in copy_from_psa()
951 if (ret != 0) { in copy_from_psa()
960 if (ret != 0) { in copy_from_psa()
995 if (*hash_len != 0) { in pk_hashlen_helper()
1001 if (*hash_len == 0) { in pk_hashlen_helper()
1008 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
1010 * Helper to set up a restart context if needed
1015 /* Don't do anything if already set up or invalid */ in pk_restart_setup()
1016 if (ctx == NULL || ctx->pk_info != NULL) { in pk_restart_setup()
1021 if (info->rs_alloc_func == NULL || info->rs_free_func == NULL) { in pk_restart_setup()
1025 if ((ctx->rs_ctx = info->rs_alloc_func()) == NULL) { in pk_restart_setup()
1044 if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { in mbedtls_pk_verify_restartable()
1048 if (ctx->pk_info == NULL || in mbedtls_pk_verify_restartable()
1053 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) in mbedtls_pk_verify_restartable()
1054 /* optimization: use non-restartable version if restart disabled */ in mbedtls_pk_verify_restartable()
1055 if (rs_ctx != NULL && in mbedtls_pk_verify_restartable()
1060 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { in mbedtls_pk_verify_restartable()
1067 if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) { in mbedtls_pk_verify_restartable()
1077 if (ctx->pk_info->verify_func == NULL) { in mbedtls_pk_verify_restartable()
1104 if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { in mbedtls_pk_verify_ext()
1108 if (ctx->pk_info == NULL) { in mbedtls_pk_verify_ext()
1112 if (!mbedtls_pk_can_do(ctx, type)) { in mbedtls_pk_verify_ext()
1116 if (type != MBEDTLS_PK_RSASSA_PSS) { in mbedtls_pk_verify_ext()
1118 if (options != NULL) { in mbedtls_pk_verify_ext()
1127 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) { in mbedtls_pk_verify_ext()
1131 #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) in mbedtls_pk_verify_ext()
1135 #if SIZE_MAX > UINT_MAX in mbedtls_pk_verify_ext()
1136 if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) { in mbedtls_pk_verify_ext()
1141 if (options == NULL) { in mbedtls_pk_verify_ext()
1147 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_verify_ext()
1148 if (pss_opts->mgf1_hash_id == md_alg) { in mbedtls_pk_verify_ext()
1163 if (key_len < 0) { in mbedtls_pk_verify_ext()
1174 if (status != PSA_SUCCESS) { in mbedtls_pk_verify_ext()
1190 if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1194 if (status == PSA_SUCCESS) { in mbedtls_pk_verify_ext()
1202 if (sig_len < mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1211 if (ret != 0) { in mbedtls_pk_verify_ext()
1215 if (sig_len > mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1236 if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { in mbedtls_pk_sign_restartable()
1240 if (ctx->pk_info == NULL || pk_hashlen_helper(md_alg, &hash_len) != 0) { in mbedtls_pk_sign_restartable()
1244 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) in mbedtls_pk_sign_restartable()
1245 /* optimization: use non-restartable version if restart disabled */ in mbedtls_pk_sign_restartable()
1246 if (rs_ctx != NULL && in mbedtls_pk_sign_restartable()
1251 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { in mbedtls_pk_sign_restartable()
1260 if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) { in mbedtls_pk_sign_restartable()
1270 if (ctx->pk_info->sign_func == NULL) { in mbedtls_pk_sign_restartable()
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()
1312 if (pk_type != MBEDTLS_PK_RSASSA_PSS) { in mbedtls_pk_sign_ext()
1317 #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) in mbedtls_pk_sign_ext()
1319 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_sign_ext()
1321 if (psa_md_alg == 0) { in mbedtls_pk_sign_ext()
1325 if (mbedtls_pk_get_type(ctx) == MBEDTLS_PK_OPAQUE) { in mbedtls_pk_sign_ext()
1334 if (status == PSA_ERROR_NOT_PERMITTED) { in mbedtls_pk_sign_ext()
1347 if (sig_size < mbedtls_pk_get_len(ctx)) { in mbedtls_pk_sign_ext()
1351 if (pk_hashlen_helper(md_alg, &hash_len) != 0) { in mbedtls_pk_sign_ext()
1359 if (ret == 0) { in mbedtls_pk_sign_ext()
1379 if (ctx->pk_info == NULL) { in mbedtls_pk_decrypt()
1383 if (ctx->pk_info->decrypt_func == NULL) { in mbedtls_pk_decrypt()
1399 if (ctx->pk_info == NULL) { in mbedtls_pk_encrypt()
1403 if (ctx->pk_info->encrypt_func == NULL) { in mbedtls_pk_encrypt()
1419 if (pub->pk_info == NULL || in mbedtls_pk_check_pair()
1424 if (f_rng == NULL) { in mbedtls_pk_check_pair()
1428 if (prv->pk_info->check_pair_func == NULL) { in mbedtls_pk_check_pair()
1432 if (prv->pk_info->type == MBEDTLS_PK_RSA_ALT) { in mbedtls_pk_check_pair()
1433 if (pub->pk_info->type != MBEDTLS_PK_RSA) { in mbedtls_pk_check_pair()
1437 if ((prv->pk_info->type != MBEDTLS_PK_OPAQUE) && in mbedtls_pk_check_pair()
1455 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_bitlen()
1467 if (ctx->pk_info == NULL) { in mbedtls_pk_debug()
1471 if (ctx->pk_info->debug_func == NULL) { in mbedtls_pk_debug()
1484 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_name()
1496 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_type()