RetroArch
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;
101  int padding;
103  int hash_id;
107 #if defined(MBEDTLS_THREADING_C)
108  mbedtls_threading_mutex_t mutex;
109 #endif
110 }
112 
138  int padding,
139  int hash_id);
140 
149 void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, int hash_id);
150 
166  int (*f_rng)(void *, unsigned char *, size_t),
167  void *p_rng,
168  unsigned int nbits, int exponent );
169 
178 
187 
198 
216  const unsigned char *input,
217  unsigned char *output );
218 
234  int (*f_rng)(void *, unsigned char *, size_t),
235  void *p_rng,
236  const unsigned char *input,
237  unsigned char *output );
238 
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 
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 
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 
343  int (*f_rng)(void *, unsigned char *, size_t),
344  void *p_rng,
345  int mode, size_t *olen,
346  const unsigned char *input,
347  unsigned char *output,
348  size_t output_max_len );
349 
375  int (*f_rng)(void *, unsigned char *, size_t),
376  void *p_rng,
377  int mode, size_t *olen,
378  const unsigned char *input,
379  unsigned char *output,
380  size_t output_max_len );
381 
409  int (*f_rng)(void *, unsigned char *, size_t),
410  void *p_rng,
411  int mode,
412  const unsigned char *label, size_t label_len,
413  size_t *olen,
414  const unsigned char *input,
415  unsigned char *output,
416  size_t output_max_len );
417 
443  int (*f_rng)(void *, unsigned char *, size_t),
444  void *p_rng,
445  int mode,
446  mbedtls_md_type_t md_alg,
447  unsigned int hashlen,
448  const unsigned char *hash,
449  unsigned char *sig );
450 
470  int (*f_rng)(void *, unsigned char *, size_t),
471  void *p_rng,
472  int mode,
473  mbedtls_md_type_t md_alg,
474  unsigned int hashlen,
475  const unsigned char *hash,
476  unsigned char *sig );
477 
503  int (*f_rng)(void *, unsigned char *, size_t),
504  void *p_rng,
505  int mode,
506  mbedtls_md_type_t md_alg,
507  unsigned int hashlen,
508  const unsigned char *hash,
509  unsigned char *sig );
510 
535  int (*f_rng)(void *, unsigned char *, size_t),
536  void *p_rng,
537  int mode,
538  mbedtls_md_type_t md_alg,
539  unsigned int hashlen,
540  const unsigned char *hash,
541  const unsigned char *sig );
542 
562  int (*f_rng)(void *, unsigned char *, size_t),
563  void *p_rng,
564  int mode,
565  mbedtls_md_type_t md_alg,
566  unsigned int hashlen,
567  const unsigned char *hash,
568  const unsigned char *sig );
569 
596  int (*f_rng)(void *, unsigned char *, size_t),
597  void *p_rng,
598  int mode,
599  mbedtls_md_type_t md_alg,
600  unsigned int hashlen,
601  const unsigned char *hash,
602  const unsigned char *sig );
603 
629  int (*f_rng)(void *, unsigned char *, size_t),
630  void *p_rng,
631  int mode,
632  mbedtls_md_type_t md_alg,
633  unsigned int hashlen,
634  const unsigned char *hash,
635  mbedtls_md_type_t mgf1_hash_id,
636  int expected_salt_len,
637  const unsigned char *sig );
638 
649 
656 
662 int mbedtls_rsa_self_test( int verbose );
663 
664 #ifdef __cplusplus
665 }
666 #endif
667 
668 #endif /* MBEDTLS_RSA_C */
669 
670 #endif /* rsa.h */
int mbedtls_rsa_private(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, const unsigned char *input, unsigned char *output)
Do an RSA private key operation.
Definition: rsa.c:390
size_t len
Definition: rsa.h:82
mbedtls_mpi DP
Definition: rsa.h:90
int mbedtls_rsa_public(mbedtls_rsa_context *ctx, const unsigned char *input, unsigned char *output)
Do an RSA public key operation.
Definition: rsa.c:285
int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, const unsigned char *label, size_t label_len, size_t ilen, const unsigned char *input, unsigned char *output)
Perform a PKCS#1 v2.1 OAEP encryption (RSAES-OAEP-ENCRYPT)
Definition: rsa.c:610
mbedtls_mpi QP
Definition: rsa.h:92
int padding
Definition: rsa.h:101
GLenum mode
Definition: glext.h:6857
Threading abstraction layer.
int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_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)
Perform a PKCS#1 v1.5 decryption (RSAES-PKCS1-v1_5-DECRYPT)
Definition: rsa.c:918
mbedtls_mpi E
Definition: rsa.h:85
Configuration options (set of defines)
int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, const unsigned char *label, size_t label_len, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Perform a PKCS#1 v2.1 OAEP decryption (RSAES-OAEP-DECRYPT)
Definition: rsa.c:783
int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, unsigned int nbits, int exponent)
Generate an RSA keypair.
Definition: rsa.c:101
int ver
Definition: rsa.h:81
int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src)
Copy the components of an RSA context.
Definition: rsa.c:1617
mbedtls_mpi D
Definition: rsa.h:87
static sys_sem mutex
Definition: memp.c:120
mbedtls_mpi P
Definition: rsa.h:88
GLenum GLenum GLenum input
Definition: glext.h:9938
void mbedtls_rsa_init(mbedtls_rsa_context *ctx, int padding, int hash_id)
Initialize an RSA context.
Definition: rsa.c:74
GLuint GLsizei const GLchar * label
Definition: glext.h:8583
mbedtls_md_type_t
Definition: md.h:39
int hash_id
Definition: rsa.h:103
int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig)
Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) (This is the "simple" version....
Definition: rsa.c:1431
mbedtls_mpi RP
Definition: rsa.h:95
mbedtls_mpi Q
Definition: rsa.h:89
void mbedtls_rsa_free(mbedtls_rsa_context *ctx)
Free the components of an RSA key.
Definition: rsa.c:1654
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
int mbedtls_rsa_pkcs1_decrypt(mbedtls_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. Do an RSA operation,...
Definition: rsa.c:1014
Generic message digest wrapper.
int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx)
Check a private RSA key.
Definition: rsa.c:203
mbedtls_mpi RN
Definition: rsa.h:94
GLenum src
Definition: glext.h:6980
mbedtls_mpi RQ
Definition: rsa.h:96
int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig)
Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY)
Definition: rsa.c:1456
void mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding, int hash_id)
Set padding for an already initialized RSA context See mbedtls_rsa_init() for details.
Definition: rsa.c:90
mbedtls_mpi Vi
Definition: rsa.h:98
mbedtls_mpi Vf
Definition: rsa.h:99
GLint * exponent
Definition: glsym_gl.h:1069
MPI structure.
Definition: bignum.h:179
std::string output
Definition: Config.FromFile.cpp:44
int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Perform a PKCS#1 v2.1 PSS signature (RSASSA-PSS-SIGN)
Definition: rsa.c:1046
int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub, const mbedtls_rsa_context *prv)
Check a public-private RSA key pair. Check each of the contexts, and make sure they match.
Definition: rsa.c:265
int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Perform a PKCS#1 v1.5 signature (RSASSA-PKCS1-v1_5-SIGN)
Definition: rsa.c:1149
int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_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)
Perform a PKCS#1 v1.5 encryption (RSAES-PKCS1-v1_5-ENCRYPT)
Definition: rsa.c:687
Multi-precision integer library.
int mbedtls_rsa_pkcs1_verify(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_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. Do a public RSA ope...
Definition: rsa.c:1586
GLenum GLenum dst
Definition: glext.h:6980
mbedtls_mpi DQ
Definition: rsa.h:91
int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_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. Do a private RSA opera...
Definition: rsa.c:1273
RSA context structure.
Definition: rsa.h:79
int mbedtls_rsa_pkcs1_encrypt(mbedtls_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. Add the message paddi...
Definition: rsa.c:753
int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx)
Check a public RSA key.
Definition: rsa.c:180
mbedtls_mpi N
Definition: rsa.h:84
int mbedtls_rsa_self_test(int verbose)
Checkup routine.
Definition: rsa.c:1750
int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, mbedtls_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....
Definition: rsa.c:1305