#include "polarssl/config.h"
#include "polarssl/pk.h"
#include "polarssl/asn1write.h"
#include "polarssl/oid.h"
#include "polarssl/rsa.h"
#include "polarssl/ecp.h"
#include "polarssl/ecdsa.h"
#include "polarssl/pem.h"
#include <stdlib.h>
Go to the source code of this file.
Defines | |
#define | polarssl_malloc malloc |
#define | polarssl_free free |
#define | PEM_BEGIN_PUBLIC_KEY "-----BEGIN PUBLIC KEY-----\n" |
#define | PEM_END_PUBLIC_KEY "-----END PUBLIC KEY-----\n" |
#define | PEM_BEGIN_PRIVATE_KEY_RSA "-----BEGIN RSA PRIVATE KEY-----\n" |
#define | PEM_END_PRIVATE_KEY_RSA "-----END RSA PRIVATE KEY-----\n" |
#define | PEM_BEGIN_PRIVATE_KEY_EC "-----BEGIN EC PRIVATE KEY-----\n" |
#define | PEM_END_PRIVATE_KEY_EC "-----END EC PRIVATE KEY-----\n" |
Functions | |
static int | pk_write_rsa_pubkey (unsigned char **p, unsigned char *start, rsa_context *rsa) |
static int | pk_write_ec_pubkey (unsigned char **p, unsigned char *start, ecp_keypair *ec) |
static int | pk_write_ec_param (unsigned char **p, unsigned char *start, ecp_keypair *ec) |
int | pk_write_pubkey (unsigned char **p, unsigned char *start, const pk_context *key) |
Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer. | |
int | pk_write_pubkey_der (pk_context *key, unsigned char *buf, size_t size) |
Write a public key to a SubjectPublicKeyInfo DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer. | |
int | pk_write_key_der (pk_context *key, unsigned char *buf, size_t size) |
Write a private key to a PKCS#1 or SEC1 DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer. | |
int | pk_write_pubkey_pem (pk_context *key, unsigned char *buf, size_t size) |
Write a public key to a PEM string. | |
int | pk_write_key_pem (pk_context *key, unsigned char *buf, size_t size) |
Write a private key to a PKCS#1 or SEC1 PEM string. |
#define PEM_BEGIN_PRIVATE_KEY_EC "-----BEGIN EC PRIVATE KEY-----\n" |
Definition at line 286 of file pkwrite.c.
Referenced by pk_write_key_pem().
#define PEM_BEGIN_PRIVATE_KEY_RSA "-----BEGIN RSA PRIVATE KEY-----\n" |
Definition at line 284 of file pkwrite.c.
Referenced by pk_write_key_pem().
#define PEM_BEGIN_PUBLIC_KEY "-----BEGIN PUBLIC KEY-----\n" |
Definition at line 281 of file pkwrite.c.
Referenced by pk_write_pubkey_pem().
#define PEM_END_PRIVATE_KEY_EC "-----END EC PRIVATE KEY-----\n" |
Definition at line 287 of file pkwrite.c.
Referenced by pk_write_key_pem().
#define PEM_END_PRIVATE_KEY_RSA "-----END RSA PRIVATE KEY-----\n" |
Definition at line 285 of file pkwrite.c.
Referenced by pk_write_key_pem().
#define PEM_END_PUBLIC_KEY "-----END PUBLIC KEY-----\n" |
Definition at line 282 of file pkwrite.c.
Referenced by pk_write_pubkey_pem().
#define polarssl_free free |
#define polarssl_malloc malloc |
static int pk_write_ec_param | ( | unsigned char ** | p, | |
unsigned char * | start, | |||
ecp_keypair * | ec | |||
) | [static] |
Definition at line 110 of file pkwrite.c.
References ASN1_CHK_ADD, asn1_write_oid(), ecp_keypair::grp, ecp_group::id, and oid_get_oid_by_ec_grp().
Referenced by pk_write_key_der(), and pk_write_pubkey_der().
static int pk_write_ec_pubkey | ( | unsigned char ** | p, | |
unsigned char * | start, | |||
ecp_keypair * | ec | |||
) | [static] |
Definition at line 82 of file pkwrite.c.
References ecp_point_write_binary(), ecp_keypair::grp, POLARSSL_ECP_MAX_PT_LEN, POLARSSL_ECP_PF_UNCOMPRESSED, POLARSSL_ERR_ASN1_BUF_TOO_SMALL, and ecp_keypair::Q.
Referenced by pk_write_key_der(), and pk_write_pubkey().
int pk_write_key_der | ( | pk_context * | pk, | |
unsigned char * | buf, | |||
size_t | size | |||
) |
Write a private key to a PKCS#1 or SEC1 DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer.
key | private to write away | |
buf | buffer to write to | |
size | size of the buffer |
Definition at line 195 of file pkwrite.c.
References ASN1_BIT_STRING, ASN1_CHK_ADD, ASN1_CONSTRUCTED, ASN1_CONTEXT_SPECIFIC, ASN1_OCTET_STRING, ASN1_SEQUENCE, asn1_write_int(), asn1_write_len(), asn1_write_mpi(), asn1_write_tag(), ecp_keypair::d, rsa_context::D, rsa_context::DP, rsa_context::DQ, rsa_context::E, rsa_context::N, rsa_context::P, pk_ec, pk_get_type(), pk_rsa, pk_write_ec_param(), pk_write_ec_pubkey(), POLARSSL_ERR_ASN1_BUF_TOO_SMALL, POLARSSL_ERR_PK_FEATURE_UNAVAILABLE, POLARSSL_PK_ECKEY, POLARSSL_PK_RSA, rsa_context::Q, and rsa_context::QP.
Referenced by pk_write_key_pem().
int pk_write_key_pem | ( | pk_context * | key, | |
unsigned char * | buf, | |||
size_t | size | |||
) |
Write a private key to a PKCS#1 or SEC1 PEM string.
key | private to write away | |
buf | buffer to write to | |
size | size of the buffer |
Definition at line 311 of file pkwrite.c.
References PEM_BEGIN_PRIVATE_KEY_EC, PEM_BEGIN_PRIVATE_KEY_RSA, PEM_END_PRIVATE_KEY_EC, PEM_END_PRIVATE_KEY_RSA, pem_write_buffer(), pk_get_type(), pk_write_key_der(), POLARSSL_ERR_PK_FEATURE_UNAVAILABLE, POLARSSL_PK_ECKEY, and POLARSSL_PK_RSA.
Referenced by test_suite_pk_write_key_check().
int pk_write_pubkey | ( | unsigned char ** | p, | |
unsigned char * | start, | |||
const pk_context * | key | |||
) |
Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer.
p | reference to current position pointer | |
start | start of the buffer (for bounds-checking) | |
key | public key to write away |
Definition at line 127 of file pkwrite.c.
References ASN1_CHK_ADD, pk_ec, pk_get_type(), pk_rsa, pk_write_ec_pubkey(), pk_write_rsa_pubkey(), POLARSSL_ERR_PK_FEATURE_UNAVAILABLE, POLARSSL_PK_ECKEY, and POLARSSL_PK_RSA.
Referenced by pk_write_pubkey_der(), x509write_crt_set_authority_key_identifier(), and x509write_crt_set_subject_key_identifier().
int pk_write_pubkey_der | ( | pk_context * | key, | |
unsigned char * | buf, | |||
size_t | size | |||
) |
Write a public key to a SubjectPublicKeyInfo DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer.
key | public key to write away | |
buf | buffer to write to | |
size | size of the buffer |
Definition at line 148 of file pkwrite.c.
References ASN1_BIT_STRING, ASN1_CHK_ADD, ASN1_CONSTRUCTED, ASN1_SEQUENCE, asn1_write_algorithm_identifier(), asn1_write_len(), asn1_write_tag(), oid_get_oid_by_pk_alg(), pk_ec, pk_get_type(), pk_write_ec_param(), pk_write_pubkey(), POLARSSL_ERR_ASN1_BUF_TOO_SMALL, and POLARSSL_PK_ECKEY.
Referenced by pk_write_pubkey_pem(), x509write_crt_der(), and x509write_csr_der().
int pk_write_pubkey_pem | ( | pk_context * | key, | |
unsigned char * | buf, | |||
size_t | size | |||
) |
Write a public key to a PEM string.
key | public key to write away | |
buf | buffer to write to | |
size | size of the buffer |
Definition at line 289 of file pkwrite.c.
References PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY, pem_write_buffer(), and pk_write_pubkey_der().
Referenced by test_suite_pk_write_pubkey_check().
static int pk_write_rsa_pubkey | ( | unsigned char ** | p, | |
unsigned char * | start, | |||
rsa_context * | rsa | |||
) | [static] |
Definition at line 62 of file pkwrite.c.
References ASN1_CHK_ADD, ASN1_CONSTRUCTED, ASN1_SEQUENCE, asn1_write_len(), asn1_write_mpi(), asn1_write_tag(), rsa_context::E, and rsa_context::N.
Referenced by pk_write_pubkey().