#include "polarssl/config.h"
#include "polarssl/pem.h"
#include "polarssl/base64.h"
#include "polarssl/des.h"
#include "polarssl/aes.h"
#include "polarssl/md5.h"
#include "polarssl/cipher.h"
#include <stdlib.h>
Go to the source code of this file.
Defines | |
#define | polarssl_malloc malloc |
#define | polarssl_free free |
Functions | |
void | pem_init (pem_context *ctx) |
PEM context setup. | |
static int | pem_get_iv (const unsigned char *s, unsigned char *iv, size_t iv_len) |
static void | pem_pbkdf1 (unsigned char *key, size_t keylen, unsigned char *iv, const unsigned char *pwd, size_t pwdlen) |
static void | pem_des_decrypt (unsigned char des_iv[8], unsigned char *buf, size_t buflen, const unsigned char *pwd, size_t pwdlen) |
static void | pem_des3_decrypt (unsigned char des3_iv[8], unsigned char *buf, size_t buflen, const unsigned char *pwd, size_t pwdlen) |
static void | pem_aes_decrypt (unsigned char aes_iv[16], unsigned int keylen, unsigned char *buf, size_t buflen, const unsigned char *pwd, size_t pwdlen) |
int | pem_read_buffer (pem_context *ctx, const char *header, const char *footer, const unsigned char *data, const unsigned char *pwd, size_t pwdlen, size_t *use_len) |
Read a buffer for PEM information and store the resulting data into the specified context buffers. | |
void | pem_free (pem_context *ctx) |
PEM context memory freeing. | |
int | pem_write_buffer (const char *header, const char *footer, const unsigned char *der_data, size_t der_len, unsigned char *buf, size_t buf_len, size_t *olen) |
Write a buffer of PEM information from a DER encoded buffer. |
#define polarssl_free free |
#define polarssl_malloc malloc |
static void pem_aes_decrypt | ( | unsigned char | aes_iv[16], | |
unsigned int | keylen, | |||
unsigned char * | buf, | |||
size_t | buflen, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen | |||
) | [static] |
Definition at line 169 of file pem.c.
References aes_crypt_cbc(), AES_DECRYPT, aes_setkey_dec(), and pem_pbkdf1().
Referenced by pem_read_buffer().
static void pem_des3_decrypt | ( | unsigned char | des3_iv[8], | |
unsigned char * | buf, | |||
size_t | buflen, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen | |||
) | [static] |
Definition at line 147 of file pem.c.
References des3_crypt_cbc(), des3_set3key_dec(), DES_DECRYPT, and pem_pbkdf1().
Referenced by pem_read_buffer().
static void pem_des_decrypt | ( | unsigned char | des_iv[8], | |
unsigned char * | buf, | |||
size_t | buflen, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen | |||
) | [static] |
Definition at line 127 of file pem.c.
References des_crypt_cbc(), DES_DECRYPT, des_setkey_dec(), and pem_pbkdf1().
Referenced by pem_read_buffer().
void pem_free | ( | pem_context * | ctx | ) |
PEM context memory freeing.
ctx | context to be freed |
Definition at line 366 of file pem.c.
References pem_context::buf, pem_context::info, and polarssl_free.
Referenced by dhm_parse_dhm(), pk_parse_key(), pk_parse_public_key(), x509_crl_parse(), x509_crt_parse(), and x509_csr_parse().
static int pem_get_iv | ( | const unsigned char * | s, | |
unsigned char * | iv, | |||
size_t | iv_len | |||
) | [static] |
Definition at line 56 of file pem.c.
References POLARSSL_ERR_PEM_INVALID_ENC_IV.
Referenced by pem_read_buffer().
void pem_init | ( | pem_context * | ctx | ) |
PEM context setup.
ctx | context to be initialized |
Definition at line 46 of file pem.c.
Referenced by dhm_parse_dhm(), pk_parse_key(), pk_parse_public_key(), x509_crl_parse(), x509_crt_parse(), and x509_csr_parse().
static void pem_pbkdf1 | ( | unsigned char * | key, | |
size_t | keylen, | |||
unsigned char * | iv, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen | |||
) | [static] |
Definition at line 77 of file pem.c.
References md5_finish(), md5_starts(), and md5_update().
Referenced by pem_aes_decrypt(), pem_des3_decrypt(), and pem_des_decrypt().
int pem_read_buffer | ( | pem_context * | ctx, | |
const char * | header, | |||
const char * | footer, | |||
const unsigned char * | data, | |||
const unsigned char * | pwd, | |||
size_t | pwdlen, | |||
size_t * | use_len | |||
) |
Read a buffer for PEM information and store the resulting data into the specified context buffers.
ctx | context to use | |
header | header string to seek and expect | |
footer | footer string to seek and expect | |
data | source data to look in | |
pwd | password for decryption (can be NULL) | |
pwdlen | length of password | |
use_len | destination for total length used (set after header is correctly read, so unless you get POLARSSL_ERR_PEM_BAD_INPUT_DATA or POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is the length to skip) |
Definition at line 190 of file pem.c.
References base64_decode(), pem_context::buf, pem_context::buflen, pem_aes_decrypt(), pem_des3_decrypt(), pem_des_decrypt(), pem_get_iv(), POLARSSL_CIPHER_AES_128_CBC, POLARSSL_CIPHER_AES_192_CBC, POLARSSL_CIPHER_AES_256_CBC, POLARSSL_CIPHER_DES_CBC, POLARSSL_CIPHER_DES_EDE3_CBC, POLARSSL_CIPHER_NONE, POLARSSL_ERR_BASE64_INVALID_CHARACTER, POLARSSL_ERR_PEM_BAD_INPUT_DATA, POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE, POLARSSL_ERR_PEM_INVALID_DATA, POLARSSL_ERR_PEM_INVALID_ENC_IV, POLARSSL_ERR_PEM_MALLOC_FAILED, POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT, POLARSSL_ERR_PEM_PASSWORD_MISMATCH, POLARSSL_ERR_PEM_PASSWORD_REQUIRED, POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG, polarssl_free, and polarssl_malloc.
Referenced by dhm_parse_dhm(), pk_parse_key(), pk_parse_public_key(), x509_crl_parse(), x509_crt_parse(), and x509_csr_parse().
int pem_write_buffer | ( | const char * | header, | |
const char * | footer, | |||
const unsigned char * | der_data, | |||
size_t | der_len, | |||
unsigned char * | buf, | |||
size_t | buf_len, | |||
size_t * | olen | |||
) |
Write a buffer of PEM information from a DER encoded buffer.
header | header string to write | |
footer | footer string to write | |
der_data | DER data to write | |
der_len | length of the DER data | |
buf | buffer to write to | |
buf_len | length of output buffer | |
olen | total length written / required (if buf_len is not enough) |
Definition at line 379 of file pem.c.
References add_len, base64_encode(), POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, POLARSSL_ERR_PEM_MALLOC_FAILED, polarssl_free, and polarssl_malloc.
Referenced by pk_write_key_pem(), pk_write_pubkey_pem(), x509write_crt_pem(), and x509write_csr_pem().