RetroArch
Macros | Functions
pkwrite.c File Reference
#include "mbedtls/config.h"
#include "mbedtls/pk.h"
#include "mbedtls/asn1write.h"
#include "mbedtls/oid.h"
#include <string.h>
#include "mbedtls/rsa.h"
#include "mbedtls/ecp.h"
#include "mbedtls/ecdsa.h"
#include "mbedtls/pem.h"
#include "mbedtls/platform.h"
Include dependency graph for pkwrite.c:

Macros

#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"
 
#define RSA_PUB_DER_MAX_BYTES   38 + 2 * MBEDTLS_MPI_MAX_SIZE
 
#define MPI_MAX_SIZE_2
 
#define RSA_PRV_DER_MAX_BYTES
 
#define ECP_PUB_DER_MAX_BYTES   30 + 2 * MBEDTLS_ECP_MAX_BYTES
 
#define ECP_PRV_DER_MAX_BYTES   29 + 3 * MBEDTLS_ECP_MAX_BYTES
 
#define PUB_DER_MAX_BYTES
 
#define PRV_DER_MAX_BYTES
 

Functions

static int pk_write_rsa_pubkey (unsigned char **p, unsigned char *start, mbedtls_rsa_context *rsa)
 
static int pk_write_ec_pubkey (unsigned char **p, unsigned char *start, mbedtls_ecp_keypair *ec)
 
static int pk_write_ec_param (unsigned char **p, unsigned char *start, mbedtls_ecp_keypair *ec)
 
int mbedtls_pk_write_pubkey (unsigned char **p, unsigned char *start, const mbedtls_pk_context *key)
 Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer. More...
 
int mbedtls_pk_write_pubkey_der (mbedtls_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. More...
 
int mbedtls_pk_write_key_der (mbedtls_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. More...
 
int mbedtls_pk_write_pubkey_pem (mbedtls_pk_context *key, unsigned char *buf, size_t size)
 Write a public key to a PEM string. More...
 
int mbedtls_pk_write_key_pem (mbedtls_pk_context *key, unsigned char *buf, size_t size)
 Write a private key to a PKCS#1 or SEC1 PEM string. More...
 

Macro Definition Documentation

◆ ECP_PRV_DER_MAX_BYTES

#define ECP_PRV_DER_MAX_BYTES   29 + 3 * MBEDTLS_ECP_MAX_BYTES

◆ ECP_PUB_DER_MAX_BYTES

#define ECP_PUB_DER_MAX_BYTES   30 + 2 * MBEDTLS_ECP_MAX_BYTES

◆ MPI_MAX_SIZE_2

#define MPI_MAX_SIZE_2
Value:
MBEDTLS_MPI_MAX_SIZE % 2
#define MBEDTLS_MPI_MAX_SIZE
Definition: bignum.h:76

◆ PEM_BEGIN_PRIVATE_KEY_EC

#define PEM_BEGIN_PRIVATE_KEY_EC   "-----BEGIN EC PRIVATE KEY-----\n"

◆ PEM_BEGIN_PRIVATE_KEY_RSA

#define PEM_BEGIN_PRIVATE_KEY_RSA   "-----BEGIN RSA PRIVATE KEY-----\n"

◆ PEM_BEGIN_PUBLIC_KEY

#define PEM_BEGIN_PUBLIC_KEY   "-----BEGIN PUBLIC KEY-----\n"

◆ PEM_END_PRIVATE_KEY_EC

#define PEM_END_PRIVATE_KEY_EC   "-----END EC PRIVATE KEY-----\n"

◆ PEM_END_PRIVATE_KEY_RSA

#define PEM_END_PRIVATE_KEY_RSA   "-----END RSA PRIVATE KEY-----\n"

◆ PEM_END_PUBLIC_KEY

#define PEM_END_PUBLIC_KEY   "-----END PUBLIC KEY-----\n"

◆ PRV_DER_MAX_BYTES

#define PRV_DER_MAX_BYTES
Value:
RSA_PRV_DER_MAX_BYTES : ECP_PRV_DER_MAX_BYTES
#define ECP_PRV_DER_MAX_BYTES
Definition: pkwrite.c:364
#define RSA_PRV_DER_MAX_BYTES
Definition: pkwrite.c:331

◆ PUB_DER_MAX_BYTES

#define PUB_DER_MAX_BYTES
Value:
RSA_PUB_DER_MAX_BYTES : ECP_PUB_DER_MAX_BYTES
#define ECP_PUB_DER_MAX_BYTES
Definition: pkwrite.c:353
#define RSA_PUB_DER_MAX_BYTES
Definition: pkwrite.c:312

◆ RSA_PRV_DER_MAX_BYTES

#define RSA_PRV_DER_MAX_BYTES
Value:
#define MBEDTLS_MPI_MAX_SIZE
Definition: bignum.h:76
#define MPI_MAX_SIZE_2
Definition: pkwrite.c:329

◆ RSA_PUB_DER_MAX_BYTES

#define RSA_PUB_DER_MAX_BYTES   38 + 2 * MBEDTLS_MPI_MAX_SIZE

Function Documentation

◆ mbedtls_pk_write_key_der()

int mbedtls_pk_write_key_der ( mbedtls_pk_context ctx,
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
ctxprivate to write away
bufbuffer to write to
sizesize of the buffer
Returns
length of data written if successful, or a specific error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_pk_write_key_pem()

int mbedtls_pk_write_key_pem ( mbedtls_pk_context ctx,
unsigned char *  buf,
size_t  size 
)

Write a private key to a PKCS#1 or SEC1 PEM string.

Parameters
ctxprivate to write away
bufbuffer to write to
sizesize of the buffer
Returns
0 if successful, or a specific error code
Here is the call graph for this function:

◆ mbedtls_pk_write_pubkey()

int mbedtls_pk_write_pubkey ( unsigned char **  p,
unsigned char *  start,
const mbedtls_pk_context key 
)

Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer.

Parameters
preference to current position pointer
startstart of the buffer (for bounds-checking)
keypublic key to write away
Returns
the length written or a negative error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_pk_write_pubkey_der()

int mbedtls_pk_write_pubkey_der ( mbedtls_pk_context ctx,
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
ctxpublic key to write away
bufbuffer to write to
sizesize of the buffer
Returns
length of data written if successful, or a specific error code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbedtls_pk_write_pubkey_pem()

int mbedtls_pk_write_pubkey_pem ( mbedtls_pk_context ctx,
unsigned char *  buf,
size_t  size 
)

Write a public key to a PEM string.

Parameters
ctxpublic key to write away
bufbuffer to write to
sizesize of the buffer
Returns
0 if successful, or a specific error code
Here is the call graph for this function:

◆ pk_write_ec_param()

static int pk_write_ec_param ( unsigned char **  p,
unsigned char *  start,
mbedtls_ecp_keypair ec 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pk_write_ec_pubkey()

static int pk_write_ec_pubkey ( unsigned char **  p,
unsigned char *  start,
mbedtls_ecp_keypair ec 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pk_write_rsa_pubkey()

static int pk_write_rsa_pubkey ( unsigned char **  p,
unsigned char *  start,
mbedtls_rsa_context rsa 
)
static
Here is the call graph for this function:
Here is the caller graph for this function: