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)
48 static void polarssl_zeroize(
void *v,
size_t n ) {
49 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
69 if( ctx == NULL || ctx->
pk_info == NULL )
83 #if defined(POLARSSL_RSA_C)
87 #if defined(POLARSSL_ECP_C)
93 #if defined(POLARSSL_ECDSA_C)
108 if( ctx == NULL || info == NULL || ctx->
pk_info != NULL )
130 if( ctx == NULL || ctx->
pk_info != NULL )
154 if( ctx == NULL || ctx->
pk_info == NULL )
163 static inline int pk_hashlen_helper(
md_type_t md_alg,
size_t *hash_len )
173 *hash_len = md_info->
size;
181 const unsigned char *hash,
size_t hash_len,
182 const unsigned char *sig,
size_t sig_len )
184 if( ctx == NULL || ctx->
pk_info == NULL ||
185 pk_hashlen_helper( md_alg, &hash_len ) != 0 )
200 const unsigned char *hash,
size_t hash_len,
201 const unsigned char *sig,
size_t sig_len )
203 if( ctx == NULL || ctx->
pk_info == NULL )
211 #if defined(POLARSSL_RSA_C) && defined(POLARSSL_PKCS1_V21)
215 if( options == NULL )
225 md_alg, (
unsigned int) hash_len, hash,
242 if( options != NULL )
245 return(
pk_verify( ctx, md_alg, hash, hash_len, sig, sig_len ) );
252 const unsigned char *hash,
size_t hash_len,
253 unsigned char *sig,
size_t *sig_len,
254 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
256 if( ctx == NULL || ctx->
pk_info == NULL ||
257 pk_hashlen_helper( md_alg, &hash_len ) != 0 )
264 sig, sig_len, f_rng, p_rng ) );
271 const unsigned char *input,
size_t ilen,
272 unsigned char *output,
size_t *olen,
size_t osize,
273 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
275 if( ctx == NULL || ctx->
pk_info == NULL )
282 output, olen, osize, f_rng, p_rng ) );
289 const unsigned char *input,
size_t ilen,
290 unsigned char *output,
size_t *olen,
size_t osize,
291 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
293 if( ctx == NULL || ctx->
pk_info == NULL )
300 output, olen, osize, f_rng, p_rng ) );
308 if( ctx == NULL || ctx->
pk_info == NULL )
319 if( ctx == NULL || ctx->
pk_info == NULL )
334 if( ctx == NULL || ctx->
pk_info == NULL )
335 return(
"invalid PK" );
345 if( ctx == NULL || ctx->
pk_info == NULL )
static size_t pk_get_len(const pk_context *ctx)
Get the length in bytes of the underlying key.
#define POLARSSL_ERR_PK_SIG_LEN_MISMATCH
The signature is valid but its length is less than expected.
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.
Options for RSASSA-PSS signature verification.
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 (including padding if relevant).
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 pk_verify_ext(pk_type_t type, const void *options, 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, with options.
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.
#define POLARSSL_ERR_PK_FEATURE_UNAVAILABLE
Unavailable feature, e.g.
int rsa_rsassa_pss_verify_ext(rsa_context *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, md_type_t mgf1_hash_id, int expected_salt_len, const unsigned char *sig)
Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) (This is the version with "full" options...
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 (including padding if relevant).
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.
#define POLARSSL_ERR_RSA_VERIFY_FAILED
The PKCS#1 verification failed.
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.
#define pk_rsa(pk)
Quick access to an RSA context inside a PK context.
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, including padding if relevant.
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 (including padding if relevant).
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.