Lines Matching refs:ret

118     int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;  in mbedtls_pk_parse_keyfile()  local
122 if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) { in mbedtls_pk_parse_keyfile()
123 return ret; in mbedtls_pk_parse_keyfile()
127 ret = mbedtls_pk_parse_key(ctx, buf, n, NULL, 0, f_rng, p_rng); in mbedtls_pk_parse_keyfile()
129 ret = mbedtls_pk_parse_key(ctx, buf, n, in mbedtls_pk_parse_keyfile()
135 return ret; in mbedtls_pk_parse_keyfile()
143 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in mbedtls_pk_parse_public_keyfile() local
147 if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) { in mbedtls_pk_parse_public_keyfile()
148 return ret; in mbedtls_pk_parse_public_keyfile()
151 ret = mbedtls_pk_parse_public_key(ctx, buf, n); in mbedtls_pk_parse_public_keyfile()
155 return ret; in mbedtls_pk_parse_public_keyfile()
171 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_get_ecparams() local
189 if ((ret = mbedtls_asn1_get_tag(p, end, &params->len, params->tag)) != 0) { in pk_get_ecparams()
190 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_get_ecparams()
226 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_group_from_specified() local
234 if ((ret = mbedtls_asn1_get_int(&p, end, &ver)) != 0) { in pk_group_from_specified()
235 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_group_from_specified()
248 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_group_from_specified()
250 return ret; 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()
264 return ret; in pk_group_from_specified()
275 if ((ret = mbedtls_asn1_get_mpi(&p, end_field, &grp->P)) != 0) { in pk_group_from_specified()
276 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_group_from_specified()
295 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_group_from_specified()
297 return ret; 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()
307 (ret = mbedtls_mpi_read_binary(&grp->A, p, len)) != 0) { in pk_group_from_specified()
308 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
314 (ret = mbedtls_mpi_read_binary(&grp->B, p, len)) != 0) { in pk_group_from_specified()
315 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
333 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in pk_group_from_specified()
334 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_group_from_specified()
337 if ((ret = mbedtls_ecp_point_read_binary(grp, &grp->G, 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()
359 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_group_from_specified()
377 int ret = 0; in pk_group_id_from_group() local
407 if (ret == 0 && *id == MBEDTLS_ECP_DP_NONE) { in pk_group_id_from_group()
408 ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; in pk_group_id_from_group()
411 return ret; in pk_group_id_from_group()
420 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_group_id_from_specified() local
425 if ((ret = pk_group_from_specified(params, &grp)) != 0) { in pk_group_id_from_specified()
429 ret = pk_group_id_from_group(&grp, grp_id); in pk_group_id_from_specified()
445 return ret; in pk_group_id_from_specified()
482 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_use_ecparams() local
491 if ((ret = pk_group_id_from_specified(params, &grp_id)) != 0) { in pk_use_ecparams()
492 return ret; in pk_use_ecparams()
500 ret = pk_update_psa_ecparams(pk, grp_id); in pk_use_ecparams()
508 if ((ret = mbedtls_ecp_group_load(&(mbedtls_pk_ec_rw(*pk)->grp), in pk_use_ecparams()
510 return ret; in pk_use_ecparams()
514 return ret; in pk_use_ecparams()
524 int ret; in pk_derive_public_key() local
535 ret = psa_pk_status_to_mbedtls(status); in pk_derive_public_key()
550 ret = psa_pk_status_to_mbedtls(status); in pk_derive_public_key()
551 if (ret != 0) { in pk_derive_public_key()
552 return ret; in pk_derive_public_key()
556 ret = psa_pk_status_to_mbedtls(status); in pk_derive_public_key()
558 if (ret != 0) { in pk_derive_public_key()
559 return ret; in pk_derive_public_key()
563 ret = mbedtls_ecp_point_read_binary(&eck->grp, &eck->Q, key_buf, key_len); in pk_derive_public_key()
570 ret = mbedtls_ecp_mul(&eck->grp, &eck->Q, &eck->d, &eck->grp.G, f_rng, p_rng); in pk_derive_public_key()
572 return ret; in pk_derive_public_key()
584 int ret; in pk_use_ecparams_rfc8410() local
591 ret = pk_update_psa_ecparams(pk, grp_id); in pk_use_ecparams_rfc8410()
594 ret = mbedtls_ecp_group_load(&(ecp->grp), grp_id); in pk_use_ecparams_rfc8410()
595 if (ret != 0) { in pk_use_ecparams_rfc8410()
596 return ret; in pk_use_ecparams_rfc8410()
599 return ret; in pk_use_ecparams_rfc8410()
611 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_parse_key_rfc8410_der() local
614 if ((ret = mbedtls_asn1_get_tag(&key, (key + keylen), &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { in pk_parse_key_rfc8410_der()
615 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_rfc8410_der()
633 ret = psa_pk_status_to_mbedtls(status); in pk_parse_key_rfc8410_der()
634 return ret; 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()
640 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
648 return ret; in pk_parse_key_rfc8410_der()
667 int ret; in pk_convert_compressed_ec() local
672 ret = mbedtls_ecp_group_load(&(ecp_key.grp), ecp_group_id); in pk_convert_compressed_ec()
673 if (ret != 0) { in pk_convert_compressed_ec()
674 return ret; in pk_convert_compressed_ec()
676 ret = mbedtls_ecp_point_read_binary(&(ecp_key.grp), &ecp_key.Q, in pk_convert_compressed_ec()
678 if (ret != 0) { in pk_convert_compressed_ec()
681 ret = mbedtls_ecp_point_write_binary(&(ecp_key.grp), &ecp_key.Q, in pk_convert_compressed_ec()
687 return ret; in pk_convert_compressed_ec()
701 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_get_ecpubkey() local
717 ret = pk_convert_compressed_ec(pk, *p, len, in pk_get_ecpubkey()
720 if (ret != 0) { in pk_get_ecpubkey()
721 return ret; in pk_get_ecpubkey()
748 ret = 0; in pk_get_ecpubkey()
751 if ((ret = mbedtls_ecp_point_read_binary(&ec_key->grp, &ec_key->Q, in pk_get_ecpubkey()
754 ret = mbedtls_ecp_check_pubkey(&ec_key->grp, &ec_key->Q); in pk_get_ecpubkey()
763 return ret; in pk_get_ecpubkey()
778 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_get_rsapubkey() local
781 if ((ret = mbedtls_asn1_get_tag(p, end, &len, in pk_get_rsapubkey()
783 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret); in pk_get_rsapubkey()
792 if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) { in pk_get_rsapubkey()
793 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret); 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()
805 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret); in pk_get_rsapubkey()
808 if ((ret = mbedtls_rsa_import_raw(rsa, NULL, 0, NULL, 0, NULL, 0, in pk_get_rsapubkey()
840 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_get_pk_alg() local
845 if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) { in pk_get_pk_alg()
846 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_ALG, ret); in pk_get_pk_alg()
849 ret = mbedtls_oid_get_pk_alg(&alg_oid, pk_alg); in pk_get_pk_alg()
851 if (ret == MBEDTLS_ERR_OID_NOT_FOUND) { in pk_get_pk_alg()
852 ret = mbedtls_oid_get_ec_grp_algid(&alg_oid, ec_grp_id); in pk_get_pk_alg()
853 if (ret == 0) { in pk_get_pk_alg()
860 if (ret != 0) { in pk_get_pk_alg()
884 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in mbedtls_pk_parse_subpubkey() local
891 if ((ret = mbedtls_asn1_get_tag(p, end, &len, in mbedtls_pk_parse_subpubkey()
893 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
899 return ret; in mbedtls_pk_parse_subpubkey()
902 if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) { in mbedtls_pk_parse_subpubkey()
903 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret); in mbedtls_pk_parse_subpubkey()
915 if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) { in mbedtls_pk_parse_subpubkey()
916 return ret; in mbedtls_pk_parse_subpubkey()
921 ret = pk_get_rsapubkey(p, end, mbedtls_pk_rsa(*pk)); in mbedtls_pk_parse_subpubkey()
928 ret = pk_use_ecparams_rfc8410(&alg_params, ec_grp_id, pk); in mbedtls_pk_parse_subpubkey()
932 ret = pk_use_ecparams(&alg_params, pk); in mbedtls_pk_parse_subpubkey()
934 if (ret == 0) { in mbedtls_pk_parse_subpubkey()
935 ret = pk_get_ecpubkey(p, end, pk); in mbedtls_pk_parse_subpubkey()
939 ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; in mbedtls_pk_parse_subpubkey()
941 if (ret == 0 && *p != end) { in mbedtls_pk_parse_subpubkey()
942 ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, in mbedtls_pk_parse_subpubkey()
946 if (ret != 0) { in mbedtls_pk_parse_subpubkey()
950 return ret; in mbedtls_pk_parse_subpubkey()
968 int ret; in asn1_get_nonzero_mpi() local
970 ret = mbedtls_asn1_get_mpi(p, end, X); in asn1_get_nonzero_mpi()
971 if (ret != 0) { in asn1_get_nonzero_mpi()
972 return ret; in asn1_get_nonzero_mpi()
989 int ret, version; in pk_parse_key_pkcs1_der() local
1015 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_pkcs1_der()
1017 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_pkcs1_der()
1022 if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { in pk_parse_key_pkcs1_der()
1023 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_pkcs1_der()
1031 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1032 (ret = mbedtls_rsa_import(rsa, &T, NULL, NULL, in pk_parse_key_pkcs1_der()
1038 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1039 (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, in pk_parse_key_pkcs1_der()
1045 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1046 (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, in pk_parse_key_pkcs1_der()
1052 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1053 (ret = mbedtls_rsa_import(rsa, NULL, &T, NULL, in pk_parse_key_pkcs1_der()
1059 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1060 (ret = mbedtls_rsa_import(rsa, NULL, NULL, &T, in pk_parse_key_pkcs1_der()
1078 if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1079 (ret = mbedtls_mpi_copy(&rsa->DP, &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()
1085 (ret = mbedtls_mpi_copy(&rsa->DQ, &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()
1091 (ret = mbedtls_mpi_copy(&rsa->QP, &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()
1098 (ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || in pk_parse_key_pkcs1_der()
1099 (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()
1114 (ret = mbedtls_rsa_check_pubkey(rsa)) != 0) { in pk_parse_key_pkcs1_der()
1119 ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, in pk_parse_key_pkcs1_der()
1127 if (ret != 0) { in pk_parse_key_pkcs1_der()
1129 if ((ret & 0xff80) == 0) { in pk_parse_key_pkcs1_der()
1130 ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_pkcs1_der()
1132 ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; in pk_parse_key_pkcs1_der()
1138 return ret; in pk_parse_key_pkcs1_der()
1150 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in pk_parse_key_sec1_der() local
1175 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_sec1_der()
1177 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_sec1_der()
1182 if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { in pk_parse_key_sec1_der()
1183 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1191 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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, &params)) != 0 || in pk_parse_key_sec1_der()
1210 (ret = pk_use_ecparams(&params, pk)) != 0) { in pk_parse_key_sec1_der()
1211 return ret; in pk_parse_key_sec1_der()
1213 } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { in pk_parse_key_sec1_der()
1214 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1221 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1236 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_sec1_der()
1244 if ((ret = pk_get_ecpubkey(&p, end2, pk)) == 0) { 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()
1256 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_sec1_der()
1276 ret = psa_pk_status_to_mbedtls(status); in pk_parse_key_sec1_der()
1277 return ret; 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()
1283 return ret; in pk_parse_key_sec1_der()
1309 int ret, version; in pk_parse_key_pkcs8_unencrypted_der() local
1339 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in pk_parse_key_pkcs8_unencrypted_der()
1341 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1347 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_pkcs8_unencrypted_der()
1351 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret); in pk_parse_key_pkcs8_unencrypted_der()
1354 if ((ret = pk_get_pk_alg(&p, end, &pk_alg, &params, &ec_grp_id)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1355 return ret; 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()
1359 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); in pk_parse_key_pkcs8_unencrypted_der()
1371 if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1372 return ret; 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()
1379 return ret; in pk_parse_key_pkcs8_unencrypted_der()
1387 if ((ret = in pk_parse_key_pkcs8_unencrypted_der()
1389 (ret = in pk_parse_key_pkcs8_unencrypted_der()
1393 return ret; in pk_parse_key_pkcs8_unencrypted_der()
1398 if ((ret = pk_use_ecparams(&params, pk)) != 0 || in pk_parse_key_pkcs8_unencrypted_der()
1399 (ret = pk_parse_key_sec1_der(pk, p, len, f_rng, p_rng)) != 0) { in pk_parse_key_pkcs8_unencrypted_der()
1401 return ret; in pk_parse_key_pkcs8_unencrypted_der()
1433 int ret, decrypted = 0; in mbedtls_pk_parse_key_pkcs8_encrypted_der() local
1466 if ((ret = mbedtls_asn1_get_tag(&p, end, &len, in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1468 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1474 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1478 return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); 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()
1495 return ret; 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()
1509 return ret; in mbedtls_pk_parse_key_pkcs8_encrypted_der()
1534 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in mbedtls_pk_parse_key() local
1551 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1553 ret = mbedtls_pem_read_buffer(&pem, 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()
1562 (ret = pk_parse_key_pkcs1_der(mbedtls_pk_rsa(*pk), in mbedtls_pk_parse_key()
1568 return ret; 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()
1574 return ret; in mbedtls_pk_parse_key()
1581 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1583 ret = mbedtls_pem_read_buffer(&pem, 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()
1592 (ret = pk_parse_key_sec1_der(pk, in mbedtls_pk_parse_key()
1599 return ret; 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()
1605 return ret; in mbedtls_pk_parse_key()
1611 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1613 ret = mbedtls_pem_read_buffer(&pem, 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()
1625 return ret; in mbedtls_pk_parse_key()
1626 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_key()
1627 return ret; in mbedtls_pk_parse_key()
1633 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1635 ret = mbedtls_pem_read_buffer(&pem, 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()
1647 return ret; in mbedtls_pk_parse_key()
1648 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_key()
1649 return ret; in mbedtls_pk_parse_key()
1674 ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, key_copy, keylen, 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()
1688 return ret; in mbedtls_pk_parse_key()
1692 ret = pk_parse_key_pkcs8_unencrypted_der(pk, key, keylen, f_rng, p_rng); in mbedtls_pk_parse_key()
1693 if (ret == 0) { in mbedtls_pk_parse_key()
1741 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; in mbedtls_pk_parse_public_key() local
1760 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_public_key()
1762 ret = mbedtls_pem_read_buffer(&pem, in mbedtls_pk_parse_public_key()
1768 if (ret == 0) { in mbedtls_pk_parse_public_key()
1775 if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) { in mbedtls_pk_parse_public_key()
1777 return ret; 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()
1785 return ret; in mbedtls_pk_parse_public_key()
1786 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_public_key()
1788 return ret; in mbedtls_pk_parse_public_key()
1794 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_public_key()
1796 ret = mbedtls_pem_read_buffer(&pem, in mbedtls_pk_parse_public_key()
1802 if (ret == 0) { in mbedtls_pk_parse_public_key()
1808 ret = mbedtls_pk_parse_subpubkey(&p, p + pem.buflen, ctx); in mbedtls_pk_parse_public_key()
1810 return ret; in mbedtls_pk_parse_public_key()
1811 } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { in mbedtls_pk_parse_public_key()
1813 return ret; in mbedtls_pk_parse_public_key()
1823 if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) { in mbedtls_pk_parse_public_key()
1824 return ret; in mbedtls_pk_parse_public_key()
1828 ret = pk_get_rsapubkey(&p, p + keylen, mbedtls_pk_rsa(*ctx)); in mbedtls_pk_parse_public_key()
1829 if (ret == 0) { in mbedtls_pk_parse_public_key()
1830 return ret; in mbedtls_pk_parse_public_key()
1833 if (ret != (MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, in mbedtls_pk_parse_public_key()
1835 return ret; in mbedtls_pk_parse_public_key()
1840 ret = mbedtls_pk_parse_subpubkey(&p, p + keylen, ctx); in mbedtls_pk_parse_public_key()
1842 return ret; in mbedtls_pk_parse_public_key()