ReactOS 0.4.15-dev-7924-g5949c20
pk.h
Go to the documentation of this file.
1
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 *
28 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
48 */
49
50#ifndef MBEDTLS_PK_H
51#define MBEDTLS_PK_H
52
53#if !defined(MBEDTLS_CONFIG_FILE)
54#include "config.h"
55#else
56#include MBEDTLS_CONFIG_FILE
57#endif
58
59#include "md.h"
60
61#if defined(MBEDTLS_RSA_C)
62#include "rsa.h"
63#endif
64
65#if defined(MBEDTLS_ECP_C)
66#include "ecp.h"
67#endif
68
69#if defined(MBEDTLS_ECDSA_C)
70#include "ecdsa.h"
71#endif
72
73#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
74 !defined(inline) && !defined(__cplusplus)
75#define inline __inline
76#endif
77
78#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
79#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
80#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
81#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
82#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
83#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
84#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
85#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
86#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
87#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
88#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
89#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
90#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
91#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
93/* MBEDTLS_ERR_PK_HW_ACCEL_FAILED is deprecated and should not be used. */
94#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880
96#ifdef __cplusplus
97extern "C" {
98#endif
99
103typedef enum {
112
118{
121
123
127typedef enum
128{
133
138{
140 const char *name;
141 void *value;
143
145#define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
146
151
155typedef struct mbedtls_pk_context
156{
158 void * pk_ctx;
160
161#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
165typedef struct
166{
167 const mbedtls_pk_info_t * pk_info;
168 void * rs_ctx;
170#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
171/* Now we can declare functions that take a pointer to that */
173#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
174
175#if defined(MBEDTLS_RSA_C)
183{
184 return( (mbedtls_rsa_context *) (pk).pk_ctx );
185}
186#endif /* MBEDTLS_RSA_C */
187
188#if defined(MBEDTLS_ECP_C)
196{
197 return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
198}
199#endif /* MBEDTLS_ECP_C */
200
201#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
205typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, int mode, size_t *olen,
206 const unsigned char *input, unsigned char *output,
207 size_t output_max_len );
209 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
210 int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
211 const unsigned char *hash, unsigned char *sig );
213#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
214
223
231
239
240#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
247void mbedtls_pk_restart_init( mbedtls_pk_restart_ctx *ctx );
248
255void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx );
256#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
257
274
275#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
294 mbedtls_pk_rsa_alt_key_len_func key_len_func );
295#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
296
305
313static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx )
314{
315 return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 );
316}
317
331
357 const unsigned char *hash, size_t hash_len,
358 const unsigned char *sig, size_t sig_len );
359
381 mbedtls_md_type_t md_alg,
382 const unsigned char *hash, size_t hash_len,
383 const unsigned char *sig, size_t sig_len,
384 mbedtls_pk_restart_ctx *rs_ctx );
385
417 const unsigned char *hash, size_t hash_len,
418 const unsigned char *sig, size_t sig_len );
419
450 const unsigned char *hash, size_t hash_len,
451 unsigned char *sig, size_t *sig_len,
452 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
453
482 mbedtls_md_type_t md_alg,
483 const unsigned char *hash, size_t hash_len,
484 unsigned char *sig, size_t *sig_len,
485 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
486 mbedtls_pk_restart_ctx *rs_ctx );
487
506 const unsigned char *input, size_t ilen,
507 unsigned char *output, size_t *olen, size_t osize,
508 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
509
527 const unsigned char *input, size_t ilen,
528 unsigned char *output, size_t *olen, size_t osize,
529 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
530
540
550
559
569
570#if defined(MBEDTLS_PK_PARSE_C)
601 const unsigned char *key, size_t keylen,
602 const unsigned char *pwd, size_t pwdlen );
603
627 const unsigned char *key, size_t keylen );
628
629#if defined(MBEDTLS_FS_IO)
651int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
652 const char *path, const char *password );
653
671int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path );
672#endif /* MBEDTLS_FS_IO */
673#endif /* MBEDTLS_PK_PARSE_C */
674
675#if defined(MBEDTLS_PK_WRITE_C)
689int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
690
704int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
705
706#if defined(MBEDTLS_PEM_WRITE_C)
717int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
718
729int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
730#endif /* MBEDTLS_PEM_WRITE_C */
731#endif /* MBEDTLS_PK_WRITE_C */
732
733/*
734 * WARNING: Low-level functions. You probably do not want to use these unless
735 * you are certain you do ;)
736 */
737
738#if defined(MBEDTLS_PK_PARSE_C)
749int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
750 mbedtls_pk_context *pk );
751#endif /* MBEDTLS_PK_PARSE_C */
752
753#if defined(MBEDTLS_PK_WRITE_C)
764int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
765 const mbedtls_pk_context *key );
766#endif /* MBEDTLS_PK_WRITE_C */
767
768/*
769 * Internal module functions. You probably do not want to use these unless you
770 * know you do.
771 */
772#if defined(MBEDTLS_FS_IO)
773int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
774#endif
775
776#ifdef __cplusplus
777}
778#endif
779
780#endif /* MBEDTLS_PK_H */
void pwd(int argc, const char *argv[])
Definition: cmds.c:1401
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
__kernel_size_t size_t
Definition: linux.h:237
This file contains ECDSA definitions and functions.
This file provides an API for Elliptic Curves over GF(P) (ECP).
GLuint start
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLenum mode
Definition: glext.h:6217
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLenum GLenum input
Definition: glext.h:9031
This file contains the generic message-digest wrapper.
mbedtls_md_type_t
Supported message digests.
Definition: md.h:83
static WCHAR password[]
Definition: url.c:33
static TCHAR * items[]
Definition: page1.c:45
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:205
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.
int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
Export debug information.
static size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
Get the length in bytes of the underlying key.
Definition: pk.h:313
int mbedtls_pk_sign_restartable(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, mbedtls_pk_restart_ctx *rs_ctx)
Restartable version of mbedtls_pk_sign()
int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
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.
mbedtls_pk_type_t
Public key types.
Definition: pk.h:103
@ MBEDTLS_PK_NONE
Definition: pk.h:104
@ MBEDTLS_PK_ECDSA
Definition: pk.h:108
@ MBEDTLS_PK_RSASSA_PSS
Definition: pk.h:110
@ MBEDTLS_PK_RSA_ALT
Definition: pk.h:109
@ MBEDTLS_PK_RSA
Definition: pk.h:105
@ MBEDTLS_PK_ECKEY_DH
Definition: pk.h:107
@ MBEDTLS_PK_ECKEY
Definition: pk.h:106
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).
static mbedtls_rsa_context * mbedtls_pk_rsa(const mbedtls_pk_context pk)
Definition: pk.h:182
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.
static mbedtls_ecp_keypair * mbedtls_pk_ec(const mbedtls_pk_context pk)
Definition: pk.h:195
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.
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....
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv)
Check if a public-private pair of keys matches.
mbedtls_pk_debug_type
Types for interfacing with the debug module.
Definition: pk.h:128
@ MBEDTLS_PK_DEBUG_MPI
Definition: pk.h:130
@ MBEDTLS_PK_DEBUG_ECP
Definition: pk.h:131
@ MBEDTLS_PK_DEBUG_NONE
Definition: pk.h:129
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE).
const mbedtls_pk_info_t * mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type)
Return information associated with the given PK type.
int mbedtls_pk_verify_restartable(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, mbedtls_pk_restart_ctx *rs_ctx)
Restartable version of mbedtls_pk_verify()
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
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.
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).
size_t(* mbedtls_pk_rsa_alt_key_len_func)(void *ctx)
Definition: pk.h:212
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
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:208
void mbedtls_pk_restart_ctx
Definition: pk.h:172
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.
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).
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
This file provides an API for the RSA public-key cryptosystem.
#define mbedtls_pk_get_bitlen
Definition: _hash_fun.h:40
Definition: copy.c:22
The ECP key-pair structure.
Definition: ecp.h:398
Public key container.
Definition: pk.h:156
const mbedtls_pk_info_t * pk_info
Definition: pk.h:157
void * pk_ctx
Definition: pk.h:158
Item to send to the debug module.
Definition: pk.h:138
void * value
Definition: pk.h:141
const char * name
Definition: pk.h:140
mbedtls_pk_debug_type type
Definition: pk.h:139
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext()
Definition: pk.h:118
mbedtls_md_type_t mgf1_hash_id
Definition: pk.h:119
The RSA context structure.
Definition: rsa.h:126