mbed TLS v2.3.0
pkcs11.h
Go to the documentation of this file.
1 
27 #ifndef MBEDTLS_PKCS11_H
28 #define MBEDTLS_PKCS11_H
29 
30 #if !defined(MBEDTLS_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include MBEDTLS_CONFIG_FILE
34 #endif
35 
36 #if defined(MBEDTLS_PKCS11_C)
37 
38 #include "x509_crt.h"
39 
40 #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
41 
42 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
43  !defined(inline) && !defined(__cplusplus)
44 #define inline __inline
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
54 typedef struct {
55  pkcs11h_certificate_t pkcs11h_cert;
56  int len;
57 } mbedtls_pkcs11_context;
58 
63 void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
64 
73 int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
74 
85 int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
86  pkcs11h_certificate_t pkcs11_cert );
87 
94 void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
95 
113 int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
114  int mode, size_t *olen,
115  const unsigned char *input,
116  unsigned char *output,
117  size_t output_max_len );
118 
135 int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
136  int mode,
137  mbedtls_md_type_t md_alg,
138  unsigned int hashlen,
139  const unsigned char *hash,
140  unsigned char *sig );
141 
145 static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
146  const unsigned char *input, unsigned char *output,
147  size_t output_max_len )
148 {
149  return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
150  output_max_len );
151 }
152 
153 static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
154  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
155  int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
156  const unsigned char *hash, unsigned char *sig )
157 {
158  ((void) f_rng);
159  ((void) p_rng);
160  return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
161  hashlen, hash, sig );
162 }
163 
164 static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
165 {
166  return ( (mbedtls_pkcs11_context *) ctx )->len;
167 }
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif /* MBEDTLS_PKCS11_C */
174 
175 #endif /* MBEDTLS_PKCS11_H */
Configuration options (set of defines)
X.509 certificate parsing and writing.
Container for an X.509 certificate.
Definition: x509_crt.h:54
mbedtls_md_type_t
Definition: md.h:41