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
56 static void polarssl_zeroize(
void *v,
size_t n ) {
57 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
60 #if defined(POLARSSL_RSA_C)
67 static size_t rsa_get_size(
const void *ctx )
72 static int rsa_verify_wrap(
void *ctx,
md_type_t md_alg,
73 const unsigned char *hash,
size_t hash_len,
74 const unsigned char *sig,
size_t sig_len )
83 (
unsigned int) hash_len, hash, sig ) ) != 0 )
92 static int rsa_sign_wrap(
void *ctx,
md_type_t md_alg,
93 const unsigned char *hash,
size_t hash_len,
94 unsigned char *sig,
size_t *sig_len,
95 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
100 md_alg, (
unsigned int) hash_len, hash, sig ) );
103 static int rsa_decrypt_wrap(
void *ctx,
104 const unsigned char *input,
size_t ilen,
105 unsigned char *output,
size_t *olen,
size_t osize,
106 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
115 static int rsa_encrypt_wrap(
void *ctx,
116 const unsigned char *input,
size_t ilen,
117 unsigned char *output,
size_t *olen,
size_t osize,
118 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
125 f_rng, p_rng,
RSA_PUBLIC, ilen, input, output ) );
128 static void *rsa_alloc_wrap(
void )
138 static void rsa_free_wrap(
void *ctx )
144 static void rsa_debug(
const void *ctx,
pk_debug_item *items )
147 items->
name =
"rsa.N";
153 items->
name =
"rsa.E";
172 #if defined(POLARSSL_ECP_C)
176 static int eckey_can_do(
pk_type_t type )
183 static size_t eckey_get_size(
const void *ctx )
188 #if defined(POLARSSL_ECDSA_C)
190 static int ecdsa_verify_wrap(
void *ctx,
md_type_t md_alg,
191 const unsigned char *hash,
size_t hash_len,
192 const unsigned char *sig,
size_t sig_len );
194 static int ecdsa_sign_wrap(
void *ctx,
md_type_t md_alg,
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 static int eckey_verify_wrap(
void *ctx,
md_type_t md_alg,
200 const unsigned char *hash,
size_t hash_len,
201 const unsigned char *sig,
size_t sig_len )
209 ret = ecdsa_verify_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len );
216 static int eckey_sign_wrap(
void *ctx,
md_type_t md_alg,
217 const unsigned char *hash,
size_t hash_len,
218 unsigned char *sig,
size_t *sig_len,
219 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
227 ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len,
237 static void *eckey_alloc_wrap(
void )
247 static void eckey_free_wrap(
void *ctx )
253 static void eckey_debug(
const void *ctx,
pk_debug_item *items )
256 items->
name =
"eckey.Q";
265 #if defined(POLARSSL_ECDSA_C)
282 static int eckeydh_can_do(
pk_type_t type )
303 #if defined(POLARSSL_ECDSA_C)
304 static int ecdsa_can_do(
pk_type_t type )
309 static int ecdsa_verify_wrap(
void *ctx,
md_type_t md_alg,
310 const unsigned char *hash,
size_t hash_len,
311 const unsigned char *sig,
size_t sig_len )
317 hash, hash_len, sig, sig_len );
325 static int ecdsa_sign_wrap(
void *ctx,
md_type_t md_alg,
326 const unsigned char *hash,
size_t hash_len,
327 unsigned char *sig,
size_t *sig_len,
328 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
331 #if defined(POLARSSL_ECDSA_DETERMINISTIC)
336 hash, hash_len, sig, sig_len, md_alg ) );
341 hash, hash_len, sig, sig_len, f_rng, p_rng ) );
345 static void *ecdsa_alloc_wrap(
void )
355 static void ecdsa_free_wrap(
void *ctx )
380 static int rsa_alt_can_do(
pk_type_t type )
385 static size_t rsa_alt_get_size(
const void *ctx )
392 static int rsa_alt_sign_wrap(
void *ctx,
md_type_t md_alg,
393 const unsigned char *hash,
size_t hash_len,
394 unsigned char *sig,
size_t *sig_len,
395 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
402 md_alg, (
unsigned int) hash_len, hash, sig ) );
405 static int rsa_alt_decrypt_wrap(
void *ctx,
406 const unsigned char *input,
size_t ilen,
407 unsigned char *output,
size_t *olen,
size_t osize,
408 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
422 static void *rsa_alt_alloc_wrap(
void )
432 static void rsa_alt_free_wrap(
void *ctx )
445 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.