Lines Matching full:if
10 #if defined(MBEDTLS_PK_PARSE_C)
21 #if defined(MBEDTLS_RSA_C)
25 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
28 #if defined(MBEDTLS_ECDSA_C)
31 #if defined(MBEDTLS_PEM_PARSE_C)
34 #if defined(MBEDTLS_PKCS5_C)
37 #if defined(MBEDTLS_PKCS12_C)
41 #if defined(MBEDTLS_PSA_CRYPTO_C)
45 #if defined(MBEDTLS_USE_PSA_CRYPTO)
52 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) && defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
57 #if defined(MBEDTLS_FS_IO)
63 * length only if the data looks like it is PEM encoded.
70 if ((f = fopen(path, "rb")) == NULL) { in mbedtls_pk_load_file()
78 if ((size = ftell(f)) == -1) { in mbedtls_pk_load_file()
86 if (*n + 1 == 0 || in mbedtls_pk_load_file()
92 if (fread(*buf, 1, *n, f) != *n) { in mbedtls_pk_load_file()
104 if (strstr((const char *) *buf, "-----BEGIN ") != NULL) { in mbedtls_pk_load_file()
122 if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) { in mbedtls_pk_parse_keyfile()
126 if (pwd == NULL) { in mbedtls_pk_parse_keyfile()
147 if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) { in mbedtls_pk_parse_public_keyfile()
159 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
173 if (end - *p < 1) { in pk_get_ecparams()
180 if (params->tag != MBEDTLS_ASN1_OID in pk_get_ecparams()
181 #if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) in pk_get_ecparams()
189 if ((ret = mbedtls_asn1_get_tag(p, end, ¶ms->len, params->tag)) != 0) { in pk_get_ecparams()
196 if (*p != end) { in pk_get_ecparams()
204 #if defined(MBEDTLS_PK_PARSE_EC_EXTENDED)
209 * if it was encoded compressed.
234 if ((ret = mbedtls_asn1_get_int(&p, end, &ver)) != 0) { in pk_group_from_specified()
238 if (ver < 1 || ver > 3) { in pk_group_from_specified()
248 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_group_from_specified()
263 if ((ret = mbedtls_asn1_get_tag(&p, end_field, &len, MBEDTLS_ASN1_OID)) != 0) { in pk_group_from_specified()
267 if (len != MBEDTLS_OID_SIZE(MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD) || in pk_group_from_specified()
275 if ((ret = mbedtls_asn1_get_mpi(&p, end_field, &grp->P)) != 0) { in pk_group_from_specified()
281 if (p != end_field) { in pk_group_from_specified()
291 * -- Shall be present if used in SpecifiedECDomain in pk_group_from_specified()
295 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_group_from_specified()
306 if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 || in pk_group_from_specified()
313 if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 || in pk_group_from_specified()
321 if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING)) == 0) { in pk_group_from_specified()
325 if (p != end_curve) { in pk_group_from_specified()
333 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in pk_group_from_specified()
337 if ((ret = mbedtls_ecp_point_read_binary(grp, &grp->G, in pk_group_from_specified()
340 * If we can't read the point because it's compressed, cheat by in pk_group_from_specified()
343 if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE || in pk_group_from_specified()
358 if ((ret = mbedtls_asn1_get_mpi(&p, end, &grp->N)) != 0) { in pk_group_from_specified()
373 * pk_group_from_specified(), or return an error if unknown.
389 if (grp->pbits == ref.pbits && grp->nbits == ref.nbits && in pk_group_id_from_group()
407 if (ret == 0 && *id == MBEDTLS_ECP_DP_NONE) { in pk_group_id_from_group()
425 if ((ret = pk_group_from_specified(params, &grp)) != 0) { in pk_group_id_from_specified()
449 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
461 if ((pk->ec_family != 0) && (pk->ec_family != ec_family)) { in pk_update_psa_ecparams()
485 if (params->tag == MBEDTLS_ASN1_OID) { in pk_use_ecparams()
486 if (mbedtls_oid_get_ec_grp(params, &grp_id) != 0) { in pk_use_ecparams()
490 #if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) in pk_use_ecparams()
491 if ((ret = pk_group_id_from_specified(params, &grp_id)) != 0) { in pk_use_ecparams()
499 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_use_ecparams()
502 /* grp may already be initialized; if so, make sure IDs match */ in pk_use_ecparams()
503 if (mbedtls_pk_ec_ro(*pk)->grp.id != MBEDTLS_ECP_DP_NONE && in pk_use_ecparams()
508 if ((ret = mbedtls_ecp_group_load(&(mbedtls_pk_ec_rw(*pk)->grp), in pk_use_ecparams()
525 #if defined(MBEDTLS_USE_PSA_CRYPTO) in pk_derive_public_key()
529 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_derive_public_key()
551 if (ret != 0) { in pk_derive_public_key()
558 if (ret != 0) { in pk_derive_public_key()
560 } else if (destruction_status != PSA_SUCCESS) { in pk_derive_public_key()
575 #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES)
586 if (params->tag != 0 || params->len != 0) { in pk_use_ecparams_rfc8410()
590 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_use_ecparams_rfc8410()
595 if (ret != 0) { in pk_use_ecparams_rfc8410()
614 if ((ret = mbedtls_asn1_get_tag(&key, (key + keylen), &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in pk_parse_key_rfc8410_der()
618 if (key + len != end) { in pk_parse_key_rfc8410_der()
622 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_parse_key_rfc8410_der()
632 if (status != PSA_SUCCESS) { in pk_parse_key_rfc8410_der()
639 if ((ret = mbedtls_ecp_read_key(eck->grp.id, eck, key, len)) != 0) { in pk_parse_key_rfc8410_der()
647 if ((ret = pk_derive_public_key(pk, key, len, f_rng, p_rng)) != 0) { in pk_parse_key_rfc8410_der()
655 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) && defined(MBEDTLS_PK_PARSE_EC_COMPRESSED)
673 if (ret != 0) { in pk_convert_compressed_ec()
678 if (ret != 0) { in pk_convert_compressed_ec()
694 * The caller is responsible for clearing the structure upon failure if
703 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_get_ecpubkey()
708 if (len > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) { in pk_get_ecpubkey()
715 if ((**p == 0x02) || (**p == 0x03)) { in pk_get_ecpubkey()
716 #if defined(MBEDTLS_PK_PARSE_EC_COMPRESSED) in pk_get_ecpubkey()
720 if (ret != 0) { in pk_get_ecpubkey()
728 if ((size_t) (end - *p) > MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN) { in pk_get_ecpubkey()
741 if ((psa_import_key(&key_attrs, pk->pub_raw, pk->pub_raw_len, in pk_get_ecpubkey()
751 if ((ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, in pk_get_ecpubkey()
767 #if defined(MBEDTLS_RSA_C)
781 if ((ret = mbedtls_asn1_get_tag(p, end, &len, in pk_get_rsapubkey()
786 if (*p + len != end) { in pk_get_rsapubkey()
792 if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) { in pk_get_rsapubkey()
796 if ((ret = mbedtls_rsa_import_raw(rsa, *p, len, NULL, 0, NULL, 0, in pk_get_rsapubkey()
804 if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) { in pk_get_rsapubkey()
808 if ((ret = mbedtls_rsa_import_raw(rsa, NULL, 0, NULL, 0, NULL, 0, in pk_get_rsapubkey()
815 if (mbedtls_rsa_complete(rsa) != 0 || in pk_get_rsapubkey()
820 if (*p != end) { in pk_get_rsapubkey()
845 if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) { in pk_get_pk_alg()
850 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in pk_get_pk_alg()
851 if (ret == MBEDTLS_ERR_OID_NOT_FOUND) { in pk_get_pk_alg()
853 if (ret == 0) { in pk_get_pk_alg()
860 if (ret != 0) { in pk_get_pk_alg()
867 if (*pk_alg == MBEDTLS_PK_RSA && in pk_get_pk_alg()
891 if ((ret = mbedtls_asn1_get_tag(p, end, &len, in mbedtls_pk_parse_subpubkey()
898 if ((ret = pk_get_pk_alg(p, end, &pk_alg, &alg_params, &ec_grp_id)) != 0) { in mbedtls_pk_parse_subpubkey()
902 if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) { in mbedtls_pk_parse_subpubkey()
906 if (*p + len != end) { in mbedtls_pk_parse_subpubkey()
911 if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) { in mbedtls_pk_parse_subpubkey()
915 if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) { in mbedtls_pk_parse_subpubkey()
919 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_parse_subpubkey()
920 if (pk_alg == MBEDTLS_PK_RSA) { in mbedtls_pk_parse_subpubkey()
924 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_parse_subpubkey()
925 if (pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY) { in mbedtls_pk_parse_subpubkey()
926 #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES) in mbedtls_pk_parse_subpubkey()
927 if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) { in mbedtls_pk_parse_subpubkey()
934 if (ret == 0) { in mbedtls_pk_parse_subpubkey()
941 if (ret == 0 && *p != end) { in mbedtls_pk_parse_subpubkey()
946 if (ret != 0) { in mbedtls_pk_parse_subpubkey()
953 #if defined(MBEDTLS_RSA_C)
971 if (ret != 0) { in asn1_get_nonzero_mpi()
975 if (mbedtls_mpi_cmp_int(X, 0) == 0) { in asn1_get_nonzero_mpi()
1015 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_pkcs1_der()
1022 if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { in pk_parse_key_pkcs1_der()
1026 if (version != 0) { in pk_parse_key_pkcs1_der()
1031 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1038 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1045 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1052 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1059 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1065 #if !defined(MBEDTLS_RSA_NO_CRT) && !defined(MBEDTLS_RSA_ALT) in pk_parse_key_pkcs1_der()
1078 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1084 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1090 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1097 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1113 if ((ret = mbedtls_rsa_complete(rsa)) != 0 || in pk_parse_key_pkcs1_der()
1118 if (p != end) { in pk_parse_key_pkcs1_der()
1127 if (ret != 0) { in pk_parse_key_pkcs1_der()
1128 /* Wrap error code if it's coming from a lower level */ in pk_parse_key_pkcs1_der()
1129 if ((ret & 0xff80) == 0) { in pk_parse_key_pkcs1_der()
1142 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS)
1158 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_parse_key_sec1_der()
1175 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_sec1_der()
1182 if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { in pk_parse_key_sec1_der()
1186 if (version != 1) { in pk_parse_key_sec1_der()
1190 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in pk_parse_key_sec1_der()
1202 if (p != end) { in pk_parse_key_sec1_der()
1206 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_sec1_der()
1209 if ((ret = pk_get_ecparams(&p, p + len, ¶ms)) != 0 || in pk_parse_key_sec1_der()
1213 } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { in pk_parse_key_sec1_der()
1219 #if !defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_parse_key_sec1_der()
1220 if ((ret = mbedtls_ecp_read_key(eck->grp.id, eck, d, d_len)) != 0) { in pk_parse_key_sec1_der()
1225 if (p != end) { in pk_parse_key_sec1_der()
1227 * Is 'publickey' present? If not, or if we can't read it (eg because it in pk_parse_key_sec1_der()
1230 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_sec1_der()
1235 if ((ret = mbedtls_asn1_get_bitstring_null(&p, end2, &len)) != 0) { in pk_parse_key_sec1_der()
1239 if (p + len != end2) { in pk_parse_key_sec1_der()
1244 if ((ret = pk_get_ecpubkey(&p, end2, pk)) == 0) { in pk_parse_key_sec1_der()
1249 * is if the point format is not recognized. in pk_parse_key_sec1_der()
1251 if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) { in pk_parse_key_sec1_der()
1255 } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { in pk_parse_key_sec1_der()
1260 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) in pk_parse_key_sec1_der()
1266 #if defined(MBEDTLS_ECDSA_DETERMINISTIC) in pk_parse_key_sec1_der()
1275 if (status != PSA_SUCCESS) { in pk_parse_key_sec1_der()
1281 if (!pubkey_done) { in pk_parse_key_sec1_der()
1282 if ((ret = pk_derive_public_key(pk, d, d_len, f_rng, p_rng)) != 0) { in pk_parse_key_sec1_der()
1318 #if !defined(MBEDTLS_PK_HAVE_ECC_KEYS) in pk_parse_key_pkcs8_unencrypted_der()
1339 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_pkcs8_unencrypted_der()
1346 if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1350 if (version != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1354 if ((ret = pk_get_pk_alg(&p, end, &pk_alg, ¶ms, &ec_grp_id)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1358 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1362 if (len < 1) { in pk_parse_key_pkcs8_unencrypted_der()
1367 if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) { in pk_parse_key_pkcs8_unencrypted_der()
1371 if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1375 #if defined(MBEDTLS_RSA_C) in pk_parse_key_pkcs8_unencrypted_der()
1376 if (pk_alg == MBEDTLS_PK_RSA) { in pk_parse_key_pkcs8_unencrypted_der()
1377 if ((ret = pk_parse_key_pkcs1_der(mbedtls_pk_rsa(*pk), p, len)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1383 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in pk_parse_key_pkcs8_unencrypted_der()
1384 if (pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH) { in pk_parse_key_pkcs8_unencrypted_der()
1385 #if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES) in pk_parse_key_pkcs8_unencrypted_der()
1386 if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) { in pk_parse_key_pkcs8_unencrypted_der()
1387 if ((ret = in pk_parse_key_pkcs8_unencrypted_der()
1398 if ((ret = pk_use_ecparams(¶ms, pk)) != 0 || in pk_parse_key_pkcs8_unencrypted_der()
1409 if (end != (key + keylen)) { in pk_parse_key_pkcs8_unencrypted_der()
1426 #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
1438 #if defined(MBEDTLS_PKCS12_C) in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1447 if (pwdlen == 0) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1466 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1473 if ((ret = mbedtls_asn1_get_alg(&p, end, &pbe_alg_oid, &pbe_params)) != 0) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1477 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1486 #if defined(MBEDTLS_PKCS12_C) in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1487 if (mbedtls_oid_get_pkcs12_pbe_alg(&pbe_alg_oid, &md_alg, &cipher_alg) == 0) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1488 if ((ret = mbedtls_pkcs12_pbe_ext(&pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1491 if (ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1501 #if defined(MBEDTLS_PKCS5_C) in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1502 if (MBEDTLS_OID_CMP(MBEDTLS_OID_PKCS5_PBES2, &pbe_alg_oid) == 0) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1503 if ((ret = mbedtls_pkcs5_pbes2_ext(&pbe_params, MBEDTLS_PKCS5_DECRYPT, pwd, pwdlen, in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1505 if (ret == MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1519 if (decrypted == 0) { in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1536 #if defined(MBEDTLS_PEM_PARSE_C) in mbedtls_pk_parse_key()
1541 if (keylen == 0) { in mbedtls_pk_parse_key()
1545 #if defined(MBEDTLS_PEM_PARSE_C) in mbedtls_pk_parse_key()
1548 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_parse_key()
1550 if (key[keylen - 1] != '\0') { in mbedtls_pk_parse_key()
1559 if (ret == 0) { in mbedtls_pk_parse_key()
1561 if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 || in mbedtls_pk_parse_key()
1569 } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) { in mbedtls_pk_parse_key()
1571 } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) { in mbedtls_pk_parse_key()
1573 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_key()
1578 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_parse_key()
1580 if (key[keylen - 1] != '\0') { in mbedtls_pk_parse_key()
1588 if (ret == 0) { in mbedtls_pk_parse_key()
1591 if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 || in mbedtls_pk_parse_key()
1600 } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) { in mbedtls_pk_parse_key()
1602 } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) { in mbedtls_pk_parse_key()
1604 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_key()
1610 if (key[keylen - 1] != '\0') { in mbedtls_pk_parse_key()
1618 if (ret == 0) { in mbedtls_pk_parse_key()
1619 if ((ret = pk_parse_key_pkcs8_unencrypted_der(pk, in mbedtls_pk_parse_key()
1626 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_key()
1630 #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) in mbedtls_pk_parse_key()
1632 if (key[keylen - 1] != '\0') { in mbedtls_pk_parse_key()
1640 if (ret == 0) { in mbedtls_pk_parse_key()
1641 if ((ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, pem.buf, pem.buflen, in mbedtls_pk_parse_key()
1648 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_key()
1661 * We try the different DER format parsers to see if one passes without in mbedtls_pk_parse_key()
1664 #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) in mbedtls_pk_parse_key()
1665 if (pwdlen != 0) { in mbedtls_pk_parse_key()
1668 if ((key_copy = mbedtls_calloc(1, keylen)) == NULL) { in mbedtls_pk_parse_key()
1680 if (ret == 0) { in mbedtls_pk_parse_key()
1687 if (ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH) { in mbedtls_pk_parse_key()
1693 if (ret == 0) { in mbedtls_pk_parse_key()
1700 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_parse_key()
1703 if (mbedtls_pk_setup(pk, pk_info) == 0 && in mbedtls_pk_parse_key()
1712 #if defined(MBEDTLS_PK_HAVE_ECC_KEYS) in mbedtls_pk_parse_key()
1714 if (mbedtls_pk_setup(pk, pk_info) == 0 && in mbedtls_pk_parse_key()
1722 /* If MBEDTLS_RSA_C is defined but MBEDTLS_PK_HAVE_ECC_KEYS isn't, in mbedtls_pk_parse_key()
1726 * when it fails. If MBEDTLS_PK_HAVE_ECC_KEYS is defined but MBEDTLS_RSA_C in mbedtls_pk_parse_key()
1743 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_parse_public_key()
1746 #if defined(MBEDTLS_PEM_PARSE_C) in mbedtls_pk_parse_public_key()
1751 if (keylen == 0) { in mbedtls_pk_parse_public_key()
1755 #if defined(MBEDTLS_PEM_PARSE_C) in mbedtls_pk_parse_public_key()
1757 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_parse_public_key()
1759 if (key[keylen - 1] != '\0') { in mbedtls_pk_parse_public_key()
1768 if (ret == 0) { in mbedtls_pk_parse_public_key()
1770 if ((pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == NULL) { in mbedtls_pk_parse_public_key()
1775 if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) { in mbedtls_pk_parse_public_key()
1780 if ((ret = pk_get_rsapubkey(&p, p + pem.buflen, mbedtls_pk_rsa(*ctx))) != 0) { in mbedtls_pk_parse_public_key()
1786 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_public_key()
1793 if (key[keylen - 1] != '\0') { in mbedtls_pk_parse_public_key()
1802 if (ret == 0) { in mbedtls_pk_parse_public_key()
1811 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_public_key()
1818 #if defined(MBEDTLS_RSA_C) in mbedtls_pk_parse_public_key()
1819 if ((pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == NULL) { in mbedtls_pk_parse_public_key()
1823 if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) { in mbedtls_pk_parse_public_key()
1829 if (ret == 0) { in mbedtls_pk_parse_public_key()
1833 if (ret != (MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, in mbedtls_pk_parse_public_key()