Lines Matching refs:ret

124     int ret;  in mbedtls_pk_parse_keyfile()  local
128 if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) in mbedtls_pk_parse_keyfile()
129 return( ret ); in mbedtls_pk_parse_keyfile()
132 ret = mbedtls_pk_parse_key( ctx, buf, n, NULL, 0 ); in mbedtls_pk_parse_keyfile()
134 ret = mbedtls_pk_parse_key( ctx, buf, n, in mbedtls_pk_parse_keyfile()
140 return( ret ); in mbedtls_pk_parse_keyfile()
148 int ret; in mbedtls_pk_parse_public_keyfile() local
152 if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) in mbedtls_pk_parse_public_keyfile()
153 return( ret ); in mbedtls_pk_parse_public_keyfile()
155 ret = mbedtls_pk_parse_public_key( ctx, buf, n ); in mbedtls_pk_parse_public_keyfile()
160 return( ret ); in mbedtls_pk_parse_public_keyfile()
176 int ret; in pk_get_ecparams() local
190 if( ( ret = mbedtls_asn1_get_tag( p, end, &params->len, params->tag ) ) != 0 ) in pk_get_ecparams()
192 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_get_ecparams()
227 int ret; in pk_group_from_specified() local
235 if( ( ret = mbedtls_asn1_get_int( &p, end, &ver ) ) != 0 ) in pk_group_from_specified()
236 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_group_from_specified()
247 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_group_from_specified()
249 return( ret ); in pk_group_from_specified()
261 if( ( ret = mbedtls_asn1_get_tag( &p, end_field, &len, MBEDTLS_ASN1_OID ) ) != 0 ) in pk_group_from_specified()
262 return( ret ); in pk_group_from_specified()
273 if( ( ret = mbedtls_asn1_get_mpi( &p, end_field, &grp->P ) ) != 0 ) in pk_group_from_specified()
274 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_group_from_specified()
291 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_group_from_specified()
293 return( ret ); in pk_group_from_specified()
301 if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 || in pk_group_from_specified()
302 ( ret = mbedtls_mpi_read_binary( &grp->A, p, len ) ) != 0 ) in pk_group_from_specified()
304 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_group_from_specified()
309 if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 || in pk_group_from_specified()
310 ( ret = mbedtls_mpi_read_binary( &grp->B, p, len ) ) != 0 ) in pk_group_from_specified()
312 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_group_from_specified()
318 if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING ) ) == 0 ) in pk_group_from_specified()
328 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) in pk_group_from_specified()
329 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_group_from_specified()
331 if( ( ret = mbedtls_ecp_point_read_binary( grp, &grp->G, in pk_group_from_specified()
338 if( ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE || in pk_group_from_specified()
354 if( ( ret = mbedtls_asn1_get_mpi( &p, end, &grp->N ) ) != 0 ) in pk_group_from_specified()
355 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_group_from_specified()
372 int ret = 0; in pk_group_id_from_group() local
405 if( ret == 0 && *id == MBEDTLS_ECP_DP_NONE ) in pk_group_id_from_group()
406 ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; in pk_group_id_from_group()
408 return( ret ); in pk_group_id_from_group()
417 int ret; in pk_group_id_from_specified() local
422 if( ( ret = pk_group_from_specified( params, &grp ) ) != 0 ) in pk_group_id_from_specified()
425 ret = pk_group_id_from_group( &grp, grp_id ); in pk_group_id_from_specified()
430 return( ret ); in pk_group_id_from_specified()
444 int ret; in pk_use_ecparams() local
455 if( ( ret = pk_group_id_from_specified( params, &grp_id ) ) != 0 ) in pk_use_ecparams()
456 return( ret ); in pk_use_ecparams()
468 if( ( ret = mbedtls_ecp_group_load( grp, grp_id ) ) != 0 ) in pk_use_ecparams()
469 return( ret ); in pk_use_ecparams()
484 int ret; in pk_get_ecpubkey() local
486 if( ( ret = mbedtls_ecp_point_read_binary( &key->grp, &key->Q, in pk_get_ecpubkey()
489 ret = mbedtls_ecp_check_pubkey( &key->grp, &key->Q ); in pk_get_ecpubkey()
497 return( ret ); in pk_get_ecpubkey()
512 int ret; in pk_get_rsapubkey() local
515 if( ( ret = mbedtls_asn1_get_tag( p, end, &len, in pk_get_rsapubkey()
517 return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret ); in pk_get_rsapubkey()
523 if( ( ret = mbedtls_asn1_get_mpi( p, end, &rsa->N ) ) != 0 || in pk_get_rsapubkey()
524 ( ret = mbedtls_asn1_get_mpi( p, end, &rsa->E ) ) != 0 ) in pk_get_rsapubkey()
525 return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret ); in pk_get_rsapubkey()
531 if( ( ret = mbedtls_rsa_check_pubkey( rsa ) ) != 0 ) in pk_get_rsapubkey()
550 int ret; in pk_get_pk_alg() local
555 if( ( ret = mbedtls_asn1_get_alg( p, end, &alg_oid, params ) ) != 0 ) in pk_get_pk_alg()
556 return( MBEDTLS_ERR_PK_INVALID_ALG + ret ); in pk_get_pk_alg()
582 int ret; in mbedtls_pk_parse_subpubkey() local
588 if( ( ret = mbedtls_asn1_get_tag( p, end, &len, in mbedtls_pk_parse_subpubkey()
591 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in mbedtls_pk_parse_subpubkey()
596 if( ( ret = pk_get_pk_alg( p, end, &pk_alg, &alg_params ) ) != 0 ) in mbedtls_pk_parse_subpubkey()
597 return( ret ); in mbedtls_pk_parse_subpubkey()
599 if( ( ret = mbedtls_asn1_get_bitstring_null( p, end, &len ) ) != 0 ) in mbedtls_pk_parse_subpubkey()
600 return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret ); in mbedtls_pk_parse_subpubkey()
609 if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ) in mbedtls_pk_parse_subpubkey()
610 return( ret ); in mbedtls_pk_parse_subpubkey()
615 ret = pk_get_rsapubkey( p, end, mbedtls_pk_rsa( *pk ) ); in mbedtls_pk_parse_subpubkey()
621 ret = pk_use_ecparams( &alg_params, &mbedtls_pk_ec( *pk )->grp ); in mbedtls_pk_parse_subpubkey()
622 if( ret == 0 ) in mbedtls_pk_parse_subpubkey()
623 ret = pk_get_ecpubkey( p, end, mbedtls_pk_ec( *pk ) ); in mbedtls_pk_parse_subpubkey()
626 ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; in mbedtls_pk_parse_subpubkey()
628 if( ret == 0 && *p != end ) in mbedtls_pk_parse_subpubkey()
629 ret = MBEDTLS_ERR_PK_INVALID_PUBKEY in mbedtls_pk_parse_subpubkey()
632 if( ret != 0 ) in mbedtls_pk_parse_subpubkey()
635 return( ret ); in mbedtls_pk_parse_subpubkey()
646 int ret; in pk_parse_key_pkcs1_der() local
669 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_parse_key_pkcs1_der()
672 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs1_der()
677 if( ( ret = mbedtls_asn1_get_int( &p, end, &rsa->ver ) ) != 0 ) in pk_parse_key_pkcs1_der()
679 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs1_der()
687 if( ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->N ) ) != 0 || in pk_parse_key_pkcs1_der()
688 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->E ) ) != 0 || in pk_parse_key_pkcs1_der()
689 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->D ) ) != 0 || in pk_parse_key_pkcs1_der()
690 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->P ) ) != 0 || in pk_parse_key_pkcs1_der()
691 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->Q ) ) != 0 || in pk_parse_key_pkcs1_der()
692 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->DP ) ) != 0 || in pk_parse_key_pkcs1_der()
693 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->DQ ) ) != 0 || in pk_parse_key_pkcs1_der()
694 ( ret = mbedtls_asn1_get_mpi( &p, end, &rsa->QP ) ) != 0 ) in pk_parse_key_pkcs1_der()
697 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs1_der()
709 if( ( ret = mbedtls_rsa_check_privkey( rsa ) ) != 0 ) in pk_parse_key_pkcs1_der()
712 return( ret ); in pk_parse_key_pkcs1_der()
727 int ret; in pk_parse_key_sec1_der() local
745 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_parse_key_sec1_der()
748 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
753 if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) in pk_parse_key_sec1_der()
754 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
759 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) in pk_parse_key_sec1_der()
760 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
762 if( ( ret = mbedtls_mpi_read_binary( &eck->d, p, len ) ) != 0 ) in pk_parse_key_sec1_der()
765 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
776 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_parse_key_sec1_der()
779 if( ( ret = pk_get_ecparams( &p, p + len, &params) ) != 0 || in pk_parse_key_sec1_der()
780 ( ret = pk_use_ecparams( &params, &eck->grp ) ) != 0 ) in pk_parse_key_sec1_der()
783 return( ret ); in pk_parse_key_sec1_der()
786 else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) in pk_parse_key_sec1_der()
789 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
796 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_parse_key_sec1_der()
801 if( ( ret = mbedtls_asn1_get_bitstring_null( &p, end2, &len ) ) != 0 ) in pk_parse_key_sec1_der()
802 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
808 if( ( ret = pk_get_ecpubkey( &p, end2, eck ) ) == 0 ) in pk_parse_key_sec1_der()
816 if( ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ) in pk_parse_key_sec1_der()
820 else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) in pk_parse_key_sec1_der()
823 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
828 ( ret = mbedtls_ecp_mul( &eck->grp, &eck->Q, &eck->d, &eck->grp.G, in pk_parse_key_sec1_der()
832 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_sec1_der()
835 if( ( ret = mbedtls_ecp_check_privkey( &eck->grp, &eck->d ) ) != 0 ) in pk_parse_key_sec1_der()
838 return( ret ); in pk_parse_key_sec1_der()
853 int ret, version; in pk_parse_key_pkcs8_unencrypted_der() local
877 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_parse_key_pkcs8_unencrypted_der()
880 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_unencrypted_der()
885 if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) in pk_parse_key_pkcs8_unencrypted_der()
886 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_unencrypted_der()
889 return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION + ret ); in pk_parse_key_pkcs8_unencrypted_der()
891 if( ( ret = pk_get_pk_alg( &p, end, &pk_alg, &params ) ) != 0 ) in pk_parse_key_pkcs8_unencrypted_der()
892 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_unencrypted_der()
894 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) in pk_parse_key_pkcs8_unencrypted_der()
895 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_unencrypted_der()
904 if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ) in pk_parse_key_pkcs8_unencrypted_der()
905 return( ret ); in pk_parse_key_pkcs8_unencrypted_der()
910 if( ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), p, len ) ) != 0 ) in pk_parse_key_pkcs8_unencrypted_der()
913 return( ret ); in pk_parse_key_pkcs8_unencrypted_der()
920 if( ( ret = pk_use_ecparams( &params, &mbedtls_pk_ec( *pk )->grp ) ) != 0 || in pk_parse_key_pkcs8_unencrypted_der()
921 ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), p, len ) ) != 0 ) in pk_parse_key_pkcs8_unencrypted_der()
924 return( ret ); in pk_parse_key_pkcs8_unencrypted_der()
942 int ret, decrypted = 0; in pk_parse_key_pkcs8_encrypted_der() local
974 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, in pk_parse_key_pkcs8_encrypted_der()
977 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_encrypted_der()
982 if( ( ret = mbedtls_asn1_get_alg( &p, end, &pbe_alg_oid, &pbe_params ) ) != 0 ) in pk_parse_key_pkcs8_encrypted_der()
983 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_encrypted_der()
985 if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) in pk_parse_key_pkcs8_encrypted_der()
986 return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret ); in pk_parse_key_pkcs8_encrypted_der()
997 if( ( ret = mbedtls_pkcs12_pbe( &pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, in pk_parse_key_pkcs8_encrypted_der()
1001 if( ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH ) in pk_parse_key_pkcs8_encrypted_der()
1004 return( ret ); in pk_parse_key_pkcs8_encrypted_der()
1011 if( ( ret = mbedtls_pkcs12_pbe_sha1_rc4_128( &pbe_params, in pk_parse_key_pkcs8_encrypted_der()
1016 return( ret ); in pk_parse_key_pkcs8_encrypted_der()
1032 if( ( ret = mbedtls_pkcs5_pbes2( &pbe_params, MBEDTLS_PKCS5_DECRYPT, pwd, pwdlen, in pk_parse_key_pkcs8_encrypted_der()
1035 if( ret == MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH ) in pk_parse_key_pkcs8_encrypted_der()
1038 return( ret ); in pk_parse_key_pkcs8_encrypted_der()
1063 int ret; in mbedtls_pk_parse_key() local
1075 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1077 ret = mbedtls_pem_read_buffer( &pem, in mbedtls_pk_parse_key()
1082 if( ret == 0 ) in mbedtls_pk_parse_key()
1087 if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 || in mbedtls_pk_parse_key()
1088 ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), in mbedtls_pk_parse_key()
1095 return( ret ); in mbedtls_pk_parse_key()
1097 else if( ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ) in mbedtls_pk_parse_key()
1099 else if( ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ) in mbedtls_pk_parse_key()
1101 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) in mbedtls_pk_parse_key()
1102 return( ret ); in mbedtls_pk_parse_key()
1108 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1110 ret = mbedtls_pem_read_buffer( &pem, in mbedtls_pk_parse_key()
1114 if( ret == 0 ) in mbedtls_pk_parse_key()
1119 if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 || in mbedtls_pk_parse_key()
1120 ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), in mbedtls_pk_parse_key()
1127 return( ret ); in mbedtls_pk_parse_key()
1129 else if( ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ) in mbedtls_pk_parse_key()
1131 else if( ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ) in mbedtls_pk_parse_key()
1133 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) in mbedtls_pk_parse_key()
1134 return( ret ); in mbedtls_pk_parse_key()
1139 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1141 ret = mbedtls_pem_read_buffer( &pem, in mbedtls_pk_parse_key()
1145 if( ret == 0 ) in mbedtls_pk_parse_key()
1147 if( ( ret = pk_parse_key_pkcs8_unencrypted_der( pk, in mbedtls_pk_parse_key()
1154 return( ret ); in mbedtls_pk_parse_key()
1156 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) in mbedtls_pk_parse_key()
1157 return( ret ); in mbedtls_pk_parse_key()
1162 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_key()
1164 ret = mbedtls_pem_read_buffer( &pem, in mbedtls_pk_parse_key()
1168 if( ret == 0 ) in mbedtls_pk_parse_key()
1170 if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, in mbedtls_pk_parse_key()
1178 return( ret ); in mbedtls_pk_parse_key()
1180 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) in mbedtls_pk_parse_key()
1181 return( ret ); in mbedtls_pk_parse_key()
1184 ((void) ret); in mbedtls_pk_parse_key()
1197 if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, key, keylen, in mbedtls_pk_parse_key()
1205 if( ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH ) in mbedtls_pk_parse_key()
1207 return( ret ); in mbedtls_pk_parse_key()
1211 if( ( ret = pk_parse_key_pkcs8_unencrypted_der( pk, key, keylen ) ) == 0 ) in mbedtls_pk_parse_key()
1220 if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 || in mbedtls_pk_parse_key()
1221 ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), key, keylen ) ) == 0 ) in mbedtls_pk_parse_key()
1233 if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 || in mbedtls_pk_parse_key()
1234 ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), key, keylen ) ) == 0 ) in mbedtls_pk_parse_key()
1251 int ret; in mbedtls_pk_parse_public_key() local
1261 ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; in mbedtls_pk_parse_public_key()
1263 ret = mbedtls_pem_read_buffer( &pem, in mbedtls_pk_parse_public_key()
1268 if( ret == 0 ) in mbedtls_pk_parse_public_key()
1276 else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) in mbedtls_pk_parse_public_key()
1279 return( ret ); in mbedtls_pk_parse_public_key()
1284 ret = mbedtls_pk_parse_subpubkey( &p, p + keylen, ctx ); in mbedtls_pk_parse_public_key()
1290 return( ret ); in mbedtls_pk_parse_public_key()