26 #if !defined(POLARSSL_CONFIG_FILE)
29 #include POLARSSL_CONFIG_FILE
32 #if defined(POLARSSL_PK_C)
39 #if defined(POLARSSL_ECP_C)
43 #if defined(POLARSSL_ECDSA_C)
47 #if defined(POLARSSL_PLATFORM_C)
51 #define polarssl_malloc malloc
52 #define polarssl_free free
61 #if defined(POLARSSL_RSA_C)
62 static size_t rsa_get_size(
const void *ctx )
67 static int rsa_verify_wrap(
void *ctx,
md_type_t md_alg,
68 const unsigned char *hash,
size_t hash_len,
69 const unsigned char *sig,
size_t sig_len )
78 (
unsigned int) hash_len, hash, sig ) ) != 0 )
87 static int rsa_sign_wrap(
void *ctx,
md_type_t md_alg,
88 const unsigned char *hash,
size_t hash_len,
89 unsigned char *sig,
size_t *sig_len,
90 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
95 md_alg, (
unsigned int) hash_len, hash, sig ) );
98 static int rsa_decrypt_wrap(
void *ctx,
99 const unsigned char *input,
size_t ilen,
100 unsigned char *output,
size_t *olen,
size_t osize,
101 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
110 static int rsa_encrypt_wrap(
void *ctx,
111 const unsigned char *input,
size_t ilen,
112 unsigned char *output,
size_t *olen,
size_t osize,
113 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
120 f_rng, p_rng,
RSA_PUBLIC, ilen, input, output ) );
123 static void *rsa_alloc_wrap(
void )
133 static void rsa_free_wrap(
void *ctx )
139 static void rsa_debug(
const void *ctx,
pk_debug_item *items )
142 items->
name =
"rsa.N";
148 items->
name =
"rsa.E";
167 #if defined(POLARSSL_ECP_C)
171 static int eckey_can_do(
pk_type_t type )
178 static size_t eckey_get_size(
const void *ctx )
183 #if defined(POLARSSL_ECDSA_C)
185 static int ecdsa_verify_wrap(
void *ctx,
md_type_t md_alg,
186 const unsigned char *hash,
size_t hash_len,
187 const unsigned char *sig,
size_t sig_len );
189 static int ecdsa_sign_wrap(
void *ctx,
md_type_t md_alg,
190 const unsigned char *hash,
size_t hash_len,
191 unsigned char *sig,
size_t *sig_len,
192 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
194 static int eckey_verify_wrap(
void *ctx,
md_type_t md_alg,
195 const unsigned char *hash,
size_t hash_len,
196 const unsigned char *sig,
size_t sig_len )
204 ret = ecdsa_verify_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len );
211 static int eckey_sign_wrap(
void *ctx,
md_type_t md_alg,
212 const unsigned char *hash,
size_t hash_len,
213 unsigned char *sig,
size_t *sig_len,
214 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
222 ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len,
232 static void *eckey_alloc_wrap(
void )
242 static void eckey_free_wrap(
void *ctx )
248 static void eckey_debug(
const void *ctx,
pk_debug_item *items )
251 items->
name =
"eckey.Q";
260 #if defined(POLARSSL_ECDSA_C)
277 static int eckeydh_can_do(
pk_type_t type )
298 #if defined(POLARSSL_ECDSA_C)
299 static int ecdsa_can_do(
pk_type_t type )
304 static int ecdsa_verify_wrap(
void *ctx,
md_type_t md_alg,
305 const unsigned char *hash,
size_t hash_len,
306 const unsigned char *sig,
size_t sig_len )
312 hash, hash_len, sig, sig_len );
320 static int ecdsa_sign_wrap(
void *ctx,
md_type_t md_alg,
321 const unsigned char *hash,
size_t hash_len,
322 unsigned char *sig,
size_t *sig_len,
323 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
326 #if defined(POLARSSL_ECDSA_DETERMINISTIC)
331 hash, hash_len, sig, sig_len, md_alg ) );
336 hash, hash_len, sig, sig_len, f_rng, p_rng ) );
340 static void *ecdsa_alloc_wrap(
void )
350 static void ecdsa_free_wrap(
void *ctx )
375 static size_t rsa_alt_get_size(
const void *ctx )
382 static int rsa_alt_sign_wrap(
void *ctx,
md_type_t md_alg,
383 const unsigned char *hash,
size_t hash_len,
384 unsigned char *sig,
size_t *sig_len,
385 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
392 md_alg, (
unsigned int) hash_len, hash, sig ) );
395 static int rsa_alt_decrypt_wrap(
void *ctx,
396 const unsigned char *input,
size_t ilen,
397 unsigned char *output,
size_t *olen,
size_t osize,
398 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
412 static void *rsa_alt_alloc_wrap(
void )
422 static void rsa_alt_free_wrap(
void *ctx )
434 rsa_alt_decrypt_wrap,
int ecdsa_from_keypair(ecdsa_context *ctx, const ecp_keypair *key)
Set an ECDSA context from an EC key pair.
#define POLARSSL_ERR_PK_SIG_LEN_MISMATCH
The signature is valid but its length is less than expected.
void ecp_keypair_init(ecp_keypair *key)
Initialize a key pair (as an invalid one)
pk_rsa_alt_decrypt_func decrypt_func
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.
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...
#define POLARSSL_ERR_ECP_SIG_LEN_MISMATCH
Signature is valid but shorter than the user-supplied length.
void ecp_keypair_free(ecp_keypair *key)
Free the components of a key pair.