pkwrite.c File Reference

#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>
Include dependency graph for pkwrite.c:

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 Documentation

#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

Definition at line 52 of file pkwrite.c.

#define polarssl_malloc   malloc

Definition at line 51 of file pkwrite.c.


Function Documentation

static int pk_write_ec_param ( unsigned char **  p,
unsigned char *  start,
ecp_keypair ec 
) [static]
static int pk_write_ec_pubkey ( unsigned char **  p,
unsigned char *  start,
ecp_keypair ec 
) [static]
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.

Parameters:
key private to write away
buf buffer to write to
size size of the buffer
Returns:
length of data written if successful, or a specific error code

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.

Parameters:
key private to write away
buf buffer to write to
size size of the buffer
Returns:
0 successful, or a specific error code

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.

Parameters:
p reference to current position pointer
start start of the buffer (for bounds-checking)
key public key to write away
Returns:
the length written or a negative error code

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.

Parameters:
key public key to write away
buf buffer to write to
size size of the buffer
Returns:
length of data written if successful, or a specific error code

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.

Parameters:
key public key to write away
buf buffer to write to
size size of the buffer
Returns:
0 successful, or a specific error code

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]

Generated on 9 Apr 2014 for PolarSSL v1.3.2 by  doxygen 1.6.1