RetroArch
pk.h
Go to the documentation of this file.
1 
24 #ifndef MBEDTLS_PK_H
25 #define MBEDTLS_PK_H
26 
27 #include <retro_inline.h>
28 
29 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include "config.h"
31 #else
32 #include MBEDTLS_CONFIG_FILE
33 #endif
34 
35 #include "md.h"
36 
37 #if defined(MBEDTLS_RSA_C)
38 #include "rsa.h"
39 #endif
40 
41 #if defined(MBEDTLS_ECP_C)
42 #include "ecp.h"
43 #endif
44 
45 #if defined(MBEDTLS_ECDSA_C)
46 #include "ecdsa.h"
47 #endif
48 
49 #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
50 #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
51 #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
52 #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
53 #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
54 #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
55 #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
56 #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
57 #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
58 #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
59 #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
60 #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
61 #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
62 #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
71 typedef enum {
80 
85 typedef struct
86 {
89 
91 
95 typedef enum
96 {
101 
105 typedef struct
106 {
108  const char *name;
109  void *value;
111 
113 #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
114 
119 
123 typedef struct
124 {
126  void * pk_ctx;
128 
129 #if defined(MBEDTLS_RSA_C)
130 
137 {
138  return( (mbedtls_rsa_context *) (pk).pk_ctx );
139 }
140 #endif /* MBEDTLS_RSA_C */
141 
142 #if defined(MBEDTLS_ECP_C)
143 
150 {
151  return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
152 }
153 #endif /* MBEDTLS_ECP_C */
154 
155 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
156 
159 typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, int mode, size_t *olen,
160  const unsigned char *input, unsigned char *output,
161  size_t output_max_len );
162 typedef int (*mbedtls_pk_rsa_alt_sign_func)( void *ctx,
163  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
164  int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
165  const unsigned char *hash, unsigned char *sig );
166 typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx );
167 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
168 
177 
182 
187 
203 
204 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
205 
222  mbedtls_pk_rsa_alt_key_len_func key_len_func );
223 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
224 
233 
241 {
242  return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 );
243 }
244 
255 
281  const unsigned char *hash, size_t hash_len,
282  const unsigned char *sig, size_t sig_len );
283 
315  const unsigned char *hash, size_t hash_len,
316  const unsigned char *sig, size_t sig_len );
317 
343  const unsigned char *hash, size_t hash_len,
344  unsigned char *sig, size_t *sig_len,
345  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
346 
364  const unsigned char *input, size_t ilen,
365  unsigned char *output, size_t *olen, size_t osize,
366  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
367 
385  const unsigned char *input, size_t ilen,
386  unsigned char *output, size_t *olen, size_t osize,
387  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
388 
397 int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv );
398 
408 
416 const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx );
417 
426 
427 #if defined(MBEDTLS_PK_PARSE_C)
428 
448  const unsigned char *key, size_t keylen,
449  const unsigned char *pwd, size_t pwdlen );
450 
469  const unsigned char *key, size_t keylen );
470 
471 #if defined(MBEDTLS_FS_IO)
472 
489  const char *path, const char *password );
490 
508 #endif /* MBEDTLS_FS_IO */
509 #endif /* MBEDTLS_PK_PARSE_C */
510 
511 #if defined(MBEDTLS_PK_WRITE_C)
512 
525 int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
526 
540 int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
541 
542 #if defined(MBEDTLS_PEM_WRITE_C)
543 
552 int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
553 
563 int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
564 #endif /* MBEDTLS_PEM_WRITE_C */
565 #endif /* MBEDTLS_PK_WRITE_C */
566 
567 /*
568  * WARNING: Low-level functions. You probably do not want to use these unless
569  * you are certain you do ;)
570  */
571 
572 #if defined(MBEDTLS_PK_PARSE_C)
573 
582 int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
583  mbedtls_pk_context *pk );
584 #endif /* MBEDTLS_PK_PARSE_C */
585 
586 #if defined(MBEDTLS_PK_WRITE_C)
587 
597 int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
598  const mbedtls_pk_context *key );
599 #endif /* MBEDTLS_PK_WRITE_C */
600 
601 /*
602  * Internal module functions. You probably do not want to use these unless you
603  * know you do.
604  */
605 #if defined(MBEDTLS_FS_IO)
606 int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
607 #endif
608 
609 #ifdef __cplusplus
610 }
611 #endif
612 
613 #endif /* MBEDTLS_PK_H */
void * value
Definition: pk.h:109
int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path, const char *password)
Load and parse a private key.
Definition: pkparse.c:118
Definition: pk_internal.h:35
const char * name
Definition: pk.h:108
Definition: pk.h:74
Definition: pk.h:97
int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options, mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature, with options. (Includes verification of the padding depending on type....
Definition: pk.c:196
Elliptic curves over GF(p)
GLenum mode
Definition: glext.h:6857
static const unsigned char password[MAX_TESTS][32]
Definition: pkcs5.c:305
Definition: pk.h:75
#define INLINE
Definition: retro_inline.h:35
int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Make signature, including padding if relevant.
Definition: pk.c:254
int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature (including padding if relevant).
Definition: pk.c:178
int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Decrypt message (including padding if relevant).
Definition: pk.c:273
Configuration options (set of defines)
GLuint start
Definition: glext.h:6292
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free a mbedtls_pk_context.
Definition: pk.c:63
Definition: libretro.h:2275
int(* sign_func)(void *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Definition: pk_internal.h:55
GLsizei const GLchar ** path
Definition: glext.h:7901
Definition: pk.h:78
int expected_salt_len
Definition: pk.h:88
GLsizeiptr size
Definition: glext.h:6559
int mbedtls_pk_write_key_pem(mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a private key to a PKCS#1 or SEC1 PEM string.
Definition: pkwrite.c:400
static INLINE mbedtls_ecp_keypair * mbedtls_pk_ec(const mbedtls_pk_context pk)
Definition: pk.h:149
int mbedtls_pk_parse_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen)
Parse a private key in PEM or DER format.
Definition: pkparse.c:1056
int mbedtls_pk_write_key_der(mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a private key to a PKCS#1 or SEC1 DER structure Note: data is written at the end of the buffer!...
Definition: pkwrite.c:199
Elliptic curve DSA.
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv)
Check if a public-private pair of keys matches.
Definition: pk.c:309
int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n)
Definition: pkparse.c:73
const mbedtls_pk_info_t * mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type)
Return information associated with the given PK type.
Definition: pk.c:76
int mbedtls_pk_write_pubkey_der(mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a public key to a SubjectPublicKeyInfo DER structure Note: data is written at the end of the bu...
Definition: pkwrite.c:151
GLenum GLenum GLenum input
Definition: glext.h:9938
mbedtls_pk_debug_type type
Definition: pk.h:107
mbedtls_md_type_t
Definition: md.h:39
int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path)
Load and parse a public key.
Definition: pkparse.c:143
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
Definition: pk.c:372
mbedtls_pk_type_t
Public key types.
Definition: pk.h:71
Definition: pk.h:72
int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start, const mbedtls_pk_context *key)
Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer.
Definition: pkwrite.c:130
Definition: pk.h:98
int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
Definition: pkparse.c:576
GLenum type
Definition: glext.h:6233
int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, mbedtls_pk_rsa_alt_decrypt_func decrypt_func, mbedtls_pk_rsa_alt_sign_func sign_func, mbedtls_pk_rsa_alt_key_len_func key_len_func)
Initialize an RSA-alt context.
Definition: pk.c:119
const mbedtls_pk_info_t * pk_info
Definition: pk.h:125
int mbedtls_pk_write_pubkey_pem(mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a public key to a PEM string.
Definition: pkwrite.c:378
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
Definition: pk.h:77
int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type)
Tell if a context can do the operation given by type.
Definition: pk.c:149
Generic message digest wrapper.
int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen)
Parse a public key in PEM or DER format.
Definition: pkparse.c:1245
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext()
Definition: pk.h:85
static INLINE size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
Get the length in bytes of the underlying key.
Definition: pk.h:240
Definition: pk.h:73
void * pk_ctx
Definition: pk.h:126
int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Encrypt message (including padding if relevant).
Definition: pk.c:291
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE)
Definition: pk.c:51
Definition: pk.h:99
GLfloat GLfloat p
Definition: glext.h:9809
int(* decrypt_func)(void *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Definition: pk_internal.h:62
int(* mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Types for RSA-alt abstraction.
Definition: pk.h:159
size_t(* mbedtls_pk_rsa_alt_key_len_func)(void *ctx)
Definition: pk.h:166
int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
Export debug information.
Definition: pk.c:346
std::string output
Definition: Config.FromFile.cpp:44
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
Definition: pk.c:361
Public key container.
Definition: pk.h:123
mbedtls_md_type_t mgf1_hash_id
Definition: pk.h:87
Definition: pk.h:76
GLuint GLuint end
Definition: glext.h:6292
RSA context structure.
Definition: rsa.h:79
int(* mbedtls_pk_rsa_alt_sign_func)(void *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)
Definition: pk.h:162
Item to send to the debug module.
Definition: pk.h:105
static INLINE mbedtls_rsa_context * mbedtls_pk_rsa(const mbedtls_pk_context pk)
Definition: pk.h:136
The RSA public-key cryptosystem.
size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
Get the size in bits of the underlying key.
Definition: pk.c:335
int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info)
Initialize a PK context with the information given and allocates the type-specific PK subcontext.
Definition: pk.c:102
GLdouble n
Definition: glext.h:8396
bf_uint8_t options
Definition: connect_ps4.c:78
ECP key pair structure.
Definition: ecp.h:165
mbedtls_pk_debug_type
Types for interfacing with the debug module.
Definition: pk.h:95