26 #if !defined(POLARSSL_CONFIG_FILE)
29 #include POLARSSL_CONFIG_FILE
32 #if defined(POLARSSL_PK_C)
37 #if defined(POLARSSL_RSA_C)
40 #if defined(POLARSSL_ECP_C)
43 #if defined(POLARSSL_ECDSA_C)
64 if( ctx == NULL || ctx->
pk_info == NULL)
79 #if defined(POLARSSL_RSA_C)
83 #if defined(POLARSSL_ECP_C)
89 #if defined(POLARSSL_ECDSA_C)
104 if( ctx == NULL || info == NULL || ctx->
pk_info != NULL )
126 if( ctx == NULL || ctx->
pk_info != NULL )
150 if( ctx == NULL || ctx->
pk_info == NULL )
159 static inline int pk_hashlen_helper(
md_type_t md_alg,
size_t *hash_len )
169 *hash_len = md_info->
size;
177 const unsigned char *hash,
size_t hash_len,
178 const unsigned char *sig,
size_t sig_len )
180 if( ctx == NULL || ctx->
pk_info == NULL ||
181 pk_hashlen_helper( md_alg, &hash_len ) != 0 )
195 const unsigned char *hash,
size_t hash_len,
196 unsigned char *sig,
size_t *sig_len,
197 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
199 if( ctx == NULL || ctx->
pk_info == NULL ||
200 pk_hashlen_helper( md_alg, &hash_len ) != 0 )
207 sig, sig_len, f_rng, p_rng ) );
214 const unsigned char *input,
size_t ilen,
215 unsigned char *output,
size_t *olen,
size_t osize,
216 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
218 if( ctx == NULL || ctx->
pk_info == NULL )
225 output, olen, osize, f_rng, p_rng ) );
232 const unsigned char *input,
size_t ilen,
233 unsigned char *output,
size_t *olen,
size_t osize,
234 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
236 if( ctx == NULL || ctx->
pk_info == NULL )
243 output, olen, osize, f_rng, p_rng ) );
251 if( ctx == NULL || ctx->
pk_info == NULL )
262 if( ctx == NULL || ctx->
pk_info == NULL )
277 if( ctx == NULL || ctx->
pk_info == NULL )
278 return(
"invalid PK" );
288 if( ctx == NULL || ctx->
pk_info == NULL )
const pk_info_t * pk_info_from_type(pk_type_t pk_type)
Return information associated with the given PK type.
pk_rsa_alt_decrypt_func decrypt_func
const pk_info_t eckeydh_info
int(* verify_func)(void *ctx, md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature.
Elliptic curves over GF(p)
size_t pk_get_size(const pk_context *ctx)
Get the size in bits of the underlying key.
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_debug(const pk_context *ctx, pk_debug_item *items)
Export debug information.
Configuration options (set of defines)
const pk_info_t * pk_info
Public key informations.
pk_type_t pk_get_type(const pk_context *ctx)
Get the key type.
const char * pk_get_name(const pk_context *ctx)
Access the type name.
Public Key abstraction layer.
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.
#define POLARSSL_ERR_PK_BAD_INPUT_DATA
Bad input parameters to function.
int(* encrypt_func)(void *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.
int(* pk_rsa_alt_sign_func)(void *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
void(* debug_func)(const void *ctx, pk_debug_item *items)
Interface with the debug module.
int(* can_do)(pk_type_t type)
Tell if the context implements this type (e.g.
Item to send to the debug module.
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.
Public key information and operations.
int pk_can_do(pk_context *ctx, pk_type_t type)
Tell if a context can do the operation given by type.
#define POLARSSL_ERR_PK_MALLOC_FAILED
Memory alloation failed.
size_t(* get_size)(const void *)
Get key size in bits.
void * pk_ctx
Underlying public key context.
pk_type_t
Public key types.
pk_rsa_alt_sign_func sign_func
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...
const pk_info_t rsa_alt_info
The RSA public-key cryptosystem.
size_t(* pk_rsa_alt_key_len_func)(void *ctx)
#define POLARSSL_ERR_PK_TYPE_MISMATCH
Type mismatch, eg attempt to encrypt with an ECDSA key.
void pk_free(pk_context *ctx)
Free a pk_context.
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.
void *(* ctx_alloc_func)(void)
Allocate a new context.
const pk_info_t eckey_info
const pk_info_t ecdsa_info
int(* pk_rsa_alt_decrypt_func)(void *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Types for RSA-alt abstraction.
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.
void pk_init(pk_context *ctx)
Initialize a pk_context (as NONE)
int size
Output length of the digest function.
const char * name
Type name.
pk_rsa_alt_key_len_func key_len_func
pk_type_t type
Public key type.
int(* sign_func)(void *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.
Message digest information.
int(* decrypt_func)(void *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.
void(* ctx_free_func)(void *ctx)
Free the given context.