#include "polarssl/config.h"
#include "polarssl/pk.h"
#include "polarssl/asn1.h"
#include "polarssl/oid.h"
#include "polarssl/rsa.h"
#include "polarssl/ecp.h"
#include "polarssl/ecdsa.h"
#include "polarssl/pem.h"
#include "polarssl/pkcs5.h"
#include "polarssl/pkcs12.h"
#include <stdlib.h>
Go to the source code of this file.
Defines | |
#define | polarssl_malloc malloc |
#define | polarssl_free free |
Functions | |
static int | load_file (const char *path, unsigned char **buf, size_t *n) |
int | pk_parse_keyfile (pk_context *ctx, const char *path, const char *pwd) |
Load and parse a private key. | |
int | pk_parse_public_keyfile (pk_context *ctx, const char *path) |
Load and parse a public key. | |
static int | pk_get_ecparams (unsigned char **p, const unsigned char *end, asn1_buf *params) |
static int | pk_use_ecparams (const asn1_buf *params, ecp_group *grp) |
static int | pk_get_ecpubkey (unsigned char **p, const unsigned char *end, ecp_keypair *key) |
static int | pk_get_rsapubkey (unsigned char **p, const unsigned char *end, rsa_context *rsa) |
static int | pk_get_pk_alg (unsigned char **p, const unsigned char *end, pk_type_t *pk_alg, asn1_buf *params) |
int | pk_parse_subpubkey (unsigned char **p, const unsigned char *end, pk_context *pk) |
Parse a SubjectPublicKeyInfo DER structure. | |
static int | pk_parse_key_pkcs1_der (rsa_context *rsa, const unsigned char *key, size_t keylen) |
static int | pk_parse_key_sec1_der (ecp_keypair *eck, const unsigned char *key, size_t keylen) |
static int | pk_parse_key_pkcs8_unencrypted_der (pk_context *pk, const unsigned char *key, size_t keylen) |
static int | pk_parse_key_pkcs8_encrypted_der (pk_context *pk, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen) |
int | pk_parse_key (pk_context *pk, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen) |
Parse a private key. | |
int | pk_parse_public_key (pk_context *ctx, const unsigned char *key, size_t keylen) |
Parse a public key. |
#define polarssl_free free |
#define polarssl_malloc malloc |
static int load_file | ( | const char * | path, | |
unsigned char ** | buf, | |||
size_t * | n | |||
) | [static] |
Definition at line 65 of file pkparse.c.
References POLARSSL_ERR_PK_FILE_IO_ERROR, POLARSSL_ERR_PK_MALLOC_FAILED, polarssl_free, and polarssl_malloc.
Referenced by pk_parse_keyfile(), and pk_parse_public_keyfile().
static int pk_get_ecparams | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
asn1_buf * | params | |||
) | [static] |
Definition at line 159 of file pkparse.c.
References asn1_get_tag(), ASN1_OID, _asn1_buf::len, _asn1_buf::p, POLARSSL_ERR_ASN1_LENGTH_MISMATCH, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, and _asn1_buf::tag.
Referenced by pk_parse_key_sec1_der().
static int pk_get_ecpubkey | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
ecp_keypair * | key | |||
) | [static] |
Definition at line 205 of file pkparse.c.
References ecp_check_pubkey(), ecp_keypair_free(), ecp_point_read_binary(), ecp_keypair::grp, POLARSSL_ERR_PK_INVALID_PUBKEY, and ecp_keypair::Q.
Referenced by pk_parse_key_sec1_der(), and pk_parse_subpubkey().
static int pk_get_pk_alg | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
pk_type_t * | pk_alg, | |||
asn1_buf * | params | |||
) | [static] |
Definition at line 272 of file pkparse.c.
References asn1_get_alg(), ASN1_NULL, _asn1_buf::len, oid_get_pk_alg(), POLARSSL_ERR_PK_INVALID_ALG, POLARSSL_ERR_PK_UNKNOWN_PK_ALG, POLARSSL_PK_RSA, and _asn1_buf::tag.
Referenced by pk_parse_key_pkcs8_unencrypted_der(), and pk_parse_subpubkey().
static int pk_get_rsapubkey | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
rsa_context * | rsa | |||
) | [static] |
Definition at line 234 of file pkparse.c.
References ASN1_CONSTRUCTED, asn1_get_mpi(), asn1_get_tag(), ASN1_SEQUENCE, rsa_context::E, rsa_context::len, mpi_size(), rsa_context::N, POLARSSL_ERR_ASN1_LENGTH_MISMATCH, POLARSSL_ERR_PK_INVALID_PUBKEY, and rsa_check_pubkey().
Referenced by pk_parse_subpubkey().
int pk_parse_key | ( | pk_context * | ctx, | |
const unsigned char * | key, | |||
size_t | keylen, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen | |||
) |
Parse a private key.
ctx | key to be initialized | |
key | input buffer | |
keylen | size of the buffer | |
pwd | password for decryption (optional) | |
pwdlen | size of the password |
Definition at line 759 of file pkparse.c.
References pem_context::buf, pem_context::buflen, pem_free(), pem_init(), pem_read_buffer(), pk_ec, pk_free(), pk_info_from_type(), pk_init_ctx(), pk_parse_key_pkcs1_der(), pk_parse_key_pkcs8_encrypted_der(), pk_parse_key_pkcs8_unencrypted_der(), pk_parse_key_sec1_der(), pk_rsa, POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT, POLARSSL_ERR_PEM_PASSWORD_MISMATCH, POLARSSL_ERR_PEM_PASSWORD_REQUIRED, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, POLARSSL_ERR_PK_PASSWORD_MISMATCH, POLARSSL_ERR_PK_PASSWORD_REQUIRED, POLARSSL_ERR_PK_UNKNOWN_PK_ALG, POLARSSL_PK_ECKEY, and POLARSSL_PK_RSA.
Referenced by pk_parse_keyfile(), and test_suite_pk_parse_key_rsa().
static int pk_parse_key_pkcs1_der | ( | rsa_context * | rsa, | |
const unsigned char * | key, | |||
size_t | keylen | |||
) | [static] |
Definition at line 368 of file pkparse.c.
References ASN1_CONSTRUCTED, asn1_get_int(), asn1_get_mpi(), asn1_get_tag(), ASN1_SEQUENCE, rsa_context::D, rsa_context::DP, rsa_context::DQ, rsa_context::E, rsa_context::len, mpi_size(), rsa_context::N, rsa_context::P, POLARSSL_ERR_ASN1_LENGTH_MISMATCH, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, POLARSSL_ERR_PK_KEY_INVALID_VERSION, rsa_context::Q, rsa_context::QP, rsa_check_privkey(), rsa_free(), and rsa_context::ver.
Referenced by pk_parse_key(), and pk_parse_key_pkcs8_unencrypted_der().
static int pk_parse_key_pkcs8_encrypted_der | ( | pk_context * | pk, | |
const unsigned char * | key, | |||
size_t | keylen, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen | |||
) | [static] |
Definition at line 646 of file pkparse.c.
References ASN1_CONSTRUCTED, asn1_get_alg(), asn1_get_tag(), ASN1_OCTET_STRING, ASN1_SEQUENCE, OID_CMP, oid_get_pkcs12_pbe_alg(), OID_PKCS12_PBE_SHA1_RC4_128, OID_PKCS5_PBES2, pk_parse_key_pkcs8_unencrypted_der(), pkcs12_pbe(), PKCS12_PBE_DECRYPT, pkcs12_pbe_sha1_rc4_128(), PKCS5_DECRYPT, pkcs5_pbes2(), POLARSSL_ERR_PK_BAD_INPUT_DATA, POLARSSL_ERR_PK_FEATURE_UNAVAILABLE, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, POLARSSL_ERR_PK_PASSWORD_MISMATCH, POLARSSL_ERR_PK_PASSWORD_REQUIRED, POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH, and POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH.
Referenced by pk_parse_key().
static int pk_parse_key_pkcs8_unencrypted_der | ( | pk_context * | pk, | |
const unsigned char * | key, | |||
size_t | keylen | |||
) | [static] |
Definition at line 558 of file pkparse.c.
References ASN1_CONSTRUCTED, asn1_get_int(), asn1_get_tag(), ASN1_OCTET_STRING, ASN1_SEQUENCE, pk_ec, pk_free(), pk_get_pk_alg(), pk_info_from_type(), pk_init_ctx(), pk_parse_key_pkcs1_der(), pk_parse_key_sec1_der(), pk_rsa, pk_use_ecparams(), POLARSSL_ERR_ASN1_OUT_OF_DATA, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, POLARSSL_ERR_PK_KEY_INVALID_VERSION, POLARSSL_ERR_PK_UNKNOWN_PK_ALG, POLARSSL_PK_ECKEY, POLARSSL_PK_ECKEY_DH, POLARSSL_PK_NONE, POLARSSL_PK_RSA, and version.
Referenced by pk_parse_key(), and pk_parse_key_pkcs8_encrypted_der().
static int pk_parse_key_sec1_der | ( | ecp_keypair * | eck, | |
const unsigned char * | key, | |||
size_t | keylen | |||
) | [static] |
Definition at line 449 of file pkparse.c.
References ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, asn1_get_bitstring_null(), asn1_get_int(), asn1_get_tag(), ASN1_OCTET_STRING, ASN1_SEQUENCE, ecp_keypair::d, ecp_check_privkey(), ecp_keypair_free(), ecp_mul(), ecp_group::G, ecp_keypair::grp, mpi_read_binary(), pk_get_ecparams(), pk_get_ecpubkey(), pk_use_ecparams(), POLARSSL_ERR_ASN1_LENGTH_MISMATCH, POLARSSL_ERR_ASN1_UNEXPECTED_TAG, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, POLARSSL_ERR_PK_KEY_INVALID_VERSION, ecp_keypair::Q, and version.
Referenced by pk_parse_key(), and pk_parse_key_pkcs8_unencrypted_der().
int pk_parse_keyfile | ( | pk_context * | ctx, | |
const char * | path, | |||
const char * | password | |||
) |
Load and parse a private key.
ctx | key to be initialized | |
path | filename to read the private key from | |
password | password to decrypt the file (can be NULL) |
Definition at line 107 of file pkparse.c.
References load_file(), pk_parse_key(), and polarssl_free.
Referenced by test_suite_pk_parse_keyfile_ec(), test_suite_pk_parse_keyfile_rsa(), test_suite_pk_write_key_check(), test_suite_x509_crt_check(), and test_suite_x509_csr_check().
int pk_parse_public_key | ( | pk_context * | ctx, | |
const unsigned char * | key, | |||
size_t | keylen | |||
) |
Parse a public key.
ctx | key to be initialized | |
key | input buffer | |
keylen | size of the buffer |
Definition at line 926 of file pkparse.c.
References pem_context::buf, pem_context::buflen, pem_free(), pem_init(), pem_read_buffer(), pk_parse_subpubkey(), and POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT.
Referenced by pk_parse_public_keyfile().
int pk_parse_public_keyfile | ( | pk_context * | ctx, | |
const char * | path | |||
) |
Load and parse a public key.
ctx | key to be initialized | |
path | filename to read the private key from |
Definition at line 132 of file pkparse.c.
References load_file(), pk_parse_public_key(), and polarssl_free.
Referenced by test_suite_pk_parse_public_keyfile_ec(), test_suite_pk_parse_public_keyfile_rsa(), and test_suite_pk_write_pubkey_check().
int pk_parse_subpubkey | ( | unsigned char ** | p, | |
const unsigned char * | end, | |||
pk_context * | pk | |||
) |
Parse a SubjectPublicKeyInfo DER structure.
p | the position in the ASN.1 data | |
end | end of the buffer | |
pk | the key to fill |
Definition at line 305 of file pkparse.c.
References ASN1_CONSTRUCTED, asn1_get_bitstring_null(), asn1_get_tag(), ASN1_SEQUENCE, pk_ec, pk_free(), pk_get_ecpubkey(), pk_get_pk_alg(), pk_get_rsapubkey(), pk_info_from_type(), pk_init_ctx(), pk_rsa, pk_use_ecparams(), POLARSSL_ERR_ASN1_LENGTH_MISMATCH, POLARSSL_ERR_PK_INVALID_PUBKEY, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, POLARSSL_ERR_PK_UNKNOWN_PK_ALG, POLARSSL_PK_ECKEY, POLARSSL_PK_ECKEY_DH, POLARSSL_PK_NONE, and POLARSSL_PK_RSA.
Referenced by pk_parse_public_key(), x509_crt_parse_der_core(), and x509_csr_parse().
Definition at line 182 of file pkparse.c.
References ecp_use_known_dp(), ecp_group::id, oid_get_ec_grp(), POLARSSL_ECP_DP_NONE, POLARSSL_ERR_PK_KEY_INVALID_FORMAT, and POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE.
Referenced by pk_parse_key_pkcs8_unencrypted_der(), pk_parse_key_sec1_der(), and pk_parse_subpubkey().