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)
49 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_init()
52 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in mbedtls_pk_init()
65 if (ctx == NULL) { in mbedtls_pk_free()
69 if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) { in mbedtls_pk_free()
73 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in mbedtls_pk_free()
76 if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) { in mbedtls_pk_free()
84 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
99 if (ctx == NULL || ctx->pk_info == NULL || in mbedtls_pk_restart_free()
117 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_info_from_type()
121 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_info_from_type()
127 #if defined(MBEDTLS_PK_CAN_ECDSA_SOME) in mbedtls_pk_info_from_type()
142 if (info == NULL || ctx->pk_info != NULL) { in mbedtls_pk_setup()
146 if ((info->ctx_alloc_func != NULL) && in mbedtls_pk_setup()
156 #if defined(MBEDTLS_USE_PSA_CRYPTO)
167 if (ctx == NULL || ctx->pk_info != NULL) { in mbedtls_pk_setup_opaque()
171 if (PSA_SUCCESS != psa_get_key_attributes(key, &attributes)) { in mbedtls_pk_setup_opaque()
177 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_setup_opaque()
178 if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) { in mbedtls_pk_setup_opaque()
182 if (type == PSA_KEY_TYPE_RSA_KEY_PAIR) { in mbedtls_pk_setup_opaque()
195 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
207 if (ctx->pk_info != NULL) { in mbedtls_pk_setup_rsa_alt()
211 if ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL) { in mbedtls_pk_setup_rsa_alt()
229 * Tell if a PK can do the operations of the given type
236 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_can_do()
243 #if defined(MBEDTLS_USE_PSA_CRYPTO)
245 * Tell if a PK can do the operations of the given PSA algorithm
255 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_can_do_ext()
260 if (PSA_ALG_IS_ECDSA(alg) == 0 && in mbedtls_pk_can_do_ext()
269 if (usage == 0 || in mbedtls_pk_can_do_ext()
277 if (PSA_ALG_IS_SIGN_HASH(alg) && in mbedtls_pk_can_do_ext()
282 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_OPAQUE) { in mbedtls_pk_can_do_ext()
285 if (PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_ECDH(alg)) { in mbedtls_pk_can_do_ext()
287 } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || in mbedtls_pk_can_do_ext()
290 } else if (PSA_ALG_IS_RSA_PSS(alg)) { in mbedtls_pk_can_do_ext()
296 if (ctx->pk_info->can_do(type) == 0) { in mbedtls_pk_can_do_ext()
322 if (status != PSA_SUCCESS) { in mbedtls_pk_can_do_ext()
332 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_can_do_ext()
338 if ((key_usage & usage) != usage) { in mbedtls_pk_can_do_ext()
349 if (alg == key_alg) { in mbedtls_pk_can_do_ext()
352 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_can_do_ext()
353 if (alg == key_alg2) { in mbedtls_pk_can_do_ext()
359 * If key_alg [or key_alg2] is a hash-and-sign with a wildcard for the hash, in mbedtls_pk_can_do_ext()
363 if (PSA_ALG_IS_SIGN_HASH(alg)) { in mbedtls_pk_can_do_ext()
364 if (PSA_ALG_IS_SIGN_HASH(key_alg) && in mbedtls_pk_can_do_ext()
369 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_can_do_ext()
370 if (PSA_ALG_IS_SIGN_HASH(key_alg2) && in mbedtls_pk_can_do_ext()
382 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
383 #if defined(MBEDTLS_RSA_C)
387 if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) { in psa_algorithm_for_rsa()
388 if (want_crypt) { in psa_algorithm_for_rsa()
395 if (want_crypt) { in psa_algorithm_for_rsa()
411 if (usage == PSA_KEY_USAGE_SIGN_MESSAGE) { in mbedtls_pk_get_psa_attributes()
413 } else if (usage == PSA_KEY_USAGE_SIGN_HASH) { in mbedtls_pk_get_psa_attributes()
415 } else if (usage == PSA_KEY_USAGE_DECRYPT) { in mbedtls_pk_get_psa_attributes()
425 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_get_psa_attributes()
447 if (want_private && !has_private) { in mbedtls_pk_get_psa_attributes()
460 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_get_psa_attributes()
467 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in mbedtls_pk_get_psa_attributes()
471 if (pk->priv_id != MBEDTLS_SVC_KEY_ID_INIT) { in mbedtls_pk_get_psa_attributes()
487 if (!sign_ok) { in mbedtls_pk_get_psa_attributes()
490 #if defined(MBEDTLS_ECDSA_DETERMINISTIC) in mbedtls_pk_get_psa_attributes()
498 if (!derive_ok) { in mbedtls_pk_get_psa_attributes()
505 if (want_private && !has_private) { in mbedtls_pk_get_psa_attributes()
517 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) in mbedtls_pk_get_psa_attributes()
522 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_get_psa_attributes()
528 if (status != PSA_SUCCESS) { in mbedtls_pk_get_psa_attributes()
537 if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type) || in mbedtls_pk_get_psa_attributes()
544 if (old_type != PSA_KEY_TYPE_RSA_KEY_PAIR) { in mbedtls_pk_get_psa_attributes()
549 if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type))) { in mbedtls_pk_get_psa_attributes()
558 * on the input if the required usage is private. We just need in mbedtls_pk_get_psa_attributes()
559 * to adjust the type correctly if the required usage is public. */ in mbedtls_pk_get_psa_attributes()
560 if (!want_private) { in mbedtls_pk_get_psa_attributes()
564 if ((usage & more_usage) == 0) { in mbedtls_pk_get_psa_attributes()
584 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_get_psa_attributes()
591 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) || defined(MBEDTLS_USE_PSA_CRYPTO)
601 if (status != PSA_SUCCESS) { in export_import_into_psa()
616 if (status == PSA_ERROR_NOT_PERMITTED /*missing COPY usage*/ || in copy_into_psa()
620 * - If the old key does not allow PSA_KEY_USAGE_COPY. in copy_into_psa()
621 * - If the old key's usage does not allow what attributes wants. in copy_into_psa()
631 if (status != PSA_SUCCESS) { in copy_into_psa()
636 if (old_type != psa_get_key_type(attributes)) { in copy_into_psa()
650 #if defined(MBEDTLS_RSA_C) in import_pair_into_psa()
653 if (psa_get_key_type(attributes) != PSA_KEY_TYPE_RSA_KEY_PAIR) { in import_pair_into_psa()
662 if (ret < 0) { in import_pair_into_psa()
674 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in import_pair_into_psa()
682 * and if it's specified, psa_import_key() will know from the key in import_pair_into_psa()
685 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in import_pair_into_psa()
693 if (to_type != PSA_KEY_TYPE_ECC_KEY_PAIR(from_family)) { in import_pair_into_psa()
697 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in import_pair_into_psa()
698 if (mbedtls_svc_key_id_is_null(pk->priv_id)) { in import_pair_into_psa()
704 if (ec->d.n == 0) { in import_pair_into_psa()
717 if (ret < 0) { in import_pair_into_psa()
729 #if defined(MBEDTLS_USE_PSA_CRYPTO) in import_pair_into_psa()
745 #if defined(MBEDTLS_RSA_C) || \ in import_public_into_psa()
754 #if defined(MBEDTLS_RSA_C) in import_public_into_psa()
757 if (psa_type != PSA_KEY_TYPE_RSA_PUBLIC_KEY) { in import_public_into_psa()
764 if (ret < 0) { in import_public_into_psa()
772 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in import_public_into_psa()
780 * and if it's specified, psa_import_key() will know from the key in import_public_into_psa()
782 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in import_public_into_psa()
783 if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family)) { in import_public_into_psa()
793 if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(from_family)) { in import_public_into_psa()
799 if (ret < 0) { in import_public_into_psa()
808 #if defined(MBEDTLS_USE_PSA_CRYPTO) in import_public_into_psa()
814 if (status != PSA_SUCCESS) { in import_public_into_psa()
819 if (psa_type != PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(old_type)) { in import_public_into_psa()
825 if (status != PSA_SUCCESS) { in import_public_into_psa()
847 * if we error out before calling psa_import_key(). */ in mbedtls_pk_import_into_psa()
850 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) in mbedtls_pk_import_into_psa()
851 if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSA_ALT) { in mbedtls_pk_import_into_psa()
857 if (want_public) { in mbedtls_pk_import_into_psa()
878 if (pk == NULL) { in copy_from_psa()
883 if (status != PSA_SUCCESS) { in copy_from_psa()
887 if (public_only) { in copy_from_psa()
892 if (status != PSA_SUCCESS) { in copy_from_psa()
898 if (public_only) { in copy_from_psa()
904 #if defined(MBEDTLS_RSA_C) in copy_from_psa()
905 if ((key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) || in copy_from_psa()
909 if (ret != 0) { in copy_from_psa()
913 if (key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) { in copy_from_psa()
918 if (ret != 0) { in copy_from_psa()
923 if (PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH) { in copy_from_psa()
927 if (PSA_ALG_IS_RSA_OAEP(alg_type) || PSA_ALG_IS_RSA_PSS(alg_type)) { in copy_from_psa()
929 } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg_type) || in copy_from_psa()
933 if (ret != 0) { in copy_from_psa()
938 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in copy_from_psa()
939 if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) || in copy_from_psa()
944 if (ret != 0) { in copy_from_psa()
950 if (ret != 0) { in copy_from_psa()
954 if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type)) { in copy_from_psa()
956 if (ret != 0) { in copy_from_psa()
965 if (ret != 0) { in copy_from_psa()
999 if (*hash_len != 0) { in pk_hashlen_helper()
1005 if (*hash_len == 0) { in pk_hashlen_helper()
1012 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
1014 * Helper to set up a restart context if needed
1019 /* Don't do anything if already set up or invalid */ in pk_restart_setup()
1020 if (ctx == NULL || ctx->pk_info != NULL) { in pk_restart_setup()
1025 if (info->rs_alloc_func == NULL || info->rs_free_func == NULL) { in pk_restart_setup()
1029 if ((ctx->rs_ctx = info->rs_alloc_func()) == NULL) { in pk_restart_setup()
1048 if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { in mbedtls_pk_verify_restartable()
1052 if (ctx->pk_info == NULL || in mbedtls_pk_verify_restartable()
1057 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) in mbedtls_pk_verify_restartable()
1058 /* optimization: use non-restartable version if restart disabled */ in mbedtls_pk_verify_restartable()
1059 if (rs_ctx != NULL && in mbedtls_pk_verify_restartable()
1064 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { in mbedtls_pk_verify_restartable()
1071 if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) { in mbedtls_pk_verify_restartable()
1081 if (ctx->pk_info->verify_func == NULL) { in mbedtls_pk_verify_restartable()
1108 if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { in mbedtls_pk_verify_ext()
1112 if (ctx->pk_info == NULL) { in mbedtls_pk_verify_ext()
1116 if (!mbedtls_pk_can_do(ctx, type)) { in mbedtls_pk_verify_ext()
1120 if (type != MBEDTLS_PK_RSASSA_PSS) { in mbedtls_pk_verify_ext()
1122 if (options != NULL) { in mbedtls_pk_verify_ext()
1131 if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) { in mbedtls_pk_verify_ext()
1135 #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) in mbedtls_pk_verify_ext()
1139 #if SIZE_MAX > UINT_MAX in mbedtls_pk_verify_ext()
1140 if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) { in mbedtls_pk_verify_ext()
1145 if (options == NULL) { in mbedtls_pk_verify_ext()
1151 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_verify_ext()
1152 if (pss_opts->mgf1_hash_id == md_alg) { in mbedtls_pk_verify_ext()
1167 if (key_len < 0) { in mbedtls_pk_verify_ext()
1178 if (status != PSA_SUCCESS) { in mbedtls_pk_verify_ext()
1194 if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1198 if (status == PSA_SUCCESS) { in mbedtls_pk_verify_ext()
1206 if (sig_len < mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1215 if (ret != 0) { in mbedtls_pk_verify_ext()
1219 if (sig_len > mbedtls_pk_get_len(ctx)) { in mbedtls_pk_verify_ext()
1240 if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { in mbedtls_pk_sign_restartable()
1244 if (ctx->pk_info == NULL || pk_hashlen_helper(md_alg, &hash_len) != 0) { in mbedtls_pk_sign_restartable()
1248 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) in mbedtls_pk_sign_restartable()
1249 /* optimization: use non-restartable version if restart disabled */ in mbedtls_pk_sign_restartable()
1250 if (rs_ctx != NULL && in mbedtls_pk_sign_restartable()
1255 if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { in mbedtls_pk_sign_restartable()
1264 if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) { in mbedtls_pk_sign_restartable()
1274 if (ctx->pk_info->sign_func == NULL) { in mbedtls_pk_sign_restartable()
1308 if (ctx->pk_info == NULL) { in mbedtls_pk_sign_ext()
1312 if (!mbedtls_pk_can_do(ctx, pk_type)) { in mbedtls_pk_sign_ext()
1316 if (pk_type != MBEDTLS_PK_RSASSA_PSS) { in mbedtls_pk_sign_ext()
1321 #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) in mbedtls_pk_sign_ext()
1323 #if defined(MBEDTLS_USE_PSA_CRYPTO) in mbedtls_pk_sign_ext()
1325 if (psa_md_alg == 0) { in mbedtls_pk_sign_ext()
1329 if (mbedtls_pk_get_type(ctx) == MBEDTLS_PK_OPAQUE) { in mbedtls_pk_sign_ext()
1332 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_sign_ext()
1338 if (status != PSA_SUCCESS) { in mbedtls_pk_sign_ext()
1342 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_sign_ext()
1349 if (PSA_ALG_IS_RSA_PSS(psa_alg)) { in mbedtls_pk_sign_ext()
1352 #if defined(MBEDTLS_PSA_CRYPTO_C) in mbedtls_pk_sign_ext()
1353 else if (PSA_ALG_IS_RSA_PSS(psa_enrollment_alg)) { in mbedtls_pk_sign_ext()
1375 if (sig_size < mbedtls_pk_get_len(ctx)) { in mbedtls_pk_sign_ext()
1379 if (pk_hashlen_helper(md_alg, &hash_len) != 0) { in mbedtls_pk_sign_ext()
1387 if (ret == 0) { in mbedtls_pk_sign_ext()
1407 if (ctx->pk_info == NULL) { in mbedtls_pk_decrypt()
1411 if (ctx->pk_info->decrypt_func == NULL) { in mbedtls_pk_decrypt()
1427 if (ctx->pk_info == NULL) { in mbedtls_pk_encrypt()
1431 if (ctx->pk_info->encrypt_func == NULL) { in mbedtls_pk_encrypt()
1447 if (pub->pk_info == NULL || in mbedtls_pk_check_pair()
1452 if (f_rng == NULL) { in mbedtls_pk_check_pair()
1456 if (prv->pk_info->check_pair_func == NULL) { in mbedtls_pk_check_pair()
1460 if (prv->pk_info->type == MBEDTLS_PK_RSA_ALT) { in mbedtls_pk_check_pair()
1461 if (pub->pk_info->type != MBEDTLS_PK_RSA) { in mbedtls_pk_check_pair()
1465 if ((prv->pk_info->type != MBEDTLS_PK_OPAQUE) && in mbedtls_pk_check_pair()
1483 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_bitlen()
1495 if (ctx->pk_info == NULL) { in mbedtls_pk_debug()
1499 if (ctx->pk_info->debug_func == NULL) { in mbedtls_pk_debug()
1512 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_name()
1524 if (ctx == NULL || ctx->pk_info == NULL) { in mbedtls_pk_get_type()