mbed TLS v2.2.0
rsa.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_RSA_H
24 #define MBEDTLS_RSA_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #include "bignum.h"
33 #include "md.h"
34 
35 #if defined(MBEDTLS_THREADING_C)
36 #include "threading.h"
37 #endif
38 
39 /*
40  * RSA Error codes
41  */
42 #define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080
43 #define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100
44 #define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180
45 #define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200
46 #define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280
47 #define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300
48 #define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380
49 #define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
50 #define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480
52 /*
53  * RSA constants
54  */
55 #define MBEDTLS_RSA_PUBLIC 0
56 #define MBEDTLS_RSA_PRIVATE 1
57 
58 #define MBEDTLS_RSA_PKCS_V15 0
59 #define MBEDTLS_RSA_PKCS_V21 1
60 
61 #define MBEDTLS_RSA_SIGN 1
62 #define MBEDTLS_RSA_CRYPT 2
63 
64 #define MBEDTLS_RSA_SALT_LEN_ANY -1
65 
66 /*
67  * The above constants may be used even if the RSA module is compile out,
68  * eg for alternative (PKCS#11) RSA implemenations in the PK layers.
69  */
70 #if defined(MBEDTLS_RSA_C)
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
79 typedef struct
80 {
81  int ver;
82  size_t len;
84  mbedtls_mpi N;
85  mbedtls_mpi E;
87  mbedtls_mpi D;
88  mbedtls_mpi P;
89  mbedtls_mpi Q;
90  mbedtls_mpi DP;
91  mbedtls_mpi DQ;
92  mbedtls_mpi QP;
94  mbedtls_mpi RN;
95  mbedtls_mpi RP;
96  mbedtls_mpi RQ;
98  mbedtls_mpi Vi;
99  mbedtls_mpi Vf;
101  int padding;
103  int hash_id;
107 #if defined(MBEDTLS_THREADING_C)
108  mbedtls_threading_mutex_t mutex;
109 #endif
110 }
111 mbedtls_rsa_context;
112 
137 void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
138  int padding,
139  int hash_id);
140 
149 void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, int hash_id);
150 
165 int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
166  int (*f_rng)(void *, unsigned char *, size_t),
167  void *p_rng,
168  unsigned int nbits, int exponent );
169 
177 int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx );
178 
186 int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx );
187 
197 int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, const mbedtls_rsa_context *prv );
198 
215 int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
216  const unsigned char *input,
217  unsigned char *output );
218 
233 int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
234  int (*f_rng)(void *, unsigned char *, size_t),
235  void *p_rng,
236  const unsigned char *input,
237  unsigned char *output );
238 
258 int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
259  int (*f_rng)(void *, unsigned char *, size_t),
260  void *p_rng,
261  int mode, size_t ilen,
262  const unsigned char *input,
263  unsigned char *output );
264 
281 int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
282  int (*f_rng)(void *, unsigned char *, size_t),
283  void *p_rng,
284  int mode, size_t ilen,
285  const unsigned char *input,
286  unsigned char *output );
287 
307 int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
308  int (*f_rng)(void *, unsigned char *, size_t),
309  void *p_rng,
310  int mode,
311  const unsigned char *label, size_t label_len,
312  size_t ilen,
313  const unsigned char *input,
314  unsigned char *output );
315 
336 int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
337  int (*f_rng)(void *, unsigned char *, size_t),
338  void *p_rng,
339  int mode, size_t *olen,
340  const unsigned char *input,
341  unsigned char *output,
342  size_t output_max_len );
343 
362 int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
363  int (*f_rng)(void *, unsigned char *, size_t),
364  void *p_rng,
365  int mode, size_t *olen,
366  const unsigned char *input,
367  unsigned char *output,
368  size_t output_max_len );
369 
390 int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
391  int (*f_rng)(void *, unsigned char *, size_t),
392  void *p_rng,
393  int mode,
394  const unsigned char *label, size_t label_len,
395  size_t *olen,
396  const unsigned char *input,
397  unsigned char *output,
398  size_t output_max_len );
399 
424 int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
425  int (*f_rng)(void *, unsigned char *, size_t),
426  void *p_rng,
427  int mode,
428  mbedtls_md_type_t md_alg,
429  unsigned int hashlen,
430  const unsigned char *hash,
431  unsigned char *sig );
432 
451 int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
452  int (*f_rng)(void *, unsigned char *, size_t),
453  void *p_rng,
454  int mode,
455  mbedtls_md_type_t md_alg,
456  unsigned int hashlen,
457  const unsigned char *hash,
458  unsigned char *sig );
459 
484 int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
485  int (*f_rng)(void *, unsigned char *, size_t),
486  void *p_rng,
487  int mode,
488  mbedtls_md_type_t md_alg,
489  unsigned int hashlen,
490  const unsigned char *hash,
491  unsigned char *sig );
492 
516 int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
517  int (*f_rng)(void *, unsigned char *, size_t),
518  void *p_rng,
519  int mode,
520  mbedtls_md_type_t md_alg,
521  unsigned int hashlen,
522  const unsigned char *hash,
523  const unsigned char *sig );
524 
543 int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
544  int (*f_rng)(void *, unsigned char *, size_t),
545  void *p_rng,
546  int mode,
547  mbedtls_md_type_t md_alg,
548  unsigned int hashlen,
549  const unsigned char *hash,
550  const unsigned char *sig );
551 
577 int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
578  int (*f_rng)(void *, unsigned char *, size_t),
579  void *p_rng,
580  int mode,
581  mbedtls_md_type_t md_alg,
582  unsigned int hashlen,
583  const unsigned char *hash,
584  const unsigned char *sig );
585 
610 int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
611  int (*f_rng)(void *, unsigned char *, size_t),
612  void *p_rng,
613  int mode,
614  mbedtls_md_type_t md_alg,
615  unsigned int hashlen,
616  const unsigned char *hash,
617  mbedtls_md_type_t mgf1_hash_id,
618  int expected_salt_len,
619  const unsigned char *sig );
620 
630 int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src );
631 
637 void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
638 
644 int mbedtls_rsa_self_test( int verbose );
645 
646 #ifdef __cplusplus
647 }
648 #endif
649 
650 #endif /* MBEDTLS_RSA_C */
651 
652 #endif /* rsa.h */
Compatibility names (set of defines)
Multi-precision integer library.
Threading abstraction layer.
Generic message digest wrapper.
MPI structure.
Definition: bignum.h:143
mbedtls_md_type_t
Definition: md.h:39