PolarSSL v1.3.9
Main Page
Modules
Data Structures
Files
File List
Globals
include
polarssl
pk.h
Go to the documentation of this file.
1
28
#ifndef POLARSSL_PK_H
29
#define POLARSSL_PK_H
30
31
#if !defined(POLARSSL_CONFIG_FILE)
32
#include "
config.h
"
33
#else
34
#include POLARSSL_CONFIG_FILE
35
#endif
36
37
#include "
md.h
"
38
39
#if defined(POLARSSL_RSA_C)
40
#include "
rsa.h
"
41
#endif
42
43
#if defined(POLARSSL_ECP_C)
44
#include "
ecp.h
"
45
#endif
46
47
#if defined(POLARSSL_ECDSA_C)
48
#include "
ecdsa.h
"
49
#endif
50
51
#define POLARSSL_ERR_PK_MALLOC_FAILED -0x2F80
52
#define POLARSSL_ERR_PK_TYPE_MISMATCH -0x2F00
53
#define POLARSSL_ERR_PK_BAD_INPUT_DATA -0x2E80
54
#define POLARSSL_ERR_PK_FILE_IO_ERROR -0x2E00
55
#define POLARSSL_ERR_PK_KEY_INVALID_VERSION -0x2D80
56
#define POLARSSL_ERR_PK_KEY_INVALID_FORMAT -0x2D00
57
#define POLARSSL_ERR_PK_UNKNOWN_PK_ALG -0x2C80
58
#define POLARSSL_ERR_PK_PASSWORD_REQUIRED -0x2C00
59
#define POLARSSL_ERR_PK_PASSWORD_MISMATCH -0x2B80
60
#define POLARSSL_ERR_PK_INVALID_PUBKEY -0x2B00
61
#define POLARSSL_ERR_PK_INVALID_ALG -0x2A80
62
#define POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE -0x2A00
63
#define POLARSSL_ERR_PK_FEATURE_UNAVAILABLE -0x2980
64
#define POLARSSL_ERR_PK_SIG_LEN_MISMATCH -0x2000
67
#if defined(POLARSSL_RSA_C)
68
74
#define pk_rsa( pk ) ( (rsa_context *) (pk).pk_ctx )
75
#endif
/* POLARSSL_RSA_C */
76
77
#if defined(POLARSSL_ECP_C)
78
84
#define pk_ec( pk ) ( (ecp_keypair *) (pk).pk_ctx )
85
#endif
/* POLARSSL_ECP_C */
86
87
88
#ifdef __cplusplus
89
extern
"C"
{
90
#endif
91
95
typedef
enum
{
96
POLARSSL_PK_NONE
=0,
97
POLARSSL_PK_RSA
,
98
POLARSSL_PK_ECKEY
,
99
POLARSSL_PK_ECKEY_DH
,
100
POLARSSL_PK_ECDSA
,
101
POLARSSL_PK_RSA_ALT
,
102
POLARSSL_PK_RSASSA_PSS
,
103
}
pk_type_t
;
104
109
typedef
struct
110
{
111
md_type_t
mgf1_hash_id
;
112
int
expected_salt_len
;
113
114
}
pk_rsassa_pss_options
;
115
119
typedef
enum
120
{
121
POLARSSL_PK_DEBUG_NONE
= 0,
122
POLARSSL_PK_DEBUG_MPI
,
123
POLARSSL_PK_DEBUG_ECP
,
124
}
pk_debug_type
;
125
129
typedef
struct
130
{
131
pk_debug_type
type
;
132
const
char
*
name
;
133
void
*
value
;
134
}
pk_debug_item
;
135
137
#define POLARSSL_PK_DEBUG_MAX_ITEMS 3
138
142
typedef
struct
143
{
145
pk_type_t
type
;
146
148
const
char
*
name
;
149
151
size_t (*get_size)(
const
void
* );
152
154
int (*can_do)(
pk_type_t
type );
155
157
int (*verify_func)(
void
*ctx,
md_type_t
md_alg,
158
const
unsigned
char
*hash,
size_t
hash_len,
159
const
unsigned
char
*sig,
size_t
sig_len );
160
162
int (*sign_func)(
void
*ctx,
md_type_t
md_alg,
163
const
unsigned
char
*hash,
size_t
hash_len,
164
unsigned
char
*sig,
size_t
*sig_len,
165
int (*f_rng)(
void
*,
unsigned
char
*, size_t),
166
void
*p_rng );
167
169
int (*decrypt_func)(
void
*ctx,
const
unsigned
char
*input,
size_t
ilen,
170
unsigned
char
*output,
size_t
*olen,
size_t
osize,
171
int (*f_rng)(
void
*,
unsigned
char
*, size_t),
172
void
*p_rng );
173
175
int (*encrypt_func)(
void
*ctx,
const
unsigned
char
*input,
size_t
ilen,
176
unsigned
char
*output,
size_t
*olen,
size_t
osize,
177
int (*f_rng)(
void
*,
unsigned
char
*, size_t),
178
void
*p_rng );
179
181
void
* (*ctx_alloc_func)( void );
182
184
void (*ctx_free_func)(
void
*ctx );
185
187
void (*debug_func)(
const
void
*ctx,
pk_debug_item
*items );
188
189
}
pk_info_t
;
190
194
typedef
struct
195
{
196
const
pk_info_t
*
pk_info
;
197
void
*
pk_ctx
;
198
}
pk_context
;
199
203
typedef
int (*
pk_rsa_alt_decrypt_func
)(
void
*ctx,
int
mode,
size_t
*olen,
204
const
unsigned
char
*input,
unsigned
char
*output,
205
size_t
output_max_len );
206
typedef
int (*
pk_rsa_alt_sign_func
)(
void
*ctx,
207
int (*f_rng)(
void
*,
unsigned
char
*, size_t),
void
*p_rng,
208
int
mode,
md_type_t
md_alg,
unsigned
int
hashlen,
209
const
unsigned
char
*hash,
unsigned
char
*sig );
210
typedef
size_t (*
pk_rsa_alt_key_len_func
)(
void
*ctx );
211
219
const
pk_info_t
*
pk_info_from_type
(
pk_type_t
pk_type );
220
224
void
pk_init
(
pk_context
*ctx );
225
229
void
pk_free
(
pk_context
*ctx );
230
245
int
pk_init_ctx
(
pk_context
*ctx,
const
pk_info_t
*info );
246
261
int
pk_init_ctx_rsa_alt
(
pk_context
*ctx,
void
* key,
262
pk_rsa_alt_decrypt_func
decrypt_func,
263
pk_rsa_alt_sign_func
sign_func,
264
pk_rsa_alt_key_len_func
key_len_func );
265
273
size_t
pk_get_size
(
const
pk_context
*ctx );
274
281
static
inline
size_t
pk_get_len
(
const
pk_context
*ctx )
282
{
283
return
( (
pk_get_size
( ctx ) + 7 ) / 8 );
284
}
285
295
int
pk_can_do
(
pk_context
*ctx,
pk_type_t
type );
296
321
int
pk_verify
(
pk_context
*ctx,
md_type_t
md_alg,
322
const
unsigned
char
*hash,
size_t
hash_len,
323
const
unsigned
char
*sig,
size_t
sig_len );
324
354
int
pk_verify_ext
(
pk_type_t
type,
const
void
*options,
355
pk_context
*ctx,
md_type_t
md_alg,
356
const
unsigned
char
*hash,
size_t
hash_len,
357
const
unsigned
char
*sig,
size_t
sig_len );
358
382
int
pk_sign
(
pk_context
*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 );
386
403
int
pk_decrypt
(
pk_context
*ctx,
404
const
unsigned
char
*input,
size_t
ilen,
405
unsigned
char
*output,
size_t
*olen,
size_t
osize,
406
int
(*f_rng)(
void
*,
unsigned
char
*,
size_t
),
void
*p_rng );
407
424
int
pk_encrypt
(
pk_context
*ctx,
425
const
unsigned
char
*input,
size_t
ilen,
426
unsigned
char
*output,
size_t
*olen,
size_t
osize,
427
int
(*f_rng)(
void
*,
unsigned
char
*,
size_t
),
void
*p_rng );
428
437
int
pk_debug
(
const
pk_context
*ctx,
pk_debug_item
*items );
438
446
const
char
*
pk_get_name
(
const
pk_context
*ctx );
447
455
pk_type_t
pk_get_type
(
const
pk_context
*ctx );
456
457
#if defined(POLARSSL_PK_PARSE_C)
458
476
int
pk_parse_key
(
pk_context
*ctx,
477
const
unsigned
char
*key,
size_t
keylen,
478
const
unsigned
char
*pwd,
size_t
pwdlen );
479
496
int
pk_parse_public_key
(
pk_context
*ctx,
497
const
unsigned
char
*key,
size_t
keylen );
498
499
#if defined(POLARSSL_FS_IO)
500
516
int
pk_parse_keyfile
(
pk_context
*ctx,
517
const
char
*path,
const
char
*password );
518
534
int
pk_parse_public_keyfile
(
pk_context
*ctx,
const
char
*path );
535
#endif
/* POLARSSL_FS_IO */
536
#endif
/* POLARSSL_PK_PARSE_C */
537
538
#if defined(POLARSSL_PK_WRITE_C)
539
552
int
pk_write_key_der
(
pk_context
*ctx,
unsigned
char
*buf,
size_t
size );
553
567
int
pk_write_pubkey_der
(
pk_context
*ctx,
unsigned
char
*buf,
size_t
size );
568
569
#if defined(POLARSSL_PEM_WRITE_C)
570
579
int
pk_write_pubkey_pem
(
pk_context
*ctx,
unsigned
char
*buf,
size_t
size );
580
590
int
pk_write_key_pem
(
pk_context
*ctx,
unsigned
char
*buf,
size_t
size );
591
#endif
/* POLARSSL_PEM_WRITE_C */
592
#endif
/* POLARSSL_PK_WRITE_C */
593
594
/*
595
* WARNING: Low-level functions. You probably do not want to use these unless
596
* you are certain you do ;)
597
*/
598
599
#if defined(POLARSSL_PK_PARSE_C)
600
609
int
pk_parse_subpubkey
(
unsigned
char
**p,
const
unsigned
char
*end,
610
pk_context
*pk );
611
#endif
/* POLARSSL_PK_PARSE_C */
612
613
#if defined(POLARSSL_PK_WRITE_C)
614
624
int
pk_write_pubkey
(
unsigned
char
**p,
unsigned
char
*start,
625
const
pk_context
*key );
626
#endif
/* POLARSSL_PK_WRITE_C */
627
628
#ifdef __cplusplus
629
}
630
#endif
631
632
#endif
/* POLARSSL_PK_H */
Generated on Fri Nov 14 2014 20:22:54 for PolarSSL v1.3.9 by
1.8.3