1 /**
2  * \file pk.h
3  *
4  * \brief Public Key abstraction layer: wrapper functions
5  *
6  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7  *  SPDX-License-Identifier: Apache-2.0
8  *
9  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
10  *  not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *
13  *  http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  *
21  *  This file is part of mbed TLS (https://tls.mbed.org)
22  */
23 
24 #ifndef MBEDTLS_PK_WRAP_H
25 #define MBEDTLS_PK_WRAP_H
26 
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
32 
33 #include "pk.h"
34 
35 struct mbedtls_pk_info_t
36 {
37     /** Public key type */
38     mbedtls_pk_type_t type;
39 
40     /** Type name */
41     const char *name;
42 
43     /** Get key size in bits */
44     size_t (*get_bitlen)( const void * );
45 
46     /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
47     int (*can_do)( mbedtls_pk_type_t type );
48 
49     /** Verify signature */
50     int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
51                         const unsigned char *hash, size_t hash_len,
52                         const unsigned char *sig, size_t sig_len );
53 
54     /** Make signature */
55     int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
56                       const unsigned char *hash, size_t hash_len,
57                       unsigned char *sig, size_t *sig_len,
58                       int (*f_rng)(void *, unsigned char *, size_t),
59                       void *p_rng );
60 
61     /** Decrypt message */
62     int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
63                          unsigned char *output, size_t *olen, size_t osize,
64                          int (*f_rng)(void *, unsigned char *, size_t),
65                          void *p_rng );
66 
67     /** Encrypt message */
68     int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
69                          unsigned char *output, size_t *olen, size_t osize,
70                          int (*f_rng)(void *, unsigned char *, size_t),
71                          void *p_rng );
72 
73     /** Check public-private key pair */
74     int (*check_pair_func)( const void *pub, const void *prv );
75 
76     /** Allocate a new context */
77     void * (*ctx_alloc_func)( void );
78 
79     /** Free the given context */
80     void (*ctx_free_func)( void *ctx );
81 
82     /** Interface with the debug module */
83     void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
84 
85 };
86 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
87 /* Container for RSA-alt */
88 typedef struct
89 {
90     void *key;
91     mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
92     mbedtls_pk_rsa_alt_sign_func sign_func;
93     mbedtls_pk_rsa_alt_key_len_func key_len_func;
94 } mbedtls_rsa_alt_context;
95 #endif
96 
97 #if defined(MBEDTLS_RSA_C)
98 extern const mbedtls_pk_info_t mbedtls_rsa_info;
99 #endif
100 
101 #if defined(MBEDTLS_ECP_C)
102 extern const mbedtls_pk_info_t mbedtls_eckey_info;
103 extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
104 #endif
105 
106 #if defined(MBEDTLS_ECDSA_C)
107 extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
108 #endif
109 
110 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
111 extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
112 #endif
113 
114 #endif /* MBEDTLS_PK_WRAP_H */
115