#include "polarssl/config.h"
#include "polarssl/pk.h"
#include "polarssl/pk_wrap.h"
#include "polarssl/rsa.h"
#include "polarssl/ecp.h"
#include "polarssl/ecdsa.h"
Go to the source code of this file.
Functions | |
void | pk_init (pk_context *ctx) |
Initialize a pk_context (as NONE). | |
void | pk_free (pk_context *ctx) |
Free a pk_context. | |
const pk_info_t * | pk_info_from_type (pk_type_t pk_type) |
Return information associated with the given PK type. | |
int | pk_init_ctx (pk_context *ctx, const pk_info_t *info) |
Initialize a PK context with the information given and allocates the type-specific PK subcontext. | |
int | pk_init_ctx_rsa_alt (pk_context *ctx, void *key, pk_rsa_alt_decrypt_func decrypt_func, pk_rsa_alt_sign_func sign_func, pk_rsa_alt_key_len_func key_len_func) |
Initialize an RSA-alt context. | |
int | pk_can_do (pk_context *ctx, pk_type_t type) |
Tell if a context can do the operation given by type. | |
static int | pk_hashlen_helper (md_type_t md_alg, size_t *hash_len) |
int | pk_verify (pk_context *ctx, md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len) |
Verify signature. | |
int | pk_sign (pk_context *ctx, md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
Make signature. | |
int | pk_decrypt (pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
Decrypt message. | |
int | pk_encrypt (pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
Encrypt message. | |
size_t | pk_get_size (const pk_context *ctx) |
Get the size in bits of the underlying key. | |
int | pk_debug (const pk_context *ctx, pk_debug_item *items) |
Export debug information. | |
const char * | pk_get_name (const pk_context *ctx) |
Access the type name. | |
pk_type_t | pk_get_type (const pk_context *ctx) |
Get the key type. |
int pk_can_do | ( | pk_context * | ctx, | |
pk_type_t | type | |||
) |
Tell if a context can do the operation given by type.
ctx | Context to test | |
type | Target type |
Definition at line 143 of file pk.c.
References pk_info_t::can_do, and pk_context::pk_info.
Referenced by ssl_parse_certificate_request(), ssl_parse_certificate_verify(), ssl_parse_encrypted_pms(), ssl_parse_server_key_exchange(), ssl_pick_cert(), ssl_sig_from_pk(), ssl_write_certificate_verify(), ssl_write_encrypted_pms(), test_suite_pk_ec_test_vec(), test_suite_pk_parse_keyfile_ec(), test_suite_pk_parse_keyfile_rsa(), test_suite_pk_parse_public_keyfile_ec(), test_suite_pk_parse_public_keyfile_rsa(), test_suite_pk_utils(), x509_crt_verify_child(), x509_crt_verify_top(), and x509_crt_verifycrl().
int pk_debug | ( | const pk_context * | ctx, | |
pk_debug_item * | items | |||
) |
Export debug information.
ctx | Context to use | |
items | Place to write debug items |
Definition at line 256 of file pk.c.
References pk_info_t::debug_func, pk_context::pk_ctx, pk_context::pk_info, and POLARSSL_ERR_PK_BAD_INPUT_DATA.
Referenced by debug_print_pk().
int pk_decrypt | ( | pk_context * | ctx, | |
const unsigned char * | input, | |||
size_t | ilen, | |||
unsigned char * | output, | |||
size_t * | olen, | |||
size_t | osize, | |||
int(*)(void *, unsigned char *, size_t) | f_rng, | |||
void * | p_rng | |||
) |
Decrypt message.
ctx | PK context to use | |
input | Input to decrypt | |
ilen | Input size | |
output | Decrypted output | |
olen | Decrypted message length | |
osize | Size of the output buffer | |
f_rng | RNG function | |
p_rng | RNG parameter |
Definition at line 209 of file pk.c.
References pk_info_t::decrypt_func, pk_context::pk_ctx, pk_context::pk_info, POLARSSL_ERR_PK_BAD_INPUT_DATA, and POLARSSL_ERR_PK_TYPE_MISMATCH.
Referenced by ssl_parse_encrypted_pms(), test_suite_pk_ec_nocrypt(), and test_suite_pk_rsa_decrypt_test_vec().
int pk_encrypt | ( | pk_context * | ctx, | |
const unsigned char * | input, | |||
size_t | ilen, | |||
unsigned char * | output, | |||
size_t * | olen, | |||
size_t | osize, | |||
int(*)(void *, unsigned char *, size_t) | f_rng, | |||
void * | p_rng | |||
) |
Encrypt message.
ctx | PK context to use | |
input | Message to encrypt | |
ilen | Message size | |
output | Encrypted output | |
olen | Encrypted output length | |
osize | Size of the output buffer | |
f_rng | RNG function | |
p_rng | RNG parameter |
Definition at line 227 of file pk.c.
References pk_info_t::encrypt_func, pk_context::pk_ctx, pk_context::pk_info, POLARSSL_ERR_PK_BAD_INPUT_DATA, and POLARSSL_ERR_PK_TYPE_MISMATCH.
Referenced by ssl_write_encrypted_pms(), test_suite_pk_ec_nocrypt(), and test_suite_pk_rsa_encrypt_test_vec().
void pk_free | ( | pk_context * | ctx | ) |
Free a pk_context.
Definition at line 58 of file pk.c.
References pk_info_t::ctx_free_func, pk_context::pk_ctx, and pk_context::pk_info.
Referenced by pk_parse_key(), pk_parse_key_pkcs8_unencrypted_der(), pk_parse_subpubkey(), ssl_key_cert_free(), test_suite_pk_ec_nocrypt(), test_suite_pk_ec_test_vec(), test_suite_pk_parse_key_rsa(), test_suite_pk_parse_keyfile_ec(), test_suite_pk_parse_keyfile_rsa(), test_suite_pk_parse_public_keyfile_ec(), test_suite_pk_parse_public_keyfile_rsa(), test_suite_pk_rsa_decrypt_test_vec(), test_suite_pk_rsa_encrypt_test_vec(), test_suite_pk_rsa_verify_test_vec(), test_suite_pk_sign_verify(), test_suite_pk_utils(), test_suite_pk_write_key_check(), test_suite_pk_write_pubkey_check(), test_suite_x509_crt_check(), test_suite_x509_csr_check(), x509_crt_free(), and x509_csr_free().
const char* pk_get_name | ( | const pk_context * | ctx | ) |
Access the type name.
ctx | Context to use |
Definition at line 268 of file pk.c.
References pk_info_t::name, and pk_context::pk_info.
Referenced by test_suite_pk_utils(), x509_crt_info(), and x509_csr_info().
size_t pk_get_size | ( | const pk_context * | ctx | ) |
Get the size in bits of the underlying key.
ctx | Context to use |
Definition at line 245 of file pk.c.
References pk_info_t::get_size, pk_context::pk_ctx, and pk_context::pk_info.
Referenced by pk_get_len(), test_suite_pk_utils(), x509_crt_info(), and x509_csr_info().
pk_type_t pk_get_type | ( | const pk_context * | ctx | ) |
Get the key type.
ctx | Context to use |
Definition at line 279 of file pk.c.
References pk_context::pk_info, POLARSSL_PK_NONE, and pk_info_t::type.
Referenced by pk_genkey(), pk_write_key_der(), pk_write_key_pem(), pk_write_pubkey(), pk_write_pubkey_der(), test_suite_pk_utils(), x509write_crt_der(), and x509write_csr_der().
static int pk_hashlen_helper | ( | md_type_t | md_alg, | |
size_t * | hash_len | |||
) | [inline, static] |
Definition at line 155 of file pk.c.
References md_info_from_type(), and md_info_t::size.
Referenced by pk_sign(), and pk_verify().
Return information associated with the given PK type.
pk_type | PK type to search for. |
Definition at line 72 of file pk.c.
References ecdsa_info, eckey_info, eckeydh_info, POLARSSL_PK_ECDSA, POLARSSL_PK_ECKEY, POLARSSL_PK_ECKEY_DH, POLARSSL_PK_RSA, and rsa_info.
Referenced by pk_parse_key(), pk_parse_key_pkcs8_unencrypted_der(), pk_parse_subpubkey(), ssl_set_own_cert_rsa(), test_suite_pk_ec_nocrypt(), test_suite_pk_ec_test_vec(), test_suite_pk_rsa_decrypt_test_vec(), test_suite_pk_rsa_encrypt_test_vec(), test_suite_pk_rsa_verify_test_vec(), test_suite_pk_sign_verify(), and test_suite_pk_utils().
void pk_init | ( | pk_context * | ctx | ) |
Initialize a pk_context (as NONE).
Definition at line 46 of file pk.c.
References pk_context::pk_ctx, and pk_context::pk_info.
Referenced by ssl_set_own_cert_alt(), ssl_set_own_cert_rsa(), test_suite_pk_ec_nocrypt(), test_suite_pk_ec_test_vec(), test_suite_pk_parse_key_rsa(), test_suite_pk_parse_keyfile_ec(), test_suite_pk_parse_keyfile_rsa(), test_suite_pk_parse_public_keyfile_ec(), test_suite_pk_parse_public_keyfile_rsa(), test_suite_pk_rsa_decrypt_test_vec(), test_suite_pk_rsa_encrypt_test_vec(), test_suite_pk_rsa_verify_test_vec(), test_suite_pk_sign_verify(), test_suite_pk_utils(), test_suite_pk_write_key_check(), test_suite_pk_write_pubkey_check(), test_suite_x509_crt_check(), and test_suite_x509_csr_check().
int pk_init_ctx | ( | pk_context * | ctx, | |
const pk_info_t * | info | |||
) |
Initialize a PK context with the information given and allocates the type-specific PK subcontext.
ctx | Context to initialize. Must be empty (type NONE). | |
info | Information to use |
pk_init_ctx_rsa_alt()
instead. Definition at line 98 of file pk.c.
References pk_info_t::ctx_alloc_func, pk_context::pk_ctx, pk_context::pk_info, POLARSSL_ERR_PK_BAD_INPUT_DATA, and POLARSSL_ERR_PK_MALLOC_FAILED.
Referenced by pk_parse_key(), pk_parse_key_pkcs8_unencrypted_der(), pk_parse_subpubkey(), ssl_set_own_cert_rsa(), test_suite_pk_ec_nocrypt(), test_suite_pk_ec_test_vec(), test_suite_pk_rsa_decrypt_test_vec(), test_suite_pk_rsa_encrypt_test_vec(), test_suite_pk_rsa_verify_test_vec(), test_suite_pk_sign_verify(), and test_suite_pk_utils().
int pk_init_ctx_rsa_alt | ( | pk_context * | ctx, | |
void * | key, | |||
pk_rsa_alt_decrypt_func | decrypt_func, | |||
pk_rsa_alt_sign_func | sign_func, | |||
pk_rsa_alt_key_len_func | key_len_func | |||
) |
Initialize an RSA-alt context.
ctx | Context to initialize. Must be empty (type NONE). | |
key | RSA key pointer | |
decrypt_func | Decryption function | |
sign_func | Signing function | |
key_len_func | Function returning key length |
pk_init_ctx()
for RSA-alt. Definition at line 114 of file pk.c.
References pk_info_t::ctx_alloc_func, rsa_alt_context::decrypt_func, rsa_alt_context::key, rsa_alt_context::key_len_func, pk_context::pk_ctx, pk_context::pk_info, POLARSSL_ERR_PK_BAD_INPUT_DATA, POLARSSL_ERR_PK_MALLOC_FAILED, rsa_alt_info, and rsa_alt_context::sign_func.
Referenced by ssl_set_own_cert_alt().
int pk_sign | ( | pk_context * | ctx, | |
md_type_t | md_alg, | |||
const unsigned char * | hash, | |||
size_t | hash_len, | |||
unsigned char * | sig, | |||
size_t * | sig_len, | |||
int(*)(void *, unsigned char *, size_t) | f_rng, | |||
void * | p_rng | |||
) |
Make signature.
ctx | PK context to use | |
md_alg | Hash algorithm used (see notes) | |
hash | Hash of the message to sign | |
hash_len | Hash length or 0 (see notes) | |
sig | Place to write the signature | |
sig_len | Number of bytes written | |
f_rng | RNG function | |
p_rng | RNG parameter |
Definition at line 190 of file pk.c.
References pk_context::pk_ctx, pk_hashlen_helper(), pk_context::pk_info, POLARSSL_ERR_PK_BAD_INPUT_DATA, POLARSSL_ERR_PK_TYPE_MISMATCH, and pk_info_t::sign_func.
Referenced by ssl_write_certificate_verify(), ssl_write_server_key_exchange(), test_suite_pk_sign_verify(), x509write_crt_der(), and x509write_csr_der().
int pk_verify | ( | pk_context * | ctx, | |
md_type_t | md_alg, | |||
const unsigned char * | hash, | |||
size_t | hash_len, | |||
const unsigned char * | sig, | |||
size_t | sig_len | |||
) |
Verify signature.
ctx | PK context to use | |
md_alg | Hash algorithm used (see notes) | |
hash | Hash of the message to sign | |
hash_len | Hash length or 0 (see notes) | |
sig | Signature to verify | |
sig_len | Signature length |
Definition at line 172 of file pk.c.
References pk_context::pk_ctx, pk_hashlen_helper(), pk_context::pk_info, POLARSSL_ERR_PK_BAD_INPUT_DATA, POLARSSL_ERR_PK_TYPE_MISMATCH, and pk_info_t::verify_func.
Referenced by ssl_parse_certificate_verify(), ssl_parse_server_key_exchange(), test_suite_pk_ec_test_vec(), test_suite_pk_rsa_verify_test_vec(), test_suite_pk_sign_verify(), x509_crt_verify_child(), x509_crt_verify_top(), and x509_crt_verifycrl().