28 #if defined(POLARSSL_PK_C)
35 #if defined(POLARSSL_ECP_C)
39 #if defined(POLARSSL_ECDSA_C)
43 #if defined(POLARSSL_MEMORY_C)
47 #define polarssl_malloc malloc
48 #define polarssl_free free
57 #if defined(POLARSSL_RSA_C)
58 static size_t rsa_get_size(
const void *ctx )
63 static int rsa_verify_wrap(
void *ctx,
md_type_t md_alg,
64 const unsigned char *hash,
size_t hash_len,
65 const unsigned char *sig,
size_t sig_len )
71 RSA_PUBLIC, md_alg, (
unsigned int) hash_len, hash, sig ) );
74 static int rsa_sign_wrap(
void *ctx,
md_type_t md_alg,
75 const unsigned char *hash,
size_t hash_len,
76 unsigned char *sig,
size_t *sig_len,
77 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
82 md_alg, (
unsigned int) hash_len, hash, sig ) );
85 static int rsa_decrypt_wrap(
void *ctx,
86 const unsigned char *input,
size_t ilen,
87 unsigned char *output,
size_t *olen,
size_t osize,
88 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
97 static int rsa_encrypt_wrap(
void *ctx,
98 const unsigned char *input,
size_t ilen,
99 unsigned char *output,
size_t *olen,
size_t osize,
100 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
107 f_rng, p_rng,
RSA_PUBLIC, ilen, input, output ) );
110 static void *rsa_alloc_wrap(
void )
120 static void rsa_free_wrap(
void *ctx )
126 static void rsa_debug(
const void *ctx,
pk_debug_item *items )
129 items->
name =
"rsa.N";
135 items->
name =
"rsa.E";
154 #if defined(POLARSSL_ECP_C)
158 static int eckey_can_do(
pk_type_t type )
165 static size_t eckey_get_size(
const void *ctx )
170 #if defined(POLARSSL_ECDSA_C)
172 static int ecdsa_verify_wrap(
void *ctx,
md_type_t md_alg,
173 const unsigned char *hash,
size_t hash_len,
174 const unsigned char *sig,
size_t sig_len );
176 static int ecdsa_sign_wrap(
void *ctx,
md_type_t md_alg,
177 const unsigned char *hash,
size_t hash_len,
178 unsigned char *sig,
size_t *sig_len,
179 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
181 static int eckey_verify_wrap(
void *ctx,
md_type_t md_alg,
182 const unsigned char *hash,
size_t hash_len,
183 const unsigned char *sig,
size_t sig_len )
191 ret = ecdsa_verify_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len );
198 static int eckey_sign_wrap(
void *ctx,
md_type_t md_alg,
199 const unsigned char *hash,
size_t hash_len,
200 unsigned char *sig,
size_t *sig_len,
201 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
209 ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len,
219 static void *eckey_alloc_wrap(
void )
229 static void eckey_free_wrap(
void *ctx )
235 static void eckey_debug(
const void *ctx,
pk_debug_item *items )
238 items->
name =
"eckey.Q";
247 #if defined(POLARSSL_ECDSA_C)
264 static int eckeydh_can_do(
pk_type_t type )
285 #if defined(POLARSSL_ECDSA_C)
286 static int ecdsa_can_do(
pk_type_t type )
291 static int ecdsa_verify_wrap(
void *ctx,
md_type_t md_alg,
292 const unsigned char *hash,
size_t hash_len,
293 const unsigned char *sig,
size_t sig_len )
298 hash, hash_len, sig, sig_len ) );
301 static int ecdsa_sign_wrap(
void *ctx,
md_type_t md_alg,
302 const unsigned char *hash,
size_t hash_len,
303 unsigned char *sig,
size_t *sig_len,
304 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
307 #if defined(POLARSSL_ECDSA_DETERMINISTIC)
312 hash, hash_len, sig, sig_len, md_alg ) );
317 hash, hash_len, sig, sig_len, f_rng, p_rng ) );
321 static void *ecdsa_alloc_wrap(
void )
331 static void ecdsa_free_wrap(
void *ctx )
356 static size_t rsa_alt_get_size(
const void *ctx )
363 static int rsa_alt_sign_wrap(
void *ctx,
md_type_t md_alg,
364 const unsigned char *hash,
size_t hash_len,
365 unsigned char *sig,
size_t *sig_len,
366 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
373 md_alg, (
unsigned int) hash_len, hash, sig ) );
376 static int rsa_alt_decrypt_wrap(
void *ctx,
377 const unsigned char *input,
size_t ilen,
378 unsigned char *output,
size_t *olen,
size_t osize,
379 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
393 static void *rsa_alt_alloc_wrap(
void )
403 static void rsa_alt_free_wrap(
void *ctx )
415 rsa_alt_decrypt_wrap,
int ecdsa_from_keypair(ecdsa_context *ctx, const ecp_keypair *key)
Set an ECDSA context from an EC key pair.
void ecp_keypair_init(ecp_keypair *key)
Initialize a key pair (as an invalid one)
pk_rsa_alt_decrypt_func decrypt_func
void *(* polarssl_malloc)(size_t len)
const pk_info_t eckeydh_info
Elliptic curves over GF(p)
int ecdsa_write_signature(ecdsa_context *ctx, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Compute ECDSA signature and write it to buffer, serialized as defined in RFC 4492 page 20...
Configuration options (set of defines)
int rsa_pkcs1_decrypt(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Generic wrapper to perform a PKCS#1 decryption using the mode from the context.
void rsa_free(rsa_context *ctx)
Free the components of an RSA key.
int rsa_pkcs1_encrypt(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t ilen, const unsigned char *input, unsigned char *output)
Generic wrapper to perform a PKCS#1 encryption using the mode from the context.
Item to send to the debug module.
void(* polarssl_free)(void *ptr)
Public key information and operations.
int ecdsa_read_signature(ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen)
Read and verify an ECDSA signature.
void ecdsa_init(ecdsa_context *ctx)
Initialize context.
pk_type_t
Public key types.
int rsa_pkcs1_verify(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, const unsigned char *sig)
Generic wrapper to perform a PKCS#1 verification using the mode from the context. ...
#define POLARSSL_ERR_RSA_VERIFY_FAILED
The PKCS#1 verification failed.
pk_rsa_alt_sign_func sign_func
int rsa_pkcs1_sign(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, unsigned char *sig)
Generic wrapper to perform a PKCS#1 signature using the mode from the context.
const pk_info_t rsa_alt_info
The RSA public-key cryptosystem.
#define POLARSSL_ERR_RSA_BAD_INPUT_DATA
Bad input parameters to function.
const pk_info_t eckey_info
const pk_info_t ecdsa_info
void rsa_init(rsa_context *ctx, int padding, int hash_id)
Initialize an RSA context.
void ecdsa_free(ecdsa_context *ctx)
Free context.
pk_rsa_alt_key_len_func key_len_func
int ecdsa_write_signature_det(ecdsa_context *ctx, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, md_type_t md_alg)
Compute ECDSA signature and write it to buffer, serialized as defined in RFC 4492 page 20...
void ecp_keypair_free(ecp_keypair *key)
Free the components of a key pair.